Skip to content
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

Add integration test for vcenter_vm_guest_filesystem_directories module #578

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/integration/targets/group_vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Loading