From 59a0ddcd01f7da1a8121a584908a9d4a90d9b211 Mon Sep 17 00:00:00 2001
From: caoyuan <cao.yuan@99cloud.net>
Date: Fri, 13 Apr 2018 00:21:21 +0800
Subject: [PATCH] dev mode: Add support for designate

Provide support for kolla dev mode in designate. When
'kolla_dev_mode' or 'designate_dev_mode' variables are
enabled, source code of designate project is cloned
and bindmounted.

Partially implements: blueprint mount-sources
Co-Authored-By: zhulingjie <easyzlj@gmail.com>

Change-Id: Ib23fbd3d5ebc7e3ac372e0db1e0048d333eb95c0
---
 ansible/roles/designate/defaults/main.yml          | 14 ++++++++++++++
 ansible/roles/designate/handlers/main.yml          | 14 +++++++-------
 .../roles/designate/tasks/bootstrap_service.yml    |  2 +-
 ansible/roles/designate/tasks/clone.yml            |  6 ++++++
 ansible/roles/designate/tasks/config.yml           |  2 +-
 ansible/roles/designate/tasks/deploy.yml           |  3 +++
 6 files changed, 32 insertions(+), 9 deletions(-)
 create mode 100644 ansible/roles/designate/tasks/clone.yml

diff --git a/ansible/roles/designate/defaults/main.yml b/ansible/roles/designate/defaults/main.yml
index a7e142fbb..3af79afdf 100644
--- a/ansible/roles/designate/defaults/main.yml
+++ b/ansible/roles/designate/defaults/main.yml
@@ -11,6 +11,7 @@ designate_services:
       - "{{ node_config_directory }}/designate-api/:{{ container_config_directory }}/:ro"
       - "/etc/localtime:/etc/localtime:ro"
       - "kolla_logs:/var/log/kolla/"
+      - "{{ kolla_dev_repos_directory ~ '/designate/designate:/var/lib/kolla/venv/lib/python2.7/site-packages/designate' if designate_dev_mode | bool else '' }}"
   designate-backend-bind9:
     container_name: designate_backend_bind9
     group: designate-backend-bind9
@@ -30,6 +31,7 @@ designate_services:
       - "{{ node_config_directory }}/designate-central/:{{ container_config_directory }}/:ro"
       - "/etc/localtime:/etc/localtime:ro"
       - "kolla_logs:/var/log/kolla/"
+      - "{{ kolla_dev_repos_directory ~ '/designate/designate:/var/lib/kolla/venv/lib/python2.7/site-packages/designate' if designate_dev_mode | bool else '' }}"
   designate-mdns:
     container_name: designate_mdns
     group: designate-mdns
@@ -39,6 +41,7 @@ designate_services:
       - "{{ node_config_directory }}/designate-mdns/:{{ container_config_directory }}/:ro"
       - "/etc/localtime:/etc/localtime:ro"
       - "kolla_logs:/var/log/kolla/"
+      - "{{ kolla_dev_repos_directory ~ '/designate/designate:/var/lib/kolla/venv/lib/python2.7/site-packages/designate' if designate_dev_mode | bool else '' }}"
   designate-producer:
     container_name: designate_producer
     group: designate-producer
@@ -48,6 +51,7 @@ designate_services:
       - "{{ node_config_directory }}/designate-producer/:{{ container_config_directory }}/:ro"
       - "/etc/localtime:/etc/localtime:ro"
       - "kolla_logs:/var/log/kolla/"
+      - "{{ kolla_dev_repos_directory ~ '/designate/designate:/var/lib/kolla/venv/lib/python2.7/site-packages/designate' if designate_dev_mode | bool else '' }}"
   designate-worker:
     container_name: designate_worker
     group: designate-worker
@@ -57,6 +61,7 @@ designate_services:
       - "{{ node_config_directory }}/designate-worker/:{{ container_config_directory }}/:ro"
       - "/etc/localtime:/etc/localtime:ro"
       - "kolla_logs:/var/log/kolla/"
+      - "{{ kolla_dev_repos_directory ~ '/designate/designate:/var/lib/kolla/venv/lib/python2.7/site-packages/designate' if designate_dev_mode | bool else '' }}"
   designate-sink:
     container_name: designate_sink
     group: designate-sink
@@ -66,6 +71,7 @@ designate_services:
       - "{{ node_config_directory }}/designate-sink/:{{ container_config_directory }}/:ro"
       - "/etc/localtime:/etc/localtime:ro"
       - "kolla_logs:/var/log/kolla/"
+      - "{{ kolla_dev_repos_directory ~ '/designate/designate:/var/lib/kolla/venv/lib/python2.7/site-packages/designate' if designate_dev_mode | bool else '' }}"
 
 
 ####################
@@ -126,3 +132,11 @@ designate_logging_debug: "{{ openstack_logging_debug }}"
 designate_keystone_user: "designate"
 
 openstack_designate_auth: "{{ openstack_auth }}"
+
+
+####################
+# Kolla
+####################
+designate_git_repository: "{{ kolla_dev_repos_git }}/{{ project_name }}"
+designate_dev_repos_pull: "{{ kolla_dev_repos_pull }}"
+designate_dev_mode: "{{ kolla_dev_mode }}"
diff --git a/ansible/roles/designate/handlers/main.yml b/ansible/roles/designate/handlers/main.yml
index d78e528c5..39d514ec9 100644
--- a/ansible/roles/designate/handlers/main.yml
+++ b/ansible/roles/designate/handlers/main.yml
@@ -11,7 +11,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]
@@ -36,7 +36,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]
@@ -60,7 +60,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]
@@ -84,7 +84,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]
@@ -108,7 +108,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]
@@ -132,7 +132,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]
@@ -158,7 +158,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/designate/tasks/bootstrap_service.yml b/ansible/roles/designate/tasks/bootstrap_service.yml
index be3b9dde1..b7928f91d 100644
--- a/ansible/roles/designate/tasks/bootstrap_service.yml
+++ b/ansible/roles/designate/tasks/bootstrap_service.yml
@@ -15,6 +15,6 @@
       BOOTSTRAP:
     name: "bootstrap_designate"
     restart_policy: "never"
-    volumes: "{{ designate_central.volumes }}"
+    volumes: "{{ designate_central.volumes|reject('equalto', '')|list }}"
   run_once: True
   delegate_to: "{{ groups[designate_central.group][0] }}"
diff --git a/ansible/roles/designate/tasks/clone.yml b/ansible/roles/designate/tasks/clone.yml
new file mode 100644
index 000000000..9e7e97e92
--- /dev/null
+++ b/ansible/roles/designate/tasks/clone.yml
@@ -0,0 +1,6 @@
+---
+- name: Cloning designate source repository for development
+  git:
+    repo: "{{ designate_git_repository }}"
+    dest: "{{ kolla_dev_repos_directory }}/{{ project_name }}"
+    update: "{{ designate_dev_repos_pull }}"
diff --git a/ansible/roles/designate/tasks/config.yml b/ansible/roles/designate/tasks/config.yml
index a51e1a798..3f4be6b6f 100644
--- a/ansible/roles/designate/tasks/config.yml
+++ b/ansible/roles/designate/tasks/config.yml
@@ -183,7 +183,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_designate_containers
   when:
     - kolla_action != "config"
diff --git a/ansible/roles/designate/tasks/deploy.yml b/ansible/roles/designate/tasks/deploy.yml
index 35cf6a371..0d05569d8 100644
--- a/ansible/roles/designate/tasks/deploy.yml
+++ b/ansible/roles/designate/tasks/deploy.yml
@@ -11,6 +11,9 @@
         inventory_hostname in groups['designate-sink'] or
         inventory_hostname in groups['designate-backend-bind9']
 
+- include: clone.yml
+  when: designate_dev_mode | bool
+
 - include: bootstrap.yml
   when: inventory_hostname in groups['designate-central']
 
-- 
GitLab