Merge pull request #1 from salt-formulas/known-fixups

Cleanup + extend tests/pillars
diff --git a/.gitignore b/.gitignore
index 1bfce6e..aa8e42a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
+.kitchen
 tests/build/
 *.swp
 *.pyc
-.ropeproject
\ No newline at end of file
+.ropeproject
diff --git a/.gitreview b/.gitreview
deleted file mode 100644
index d2e4e1c..0000000
--- a/.gitreview
+++ /dev/null
@@ -1,4 +0,0 @@
-[gerrit]
-host=review.openstack.org
-port=29418
-project=openstack/salt-formula-opencontrail.git
diff --git a/Makefile b/Makefile
index fc83783..1043fbe 100644
--- a/Makefile
+++ b/Makefile
@@ -1,12 +1,38 @@
 DESTDIR=/
 SALTENVDIR=/usr/share/salt-formulas/env
 RECLASSDIR=/usr/share/salt-formulas/reclass
-FORMULANAME=$(shell grep name: metadata.yml|head -1|cut -d : -f 2|grep -Eo '[a-z0-9\-]*')
+FORMULANAME=$(shell grep name: metadata.yml|head -1|cut -d : -f 2|grep -Eo '[a-z0-9\-\_]*')
+VERSION=$(shell grep version: metadata.yml|head -1|cut -d : -f 2|grep -Eo '[a-z0-9\.\-\_]*')
+VERSION_MAJOR := $(shell echo $(VERSION)|cut -d . -f 1-2)
+VERSION_MINOR := $(shell echo $(VERSION)|cut -d . -f 3)
+
+NEW_MAJOR_VERSION ?= $(shell date +%Y.%m|sed 's,\.0,\.,g')
+NEW_MINOR_VERSION ?= $(shell /bin/bash -c 'echo $$[ $(VERSION_MINOR) + 1 ]')
+
+MAKE_PID := $(shell echo $$PPID)
+JOB_FLAG := $(filter -j%, $(subst -j ,-j,$(shell ps T | grep "^\s*$(MAKE_PID).*$(MAKE)")))
+
+ifneq ($(subst -j,,$(JOB_FLAG)),)
+JOBS := $(subst -j,,$(JOB_FLAG))
+else
+JOBS := 1
+endif
+
+KITCHEN_LOCAL_YAML?=.kitchen.yml
+KITCHEN_OPTS?="--concurrency=$(JOBS)"
+KITCHEN_OPTS_CREATE?=""
+KITCHEN_OPTS_CONVERGE?=""
+KITCHEN_OPTS_VERIFY?=""
+KITCHEN_OPTS_TEST?=""
 
 all:
 	@echo "make install - Install into DESTDIR"
 	@echo "make test    - Run tests"
+	@echo "make kitchen - Run Kitchen CI tests (create, converge, verify)"
 	@echo "make clean   - Cleanup after tests run"
+	@echo "make release-major  - Generate new major release"
+	@echo "make release-minor  - Generate new minor release"
+	@echo "make changelog      - Show changes since last release"
 
 install:
 	# Formula
@@ -14,6 +40,7 @@
 	cp -a $(FORMULANAME) $(DESTDIR)/$(SALTENVDIR)/
 	[ ! -d _modules ] || cp -a _modules $(DESTDIR)/$(SALTENVDIR)/
 	[ ! -d _states ] || cp -a _states $(DESTDIR)/$(SALTENVDIR)/ || true
