From 2a3aa591e097567e7f60ad3cfd5d87bff3daf673 Mon Sep 17 00:00:00 2001
From: Antoine Legrand <2t.antoine@gmail.com>
Date: Sat, 20 Oct 2018 13:56:55 +0200
Subject: [PATCH] Download role (#3553)

* codestyle tests

* Download destination can be different than local_release_dir
---
 roles/download/defaults/main.yml          | 12 ++++--------
 roles/download/tasks/download_file.yml    | 10 +++++-----
 tests/testcases/040_check-network-adv.yml |  8 +++++---
 3 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/roles/download/defaults/main.yml b/roles/download/defaults/main.yml
index 17b918343..6d81c9109 100644
--- a/roles/download/defaults/main.yml
+++ b/roles/download/defaults/main.yml
@@ -233,11 +233,10 @@ downloads:
     file: "{{ etcd_deployment_type == 'host' }}"
     enabled: true
     version: "{{ etcd_version }}"
-    dest: "etcd-{{ etcd_version }}-linux-amd64.tar.gz"
+    dest: "{{local_release_dir}}/etcd-{{ etcd_version }}-linux-amd64.tar.gz"
     repo: "{{ etcd_image_repo }}"
     tag: "{{ etcd_image_tag }}"
     sha256: "{{ etcd_binary_checksum if etcd_deployment_type == 'host' else etcd_digest_checksum|d(None) }}"
-    source_url: "{{ etcd_download_url }}"
     url: "{{ etcd_download_url }}"
     unarchive: true
     owner: "root"
@@ -249,9 +248,8 @@ downloads:
     enabled: "{{ kubeadm_enabled }}"
     file: true
     version: "{{ kubeadm_version }}"
-    dest: "kubeadm"
+    dest: "{{local_release_dir}}/kubeadm"
     sha256: "{{ kubeadm_binary_checksum }}"
-    source_url: "{{ kubeadm_download_url }}"
     url: "{{ kubeadm_download_url }}"
     unarchive: false
     owner: "root"
@@ -272,9 +270,8 @@ downloads:
     enabled: true
     file: true
     version: "{{ kube_version }}"
-    dest: "hyperkube"
+    dest: "{{local_release_dir}}/hyperkube"
     sha256: "{{ hyperkube_binary_checksum }}"
-    source_url: "{{ hyperkube_download_url }}"
     url: "{{ hyperkube_download_url }}"
     unarchive: false
     owner: "root"
@@ -527,12 +524,11 @@ downloads:
     enabled: "{{ cert_management == 'vault' }}"
     container: "{{ vault_deployment_type != 'host' }}"
     file: "{{ vault_deployment_type == 'host' }}"
-    dest: "vault/vault_{{ vault_version }}_linux_{{ image_arch }}.zip"
+    dest: "{{local_release_dir}}/vault/vault_{{ vault_version }}_linux_{{ image_arch }}.zip"
     mode: "0755"
     owner: "vault"
     repo: "{{ vault_image_repo }}"
     sha256: "{{ vault_binary_checksum if vault_deployment_type == 'host' else vault_digest_checksum|d(none) }}"
-    source_url: "{{ vault_download_url }}"
     tag: "{{ vault_image_tag }}"
     unarchive: true
     url: "{{ vault_download_url }}"
diff --git a/roles/download/tasks/download_file.yml b/roles/download/tasks/download_file.yml
index 2d0106fe6..bc8bbcf89 100644
--- a/roles/download/tasks/download_file.yml
+++ b/roles/download/tasks/download_file.yml
@@ -7,7 +7,7 @@
 
 - name: file_download | Create dest directory
   file:
-    path: "{{local_release_dir}}/{{download.dest|dirname}}"
+    path: "{{download.dest|dirname}}"
     state: directory
     recurse: yes
   when:
@@ -18,7 +18,7 @@
 - name: file_download | Download item
   get_url:
     url: "{{download.url}}"
-    dest: "{{local_release_dir}}/{{download.dest}}"
+    dest: "{{download.dest}}"
     sha256sum: "{{download.sha256 | default(omit)}}"
     owner: "{{ download.owner|default(omit) }}"
     mode: "{{ download.mode|default(omit) }}"
@@ -26,7 +26,7 @@
   register: get_url_result
   until: "'OK' in get_url_result.msg or 'file already exists' in get_url_result.msg"
   retries: 4
-  delay: "{{ retry_stagger | random + 3 }}"
+  delay: "{{ retry_stagger | default(5) }}"
   when:
     - download.enabled
     - download.file
@@ -34,8 +34,8 @@
 
 - name: file_download | Extract archives
   unarchive:
-    src: "{{ local_release_dir }}/{{download.dest}}"
-    dest: "{{ local_release_dir }}/{{download.dest|dirname}}"
+    src: "{{download.dest}}"
+    dest: "{{download.dest|dirname}}"
     owner: "{{ download.owner|default(omit) }}"
     mode: "{{ download.mode|default(omit) }}"
     copy: no
diff --git a/tests/testcases/040_check-network-adv.yml b/tests/testcases/040_check-network-adv.yml
index acf8658f9..709e8d8b4 100644
--- a/tests/testcases/040_check-network-adv.yml
+++ b/tests/testcases/040_check-network-adv.yml
@@ -67,14 +67,16 @@
       delay: "{{ agent_report_interval }}"
       no_log: true
       failed_when: false
-      when: not agents.content=='{}'
+      when:
+        - agents.content != '{}'
 
     - debug: var=result.content|from_json
       failed_when: not result is success
       run_once: true
-      when: not agents.content=='{}'
+      when: not agents.content == '{}'
       delegate_to: "{{groups['kube-master'][0]}}"
 
     - debug: msg="Cannot get reports from agents, consider as PASSING"
       run_once: true
-      when: agents.content=='{}'
+      when:
+        - agents.content == '{}'
-- 
GitLab