cs_instance: implement host migration support (#40309)

* cs_instance: implement host migration support

* fix build

* fail fast on update if user is not admin

* improve tests a bit

* expunge it

* fix typo

* disable temporarly verify for host on starting instance.
This commit is contained in:
René Moser
2018-05-25 11:20:04 +02:00
committed by GitHub
parent 6443a56069
commit 5dd3aa26ea
6 changed files with 125 additions and 26 deletions

View File

@@ -3,3 +3,4 @@ cs_resource_prefix: "cs-{{ (ansible_date_time.iso8601_micro | to_uuid).split('-'
cs_common_template: CentOS 5.6 (64-bit) no GUI (Simulator)
cs_common_service_offering: Small Instance
cs_common_zone_adv: Sandbox-simulator-advanced
cs_common_zone_basic: Sandbox-simulator-basic

View File

@@ -1,15 +1,15 @@
---
- include: setup.yml
- include_tasks: setup.yml
- include: present.yml
- include: tags.yml
- include: absent.yml
- include_tasks: present.yml
- include_tasks: tags.yml
- include_tasks: absent.yml
- include: present_display_name.yml
- include: absent_display_name.yml
- include_tasks: present_display_name.yml
- include_tasks: absent_display_name.yml
- include: sshkeys.yml
- include_tasks: sshkeys.yml
- include: project.yml
- include_tasks: project.yml
- include: cleanup.yml
- include_tasks: cleanup.yml

View File

@@ -1,6 +1,8 @@
---
- name: setup instance to be absent
cs_instance: name={{ cs_resource_prefix }}-vm-{{ instance_number }} state=absent
cs_instance:
name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}"
state: expunged
register: instance
- name: verify instance to be absent
assert:
@@ -83,6 +85,10 @@
- instance.ssh_key == "{{ cs_resource_prefix }}-sshkey"
- not instance.tags
- name: gather host facts of running instance
cs_instance_facts:
name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}"
- name: test running instance not updated in check mode
cs_instance:
name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}"
@@ -206,9 +212,28 @@
- instance.service_offering == "{{ test_cs_instance_offering_2 }}"
- instance.state == "Stopped"
- name: test starting instance in check mdoe
- name: setup zone facts
cs_zone_facts:
name: "{{ cs_common_zone_basic }}"
- name: setup find the host name
shell: cs listHosts type=routing zoneid="{{ cloudstack_zone.id }}"
args:
chdir: "{{ playbook_dir }}"
register: host
- name: host convert from json
set_fact:
host_json: "{{ host.stdout | from_json }}"
- name: select a host on which the instance is not running on
set_fact:
host: "{{ host_json | json_query('host[?name!=`' + cloudstack_instance.host + '`] | [0]') }}"
- name: test starting instance in check mode
cs_instance:
name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}"
host: "{{ host.name }}"
state: started
register: instance
check_mode: true
@@ -220,11 +245,13 @@
- instance.name == "{{ cs_resource_prefix }}-vm-{{ instance_number }}"
- instance.display_name == "{{ cs_resource_prefix }}-display-{{ instance_number }}"
- instance.service_offering == "{{ test_cs_instance_offering_2 }}"
- instance.host is not defined
- instance.state == "Stopped"
- name: test starting instance
cs_instance:
name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}"
host: "{{ host.name }}"
state: started
register: instance
- name: verify starting instance
@@ -235,11 +262,14 @@
- instance.name == "{{ cs_resource_prefix }}-vm-{{ instance_number }}"
- instance.display_name == "{{ cs_resource_prefix }}-display-{{ instance_number }}"
- instance.service_offering == "{{ test_cs_instance_offering_2 }}"
# TODO: this fails randomly, cloudstack issue?
#- instance.host == "{{ host.name }}"
- instance.state == "Running"
- name: test starting instance idempotence
cs_instance:
name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}"
host: "{{ host.name }}"
state: started
register: instance
- name: verify starting instance idempotence
@@ -250,12 +280,19 @@
- instance.name == "{{ cs_resource_prefix }}-vm-{{ instance_number }}"
- instance.display_name == "{{ cs_resource_prefix }}-display-{{ instance_number }}"
- instance.service_offering == "{{ test_cs_instance_offering_2 }}"
# TODO: this fails randomly, cloudstack issue?
#- instance.host == "{{ host.name }}"
- instance.state == "Running"
- name: select a host on which the instance is not running on
set_fact:
host: "{{ host_json | json_query('host[?name!=`' + instance.host + '`] | [0]') }}"
- name: test force update running instance in check mode
cs_instance:
name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}"
service_offering: "{{ test_cs_instance_offering_1 }}"
host: "{{ host.name }}"
force: true
register: instance
check_mode: true
@@ -267,12 +304,14 @@
- instance.name == "{{ cs_resource_prefix }}-vm-{{ instance_number }}"
- instance.display_name == "{{ cs_resource_prefix }}-display-{{ instance_number }}"
- instance.service_offering == "{{ test_cs_instance_offering_2 }}"
- instance.host != "{{ host.name }}"
- instance.state == "Running"
- name: test force update running instance
cs_instance:
name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}"
service_offering: "{{ test_cs_instance_offering_1 }}"
host: "{{ host.name }}"
force: true
register: instance
- name: verify force update running instance
@@ -283,12 +322,14 @@
- instance.name == "{{ cs_resource_prefix }}-vm-{{ instance_number }}"
- instance.display_name == "{{ cs_resource_prefix }}-display-{{ instance_number }}"
- instance.service_offering == "{{ test_cs_instance_offering_1 }}"
- instance.host == "{{ host.name }}"
- instance.state == "Running"
- name: test force update running instance idempotence
cs_instance:
name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}"
service_offering: "{{ test_cs_instance_offering_1 }}"
host: "{{ host.name }}"
force: true
register: instance
- name: verify force update running instance idempotence
@@ -299,6 +340,7 @@
- instance.name == "{{ cs_resource_prefix }}-vm-{{ instance_number }}"
- instance.display_name == "{{ cs_resource_prefix }}-display-{{ instance_number }}"
- instance.service_offering == "{{ test_cs_instance_offering_1 }}"
- instance.host == "{{ host.name }}"
- instance.state == "Running"
- name: test restore instance in check mode

View File

@@ -1,6 +1,8 @@
---
- name: setup instance with display_name to be absent
cs_instance: display_name={{ cs_resource_prefix }}-vm-{{ instance_number }} state=absent
cs_instance:
display_name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}"
state: expunged
register: instance
- name: verify instance with display_name to be absent
assert:

View File

@@ -154,7 +154,6 @@ lib/ansible/modules/cloud/cloudscale/cloudscale_server.py E325
lib/ansible/modules/cloud/cloudstack/cs_cluster.py E326
lib/ansible/modules/cloud/cloudstack/cs_domain.py E325
lib/ansible/modules/cloud/cloudstack/cs_host.py E326
lib/ansible/modules/cloud/cloudstack/cs_instance.py E325
lib/ansible/modules/cloud/cloudstack/cs_instance.py E326
lib/ansible/modules/cloud/cloudstack/cs_instance_nic_secondaryip.py E325
lib/ansible/modules/cloud/cloudstack/cs_iso.py E323