Skip to content

Commit

Permalink
Add retry mechanism to db verification tasks (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyphreak authored Jan 4, 2023
1 parent 2f9f1c6 commit 1e463c6
Showing 1 changed file with 35 additions and 24 deletions.
59 changes: 35 additions & 24 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,28 +236,39 @@
ansible.builtin.set_fact:
metabase_session: "{{ metabase_login_query.json.id }}"

- name: query metabase dbs
ansible.builtin.uri:
url: "https://{{ metabase_host }}/api/database/?include=tables"
method: GET
headers:
Host: "{{ dataplane_metabase_hostname }}"
Content-Type: application/json
X-Metabase-Session: "{{ metabase_session }}"
status_code: 200
validate_certs: false
register: metabase_db_query

- name: verify sample db deletion
ansible.builtin.fail:
msg: "Sample databases have not been removed from Metabase"
vars:
extra_dbs: "{{ metabase_db_query.json.data | rejectattr('name', 'equalto', 'dataplane') }}"
when: extra_dbs | length > 0

- name: verify metabase db creation
ansible.builtin.fail:
msg: "Database 'dataplane' has not been registered to Metabase"
vars:
metabase_dbs: "{{ metabase_db_query.json.data | selectattr('name', 'equalto', 'dataplane') }}"
when: metabase_dbs | length < 1
- name: verify metabase dbs
block:

- name: query metabase dbs
ansible.builtin.uri:
url: "https://{{ metabase_host }}/api/database/?include=tables"
method: GET
headers:
Host: "{{ dataplane_metabase_hostname }}"
Content-Type: application/json
X-Metabase-Session: "{{ metabase_session }}"
status_code: 200
validate_certs: false
register: metabase_db_query
retries: 10
delay: 30
until:
- metabase_db_query.json.data | rejectattr('name', 'equalto', 'dataplane') | length == 0
- metabase_db_query.json.data | selectattr('name', 'equalto', 'dataplane') | length == 1

rescue:

- name: verify sample db deletion
ansible.builtin.fail:
msg: "Sample databases have not been removed from Metabase"
vars:
extra_dbs: "{{ metabase_db_query.json.data | rejectattr('name', 'equalto', 'dataplane') }}"
when: extra_dbs | length > 0

- name: verify metabase db creation
ansible.builtin.fail:
msg: "Database 'dataplane' has not been registered to Metabase"
vars:
metabase_dbs: "{{ metabase_db_query.json.data | selectattr('name', 'equalto', 'dataplane') }}"
when: metabase_dbs | length < 1

0 comments on commit 1e463c6

Please sign in to comment.