]> git.immae.eu Git - github/fretlink/ansible-clever.git/commitdiff
Merge pull request #70 from paulrbr-fl/clever-restart
authorpaulrbr-fl <43074087+paulrbr-fl@users.noreply.github.com>
Tue, 23 Jun 2020 09:20:46 +0000 (11:20 +0200)
committerGitHub <noreply@github.com>
Tue, 23 Jun 2020 09:20:46 +0000 (11:20 +0200)
feature: add a new 'clever_restart_only' flag to restart an app

.travis.yml
README.md
tasks/main.yml
tasks/restart.yml [new file with mode: 0644]
tests/fake.sh
tests/test-all.yml [new file with mode: 0644]
tests/test-configure-app.yml
tests/test-restart-app.yml [new file with mode: 0644]
tests/test-scalability.yml

index 92f6295cf48d8ceaf869d533a17b99479a88fffa..7ce4540ee5c587a504d15499c6adb702ad6baf1e 100644 (file)
@@ -26,10 +26,7 @@ script:
   - mkdir -p ~/.local/bin
   - cp tests/fake.sh ~/.local/bin/clever
   - cp tests/fake.sh ~/.local/bin/git
-  - ansible-playbook tests/test-simple-app.yml -i tests/inventory
-  - ansible-playbook tests/test-haskell-app.yml -i tests/inventory
-  - ansible-playbook tests/test-configure-app.yml -i tests/inventory
-  - ansible-playbook tests/test-scalability.yml -i tests/inventory
+  - ansible-playbook -i tests/inventory tests/test-all.yml
 
 notifications:
   slack: fretlink:pTIylIN7zkwRFuL3aHERmsbB
index 22c70b46f2435a38dd746c59df9d9054178a03eb..51b9e3d49e180cdefee74472bcc8a6747d481a16 100644 (file)
--- a/README.md
+++ b/README.md
@@ -35,13 +35,14 @@ Variables for the application:
 - `clever_build_flavor`: an optional text value used to configure the size of the dedicated build instance (for instance `S` or `XL`). If not defined, it delegates to clever cloud default behaviour. Setting `disabled` disables the dedicated build instance altogether.
 - `clever_scaling`: an optional object used to configure the runtime instances flavours and numbers. If not defined, it delegates to clever cloud default behaviour.
 
-Variables specific to deployment, default should be fine:
+Variables specific to deployment, defaults should be fine:
 
 - `clever_cli_version`: Version of clever cli tools, default to `2.6.1`.
 - `clever_user_path`: Path relative to ansible_user home dir where cli tools and helpers are installed default to `.local/bin`.
 - `clever_app_root`: Path of the application to deploy, default to `app_root` if defined or `"{{ playbook_dir }}/.."` otherwise. I.e. the default behavior will work fine if you define a playbook using this role in a one level deep directory (e.g. `deployment/`) of the root of the application.
 - `clever_app_confdir`: Path where to store clever cloud data specific to this application, default to `"{{ clever_app_root }}/.clever_cloud"`
 - `clever_login_file`: Path to store login information. Default to `"{{ clever_app_confdir }}/login"`.
+- `clever_restart_only`: set to `true` to skip any deployment related tasks (domain, scaling, env, deploy, …) and only restart the application. Optional.
 
 Variables specific to Haskell applications:
 
index 3c59c90967ad8dc375b2169eef21231388850fee..002dc9c55b65f9879833ae9cbe243f278ff72fd9 100644 (file)
 
 - name: Deploy app
   import_tasks: deploy.yml
+  when: not clever_restart_only is defined or not clever_restart_only
   tags:
     - clever
     - clever-deploy
 
 - name: Post deploy tasks
   import_tasks: post_deploy.yml
+  when: not clever_restart_only is defined or not clever_restart_only
   tags:
     - clever
     - clever-deploy
     - clever-env
+
+- name: Restart app
+  import_tasks: restart.yml
+  when: clever_restart_only is defined and clever_restart_only
+  tags:
+    - clever
+    - clever-restart
diff --git a/tasks/restart.yml b/tasks/restart.yml
new file mode 100644 (file)
index 0000000..e2a8891
--- /dev/null
@@ -0,0 +1,22 @@
+---
+- name: Restart app on Clever-Cloud
+  shell: "clever restart"
+  args:
+    chdir: "{{ clever_app_root }}"
+  environment:
+    CONFIGURATION_FILE: "{{ clever_login_file }}"
+  async: 300 # 5 minutes
+  poll: 0
+  ignore_errors: true
+  register: clever_deploy
+  tags:
+    - skip_ansible_lint
+
+- name: Wait up to 5 minutes for restart completion
+  async_status:
+    jid: "{{ clever_deploy.ansible_job_id }}"
+  register: job_result
+  until: job_result.finished
+  ignore_errors: true
+  delay: 30
+  retries: 10 # 5 minutes (10 * 30 secs delay)
index 75bc0514d8b22407f45355259ce8ae74936b2ddb..bbb4380637bf691669764043ccd1856cc9ec4c6e 100755 (executable)
@@ -10,5 +10,6 @@ elif [ "${binary}" = "clever" ] && [ "${1}" = "activity" ]; then
 elif [ "${binary}" = "git" ]; then
     echo "${fakeCommit}"
 else
+    echo "${1}" >> "${binary}-commands"
     echo "${binary} called with arguments: ${*}"
 fi