+	[ ! -d _grains ] || cp -a _grains $(DESTDIR)/$(SALTENVDIR)/ || true
 	# Metadata
 	[ -d $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME) ] || mkdir -p $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME)
 	cp -a metadata/service/* $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME)
@@ -21,6 +48,71 @@
 test:
 	[ ! -d tests ] || (cd tests; ./run_tests.sh)
 
+release-major: check-changes
+	@echo "Current version is $(VERSION), new version is $(NEW_MAJOR_VERSION)"
+	@[ $(VERSION_MAJOR) != $(NEW_MAJOR_VERSION) ] || (echo "Major version $(NEW_MAJOR_VERSION) already released, nothing to do. Do you want release-minor?" && exit 1)
+	echo "$(NEW_MAJOR_VERSION)" > VERSION
+	sed -i 's,version: .*,version: "$(NEW_MAJOR_VERSION)",g' metadata.yml
+	[ ! -f debian/changelog ] || dch -v $(NEW_MAJOR_VERSION) -m --force-distribution -D `dpkg-parsechangelog -S Distribution` "New version"
+	make genchangelog-$(NEW_MAJOR_VERSION)
+	(git add -u; git commit -m "Version $(NEW_MAJOR_VERSION)")
+	git tag -s -m $(NEW_MAJOR_VERSION) $(NEW_MAJOR_VERSION)
+
+release-minor: check-changes
+	@echo "Current version is $(VERSION), new version is $(VERSION_MAJOR).$(NEW_MINOR_VERSION)"
+	echo "$(VERSION_MAJOR).$(NEW_MINOR_VERSION)" > VERSION
+	sed -i 's,version: .*,version: "$(VERSION_MAJOR).$(NEW_MINOR_VERSION)",g' metadata.yml
+	[ ! -f debian/changelog ] || dch -v $(VERSION_MAJOR).$(NEW_MINOR_VERSION) -m --force-distribution -D `dpkg-parsechangelog -S Distribution` "New version"
+	make genchangelog-$(VERSION_MAJOR).$(NEW_MINOR_VERSION)
+	(git add -u; git commit -m "Version $(VERSION_MAJOR).$(NEW_MINOR_VERSION)")
+	git tag -s -m $(NEW_MAJOR_VERSION) $(VERSION_MAJOR).$(NEW_MINOR_VERSION)
+
+check-changes:
+	@git log --pretty=oneline --decorate $(VERSION)..HEAD | grep -Eqc '.*' || (echo "No new changes since version $(VERSION)"; exit 1)
+
+changelog:
+	git log --pretty=short --invert-grep --grep="Merge pull request" --decorate $(VERSION)..HEAD
+
+genchangelog: genchangelog-$(VERSION_MAJOR).$(NEW_MINOR_VERSION)
+
+genchangelog-%:
+	$(eval NEW_VERSION := $(patsubst genchangelog-%,%,$@))
+	(echo "=========\nChangelog\n=========\n"; \
+	(echo $(NEW_VERSION);git tag) | sort -r | grep -E '^[0-9\.]+' | while read i; do \
+	    cur=$$i; \
+	    test $$i = $(NEW_VERSION) && i=HEAD; \
+	    prev=`(echo $(NEW_VERSION);git tag)|sort|grep -E '^[0-9\.]+'|grep -B1 "$$cur\$$"|head -1`; \
+	    echo "Version $$cur\n=============================\n"; \
+	    git log --pretty=short --invert-grep --grep="Merge pull request" --decorate $$prev..$$i; \
+	    echo; \
+	done) > CHANGELOG.rst
+
+kitchen-check:
+	@[ -e $(KITCHEN_LOCAL_YAML) ] || (echo "Kitchen tests not available, there's no $(KITCHEN_LOCAL_YAML)." && exit 1)
+
+kitchen: kitchen-check kitchen-create kitchen-converge kitchen-verify kitchen-list
+
+kitchen-create: kitchen-check
+	kitchen create ${KITCHEN_OPTS} ${KITCHEN_OPTS_CREATE}
+	[ "$(shell echo $(KITCHEN_LOCAL_YAML)|grep -Eo docker)" = "docker" ] || sleep 120
+
+kitchen-converge: kitchen-check
+	kitchen converge ${KITCHEN_OPTS} ${KITCHEN_OPTS_CONVERGE} &&\
+	kitchen converge ${KITCHEN_OPTS} ${KITCHEN_OPTS_CONVERGE}
+
+kitchen-verify: kitchen-check
+	[ ! -d tests/integration ] || kitchen verify -t tests/integration ${KITCHEN_OPTS} ${KITCHEN_OPTS_VERIFY}
+	[ -d tests/integration ]   || kitchen verify ${KITCHEN_OPTS} ${KITCHEN_OPTS_VERIFY}
+
+kitchen-test: kitchen-check
+	[ ! -d tests/integration ] || kitchen test -t tests/integration ${KITCHEN_OPTS} ${KITCHEN_OPTS_TEST}
+	[ -d tests/integration ]   || kitchen test ${KITCHEN_OPTS} ${KITCHEN_OPTS_TEST}
+
+kitchen-list: kitchen-check
+	kitchen list
+
 clean:
+	[ ! -x "$(shell which kitchen)" ] || kitchen destroy
+	[ ! -d .kitchen ] || rm -rf .kitchen
 	[ ! -d tests/build ] || rm -rf tests/build
 	[ ! -d build ] || rm -rf build
diff --git a/README.rst b/README.rst
index 1fd8771..fb8ebbe 100644
--- a/README.rst
+++ b/README.rst
@@ -769,3 +769,36 @@
 Developers should also join the discussion on the IRC list, at:
 
     https://wiki.openstack.org/wiki/Meetings/openstack-salt
+
+Documentation and Bugs
+======================
+
+To learn how to install and update salt-formulas, consult the documentation
+available online at:
+
+    http://salt-formulas.readthedocs.io/
+
+In the unfortunate event that bugs are discovered, they should be reported to
+the appropriate issue tracker. Use Github issue tracker for specific salt
+formula:
+
+    https://github.com/salt-formulas/salt-formula-opencontrail/issues
+
+For feature requests, bug reports or blueprints affecting entire ecosystem,
+use Launchpad salt-formulas project:
+
+    https://launchpad.net/salt-formulas
+
+You can also join salt-formulas-users team and subscribe to mailing list:
+
+    https://launchpad.net/~salt-formulas-users
+
+Developers wishing to work on the salt-formulas projects should always base
+their work on master branch and submit pull request against specific formula.
+
+    https://github.com/salt-formulas/salt-formula-opencontrail
+
+Any questions or feedback is always welcome so feel free to join our IRC
+channel:
+
+    #salt-formulas @ irc.freenode.net
diff --git a/opencontrail/meta/collectd.yml b/opencontrail/meta/collectd.yml
index 846450c..9cce855 100644
--- a/opencontrail/meta/collectd.yml
+++ b/opencontrail/meta/collectd.yml
@@ -1,18 +1,23 @@
 {%- if pillar.opencontrail is defined %}
-{%- if pillar.opencontrail.control is defined %}
-{%- from "opencontrail/map.jinja" import control, collector, config, database, web with context %}
+  {%- from "opencontrail/map.jinja" import control, collector, compute, config, database, web with context %}
 local_plugin:
-{%- if control.get('enabled', False) %}
-{%- if database is defined and database.get('cassandra', False) %}
+  {%- if compute.get('enabled', False) %}
+  contrail_ifmap_elements_count:
+    plugin: python
+    template: opencontrail/files/collectd_contrail_ifmap_elements_count.conf
+  {%- endif %}
+  {%- if database.get('cassandra', False) %}
   collectd_cassandra_jmx:
     plugin: java
     template: opencontrail/files/collectd_cassandra_jmx.conf
-{%- endif %}
-{%- set bind_addr=control.bind.address|replace('0.0.0.0', '127.0.0.1') %}
+  {%- endif %}
+  {%- if control.get('enabled', False) or compute.get('enabled', False) %}
   collectd_contrail_apis:
     plugin: python
     template: opencontrail/files/collectd_contrail_apis.conf
     api_checks:
+    {%- if control.get('enabled', False) %}
+      {%- set bind_addr=control.bind.address|replace('0.0.0.0', '127.0.0.1') %}
       bgp_session_count:
         url: "http://{{ bind_addr }}:8083/Snh_ShowNeighborStatisticsReq?bgp_or_xmpp=bgp"
         xml_element: "ShowNeighborStatisticsResp"
@@ -37,99 +42,9 @@
         url: "http://{{ bind_addr }}:8083/Snh_ShowNeighborStatisticsReq?bgp_or_xmpp=xmpp&up_or_down=down"
         xml_element: "ShowNeighborStatisticsResp"
         result_type: "count"
-{%- endif %}
-  collectd_check_local_endpoint:
-    endpoint:
-{%- if config.get('enabled', False) %}
-{%- set bind_addr=config.bind.address|replace('0.0.0.0', '127.0.0.1') %}
-      contrail-api:
-        expected_code: 401
-        url: "http://{{ bind_addr }}:{{ config.bind.api_port }}/"
-      contrail-discovery:
-        expected_code: 200
-        url: "http://{{ bind_addr }}:{{ config.bind.discovery_port }}/"
-{%- endif %}
-{%- if collector.get('enabled', False) %}
-      contrail-collector:
-        expected_code: 200
-        url: "http://{{ collector.bind.address|replace('0.0.0.0', '127.0.0.1') }}:{{ collector.bind.port }}/"
-{%- endif %}
-  collectd_processes:
-    process:
-      contrail-alarm-gen:
-        match: 'python.*contrail-alarm-gen'
-      contrail-analytics-api:
-        match: 'python.*contrail-analytics-api'
-      contrail-api:
-        match: 'python.*contrail-api'
-      contrail-collector:
-        match: 'contrail-collector'
-      contrail-control:
-        match: '[^=]contrail-control$'
-      contrail-device-manager:
-        match: 'python.*contrail-device-manager'
-      contrail-discovery:
-        match: 'python.*contrail-discovery'
-      contrail-dns:
-        match: 'contrail-dns'
-      contrail-ifmap-server:
-        match: 'sh.*ifmap-server'
-      contrail-irond:
-        match: 'java.*irond'
-      contrail-job-server:
-        match: 'node.*jobServerStart'
-      contrail-named:
-        match: 'contrail-named'
-      contrail-nodemgr:
-        match: 'python.*contrail-nodemgr$'
-      contrail-nodemgr-config:
-        match: 'python.*contrail-nodemgr.*-config'
-      contrail-nodemgr-control:
-        match: 'python.*contrail-nodemgr.*-control'
-      contrail-nodemgr-database:
-        match: 'python.*contrail-nodemgr.*-database'
-      contrail-query-engine:
-        match: 'contrail-query-engine'
-      contrail-schema:
-        match: 'python.*contrail-schema'
-      contrail-snmp-collector:
-        match: 'python.*contrail-snmp-collector'
-      contrail-supervisord-analytics:
-        match: 'python.*supervisord.*_analytics'
-      contrail-supervisord-config:
-        match: 'python.*supervisord.*_config'
-      contrail-supervisord-control:
-        match: 'python.*supervisord.*_control'
-      contrail-supervisord-database:
-        match: 'python.*supervisord.*_database'
-      contrail-svc-monitor:
-        match: 'python.*contrail-svc-monitor'
-      contrail-topology:
-        match: 'python.*contrail-topology'
-{%- if web.get('enabled', False) %}
-      contrail-web-server:
-        match: 'node.*webServerStart'
-{%- endif %}
-      zookeeper-server:
-        match: 'java.*zookeeper.server'
-      kafka-server:
-        match: 'java.*kafka.Kafka'
-      redis-server:
-        match: 'redis-server'
-      cassandra-server:
-        match: 'java.*service.CassandraDaemon'
-{%- elif pillar.opencontrail.compute is defined %}
-{%- from "opencontrail/map.jinja" import compute with context %}
-{%- if compute.get('enabled', False) %}
-{%- set bind_addr=compute.interface.address|replace('0.0.0.0', '127.0.0.1') %}
-local_plugin:
-  contrail_ifmap_elements_count:
-    plugin: python
-    template: opencontrail/files/collectd_contrail_ifmap_elements_count.conf
-  collectd_contrail_apis:
-    plugin: python
-    template: opencontrail/files/collectd_contrail_apis.conf
-    api_checks:
+    {%- endif %}
+    {%- if compute.get('enabled', False) %}
+      {%- set bind_addr=compute.interface.address|replace('0.0.0.0', '127.0.0.1') %}
       vrouter_flows_active:
         url: "http://{{ bind_addr }}:8085/Snh_AgentStatsReq"
         xml_element: "FlowStatsResp"
@@ -185,22 +100,115 @@
         url: "http://{{ bind_addr }}:8085/Snh_AgentXmppConnectionStatusReq"
         xml_element: "AgentXmppData"
         state: "Established"
+    {%- endif %}
+  {%- endif %}
+  {%- if config.get('enabled', False) or collector.get('enabled', False) or compute.get('enabled', False) %}
   collectd_check_local_endpoint:
     endpoint:
+    {%- if config.get('enabled', False) %}
+      {%- set bind_addr=config.bind.address|replace('0.0.0.0', '127.0.0.1') %}
+      contrail-api:
+        expected_code: 401
+        url: "http://{{ bind_addr }}:{{ config.bind.api_port }}/"
+      contrail-discovery:
+        expected_code: 200
+        url: "http://{{ bind_addr }}:{{ config.bind.discovery_port }}/"
+    {%- endif %}
+    {%- if collector.get('enabled', False) %}
+      contrail-collector:
+        expected_code: 200
+        url: "http://{{ collector.bind.address|replace('0.0.0.0', '127.0.0.1') }}:{{ collector.bind.port }}/"
+    {%- endif %}
+    {%- if compute.get('enabled', False) %}
       contrail-node-manager:
         expected_code: 200
         url: "http://127.0.0.1:8102/"
       contrail-vrouter:
         expected_code: 200
         url: "http://127.0.0.1:8085/"
+    {%- endif %}
+  {%- endif %}
+  {%- if collector.get('enabled', False) or database.get('enabled', False) or control.get('enabled', False)
+         or web.get('enabled', False) or compute.get('enabled', False) %}
   collectd_processes:
     process:
+    {%- if collector.get('enabled', False) %}
+      contrail-alarm-gen:
+        match: 'python.*contrail-alarm-gen'
+      contrail-analytics-api:
+        match: 'python.*contrail-analytics-api'
+      contrail-collector:
+        match: 'contrail-collector'
+      contrail-nodemgr:
+        match: 'python.*contrail-nodemgr$'
+      contrail-query-engine:
+        match: 'contrail-query-engine'
+      contrail-snmp-collector:
+        match: 'python.*contrail-snmp-collector'
+      contrail-supervisord-analytics:
+        match: 'python.*supervisord.*_analytics'
+      contrail-topology:
+        match: 'python.*contrail-topology'
+    {%- endif %}
+    {%- if database.get('enabled', False) %}
+      zookeeper-server:
+        match: 'java.*zookeeper.server'
+      kafka-server:
+        match: 'java.*kafka.Kafka'
+      cassandra-server:
+        match: 'java.*service.CassandraDaemon'
+      contrail-nodemgr-database:
+        match: 'python.*contrail-nodemgr.*-database'
+      contrail-supervisord-database:
+        match: 'python.*supervisord.*_database'
+    {%- endif %}
+    {%- if control.get('enabled', False) %}
+      contrail-api:
+        match: 'python.*contrail-api'
+      contrail-control:
+        match: '[^=]contrail-control$'
+      contrail-device-manager:
+        match: 'python.*contrail-device-manager'
+      contrail-discovery:
+        match: 'python.*contrail-discovery'
+      contrail-dns:
+        match: 'contrail-dns'
+      contrail-ifmap-server:
+        match: 'sh.*ifmap-server'
+      contrail-irond:
+        match: 'java.*irond'
+      contrail-job-server:
+        match: 'node.*jobServerStart'
+      contrail-named:
+        match: 'contrail-named'
+      contrail-nodemgr-config:
+        match: 'python.*contrail-nodemgr.*-config'
+      contrail-nodemgr-control:
+        match: 'python.*contrail-nodemgr.*-control'
+      contrail-schema:
+        match: 'python.*contrail-schema'
+      contrail-supervisord-config:
+        match: 'python.*supervisord.*_config'
+      contrail-supervisord-control:
+        match: 'python.*supervisord.*_control'
+      contrail-svc-monitor:
+        match: 'python.*contrail-svc-monitor'
+    {%- endif %}
+    {%- if web.get('enabled', False) %}
+      contrail-web-server:
+        match: 'node.*webServerStart'
+      {%- if web.get('cache', {}).get('engine', '') == 'redis' %}
+      redis-server:
+        match: 'redis-server'
+      {%- endif %}
+    {%- endif %}
+    {%- if compute.get('enabled', False) %}
       contrail-nodemgr-vrouter:
         match: 'python.*contrail-nodemgr.*-vrouter'
       contrail-supervisord-vrouter:
         match: 'python.*supervisord.*_vrouter'
       contrail-vrouter-agent:
         match: 'contrail-vrouter-agent'
-{%- endif %}
-{%- endif %}
+    {%- endif %}
+  {%- endif %}
 {%- endif %}
diff --git a/opencontrail/meta/heka.yml b/opencontrail/meta/heka.yml
index 5106197..b2cc93e 100644
--- a/opencontrail/meta/heka.yml
+++ b/opencontrail/meta/heka.yml
@@ -1,41 +1,47 @@
 {%- if pillar.opencontrail is defined %}
-  {%- if pillar.opencontrail.control is defined %}
-    {%- from "opencontrail/map.jinja" import control with context %}
-    {%- if control.get('enabled', False) %}
-      {%- set controller_ref = control %}
-      {%- set control_processes = (
-            'cassandra-server', 'contrail-alarm-gen', 'contrail-analytics-api',
-            'contrail-api', 'contrail-collector', 'contrail-control',
-            'contrail-device-manager', 'contrail-discovery', 'contrail-dns',
-            'contrail-ifmap-server', 'contrail-irond', 'contrail-job-server',
-            'contrail-named', 'contrail-nodemgr', 'contrail-nodemgr-config',
-            'contrail-nodemgr-control', 'contrail-nodemgr-database', 'contrail-query-engine',
-            'contrail-schema', 'contrail-snmp-collector', 'contrail-supervisord-analytics',
-            'contrail-supervisord-config', 'contrail-supervisord-control', 'contrail-supervisord-database',
-            'contrail-svc-monitor', 'contrail-topology',
-            'kafka-server', 'redis-server', 'zookeeper-server'
+  {%- from "opencontrail/map.jinja" import control, collector, compute, config, database, web with context %}
+  {%- if collector.get('enabled', False) %}
+    {%- set collector_processes = (
+        'contrail-alarm-gen', 'contrail-analytics-api', 'contrail-collector',
+        'contrail-nodemgr', 'contrail-query-engine', 'contrail-snmp-collector',
+        'contrail-supervisord-analytics', 'contrail-topology',
+        ) %}
+  {%- endif %}
+  {%- if compute.get('enabled', False) %}
+    {%- set compute_processes = (
+        'contrail-nodemgr-vrouter', 'contrail-supervisord-vrouter', 'contrail-vrouter-agent'
+        ) %}
+  {%- endif %}
+  {%- if control.get('enabled', False) %}
+    {%- set control_processes = (
+        'contrail-api', 'contrail-control', 'contrail-device-manager',
+        'contrail-discovery', 'contrail-dns', 'contrail-ifmap-server',
+        'contrail-irond', 'contrail-job-server', 'contrail-named',
+        'contrail-nodemgr-config', 'contrail-nodemgr-control',
+        'contrail-schema', 'contrail-supervisord-config',
+        'contrail-supervisord-control', 'contrail-svc-monitor',
+        ) %}
+  {%- endif %}
+  {%- if database.get('enabled', False) %}
+    {%- set database_processes = (
+        'zookeeper-server', 'kafka-server', 'cassandra-server',
+        'contrail-nodemgr-database', 'contrail-supervisord-database',
+        ) %}
+  {%- endif %}
+  {%- if web.get('enabled', False) %}
+    {%- if web.get('cache', {}).get('engine', '') == 'redis' %}
+      {%- set web_processes = (
+          'contrail-web-server', 'redis-server'
           ) %}
-    {%- endif %}
-  {%- elif pillar.opencontrail.compute is defined %}
-    {%- from "opencontrail/map.jinja" import compute with context %}
-    {%- if compute.get('enabled', False) %}
-      {%- set compute_ref = compute %}
-      {%- set compute_processes = (
-            'contrail-nodemgr-vrouter', 'contrail-supervisord-vrouter', 'contrail-vrouter-agent'
+    {%- else %}
+      {%- set web_processes = (
+          'contrail-web-server'
           ) %}
     {%- endif %}
   {%- endif %}
-  {%- if pillar.opencontrail.web is defined %}
-    {%- from "opencontrail/map.jinja" import web with context %}
-    {%- if web.get('enabled', False) %}
-      {%- set web_ref = web %}
-    {%- endif %}
-  {%- endif %}
-{%- endif %}
 
-{%- if controller_ref is defined or compute_ref is defined %}
 log_collector:
-  {%- if controller_ref is defined %}
+  {%- if database_processes is defined %}
   splitter:
     java:
       engine: regex
@@ -53,7 +59,7 @@
       module_file: /usr/share/lma_collector/decoders/contrail_supervisor_log.lua
       module_dir: /usr/share/lma_collector/common;/usr/share/heka/lua_modules
       adjust_timezone: true
-  {%- if controller_ref is defined %}
+  {%- if control_processes is defined %}
     contrail_collector:
       engine: sandbox
       module_file: /usr/share/lma_collector/decoders/contrail_collector_log.lua
@@ -64,6 +70,13 @@
       module_file: /usr/share/lma_collector/decoders/contrail_api_stdout_log.lua
       module_dir: /usr/share/lma_collector/common;/usr/share/heka/lua_modules
       adjust_timezone: true
+    ifmap:
+      engine: sandbox
+      module_file: /usr/share/lma_collector/decoders/ifmap.lua
+      module_dir: /usr/share/lma_collector/common;/usr/share/heka/lua_modules
+      adjust_timezone: true
+  {%- endif %}
+  {%- if database_processes is defined %}
     zookeeper:
       engine: sandbox
       module_file: /usr/share/lma_collector/decoders/zookeeper.lua
@@ -74,13 +87,8 @@
       module_file: /usr/share/lma_collector/decoders/cassandra.lua
       module_dir: /usr/share/lma_collector/common;/usr/share/heka/lua_modules
       adjust_timezone: true
-    ifmap:
-      engine: sandbox
-      module_file: /usr/share/lma_collector/decoders/ifmap.lua
-      module_dir: /usr/share/lma_collector/common;/usr/share/heka/lua_modules
-      adjust_timezone: true
   {%- endif %}
-  {%- if web_ref is defined %}
+  {%- if web_processes is defined and web.get('cache', {}).get('engine', '') == 'redis' %}
     redis:
       engine: sandbox
       module_file: /usr/share/lma_collector/decoders/redis.lua
@@ -104,7 +112,7 @@
       priority: ["^Seq"]
       decoder: "contrail_supervisor_decoder"
       splitter: "TokenSplitter"
-  {%- if controller_ref is defined %}
+  {%- if control_processes is defined %}
     contrail_collector_log:
       engine: logstreamer
       log_directory: "/var/log"
@@ -121,22 +129,6 @@
       priority: ["^Seq"]
       decoder: "contrail_api_stdout_decoder"
       splitter: "TokenSplitter"
-    zookeeper:
-      engine: logstreamer
-      log_directory: "/var/log"
-      file_match: 'zookeeper/(?P<Service>zookeeper)\.log\.?(?P<Seq>\d*)$'
-      differentiator: ['contrail', '.', 'Service']
-      priority: ["^Seq"]
-      decoder: "zookeeper_decoder"
-      splitter: "java_splitter"
-    cassandra:
-      engine: logstreamer
-      log_directory: "/var/log"
-      file_match: 'cassandra/(?P<Service>system|status)\.log\.?(?P<Seq>\d*)$'
-      differentiator: ['contrail.cassandra', '.', 'Service']
-      priority: ["^Seq"]
-      decoder: "cassandra_decoder"
-      splitter: "java_splitter"
     ifmap:
       engine: logstreamer
       log_directory: "/var/log"
@@ -154,7 +146,25 @@
       priority: ["^Seq"]
       decoder: "contrail_decoder"
       splitter: "TokenSplitter"
-  {%- if web_ref is defined and web_ref.get('cache', {}).get('engine', '') == 'redis' %}
+  {%- if database_processes is defined %}
+    zookeeper:
+      engine: logstreamer
+      log_directory: "/var/log"
+      file_match: 'zookeeper/(?P<Service>zookeeper)\.log\.?(?P<Seq>\d*)$'
+      differentiator: ['contrail', '.', 'Service']
+      priority: ["^Seq"]
+      decoder: "zookeeper_decoder"
+      splitter: "java_splitter"
+    cassandra:
+      engine: logstreamer
+      log_directory: "/var/log"
+      file_match: 'cassandra/(?P<Service>system|status)\.log\.?(?P<Seq>\d*)$'
+      differentiator: ['contrail.cassandra', '.', 'Service']
+      priority: ["^Seq"]
+      decoder: "cassandra_decoder"
+      splitter: "java_splitter"
+  {%- endif %}
+  {%- if web_processes is defined and web.get('cache', {}).get('engine', '') == 'redis' %}
     redis_log:
       engine: logstreamer
       log_directory: "/var/log"
@@ -166,7 +176,7 @@
   {%- endif %}
 metric_collector:
   trigger:
-  {%- if controller_ref is defined %}
+  {%- if control_processes is defined %}
     contrail_api_local_endpoint:
       description: 'Contrail API is locally down'
       severity: down
@@ -203,20 +213,6 @@
         window: 60
         periods: 0
         function: last
-    {%- for contrail_process in control_processes %}
-    {{ contrail_process|replace("-", "_") }}:
-      description: "There is no {{ contrail_process }} process running"
-      severity: down
-      rules:
-      - metric: lma_components_processes
-        field:
-          service: {{ contrail_process }}
-        relational_operator: '=='
-        threshold: 0
-        window: 60
-        periods: 0
-        function: last
-    {%- endfor %}
     xmpp_number_of_sessions_up:
       description: "There are no active XMPP sessions "
       severity: warning
@@ -267,6 +263,76 @@
         window: 100
         periods: 0
         function: diff
+    bgp_number_of_session_lo:
+      description: "There are no BGP sessions"
+      severity: warning
+      rules:
+      - metric: contrail_bgp_session_count
+        relational_operator: '=='
+        threshold: 0
+        window: 100
+        periods: 0
+        function: min
+    bgp_number_of_sessions__up:
+      description: "There are no active BGP sessions "
+      severity: warning
+      rules:
+      - metric: contrail_bgp_session_up_count
+        relational_operator: '=='
+        threshold: 0
+        window: 100
+        periods: 0
+        function: min
+    bgp_number_of_sessions_down:
+      description: "There are inactive BGP sessions"
+      severity: warning
+      rules:
+      - metric: contrail_bgp_session_down_count
+        relational_operator: '>='
+        threshold: 1
+        window: 100
+        periods: 0
+        function: min
+    {%- for contrail_process in control_processes %}
+    {{ contrail_process|replace("-", "_") }}:
+      description: "There is no {{ contrail_process }} process running"
+      severity: down
+      rules:
+      - metric: lma_components_processes
+        field:
+          service: {{ contrail_process }}
+        relational_operator: '=='
+        threshold: 0
+        window: 60
+        periods: 0
+        function: last
+    {%- endfor %}
+  {%- endif %}
+  {%- if compute_processes is defined %}
+    contrail_node_manager_api_local_endpoint:
+      description: 'Contrail Node Manager API is locally down'
+      severity: down
+      rules:
+      - metric: openstack_check_local_api
+        field:
+          service: contrail-node-manager
+        relational_operator: '=='
+        threshold: 0
+        window: 60
+        periods: 0
+        function: last
+    contrail_vrouter_api_local_endpoint:
+      description: 'Contrail vrouter API is locally down'
+      severity: down
+      rules:
+      - metric: openstack_check_local_api
+        field:
+          service: contrail-vrouter
+        relational_operator: '=='
+        threshold: 0
+        window: 60
+        periods: 0
+        function: last
     vrouter_xmpp_of_sessions_lo:
       description: "There are no vrouter XMPP sessions"
       severity: warning
@@ -357,36 +423,6 @@
         window: 100
         periods: 0
         function: diff
-    bgp_number_of_session_lo:
-      description: "There are no BGP sessions"
-      severity: warning
-      rules:
-      - metric: contrail_bgp_session_count
-        relational_operator: '=='
-        threshold: 0
-        window: 100
-        periods: 0
-        function: min
-    bgp_number_of_sessions__up:
-      description: "There are no active BGP sessions "
-      severity: warning
-      rules:
-      - metric: contrail_bgp_session_up_count
-        relational_operator: '=='
-        threshold: 0
-        window: 100
-        periods: 0
-        function: min
-    bgp_number_of_sessions_down:
-      description: "There are inactive BGP sessions"
-      severity: warning
-      rules:
-      - metric: contrail_bgp_session_down_count
-        relational_operator: '>='
-        threshold: 1
-        window: 100
-        periods: 0
-        function: min
     vrouter_flows_active:
       description: "There are too many active vrouter flows"
       severity: warning
@@ -497,42 +533,6 @@
         window: 120
         periods: 0
         function: min
-    cassandra_cluster_endpoint_down:
-      description: "Cassandra Cluster Endpoint is down"
-      severity: critical
-      rules:
-      - metric: DownEndpointCount
-        relational_operator: '>'
-        threshold: 0
-        window: 100
-        periods: 0
-        function: min
-  {%- endif %}
-  {%- if compute_ref is defined %}
-    contrail_node_manager_api_local_endpoint:
-      description: 'Contrail Node Manager API is locally down'
-      severity: down
-      rules:
-      - metric: openstack_check_local_api
-        field:
-          service: contrail-node-manager
-        relational_operator: '=='
-        threshold: 0
-        window: 60
-        periods: 0
-        function: last
-    contrail_vrouter_api_local_endpoint:
-      description: 'Contrail vrouter API is locally down'
-      severity: down
-      rules:
-      - metric: openstack_check_local_api
-        field:
-          service: contrail-vrouter
-        relational_operator: '=='
-        threshold: 0
-        window: 60
-        periods: 0
-        function: last
     {%- for contrail_process in compute_processes %}
     {{ contrail_process|replace("-", "_") }}:
       description: "There is no {{ contrail_process }} process running"
@@ -548,8 +548,50 @@
         function: last
     {%- endfor %}
   {%- endif %}
+  {%- if database_processes is defined %}
+    cassandra_cluster_endpoint_down:
+      description: "Cassandra Cluster Endpoint is down"
+      severity: critical
+      rules:
+      - metric: DownEndpointCount
+        relational_operator: '>'
+        threshold: 0
+        window: 100
+        periods: 0
+        function: min
+    {%- for contrail_process in database_processes %}
+    {{ contrail_process|replace("-", "_") }}:
+      description: "There is no {{ contrail_process }} process running"
+      severity: down
+      rules:
+      - metric: lma_components_processes
+        field:
+          service: {{ contrail_process }}
+        relational_operator: '=='
+        threshold: 0
+        window: 60
+        periods: 0
+        function: last
+    {%- endfor %}
+  {%- endif %}
+  {%- if web_processes is defined %}
+    {%- for contrail_process in web_processes %}
+    {{ contrail_process|replace("-", "_") }}:
+      description: "There is no {{ contrail_process }} process running"
+      severity: down
+      rules:
+      - metric: lma_components_processes
+        field:
+          service: {{ contrail_process }}
+        relational_operator: '=='
+        threshold: 0
+        window: 60
+        periods: 0
+        function: last
+    {%- endfor %}
+  {%- endif %}
   alarm:
-  {%- if controller_ref is defined %}
+  {%- if control_processes is defined %}
     contrail_api_endpoint:
       alerting: enabled
       triggers:
@@ -577,7 +619,7 @@
         process: {{ contrail_process }}
     {%- endfor %}
   {%- endif %}
-  {%- if compute_ref is defined %}
+  {%- if compute_processes is defined %}
     contrail_node_manager_api_endpoint:
       alerting: enabled
       triggers:
@@ -599,9 +641,29 @@
         process: {{ contrail_process }}
     {%- endfor %}
   {%- endif %}
+  {%- if database_processes is defined %}
+    {%- for contrail_process in database_processes %}
+    {{ contrail_process|replace("-", "_") }}:
+      alerting: enabled
+      triggers:
+      - {{ contrail_process|replace("-", "_") }}
+      dimension:
+        process: {{ contrail_process }}
+    {%- endfor %}
+  {%- endif %}
+  {%- if web_processes is defined %}
+    {%- for contrail_process in web_processes %}
+    {{ contrail_process|replace("-", "_") }}:
+      alerting: enabled
+      triggers:
+      - {{ contrail_process|replace("-", "_") }}
+      dimension:
+        process: {{ contrail_process }}
+    {%- endfor %}
+  {%- endif %}
+  {%- if control_processes is defined %}
 aggregator:
   alarm_cluster:
-  {%- if controller_ref is defined %}
     contrail_api_endpoint:
       policy: availability_of_members
       alerting: enabled
@@ -664,7 +726,7 @@
         cluster_name: contrail-control
         nagios_host: 00-top-clusters
   {%- endif %}
-  {%- if compute_ref is defined %}
+  {%- if compute_processes is defined %}
     contrail_node_manager_api_endpoint:
       policy: availability_of_members
       alerting: enabled