Skip to content

Commit ec85f8c

Browse files
committed
Add first integration tests
1 parent 9d48694 commit ec85f8c

File tree

7 files changed

+276
-0
lines changed

7 files changed

+276
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cloud/vcenter
2+
needs/target/prepare_vmware_tests
3+
zuul/vmware/vcenter_1esxi
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
guest_test_playbooks:
2+
- boot_firmware_d1_c1_f0.yml
3+
- create_d1_c1_f0.yml
4+
- create_guest_invalid_d1_c1_f0.yml
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Test code for the guest module.
2+
# Copyright: (c) 2018, Abhijeet Kasurde <[email protected]>
3+
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4+
5+
- &create_test_vm1
6+
name: create new VMs with boot_firmware as 'bios'
7+
guest:
8+
validate_certs: false
9+
hostname: "{{ vcenter_hostname }}"
10+
username: "{{ vcenter_username }}"
11+
password: "{{ vcenter_password }}"
12+
name: test_vm1
13+
guest_id: centos64Guest
14+
datacenter: "{{ dc1 }}"
15+
hardware:
16+
num_cpus: 1
17+
boot_firmware: "bios"
18+
memory_mb: 128
19+
state: present
20+
folder: "{{ f0 }}"
21+
register: create_d1_c1_f0
22+
23+
- debug: var=create_d1_c1_f0
24+
25+
- name: assert that changes were made
26+
assert:
27+
that:
28+
- create_d1_c1_f0 is changed
29+
30+
- <<: *create_test_vm1
31+
name: create new VMs again with boot_firmware as 'bios'
32+
register: create_d1_c1_f0_again
33+
34+
- debug: var=create_d1_c1_f0_again
35+
36+
- name: assert that changes were not made
37+
assert:
38+
that:
39+
- create_d1_c1_f0_again is not changed
40+
41+
- &create_test_vm2
42+
name: create new VMs with boot_firmware as 'efi'
43+
guest:
44+
validate_certs: false
45+
hostname: "{{ vcenter_hostname }}"
46+
username: "{{ vcenter_username }}"
47+
password: "{{ vcenter_password }}"
48+
name: test_vm2
49+
guest_id: centos64Guest
50+
datacenter: "{{ dc1 }}"
51+
hardware:
52+
num_cpus: 1
53+
boot_firmware: "efi"
54+
memory_mb: 128
55+
state: present
56+
folder: "{{ f0 }}"
57+
register: create_d1_c1_f0
58+
59+
- debug: var=create_d1_c1_f0
60+
61+
- name: assert that changes were made
62+
assert:
63+
that:
64+
- create_d1_c1_f0 is changed
65+
66+
- <<: *create_test_vm2
67+
name: create new VMs again with boot_firmware as 'efi'
68+
register: create_d1_c1_f0_again
69+
70+
- debug: var=create_d1_c1_f0
71+
72+
- name: assert that changes were not made
73+
assert:
74+
that:
75+
- create_d1_c1_f0_again is not changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Test code for the guest module.
2+
# Copyright: (c) 2017, James Tanner <[email protected]>
3+
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4+
5+
- &create_test_vm1
6+
name: create new VM
7+
guest:
8+
validate_certs: false
9+
hostname: "{{ vcenter_hostname }}"
10+
username: "{{ vcenter_username }}"
11+
password: "{{ vcenter_password }}"
12+
name: test_vm1
13+
guest_id: centos64Guest
14+
datacenter: "{{ dc1 }}"
15+
hardware:
16+
num_cpus: 1
17+
num_cpu_cores_per_socket: 1
18+
memory_mb: 128
19+
hotadd_memory: true
20+
hotadd_cpu: false
21+
memory_reservation: 128
22+
memory_reservation_lock: false
23+
nested_virt: true
24+
hotremove_cpu: true
25+
mem_limit: 8096
26+
mem_reservation: 4096
27+
cpu_limit: 8096
28+
cpu_reservation: 4096
29+
max_connections: 10
30+
state: present
31+
folder: '{{ f0 }}'
32+
register: create_d1_c1_f0
33+
34+
- debug: var=create_d1_c1_f0
35+
36+
- name: assert that changes were made
37+
assert:
38+
that:
39+
- create_d1_c1_f0 is changed
40+
41+
- <<: *create_test_vm1
42+
name: create the VM again
43+
register: create_d1_c1_f0_again
44+
45+
- debug: var=create_d1_c1_f0_again
46+
47+
- name: assert that no changes were made after re-creating
48+
assert:
49+
that:
50+
- create_d1_c1_f0_again is not changed
51+
52+
- &modify_test_vm1
53+
name: modify the new VM
54+
guest:
55+
validate_certs: false
56+
hostname: "{{ vcenter_hostname }}"
57+
username: "{{ vcenter_username }}"
58+
password: "{{ vcenter_password }}"
59+
name: test_vm1
60+
guest_id: centos64Guest
61+
datacenter: "{{ dc1 }}"
62+
hardware:
63+
num_cpus: 2
64+
memory_mb: 128
65+
state: present
66+
folder: '{{ f0 }}'
67+
register: modify_d1_c1_f0
68+
69+
- debug: var=modify_d1_c1_f0
70+
71+
- name: assert that changes were made with modification
72+
assert:
73+
that:
74+
- modify_d1_c1_f0 is changed
75+
76+
- <<: *modify_test_vm1
77+
name: re-modify the new VMs
78+
register: modify_d1_c1_f0_again
79+
80+
- debug: var=modify_d1_c1_f0_again
81+
82+
- name: assert that no changes were made when re-modified
83+
assert:
84+
that:
85+
- modify_d1_c1_f0_again is not changed
86+
87+
- &delete_test_vm1
88+
name: delete the new VMs
89+
guest:
90+
validate_certs: false
91+
hostname: "{{ vcenter_hostname }}"
92+
username: "{{ vcenter_username }}"
93+
password: "{{ vcenter_password }}"
94+
name: test_vm1
95+
datacenter: "{{ dc1 }}"
96+
state: absent
97+
folder: '{{ f0 }}'
98+
register: delete_d1_c1_f0
99+
100+
- debug: var=delete_d1_c1_f0
101+
102+
- name: assert that changes were made with deletion
103+
assert:
104+
that:
105+
- delete_d1_c1_f0 is changed
106+
107+
- <<: *delete_test_vm1
108+
name: re-delete the new VMs
109+
register: delete_d1_c1_f0_again
110+
111+
- debug: var=delete_d1_c1_f0_again
112+
113+
- name: assert that no changes were made with redeletion
114+
assert:
115+
that:
116+
- delete_d1_c1_f0_again is not changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Test code for the guest module.
2+
# Copyright: (c) 2017, Abhijeet Kasurde <[email protected]>
3+
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4+
5+
- name: create new virtual machine with invalid guest id
6+
guest:
7+
validate_certs: false
8+
hostname: "{{ vcenter_hostname }}"
9+
username: "{{ vcenter_username }}"
10+
password: "{{ vcenter_password }}"
11+
name: invalid_vm
12+
guest_id: "invalid_guest_id"
13+
datacenter: "{{ dc1 }}"
14+
hardware:
15+
num_cpus: 1
16+
memory_mb: 128
17+
state: present
18+
folder: "{{ f0 }}"
19+
register: invalid_guest_0001_d1_c1_f0
20+
ignore_errors: true
21+
22+
- debug: var=invalid_guest_0001_d1_c1_f0
23+
24+
- name: assert that changes were made
25+
assert:
26+
that:
27+
- "not (invalid_guest_0001_d1_c1_f0 is changed)"
28+
- "'configSpec.guestId' in invalid_guest_0001_d1_c1_f0['msg']"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Test code for the guest module.
2+
# Copyright: (c) 2017, James Tanner <[email protected]>
3+
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4+
5+
- import_role:
6+
name: prepare_vmware_tests
7+
vars:
8+
setup_attach_host: true
9+
setup_datacenter: true
10+
setup_datastore: true
11+
setup_dvswitch: true
12+
setup_resource_pool: true
13+
setup_dvs_portgroup: true
14+
15+
- include_tasks: run_test_playbook.yml
16+
with_items: '{{ guest_test_playbooks }}'
17+
loop_control:
18+
loop_var: test_playbook
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
- block:
2+
- include_tasks: '{{ test_playbook }}'
3+
always:
4+
- name: Collect the list of the existing VM
5+
vmware.vmware_rest.vcenter_vm_info:
6+
vcenter_hostname: '{{ vcenter_hostname }}'
7+
vcenter_username: '{{ vcenter_username }}'
8+
vcenter_password: '{{ vcenter_password }}'
9+
vcenter_validate_certs: false
10+
register: existing_vms
11+
until: existing_vms is not failed
12+
- name: Turn off the VM
13+
vmware.vmware_rest.vcenter_vm_power:
14+
vcenter_hostname: '{{ vcenter_hostname }}'
15+
vcenter_username: '{{ vcenter_username }}'
16+
vcenter_password: '{{ vcenter_password }}'
17+
vcenter_validate_certs: false
18+
state: stop
19+
vm: '{{ item.vm }}'
20+
with_items: "{{ existing_vms.value }}"
21+
ignore_errors: true
22+
- name: Clean up VM
23+
vmware.vmware_rest.vcenter_vm:
24+
vcenter_hostname: '{{ vcenter_hostname }}'
25+
vcenter_username: '{{ vcenter_username }}'
26+
vcenter_password: '{{ vcenter_password }}'
27+
vcenter_validate_certs: false
28+
state: absent
29+
vm: '{{ item.vm }}'
30+
with_items: "{{ existing_vms.value }}"
31+
when:
32+
- not item.name.startswith("vCLS")

0 commit comments

Comments
 (0)