From 0035d6c6fcd3ff9ebf7f214f93dbeaa82391716e Mon Sep 17 00:00:00 2001 From: anna-savina Date: Thu, 2 Jan 2025 15:40:09 +0200 Subject: [PATCH] added test for vcenter_vm_guest_filesystem_directories module --- tests/integration/targets/group_vars.yml | 2 + .../defaults/main.yml | 8 + .../playbook.yml | 9 + .../tasks/main.yml | 181 ++++++++++++++++++ 4 files changed, 200 insertions(+) create mode 100644 tests/integration/targets/vmware_rest_vcenter_vm_guest_filesystem_directories/defaults/main.yml create mode 100644 tests/integration/targets/vmware_rest_vcenter_vm_guest_filesystem_directories/playbook.yml create mode 100644 tests/integration/targets/vmware_rest_vcenter_vm_guest_filesystem_directories/tasks/main.yml diff --git a/tests/integration/targets/group_vars.yml b/tests/integration/targets/group_vars.yml index e642e84d..89482660 100644 --- a/tests/integration/targets/group_vars.yml +++ b/tests/integration/targets/group_vars.yml @@ -17,3 +17,5 @@ vcenter_test_content_library: vcenter_test_vm_template: name: "test-vm-template" id: "009163b9-83aa-46ca-bf7c-07af4a916735" +vcenter_test_vm_user_name: root +vcenter_test_vm_user_password: redhat12345! diff --git a/tests/integration/targets/vmware_rest_vcenter_vm_guest_filesystem_directories/defaults/main.yml b/tests/integration/targets/vmware_rest_vcenter_vm_guest_filesystem_directories/defaults/main.yml new file mode 100644 index 00000000..5ce68526 --- /dev/null +++ b/tests/integration/targets/vmware_rest_vcenter_vm_guest_filesystem_directories/defaults/main.yml @@ -0,0 +1,8 @@ +--- +test_resource_pool_name: "{{ tiny_prefix }}-vm-dir-resource-pool" +test_vm_name: "{{ tiny_prefix }}-vm" +path_tmp: + dir: /tmp/test + new_dir: /tmp/new/ + no_dir: /tmp/no_dir + new_no_dir: /tmp/new_no_dir diff --git a/tests/integration/targets/vmware_rest_vcenter_vm_guest_filesystem_directories/playbook.yml b/tests/integration/targets/vmware_rest_vcenter_vm_guest_filesystem_directories/playbook.yml new file mode 100644 index 00000000..1db6a7f1 --- /dev/null +++ b/tests/integration/targets/vmware_rest_vcenter_vm_guest_filesystem_directories/playbook.yml @@ -0,0 +1,9 @@ +- hosts: localhost + gather_facts: no + + tasks: + - name: Import vmware_rest_vcenter_vm_guest_filesystem_directories test + ansible.builtin.import_role: + name: vmware_rest_vcenter_vm_guest_filesystem_directories + tags: + - eco-vcenter-ci diff --git a/tests/integration/targets/vmware_rest_vcenter_vm_guest_filesystem_directories/tasks/main.yml b/tests/integration/targets/vmware_rest_vcenter_vm_guest_filesystem_directories/tasks/main.yml new file mode 100644 index 00000000..4b586aeb --- /dev/null +++ b/tests/integration/targets/vmware_rest_vcenter_vm_guest_filesystem_directories/tasks/main.yml @@ -0,0 +1,181 @@ +--- +- name: Test vmware_rest_vm_guest_filesystem_directories module on a real vCenter + block: + - name: Import eco-vcenter common vars + ansible.builtin.include_vars: + file: ../group_vars.yml + tags: eco-vcenter-ci + + - name: Create VM from template + ansible.builtin.include_tasks: ../../action_on_vm/create_vm_from_template.yml + vars: + resource_pool_name: "{{ test_resource_pool_name }}" + resource_pool_parent_name: "{{ vcenter_resource_pool }}" + vm_name: "{{ test_vm_name }}" + + - name: Power on VM + vmware.vmware_rest.vcenter_vm_power: + state: start + vm: "{{ lookup('vmware.vmware_rest.vm_moid', test_vm_name) }}" + + - name: Wait until VM is ready + vmware.vmware_rest.vcenter_vm_tools_info: + vm: "{{ lookup('vmware.vmware_rest.vm_moid', test_vm_name) }}" + register: vm_tools_info + until: + - vm_tools_info is not failed + - vm_tools_info.value.run_state == "RUNNING" + retries: 60 + delay: 5 + + - name: Create a directory in /tmp + vmware.vmware_rest.vcenter_vm_guest_filesystem_directories: + vm: "{{ lookup('vmware.vmware_rest.vm_moid', test_vm_name) }}" + path: "{{ path_tmp.dir }}" + create_parents: true + credentials: + interactive_session: false + type: USERNAME_PASSWORD + user_name: "{{ vcenter_test_vm_user_name }}" + password: "{{ vcenter_test_vm_user_password }}" + register: vm_dir_info + + - name: Print debug info + ansible.builtin.debug: + var: vm_dir_info + + - name: Verify changed true + ansible.builtin.assert: + that: + - vm_dir_info.changed + + - name: Create directory with name duplication in /tmp + vmware.vmware_rest.vcenter_vm_guest_filesystem_directories: + vm: "{{ lookup('vmware.vmware_rest.vm_moid', test_vm_name) }}" + path: "{{ path_tmp.dir }}" + create_parents: true + credentials: + interactive_session: false + type: USERNAME_PASSWORD + user_name: "{{ vcenter_test_vm_user_name }}" + password: "{{ vcenter_test_vm_user_password }}" + register: vm_dir_info + + - name: Print debug info + ansible.builtin.debug: + var: vm_dir_info + + - name: Verify no changes + ansible.builtin.assert: + that: + - not vm_dir_info.changed + - vm_dir_info.value.error_type == "ALREADY_EXISTS" + + - name: Move directory in /tmp + vmware.vmware_rest.vcenter_vm_guest_filesystem_directories: + vm: "{{ lookup('vmware.vmware_rest.vm_moid', test_vm_name) }}" + path: "{{ path_tmp.dir }}" + new_path: "{{ path_tmp.new_dir }}" + create_parents: true + credentials: + interactive_session: false + type: USERNAME_PASSWORD + user_name: "{{ vcenter_test_vm_user_name }}" + password: "{{ vcenter_test_vm_user_password }}" + state: move + register: vm_dir_info + + - name: Print debug info + ansible.builtin.debug: + var: vm_dir_info + + - name: Verify changed true + ansible.builtin.assert: + that: + - vm_dir_info.changed + + - name: Create a directory in /tmp + vmware.vmware_rest.vcenter_vm_guest_filesystem_directories: + vm: "{{ lookup('vmware.vmware_rest.vm_moid', test_vm_name) }}" + path: "{{ path_tmp.dir }}" + create_parents: true + credentials: + interactive_session: false + type: USERNAME_PASSWORD + user_name: "{{ vcenter_test_vm_user_name }}" + password: "{{ vcenter_test_vm_user_password }}" + register: vm_dir_info + + - name: Print debug info + ansible.builtin.debug: + var: vm_dir_info + + - name: Verify changed true + ansible.builtin.assert: + that: + - vm_dir_info.changed + + - name: Create a temporary directory in /tmp + vmware.vmware_rest.vcenter_vm_guest_filesystem_directories: + vm: "{{ lookup('vmware.vmware_rest.vm_moid', test_vm_name) }}" + suffix: test + prefix: test + credentials: + interactive_session: false + type: USERNAME_PASSWORD + user_name: "{{ vcenter_test_vm_user_name }}" + password: "{{ vcenter_test_vm_user_password }}" + state: create_temporary + register: vm_dir_info_temp + + - name: Print debug info + ansible.builtin.debug: + var: vm_dir_info_temp + + - name: Verify changed true + ansible.builtin.assert: + that: + - vm_dir_info_temp.changed + - vm_dir_info_temp.value + + - name: Delete directories in /tmp + vmware.vmware_rest.vcenter_vm_guest_filesystem_directories: + vm: "{{ lookup('vmware.vmware_rest.vm_moid', test_vm_name) }}" + path: "{{ item }}" + credentials: + interactive_session: false + type: USERNAME_PASSWORD + user_name: "{{ vcenter_test_vm_user_name }}" + password: "{{ vcenter_test_vm_user_password }}" + state: absent + loop: + - "{{ path_tmp.dir }}" + - "{{ path_tmp.new_dir }}" + - "{{ path_tmp.no_dir }}" + - "{{ path_tmp.new_no_dir }}" + - "{{ vm_dir_info_temp.value }}" + register: vm_del_dir_info + + - name: Print debug info + ansible.builtin.debug: + var: vm_del_dir_info + + - name: Verify directories deletion + ansible.builtin.assert: + that: + - vm_del_dir_info.results[0].item == path_tmp.dir and vm_del_dir_info.results[0].changed + - vm_del_dir_info.results[1].item == path_tmp.new_dir and vm_del_dir_info.results[1].changed + - vm_del_dir_info.results[2].item == path_tmp.no_dir and not vm_del_dir_info.results[2].changed + - vm_del_dir_info.results[3].item == path_tmp.new_no_dir and not vm_del_dir_info.results[3].changed + - vm_del_dir_info.results[4].item == vm_dir_info_temp.value and vm_del_dir_info.results[4].changed + + always: + - name: Delete VM + ansible.builtin.include_tasks: ../../action_on_vm/delete_vm.yml + vars: + vm_id: "{{ lookup('vmware.vmware_rest.vm_moid', test_vm_name) }}" + + - name: Delete resource pool + vmware.vmware_rest.vcenter_resourcepool: + resource_pool: "{{ lookup('vmware.vmware_rest.resource_pool_moid', test_resource_pool_name) }}" + state: absent