Skip to content

Commit 2794a34

Browse files
committed
CI test vm_params changing power_state
Signed-off-by: Justin Cinkelj <justin.cinkelj@xlab.si>
1 parent 38b7f64 commit 2794a34

File tree

4 files changed

+220
-0
lines changed

4 files changed

+220
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
# ===================================================================
3+
# Nice ACPI shutdown
4+
- &vm_info
5+
name: Get VM state {{ vm_name }}
6+
scale_computing.hypercore.vm_info:
7+
vm_name: "{{ vm_name }}"
8+
register: vm_info_result
9+
- ansible.builtin.assert:
10+
that:
11+
- vm_info_result.records[0].vm_name == vm_name
12+
- vm_info_result.records[0].power_state == "started"
13+
14+
- &vm_shutdown
15+
name: Send nice ACPI shutdown VM {{ vm_name }}
16+
scale_computing.hypercore.vm_params:
17+
vm_name: "{{ vm_name }}"
18+
power_state: shutdown
19+
# shutdown_timeout applies only if force shutdown is allowed
20+
# shutdown_timeout: 30
21+
register: output
22+
- ansible.builtin.assert:
23+
that:
24+
- output is changed
25+
- output.vm_rebooted is false
26+
27+
# Porteus ISO requires about 60-100 sec to boot, 15 sec to shutdown
28+
- &wait_shutdown
29+
name: Wait 30 sec on VM to fully shutdown {{ vm_name }}
30+
ansible.builtin.pause:
31+
seconds: 30
32+
33+
- *vm_info
34+
- ansible.builtin.assert:
35+
that:
36+
- vm_info_result.records[0].vm_name == vm_name
37+
- vm_info_result.records[0].power_state == state_after_acpi_shutdown
38+
39+
# ===================================================================
40+
# Idempotence
41+
# But retry results in 500 internal error on HC3 9.1 - 9.4, we need to avoid sending a second request to HyperCore.
42+
- name: Retry ACPI shutdown
43+
when: state_after_acpi_shutdown == "started"
44+
block:
45+
- *vm_shutdown
46+
- ansible.builtin.assert:
47+
that:
48+
- output is changed
49+
- output.vm_rebooted is false
50+
- *wait_shutdown
51+
- *vm_info
52+
- ansible.builtin.assert:
53+
that:
54+
- vm_info_result.records[0].vm_name == vm_name
55+
- vm_info_result.records[0].power_state == state_after_acpi_shutdown
56+
57+
# ===================================================================
58+
# Force shutdown
59+
- &vm_stop
60+
name: Send force shutdown VM {{ vm_name }}
61+
scale_computing.hypercore.vm_params:
62+
vm_name: "{{ vm_name }}"
63+
power_state: stop
64+
# shutdown_timeout applies only if force shutdown is allowed
65+
shutdown_timeout: 30
66+
register: output
67+
- ansible.builtin.assert:
68+
that:
69+
- output.changed == power_state_stop_is_change
70+
- output.vm_rebooted is false
71+
72+
- *wait_shutdown
73+
- *vm_info
74+
- ansible.builtin.assert:
75+
that:
76+
- vm_info_result.records[0].vm_name == vm_name
77+
- vm_info_result.records[0].power_state == "stopped"
78+
79+
# ===================================================================
80+
# Idempotence
81+
- *vm_stop
82+
- ansible.builtin.assert:
83+
that:
84+
- output is not changed
85+
- output.vm_rebooted is false
86+
87+
# - *wait_shutdown
88+
- *vm_info
89+
- ansible.builtin.assert:
90+
that:
91+
- vm_info_result.records[0].vm_name == vm_name
92+
- vm_info_result.records[0].power_state == "stopped"
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
# ------------------------------------------------------------------------------------------------------------------
3+
# Prerequisites
4+
# integration-test.iso must be already present, we have prepare.yml task
5+
- name: Get ISO {{ iso_name_with_acpi }} info
6+
scale_computing.hypercore.iso_info:
7+
name: "{{ iso_name_with_acpi }}"
8+
register: uploaded_iso_info
9+
- ansible.builtin.assert:
10+
that:
11+
- uploaded_iso_info.records | length == 1
12+
13+
- name: Get ISO {{ iso_name_no_acpi }} info
14+
scale_computing.hypercore.iso_info:
15+
name: "{{ iso_name_no_acpi }}"
16+
register: uploaded_iso_info
17+
- ansible.builtin.assert:
18+
that:
19+
- uploaded_iso_info.records | length == 1
20+
21+
# ------------------------------------------------------------------------------------------------------------------
22+
# Create test VMs
23+
- name: Create test VM a - {{ vm_name_a }}
24+
scale_computing.hypercore.vm:
25+
vm_name: "{{ vm_name_a }}"
26+
description: "{{ vm_name_a }}"
27+
state: present
28+
tags:
29+
- Xlab
30+
- ci_live_migrate__no_a
31+
memory: "{{ '512 MB' | human_to_bytes }}"
32+
vcpu: 2
33+
attach_guest_tools_iso: false
34+
power_state: start
35+
disks:
36+
- type: ide_cdrom
37+
disk_slot: 0
38+
iso_name: "{{ iso_name_with_acpi }}"
39+
nics:
40+
- vlan: 1
41+
type: virtio
42+
boot_devices:
43+
- type: ide_cdrom
44+
disk_slot: 0
45+
machine_type: BIOS
46+
register: vm_created
47+
- ansible.builtin.assert:
48+
that:
49+
- vm_created.record.0.power_state == "started"
50+
- vm_created.record.0.boot_devices | length == 1
51+
- vm_created.record.0.boot_devices.0.type == "ide_cdrom"
52+
53+
- name: Create test VM b - {{ vm_name_b }}
54+
scale_computing.hypercore.vm:
55+
vm_name: "{{ vm_name_b }}"
56+
description: "{{ vm_name_b }}"
57+
state: present
58+
tags:
59+
- Xlab
60+
- ci_live_migrate__no_b
61+
memory: "{{ '512 MB' | human_to_bytes }}"
62+
vcpu: 2
63+
attach_guest_tools_iso: false
64+
power_state: start
65+
disks:
66+
- type: ide_cdrom
67+
disk_slot: 0
68+
iso_name: "{{ iso_name_no_acpi }}"
69+
nics:
70+
- vlan: 1
71+
type: virtio
72+
boot_devices:
73+
- type: ide_cdrom
74+
disk_slot: 0
75+
machine_type: BIOS
76+
register: vm_created
77+
- ansible.builtin.assert:
78+
that:
79+
- vm_created.record.0.power_state == "started"
80+
- vm_created.record.0.boot_devices | length == 1
81+
- vm_created.record.0.boot_devices.0.type == "ide_cdrom"
82+
83+
# Porteus ISO requires about 60-100 sec to boot, 15 sec to shutdown
84+
- name: Wait 100 sec on ACPI VM to fully boot
85+
ansible.builtin.pause:
86+
seconds: 100
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
# Cleanup
3+
- name: Delete test VMs
4+
scale_computing.hypercore.vm:
5+
vm_name: "{{ vm_name }}"
6+
state: absent
7+
loop: "{{ vm_name_all }}"
8+
loop_control:
9+
loop_var: vm_name
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
- environment:
3+
SC_HOST: "{{ sc_host }}"
4+
SC_USERNAME: "{{ sc_config[sc_host].sc_username }}"
5+
SC_PASSWORD: "{{ sc_config[sc_host].sc_password }}"
6+
SC_TIMEOUT: "{{ sc_timeout }}"
7+
vars:
8+
vm_name_a: XLAB-vm_params-power-state-a
9+
vm_name_b: XLAB-vm_params-power-state-b
10+
vm_name_all:
11+
- "{{ vm_name_a }}"
12+
- "{{ vm_name_b }}"
13+
iso_name_with_acpi: "Porteus-XFCE-v5.0-x86_64.iso"
14+
iso_name_no_acpi: "integration-test.iso"
15+
16+
block:
17+
- include_tasks: helper_remove_vms.yml
18+
- include_tasks: helper_create_vms.yml
19+
20+
- include_tasks: 03_power_state.yml
21+
vars:
22+
vm_name: "{{ vm_name_a }}"
23+
# what will be VM power_state after acpi shutdown
24+
state_after_acpi_shutdown: stopped
25+
# Is 1st power_state stop a change or not?
26+
power_state_stop_is_change: False
27+
- include_tasks: 03_power_state.yml
28+
vars:
29+
vm_name: "{{ vm_name_b }}"
30+
state_after_acpi_shutdown: started
31+
power_state_stop_is_change: True
32+
33+
- include_tasks: helper_remove_vms.yml

0 commit comments

Comments
 (0)