From 43e43e650b0978272f65f713dfea9932fdb56dc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Mass=C3=A9?= Date: Wed, 25 Apr 2018 21:11:59 +0200 Subject: [PATCH] re-organize tests --- .travis.yml | 4 ++-- tests/.meta/inventory | 1 - .../roles/threescale-cicd | 1 - tests/01-3scale-SaaS-Apicast-Saas/test.yml | 9 --------- tests/3scale-saas-with-hosted-apicast.yml | 14 +++++++++++++ .../echo-api.yaml | 0 tests/cleanup.yaml | 20 +++++++++++++++++++ .../inventory.j2 | 0 tests/roles/nmasse-itix.threescale-cicd | 1 + .../main.yml => write-inventory-files.yml} | 8 +++++--- 10 files changed, 42 insertions(+), 16 deletions(-) delete mode 100644 tests/.meta/inventory delete mode 120000 tests/01-3scale-SaaS-Apicast-Saas/roles/threescale-cicd delete mode 100644 tests/01-3scale-SaaS-Apicast-Saas/test.yml create mode 100644 tests/3scale-saas-with-hosted-apicast.yml rename tests/{01-3scale-SaaS-Apicast-Saas => api}/echo-api.yaml (100%) create mode 100644 tests/cleanup.yaml rename tests/{01-3scale-SaaS-Apicast-Saas => }/inventory.j2 (100%) create mode 120000 tests/roles/nmasse-itix.threescale-cicd rename tests/{.meta/main.yml => write-inventory-files.yml} (86%) diff --git a/.travis.yml b/.travis.yml index 47cf445..65d3f6a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,8 @@ install: - pip install ansible==2.4.0 - pip install jmespath script: -- ansible-playbook -i tests/.meta/inventory tests/.meta/main.yml -- ansible-playbook -i tests/01-*/inventory tests/01-*/test.yml +- ansible-playbook tests/write-inventory-files.yml +- ansible-playbook -i tests/inventory tests/3scale-saas-with-hosted-apicast.yml env: global: secure: 0Ov2beobc70Avi7EW634Jn7Y/ILTiql/llnfTkWBlaHLQCmI//xBON95qLjaksoBqCo0AMYRUAM2Rek50qNMqOxgM+AgYCSwZeRwZnIwj+J4FHrb6kHpFGPK64iu/AQROjFKOPwI/0vl7kmUYEuQRwTbLwuS4gxxm7COpje436sJfRb6yag1dRzLOaXade2pr8ojdeByw6PyJGkJQ6To/gCyJ+UOTqhwQLTkqK+WcnrcTCRAUauVDfJr+8wXz9IZJp1hX5NIAcv8BFSs2KQWU90YKQ2B2ruZnmY4CBlvE+xh/O0ltssphDBy+b4nqwVNdb+3I1sawKGGAmawz1pBc2rqE28CmMhuUXdLkJ5oUOKsBfiygDMh7j5+fqTanyeOVMYHOZ6U5zNaQiU+aFdnqexXgnj19Yn/3cpkceQgUwyTtZj63lkUVB2mk7rPcpprVBNmCUr2SfRpHA943NtERIbB4pRRUIOoDOcR8ngj7NZaAt9crghP7pz6DKwT9PVkjzJFODqAQ4lGtOcZ8db4TUfpmVCvQIhYXxZYZX6mDNNFUTreDRJVjfXUMjvhCeub4nJ86ODcpShDFlVh+clVBcWrmlwR4EvEuy0kLaALZFS2C/Y6xTDdPI1b4He/2Ciefd1EPdwM+hmbZMk0T0+H7TfK86/nnPBNw58q00k3+dA= diff --git a/tests/.meta/inventory b/tests/.meta/inventory deleted file mode 100644 index 2302eda..0000000 --- a/tests/.meta/inventory +++ /dev/null @@ -1 +0,0 @@ -localhost ansible_connection=local diff --git a/tests/01-3scale-SaaS-Apicast-Saas/roles/threescale-cicd b/tests/01-3scale-SaaS-Apicast-Saas/roles/threescale-cicd deleted file mode 120000 index a8a4f8c..0000000 --- a/tests/01-3scale-SaaS-Apicast-Saas/roles/threescale-cicd +++ /dev/null @@ -1 +0,0 @@ -../../.. \ No newline at end of file diff --git a/tests/01-3scale-SaaS-Apicast-Saas/test.yml b/tests/01-3scale-SaaS-Apicast-Saas/test.yml deleted file mode 100644 index 85b77c8..0000000 --- a/tests/01-3scale-SaaS-Apicast-Saas/test.yml +++ /dev/null @@ -1,9 +0,0 @@ ---- - -- name: Deploy the Echo API to a 3scale SaaS instance, with hosted APIcasts - hosts: threescale - gather_facts: no - vars: - threescale_cicd_openapi_file: '{{ playbook_dir }}/echo-api.yaml' - roles: - - threescale-cicd diff --git a/tests/3scale-saas-with-hosted-apicast.yml b/tests/3scale-saas-with-hosted-apicast.yml new file mode 100644 index 0000000..d7956ea --- /dev/null +++ b/tests/3scale-saas-with-hosted-apicast.yml @@ -0,0 +1,14 @@ +--- + +- name: Deploy the Echo API to a 3scale SaaS instance, with hosted APIcasts + hosts: threescale + gather_facts: no + vars: + threescale_cicd_openapi_file: '{{ playbook_dir }}/api/echo-api.yaml' + roles: + # Test first deployment + - { name: 'nmasse-itix.threescale-cicd', vars: { 'round': 1 } } + # Verify idempotence + - { name: 'nmasse-itix.threescale-cicd', vars: { 'round': 2 } } + post_tasks: + - import_tasks: 'cleanup.yaml' diff --git a/tests/01-3scale-SaaS-Apicast-Saas/echo-api.yaml b/tests/api/echo-api.yaml similarity index 100% rename from tests/01-3scale-SaaS-Apicast-Saas/echo-api.yaml rename to tests/api/echo-api.yaml diff --git a/tests/cleanup.yaml b/tests/cleanup.yaml new file mode 100644 index 0000000..377c3ed --- /dev/null +++ b/tests/cleanup.yaml @@ -0,0 +1,20 @@ +--- + +- name: Delete the created service and any dependent object + uri: + url: 'https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }}.json?access_token={{ threescale_cicd_access_token|urlencode }}' + validate_certs: no + method: DELETE + status_code: 200 + register: threescale_cicd_tmpresponse + changed_when: 'threescale_cicd_tmpresponse.status == 200' + when: 'threescale_cicd_api_service_id is defined' +- name: Delete the created ActiveDocs + uri: + url: 'https://{{ inventory_hostname }}/admin/api/active_docs/{{ threescale_cicd_api_activedocs_id }}.json?access_token={{ threescale_cicd_access_token|urlencode }}' + validate_certs: no + method: DELETE + status_code: 200 + register: threescale_cicd_tmpresponse + changed_when: 'threescale_cicd_tmpresponse.status == 200' + when: 'threescale_cicd_api_activedocs_id is defined' diff --git a/tests/01-3scale-SaaS-Apicast-Saas/inventory.j2 b/tests/inventory.j2 similarity index 100% rename from tests/01-3scale-SaaS-Apicast-Saas/inventory.j2 rename to tests/inventory.j2 diff --git a/tests/roles/nmasse-itix.threescale-cicd b/tests/roles/nmasse-itix.threescale-cicd new file mode 120000 index 0000000..c25bddb --- /dev/null +++ b/tests/roles/nmasse-itix.threescale-cicd @@ -0,0 +1 @@ +../.. \ No newline at end of file diff --git a/tests/.meta/main.yml b/tests/write-inventory-files.yml similarity index 86% rename from tests/.meta/main.yml rename to tests/write-inventory-files.yml index 06bd16c..1fe066a 100644 --- a/tests/.meta/main.yml +++ b/tests/write-inventory-files.yml @@ -3,6 +3,8 @@ - name: Write the inventory files for the included test cases hosts: localhost gather_facts: no + vars: + ansible_connection: local tasks: - set_fact: threescale_inventory: '{{ lookup(''env'', ''THREESCALE_INVENTORY'')|b64decode|from_json }}' @@ -14,9 +16,9 @@ - name: Find the Jinja2 templates to process find: - paths: '{{ playbook_dir }}/../' - patterns: 'inventory.j2' - recurse: yes + paths: '{{ playbook_dir }}' + patterns: '*.j2' + recurse: no register: templates - name: Process the Jinja2 templates