diff --git a/tests/test-all.yml b/tests/test-all.yml
new file mode 100644 (file)
index 0000000..64eb239
--- /dev/null
@@ -0,0 +1,6 @@
+---
+- import_playbook: ./test-simple-app.yml
+- import_playbook: ./test-configure-app.yml
+- import_playbook: ./test-haskell-app.yml
+- import_playbook: ./test-scalability.yml
+- import_playbook: ./test-restart-app.yml
index 06e5e920b947a241a31d9582d47bc5029eb2de78..15987fd8248288743e2d529e8b2027205a064e99 100644 (file)
@@ -2,6 +2,10 @@
 - name: Deploy an app & configure system details on clever
   hosts: localhost
   remote_user: root
+  pre_tasks:
+    - file:
+        state: absent
+        path: ../clever-commands
   roles:
     - role: clever
       vars:
       fail:
         msg: "CC_RUN_COMMAND env variable should not be present in the environment dict"
       when: clever_env.CC_RUN_COMMAND is defined
+    - name: Check stubbed commands
+      command: "{{ item.cmd }}"
+      ignore_errors: true
+      vars:
+        display: "{{ item.display }}"
+      with_list:
+        - cmd: "grep deploy ../clever-commands"
+          display: "Expected 'clever deploy' command to be called"
+        - cmd: "grep scale ../clever-commands"
+          display: "Expected 'clever scale' command to be called"
+        - cmd: "grep domain ../clever-commands"
+          display: "Expected 'clever domain' command to be called"
+        - cmd: "grep drain ../clever-commands"
+          display: "Expected 'clever drain' command to be called"
+        - cmd: "grep -v restart ../clever-commands"
+          display: "Expected 'clever restart' command to NOT be called"
+      register: tests_results
+    - name: show results
+      debug:
+        msg:
+          - "failed_results: {{ failed_results }}"
+          - "success_results: {{ success_results }}"
+      failed_when: tests_results is failed
+      vars:
+        failed_results: "{{ tests_results.results | selectattr('failed') | map(attribute='item.display') | list }}"
+        success_results: "{{ tests_results.results | rejectattr('failed') | map(attribute='item.display') | list }}"
diff --git a/tests/test-restart-app.yml b/tests/test-restart-app.yml
new file mode 100644 (file)
index 0000000..4c13a14
--- /dev/null
@@ -0,0 +1,38 @@
+---
+- name: Restart app on clever
+  hosts: localhost
+  remote_user: root
+  pre_tasks:
+    - file:
+        state: absent
+        path: ../clever-commands
+  roles:
+    - role: clever
+      vars:
+        clever_token: 123abc
+        clever_secret: cba321
+        clever_app: app_00000000-0000-0000-0000-000000000000
+        clever_restart_only: true
+  post_tasks:
+    - name: Check stubbed commands
+      command: "{{ item.cmd }}"
+      ignore_errors: true
+      vars:
+        display: "{{ item.display }}"
+      with_list:
+        - cmd: "grep restart ../clever-commands"
+          display: "Expected 'clever restart' command to be called"
+        - cmd: "grep -v deploy ../clever-commands"
+          display: "Expected 'clever deploy' command to NOT be called"
+        - cmd: "grep -v scale ../clever-commands"
+          display: "Expected 'clever scale' command to NOT be called"
+      register: tests_results
+    - name: show results
+      debug:
+        msg:
+          - "failed_results: {{ failed_results }}"
+          - "success_results: {{ success_results }}"
+      failed_when: tests_results is failed
+      vars:
+        failed_results: "{{ tests_results.results | selectattr('failed') | map(attribute='item.display') | list }}"
+        success_results: "{{ tests_results.results | rejectattr('failed') | map(attribute='item.display') | list }}"
index fefc86c7beff80839ba1e5e4782f80f31b0890d3..6bb90d2ac97ecd04116bcd7402f900e8daf67237 100644 (file)
 - name: Configure scalability (no instances and ranged flavors)
   hosts: localhost
   remote_user: root
+  pre_tasks:
+    - file:
+        state: absent
+        path: ../clever-commands
   roles:
     - role: clever
       vars:
         clever_app: app_00000000-0000-0000-0000-000000000000
         clever_scaling:
           flavors: { min: "nano", max: "XS" }
+  post_tasks:
+    - name: Check stubbed commands
+      command: "{{ item.cmd }}"
+      ignore_errors: true
+      vars:
+        display: "{{ item.display }}"
+      with_list:
+        - cmd: "grep deploy ../clever-commands"
+          display: "Expected 'clever deploy' command to be called"
+        - cmd: "grep scale ../clever-commands"
+          display: "Expected 'clever scale' command to be called"
+        - cmd: "grep -v restart ../clever-commands"
+          display: "Expected 'clever restart' command to NOT be called"
+      register: tests_results
+    - name: show results
+      debug:
+        msg:
+          - "failed_results: {{ failed_results }}"
+          - "success_results: {{ success_results }}"
+      failed_when: tests_results is failed
+      vars:
+        failed_results: "{{ tests_results.results | selectattr('failed') | map(attribute='item.display') | list }}"
+        success_results: "{{ tests_results.results | rejectattr('failed') | map(attribute='item.display') | list }}"
 
 - name: Configure scalability (incomplete flavors)
   hosts: localhost