|
| 1 | +--- |
| 2 | +- name: setup ensure running instance to get host infos |
| 3 | + ngine_io.cloudstack.instance: |
| 4 | + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" |
| 5 | + zone: "{{ cs_common_zone_basic }}" |
| 6 | + template: "{{ test_cs_instance_template }}" |
| 7 | + service_offering: "{{ test_cs_instance_offering_1 }}" |
| 8 | + state: started |
| 9 | + register: running_instance |
| 10 | + |
| 11 | +- name: setup ensure stopped instance |
| 12 | + ngine_io.cloudstack.instance: |
| 13 | + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" |
| 14 | + zone: "{{ cs_common_zone_basic }}" |
| 15 | + state: stopped |
| 16 | + |
| 17 | +- name: setup zone facts |
| 18 | + ngine_io.cloudstack.zone_info: |
| 19 | + name: "{{ cs_common_zone_basic }}" |
| 20 | + register: zone_info |
| 21 | + |
| 22 | +- name: setup find the host name |
| 23 | + shell: cs listHosts type=routing zoneid="{{ zone_info.zones[0].id }}" |
| 24 | + args: |
| 25 | + chdir: "{{ playbook_dir }}" |
| 26 | + register: host |
| 27 | + |
| 28 | +- name: host convert from json |
| 29 | + set_fact: |
| 30 | + host_json: "{{ host.stdout | from_json }}" |
| 31 | + |
| 32 | +- name: select a host on which the instance was not running on |
| 33 | + set_fact: |
| 34 | + host: "{{ host_json | json_query('host[?name!=`' + running_instance.host + '`] | [0]') }}" |
| 35 | + |
| 36 | +- debug: |
| 37 | + msg: "from current host {{ running_instance.host }} to new host {{ host.name }}" |
| 38 | + |
| 39 | +- name: test starting instance on new host in check mode |
| 40 | + ngine_io.cloudstack.instance: |
| 41 | + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" |
| 42 | + zone: "{{ cs_common_zone_basic }}" |
| 43 | + host: "{{ host.name }}" |
| 44 | + state: started |
| 45 | + register: instance |
| 46 | + check_mode: true |
| 47 | +- name: verify test starting instance on new host in check mode |
| 48 | + assert: |
| 49 | + that: |
| 50 | + - instance is changed |
| 51 | + - instance.name == cs_resource_prefix + "-vm-" + instance_number |
| 52 | + - instance.host is not defined |
| 53 | + - instance.state == "Stopped" |
| 54 | + |
| 55 | +- name: test starting instance on new host |
| 56 | + ngine_io.cloudstack.instance: |
| 57 | + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" |
| 58 | + zone: "{{ cs_common_zone_basic }}" |
| 59 | + host: "{{ host.name }}" |
| 60 | + state: started |
| 61 | + register: instance |
| 62 | +- name: verify test starting instance on new host |
| 63 | + assert: |
| 64 | + that: |
| 65 | + - instance is changed |
| 66 | + - instance.name == cs_resource_prefix + "-vm-" + instance_number |
| 67 | + - instance.host == host.name |
| 68 | + - instance.state == "Running" |
| 69 | + |
| 70 | +- name: test starting instance on new host idempotence |
| 71 | + ngine_io.cloudstack.instance: |
| 72 | + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" |
| 73 | + zone: "{{ cs_common_zone_basic }}" |
| 74 | + host: "{{ host.name }}" |
| 75 | + state: started |
| 76 | + register: instance |
| 77 | +- name: verify test starting instance on new host idempotence |
| 78 | + assert: |
| 79 | + that: |
| 80 | + - instance is not changed |
| 81 | + - instance.name == cs_resource_prefix + "-vm-" + instance_number |
| 82 | + - instance.host == host.name |
| 83 | + - instance.state == "Running" |
| 84 | + |
| 85 | +- name: select a host on which the instance is not running on |
| 86 | + set_fact: |
| 87 | + host: "{{ host_json | json_query('host[?name!=`' + instance.host + '`] | [0]') }}" |
| 88 | + |
| 89 | +- debug: |
| 90 | + msg: "from current host {{ instance.host }} to new host {{ host.name }}" |
| 91 | + |
| 92 | +- name: test force update running instance in check mode |
| 93 | + ngine_io.cloudstack.instance: |
| 94 | + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" |
| 95 | + zone: "{{ cs_common_zone_basic }}" |
| 96 | + host: "{{ host.name }}" |
| 97 | + force: true |
| 98 | + register: instance |
| 99 | + check_mode: true |
| 100 | +- name: verify force update running instance in check mode |
| 101 | + assert: |
| 102 | + that: |
| 103 | + - instance is changed |
| 104 | + - instance.name == cs_resource_prefix + "-vm-" + instance_number |
| 105 | + - instance.host != host.name |
| 106 | + - instance.state == "Running" |
| 107 | + |
| 108 | +- name: test force update running instance |
| 109 | + ngine_io.cloudstack.instance: |
| 110 | + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" |
| 111 | + zone: "{{ cs_common_zone_basic }}" |
| 112 | + host: "{{ host.name }}" |
| 113 | + force: true |
| 114 | + register: instance |
| 115 | +- name: verify force update running instance |
| 116 | + assert: |
| 117 | + that: |
| 118 | + - instance is changed |
| 119 | + - instance.name cs_resource_prefix + "-vm-" + instance_number |
| 120 | + - instance.host == host.name |
| 121 | + - instance.state == "Running" |
| 122 | + |
| 123 | +- name: test force update running instance idempotence |
| 124 | + ngine_io.cloudstack.instance: |
| 125 | + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" |
| 126 | + zone: "{{ cs_common_zone_basic }}" |
| 127 | + host: "{{ host.name }}" |
| 128 | + force: true |
| 129 | + register: instance |
| 130 | +- name: verify force update running instance idempotence |
| 131 | + assert: |
| 132 | + that: |
| 133 | + - instance is not changed |
| 134 | + - instance.name == cs_resource_prefix + "-vm-" + instance_number |
| 135 | + - instance.display_name == cs_resource_prefix + "-display-" + instance_number |
| 136 | + - instance.host == host.name |
| 137 | + - instance.state == "Running" |
0 commit comments