Repository navigation
Add vmcp command - #958
Add vmcp command#958kunal-naik wants to merge 1 commit into
Conversation
e233ad5 to
dbb35bb
Compare
3da2a3c to
67eab65
Compare
|
What the PR is trying to do is sensible: add a VMCP-based alternative for active NIC detach/uncouple paths and switch to it when the config says not to use SMAPI. The problem is the implementation is incomplete in a couple of important ways. I’d call out these as blocking issues before merge: The general direction is good, but the implementation should either: |
67eab65 to
fe096f6
Compare
|
VMCP results are validated and raise the same SDK errors as the SMAPI path. Config registration is tracked in a separate PR - #954. |
Bischoff
left a comment
There was a problem hiding this comment.
Eric
Thanks as usual for the PR.
I see no doc nor unit tests.
Claude, prompted by Eric
I reviewed the current head of the branch (fe096f6).
Thanks for having checked the VMCP return codes since Rajat's review.
Points common to the whole VMCP series
For the problems of the shared vmcpHandler.py, of the single option name, and of CP privilege classes, please see my review of #954.
Points specific to this PR:
- Bug: possible race condition
As in #956, SMTClient.__init__() creates a single shared ReqHandle, with the same concurrency issues; please see my review of #956 for a way to fix that.
- Inconsistency with SMAPI: tolerated errors are now failures
On the SMAPI path, delete_nic() only logs a warning when the NIC does not exist on the active system (rc 204 / rs 8), and uncouple_nic() when the NIC is already disconnected (rc 204 / rs 48).
On the VMCP path, any failure of FOR <userid> CMD DETACH NIC or UNCOUPLE raises SDKConflictError.
For delete_nic(), the switch table record has already been deleted at that point, so the caller gets an error while the database is already updated. I suggest recognizing the equivalent CP messages and handling them like the SMAPI path.
- Inconsistency with SMAPI: error mapping
The SMAPI path uses _delete_nic_active_exception() and _uncouple_active_exception(), which distinguish conflicts (rs 28) from other errors. The VMCP path always raises SDKConflictError, so callers get different exceptions depending on the option.
- Unit tests
There are no tests for delete_nic_for_guest(), uncouple_nic_for_guest() and the new branches.
Without #954, the existing test_delete_nic and test_uncouple_nic fail with AttributeError: 'CONF' object has no attribute 'use_smapi'.
- Documentation
Nothing documents that the NIC detach and uncouple on an active guest go through VMCP when the option is disabled, nor the privilege classes needed by FOR ... CMD.
8b9db0b to
033745d
Compare
|
@Bischoff Thanks for the detailed review. All points addressed:
|
033745d to
b501b4d
Compare
Bischoff
left a comment
There was a problem hiding this comment.
Claude, prompted by Eric
I reviewed the current head of the branch (b501b4d). Thank you Kunal for this thorough update.
Solved issues
- Shared ReqHandle: a fresh
ReqHandleis now created per call. - Tolerated errors:
HCPNIC040Eon detach andHCPCPL2791Eon uncouple now only log a warning, like the SMAPI path. - Error mapping:
SDKConflictErrorrs 8 / rs 12 andSDKObjectNotExistErrornow mirror_delete_nic_active_exception()and_uncouple_active_exception(). - Unit tests: the new tests cover
delete_nic_for_guest(),uncouple_nic_for_guest()and the new branches ofSMTClient; all unit tests pass (zvmsdk 1083, smtLayer 108). - Merging master brought no regression: no test and no function from master was lost.
Remaining points
-
Style
tox -e pep8fails:zvmsdk/smtclient.py:53: F811,ReqHandle(andvmcpHandler) are already imported a few lines above since master brought them; the existingVMCPHandler(rh)import can be
reused;smtLayer/vmcpHandler.py:147: E303, one blank line too many after_run_for().
-
Return code of
FOR ... CMDThe error handling in
SMTClient.delete_nic()and_uncouple_nic()relies on vmcp exiting with a non-zero code when the inner command fails. The test data containHCPFOR069I Command Complete. CP return code = 0040, which suggests thatFORitself may complete while reporting the inner return code. Could you confirm how vmcp behaves in that case, and
attach real outputs for a successful detach and uncouple, a non-existent NIC (for both commands) and an already uncoupled NIC? That would also confirm theHCPNIC040E,
HCPCPL040EandHCPCPL2791Emessage ids. -
Overlap with #957
#957 adds a nearly identical
VMCPHandler._run_for()and also edits step 7 ofquickstart.rst(its title becomes "A, B and C"). The two branches conflict on both files.
Whichever is merged second will need a careful conflict resolution, keeping a single_run_for(). -
Documentation
Thanks for the two rows in
doc/source/quickstart.rst. Two small additions would complete it:- the title of step 7 still says "A and B" while this PR needs class C (see point 3);
- the help of the
use_smapioption inzvmsdk/config.pymentions only power operations; it would be nice to mention the NIC detach and uncouple on an active guest too (and to regeneratedoc/source/zvmsdk.conf.sample).
b501b4d to
cc02893
Compare
d972e92 to
dbf19f2
Compare
|
Open |
dbf19f2 to
ca1841f
Compare
|
@Bischoff @Rajat-0 Thanks for the detailed reviews. Updated and rebased on current master.
Known limitation and follow-up: |
There was a problem hiding this comment.
Eric
I was not sure I was requested to proofread this one, but your comment started with "@Bischoff @Rajat-0", so I did it after all.
I saw nothing with a quick human glance, so I offloaded the details to Claude. It found a possible inconsistency with the database, so I requested changes.
Claude, prompted by Eric
I reviewed the current head of the branch (ca1841f). Thank you Kunal for this rework and for opening #993. The PR now checks that the NIC exists, and whether it is coupled, before it runs FOR ... CMD DETACH NIC and FOR ... CMD UNCOUPLE. The guessed CP message ids are gone. The PR also reuses VMCPHandler._run_for() from master.
Checks
After the rebase on master (cae3071), nothing was lost. All the files of the previous diff (b501b4d) are still there. No function or test of master disappeared. _run_for(), the imports and the two quickstart.rst rows were dropped from the PR because they are now on master. The three removed tests (*_hcpnic040e_*, *_hcpcpl040e_*, *_hcpcpl2791e_*) belonged to the message ids you removed on purpose.
tox -e pep8 passes. Unit tests, Python 3.13: master gives 1106 (zvmsdk) and 197 (smtLayer), all passing. With the PR: 1113 and 211, all passing, no new failure.
No test on a real z/VM.
Previous remarks
| Remark | Status |
|---|---|
| Eric, 26/10: no documentation, no unit tests | Fixed |
| Eric, 26/10, common to the series (#954): shared handler, one option name, privilege classes | Fixed on master: single use_smapi option, privilege table in quickstart.rst |
Eric, 26/10, 1: shared ReqHandle |
Fixed: one ReqHandle per call |
| Eric, 26/10, 2: tolerated errors become failures | Fixed with pre-checks: an absent NIC on detach and an uncoupled NIC on uncouple only log a warning |
| Eric, 26/10, 3: error mapping | Partly fixed: absent NIC on uncouple gives SDKObjectNotExistError; every other failure still gives SDKConflictError (see point 2) |
Eric, 26/10, 4: unit tests, AttributeError without #954 |
Fixed: 7 new tests in test_smtclient.py, 14 in test_vmcpHandler.py; #954 is merged |
| Eric, 26/10, 5: documentation | Fixed: see point 4 for what is still missing |
| Eric, 29/10, 1: pep8 (F811, E303) | Fixed: tox -e pep8 passes |
Eric, 29/10, 2: return code of FOR, real outputs |
Answered: vmcp does not report the inner result, hence the pre-checks. Real outputs are still not attached (see points 1 and 3) |
| Eric, 29/10, 3: overlap with #957 | Resolved: one _run_for(), on master |
Eric, 29/10, 4: title of step 7, use_smapi help, zvmsdk.conf.sample |
Fixed: master rewrote the paragraph; the PR extends the help and regenerates the sample |
| Rajat, 22/10: VMCP errors ignored | Partly fixed: a non-zero rc is now raised, but a failed inner command can still look like a success (point 1) |
| Rajat, 22/10: config flag undefined | Fixed: use_smapi from #954 |
| Rajat, 30/10, 1: every vmcp failure is a 409 | Open, deferred to #993 (point 2) |
| Rajat, 30/10, 2: invented CP message ids | Old ids removed; the new ids still include the module prefix, and the outputs are not shown (point 3) |
Rajat, 30/10, 3: use_smapi help mentions FCP WWPN and LINK |
Resolved: these lines now come from master, where both operations exist |
Rajat, 30/10, 4: message 0405 in _run_for() |
_run_for() is now master code, so this PR is no longer the place to fix it |
Remaining points
-
Bug: a failed detach or uncouple can still be reported as a success
You wrote that vmcp can exit with rc 0 and no output when the inner command of
FORfails. In that caseVMCPHandler.delete_nic_for_guest()anduncouple_nic_for_guest()return success. ThenSMTClient.delete_nic()and_uncouple_nic()log "successfully", but the NIC is still present, or still coupled, on the active guest. The directory and the switch table are already updated at that point, so the two views disagree. This is the "fail closed" problem Rajat raised on 22/10.On master,
create_nic_for_guest()already handles this case: afterDEFINE NICit runsQUERY NIC USERIDto confirm the result. I suggest doing the same here. AfterDETACH NIC,QUERY NICshould report the NIC as absent. AfterUNCOUPLE,is_nic_coupled()should returnFalse. If not, raise an error. It is a small change and does not need the IUCV approach of #993. -
Error mapping (Rajat's point 1)
I understand that the inner
FORfailures are left to #993. The failures of the twoQUERYpre-checks, though, are ordinary vmcp failures. "Not authorized" or "guest not found" are not conflicts. Right nowSMTClient.delete_nic()and_uncouple_nic()turn them intoSDKConflictError(409). It would be nice to raiseSDKSMTRequestFailedorSDKInternalErrorfor them, as the SMAPI path does for anything other than rs 28. Also,_run()returns an emptyresponseon failure unless you passoutput=True. The exception then only says "QUERY NIC failed for X 0600, rc: 1", without the CP reply. Passingoutput=Trueand putting the CP text (theoutputkey) in the message would help diagnose problems. -
CP message ids of the pre-checks
NIC_NOT_FOUND_PATTERN = r'HCPNIC2836E'andNO_VSWITCH_ADAPTER_PATTERN = r'HCPSWQ2836E'insmtLayer/vmcpHandler.pyhard-code the CP module prefix. The patterns already on master (NOT_ATTACHED_PATTERN = r'HCP\w*040E') and Rajat's suggestion match only the message number. Could you user'HCP\w{3}2836E', or explain why the prefix is needed?- The fixtures in
test_vmcpHandler.pystill look hand-written. For example,HCPSWQ2836E USERID was not found.is interpreted as "no adapter on any vswitch". Is that really the reply ofQUERY VSWITCH ALL DETAILS USERIDfor a logged-on guest without a vswitch adapter? Could you attach real outputs ofQUERY NIC USERID <id> <vdev>for an existing and a missing NIC, and ofQUERY VSWITCH ALL DETAILS USERID <id>for a guest with a coupled NIC and for a guest without one? That would also confirm the regular expression inis_nic_coupled(). is_nic_coupled()only looks at vswitches. A NIC coupled to a guest LAN would be reported as "already uncoupled", andUNCOUPLEwould be skipped. Is it safe to assume that Feilong only couples NICs to vswitches (couple_nic_to_vswitch())? If so, a comment would help.
-
Documentation
This PR adds two CP commands to what Feilong needs when
use_smapi = False. The rows forFOR userid CMD UNCOUPLEandFOR userid CMD DETACH NICare already on master. To complete the documentation:doc/source/quickstart.rst: the new row gives class B forQUERY VSWITCH ALL DETAILS USERID userid, while the existingQUERY VSWITCH DETAILSrow says B, G. Could you check both against the CP Commands and Utilities Reference, as well as class B forQUERY NIC USERID?- The help of
use_smapiinzvmsdk/config.py(anddoc/source/zvmsdk.conf.sample): it would be nice to mention the known limitation tracked in #993 there, until it is fixed. Withuse_smapi = False, a NIC delete or disconnect on an active guest returns 409 where the SMAPI path returns 500. It may also miss a failure of the inner command. - The PR description is out of date: it still mentions only
FOR ... CMDand the dependency on #954. It would help reviewers to describe the pre-checks there.
When use_smapi=False, issue the following CP commands through vmcp instead of SMAPI: - FOR <userid> CMD UNCOUPLE (NIC uncouple on an active guest) - FOR <userid> CMD DETACH NIC (NIC detach on an active guest) Before running them, check the state of the NIC: - QUERY NIC USERID <userid> <vdev> verifies that the NIC exists. A missing NIC (message number 2836E) is tolerated: detach is skipped and reported as nic_not_found with overallRC 0; uncouple reports nic_not_found with overallRC 1. - QUERY VSWITCH ALL DETAILS USERID <userid> tells whether the NIC is coupled to a vswitch. A guest with no adapter on any vswitch (message number 2836E) is reported as not coupled. An already uncoupled NIC is not uncoupled again and is reported as already_uncoupled. After UNCOUPLE, the vswitch query is run again. If the NIC is still coupled, an error is returned. vmcp does not return the result of the command run through FOR ... CMD: it can exit with rc 0 and no output when the inner command failed, as CP does not return the messages of some commands through diagnose X'08'. The CP messages of the inner command are therefore not parsed. Only a failure of the FOR itself (non-zero exit) is detected. The result of DETACH NIC is not verified afterwards. A failed QUERY returns the CP reply in strError. SMTClient.delete_nic logs a warning when the NIC is not found, and SMTClient._uncouple_nic raises SDKObjectNotExistError for a missing NIC and only logs a warning for an already uncoupled one. Any other failure raises SDKSMTRequestFailed. Document the new CP commands and their privilege classes in the quickstart step 7 table and in the use_smapi help of config.py and zvmsdk.conf.sample. Signed-off-by: Kunal Naik <kunalnaik@Kunals-MacBook-Pro.local>
ca1841f to
c0568a8
Compare
|
Hi @Bischoff
DETACH NIC: I could not add a check, because QUERY NIC USERID does not show whether the NIC was detached. After a successful FOR RJSH0003 CMD DETACH NIC 1003, the guest reports HCPQVD040E Device 1003 does not exist for q v 1003. From the hypervisor, QUERY NIC USERID still returns the MAC record: It stayed that way until the guest was restarted, and after the restart it returned HCPNIC2836E VDEV was not found. A post-check on QUERY NIC USERID would therefore report every successful detach as a failure. I did not find another CP command that shows the detach without going into the guest, so the detach check we can plan to add in #993.
Both patterns are now r'HCP\w{3}2836E'. The two ids are the same message number from two modules: HCPNIC2836E for QUERY NIC and HCPSWQ2836E for QUERY VSWITCH. for a missing nic QUERY VSWITCH ALL DETAILS USERID for a logged-on guest - With 1003 vdev coupled With 1003 vdev uncoupled For a user that does not exist Guest LAN: Feilong's only coupling path is couple_nic_to_vswitch() (SMAPI Virtual_Network_Adapter_Connect_Vswitch), and there is no API for a guest LAN. A NIC coupled to a guest LAN by other means would be reported as not coupled, and UNCOUPLE would be skipped.
QUERY VSWITCH ALL DETAILS USERID is now B, G in the quickstart table. The CP reference lists QUERY VSWITCH as class B, G. QUERY NIC USERID is class B, which matches the reference. |
PR Description:
Implemented VMCP as the preferred method for detaching and uncoupling a NIC from a running guest, providing vmcp-based alternatives to the existing smcli SMAPI calls. Both operations are handled exclusively within smtclient.py, replacing the Virtual_Network_Adapter_Delete and Virtual_Network_Adapter_Disconnect SMAPI calls.
When use_smapi option is disabled (False), the NIC delete and NIC disconnect operations are dispatched through VMCPHandler using the CP FOR userid CMD mechanism instead of the corresponding SMAPI calls.
Other Implementation in this PR:
Command 1: Virtual_Network_Adapter_Delete
SMCLI: smcli Virtual_Network_Adapter_Delete -v VDEV
Equivalent VMCP: vmcp "FOR USERID CMD DETACH NIC VDEV"
Usage:
Implemented vmcp equivalent for the function that used Virtual_Network_Adapter_Delete.
Command 2: Virtual_Network_Adapter_Disconnect
SMCLI: smcli Virtual_Network_Adapter_Disconnect -v VDEV
Equivalent VMCP: vmcp "FOR USERID CMD UNCOUPLE VDEV"
Usage:
Implemented vmcp equivalent for the function that used Virtual_Network_Adapter_Disconnect.