From 3a25ed9716139fb52ed209eade4401db24ef02a5 Mon Sep 17 00:00:00 2001 From: Domen Date: Wed, 3 May 2023 13:08:58 +0200 Subject: [PATCH 01/12] Adding vm_snapshot examples to collection: - filter and delete based on special properties - filter and delete based on timestamps --- ...vm_snapshot_removal_based_on_timestamp.yml | 68 +++++++++++++++++++ examples/vm_snapshot_special_cleanup.yml | 60 ++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 examples/vm_snapshot_removal_based_on_timestamp.yml create mode 100644 examples/vm_snapshot_special_cleanup.yml diff --git a/examples/vm_snapshot_removal_based_on_timestamp.yml b/examples/vm_snapshot_removal_based_on_timestamp.yml new file mode 100644 index 000000000..a3658e2c4 --- /dev/null +++ b/examples/vm_snapshot_removal_based_on_timestamp.yml @@ -0,0 +1,68 @@ +--- +- name: Example - delete all snapshots that are older than X days. + hosts: localhost + connection: local + gather_facts: false + environment: + SC_HOST: "your_host" + SC_USERNAME: "your_username" + SC_PASSWORD: "your_password" + vars: + # Format: 'YYYY-MM-DD hh:mm:ss' + # All snapshots older than this date will be deleted. + use_date: '2023-05-03 12:52:00' + + tasks: + # ------------------------------------------------------ + - name: List all snapshots + scale_computing.hypercore.vm_snapshot_info: + register: snapshot_results + + - name: Convert date to unix timestamp "epoch" + set_fact: + epoch_timestamp: "{{ (use_date | to_datetime).strftime('%s') }}" + + - name: Show epoch_timestamp + ansible.builtin.debug: + var: epoch_timestamp + + - name: Create filtered_snapshots list + set_fact: + filtered_snapshots: [] + + - name: Loop through snapshots and add snapshots that are older than "use_date" + set_fact: + filtered_snapshots: "{{ filtered_snapshots + [ item ] }}" + when: "{{ item.timestamp > epoch_timestamp | int }}" + loop: "{{ snapshot_results.records }}" + no_log: true + + - name: Show only snapshots that are older than "use_date" + ansible.builtin.debug: + var: filtered_snapshots + + # We could reuse "filtered_snapshots" here instead of "snapshot_results" and avoid the "when" statement. + # But leaving it as is for example purposes. + # Since this is the only mandatory task of the playbook, can be copy-pasted and reused as standalone task. + - name: Loop through list of snapshots and delete all older than the "use_date" + scale_computing.hypercore.vm_snapshot: + vm_name: "{{ item.vm.name }}" + label: "{{ item.label }}" + state: absent + when: "{{ item.timestamp > epoch_timestamp | int }}" + loop: "{{ snapshot_results.records }}" + + - name: Create filtered_snapshots list - second time + set_fact: + filtered_snapshots: [] + + - name: Loop through snapshots and add snapshots that are older than "use_date" - second time + set_fact: + filtered_snapshots: "{{ filtered_snapshots + [ item ] }}" + when: "{{ item.timestamp > epoch_timestamp | int }}" + loop: "{{ snapshot_results.records }}" + no_log: true + + - name: Show only snapshots that are older than "use_date" - second time + ansible.builtin.debug: + var: filtered_snapshots diff --git a/examples/vm_snapshot_special_cleanup.yml b/examples/vm_snapshot_special_cleanup.yml new file mode 100644 index 000000000..897f7fa96 --- /dev/null +++ b/examples/vm_snapshot_special_cleanup.yml @@ -0,0 +1,60 @@ +--- +- name: Example - delete all snapshots with label "TEST" and type "USER". + hosts: localhost + connection: local + gather_facts: false + environment: + SC_HOST: "your_host" + SC_USERNAME: "your_username" + SC_PASSWORD: "your_password" + + tasks: + # ------------------------------------------------------ + - name: List all snapshots + scale_computing.hypercore.vm_snapshot_info: + register: snapshot_results + + - name: Create filtered_snapshots list + set_fact: + filtered_snapshots: [] + + - name: Loop through snapshots and add snapshots with label "TEST" and type "USER" to filtered_snapshots + set_fact: + filtered_snapshots: "{{ filtered_snapshots + [ item ] }}" + when: "{{ item.label == 'TEST' and item.type == 'USER' }}" + loop: "{{ snapshot_results.records }}" + no_log: true + + - name: Show only snapshots with label "TEST" and type "USER" + ansible.builtin.debug: + var: filtered_snapshots + + # We could reuse "filtered_snapshots" here instead of "snapshot_results" and avoid the "when" statement. + # But leaving it as is for example purposes. + # Since this is the only mandatory task of the playbook, can be copy-pasted and reused as standalone task. + - name: Loop through list of snapshots delete if label is "TEST" and type is "USER" + scale_computing.hypercore.vm_snapshot: + vm_name: "{{ item.vm.name }}" + label: "{{ item.label }}" + state: absent + when: "{{ item.label == 'TEST' and item.type == 'USER' }}" + loop: "{{ snapshot_results.records }}" + + - name: List all snapshots - second time + scale_computing.hypercore.vm_snapshot_info: + register: snapshot_results + + - name: Create filtered_snapshots list - second time + set_fact: + filtered_snapshots: [] + + - name: Loop through snapshots and add snapshots with label "TEST" and type "USER" to filtered_snapshots - second time + set_fact: + filtered_snapshots: "{{ filtered_snapshots + [ item ] }}" + when: "{{ item.label == 'TEST' and item.type == 'USER' }}" + loop: "{{ snapshot_results.records }}" + no_log: true + + - name: Show only snapshots with label "TEST" and type "USER" - second time + ansible.builtin.debug: + var: filtered_snapshots From db3abdb66fc294f7c33fef1db95fb310d3b6fca1 Mon Sep 17 00:00:00 2001 From: Domen Dobnikar <113340617+domendobnikar@users.noreply.github.com> Date: Wed, 3 May 2023 13:29:53 +0200 Subject: [PATCH 02/12] Update vm_snapshot_removal_based_on_timestamp.yml --- examples/vm_snapshot_removal_based_on_timestamp.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/vm_snapshot_removal_based_on_timestamp.yml b/examples/vm_snapshot_removal_based_on_timestamp.yml index a3658e2c4..d0993b490 100644 --- a/examples/vm_snapshot_removal_based_on_timestamp.yml +++ b/examples/vm_snapshot_removal_based_on_timestamp.yml @@ -18,7 +18,7 @@ scale_computing.hypercore.vm_snapshot_info: register: snapshot_results - - name: Convert date to unix timestamp "epoch" + - name: Convert date to unix timestamp 'epoch' set_fact: epoch_timestamp: "{{ (use_date | to_datetime).strftime('%s') }}" @@ -30,21 +30,21 @@ set_fact: filtered_snapshots: [] - - name: Loop through snapshots and add snapshots that are older than "use_date" + - name: Loop through snapshots and add snapshots that are older than 'use_date' set_fact: filtered_snapshots: "{{ filtered_snapshots + [ item ] }}" when: "{{ item.timestamp > epoch_timestamp | int }}" loop: "{{ snapshot_results.records }}" no_log: true - - name: Show only snapshots that are older than "use_date" + - name: Show only snapshots that are older than 'use_date' ansible.builtin.debug: var: filtered_snapshots # We could reuse "filtered_snapshots" here instead of "snapshot_results" and avoid the "when" statement. # But leaving it as is for example purposes. # Since this is the only mandatory task of the playbook, can be copy-pasted and reused as standalone task. - - name: Loop through list of snapshots and delete all older than the "use_date" + - name: Loop through list of snapshots and delete all older than the 'use_date' scale_computing.hypercore.vm_snapshot: vm_name: "{{ item.vm.name }}" label: "{{ item.label }}" @@ -56,13 +56,13 @@ set_fact: filtered_snapshots: [] - - name: Loop through snapshots and add snapshots that are older than "use_date" - second time + - name: Loop through snapshots and add snapshots that are older than 'use_date' - second time set_fact: filtered_snapshots: "{{ filtered_snapshots + [ item ] }}" when: "{{ item.timestamp > epoch_timestamp | int }}" loop: "{{ snapshot_results.records }}" no_log: true - - name: Show only snapshots that are older than "use_date" - second time + - name: Show only snapshots that are older than 'use_date' - second time ansible.builtin.debug: var: filtered_snapshots From 9449b62512e4c610a3847498965c287630e3c366 Mon Sep 17 00:00:00 2001 From: Domen Dobnikar <113340617+domendobnikar@users.noreply.github.com> Date: Wed, 3 May 2023 13:30:46 +0200 Subject: [PATCH 03/12] Update vm_snapshot_special_cleanup.yml --- examples/vm_snapshot_special_cleanup.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/vm_snapshot_special_cleanup.yml b/examples/vm_snapshot_special_cleanup.yml index 897f7fa96..fffdde4d1 100644 --- a/examples/vm_snapshot_special_cleanup.yml +++ b/examples/vm_snapshot_special_cleanup.yml @@ -18,7 +18,7 @@ set_fact: filtered_snapshots: [] - - name: Loop through snapshots and add snapshots with label "TEST" and type "USER" to filtered_snapshots + - name: Loop through snapshots and add snapshots with label 'TEST' and type 'USER' to filtered_snapshots set_fact: filtered_snapshots: "{{ filtered_snapshots + [ item ] }}" when: "{{ item.label == 'TEST' and item.type == 'USER' }}" @@ -32,7 +32,7 @@ # We could reuse "filtered_snapshots" here instead of "snapshot_results" and avoid the "when" statement. # But leaving it as is for example purposes. # Since this is the only mandatory task of the playbook, can be copy-pasted and reused as standalone task. - - name: Loop through list of snapshots delete if label is "TEST" and type is "USER" + - name: Loop through list of snapshots delete if label is 'TEST' and type is 'USER' scale_computing.hypercore.vm_snapshot: vm_name: "{{ item.vm.name }}" label: "{{ item.label }}" @@ -48,13 +48,13 @@ set_fact: filtered_snapshots: [] - - name: Loop through snapshots and add snapshots with label "TEST" and type "USER" to filtered_snapshots - second time + - name: Loop through snapshots and add snapshots with label 'TEST' and type 'USER' to filtered_snapshots - second time set_fact: filtered_snapshots: "{{ filtered_snapshots + [ item ] }}" when: "{{ item.label == 'TEST' and item.type == 'USER' }}" loop: "{{ snapshot_results.records }}" no_log: true - - name: Show only snapshots with label "TEST" and type "USER" - second time + - name: Show only snapshots with label 'TEST' and type 'USER' - second time ansible.builtin.debug: var: filtered_snapshots From 04a1e75f8fd389d2f1cbb7cb2d0d8cec5e0d44a4 Mon Sep 17 00:00:00 2001 From: Domen Date: Mon, 15 May 2023 14:37:59 +0200 Subject: [PATCH 04/12] CR fixes --- ...vm_snapshot_removal_based_on_timestamp.yml | 17 ++++--- examples/vm_snapshot_special_cleanup.yml | 26 +++++----- plugins/modules/vm_snapshot.py | 51 +++++++++++++++---- .../unit/plugins/modules/test_vm_snapshot.py | 3 +- 4 files changed, 64 insertions(+), 33 deletions(-) diff --git a/examples/vm_snapshot_removal_based_on_timestamp.yml b/examples/vm_snapshot_removal_based_on_timestamp.yml index d0993b490..9ab7a74b5 100644 --- a/examples/vm_snapshot_removal_based_on_timestamp.yml +++ b/examples/vm_snapshot_removal_based_on_timestamp.yml @@ -4,13 +4,14 @@ connection: local gather_facts: false environment: - SC_HOST: "your_host" - SC_USERNAME: "your_username" - SC_PASSWORD: "your_password" + SC_HOST: "https://10.5.11.50" + SC_USERNAME: "xlab" + SC_PASSWORD: "xlab2022" vars: # Format: 'YYYY-MM-DD hh:mm:ss' # All snapshots older than this date will be deleted. - use_date: '2023-05-03 12:52:00' + # use_date timezone should match the Scale cluster timezone + use_date: '1999-05-03 12:52:00' tasks: # ------------------------------------------------------ @@ -33,7 +34,7 @@ - name: Loop through snapshots and add snapshots that are older than 'use_date' set_fact: filtered_snapshots: "{{ filtered_snapshots + [ item ] }}" - when: "{{ item.timestamp > epoch_timestamp | int }}" + when: "{{ item.timestamp < epoch_timestamp | int }}" loop: "{{ snapshot_results.records }}" no_log: true @@ -47,9 +48,9 @@ - name: Loop through list of snapshots and delete all older than the 'use_date' scale_computing.hypercore.vm_snapshot: vm_name: "{{ item.vm.name }}" - label: "{{ item.label }}" + uuid: "{{ item.snapshot_uuid }}" state: absent - when: "{{ item.timestamp > epoch_timestamp | int }}" + when: "{{ item.timestamp < epoch_timestamp | int }}" loop: "{{ snapshot_results.records }}" - name: Create filtered_snapshots list - second time @@ -59,7 +60,7 @@ - name: Loop through snapshots and add snapshots that are older than 'use_date' - second time set_fact: filtered_snapshots: "{{ filtered_snapshots + [ item ] }}" - when: "{{ item.timestamp > epoch_timestamp | int }}" + when: "{{ item.timestamp < epoch_timestamp | int }}" loop: "{{ snapshot_results.records }}" no_log: true diff --git a/examples/vm_snapshot_special_cleanup.yml b/examples/vm_snapshot_special_cleanup.yml index fffdde4d1..c34bbca22 100644 --- a/examples/vm_snapshot_special_cleanup.yml +++ b/examples/vm_snapshot_special_cleanup.yml @@ -3,10 +3,10 @@ hosts: localhost connection: local gather_facts: false - environment: - SC_HOST: "your_host" - SC_USERNAME: "your_username" - SC_PASSWORD: "your_password" + vars: + # This variable is used to filter and delete snapshots. + # All snapshots with 'use_label' will be DELETED. + use_label: 'TEST' tasks: # ------------------------------------------------------ @@ -18,26 +18,26 @@ set_fact: filtered_snapshots: [] - - name: Loop through snapshots and add snapshots with label 'TEST' and type 'USER' to filtered_snapshots + - name: Loop through snapshots and add snapshots with use_label and type 'USER' to filtered_snapshots set_fact: filtered_snapshots: "{{ filtered_snapshots + [ item ] }}" - when: "{{ item.label == 'TEST' and item.type == 'USER' }}" + when: "{{ item.label == use_label and item.type == 'USER' }}" loop: "{{ snapshot_results.records }}" no_log: true - - name: Show only snapshots with label "TEST" and type "USER" + - name: Show only snapshots with use_label and type "USER" ansible.builtin.debug: var: filtered_snapshots # We could reuse "filtered_snapshots" here instead of "snapshot_results" and avoid the "when" statement. # But leaving it as is for example purposes. # Since this is the only mandatory task of the playbook, can be copy-pasted and reused as standalone task. - - name: Loop through list of snapshots delete if label is 'TEST' and type is 'USER' + - name: Loop through list of snapshots delete if label is use_label and type is 'USER' scale_computing.hypercore.vm_snapshot: vm_name: "{{ item.vm.name }}" - label: "{{ item.label }}" + uuid: "{{ item.snapshot_uuid }}" state: absent - when: "{{ item.label == 'TEST' and item.type == 'USER' }}" + when: "{{ item.label == use_label and item.type == 'USER' }}" loop: "{{ snapshot_results.records }}" - name: List all snapshots - second time @@ -48,13 +48,13 @@ set_fact: filtered_snapshots: [] - - name: Loop through snapshots and add snapshots with label 'TEST' and type 'USER' to filtered_snapshots - second time + - name: Loop through snapshots and add snapshots with use_label and type 'USER' to filtered_snapshots - second time set_fact: filtered_snapshots: "{{ filtered_snapshots + [ item ] }}" - when: "{{ item.label == 'TEST' and item.type == 'USER' }}" + when: "{{ item.label == use_label and item.type == 'USER' }}" loop: "{{ snapshot_results.records }}" no_log: true - - name: Show only snapshots with label 'TEST' and type 'USER' - second time + - name: Show only snapshots with use_label and type 'USER' - second time ansible.builtin.debug: var: filtered_snapshots diff --git a/plugins/modules/vm_snapshot.py b/plugins/modules/vm_snapshot.py index eba5269f5..7db0114ad 100644 --- a/plugins/modules/vm_snapshot.py +++ b/plugins/modules/vm_snapshot.py @@ -28,7 +28,6 @@ description: source VM name. label: type: str - required: true description: - Snapshot label, used as identificator in combination with vm_name. - Must be unique for a specific VM. @@ -49,6 +48,12 @@ choices: [ present, absent] type: str required: True + uuid: + type: str + description: + - Snapshot uuid, used as identificator. + - Can be used instead of label. + - Must be unique. """ @@ -145,6 +150,31 @@ from ..module_utils.vm import VM +def get_snapshot( + module: AnsibleModule, rest_client: RestClient, vm_object: VM +) -> List[TypedVMSnapshotToAnsible]: + # Get snapshot by uuid first if parameter exists. + if module.params["uuid"]: + snapshot_list = [ + VMSnapshot.get_snapshot_by_uuid( # type: ignore + module.params["uuid"], rest_client, must_exist=True + ).to_ansible() + ] + # Otherwise get by label + else: + snapshot_list = VMSnapshot.get_snapshots_by_query( + dict(label=module.params["label"], domainUUID=vm_object.uuid), rest_client + ) + + # Snapshot should be unique by this point. + if len(snapshot_list) > 1: + raise errors.ScaleComputingError( + f"Virtual machine - {module.params['vm_name']} - has more than one snapshot with label - {module.params['label']}, specify uuid instead." + ) + + return snapshot_list + + def ensure_present( module: AnsibleModule, rest_client: RestClient, @@ -203,15 +233,7 @@ def run( module: AnsibleModule, rest_client: RestClient ) -> Tuple[bool, Optional[TypedVMSnapshotToAnsible], TypedDiff]: vm_object: VM = VM.get_by_name(module.params, rest_client, must_exist=True) # type: ignore - snapshot_list = VMSnapshot.get_snapshots_by_query( - dict(label=module.params["label"], domainUUID=vm_object.uuid), rest_client - ) - - # VM should only have one snapshot with a specific label, we use vm_name and label as snapshot identificator. - if len(snapshot_list) > 1: - raise errors.ScaleComputingError( - f"Virtual machine - {module.params['vm_name']} - has more than one snapshot with label - {module.params['label']}." - ) + snapshot_list = get_snapshot(module, rest_client, vm_object) if module.params["state"] == State.present: return ensure_present(module, rest_client, vm_object, snapshot_list) @@ -237,7 +259,6 @@ def main() -> None: ), label=dict( type="str", - required=True, ), retain_for=dict( type="int", @@ -246,7 +267,15 @@ def main() -> None: type="bool", default=True, ), + uuid=dict( + type="str", + ), ), + mutually_exclusive=[("label", "uuid")], + required_if=[ + ("state", "absent", ("label", "uuid"), True), + ("state", "present", ["label"]), + ], ) try: diff --git a/tests/unit/plugins/modules/test_vm_snapshot.py b/tests/unit/plugins/modules/test_vm_snapshot.py index 002e469c7..92146e131 100644 --- a/tests/unit/plugins/modules/test_vm_snapshot.py +++ b/tests/unit/plugins/modules/test_vm_snapshot.py @@ -156,7 +156,7 @@ class TestRun: ), ], ) - def test_run_virtual_disk( + def test_run_vm_snapshot( self, create_module, rest_client, @@ -176,6 +176,7 @@ def test_run_virtual_disk( retain_for=30, replication=True, state=state, + uuid=None, ) ) From 3fb77c9ab64fd8fc4c0255baa2eb1165c01becb5 Mon Sep 17 00:00:00 2001 From: Domen Date: Mon, 15 May 2023 14:38:56 +0200 Subject: [PATCH 05/12] Removing env --- examples/vm_snapshot_removal_based_on_timestamp.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/examples/vm_snapshot_removal_based_on_timestamp.yml b/examples/vm_snapshot_removal_based_on_timestamp.yml index 9ab7a74b5..dcec3a4be 100644 --- a/examples/vm_snapshot_removal_based_on_timestamp.yml +++ b/examples/vm_snapshot_removal_based_on_timestamp.yml @@ -3,10 +3,6 @@ hosts: localhost connection: local gather_facts: false - environment: - SC_HOST: "https://10.5.11.50" - SC_USERNAME: "xlab" - SC_PASSWORD: "xlab2022" vars: # Format: 'YYYY-MM-DD hh:mm:ss' # All snapshots older than this date will be deleted. From d0bb96b3486ceac78667388d60dafe96f1b267e0 Mon Sep 17 00:00:00 2001 From: Domen Date: Mon, 15 May 2023 14:46:53 +0200 Subject: [PATCH 06/12] sanity fix --- examples/vm_snapshot_removal_based_on_timestamp.yml | 6 +++--- examples/vm_snapshot_special_cleanup.yml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/vm_snapshot_removal_based_on_timestamp.yml b/examples/vm_snapshot_removal_based_on_timestamp.yml index dcec3a4be..1846d6ae9 100644 --- a/examples/vm_snapshot_removal_based_on_timestamp.yml +++ b/examples/vm_snapshot_removal_based_on_timestamp.yml @@ -30,7 +30,7 @@ - name: Loop through snapshots and add snapshots that are older than 'use_date' set_fact: filtered_snapshots: "{{ filtered_snapshots + [ item ] }}" - when: "{{ item.timestamp < epoch_timestamp | int }}" + when: item.timestamp < epoch_timestamp | int loop: "{{ snapshot_results.records }}" no_log: true @@ -46,7 +46,7 @@ vm_name: "{{ item.vm.name }}" uuid: "{{ item.snapshot_uuid }}" state: absent - when: "{{ item.timestamp < epoch_timestamp | int }}" + when: item.timestamp < epoch_timestamp | int loop: "{{ snapshot_results.records }}" - name: Create filtered_snapshots list - second time @@ -56,7 +56,7 @@ - name: Loop through snapshots and add snapshots that are older than 'use_date' - second time set_fact: filtered_snapshots: "{{ filtered_snapshots + [ item ] }}" - when: "{{ item.timestamp < epoch_timestamp | int }}" + when: item.timestamp < epoch_timestamp | int loop: "{{ snapshot_results.records }}" no_log: true diff --git a/examples/vm_snapshot_special_cleanup.yml b/examples/vm_snapshot_special_cleanup.yml index c34bbca22..f6aab0a3a 100644 --- a/examples/vm_snapshot_special_cleanup.yml +++ b/examples/vm_snapshot_special_cleanup.yml @@ -21,7 +21,7 @@ - name: Loop through snapshots and add snapshots with use_label and type 'USER' to filtered_snapshots set_fact: filtered_snapshots: "{{ filtered_snapshots + [ item ] }}" - when: "{{ item.label == use_label and item.type == 'USER' }}" + when: item.label == use_label and item.type == 'USER' loop: "{{ snapshot_results.records }}" no_log: true @@ -37,7 +37,7 @@ vm_name: "{{ item.vm.name }}" uuid: "{{ item.snapshot_uuid }}" state: absent - when: "{{ item.label == use_label and item.type == 'USER' }}" + when: item.label == use_label and item.type == 'USER' loop: "{{ snapshot_results.records }}" - name: List all snapshots - second time @@ -51,7 +51,7 @@ - name: Loop through snapshots and add snapshots with use_label and type 'USER' to filtered_snapshots - second time set_fact: filtered_snapshots: "{{ filtered_snapshots + [ item ] }}" - when: "{{ item.label == use_label and item.type == 'USER' }}" + when: item.label == use_label and item.type == 'USER' loop: "{{ snapshot_results.records }}" no_log: true From 8830c5299b1db5af93c8bc817588429e4a0b4d51 Mon Sep 17 00:00:00 2001 From: Domen Date: Mon, 15 May 2023 14:56:16 +0200 Subject: [PATCH 07/12] sanity fixes --- examples/vm_snapshot_removal_based_on_timestamp.yml | 4 ++-- examples/vm_snapshot_special_cleanup.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/vm_snapshot_removal_based_on_timestamp.yml b/examples/vm_snapshot_removal_based_on_timestamp.yml index 1846d6ae9..aea8b762c 100644 --- a/examples/vm_snapshot_removal_based_on_timestamp.yml +++ b/examples/vm_snapshot_removal_based_on_timestamp.yml @@ -30,7 +30,7 @@ - name: Loop through snapshots and add snapshots that are older than 'use_date' set_fact: filtered_snapshots: "{{ filtered_snapshots + [ item ] }}" - when: item.timestamp < epoch_timestamp | int + when: item.timestamp < epoch_timestamp | int loop: "{{ snapshot_results.records }}" no_log: true @@ -56,7 +56,7 @@ - name: Loop through snapshots and add snapshots that are older than 'use_date' - second time set_fact: filtered_snapshots: "{{ filtered_snapshots + [ item ] }}" - when: item.timestamp < epoch_timestamp | int + when: item.timestamp < epoch_timestamp | int loop: "{{ snapshot_results.records }}" no_log: true diff --git a/examples/vm_snapshot_special_cleanup.yml b/examples/vm_snapshot_special_cleanup.yml index f6aab0a3a..b6368c243 100644 --- a/examples/vm_snapshot_special_cleanup.yml +++ b/examples/vm_snapshot_special_cleanup.yml @@ -21,7 +21,7 @@ - name: Loop through snapshots and add snapshots with use_label and type 'USER' to filtered_snapshots set_fact: filtered_snapshots: "{{ filtered_snapshots + [ item ] }}" - when: item.label == use_label and item.type == 'USER' + when: item.label == use_label and item.type == 'USER' loop: "{{ snapshot_results.records }}" no_log: true @@ -51,7 +51,7 @@ - name: Loop through snapshots and add snapshots with use_label and type 'USER' to filtered_snapshots - second time set_fact: filtered_snapshots: "{{ filtered_snapshots + [ item ] }}" - when: item.label == use_label and item.type == 'USER' + when: item.label == use_label and item.type == 'USER' loop: "{{ snapshot_results.records }}" no_log: true From 9d24194b1ac8caaf7833522cf757d96bc7c6cd2f Mon Sep 17 00:00:00 2001 From: Domen Date: Mon, 15 May 2023 15:03:27 +0200 Subject: [PATCH 08/12] sanity fix --- examples/vm_snapshot_removal_based_on_timestamp.yml | 4 ++-- examples/vm_snapshot_special_cleanup.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/vm_snapshot_removal_based_on_timestamp.yml b/examples/vm_snapshot_removal_based_on_timestamp.yml index aea8b762c..8d1aaedc6 100644 --- a/examples/vm_snapshot_removal_based_on_timestamp.yml +++ b/examples/vm_snapshot_removal_based_on_timestamp.yml @@ -29,7 +29,7 @@ - name: Loop through snapshots and add snapshots that are older than 'use_date' set_fact: - filtered_snapshots: "{{ filtered_snapshots + [ item ] }}" + filtered_snapshots: "{{ filtered_snapshots + [item] }}" when: item.timestamp < epoch_timestamp | int loop: "{{ snapshot_results.records }}" no_log: true @@ -55,7 +55,7 @@ - name: Loop through snapshots and add snapshots that are older than 'use_date' - second time set_fact: - filtered_snapshots: "{{ filtered_snapshots + [ item ] }}" + filtered_snapshots: "{{ filtered_snapshots + [item] }}" when: item.timestamp < epoch_timestamp | int loop: "{{ snapshot_results.records }}" no_log: true diff --git a/examples/vm_snapshot_special_cleanup.yml b/examples/vm_snapshot_special_cleanup.yml index b6368c243..f43b0e631 100644 --- a/examples/vm_snapshot_special_cleanup.yml +++ b/examples/vm_snapshot_special_cleanup.yml @@ -20,7 +20,7 @@ - name: Loop through snapshots and add snapshots with use_label and type 'USER' to filtered_snapshots set_fact: - filtered_snapshots: "{{ filtered_snapshots + [ item ] }}" + filtered_snapshots: "{{ filtered_snapshots + [item] }}" when: item.label == use_label and item.type == 'USER' loop: "{{ snapshot_results.records }}" no_log: true @@ -50,7 +50,7 @@ - name: Loop through snapshots and add snapshots with use_label and type 'USER' to filtered_snapshots - second time set_fact: - filtered_snapshots: "{{ filtered_snapshots + [ item ] }}" + filtered_snapshots: "{{ filtered_snapshots + [item] }}" when: item.label == use_label and item.type == 'USER' loop: "{{ snapshot_results.records }}" no_log: true From aa4d7489ac5e5ace1ddc45132bddcc036b996619 Mon Sep 17 00:00:00 2001 From: Domen Date: Mon, 15 May 2023 15:14:54 +0200 Subject: [PATCH 09/12] sanity fix --- examples/vm_snapshot_removal_based_on_timestamp.yml | 10 +++++----- examples/vm_snapshot_special_cleanup.yml | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/vm_snapshot_removal_based_on_timestamp.yml b/examples/vm_snapshot_removal_based_on_timestamp.yml index 8d1aaedc6..2675f0e87 100644 --- a/examples/vm_snapshot_removal_based_on_timestamp.yml +++ b/examples/vm_snapshot_removal_based_on_timestamp.yml @@ -16,7 +16,7 @@ register: snapshot_results - name: Convert date to unix timestamp 'epoch' - set_fact: + ansible.builtin.set_fact: epoch_timestamp: "{{ (use_date | to_datetime).strftime('%s') }}" - name: Show epoch_timestamp @@ -24,11 +24,11 @@ var: epoch_timestamp - name: Create filtered_snapshots list - set_fact: + ansible.builtin.set_fact: filtered_snapshots: [] - name: Loop through snapshots and add snapshots that are older than 'use_date' - set_fact: + ansible.builtin.set_fact: filtered_snapshots: "{{ filtered_snapshots + [item] }}" when: item.timestamp < epoch_timestamp | int loop: "{{ snapshot_results.records }}" @@ -50,11 +50,11 @@ loop: "{{ snapshot_results.records }}" - name: Create filtered_snapshots list - second time - set_fact: + ansible.builtin.set_fact: filtered_snapshots: [] - name: Loop through snapshots and add snapshots that are older than 'use_date' - second time - set_fact: + ansible.builtin.set_fact: filtered_snapshots: "{{ filtered_snapshots + [item] }}" when: item.timestamp < epoch_timestamp | int loop: "{{ snapshot_results.records }}" diff --git a/examples/vm_snapshot_special_cleanup.yml b/examples/vm_snapshot_special_cleanup.yml index f43b0e631..ce1637b3e 100644 --- a/examples/vm_snapshot_special_cleanup.yml +++ b/examples/vm_snapshot_special_cleanup.yml @@ -15,11 +15,11 @@ register: snapshot_results - name: Create filtered_snapshots list - set_fact: + ansible.builtin.set_fact: filtered_snapshots: [] - name: Loop through snapshots and add snapshots with use_label and type 'USER' to filtered_snapshots - set_fact: + ansible.builtin.set_fact: filtered_snapshots: "{{ filtered_snapshots + [item] }}" when: item.label == use_label and item.type == 'USER' loop: "{{ snapshot_results.records }}" @@ -45,11 +45,11 @@ register: snapshot_results - name: Create filtered_snapshots list - second time - set_fact: + ansible.builtin.set_fact: filtered_snapshots: [] - name: Loop through snapshots and add snapshots with use_label and type 'USER' to filtered_snapshots - second time - set_fact: + ansible.builtin.set_fact: filtered_snapshots: "{{ filtered_snapshots + [item] }}" when: item.label == use_label and item.type == 'USER' loop: "{{ snapshot_results.records }}" From 713257657ea06295460b2329b6f987680c28a200 Mon Sep 17 00:00:00 2001 From: Domen Date: Wed, 17 May 2023 15:34:20 +0200 Subject: [PATCH 10/12] Extending integration tests for vm_snapshot --- plugins/module_utils/vm_snapshot.py | 3 +- ...2_vm_snapshot.yml => 02_1_vm_snapshot.yml} | 0 .../tasks/02_2_vm_snapshot_uuid.yml | 220 ++++++++++++++++++ .../targets/vm_snapshot/tasks/main.yml | 4 +- 4 files changed, 224 insertions(+), 3 deletions(-) rename tests/integration/targets/vm_snapshot/tasks/{02_vm_snapshot.yml => 02_1_vm_snapshot.yml} (100%) create mode 100644 tests/integration/targets/vm_snapshot/tasks/02_2_vm_snapshot_uuid.yml diff --git a/plugins/module_utils/vm_snapshot.py b/plugins/module_utils/vm_snapshot.py index 4af0b7fa9..9dd267d8e 100644 --- a/plugins/module_utils/vm_snapshot.py +++ b/plugins/module_utils/vm_snapshot.py @@ -226,8 +226,7 @@ def get_snapshot_by_uuid( cls, snapshot_uuid: str, rest_client: RestClient, must_exist: bool = False ) -> Optional[VMSnapshot]: hypercore_dict = rest_client.get_record( - endpoint="/rest/v1/VirDomainSnapshot", - query={"uuid": snapshot_uuid}, + endpoint=f"/rest/v1/VirDomainSnapshot/{snapshot_uuid}", must_exist=must_exist, ) vm_snapshot = cls.from_hypercore(hypercore_dict) diff --git a/tests/integration/targets/vm_snapshot/tasks/02_vm_snapshot.yml b/tests/integration/targets/vm_snapshot/tasks/02_1_vm_snapshot.yml similarity index 100% rename from tests/integration/targets/vm_snapshot/tasks/02_vm_snapshot.yml rename to tests/integration/targets/vm_snapshot/tasks/02_1_vm_snapshot.yml diff --git a/tests/integration/targets/vm_snapshot/tasks/02_2_vm_snapshot_uuid.yml b/tests/integration/targets/vm_snapshot/tasks/02_2_vm_snapshot_uuid.yml new file mode 100644 index 000000000..bd239d16f --- /dev/null +++ b/tests/integration/targets/vm_snapshot/tasks/02_2_vm_snapshot_uuid.yml @@ -0,0 +1,220 @@ +# ----------------------------------Cleanup------------------------------------------------------------------------ +- name: Delete XLAB-snapshot-uuid-test + scale_computing.hypercore.vm: &delete-XLAB-snapshot-test + vm_name: "{{ item }}" + state: absent + loop: + - XLAB-snapshot-uuid-test + +# ----------------------------------Setup----------------------------------------------------------------------------- +- name: Create XLAB-snapshot-uuid-test + scale_computing.hypercore.api: + action: post + endpoint: /rest/v1/VirDomain + data: + dom: + name: XLAB-snapshot-uuid-test + tags: Xlab,CI,test,vm_snapshots + mem: 511705088 + numVCPU: 2 + blockDevs: + - type: VIRTIO_DISK + capacity: 8100100100 + name: jc1-disk-0 + netDevs: + - type: RTL8139 + vlan: 0 + connected: true + options: + attachGuestToolsISO: False + register: vm_created +- ansible.builtin.assert: + that: + - vm_created is succeeded + - vm_created is changed + +- name: Wait for the VM to be created + scale_computing.hypercore.task_wait: + task_tag: "{{ vm_created.record }}" + +# ----------------------------------Job------------------------------------------------------------------------------------- +# Test module input parameters with present (mutually exclusive uuid and label) +- name: Create snapshot of VM after create using label and uuid - must fail + scale_computing.hypercore.vm_snapshot: + state: present + vm_name: XLAB-snapshot-uuid-test + label: test-snapshot-integration + uuid: some-uuid + replication: true + register: snapshot_created + failed_when: snapshot_created is not failed +- ansible.builtin.assert: + that: + - snapshot_created is not changed + - snapshot_created.msg == "parameters are mutually exclusive: label|uuid" + +- name: Create snapshot of VM after create using uuid - must fail + scale_computing.hypercore.vm_snapshot: + state: present + vm_name: XLAB-snapshot-uuid-test + uuid: some-uuid + replication: true + register: snapshot_created + failed_when: snapshot_created is not failed +- ansible.builtin.assert: + that: + - snapshot_created is not changed + - snapshot_created.msg == "state is present but all of the following are missing: label" + +- name: Create snapshot of VM after create - this time succeed + scale_computing.hypercore.vm_snapshot: + state: present + vm_name: XLAB-snapshot-uuid-test + label: test-snapshot-integration + replication: true + register: snapshot_created +- ansible.builtin.assert: + that: + - snapshot_created is succeeded + - snapshot_created is changed + - snapshot_created.record.vm.name == "XLAB-snapshot-uuid-test" + - snapshot_created.record.label == "test-snapshot-integration" + - snapshot_created.record.replication is true + +- name: Create snapshot of VM after create - this time succeed - idempotence + scale_computing.hypercore.vm_snapshot: + state: present + vm_name: XLAB-snapshot-uuid-test + label: test-snapshot-integration + replication: true + register: snapshot_created +- ansible.builtin.assert: + that: + - snapshot_created is succeeded + - snapshot_created is not changed + - snapshot_created.record.vm.name == "XLAB-snapshot-uuid-test" + - snapshot_created.record.label == "test-snapshot-integration" + - snapshot_created.record.replication is true + +- name: Get snapshot info after create - assert it was created once + scale_computing.hypercore.vm_snapshot_info: + vm_name: XLAB-snapshot-uuid-test + label: test-snapshot-integration + register: snapshot_info +- ansible.builtin.assert: + that: + - snapshot_info is succeeded + - snapshot_info is not changed + - snapshot_info.records | length == 1 + - snapshot_created.record == snapshot_info.records.0 + +# We can have multiple snapshots with same label. +# vm_snapshot module has constraints but API does not. +- name: Create another snapshot with label 'test-snapshot-integration' with API + scale_computing.hypercore.api: + action: post + endpoint: /rest/v1/VirDomainSnapshot + data: + domainUUID: "{{ vm_created.record.createdUUID }}" + label: test-snapshot-integration + type: USER + register: snapshot_created_api +- ansible.builtin.assert: + that: + - snapshot_created_api is succeeded + - snapshot_created_api is changed + +- name: Wait for the snapshot to crate + scale_computing.hypercore.task_wait: + task_tag: "{{ snapshot_created_api.record }}" + +- name: Get snapshot info after API create - assert there are two snapshot with same label + scale_computing.hypercore.vm_snapshot_info: + vm_name: XLAB-snapshot-uuid-test + label: test-snapshot-integration + register: snapshot_info +- ansible.builtin.assert: + that: + - snapshot_info is succeeded + - snapshot_info is not changed + - snapshot_info.records | length == 2 + +#------------------------------- Test vm_snapshot with absent when snapshots have the same label ------------------------------- +# Here we pass both label and uuid, but they are mutually exclusive. +- name: Delete snapshot of VM when both label and uuid are passed - must fail + scale_computing.hypercore.vm_snapshot: + state: absent + vm_name: XLAB-snapshot-uuid-test + label: test-snapshot-integration + uuid: some-uuid + register: snapshot_deleted + failed_when: snapshot_deleted is not failed +- ansible.builtin.assert: + that: + - snapshot_deleted is succeeded + - snapshot_deleted is not changed + - snapshot_deleted.msg == "parameters are mutually exclusive: label|uuid" + +# Here we pass only label as parameter. +- name: Delete snapshot of VM when labels are the same, using label as parameter - must fail + scale_computing.hypercore.vm_snapshot: + state: absent + vm_name: XLAB-snapshot-uuid-test + label: test-snapshot-integration + register: snapshot_deleted + failed_when: snapshot_deleted is not failed +- ansible.builtin.assert: + that: + - snapshot_deleted is succeeded + - snapshot_deleted is not changed + - snapshot_deleted.msg == "Virtual machine - XLAB-snapshot-uuid-test - has more than one snapshot with label - test-snapshot-integration, specify uuid instead." + +- name: Delete snapshot of VM with uuid + scale_computing.hypercore.vm_snapshot: + state: absent + vm_name: XLAB-snapshot-uuid-test + uuid: "{{ snapshot_created_api.record.createdUUID }}" + register: snapshot_deleted +- ansible.builtin.assert: + that: + - snapshot_deleted is succeeded + - snapshot_deleted is changed + +- name: Get snapshot info after delete - assert delete happened + scale_computing.hypercore.vm_snapshot_info: + vm_name: XLAB-snapshot-uuid-test + label: test-snapshot-integration + register: snapshot_info +- ansible.builtin.assert: + that: + - snapshot_info is succeeded + - snapshot_info is not changed + - snapshot_info.records | length == 1 + - snapshot_info.records.0.snapshot_uuid != snapshot_created_api.record.createdUUID + +- name: Delete snapshot of VM with label + scale_computing.hypercore.vm_snapshot: + state: absent + vm_name: XLAB-snapshot-uuid-test + label: test-snapshot-integration + register: snapshot_deleted +- ansible.builtin.assert: + that: + - snapshot_deleted is succeeded + - snapshot_deleted is changed + +- name: Get snapshot info after second delete - assert delete happened + scale_computing.hypercore.vm_snapshot_info: + vm_name: XLAB-snapshot-uuid-test + label: test-snapshot-integration + register: snapshot_info +- ansible.builtin.assert: + that: + - snapshot_info is succeeded + - snapshot_info is not changed + - snapshot_info.records | length == 0 + +- name: Delete XLAB-snapshot-test + scale_computing.hypercore.vm: *delete-XLAB-snapshot-test + loop: + - XLAB-snapshot-uuid-test diff --git a/tests/integration/targets/vm_snapshot/tasks/main.yml b/tests/integration/targets/vm_snapshot/tasks/main.yml index eb97a46a8..5e45b646d 100644 --- a/tests/integration/targets/vm_snapshot/tasks/main.yml +++ b/tests/integration/targets/vm_snapshot/tasks/main.yml @@ -18,7 +18,9 @@ vars: test_vms_number: "{{ number_of_snapshot_testing_vms }}" - - include_tasks: 02_vm_snapshot.yml + - include_tasks: 02_1_vm_snapshot.yml + + - include_tasks: 02_2_vm_snapshot_uuid.yml - include_tasks: 03_vm_snapshot_attach_disk.yml vars: From b2341720b923917d9667451f2e581a211ccfed9c Mon Sep 17 00:00:00 2001 From: Domen Date: Thu, 18 May 2023 14:16:24 +0200 Subject: [PATCH 11/12] extending integration tests --- plugins/modules/vm_snapshot.py | 8 +- .../tasks/02_2_vm_snapshot_uuid.yml | 98 +++++++++++++++++++ 2 files changed, 101 insertions(+), 5 deletions(-) diff --git a/plugins/modules/vm_snapshot.py b/plugins/modules/vm_snapshot.py index 7db0114ad..b6181676e 100644 --- a/plugins/modules/vm_snapshot.py +++ b/plugins/modules/vm_snapshot.py @@ -155,11 +155,9 @@ def get_snapshot( ) -> List[TypedVMSnapshotToAnsible]: # Get snapshot by uuid first if parameter exists. if module.params["uuid"]: - snapshot_list = [ - VMSnapshot.get_snapshot_by_uuid( # type: ignore - module.params["uuid"], rest_client, must_exist=True - ).to_ansible() - ] + snapshot_list = VMSnapshot.get_snapshots_by_query( + dict(uuid=module.params["uuid"], domainUUID=vm_object.uuid), rest_client + ) # Otherwise get by label else: snapshot_list = VMSnapshot.get_snapshots_by_query( diff --git a/tests/integration/targets/vm_snapshot/tasks/02_2_vm_snapshot_uuid.yml b/tests/integration/targets/vm_snapshot/tasks/02_2_vm_snapshot_uuid.yml index bd239d16f..501ea0f41 100644 --- a/tests/integration/targets/vm_snapshot/tasks/02_2_vm_snapshot_uuid.yml +++ b/tests/integration/targets/vm_snapshot/tasks/02_2_vm_snapshot_uuid.yml @@ -5,6 +5,7 @@ state: absent loop: - XLAB-snapshot-uuid-test + - XLAB-snapshot-uuid-test-2 # ----------------------------------Setup----------------------------------------------------------------------------- - name: Create XLAB-snapshot-uuid-test @@ -37,6 +38,36 @@ scale_computing.hypercore.task_wait: task_tag: "{{ vm_created.record }}" +- name: Create XLAB-snapshot-uuid-test-2 + scale_computing.hypercore.api: + action: post + endpoint: /rest/v1/VirDomain + data: + dom: + name: XLAB-snapshot-uuid-test-2 + tags: Xlab,CI,test,vm_snapshots + mem: 511705088 + numVCPU: 2 + blockDevs: + - type: VIRTIO_DISK + capacity: 8100100100 + name: jc1-disk-0 + netDevs: + - type: RTL8139 + vlan: 0 + connected: true + options: + attachGuestToolsISO: False + register: vm_created_2 +- ansible.builtin.assert: + that: + - vm_created_2 is succeeded + - vm_created_2 is changed + +- name: Wait for the VM-2 to be created + scale_computing.hypercore.task_wait: + task_tag: "{{ vm_created_2.record }}" + # ----------------------------------Job------------------------------------------------------------------------------------- # Test module input parameters with present (mutually exclusive uuid and label) - name: Create snapshot of VM after create using label and uuid - must fail @@ -108,6 +139,48 @@ - snapshot_info.records | length == 1 - snapshot_created.record == snapshot_info.records.0 +- name: Create snapshot of VM-2 after create + scale_computing.hypercore.vm_snapshot: + state: present + vm_name: XLAB-snapshot-uuid-test-2 + label: test-snapshot-integration + replication: true + register: snapshot_created +- ansible.builtin.assert: + that: + - snapshot_created is succeeded + - snapshot_created is changed + - snapshot_created.record.vm.name == "XLAB-snapshot-uuid-test-2" + - snapshot_created.record.label == "test-snapshot-integration" + - snapshot_created.record.replication is true + +- name: Create snapshot of VM-2 after create - idempotence + scale_computing.hypercore.vm_snapshot: + state: present + vm_name: XLAB-snapshot-uuid-test-2 + label: test-snapshot-integration + replication: true + register: snapshot_created +- ansible.builtin.assert: + that: + - snapshot_created is succeeded + - snapshot_created is not changed + - snapshot_created.record.vm.name == "XLAB-snapshot-uuid-test-2" + - snapshot_created.record.label == "test-snapshot-integration" + - snapshot_created.record.replication is true + +- name: Get snapshot info after create - assert it was created once + scale_computing.hypercore.vm_snapshot_info: + vm_name: XLAB-snapshot-uuid-test-2 + label: test-snapshot-integration + register: snapshot_info +- ansible.builtin.assert: + that: + - snapshot_info is succeeded + - snapshot_info is not changed + - snapshot_info.records | length == 1 + - snapshot_created.record == snapshot_info.records.0 + # We can have multiple snapshots with same label. # vm_snapshot module has constraints but API does not. - name: Create another snapshot with label 'test-snapshot-integration' with API @@ -140,6 +213,30 @@ - snapshot_info.records | length == 2 #------------------------------- Test vm_snapshot with absent when snapshots have the same label ------------------------------- +- name: Get snapshot info from VM-2 + scale_computing.hypercore.vm_snapshot_info: + vm_name: XLAB-snapshot-uuid-test-2 + label: test-snapshot-integration + register: snapshot_info +- ansible.builtin.assert: + that: + - snapshot_info is succeeded + - snapshot_info is not changed + - snapshot_info.records | length == 1 + +# Here we try to delete snapshot that doesn't belong to the specified VM +- name: Delete snapshot from VM-2 using VM-1 - Must be not changed + scale_computing.hypercore.vm_snapshot: + state: absent + vm_name: XLAB-snapshot-uuid-test + uuid: "{{ snapshot_info.records.0.snapshot_uuid }}" + register: snapshot_deleted + failed_when: snapshot_deleted is changed +- ansible.builtin.assert: + that: + - snapshot_deleted is succeeded + - snapshot_deleted is not changed + # Here we pass both label and uuid, but they are mutually exclusive. - name: Delete snapshot of VM when both label and uuid are passed - must fail scale_computing.hypercore.vm_snapshot: @@ -218,3 +315,4 @@ scale_computing.hypercore.vm: *delete-XLAB-snapshot-test loop: - XLAB-snapshot-uuid-test + - XLAB-snapshot-uuid-test-2 From e30bb4a44d4c143bb74e57cd06e8f1035397891e Mon Sep 17 00:00:00 2001 From: Domen Dobnikar <113340617+domendobnikar@users.noreply.github.com> Date: Thu, 18 May 2023 14:46:11 +0200 Subject: [PATCH 12/12] Update 02_2_vm_snapshot_uuid.yml --- .../vm_snapshot/tasks/02_2_vm_snapshot_uuid.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/integration/targets/vm_snapshot/tasks/02_2_vm_snapshot_uuid.yml b/tests/integration/targets/vm_snapshot/tasks/02_2_vm_snapshot_uuid.yml index 501ea0f41..cbb7c13e1 100644 --- a/tests/integration/targets/vm_snapshot/tasks/02_2_vm_snapshot_uuid.yml +++ b/tests/integration/targets/vm_snapshot/tasks/02_2_vm_snapshot_uuid.yml @@ -237,6 +237,17 @@ - snapshot_deleted is succeeded - snapshot_deleted is not changed +- name: Assert that snapshot was NOT deleted + scale_computing.hypercore.vm_snapshot_info: + vm_name: XLAB-snapshot-uuid-test-2 + label: test-snapshot-integration + register: snapshot_info +- ansible.builtin.assert: + that: + - snapshot_info is succeeded + - snapshot_info is not changed + - snapshot_info.records | length == 1 + # Here we pass both label and uuid, but they are mutually exclusive. - name: Delete snapshot of VM when both label and uuid are passed - must fail scale_computing.hypercore.vm_snapshot: