From 8fd7162fa30b1bf226ac88cd7648970f29fb2eb4 Mon Sep 17 00:00:00 2001
From: caoyuan <cao.yuan@99cloud.net>
Date: Thu, 18 Jan 2018 14:57:38 +0800
Subject: [PATCH] dev mode: Add support for Watcher

Provide support for kolla dev mode in Watcher. When
'kolla_dev_mode' or 'watcher_dev_mode' variables are
enabled, source code of Watcher project is cloned
and bind mounted.

Partially implements: blueprint mount-sources

Change-Id: I104c010a8308607b68fc8c7352a0511d16f06fb5
---
 ansible/roles/watcher/defaults/main.yml           | 11 +++++++++++
 ansible/roles/watcher/handlers/main.yml           |  6 +++---
 ansible/roles/watcher/tasks/bootstrap_service.yml |  2 +-
 ansible/roles/watcher/tasks/clone.yml             |  6 ++++++
 ansible/roles/watcher/tasks/config.yml            |  2 +-
 ansible/roles/watcher/tasks/deploy.yml            |  3 +++
 6 files changed, 25 insertions(+), 5 deletions(-)
 create mode 100644 ansible/roles/watcher/tasks/clone.yml

diff --git a/ansible/roles/watcher/defaults/main.yml b/ansible/roles/watcher/defaults/main.yml
index 854afe1ba..b5eafe622 100644
--- a/ansible/roles/watcher/defaults/main.yml
+++ b/ansible/roles/watcher/defaults/main.yml
@@ -10,6 +10,7 @@ watcher_services:
     volumes:
       - "{{ node_config_directory }}/watcher-api/:{{ container_config_directory }}/:ro"
       - "/etc/localtime:/etc/localtime:ro"
+      - "{{ kolla_dev_repos_directory ~ '/watcher/watcher:/var/lib/kolla/venv/lib/python2.7/site-packages/watcher' if watcher_dev_mode | bool else '' }}"
       - "kolla_logs:/var/log/kolla/"
   watcher-applier:
     container_name: watcher_applier
@@ -19,6 +20,7 @@ watcher_services:
     volumes:
       - "{{ node_config_directory }}/watcher-applier/:{{ container_config_directory }}/:ro"
       - "/etc/localtime:/etc/localtime:ro"
+      - "{{ kolla_dev_repos_directory ~ '/watcher/watcher:/var/lib/kolla/venv/lib/python2.7/site-packages/watcher' if watcher_dev_mode | bool else '' }}"
       - "kolla_logs:/var/log/kolla/"
   watcher-engine:
     container_name: watcher_engine
@@ -28,6 +30,7 @@ watcher_services:
     volumes:
       - "{{ node_config_directory }}/watcher-engine/:{{ container_config_directory }}/:ro"
       - "/etc/localtime:/etc/localtime:ro"
+      - "{{ kolla_dev_repos_directory ~ '/watcher/watcher:/var/lib/kolla/venv/lib/python2.7/site-packages/watcher' if watcher_dev_mode | bool else '' }}"
       - "kolla_logs:/var/log/kolla/"
 
 
@@ -69,3 +72,11 @@ watcher_logging_debug: "{{ openstack_logging_debug }}"
 watcher_keystone_user: "watcher"
 
 openstack_watcher_auth: "{{ openstack_auth }}"
+
+
+####################
+# Kolla
+####################
+watcher_git_repository: "{{ kolla_dev_repos_git }}/{{ project_name }}"
+watcher_dev_repos_pull: "{{ kolla_dev_repos_pull }}"
+watcher_dev_mode: "{{ kolla_dev_mode }}"
diff --git a/ansible/roles/watcher/handlers/main.yml b/ansible/roles/watcher/handlers/main.yml
index 3ae4379b5..4fd9e4b0d 100644
--- a/ansible/roles/watcher/handlers/main.yml
+++ b/ansible/roles/watcher/handlers/main.yml
@@ -13,7 +13,7 @@
     common_options: "{{ docker_common_options }}"
     name: "{{ service.container_name }}"
     image: "{{ service.image }}"
-    volumes: "{{ service.volumes }}"
+    volumes: "{{ service.volumes|reject('equalto', '')|list }}"
   when:
     - kolla_action != "config"
     - inventory_hostname in groups[service.group]
@@ -37,7 +37,7 @@
     common_options: "{{ docker_common_options }}"
     name: "{{ service.container_name }}"
     image: "{{ service.image }}"
-    volumes: "{{ service.volumes }}"
+    volumes: "{{ service.volumes|reject('equalto', '')|list }}"
   when:
     - kolla_action != "config"
     - inventory_hostname in groups[service.group]
@@ -61,7 +61,7 @@
     common_options: "{{ docker_common_options }}"
     name: "{{ service.container_name }}"
     image: "{{ service.image }}"
-    volumes: "{{ service.volumes }}"
+    volumes: "{{ service.volumes|reject('equalto', '')|list }}"
   when:
     - kolla_action != "config"
     - inventory_hostname in groups[service.group]
diff --git a/ansible/roles/watcher/tasks/bootstrap_service.yml b/ansible/roles/watcher/tasks/bootstrap_service.yml
index 7e419de3b..089e9f2dc 100644
--- a/ansible/roles/watcher/tasks/bootstrap_service.yml
+++ b/ansible/roles/watcher/tasks/bootstrap_service.yml
@@ -15,6 +15,6 @@
       BOOTSTRAP:
     name: "bootstrap_watcher"
     restart_policy: "never"
-    volumes: "{{ watcher_api.volumes }}"
+    volumes: "{{ watcher_api.volumes|reject('equalto', '')|list }}"
   run_once: True
   delegate_to: "{{ groups[watcher_api.group][0] }}"
diff --git a/ansible/roles/watcher/tasks/clone.yml b/ansible/roles/watcher/tasks/clone.yml
new file mode 100644
index 000000000..47c1b86be
--- /dev/null
+++ b/ansible/roles/watcher/tasks/clone.yml
@@ -0,0 +1,6 @@
+---
+- name: Cloning watcher source repository for development
+  git:
+    repo: "{{ watcher_git_repository }}"
+    dest: "{{ kolla_dev_repos_directory }}/{{ project_name }}"
+    update: "{{ watcher_dev_repos_pull }}"
diff --git a/ansible/roles/watcher/tasks/config.yml b/ansible/roles/watcher/tasks/config.yml
index aa2e09fe3..775e3840d 100644
--- a/ansible/roles/watcher/tasks/config.yml
+++ b/ansible/roles/watcher/tasks/config.yml
@@ -88,7 +88,7 @@
     common_options: "{{ docker_common_options }}"
     name: "{{ item.value.container_name }}"
     image: "{{ item.value.image }}"
-    volumes: "{{ item.value.volumes }}"
+    volumes: "{{ item.value.volumes|reject('equalto', '')|list }}"
   register: check_watcher_containers
   when:
     - kolla_action != "config"
diff --git a/ansible/roles/watcher/tasks/deploy.yml b/ansible/roles/watcher/tasks/deploy.yml
index 2b77abf57..3383b08d5 100644
--- a/ansible/roles/watcher/tasks/deploy.yml
+++ b/ansible/roles/watcher/tasks/deploy.yml
@@ -7,6 +7,9 @@
         inventory_hostname in groups['watcher-engine'] or
         inventory_hostname in groups['watcher-applier']
 
+- include: clone.yml
+  when: watcher_dev_mode | bool
+
 - include: bootstrap.yml
   when: inventory_hostname in groups['watcher-api']
 
-- 
GitLab