diff --git a/tests/integration/targets/instance/aliases b/tests/integration/targets/instance/aliases new file mode 100644 index 00000000..2ce8657c --- /dev/null +++ b/tests/integration/targets/instance/aliases @@ -0,0 +1,3 @@ +cloud/cs +cs/group1 +cs/group3 diff --git a/tests/integration/targets/instance/defaults/main.yml b/tests/integration/targets/instance/defaults/main.yml new file mode 100644 index 00000000..4db5c7c9 --- /dev/null +++ b/tests/integration/targets/instance/defaults/main.yml @@ -0,0 +1,5 @@ +--- +instance_number: 1 +test_cs_instance_template: "{{ cs_common_template }}" +test_cs_instance_offering_1: Small Instance +test_cs_instance_offering_2: Medium Instance diff --git a/tests/integration/targets/instance/meta/main.yml b/tests/integration/targets/instance/meta/main.yml new file mode 100644 index 00000000..e9a5b9ee --- /dev/null +++ b/tests/integration/targets/instance/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - cs_common diff --git a/tests/integration/targets/instance/tasks/absent.yml b/tests/integration/targets/instance/tasks/absent.yml new file mode 100644 index 00000000..4c561112 --- /dev/null +++ b/tests/integration/targets/instance/tasks/absent.yml @@ -0,0 +1,115 @@ +--- +- name: test destroy instance in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + state: absent + register: instance + check_mode: true +- name: verify destroy instance in check mode + assert: + that: + - instance is changed + - instance.state != "Destroyed" + +- name: test destroy instance + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + state: absent + register: instance +- name: verify destroy instance + assert: + that: + - instance is changed + - instance.state == "Destroyed" + +- name: test destroy instance idempotence + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + state: absent + register: instance +- name: verify destroy instance idempotence + assert: + that: + - instance is not changed + +- name: test recover to stopped state and update a deleted instance in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + state: stopped + register: instance + check_mode: true +- name: verify test recover to stopped state and update a deleted instance in check mode + assert: + that: + - instance is changed + +- name: test recover to stopped state and update a deleted instance + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + state: stopped + register: instance +- name: verify test recover to stopped state and update a deleted instance + assert: + that: + - instance is changed + - instance.state == "Stopped" + - instance.service_offering == test_cs_instance_offering_1 + +- name: test recover to stopped state and update a deleted instance idempotence + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + state: stopped + register: instance +- name: verify test recover to stopped state and update a deleted instance idempotence + assert: + that: + - instance is not changed + - instance.state == "Stopped" + - instance.service_offering == test_cs_instance_offering_1 + +- name: test expunge instance in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + state: expunged + register: instance + check_mode: true +- name: verify test expunge instance in check mode + assert: + that: + - instance is changed + - instance.state == "Stopped" + - instance.service_offering == test_cs_instance_offering_1 + +- name: test expunge instance + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + state: expunged + register: instance +- name: verify test expunge instance + assert: + that: + - instance is changed + - instance.state == "Stopped" + - instance.service_offering == test_cs_instance_offering_1 + +- name: test expunge instance idempotence + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + state: expunged + register: instance +- name: verify test expunge instance idempotence + assert: + that: + - instance is not changed diff --git a/tests/integration/targets/instance/tasks/absent_display_name.yml b/tests/integration/targets/instance/tasks/absent_display_name.yml new file mode 100644 index 00000000..bf737cd5 --- /dev/null +++ b/tests/integration/targets/instance/tasks/absent_display_name.yml @@ -0,0 +1,44 @@ +--- +- name: test destroy instance with display_name + ngine_io.cloudstack.instance: + display_name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + state: absent + register: instance +- name: verify destroy instance with display_name + assert: + that: + - instance is changed + - instance.state == "Destroyed" + +- name: test destroy instance with display_name idempotence + ngine_io.cloudstack.instance: + display_name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + state: absent + register: instance +- name: verify destroy instance with display_name idempotence + assert: + that: + - instance is not changed + +- name: test recover to stopped state and update a deleted instance with display_name + ngine_io.cloudstack.instance: + display_name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + state: stopped + register: instance +- name: verify test recover to stopped state and update a deleted instance with display_name + assert: + that: + - instance is changed + - instance.state == "Stopped" + - instance.service_offering == test_cs_instance_offering_1 + +# force expunge, only works with admin permissions +- ngine_io.cloudstack.instance: + display_name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + state: expunged + failed_when: false diff --git a/tests/integration/targets/instance/tasks/cleanup.yml b/tests/integration/targets/instance/tasks/cleanup.yml new file mode 100644 index 00000000..394c944c --- /dev/null +++ b/tests/integration/targets/instance/tasks/cleanup.yml @@ -0,0 +1,36 @@ +--- +- name: cleanup ssh key + ngine_io.cloudstack.ssh_key: + name: "{{ cs_resource_prefix }}-sshkey" + state: absent + register: sshkey +- name: verify cleanup ssh key + assert: + that: + - sshkey is successful + +- name: cleanup affinity group + ngine_io.cloudstack.affinity_group: + name: "{{ cs_resource_prefix }}-ag" + state: absent + register: ag + until: ag is successful + retries: 20 + delay: 5 +- name: verify cleanup affinity group + assert: + that: + - ag is successful + +- name: cleanup security group ...take a while unless instance is expunged + ngine_io.cloudstack.security_group: + name: "{{ cs_resource_prefix }}-sg" + state: absent + register: sg + until: sg is successful + retries: 100 + delay: 10 +- name: verify cleanup security group + assert: + that: + - sg is successful diff --git a/tests/integration/targets/instance/tasks/host.yml b/tests/integration/targets/instance/tasks/host.yml new file mode 100644 index 00000000..594ef0c4 --- /dev/null +++ b/tests/integration/targets/instance/tasks/host.yml @@ -0,0 +1,137 @@ +--- +- name: setup ensure running instance to get host infos + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + template: "{{ test_cs_instance_template }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + state: started + register: running_instance + +- name: setup ensure stopped instance + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + state: stopped + +- name: setup zone facts + ngine_io.cloudstack.zone_info: + name: "{{ cs_common_zone_basic }}" + register: zone_info + +- name: setup find the host name + shell: cs listHosts type=routing zoneid="{{ zone_info.zones[0].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 was not running on + set_fact: + host: "{{ host_json | json_query('host[?name!=`' + running_instance.host + '`] | [0]') }}" + +- debug: + msg: "from current host {{ running_instance.host }} to new host {{ host.name }}" + +- name: test starting instance on new host in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + host: "{{ host.name }}" + state: started + register: instance + check_mode: true +- name: verify test starting instance on new host in check mode + assert: + that: + - instance is changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.host is not defined + - instance.state == "Stopped" + +- name: test starting instance on new host + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + host: "{{ host.name }}" + state: started + register: instance +- name: verify test starting instance on new host + assert: + that: + - instance is changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.host == host.name + - instance.state == "Running" + +- name: test starting instance on new host idempotence + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + host: "{{ host.name }}" + state: started + register: instance +- name: verify test starting instance on new host idempotence + assert: + that: + - instance is not changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - 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]') }}" + +- debug: + msg: "from current host {{ instance.host }} to new host {{ host.name }}" + +- name: test force update running instance in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + host: "{{ host.name }}" + force: true + register: instance + check_mode: true +- name: verify force update running instance in check mode + assert: + that: + - instance is changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.host != host.name + - instance.state == "Running" + +- name: test force update running instance + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + host: "{{ host.name }}" + force: true + register: instance +- name: verify force update running instance + assert: + that: + - instance is changed + - instance.name cs_resource_prefix + "-vm-" + instance_number + - instance.host == host.name + - instance.state == "Running" + +- name: test force update running instance idempotence + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + host: "{{ host.name }}" + force: true + register: instance +- name: verify force update running instance idempotence + assert: + that: + - instance is not changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.display_name == cs_resource_prefix + "-display-" + instance_number + - instance.host == host.name + - instance.state == "Running" diff --git a/tests/integration/targets/instance/tasks/main.yml b/tests/integration/targets/instance/tasks/main.yml new file mode 100644 index 00000000..13fb7995 --- /dev/null +++ b/tests/integration/targets/instance/tasks/main.yml @@ -0,0 +1,18 @@ +--- +- import_tasks: setup.yml + +- import_tasks: present.yml +- import_tasks: tags.yml +- import_tasks: absent.yml + +- import_tasks: present_display_name.yml +- import_tasks: absent_display_name.yml + +# TODO: These tests randomly fail in all kinds of unexpected states. +# This needs to be verified by the cloudstack community. +# - import_tasks: host.yml + +- import_tasks: sshkeys.yml +- import_tasks: project.yml + +- import_tasks: cleanup.yml diff --git a/tests/integration/targets/instance/tasks/present.yml b/tests/integration/targets/instance/tasks/present.yml new file mode 100644 index 00000000..966ea5c3 --- /dev/null +++ b/tests/integration/targets/instance/tasks/present.yml @@ -0,0 +1,319 @@ +--- +- name: setup instance to be absent + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + state: expunged + +- name: test create instance in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + template: "{{ test_cs_instance_template }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + affinity_group: "{{ cs_resource_prefix }}-ag" + security_group: "{{ cs_resource_prefix }}-sg" + ssh_key: "{{ cs_resource_prefix }}-sshkey" + user_data: | + #cloud-config + package_upgrade: true + packages: + - tmux + tags: [] + register: instance + check_mode: true +- name: verify create instance in check mode + assert: + that: + - instance is changed + +- name: test create instance + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + template: "{{ test_cs_instance_template }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + affinity_group: "{{ cs_resource_prefix }}-ag" + security_group: "{{ cs_resource_prefix }}-sg" + ssh_key: "{{ cs_resource_prefix }}-sshkey" + user_data: | + #cloud-config + package_upgrade: true + packages: + - tmux + tags: [] + register: instance +- name: verify create instance + assert: + that: + - instance is changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.display_name == cs_resource_prefix + "-vm-" + instance_number + - instance.service_offering == test_cs_instance_offering_1 + - instance.state == "Running" + - instance.ssh_key == cs_resource_prefix + "-sshkey" + - not instance.tags + +- name: test create instance idempotence + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + template: "{{ test_cs_instance_template }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + affinity_group: "{{ cs_resource_prefix }}-ag" + security_group: "{{ cs_resource_prefix }}-sg" + ssh_key: "{{ cs_resource_prefix }}-sshkey" + user_data: | + #cloud-config + package_upgrade: true + packages: + - tmux + tags: [] + register: instance +- name: verify create instance idempotence + assert: + that: + - instance is not changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.display_name == cs_resource_prefix + "-vm-" + instance_number + - instance.service_offering == test_cs_instance_offering_1 + - instance.state == "Running" + - instance.ssh_key == cs_resource_prefix + "-sshkey" + - not instance.tags + +- name: gather host infos of running instance + ngine_io.cloudstack.instance_info: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + +- name: test running instance not updated in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + service_offering: "{{ test_cs_instance_offering_2 }}" + register: instance + check_mode: true +- name: verify running instance not updated in check mode + assert: + that: + - instance is not changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.display_name == cs_resource_prefix + "-vm-" + instance_number + - instance.service_offering == test_cs_instance_offering_1 + - instance.state == "Running" + +- name: test running instance not updated + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + service_offering: "{{ test_cs_instance_offering_2 }}" + register: instance +- name: verify running instance not updated + assert: + that: + - instance is not changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.display_name == cs_resource_prefix + "-vm-" + instance_number + - instance.service_offering == test_cs_instance_offering_1 + - instance.state == "Running" + +- name: test stopping instance in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + state: stopped + register: instance + check_mode: true +- name: verify stopping instance in check mode + assert: + that: + - instance is changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.display_name == cs_resource_prefix + "-vm-" + instance_number + - instance.service_offering == test_cs_instance_offering_1 + - instance.state == "Running" + +- name: test stopping instance + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + state: stopped + register: instance +- name: verify stopping instance + assert: + that: + - instance is changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.display_name == cs_resource_prefix + "-vm-" + instance_number + - instance.service_offering == test_cs_instance_offering_1 + - instance.state == "Stopped" + +- name: test stopping instance idempotence + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + state: stopped + register: instance +- name: verify stopping instance idempotence + assert: + that: + - instance is not changed + - instance.state == "Stopped" + +- name: test updating stopped instance in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + display_name: "{{ cs_resource_prefix }}-display-{{ instance_number }}" + service_offering: "{{ test_cs_instance_offering_2 }}" + register: instance + check_mode: true +- name: verify updating stopped instance in check mode + assert: + that: + - instance is changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.display_name == cs_resource_prefix + "-vm-" + instance_number + - instance.service_offering == test_cs_instance_offering_1 + - instance.state == "Stopped" + +- name: test updating stopped instance + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + display_name: "{{ cs_resource_prefix }}-display-{{ instance_number }}" + service_offering: "{{ test_cs_instance_offering_2 }}" + register: instance +- name: verify updating stopped instance + assert: + that: + - instance is changed + - 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.state == "Stopped" + +- name: test updating stopped instance idempotence + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + display_name: "{{ cs_resource_prefix }}-display-{{ instance_number }}" + service_offering: "{{ test_cs_instance_offering_2 }}" + register: instance +- name: verify updating stopped instance idempotence + assert: + that: + - instance is not changed + - 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.state == "Stopped" + +- name: test starting instance + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + state: started + register: instance +- name: verify starting instance + assert: + that: + - instance is changed + - 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.state == "Running" + +- name: test starting instance idempotence + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + state: started + register: instance +- name: verify starting instance idempotence + assert: + that: + - instance is not changed + - 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.state == "Running" + +- name: test force update running instance in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + force: true + register: instance + check_mode: true +- name: verify force update running instance in check mode + assert: + that: + - instance is changed + - 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.state == "Running" + +- name: test force update running instance + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + force: true + register: instance +- name: verify force update running instance + assert: + that: + - instance is changed + - 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.state == "Running" + +- name: test force update running instance idempotence + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + force: true + register: instance +- name: verify force update running instance idempotence + assert: + that: + - instance is not changed + - 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.state == "Running" + +- name: test restore instance in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + template: "{{ test_cs_instance_template }}" + state: restored + register: instance + check_mode: true +- name: verify restore instance in check mode + assert: + that: + - instance is changed + - 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 + +- name: test restore instance + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + template: "{{ test_cs_instance_template }}" + state: restored + register: instance +- name: verify restore instance + assert: + that: + - instance is changed + - 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 diff --git a/tests/integration/targets/instance/tasks/present_display_name.yml b/tests/integration/targets/instance/tasks/present_display_name.yml new file mode 100644 index 00000000..b354ffca --- /dev/null +++ b/tests/integration/targets/instance/tasks/present_display_name.yml @@ -0,0 +1,178 @@ +--- +- name: setup instance with display_name to be absent + ngine_io.cloudstack.instance: + display_name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + state: expunged + register: instance +- name: verify instance with display_name to be absent + assert: + that: + +- name: test create instance with display_name + ngine_io.cloudstack.instance: + display_name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + template: "{{ test_cs_instance_template }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + affinity_group: "{{ cs_resource_prefix }}-ag" + security_group: "{{ cs_resource_prefix }}-sg" + ssh_key: "{{ cs_resource_prefix }}-sshkey" + tags: [] + register: instance +- name: verify create instance with display_name + assert: + that: + - instance is changed + - instance.display_name == cs_resource_prefix + "-vm-" + instance_number + - instance.service_offering == test_cs_instance_offering_1 + - instance.state == "Running" + - instance.ssh_key == cs_resource_prefix + "-sshkey" + - not instance.tags + +- name: test create instance with display_name idempotence + ngine_io.cloudstack.instance: + display_name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + template: "{{ test_cs_instance_template }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + affinity_group: "{{ cs_resource_prefix }}-ag" + security_group: "{{ cs_resource_prefix }}-sg" + ssh_key: "{{ cs_resource_prefix }}-sshkey" + tags: [] + register: instance +- name: verify create instance with display_name idempotence + assert: + that: + - instance is not changed + - instance.display_name == cs_resource_prefix + "-vm-" + instance_number + - instance.service_offering == test_cs_instance_offering_1 + - instance.state == "Running" + - instance.ssh_key == cs_resource_prefix + "-sshkey" + - not instance.tags + +- name: test running instance with display_name not updated + ngine_io.cloudstack.instance: + display_name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + service_offering: "{{ test_cs_instance_offering_2 }}" + register: instance +- name: verify running instance with display_name not updated + assert: + that: + - instance is not changed + - instance.display_name == cs_resource_prefix + "-vm-" + instance_number + - instance.service_offering == test_cs_instance_offering_1 + - instance.state == "Running" + +- name: test stopping instance with display_name + ngine_io.cloudstack.instance: + display_name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + state: stopped + register: instance +- name: verify stopping instance with display_name + assert: + that: + - instance is changed + - instance.display_name == cs_resource_prefix + "-vm-" + instance_number + - instance.service_offering == test_cs_instance_offering_1 + - instance.state == "Stopped" + +- name: test stopping instance with display_name idempotence + ngine_io.cloudstack.instance: + display_name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + state: stopped + register: instance +- name: verify stopping instance idempotence + assert: + that: + - instance is not changed + - instance.state == "Stopped" + +- name: test updating stopped instance with display_name + ngine_io.cloudstack.instance: + display_name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + service_offering: "{{ test_cs_instance_offering_2 }}" + register: instance +- name: verify updating stopped instance with display_name + assert: + that: + - instance is changed + - instance.display_name == cs_resource_prefix + "-vm-" + instance_number + - instance.service_offering == "{{ test_cs_instance_offering_2 }}" + - instance.state == "Stopped" + +- name: test starting instance with display_name + ngine_io.cloudstack.instance: + display_name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + state: started + register: instance +- name: verify starting instance with display_name + assert: + that: + - instance is changed + - instance.display_name == cs_resource_prefix + "-vm-" + instance_number + - instance.service_offering == "{{ test_cs_instance_offering_2 }}" + - instance.state == "Running" + +- name: test starting instance with display_name idempotence + ngine_io.cloudstack.instance: + display_name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + state: started + register: instance +- name: verify starting instance with display_name idempotence + assert: + that: + - instance is not changed + - instance.display_name == cs_resource_prefix + "-vm-" + instance_number + - instance.service_offering == "{{ test_cs_instance_offering_2 }}" + - instance.state == "Running" + +- name: test force update running instance with display_name + ngine_io.cloudstack.instance: + display_name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + force: true + register: instance +- name: verify force update running instance with display_name + assert: + that: + - instance is changed + - instance.display_name == cs_resource_prefix + "-vm-" + instance_number + - instance.service_offering == test_cs_instance_offering_1 + - instance.state == "Running" + +- name: test force update running instance with display_name idempotence + ngine_io.cloudstack.instance: + display_name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + force: true + register: instance +- name: verify force update running instance with display_name idempotence + assert: + that: + - instance is not changed + - instance.display_name == cs_resource_prefix + "-vm-" + instance_number + - instance.service_offering == test_cs_instance_offering_1 + - instance.state == "Running" + +- name: test restore instance with display_name + ngine_io.cloudstack.instance: + display_name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + template: "{{ test_cs_instance_template }}" + state: restored + register: instance +- name: verify restore instance with display_name + assert: + that: + - instance is changed + - instance.display_name == cs_resource_prefix + "-vm-" + instance_number + - instance.service_offering == test_cs_instance_offering_1 diff --git a/tests/integration/targets/instance/tasks/project.yml b/tests/integration/targets/instance/tasks/project.yml new file mode 100644 index 00000000..d1a3e6de --- /dev/null +++ b/tests/integration/targets/instance/tasks/project.yml @@ -0,0 +1,559 @@ +--- +- name: setup create project + ngine_io.cloudstack.project: + name: "{{ cs_resource_prefix }}-prj" + register: prj +- name: verify test create project + assert: + that: + - prj is successful + +- name: setup instance in project to be absent + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + project: "{{ cs_resource_prefix }}-prj" + state: absent + register: instance +- name: verify instance in project to be absent + assert: + that: + +- name: setup ssh key in project + ngine_io.cloudstack.sshkeypair: + name: "{{ cs_resource_prefix }}-sshkey-prj" + project: "{{ cs_resource_prefix }}-prj" + register: sshkey +- name: verify setup ssh key in project + assert: + that: + - sshkey is successful + +- name: setup affinity group in project + ngine_io.cloudstack.affinitygroup: + name: "{{ cs_resource_prefix }}-ag-prj" + project: "{{ cs_resource_prefix }}-prj" + register: ag +- name: verify setup affinity group in project + assert: + that: + - ag is successful + +- name: setup security group in project + ngine_io.cloudstack.securitygroup: + name: "{{ cs_resource_prefix }}-sg-prj" + project: "{{ cs_resource_prefix }}-prj" + register: sg +- name: verify setup security group in project + assert: + that: + - sg is successful + +- name: test create instance in project in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + template: "{{ test_cs_instance_template }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + affinity_group: "{{ cs_resource_prefix }}-ag-prj" + security_group: "{{ cs_resource_prefix }}-sg-prj" + project: "{{ cs_resource_prefix }}-prj" + ssh_key: "{{ cs_resource_prefix }}-sshkey-prj" + tags: [] + register: instance + check_mode: true +- name: verify create instance in project in check mode + assert: + that: + - instance is changed + +- name: test create instance in project + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + template: "{{ test_cs_instance_template }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + affinity_group: "{{ cs_resource_prefix }}-ag-prj" + security_group: "{{ cs_resource_prefix }}-sg-prj" + project: "{{ cs_resource_prefix }}-prj" + ssh_key: "{{ cs_resource_prefix }}-sshkey-prj" + tags: [] + register: instance +- name: verify create instance in project + assert: + that: + - instance is changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.project == cs_resource_prefix + "-prj" + - instance.display_name == cs_resource_prefix + "-vm-" + instance_number + - instance.service_offering == test_cs_instance_offering_1 + - instance.state == "Running" + - instance.ssh_key == cs_resource_prefix + "-sshkey-prj" + - not instance.tags + +- name: test create instance in project idempotence + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + template: "{{ test_cs_instance_template }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + affinity_group: "{{ cs_resource_prefix }}-ag-prj" + security_group: "{{ cs_resource_prefix }}-sg-prj" + project: "{{ cs_resource_prefix }}-prj" + ssh_key: "{{ cs_resource_prefix }}-sshkey-prj" + tags: [] + register: instance +- name: verify create instance in project idempotence + assert: + that: + - instance is not changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.project == cs_resource_prefix + "-prj" + - instance.display_name == cs_resource_prefix + "-vm-" + instance_number + - instance.service_offering == test_cs_instance_offering_1 + - instance.state == "Running" + - instance.ssh_key == cs_resource_prefix + "-sshkey-prj" + - not instance.tags + +- name: test running instance in project not updated in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + service_offering: "{{ test_cs_instance_offering_2 }}" + project: "{{ cs_resource_prefix }}-prj" + register: instance + check_mode: true +- name: verify running instance in project not updated in check mode + assert: + that: + - instance is not changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.project == cs_resource_prefix + "-prj" + - instance.display_name == cs_resource_prefix + "-vm-" + instance_number + - instance.service_offering == test_cs_instance_offering_1 + - instance.state == "Running" + +- name: test running instance in project not updated + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + service_offering: "{{ test_cs_instance_offering_2 }}" + project: "{{ cs_resource_prefix }}-prj" + register: instance +- name: verify running instance in project not updated + assert: + that: + - instance is not changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.project == cs_resource_prefix + "-prj" + - instance.display_name == cs_resource_prefix + "-vm-" + instance_number + - instance.service_offering == test_cs_instance_offering_1 + - instance.state == "Running" + +- name: test stopping instance in project in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + project: "{{ cs_resource_prefix }}-prj" + state: stopped + register: instance + check_mode: true +- name: verify stopping instance in project in check mode + assert: + that: + - instance is changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.project == cs_resource_prefix + "-prj" + - instance.display_name == cs_resource_prefix + "-vm-" + instance_number + - instance.service_offering == test_cs_instance_offering_1 + - instance.state == "Running" + +- name: test stopping instance + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + project: "{{ cs_resource_prefix }}-prj" + state: stopped + register: instance +- name: verify stopping instance + assert: + that: + - instance is changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.project == cs_resource_prefix + "-prj" + - instance.display_name == cs_resource_prefix + "-vm-" + instance_number + - instance.service_offering == test_cs_instance_offering_1 + - instance.state == "Stopped" + +- name: test stopping instance in project idempotence + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + project: "{{ cs_resource_prefix }}-prj" + state: stopped + register: instance +- name: verify stopping instance in project idempotence + assert: + that: + - instance is not changed + - instance.state == "Stopped" + +- name: test updating stopped instance in project in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + display_name: "{{ cs_resource_prefix }}-display-{{ instance_number }}" + project: "{{ cs_resource_prefix }}-prj" + service_offering: "{{ test_cs_instance_offering_2 }}" + register: instance + check_mode: true +- name: verify updating stopped instance in project in check mode + assert: + that: + - instance is changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.project == cs_resource_prefix + "-prj" + - instance.display_name == cs_resource_prefix + "-vm-" + instance_number + - instance.service_offering == test_cs_instance_offering_1 + - instance.state == "Stopped" + +- name: test updating stopped instance + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + display_name: "{{ cs_resource_prefix }}-display-{{ instance_number }}" + project: "{{ cs_resource_prefix }}-prj" + service_offering: "{{ test_cs_instance_offering_2 }}" + register: instance +- name: verify updating stopped instance + assert: + that: + - instance is changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.project == cs_resource_prefix + "-prj" + - instance.display_name == cs_resource_prefix + "-display-" + instance_number + - instance.service_offering == test_cs_instance_offering_2 + - instance.state == "Stopped" + +- name: test updating stopped instance in project idempotence + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + display_name: "{{ cs_resource_prefix }}-display-{{ instance_number }}" + project: "{{ cs_resource_prefix }}-prj" + service_offering: "{{ test_cs_instance_offering_2 }}" + register: instance +- name: verify updating stopped instance in project idempotence + assert: + that: + - instance is not changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.project == cs_resource_prefix + "-prj" + - instance.display_name == cs_resource_prefix + "-display-" + instance_number + - instance.service_offering == test_cs_instance_offering_2 + - instance.state == "Stopped" + +- name: test starting instance in project in check mdoe + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + project: "{{ cs_resource_prefix }}-prj" + state: started + register: instance + check_mode: true +- name: verify starting instance in project in check mode + assert: + that: + - instance is changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.project == cs_resource_prefix + "-prj" + - instance.display_name == cs_resource_prefix + "-display-" + instance_number + - instance.service_offering == test_cs_instance_offering_2 + - instance.state == "Stopped" + +- name: test starting instance + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + project: "{{ cs_resource_prefix }}-prj" + state: started + register: instance +- name: verify starting instance + assert: + that: + - instance is changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.project == cs_resource_prefix + "-prj" + - instance.display_name == cs_resource_prefix + "-display-" + instance_number + - instance.service_offering == test_cs_instance_offering_2 + - instance.state == "Running" + +- name: test starting instance in project idempotence + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + project: "{{ cs_resource_prefix }}-prj" + state: started + register: instance +- name: verify starting instance in project idempotence + assert: + that: + - instance is not changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.project == cs_resource_prefix + "-prj" + - instance.display_name == cs_resource_prefix + "-display-" + instance_number + - instance.service_offering == test_cs_instance_offering_2 + - instance.state == "Running" + +- name: test force update running instance in project in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + project: "{{ cs_resource_prefix }}-prj" + force: true + register: instance + check_mode: true +- name: verify force update running instance in project in check mode + assert: + that: + - instance is changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.project == cs_resource_prefix + "-prj" + - instance.display_name == cs_resource_prefix + "-display-" + instance_number + - instance.service_offering == test_cs_instance_offering_2 + - instance.state == "Running" + +- name: test force update running instance + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + project: "{{ cs_resource_prefix }}-prj" + force: true + register: instance +- name: verify force update running instance + assert: + that: + - instance is changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.project == cs_resource_prefix + "-prj" + - instance.display_name == cs_resource_prefix + "-display-" + instance_number + - instance.service_offering == test_cs_instance_offering_1 + - instance.state == "Running" + +- name: test force update running instance in project idempotence + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + project: "{{ cs_resource_prefix }}-prj" + force: true + register: instance +- name: verify force update running instance in project idempotence + assert: + that: + - instance is not changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.project == cs_resource_prefix + "-prj" + - instance.display_name == cs_resource_prefix + "-display-" + instance_number + - instance.service_offering == test_cs_instance_offering_1 + - instance.state == "Running" + +- name: test restore instance in project in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + template: "{{ test_cs_instance_template }}" + project: "{{ cs_resource_prefix }}-prj" + state: restored + register: instance + check_mode: true +- name: verify restore instance in project in check mode + assert: + that: + - instance is changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.project == cs_resource_prefix + "-prj" + - instance.display_name == cs_resource_prefix + "-display-" + instance_number + - instance.service_offering == test_cs_instance_offering_1 + +- name: test restore instance in project + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + template: "{{ test_cs_instance_template }}" + project: "{{ cs_resource_prefix }}-prj" + state: restored + register: instance +- name: verify restore instance in project + assert: + that: + - instance is changed + - instance.name == cs_resource_prefix + "-vm-" + instance_number + - instance.project == cs_resource_prefix + "-prj" + - instance.display_name == cs_resource_prefix + "-display-" + instance_number + - instance.service_offering == test_cs_instance_offering_1 + +- name: test destroy instance in project in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + project: "{{ cs_resource_prefix }}-prj" + state: absent + register: instance + check_mode: true +- name: verify destroy instance in project in check mode + assert: + that: + - instance is changed + - instance.state != "Destroyed" + +- name: test destroy instance in project + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + project: "{{ cs_resource_prefix }}-prj" + state: absent + register: instance +- name: verify destroy instance in project + assert: + that: + - instance is changed + - instance.state == "Destroyed" + +- name: test destroy instance in project idempotence + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + project: "{{ cs_resource_prefix }}-prj" + state: absent + register: instance +- name: verify destroy instance in project idempotence + assert: + that: + - instance is not changed + +- name: test recover in project to stopped state and update a deleted instance in project in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + project: "{{ cs_resource_prefix }}-prj" + service_offering: "{{ test_cs_instance_offering_1 }}" + state: stopped + register: instance + check_mode: true +- name: verify test recover to stopped state and update a deleted instance in project in check mode + assert: + that: + - instance is changed + +- name: test recover to stopped state and update a deleted instance in project + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + project: "{{ cs_resource_prefix }}-prj" + service_offering: "{{ test_cs_instance_offering_1 }}" + state: stopped + register: instance +- name: verify test recover to stopped state and update a deleted instance in project + assert: + that: + - instance is changed + - instance.state == "Stopped" + - instance.service_offering == test_cs_instance_offering_1 + +- name: test recover to stopped state and update a deleted instance in project idempotence + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + project: "{{ cs_resource_prefix }}-prj" + service_offering: "{{ test_cs_instance_offering_1 }}" + state: stopped + register: instance +- name: verify test recover to stopped state and update a deleted instance in project idempotence + assert: + that: + - instance is not changed + - instance.state == "Stopped" + - instance.service_offering == test_cs_instance_offering_1 + +- name: test expunge instance in project in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + project: "{{ cs_resource_prefix }}-prj" + state: expunged + register: instance + check_mode: true +- name: verify test expunge instance in check mode + assert: + that: + - instance is changed + - instance.state == "Stopped" + - instance.service_offering == test_cs_instance_offering_1 + +- name: test expunge instance in project + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + project: "{{ cs_resource_prefix }}-prj" + state: expunged + register: instance +- name: verify test expunge instance in project + assert: + that: + - instance is changed + - instance.state == "Stopped" + - instance.service_offering == test_cs_instance_offering_1 + +- name: test expunge instance in project idempotence + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + project: "{{ cs_resource_prefix }}-prj" + state: expunged + register: instance +- name: verify test expunge instance in project idempotence + assert: + that: + - instance is not changed + +- name: cleanup ssh key in project + ngine_io.cloudstack.sshkeypair: + name: "{{ cs_resource_prefix }}-sshkey-prj" + project: "{{ cs_resource_prefix }}-prj" + state: absent + register: sshkey +- name: verify cleanup ssh key in project + assert: + that: + - sshkey is successful + +- name: cleanup affinity group in project + ngine_io.cloudstack.affinitygroup: + name: "{{ cs_resource_prefix }}-ag-prj" + project: "{{ cs_resource_prefix }}-prj" + state: absent + register: ag + until: ag is successful + retries: 20 + delay: 5 +- name: verify cleanup affinity group in project + assert: + that: + - ag is successful + +- name: cleanup security group in project ...take a while unless instance in project is expunged + ngine_io.cloudstack.securitygroup: + name: "{{ cs_resource_prefix }}-sg-prj" + project: "{{ cs_resource_prefix }}-prj" + state: absent + register: sg + until: sg is successful + retries: 100 + delay: 10 +- name: verify cleanup security group in project + assert: + that: + - sg is successful diff --git a/tests/integration/targets/instance/tasks/setup.yml b/tests/integration/targets/instance/tasks/setup.yml new file mode 100644 index 00000000..9523f214 --- /dev/null +++ b/tests/integration/targets/instance/tasks/setup.yml @@ -0,0 +1,27 @@ +--- +- name: setup ssh key + ngine_io.cloudstack.ssh_key: + name: "{{ cs_resource_prefix }}-sshkey" + register: sshkey +- name: verify setup ssh key + assert: + that: + - sshkey is successful + +- name: setup affinity group + ngine_io.cloudstack.affinity_group: + name: "{{ cs_resource_prefix }}-ag" + register: ag +- name: verify setup affinity group + assert: + that: + - ag is successful + +- name: setup security group + ngine_io.cloudstack.security_group: + name: "{{ cs_resource_prefix }}-sg" + register: sg +- name: verify setup security group + assert: + that: + - sg is successful diff --git a/tests/integration/targets/instance/tasks/sshkeys.yml b/tests/integration/targets/instance/tasks/sshkeys.yml new file mode 100644 index 00000000..4bb8f140 --- /dev/null +++ b/tests/integration/targets/instance/tasks/sshkeys.yml @@ -0,0 +1,181 @@ +--- +- name: test update instance ssh key non existent + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-sshkey" + zone: "{{ cs_common_zone_basic }}" + ssh_key: "{{ cs_resource_prefix }}-sshkey-does-not-exist" + template: "{{ test_cs_instance_template }}" + force: true + register: instance + ignore_errors: true +- name: verify update instance ssh key non existent + assert: + that: + - instance is failed + - 'instance.msg == "SSH key not found:" + cs_resource_prefix + "-sshkey-does-not-exist"' + +- name: test create instance without keypair in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-sshkey" + zone: "{{ cs_common_zone_basic }}" + template: "{{ test_cs_instance_template }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + check_mode: true + register: instance +- name: verify create instance without keypair in check mode + assert: + that: + - instance is successful + - instance is changed + +- name: test create instance without keypair + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-sshkey" + zone: "{{ cs_common_zone_basic }}" + template: "{{ test_cs_instance_template }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + register: instance +- name: verify create instance without keypair + assert: + that: + - instance is successful + - instance is changed + - instance.ssh_keys is not defined + +- name: test create instance without keypair idempotence + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-sshkey" + zone: "{{ cs_common_zone_basic }}" + template: "{{ test_cs_instance_template }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + register: instance +- name: verify create instance without keypair idempotence + assert: + that: + - instance is successful + - instance is not changed + - instance.ssh_keys is not defined + +- name: setup ssh key2 + ngine_io.cloudstack.ssh_key: + name: "{{ cs_resource_prefix }}-sshkey2" + register: sshkey +- name: verify setup ssh key2 + assert: + that: + - sshkey is successful + +- name: test update instance ssh key2 in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-sshkey" + zone: "{{ cs_common_zone_basic }}" + ssh_key: "{{ cs_resource_prefix }}-sshkey2" + force: true + check_mode: true + register: instance +- name: verify update instance ssh key2 in check mode + assert: + that: + - instance is changed + - instance.ssh_key is not defined + +- name: test update instance ssh key2 + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-sshkey" + zone: "{{ cs_common_zone_basic }}" + ssh_key: "{{ cs_resource_prefix }}-sshkey2" + force: true + register: instance +- name: verify update instance ssh key2 + assert: + that: + - instance is changed + - instance.ssh_key == cs_resource_prefix + "-sshkey2" + +- name: test update instance ssh key2 idempotence + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-sshkey" + zone: "{{ cs_common_zone_basic }}" + ssh_key: "{{ cs_resource_prefix }}-sshkey2" + force: true + register: instance +- name: verify update instance ssh key2 idempotence + assert: + that: + - instance is not changed + - instance.ssh_key == cs_resource_prefix + "-sshkey2" + +- name: cleanup ssh key2 + ngine_io.cloudstack.ssh_key: + name: "{{ cs_resource_prefix }}-sshkey2" + state: absent + register: sshkey2 +- name: verify cleanup ssh key2 + assert: + that: + - sshkey2 is successful + +- name: test update instance ssh key2 idempotence2 + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-sshkey" + zone: "{{ cs_common_zone_basic }}" + ssh_key: "{{ cs_resource_prefix }}-sshkey2" + force: true + register: instance + ignore_errors: true +- name: verify update instance ssh key2 idempotence2 + assert: + that: + - instance is failed + - 'instance.msg == "SSH key not found: {{ cs_resource_prefix }}-sshkey2"' + +- name: test update instance ssh key in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-sshkey" + zone: "{{ cs_common_zone_basic }}" + ssh_key: "{{ cs_resource_prefix }}-sshkey" + force: true + check_mode: true + register: instance +- name: verify update instance ssh key in check mode + assert: + that: + - instance is changed + - instance.ssh_keys is not defined + +- name: test update instance ssh key + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-sshkey" + zone: "{{ cs_common_zone_basic }}" + ssh_key: "{{ cs_resource_prefix }}-sshkey" + force: true + register: instance +- name: verify update instance ssh key + assert: + that: + - instance is changed + - "'{{ cs_resource_prefix }}-sshkey' in instance.ssh_keys" + +- name: test update instance ssh key idempotence + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-sshkey" + zone: "{{ cs_common_zone_basic }}" + ssh_key: "{{ cs_resource_prefix }}-sshkey" + force: true + register: instance +- name: verify update instance ssh key idempotence + assert: + that: + - instance is not changed + - "'{{ cs_resource_prefix }}-sshkey' in instance.ssh_keys" + +- name: cleanup expunge instance + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-sshkey" + zone: "{{ cs_common_zone_basic }}" + state: expunged + register: instance +- name: verify cleanup expunge instance + assert: + that: + - instance is successful diff --git a/tests/integration/targets/instance/tasks/tags.yml b/tests/integration/targets/instance/tasks/tags.yml new file mode 100644 index 00000000..cf1c4fd6 --- /dev/null +++ b/tests/integration/targets/instance/tasks/tags.yml @@ -0,0 +1,142 @@ +--- +- name: test add tags to instance in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + template: "{{ test_cs_instance_template }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + tags: + - key: "{{ cs_resource_prefix }}-tag1" + value: "{{ cs_resource_prefix }}-value1" + - key: "{{ cs_resource_prefix }}-tag2" + value: "{{ cs_resource_prefix }}-value2" + register: instance + check_mode: true +- name: verify add tags to instance in check mode + assert: + that: + - instance is changed + - not instance.tags + +- name: test add tags to instance + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + template: "{{ test_cs_instance_template }}" + service_offering: "{{ test_cs_instance_offering_1 }}" + tags: + - key: "{{ cs_resource_prefix }}-tag1" + value: "{{ cs_resource_prefix }}-value1" + - key: "{{ cs_resource_prefix }}-tag2" + value: "{{ cs_resource_prefix }}-value2" + register: instance +- name: verify add tags to instance + assert: + that: + - instance is changed + - instance.tags|length == 2 + - "instance.tags[0]['key'] in [ cs_resource_prefix + '-tag2', cs_resource_prefix + '-tag1' ]" + - "instance.tags[1]['key'] in [ cs_resource_prefix + '-tag2', cs_resource_prefix + '-tag1' ]" + - "instance.tags[0]['value'] in [ cs_resource_prefix + '-value2', cs_resource_prefix + '-value1' ]" + - "instance.tags[1]['value'] in [ cs_resource_prefix + '-value2', cs_resource_prefix + '-value1' ]" + +- name: test tags to instance idempotence + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + tags: + - key: "{{ cs_resource_prefix }}-tag2" + value: "{{ cs_resource_prefix }}-value2" + - key: "{{ cs_resource_prefix }}-tag1" + value: "{{ cs_resource_prefix }}-value1" + register: instance +- name: verify tags to instance idempotence + assert: + that: + - instance is not changed + - instance.tags|length == 2 + - "instance.tags[0]['key'] in [ cs_resource_prefix + '-tag2', cs_resource_prefix + '-tag1' ]" + - "instance.tags[1]['key'] in [ cs_resource_prefix + '-tag2', cs_resource_prefix + '-tag1' ]" + - "instance.tags[0]['value'] in [ cs_resource_prefix + '-value2', cs_resource_prefix + '-value1' ]" + - "instance.tags[1]['value'] in [ cs_resource_prefix + '-value2', cs_resource_prefix + '-value1' ]" + +- name: test change tags of instance in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + tags: + - key: "{{ cs_resource_prefix }}-tag2" + value: "{{ cs_resource_prefix }}-value2" + - key: "{{ cs_resource_prefix }}-tag3" + value: "{{ cs_resource_prefix }}-value3" + register: instance + check_mode: true +- name: verify tags to instance idempotence in check mode + assert: + that: + - instance is changed + - instance.tags|length == 2 + - "instance.tags[0]['key'] in [ cs_resource_prefix + '-tag2', cs_resource_prefix + '-tag1' ]" + - "instance.tags[1]['key'] in [ cs_resource_prefix + '-tag2', cs_resource_prefix + '-tag1' ]" + - "instance.tags[0]['value'] in [ cs_resource_prefix + '-value2', cs_resource_prefix + '-value1' ]" + - "instance.tags[1]['value'] in [ cs_resource_prefix + '-value2', cs_resource_prefix + '-value1' ]" + +- name: test change tags of instance + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + tags: + - key: "{{ cs_resource_prefix }}-tag2" + value: "{{ cs_resource_prefix }}-value2" + - key: "{{ cs_resource_prefix }}-tag3" + value: "{{ cs_resource_prefix }}-value3" + register: instance +- name: verify tags to instance idempotence + assert: + that: + - instance is changed + - instance.tags|length == 2 + - "instance.tags[0]['key'] in [ cs_resource_prefix + '-tag2', cs_resource_prefix + '-tag3' ]" + - "instance.tags[1]['key'] in [ cs_resource_prefix + '-tag2', cs_resource_prefix + '-tag3' ]" + - "instance.tags[0]['value'] in [ cs_resource_prefix + '-value2', cs_resource_prefix + '-value3' ]" + - "instance.tags[1]['value'] in [ cs_resource_prefix + '-value2', cs_resource_prefix + '-value3' ]" + +- name: test not touch tags of instance if no param tags + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + register: instance +- name: verify not touch tags of instance if no param tags + assert: + that: + - instance is not changed + - instance.tags|length == 2 + - "instance.tags[0]['key'] in [ cs_resource_prefix + '-tag2', cs_resource_prefix + '-tag3' ]" + - "instance.tags[1]['key'] in [ cs_resource_prefix + '-tag2', cs_resource_prefix + '-tag3' ]" + - "instance.tags[0]['value'] in [ cs_resource_prefix + '-value2', cs_resource_prefix + '-value3' ]" + - "instance.tags[1]['value'] in [ cs_resource_prefix + '-value2', cs_resource_prefix + '-value3' ]" + +- name: test remove tags in check mode + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + tags: [] + register: instance + check_mode: true +- name: verify remove tags in check mode + assert: + that: + - instance is changed + - instance.tags|length != 0 + +- name: test remove tags + ngine_io.cloudstack.instance: + name: "{{ cs_resource_prefix }}-vm-{{ instance_number }}" + zone: "{{ cs_common_zone_basic }}" + tags: [] + register: instance +- name: verify remove tags + assert: + that: + - instance is changed + - instance.tags|length == 0