Skip to content

Commit

Permalink
Merge pull request #2873 from uselagoon/fix_retries
Browse files Browse the repository at this point in the history
  • Loading branch information
tobybellwood authored Oct 18, 2021
2 parents b4bca1a + 94ff0fb commit e0bdfcb
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 18 deletions.
31 changes: 24 additions & 7 deletions tests/tasks/api/deploy-no-sha.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
- name: "{{ testname }} - POST api deployEnvironmentBranch with target git branch {{ branch }} and project {{ project }} (no sha) to {{ graphql_url }}"
- name: "Start deployEnvironmentBranch (no SHA) loop with 3 retries"
block:
- include: refresh-token.yaml
- name: "Set the retry count to {{ retry_count }}"
set_fact:
retry_count: "{{ 0 if retry_count is undefined else retry_count|int + 1 }}"
- name: "{{ testname }} - POST api deployEnvironmentBranch with target git branch {{ branch }} and project {{ project }} (no sha) to {{ graphql_url }}"
uri:
url: "{{ graphql_url }}"
method: POST
headers:
Authorization: "Bearer {{ token }}"
body_format: json
return_content: true
body:
query: '{{ lookup("template", "./deploy-no-sha.gql") }}'
#body: '{ "query": "mutation($branchName: String!, $projectName: String!) {deployEnvironmentBranch(input:{branchName:$branchName,project:{name:$projectName}})}", "variables": {"branchName":"{{ branch }}","projectName":"{{ project }}"}}'
register: apiresponse
- name: "{{ testname }} - POST api deployEnvironmentBranch with target git branch {{ branch }} and project {{ project }} (no sha) to {{ graphql_url }}"
debug:
msg: "api response: {{ apiresponse.json }}"
until: apiresponse.json.data.deployEnvironmentBranch == "success"
retries: 10
delay: 30
- name: Print apiresponse
ansible.builtin.debug:
msg: "api response: {{ apiresponse }}"
- fail:
msg: "unsuccessful deploy"
when: apiresponse.json.data.deployEnvironmentBranch != "success"
- name: "Set the retry count back to 0 when successful"
set_fact:
retry_count: 0
rescue:
- fail:
msg: Ended after 3 retries
when: retry_count|int == 3
- name: Pause for retry
pause:
seconds: 10
- debug:
msg: "Failed to connect - Retrying..."
- include_tasks: ./deploy-no-sha.yaml
28 changes: 24 additions & 4 deletions tests/tasks/api/deploy-pullrequest.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
- name: "{{ testname }} - POST api deployEnvironmentPullrequest with pr number {{ git_pr_number }}, git base branch {{ git_base_branch }}, base commit hash {{ git_base_commit_hash }}, pr branch {{ git_pr_branch }}, pr commit hash {{ git_pr_commit_hash }} to {{ graphql_url }}"
- name: "Start deployEnvironmentPullrequest loop with 3 retries"
block:
- include: refresh-token.yaml
- name: "Set the retry count to {{ retry_count }}"
set_fact:
retry_count: "{{ 0 if retry_count is undefined else retry_count|int + 1 }}"
- name: "{{ testname }} - POST api deployEnvironmentPullrequest with pr number {{ git_pr_number }}, git base branch {{ git_base_branch }}, base commit hash {{ git_base_commit_hash }}, pr branch {{ git_pr_branch }}, pr commit hash {{ git_pr_commit_hash }} to {{ graphql_url }}"
uri:
url: "{{ graphql_url }}"
method: POST
headers:
Authorization: "Bearer {{ token }}"
body_format: json
return_content: true
body:
query: '{{ lookup("template", "./deploy-pullrequest.gql") }}'
# body: '{ "query": "mutation($projectName:String!, $number:Int!, $title:String!, $baseName:String!, $baseRef:String!, $headName:String!, $headRef:String!) {deployEnvironmentPullrequest(input:{project:{name:$projectName},number:$number,title:$title,baseBranchName:$baseName,baseBranchRef:$baseRef,headBranchName:$headName,headBranchRef:$headRef})}", "variables": {"projectName":"{{ project }}","number":{{ git_pr_number }},"title":"{{ git_pr_title }}","baseName":"{{ git_base_branch }}","baseRef":"{{ git_base_commit_hash }}","headName":"{{ git_pr_branch }}","headRef":"{{ git_pr_commit_hash }}"}}'
register: apiresponse
- name: "{{ testname }} - POST api deployEnvironmentPullrequest with pr number {{ git_pr_number }}, git base branch {{ git_base_branch }}, base commit hash {{ git_base_commit_hash }}, pr branch {{ git_pr_branch }}, pr commit hash {{ git_pr_commit_hash }} to {{ graphql_url }}"
debug:
msg: "api response: {{ apiresponse.json }}"
- name: Print apiresponse
ansible.builtin.debug:
msg: "api response: {{ apiresponse }}"
- fail:
msg: "unsuccessful deploy"
when: apiresponse.json.data.deployEnvironmentPullrequest != "success"
- name: "Set the retry count back to 0 when successful"
set_fact:
retry_count: 0
rescue:
- fail:
msg: Ended after 3 retries
when: retry_count|int == 3
- name: Pause for retry
pause:
seconds: 10
- debug:
msg: "Failed to connect - Retrying..."
- include_tasks: ./deploy-pullrequest.yaml
31 changes: 24 additions & 7 deletions tests/tasks/api/deploy-sha.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
- name: "{{ testname }} - POST api deployEnvironmentBranch with target git branch {{ branch }} and project {{ project }} and sha {{ sha }} to {{ graphql_url }}"
- name: "Start deployEnvironmentBranch (SHA) loop with 3 retries"
block:
- include: refresh-token.yaml
- name: "Set the retry count to {{ retry_count }}"
set_fact:
retry_count: "{{ 0 if retry_count is undefined else retry_count|int + 1 }}"
- name: "{{ testname }} - POST api deployEnvironmentBranch with target git branch {{ branch }} and project {{ project }} and sha {{ sha }} to {{ graphql_url }}"
uri:
url: "{{ graphql_url }}"
method: POST
headers:
Authorization: "Bearer {{ token }}"
body_format: json
return_content: true
body:
query: '{{ lookup("template", "./deploy-sha.gql") }}'
# body: '{ "query": "mutation($branchName: String!, $branchRef: String!, $projectName: String!) {deployEnvironmentBranch(input:{branchName:$branchName,branchRef:$branchRef,project:{name:$projectName}})}", "variables": {"branchName":"{{ branch }}","branchRef":"{{ sha }}","projectName":"{{ project }}"}}'
register: apiresponse
- name: "{{ testname }} - POST api deployEnvironmentBranch with target git branch {{ branch }} and project {{ project }} and sha {{ sha }} to {{ graphql_url }}"
debug:
msg: "api response: {{ apiresponse.json }}"
until: apiresponse.json.data.deployEnvironmentBranch == "success"
retries: 10
delay: 30
- name: Print apiresponse
ansible.builtin.debug:
msg: "api response: {{ apiresponse }}"
- fail:
msg: "unsuccessful deploy"
when: apiresponse.json.data.deployEnvironmentBranch != "success"
- name: "Set the retry count back to 0 when successful"
set_fact:
retry_count: 0
rescue:
- fail:
msg: Ended after 3 retries
when: retry_count|int == 3
- name: Pause for retry
pause:
seconds: 10
- debug:
msg: "Failed to connect - Retrying..."
- include_tasks: ./deploy-sha.yaml

0 comments on commit e0bdfcb

Please sign in to comment.