aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorPaul Bonaud <paul.bonaud@fretlink.com>2020-08-06 11:44:26 +0200
committerPaul Bonaud <paul.bonaud@fretlink.com>2020-08-06 15:54:27 +0200
commitc3e2ff5e0f31c61eae330a1a41d7a8a83435d9bd (patch)
treef03e1db57031f574657838a8a15c41319b1c18be /tests
parent315c7f51af48b54719bd793d9d28a4bb396a926a (diff)
downloadansible-clever-c3e2ff5e0f31c61eae330a1a41d7a8a83435d9bd.tar.gz
ansible-clever-c3e2ff5e0f31c61eae330a1a41d7a8a83435d9bd.tar.zst
ansible-clever-c3e2ff5e0f31c61eae330a1a41d7a8a83435d9bd.zip
deploy: try to restart the app when the CLI asks to do it
In some cases (rollback or deployment errored on clever side), clever-tools will fail when calling `clever deploy` because it thinks the currently being deployed commit is already deployed. However in some cases the git pushed commit is not the currently running commit. Leading to a failure in our deployment process. The proposed solution from the clever tools error is to launch `clever restart`. Until we wait for https://github.com/CleverCloud/clever-tools/issues/422 to be fixed, let's do what the error message say: try to restart in case of a deployment failure.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/fake.sh14
-rw-r--r--tests/test-all.yml1
-rw-r--r--tests/test-restart-deploy.yml37
3 files changed, 50 insertions, 2 deletions
diff --git a/tests/fake.sh b/tests/fake.sh
index 65ff819..776907b 100755
--- a/tests/fake.sh
+++ b/tests/fake.sh
@@ -3,6 +3,9 @@
3binary="${0/*\/}" 3binary="${0/*\/}"
4localCommit="${PRETEND_LOCAL_COMMIT:-aaa000aaa000aaa000aaa000aaa000aaa000aaa0}" 4localCommit="${PRETEND_LOCAL_COMMIT:-aaa000aaa000aaa000aaa000aaa000aaa000aaa0}"
5remoteCommit="${PRETEND_REMOTE_COMMIT:-bbb000bbb000bbb000bbb000bbb000bbb000bbb0}" 5remoteCommit="${PRETEND_REMOTE_COMMIT:-bbb000bbb000bbb000bbb000bbb000bbb000bbb0}"
6uptodateDeployment="${DEPLOY_UP_TO_DATE_APP:-}"
7
8echo "${1}" >> "${binary}-commands"
6 9
7if [ "${binary}" = "clever" ] && [ "${1}" = "--version" ]; then 10if [ "${binary}" = "clever" ] && [ "${1}" = "--version" ]; then
8 echo "2.6.1" 11 echo "2.6.1"
@@ -10,10 +13,17 @@ elif [ "${binary}" = "clever" ] && [ "${1}" = "activity" ]; then
10 echo "2020-02-02T20:20:02+02:00 OK DEPLOY ${remoteCommit} Git" 13 echo "2020-02-02T20:20:02+02:00 OK DEPLOY ${remoteCommit} Git"
11elif [ "${binary}" = "clever" ] && [ "${1}" = "status" ]; then 14elif [ "${binary}" = "clever" ] && [ "${1}" = "status" ]; then
12 echo "test-app: running (1*pico, Commit: ${remoteCommit})" 15 echo "test-app: running (1*pico, Commit: ${remoteCommit})"
16elif [ "${binary}" = "clever" ] && [ "${1}" = "deploy" ]; then
17 if [ -z "${uptodateDeployment}" ]; then
18 echo "Clever deploy done."
19 else
20 # Mimic the current behavior until https://github.com/CleverCloud/clever-tools/issues/422 is solved
21 >&2 echo "The clever-cloud application is up-to-date. Try this command to restart the application:"
22 >&2 echo " clever restart"
23 exit 1
24 fi
13elif [ "${binary}" = "git" ]; then 25elif [ "${binary}" = "git" ]; then
14 echo "${localCommit}" 26 echo "${localCommit}"
15else 27else
16 echo "${binary} called with arguments: ${*}" 28 echo "${binary} called with arguments: ${*}"
17fi 29fi
18
19echo "${1}" >> "${binary}-commands"
diff --git a/tests/test-all.yml b/tests/test-all.yml
index 8a6c0ba..b9c5dea 100644
--- a/tests/test-all.yml
+++ b/tests/test-all.yml
@@ -3,6 +3,7 @@
3- import_playbook: ./test-configure-app.yml 3- import_playbook: ./test-configure-app.yml
4- import_playbook: ./test-haskell-app.yml 4- import_playbook: ./test-haskell-app.yml
5- import_playbook: ./test-noop-deploy.yml 5- import_playbook: ./test-noop-deploy.yml
6- import_playbook: ./test-restart-deploy.yml
6- import_playbook: ./test-scalability.yml 7- import_playbook: ./test-scalability.yml
7- import_playbook: ./test-service-deps.yml 8- import_playbook: ./test-service-deps.yml
8- import_playbook: ./test-restart-app.yml 9- import_playbook: ./test-restart-app.yml
diff --git a/tests/test-restart-deploy.yml b/tests/test-restart-deploy.yml
new file mode 100644
index 0000000..cbd6cdd
--- /dev/null
+++ b/tests/test-restart-deploy.yml
@@ -0,0 +1,37 @@
1---
2- name: Launch a restart when commit is already up-to-date on clever
3 hosts: localhost
4 remote_user: root
5 pre_tasks:
6 - file:
7 state: absent
8 path: ../clever-commands
9 roles:
10 - role: clever
11 vars:
12 clever_token: 123abc
13 clever_secret: cba321
14 clever_app: app_00000000-0000-0000-0000-000000000000
15 environment:
16 DEPLOY_UP_TO_DATE_APP: true
17 post_tasks:
18 - name: Check stubbed commands
19 shell: "{{ item.cmd }}"
20 ignore_errors: true
21 with_list:
22 - cmd: "grep deploy ../clever-commands"
23 display: "Expected 'clever deploy' command to be called"
24 - cmd: "grep restart ../clever-commands"
25 display: "Expected 'clever restart' command to be called"
26 vars:
27 display: "{{ item.display }}"
28 register: tests_results
29 - name: show results
30 debug:
31 msg:
32 - "failed_results: {{ failed_results }}"
33 - "success_results: {{ success_results }}"
34 failed_when: tests_results is failed
35 vars:
36 failed_results: "{{ tests_results.results | selectattr('failed') | map(attribute='item.display') | list }}"
37 success_results: "{{ tests_results.results | rejectattr('failed') | map(attribute='item.display') | list }}"