diff --git a/.travis.yml b/.travis.yml index cd9e661..22a5838 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,8 @@ script: - ansible-playbook -v -i tests/inventory tests/3scale-saas-with-hosted-apicast-oidc.yml - ansible-playbook -v -i tests/inventory tests/3scale-saas-with-hosted-apicast-with-basePath.yml - ansible-playbook -v -i tests/inventory tests/3scale-saas-with-hosted-apicast-multi-environment.yml +- ansible-playbook -v -i tests/inventory tests/3scale-saas-with-hosted-apicast-with-smoketest-in-extra-vars.yml +- ansible-playbook -v -i tests/inventory tests/3scale-saas-with-hosted-apicast-without-smoketest.yml env: global: # travis encrypt "THREESCALE_INVENTORY=$(yaml2json tests/3scale-inventory.yaml|base64)" diff --git a/defaults/main.yml b/defaults/main.yml index 3d82ac8..d27647e 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -48,7 +48,7 @@ threescale_cicd_default_application_appid: '{{ (threescale_cicd_default_applicat threescale_cicd_default_application_appsecret: '{{ (''secret'' ~ threescale_cicd_default_application_name ~ threescale_cicd_api_system_name ~ threescale_cicd_access_token)|hash(''sha1'') }}' # The OpenAPI Operation to use for the smoketest -threescale_cicd_openapi_smoketest_operation: '{{ threescale_cicd_openapi_file_content|json_query(''paths.*.get[? "x-threescale-smoketests-operation" ].operationId|[0]'')|default("")|regex_replace(''[^0-9a-zA-Z_]+'', ''_'') }}' +threescale_cicd_openapi_smoketest_operation: '{{ threescale_cicd_openapi_file_content|json_query(''paths.*.get[? "x-threescale-smoketests-operation" ].operationId'')|first|default("")|regex_replace(''[^0-9a-zA-Z_]+'', ''_'') }}' ## ## OpenAPI Specification File parsing diff --git a/tasks/main.yml b/tasks/main.yml index 232be36..5efbb7c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -36,13 +36,13 @@ # Create or update the default application if smoke tests are needed - include_tasks: steps/default_application.yml - when: 'threescale_cicd_openapi_smoketest_path is defined and threescale_cicd_application_plans is defined' + when: 'threescale_cicd_openapi_smoketest_operation|length > 0 and threescale_cicd_application_plans is defined' # Run smoke tests on the staging gateway - include_tasks: steps/smoke_test.yml vars: threescale_cicd_smoke_test_env: staging - when: 'threescale_cicd_openapi_smoketest_path is defined and threescale_cicd_application_plans is defined' + when: 'threescale_cicd_openapi_smoketest_operation|length > 0 and threescale_cicd_application_plans is defined' # Promote to production - import_tasks: steps/promote.yml @@ -51,7 +51,7 @@ - include_tasks: steps/smoke_test.yml vars: threescale_cicd_smoke_test_env: production - when: 'threescale_cicd_openapi_smoketest_path is defined and threescale_cicd_application_plans is defined' + when: 'threescale_cicd_openapi_smoketest_operation|length > 0 and threescale_cicd_application_plans is defined' # Delete the metrics that are not needed anymore - import_tasks: steps/cleanup_metrics.yml diff --git a/tests/3scale-saas-with-hosted-apicast-with-smoketest-in-extra-vars.yaml b/tests/3scale-saas-with-hosted-apicast-with-smoketest-in-extra-vars.yaml new file mode 100644 index 0000000..310ca6a --- /dev/null +++ b/tests/3scale-saas-with-hosted-apicast-with-smoketest-in-extra-vars.yaml @@ -0,0 +1,16 @@ +--- + +- name: Deploy the Echo API to a 3scale SaaS instance, with hosted APIcasts and no smoketests + hosts: threescale + gather_facts: no + vars: + threescale_cicd_openapi_smoketest_operation: Echo + threescale_cicd_openapi_file: '{{ playbook_dir }}/api/echo-api-bare.yaml' + tasks: + # Deploy the service + - import_role: + name: 'nmasse-itix.threescale-cicd' + # Delete the service + - import_role: + name: 'nmasse-itix.threescale-cicd' + tasks_from: 'cleanup' diff --git a/tests/3scale-saas-with-hosted-apicast-without-smoketest.yaml b/tests/3scale-saas-with-hosted-apicast-without-smoketest.yaml new file mode 100644 index 0000000..e79c6ba --- /dev/null +++ b/tests/3scale-saas-with-hosted-apicast-without-smoketest.yaml @@ -0,0 +1,16 @@ +--- + +- name: Deploy the Echo API to a 3scale SaaS instance, with hosted APIcasts and no smoketests + hosts: threescale + gather_facts: no + vars: + # There is no "threescale_cicd_openapi_smoketest_operation" variable + threescale_cicd_openapi_file: '{{ playbook_dir }}/api/echo-api-bare.yaml' + tasks: + # Deploy the service + - import_role: + name: 'nmasse-itix.threescale-cicd' + # Delete the service + - import_role: + name: 'nmasse-itix.threescale-cicd' + tasks_from: 'cleanup' diff --git a/tests/api/echo-api-bare.yaml b/tests/api/echo-api-bare.yaml new file mode 100644 index 0000000..6c19998 --- /dev/null +++ b/tests/api/echo-api-bare.yaml @@ -0,0 +1,33 @@ +swagger: '2.0' +info: + title: 'Echo API' + description: 'A very simple API.' + contact: + name: 'Nicolas MASSE' + url: 'http://github.com/nmasse-itix' + email: nmasse@redhat.com + license: + name: 'MIT License' + url: 'https://opensource.org/licenses/MIT' + version: '1.0' +host: 'echo-api.3scale.net' +schemes: +- http +paths: + /: + get: + operationId: Echo + tags: + - echo + summary: 'Get an echo' + description: 'Get an echo from the server' + responses: + 200: + description: 'An Echo from the server' +security: +- apikey: [] +securityDefinitions: + apikey: + name: api-key + in: header + type: apiKey