Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix retry loop logic in testing #2873

Merged
merged 2 commits into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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