Skip to content

Conversation

justinc1
Copy link
Collaborator

@justinc1 justinc1 commented Feb 17, 2023

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 by vm_name xor vm_name_new.
A helper function VM.get_by_old_or_new_name does this, and is used in VM module.

PR was draft:

  • (partially done) unit tests need to be updated
  • done - sanity tests
  • todo - run all integration tests
  • vm_nic, vm_disk, vm_params modules should also be updated.
    • I update vm_params module only, because only vm_params and vm modules have vm_name_new param
  • maybe we can do extra cleanup, and stop using old VM.get_by_name - I'm not sure, need to check all affected modules.
    • I didn't even try this - unit test update would be painful

But there is enough code for first review and comments

@justinc1 justinc1 self-assigned this Feb 17, 2023
@justinc1 justinc1 marked this pull request as draft February 17, 2023 13:21
@justinc1 justinc1 force-pushed the vm-rename-test branch 4 times, most recently from 38ddc3a to 2fcf65a Compare February 23, 2023 08:03
@justinc1 justinc1 marked this pull request as ready for review February 23, 2023 08:08
@justinc1
Copy link
Collaborator Author

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.

Copy link
Collaborator

@domendobnikar domendobnikar left a 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):
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

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>
@justinc1
Copy link
Collaborator Author

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.

@justinc1 justinc1 merged commit ba74e6d into main Feb 24, 2023
@justinc1 justinc1 deleted the vm-rename-test branch February 24, 2023 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants