[CORD-1566]
Generate whitelist of synchronizer and GUI containers from profile

Change-Id: I38b877abe782d8e20fa44de0ec8a64ed1ac7d1f8
diff --git a/Makefile b/Makefile
index 2e2ba86..06ecd46 100644
--- a/Makefile
+++ b/Makefile
@@ -92,7 +92,7 @@
 
 $(CONFIG_FILES):
 	test -e "$(PODCONFIG_PATH)" || { echo "PODCONFIG file $(PODCONFIG_PATH) doesn't exist!" ; exit 1; }
-	ansible-playbook -i 'localhost,' --extra-vars="cord_podconfig='$(PODCONFIG_PATH)' genconfig_dir='$(GENCONFIG_D)' scenarios_dir='$(SCENARIOS_D)'" $(BUILD)/ansible/genconfig.yml $(LOGCMD)
+	ansible-playbook -i 'localhost,' --extra-vars="cord_podconfig='$(PODCONFIG_PATH)' genconfig_dir='$(GENCONFIG_D)' scenarios_dir='$(SCENARIOS_D)' platform_install_dir='$(PI)'" $(BUILD)/ansible/genconfig.yml $(LOGCMD)
 
 printconfig:
 	@echo "Scenario: '$(SCENARIO)'"
diff --git a/ansible/genconfig.yml b/ansible/genconfig.yml
index 03b126b..1e75e14 100644
--- a/ansible/genconfig.yml
+++ b/ansible/genconfig.yml
@@ -1,4 +1,4 @@
-
+---
 # Copyright 2017-present Open Networking Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,43 +13,93 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-
----
 # ansible/genconfig.yml
-# Generate configuration files
+# Generate CORD configuration files
 
 - name: Load pod and scenario config files
   hosts: localhost
   connection: local
   gather_facts: False
+
   tasks:
 
     - name: Set pod_config_path fact
       set_fact:
         pod_config_path:  "{{ cord_podconfig | realpath }}"
 
+    - name: Check for PODCONFIG file
+      stat:
+        path: "{{ pod_config_path }}"
+      register: pod_config_stat
+
+    - name: POD config file specified by 'PODCONFIG' must exist
+      assert:
+        that: pod_config_stat.stat.isreg
+
     - name: Load pod config
       include_vars: "{{ pod_config_path }}"
 
+    - name: Set profile_manifest_path fact
+      set_fact:
+        profile_manifest_path:  "{{ (platform_install_dir ~ '/profile_manifests/' ~ cord_profile ~ '.yml') | realpath }}"
+
+    - name: Check for profile manifest
+      stat:
+        path: "{{ profile_manifest_path }}"
+      register: profile_manifest_stat
+
+    - name: Profile manifest file specified by 'cord_profile' must exist
+      assert:
+        that: profile_manifest_stat.stat.isreg
+
     - name: Set scenario_config_path fact
       set_fact:
         scenario_config_path:  "{{ (scenarios_dir ~ '/' ~ cord_scenario ~ '/config.yml') | realpath }}"
 
+    - name: Check for scenario config file manifest
+      stat:
+        path: "{{ scenario_config_path }}"
+      register: scenario_config_stat
+
+    - name: Scenario config.yml file specified by 'cord_scenario' must exist
+      assert:
+        that: scenario_config_stat.stat.isreg
+
     - name: Load scenario config
       include_vars: "{{ scenario_config_path }}"
 
     - name: Reload pod config to take precedence
       include_vars: "{{ pod_config_path }}"
 
-    - name: Load pod and scenario configs into facts
+    - name: Load pod, scenario, profile_manifest into facts
       set_fact:
         pod_config: "{{ lookup('file', pod_config_path) | from_yaml }}"
         scenario_config: "{{ lookup('file', scenario_config_path) | from_yaml }}"
+        profile_manifest: "{{ lookup('file', profile_manifest_path) | from_yaml }}"
 
     - name: Combine pod and scenario config into master config
       set_fact:
         master_config: "{{ scenario_config | combine(pod_config) }}"
 
+    - name: Prime profile_container_list from with master_config.docker_image_whitelist
+      set_fact:
+        profile_container_list: "{{ master_config.docker_image_whitelist }}"
+
+    - name: Add items to profile_container_list from profile_manifest.xos_services
+      set_fact:
+        profile_container_list: "{{ profile_container_list }} + [ 'xosproject/{{ item.name }}-synchronizer' ]"
+      with_items: "{{ profile_manifest.xos_services }}"
+      when: (not master_config.frontend_only) and (item.synchronizer is not defined or item.synchronizer)
+
+    - name: Add items to profile_container_list from profile_manifest.enabled_gui_extensions
+      set_fact:
+        profile_container_list: "{{ profile_container_list }} + [ 'xosproject/gui-extension-{{ item.name }}' ]"
+      with_items: "{{ profile_manifest.enabled_gui_extensions }}"
+
+    - name: Update docker_image_whitelist to include containers specified by profile
+      set_fact:
+        master_config: "{{ master_config | combine({'docker_image_whitelist': profile_container_list}, recursive=True) }}"
+
     - name: Print vars
       debug:
         var: master_config
diff --git a/ansible/roles/genconfig/tasks/main.yml b/ansible/roles/genconfig/tasks/main.yml
index e28bfa0..1ad13fb 100644
--- a/ansible/roles/genconfig/tasks/main.yml
+++ b/ansible/roles/genconfig/tasks/main.yml
@@ -1,4 +1,4 @@
-
+---
 # Copyright 2017-present Open Networking Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,8 +13,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-
----
 # genconfig/tasks/main.yml
 
 - name: Create cord_profile file
diff --git a/scenarios/cord/config.yml b/scenarios/cord/config.yml
index feb77e9..8d6e561 100644
--- a/scenarios/cord/config.yml
+++ b/scenarios/cord/config.yml
@@ -116,32 +116,7 @@
   - "xosproject/xos-tosca"
   - "xosproject/xos-ws"
   - "xosproject/chameleon"
-  - "xosproject/gui-extension-rcord"
-  - "xosproject/gui-extension-sample"
-  - "xosproject/gui-extension-veestat"
-  - "xosproject/gui-extension-vnaas"
-  - "xosproject/gui-extension-vtr"
   - "xosproject/xos-synchronizer-base"
-  - "xosproject/addressmanager-synchronizer"
-  - "xosproject/exampleservice-synchronizer"
-  - "xosproject/fabric-synchronizer"
-  - "xosproject/onos-synchronizer"
-  - "xosproject/openstack-synchronizer"
-  - "xosproject/volt-synchronizer"
-  - "xosproject/vrouter-synchronizer"
-  - "xosproject/vee-synchronizer"
-  - "xosproject/veg-synchronizer"
-  - "xosproject/vsg-synchronizer"
-  - "xosproject/vtn-synchronizer"
-  - "xosproject/vtr-synchronizer"
-  - "xosproject/vmme-synchronizer"
-  - "xosproject/internetemulator-synchronizer"
-  - "xosproject/sdncontroller-synchronizer"
-  - "xosproject/vspgwc-synchronizer"
-  - "xosproject/vepc-synchronizer"
-  - "xosproject/vspgwu-synchronizer"
-  - "xosproject/venb-synchronizer"
-  - "xosproject/templateservice-synchronizer"
   - "gliderlabs/consul-server"
   - "gliderlabs/registrator"
   - "nginx"
diff --git a/scenarios/local/config.yml b/scenarios/local/config.yml
index f3cf726..fb5bc72 100644
--- a/scenarios/local/config.yml
+++ b/scenarios/local/config.yml
@@ -47,9 +47,6 @@
   - "xosproject/xos-tosca"
   - "xosproject/xos-ws"
   - "xosproject/chameleon"
-  - "xosproject/gui-extension-rcord"
-  - "xosproject/gui-extension-sample"
-  - "xosproject/gui-extension-vtr"
   - "gliderlabs/consul-server"
   - "gliderlabs/registrator"
   - "redis"
diff --git a/scenarios/mock/config.yml b/scenarios/mock/config.yml
index 30b1d7c..a150a43 100644
--- a/scenarios/mock/config.yml
+++ b/scenarios/mock/config.yml
@@ -68,11 +68,6 @@
   - "xosproject/xos-tosca"
   - "xosproject/xos-ws"
   - "xosproject/chameleon"
-  - "xosproject/gui-extension-rcord"
-  - "xosproject/gui-extension-sample"
-  - "xosproject/gui-extension-veestat"
-  - "xosproject/gui-extension-vnaas"
-  - "xosproject/gui-extension-vtr"
   - "gliderlabs/consul-server"
   - "gliderlabs/registrator"
   - "nginx"
diff --git a/scenarios/opencloud/config.yml b/scenarios/opencloud/config.yml
index 6012071..0de7898 100644
--- a/scenarios/opencloud/config.yml
+++ b/scenarios/opencloud/config.yml
@@ -100,16 +100,7 @@
   - "xosproject/xos-tosca"
   - "xosproject/xos-ws"
   - "xosproject/chameleon"
-  - "xosproject/gui-extension-rcord"
-  - "xosproject/gui-extension-sample"
-  - "xosproject/gui-extension-vtr"
   - "xosproject/xos-synchronizer-base"
-  - "xosproject/addressmanager-synchronizer"
-  - "xosproject/exampleservice-synchronizer"
-  - "xosproject/onos-synchronizer"
-  - "xosproject/openstack-synchronizer"
-  - "xosproject/vrouter-synchronizer"
-  - "xosproject/vtn-synchronizer"
   - "gliderlabs/consul-server"
   - "gliderlabs/registrator"
   - "nginx"
@@ -117,8 +108,6 @@
   - "redis"
   - "node"
 
-
-
 # Ansible Inventory
 inventory_groups:
 
diff --git a/scenarios/single/config.yml b/scenarios/single/config.yml
index bcdea85..b32035e 100644
--- a/scenarios/single/config.yml
+++ b/scenarios/single/config.yml
@@ -69,33 +69,7 @@
   - "xosproject/xos-tosca"
   - "xosproject/xos-ws"
   - "xosproject/chameleon"
-  - "xosproject/gui-extension-rcord"
-  - "xosproject/gui-extension-sample"
-  - "xosproject/gui-extension-veestat"
-  - "xosproject/gui-extension-vnaas"
-  - "xosproject/gui-extension-vtr"
   - "xosproject/xos-synchronizer-base"
-  - "xosproject/addressmanager-synchronizer"
-  - "xosproject/exampleservice-synchronizer"
-  - "xosproject/fabric-synchronizer"
-  - "xosproject/onos-synchronizer"
-  - "xosproject/openstack-synchronizer"
-  - "xosproject/vee-synchronizer"
-  - "xosproject/veg-synchronizer"
-  - "xosproject/vnaas-synchronizer"
-  - "xosproject/volt-synchronizer"
-  - "xosproject/vrouter-synchronizer"
-  - "xosproject/vepc-synchronizer"
-  - "xosproject/vsg-synchronizer"
-  - "xosproject/vtn-synchronizer"
-  - "xosproject/vtr-synchronizer"
-  - "xosproject/vmme-synchronizer"
-  - "xosproject/internetemulator-synchronizer"
-  - "xosproject/sdncontroller-synchronizer"
-  - "xosproject/vspgwc-synchronizer"
-  - "xosproject/vspgwu-synchronizer"
-  - "xosproject/venb-synchronizer"
-  - "xosproject/templateservice-synchronizer"
   - "gliderlabs/consul-server"
   - "gliderlabs/registrator"
   - "nginx"