-
Notifications
You must be signed in to change notification settings - Fork 9
VM rename test and fix #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
38ddc3a
to
2fcf65a
Compare
Unit test problems with TestManageVMDisks - I didn't check why I have problems with TestManageVMNics, but not with TestManageVMDisks. At first look, those two tests are not that much different. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I will add a backlog task / issue for VM code cleanup.
- Unit test cleanup
- Get method cleanup
@@ -358,6 +357,26 @@ def get_by_name( | |||
vm_from_hypercore = cls.from_hypercore(hypercore_dict, rest_client) | |||
return vm_from_hypercore | |||
|
|||
@classmethod | |||
def get_by_old_or_new_name(cls, ansible_dict, rest_client, must_exist=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a cleanup issue/task here (not to be done in this PR)?
Feels like we have almost 10 different get methods
for VM and they all do roughly the same thing ...
Maybe we can refactor this into one or two methods maximum.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can have a talk about this. I'm a bit confused by those options (find_by_name(must_exists=True)
vs get_or_fail()
, etc).
I have a felling a more robust way would be not to search for VM by name all the time, but search for it by name 1st time, then access it by UUID.
Also, I have a felling having VM.from_hypercore(vm_hypercore_dict)
accessing HC3 to get also node info and snapshot schedule info is not ideal. Passing two extra params like hypercode_nodes and hypercore_snapshot_schedules might make unit test easier to write - less magic mocking, more like dependency injection. But whole team should agree this is something worth to try, and maybe first on some smaller class, not on VM.
2fcf65a
to
f42e1dd
Compare
A single rename works. Signed-off-by: Justin Cinkelj <justin.cinkelj@xlab.si>
We end with two VM - old and new name. Expected is to just leave VM with new unmodified. Signed-off-by: Justin Cinkelj <justin.cinkelj@xlab.si>
But now _set_disks() still searches only for old name. Likely this should be solved by _set_disks not searching for VM at all - we already found vm_before. _set_vm_params() already works this way - it has vm param. Signed-off-by: Justin Cinkelj <justin.cinkelj@xlab.si>
Signed-off-by: Justin Cinkelj <justin.cinkelj@xlab.si>
vm_params and vm modules are the only modules with param vm_name_new. Signed-off-by: Justin Cinkelj <justin.cinkelj@xlab.si>
Signed-off-by: Justin Cinkelj <justin.cinkelj@xlab.si>
Signed-off-by: Justin Cinkelj <justin.cinkelj@xlab.si>
Signed-off-by: Justin Cinkelj <justin.cinkelj@xlab.si>
Signed-off-by: Justin Cinkelj <justin.cinkelj@xlab.si>
Hypercore power_state - it is the current state of the VM Ansible power_state - it is the desired state of the VM, used by hypercore to decide if state transition is needed. TODO - enforce attribute value validation, maybe add .desired_power_state attribute. Signed-off-by: Justin Cinkelj <justin.cinkelj@xlab.si>
Signed-off-by: Justin Cinkelj <justin.cinkelj@xlab.si>
Signed-off-by: Justin Cinkelj <justin.cinkelj@xlab.si>
Signed-off-by: Justin Cinkelj <justin.cinkelj@xlab.si>
f42e1dd
to
150a56a
Compare
One more note, there is problem in VM.str() implementation. It will push branch problem-with-power-state-mapping, to show this. It seems to me that we store in VM.power_state both VM power_state as retrieved from HyperCore, and sometimes also power_state as set in ansible module. But ansible power_state is actually a command describing transition to HyperCore power_state, not HyperCore power_state (e.g. you can get into SHUTOFF state by nice shutdown or by force shutdown - two different actions, same end state). I noticed this only because I added debug module.warn. Module was not misbehaving. It would be a bit of extra work and testing, so I just added a small workaround to not throw this error to module users. |
Integration test is added to show that renaming VM a second time (idempotence test) does fail in current main.
Problem is (in most places) we search for VM by
vm_name
only, but we should byvm_name
xorvm_name_new
.A helper function
VM.get_by_old_or_new_name
does this, and is used in VM module.PR was draft:
vm_name_new
paramVM.get_by_name
- I'm not sure, need to check all affected modules.But there is enough code for first review and comments