Skip to content

Commit

Permalink
Improve the CI tests (#42)
Browse files Browse the repository at this point in the history
#31 : CI tests are run against SaaS, with hosted and self-managed APIcast + on-premise AMP 2.3
#29 : Fix the CORS smoketests that were failing
#41 : Make sure the playbook did not expose the 3scale access token in the output
  • Loading branch information
nmasse-itix authored Jan 31, 2019
1 parent fc1785e commit f22a0fc
Show file tree
Hide file tree
Showing 53 changed files with 513 additions and 56 deletions.
26 changes: 14 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,30 @@ language: python
matrix:
include:
- python: '2.7'
env: ANSIBLE_VERSION=2.4.6 THREESCALE_POOL=0
env: ANSIBLE_VERSION=2.4.6 THREESCALE_ENV=saas
- python: '2.7'
env: ANSIBLE_VERSION=2.4.6 THREESCALE_ENV=saas-apicast-selfmanaged
- python: '2.7'
env: ANSIBLE_VERSION=2.4.6 THREESCALE_ENV=onpremise-2.3
- python: '3.6'
env: ANSIBLE_VERSION=2.7.5 THREESCALE_ENV=saas
- python: '3.6'
env: ANSIBLE_VERSION=2.7.5 THREESCALE_ENV=saas-apicast-selfmanaged
- python: '3.6'
env: ANSIBLE_VERSION=2.7.5 THREESCALE_POOL=1
env: ANSIBLE_VERSION=2.7.5 THREESCALE_ENV=onpremise-2.3
install:
- pip install ansible==$ANSIBLE_VERSION
- pip install jmespath
# Pre-install go-swagger locally since it cannot be fetched from the Travis-CI
# infrastructures because of rate limits imposed by GitHub on its API.
- mkdir tests/bin/ && curl -L -o tests/bin/swagger https://github.com/go-swagger/go-swagger/releases/download/0.16.0/swagger_linux_amd64 && chmod 755 tests/bin/swagger
- mkdir -p tests/test-cases/bin/ && curl -L -o tests/test-cases/bin/swagger https://github.com/go-swagger/go-swagger/releases/download/0.16.0/swagger_linux_amd64 && chmod 755 tests/test-cases/bin/swagger
script:
- ansible-playbook tests/write-inventory-files.yml
- ansible-playbook -v -i tests/inventory tests/3scale-saas-with-hosted-apicast-apikey.yml
- 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
- tests/run-tests.sh
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
branches:
except:
- /^dev.*/
before_install:
- openssl aes-256-cbc -K $encrypted_7bf6043000c3_key -iv $encrypted_7bf6043000c3_iv
-in tests/3scale-inventory.yaml.enc -out tests/3scale-inventory.yaml -d
# travis encrypt-file tests/3scale-inventory.yaml tests/3scale-inventory.yaml.enc
- openssl aes-256-cbc -K $encrypted_5ba3c614c7e1_key -iv $encrypted_5ba3c614c7e1_iv -in tests/3scale-inventory.yaml.enc -out tests/3scale-inventory.yaml -d
7 changes: 7 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ threescale_cicd_application_plans:
state: hidden
name: Ansible Test Plan

# Controls when to log sensitive information. Can be set to false for
# production environments.
#
# By default, log sensitive information only when Ansible is called with
# A verbosity level of at least one "-v".
threescale_cicd_nolog: '{{ ansible_verbosity|default(0) == 0 }}'

# A folder where to download dependencies, when required
threescale_cicd_local_bin_path: '{{ playbook_dir }}/bin'

Expand Down
2 changes: 2 additions & 0 deletions tasks/api-calls/create_activedoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- debug:
var: threescale_cicd_create_activedoc_payload
verbosity: 1
no_log: '{{ threescale_cicd_nolog }}'

- name: Create the ActiveDocs
uri:
Expand All @@ -13,6 +14,7 @@
status_code: 201
register: threescale_cicd_tmpresponse
changed_when: 'threescale_cicd_tmpresponse.status == 201'
no_log: '{{ threescale_cicd_nolog }}'

- set_fact:
threescale_cicd_existing_activedocs: '{{ threescale_cicd_existing_activedocs|union([ threescale_cicd_tmpresponse.json.api_doc.system_name ]) }}'
Expand Down
2 changes: 2 additions & 0 deletions tasks/api-calls/create_application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- debug:
var: threescale_cicd_create_application_payload
verbosity: 1
no_log: '{{ threescale_cicd_nolog }}'

- name: Create the application
uri:
Expand All @@ -13,6 +14,7 @@
status_code: 201
register: threescale_cicd_tmpresponse
changed_when: 'threescale_cicd_tmpresponse.status == 201'
no_log: '{{ threescale_cicd_nolog }}'

- set_fact:
threescale_cicd_default_application_details: '{{ threescale_cicd_tmpresponse.json.application }}'
Expand Down
2 changes: 2 additions & 0 deletions tasks/api-calls/create_application_plan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- debug:
var: threescale_cicd_create_application_plan_payload
verbosity: 1
no_log: '{{ threescale_cicd_nolog }}'

- name: Create the application plan
uri:
Expand All @@ -13,6 +14,7 @@
status_code: 201
register: threescale_cicd_tmpresponse
changed_when: 'threescale_cicd_tmpresponse.status == 201'
no_log: '{{ threescale_cicd_nolog }}'

- set_fact:
threescale_cicd_existing_application_plans: '{{ threescale_cicd_existing_application_plans|union([ threescale_cicd_application_plan.system_name ]) }}'
Expand Down
2 changes: 2 additions & 0 deletions tasks/api-calls/create_mapping_rule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- debug:
var: threescale_cicd_create_mapping_rule_payload
verbosity: 1
no_log: '{{ threescale_cicd_nolog }}'

- name: Create the mapping rule
uri:
Expand All @@ -13,6 +14,7 @@
status_code: 201
register: threescale_cicd_tmpresponse
changed_when: 'threescale_cicd_tmpresponse.status == 201'
no_log: '{{ threescale_cicd_nolog }}'

- name: Wait for a couple seconds
pause:
Expand Down
2 changes: 2 additions & 0 deletions tasks/api-calls/create_method.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- debug:
var: threescale_cicd_create_method_payload
verbosity: 1
no_log: '{{ threescale_cicd_nolog }}'

- name: Create the method
uri:
Expand All @@ -13,6 +14,7 @@
status_code: 201
register: threescale_cicd_tmpresponse
changed_when: 'threescale_cicd_tmpresponse.status == 201'
no_log: '{{ threescale_cicd_nolog }}'

- set_fact:
threescale_cicd_existing_metrics: '{{ threescale_cicd_existing_metrics|union([ threescale_cicd_api_operation.key ]) }}'
Expand Down
2 changes: 2 additions & 0 deletions tasks/api-calls/create_service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- debug:
var: threescale_cicd_create_service_payload
verbosity: 1
no_log: '{{ threescale_cicd_nolog }}'

- name: Create the service
uri:
Expand All @@ -13,6 +14,7 @@
status_code: 201
register: threescale_cicd_tmpresponse
changed_when: 'threescale_cicd_tmpresponse.status == 201'
no_log: '{{ threescale_cicd_nolog }}'

- set_fact:
threescale_cicd_existing_services: '{{ threescale_cicd_existing_services|union([ threescale_cicd_tmpresponse.json.service.system_name ]) }}'
Expand Down
1 change: 1 addition & 0 deletions tasks/api-calls/delete_mapping_rule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
status_code: 200,404
register: threescale_cicd_tmpresponse
changed_when: 'threescale_cicd_tmpresponse.status == 200'
no_log: '{{ threescale_cicd_nolog }}'

- name: Wait for a couple seconds
pause:
Expand Down
1 change: 1 addition & 0 deletions tasks/api-calls/delete_metric.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
status_code: 200,404
register: threescale_cicd_tmpresponse
changed_when: 'threescale_cicd_tmpresponse.status == 200'
no_log: '{{ threescale_cicd_nolog }}'

- name: Wait for a couple seconds
pause:
Expand Down
1 change: 1 addition & 0 deletions tasks/api-calls/find_application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
method: GET
status_code: 200,404
register: threescale_cicd_tmpresponse
no_log: '{{ threescale_cicd_nolog }}'

- set_fact:
threescale_cicd_default_application_id: '{{ threescale_cicd_tmpresponse.json.application.id }}'
Expand Down
1 change: 1 addition & 0 deletions tasks/api-calls/find_first_account.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
url: https://{{ inventory_hostname }}/admin/api/accounts.json?access_token={{ threescale_cicd_access_token|urlencode }}&state=approved&page=1&per_page=1
validate_certs: no
register: threescale_cicd_tmpresponse
no_log: '{{ threescale_cicd_nolog }}'

- set_fact:
threescale_cicd_default_account_id: '{{ threescale_cicd_tmpresponse.json.accounts[0].account.id }}'
2 changes: 2 additions & 0 deletions tasks/api-calls/get_proxy_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
url: 'https://{{ inventory_hostname }}/admin/api/services/{{ threescale_cicd_api_service_id }}/proxy/configs/{{ threescale_cicd_staging_environment_name }}/latest.json?access_token={{ threescale_cicd_access_token|urlencode }}'
validate_certs: no
register: threescale_cicd_tmpresponse
no_log: '{{ threescale_cicd_nolog }}'

- set_fact:
threescale_cicd_staging_proxy_version: '{{ threescale_cicd_tmpresponse.json.proxy_config.version }}'
Expand All @@ -15,6 +16,7 @@
validate_certs: no
status_code: 200,404
register: threescale_cicd_tmpresponse
no_log: '{{ threescale_cicd_nolog }}'

- set_fact:
threescale_cicd_production_proxy_version: '{{ threescale_cicd_tmpresponse.json.proxy_config.version if threescale_cicd_tmpresponse.status == 200 else ''NONE'' }}'
5 changes: 4 additions & 1 deletion tasks/api-calls/keycloak/authenticate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- debug:
var: threescale_cicd_authenticate_to_keycloak_payload
verbosity: 1
no_log: '{{ threescale_cicd_nolog }}'

- name: Authenticate to RH-SSO
uri:
Expand All @@ -16,7 +17,9 @@
delay: '{{ threescale_cicd_delay }}'
# temporary fix for https://github.com/ansible/ansible/issues/28078
until: 'threescale_cicd_tmpresponse is success'

no_log: '{{ threescale_cicd_nolog }}'

- name: Extract the access_token
set_fact:
threescale_cicd_keycloak_access_token: '{{ threescale_cicd_tmpresponse.json |json_query("access_token") }}'
no_log: '{{ threescale_cicd_nolog }}'
2 changes: 2 additions & 0 deletions tasks/api-calls/keycloak/patch_client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- debug:
var: threescale_cicd_patch_keycloak_client_payload
verbosity: 1
no_log: '{{ threescale_cicd_nolog }}'

- name: Patch the client in RH-SSO to support the "client_credentials" and "password" grant_type.
uri:
Expand All @@ -17,6 +18,7 @@
Content-Type: 'application/json'
register: threescale_cicd_tmpresponse
changed_when: 'threescale_cicd_tmpresponse.status == 200'
no_log: '{{ threescale_cicd_nolog }}'

- name: Wait for a couple seconds
pause:
Expand Down
1 change: 1 addition & 0 deletions tasks/api-calls/keycloak/wait_for_client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
retries: '{{ threescale_cicd_retries }}'
delay: '{{ threescale_cicd_delay }}'
until: 'threescale_cicd_tmpresponse is success and threescale_cicd_tmpresponse.json|length > 0'
no_log: '{{ threescale_cicd_nolog }}'

- set_fact:
threescale_cicd_default_application_sso_id: '{{ threescale_cicd_tmpresponse.json[0].id }}'
Expand Down
2 changes: 2 additions & 0 deletions tasks/api-calls/promote_proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- debug:
var: threescale_cicd_promote_proxy_payload
verbosity: 1
no_log: '{{ threescale_cicd_nolog }}'

- name: Promote to production
uri:
Expand All @@ -13,6 +14,7 @@
method: POST
register: threescale_cicd_tmpresponse
changed_when: 'threescale_cicd_tmpresponse.status == 201'
no_log: '{{ threescale_cicd_nolog }}'

- name: Wait for a couple seconds
pause:
Expand Down
3 changes: 2 additions & 1 deletion tasks/api-calls/smoke_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
- name: Running smoke tests (CORS) !
uri:
url: '{{ threescale_cicd_smoke_test_url }}'
headers: '{{ threescale_cicd_smoke_test_headers|combine({ ''Origin'': threescale_cicd_smoke_test_url}) }}'
headers: '{{ threescale_cicd_smoke_test_headers|combine({ ''Origin'': threescale_cicd_smoke_test_url, ''Access-Control-Request-Method'': ''GET'' }) }}'
validate_certs: no
method: OPTIONS
status_code: 200,204
register: threescale_cicd_tmpresponse
retries: '{{ threescale_cicd_retries }}'
delay: '{{ threescale_cicd_delay }}'
Expand Down
2 changes: 2 additions & 0 deletions tasks/api-calls/update_activedoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- debug:
var: threescale_cicd_update_activedoc_payload
verbosity: 1
no_log: '{{ threescale_cicd_nolog }}'

- name: Update the ActiveDocs
uri:
Expand All @@ -13,6 +14,7 @@
status_code: 200
register: threescale_cicd_tmpresponse
changed_when: 'threescale_cicd_tmpresponse.status == 200'
no_log: '{{ threescale_cicd_nolog }}'

- name: Wait for a couple seconds
pause:
Expand Down
2 changes: 2 additions & 0 deletions tasks/api-calls/update_application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- debug:
var: threescale_cicd_update_application_payload
verbosity: 1
no_log: '{{ threescale_cicd_nolog }}'

- name: Update the application
uri:
Expand All @@ -12,6 +13,7 @@
body: '{{ threescale_cicd_update_application_payload }}'
status_code: 200
register: threescale_cicd_tmpresponse
no_log: '{{ threescale_cicd_nolog }}'

- set_fact:
threescale_cicd_default_application_details: '{{ threescale_cicd_tmpresponse.json.application }}'
Expand Down
2 changes: 2 additions & 0 deletions tasks/api-calls/update_application_plan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- debug:
var: threescale_cicd_update_application_plan_payload
verbosity: 1
no_log: '{{ threescale_cicd_nolog }}'

- name: Update the application plan
uri:
Expand All @@ -13,6 +14,7 @@
status_code: 200
register: threescale_cicd_tmpresponse
changed_when: 'threescale_cicd_tmpresponse.status == 200'
no_log: '{{ threescale_cicd_nolog }}'

- name: Wait for a couple seconds
pause:
Expand Down
2 changes: 2 additions & 0 deletions tasks/api-calls/update_mapping_rule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- debug:
var: threescale_cicd_update_mapping_rule_payload
verbosity: 1
no_log: '{{ threescale_cicd_nolog }}'

- name: Update the mapping rule
uri:
Expand All @@ -15,6 +16,7 @@
changed_when: 'threescale_cicd_tmpresponse.status == 200'
vars:
threescale_cicd_mapping_rule_id: '{{ threescale_cicd_existing_mapping_rules[threescale_cicd_mapping_rule] }}'
no_log: '{{ threescale_cicd_nolog }}'

- name: Wait for a couple seconds
pause:
Expand Down
2 changes: 2 additions & 0 deletions tasks/api-calls/update_method.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- debug:
var: threescale_cicd_update_method_payload
verbosity: 1
no_log: '{{ threescale_cicd_nolog }}'

- name: Update the method
uri:
Expand All @@ -12,6 +13,7 @@
body: '{{ threescale_cicd_update_method_payload }}'
register: threescale_cicd_tmpresponse
changed_when: 'threescale_cicd_tmpresponse.status == 200'
no_log: '{{ threescale_cicd_nolog }}'

- name: Wait for a couple seconds
pause:
Expand Down
2 changes: 2 additions & 0 deletions tasks/api-calls/update_policies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- debug:
var: threescale_cicd_update_policies_payload
verbosity: 1
no_log: '{{ threescale_cicd_nolog }}'

- name: Update the policies chain
uri:
Expand All @@ -17,6 +18,7 @@
status_code: 200
register: threescale_cicd_tmpresponse
changed_when: 'threescale_cicd_tmpresponse.status == 200'
no_log: '{{ threescale_cicd_nolog }}'

- name: Wait for a couple seconds
pause:
Expand Down
2 changes: 2 additions & 0 deletions tasks/api-calls/update_proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- debug:
var: threescale_cicd_update_proxy_payload
verbosity: 1
no_log: '{{ threescale_cicd_nolog }}'

- name: Update the proxy definition
uri:
Expand All @@ -12,6 +13,7 @@
body: '{{ threescale_cicd_update_proxy_payload }}'
register: threescale_cicd_tmpresponse
changed_when: 'threescale_cicd_tmpresponse.status == 200'
no_log: '{{ threescale_cicd_nolog }}'

- name: Extract the staging and production gateway endpoint from the proxy definition
set_fact:
Expand Down
2 changes: 2 additions & 0 deletions tasks/api-calls/update_service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- debug:
var: threescale_cicd_update_service_payload
verbosity: 1
no_log: '{{ threescale_cicd_nolog }}'

- name: Update the service
uri:
Expand All @@ -13,6 +14,7 @@
status_code: 200
register: threescale_cicd_tmpresponse
changed_when: 'threescale_cicd_tmpresponse.status == 200'
no_log: '{{ threescale_cicd_nolog }}'

- name: Wait for a couple seconds
pause:
Expand Down
Binary file modified tests/3scale-inventory.yaml.enc
Binary file not shown.
Loading

0 comments on commit f22a0fc

Please sign in to comment.