From f1ef61da4ed8a07be2ad1211de7b4ba1bba44156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Moser?= Date: Sat, 5 Aug 2017 10:33:01 +0200 Subject: [PATCH] cloudstack: cs_domain: tests: add update tests (#27791) --- .../modules/cloud/cloudstack/cs_domain.py | 38 +++--- .../targets/cs_domain/tasks/main.yml | 108 +++++++++++++++--- 2 files changed, 110 insertions(+), 36 deletions(-) diff --git a/lib/ansible/modules/cloud/cloudstack/cs_domain.py b/lib/ansible/modules/cloud/cloudstack/cs_domain.py index 1cacd6a0c7e..e3dc6b8eb17 100644 --- a/lib/ansible/modules/cloud/cloudstack/cs_domain.py +++ b/lib/ansible/modules/cloud/cloudstack/cs_domain.py @@ -40,13 +40,10 @@ options: network_domain: description: - Network domain for networks in the domain. - required: false - default: null clean_up: description: - Clean up all domain resources like child domains and accounts. - Considered on C(state=absent). - required: false default: false state: description: @@ -57,29 +54,28 @@ options: poll_async: description: - Poll async jobs until job has finished. - required: false default: true extends_documentation_fragment: cloudstack ''' EXAMPLES = ''' -# Create a domain -local_action: - module: cs_domain - path: ROOT/customers - network_domain: customers.example.com - -# Create another subdomain -local_action: - module: cs_domain - path: ROOT/customers/xy - network_domain: xy.customers.example.com - -# Remove a domain -local_action: - module: cs_domain - path: ROOT/customers/xy - state: absent +- name: Create a domain + local_action: + module: cs_domain + path: ROOT/customers + network_domain: customers.example.com + +- name: Create another subdomain + local_action: + module: cs_domain + path: ROOT/customers/xy + network_domain: xy.customers.example.com + +- name: Remove a domain + local_action: + module: cs_domain + path: ROOT/customers/xy + state: absent ''' RETURN = ''' diff --git a/test/integration/targets/cs_domain/tasks/main.yml b/test/integration/targets/cs_domain/tasks/main.yml index 0a523663b49..273d1295d7f 100644 --- a/test/integration/targets/cs_domain/tasks/main.yml +++ b/test/integration/targets/cs_domain/tasks/main.yml @@ -1,6 +1,8 @@ --- - name: setup - cs_domain: path={{ cs_resource_prefix }}_domain state=absent + cs_domain: + path: "{{ cs_resource_prefix }}_domain" + state: absent register: dom - name: verify setup assert: @@ -18,7 +20,8 @@ - 'dom.msg == "missing required arguments: path"' - name: test fail if ends with / - cs_domain: path={{ cs_resource_prefix }}_domain/ + cs_domain: + path: "{{ cs_resource_prefix }}_domain/" register: dom ignore_errors: true - name: verify results of fail if ends with / @@ -28,7 +31,8 @@ - dom.msg == "Path '{{ cs_resource_prefix }}_domain/' must not end with /" - name: test create a domain in check mode - cs_domain: path={{ cs_resource_prefix }}_domain + cs_domain: + path: "{{ cs_resource_prefix }}_domain" register: dom check_mode: true - name: verify results of test create a domain in check mode @@ -37,7 +41,8 @@ - dom|changed - name: test create a domain - cs_domain: path={{ cs_resource_prefix }}_domain + cs_domain: + path: "{{ cs_resource_prefix }}_domain" register: dom - name: verify results of test create a domain assert: @@ -47,7 +52,8 @@ - dom.name == "{{ cs_resource_prefix }}_domain" - name: test create a domain idempotence - cs_domain: path={{ cs_resource_prefix }}_domain + cs_domain: + path: "{{ cs_resource_prefix }}_domain" register: dom - name: verify results of test create a domain idempotence assert: @@ -56,6 +62,17 @@ - dom.path == "ROOT/{{ cs_resource_prefix }}_domain" - dom.name == "{{ cs_resource_prefix }}_domain" +- name: test create a domain idempotence2 + cs_domain: + path: "/{{ cs_resource_prefix }}_domain" + register: dom +- name: verify results of test create a domain idempotence2 + assert: + that: + - not dom|changed + - dom.path == "ROOT/{{ cs_resource_prefix }}_domain" + - dom.name == "{{ cs_resource_prefix }}_domain" + - name: test fail to create a subdomain for inexistent domain cs_domain: path: ROOT/inexistent/{{ cs_resource_prefix }}_subdomain @@ -68,7 +85,8 @@ - dom.msg == "Parent domain path ROOT/inexistent does not exist" - name: test create a subdomain in check mode - cs_domain: path=ROOT/{{ cs_resource_prefix }}_domain/{{ cs_resource_prefix }}_subdomain + cs_domain: + path: ROOT/{{ cs_resource_prefix }}_domain/{{ cs_resource_prefix }}_subdomain register: dom check_mode: true - name: verify results of test create a domain in check mode @@ -77,7 +95,8 @@ - dom|changed - name: test create a subdomain - cs_domain: path=ROOT/{{ cs_resource_prefix }}_domain/{{ cs_resource_prefix }}_subdomain + cs_domain: + path: ROOT/{{ cs_resource_prefix }}_domain/{{ cs_resource_prefix }}_subdomain register: dom - name: verify results of test create a domain assert: @@ -87,15 +106,60 @@ - dom.name == "{{ cs_resource_prefix }}_subdomain" - name: test create a subdomain idempotence - cs_domain: path=ROOT/{{ cs_resource_prefix }}_domain/{{ cs_resource_prefix }}_subdomain + cs_domain: + path: ROOT/{{ cs_resource_prefix }}_domain/{{ cs_resource_prefix }}_subdomain register: dom - name: verify results of test create a subdomain idempotence assert: that: - not dom|changed + - dom.path == "ROOT/{{ cs_resource_prefix }}_domain/{{ cs_resource_prefix }}_subdomain" + - dom.name == "{{ cs_resource_prefix }}_subdomain" + +- name: test update a subdomain in check mode + cs_domain: + path: ROOT/{{ cs_resource_prefix }}_domain/{{ cs_resource_prefix }}_subdomain + network_domain: domain.example.com + register: dom + check_mode: true +- name: verify results of test update a subdomain in check mode + assert: + that: + - dom|changed + - dom.network_domain is undefined + - dom.path == "ROOT/{{ cs_resource_prefix }}_domain/{{ cs_resource_prefix }}_subdomain" + - dom.name == "{{ cs_resource_prefix }}_subdomain" + +- name: test update a subdomain + cs_domain: + path: ROOT/{{ cs_resource_prefix }}_domain/{{ cs_resource_prefix }}_subdomain + network_domain: domain.example.com + register: dom +- name: verify results of test update a subdomain + assert: + that: + - dom|changed + - dom.network_domain == "domain.example.com" + - dom.path == "ROOT/{{ cs_resource_prefix }}_domain/{{ cs_resource_prefix }}_subdomain" + - dom.name == "{{ cs_resource_prefix }}_subdomain" + +- name: test update a subdomain idempotence + cs_domain: + path: ROOT/{{ cs_resource_prefix }}_domain/{{ cs_resource_prefix }}_subdomain + network_domain: domain.example.com + register: dom +- name: verify results of test update a subdomain idempotence + assert: + that: + - not dom|changed + - dom.network_domain == "domain.example.com" + - dom.path == "ROOT/{{ cs_resource_prefix }}_domain/{{ cs_resource_prefix }}_subdomain" + - dom.name == "{{ cs_resource_prefix }}_subdomain" - name: test delete a subdomain in check mode - cs_domain: path=ROOT/{{ cs_resource_prefix }}_domain/{{ cs_resource_prefix }}_subdomain state=absent + cs_domain: + path: ROOT/{{ cs_resource_prefix }}_domain/{{ cs_resource_prefix }}_subdomain + state: absent register: dom check_mode: true - name: verify results of test delete a subdomain in check mode @@ -106,7 +170,9 @@ - dom.name == "{{ cs_resource_prefix }}_subdomain" - name: test delete a subdomain - cs_domain: path=ROOT/{{ cs_resource_prefix }}_domain/{{ cs_resource_prefix }}_subdomain state=absent + cs_domain: + path: ROOT/{{ cs_resource_prefix }}_domain/{{ cs_resource_prefix }}_subdomain + state: absent register: dom - name: verify results of test delete a subdomain assert: @@ -116,7 +182,9 @@ - dom.name == "{{ cs_resource_prefix }}_subdomain" - name: test delete a subdomain idempotence - cs_domain: path=ROOT/{{ cs_resource_prefix }}_domain/{{ cs_resource_prefix }}_subdomain state=absent + cs_domain: + path: ROOT/{{ cs_resource_prefix }}_domain/{{ cs_resource_prefix }}_subdomain + state: absent register: dom - name: verify results of test delete a subdomain idempotence assert: @@ -124,7 +192,8 @@ - not dom|changed - name: test create a subdomain 2 - cs_domain: path=ROOT/{{ cs_resource_prefix }}_domain/{{ cs_resource_prefix }}_subdomain + cs_domain: + path: ROOT/{{ cs_resource_prefix }}_domain/{{ cs_resource_prefix }}_subdomain register: dom - name: verify results of test create a subdomain 2 assert: @@ -134,7 +203,10 @@ - dom.name == "{{ cs_resource_prefix }}_subdomain" - name: test delete a domain with clean up in check mode - cs_domain: path=ROOT/{{ cs_resource_prefix }}_domain state=absent clean_up=true + cs_domain: + path: ROOT/{{ cs_resource_prefix }}_domain + state: absent + clean_up: true register: dom check_mode: true - name: verify results of test delete a domain with clean up in check mode @@ -145,7 +217,10 @@ - dom.name == "{{ cs_resource_prefix }}_domain" - name: test delete a domain with clean up - cs_domain: path=ROOT/{{ cs_resource_prefix }}_domain state=absent clean_up=true + cs_domain: + path: ROOT/{{ cs_resource_prefix }}_domain + state: absent + clean_up: true register: dom - name: verify results of test delete a domain with clean up assert: @@ -155,7 +230,10 @@ - dom.name == "{{ cs_resource_prefix }}_domain" - name: test delete a domain with clean up idempotence - cs_domain: path=ROOT/{{ cs_resource_prefix }}_domain state=absent clean_up=true + cs_domain: + path: ROOT/{{ cs_resource_prefix }}_domain + state: absent + clean_up: true register: dom - name: verify results of test delete a domain with clean up idempotence assert: