Merge "Use new image for kitchen tests"
diff --git a/Makefile b/Makefile
index 1043fbe..d166862 100644
--- a/Makefile
+++ b/Makefile
@@ -27,6 +27,7 @@
 
 all:
 	@echo "make install - Install into DESTDIR"
+	@echo "make lint    - Run lint tests"
 	@echo "make test    - Run tests"
 	@echo "make kitchen - Run Kitchen CI tests (create, converge, verify)"
 	@echo "make clean   - Cleanup after tests run"
@@ -45,6 +46,9 @@
 	[ -d $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME) ] || mkdir -p $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME)
 	cp -a metadata/service/* $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME)
 
+lint:
+	[ ! -d tests ] || (cd tests; ./run_tests.sh lint)
+
 test:
 	[ ! -d tests ] || (cd tests; ./run_tests.sh)
 
@@ -65,7 +69,7 @@
 	[ ! -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)
+	git tag -s -m $(VERSION_MAJOR).$(NEW_MINOR_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)
diff --git a/README.rst b/README.rst
index 06741cd..3abd1fb 100644
--- a/README.rst
+++ b/README.rst
@@ -158,6 +158,16 @@
         barbican:
           enabled: true
 
+Enable cells update:
+
+**Note:** Useful when upgrading Openstack. To update cells to test sync db agains duplicated production database.
+
+.. code-block:: yaml
+
+    nova:
+      controller:
+        update_cells: true
+
 
 Configuring TLS communications
 ------------------------------
diff --git a/_states/novang.py b/_states/novang.py
index a3376e7..4ea4094 100644
--- a/_states/novang.py
+++ b/_states/novang.py
@@ -57,6 +57,28 @@
     return ret
 
 
+def update_cell(name='cell1', transport_url='none:///', db_engine='mysql', db_name='nova_upgrade', db_user='nova', db_password=None, db_address='0.0.0.0'):
+    '''
+    Ensures that the nova cell is setup correctly
+    '''
+    ret = {'name': name,
+           'changes': {},
+           'result': False,
+           'comment': 'Cell "{0}" does not exists'.format(name)}
+    cell_uuid = __salt__['cmd.shell']('nova-manage cell_v2 list_cells 2>&- | grep ' + name + ' | tr -d \"\n\" | awk \'{print $4}\'')
+    if cell_uuid:
+        try:
+            __salt__['cmd.shell']('nova-manage cell_v2 update_cell --cell_uuid ' + cell_uuid + ' --transport-url ' + transport_url + ' --database_connection ' + db_engine + '+pymysql://' + db_user + ':' + db_password + '@' + db_address + '/' + db_name + '?charset=utf8')
+            ret['result'] = True
+            ret['comment'] = 'Cell {0} updated'.format(name)
+            ret['changes'][name] = 'Cell {0} successfuly updated'.format(name)
+        except:
+            ret['result'] = False
+            ret['comment'] = 'Cell {0} not updated'.format(name)
+            ret['changes'][name] = 'Cell {0} failed to be updated'.format(name)
+    return ret
+
+
 def api_db_version_present(name=None, version="20"):
     '''
     Ensures that specific api_db version is present
diff --git a/nova/compute.sls b/nova/compute.sls
index 081b600..7a3b032 100644
--- a/nova/compute.sls
+++ b/nova/compute.sls
@@ -177,7 +177,11 @@
 Add_compute_to_aggregate_{{ aggregate }}:
   cmd.run:
   - name: "nova {{ identity_params }} aggregate-add-host {{ aggregate }} {{ pillar.linux.system.name }}"
+  {%- if compute.version in ['juno','kilo','liberty','mitaka'] %}
   - unless: "nova {{ identity_params }} aggregate-details {{ aggregate }} | grep {{ pillar.linux.system.name }}"
+  {%- else %}
+  - unless: "nova {{ identity_params }} aggregate-show {{ aggregate }} | grep {{ pillar.linux.system.name }}"
+  {%- endif %}
 
 {%- endfor %}
 
diff --git a/nova/controller.sls b/nova/controller.sls
index 24bb535..71d8834 100644
--- a/nova/controller.sls
+++ b/nova/controller.sls
@@ -265,6 +265,45 @@
   - require:
     - cmd: nova_controller_syncdb
 
+{%- if controller.get('update_cells') %}
+
+nova_update_cell0:
+  novang.update_cell:
+  - name: "cell0"
+  - db_name: {{ controller.database.name }}_cell0
+  - db_engine: {{ controller.database.engine }}
+  - db_password: {{ controller.database.password }}
+  - db_user: {{ controller.database.user }}
+  - db_address: {{ controller.database.host }}
+  {%- if grains.get('noservices') %}
+  - onlyif: /bin/false
+  {%- endif %}
+
+{%- set rabbit_port = controller.message_queue.get('port', 5671 if controller.message_queue.get('ssl',{}).get('enabled', False) else 5672) %}
+
+nova_update_cell1:
+  novang.update_cell:
+  - name: "cell1"
+  - db_name: {{ controller.database.name }}
+{%- if controller.message_queue.members is defined %}
+  - transport_url = rabbit://{% for member in controller.message_queue.members -%}
+                             {{ controller.message_queue.user }}:{{ controller.message_queue.password }}@{{ member.host }}:{{ member.get('port', rabbit_port) }}
+                             {%- if not loop.last -%},{%- endif -%}
+                         {%- endfor -%}
+                             /{{ controller.message_queue.virtual_host }}
+{%- else %}
+  - transport_url: rabbit://{{ controller.message_queue.user }}:{{ controller.message_queue.password }}@{{ controller.message_queue.host }}:{{ rabbit_port}}/{{ controller.message_queue.virtual_host }}
+{%- endif %}
+  - db_engine: {{ controller.database.engine }}
+  - db_password: {{ controller.database.password }}
+  - db_user: {{ controller.database.user }}
+  - db_address: {{ controller.database.host }}
+  {%- if grains.get('noservices') %}
+  - onlyif: /bin/false
+  {%- endif %}
+
+{%- endif %}
+
 nova_placement_service_mask:
   file.symlink:
    - name: /etc/systemd/system/nova-placement-api.service
diff --git a/nova/files/default b/nova/files/default
index 815ede9..be934df 100644
--- a/nova/files/default
+++ b/nova/files/default
@@ -1,4 +1,4 @@
 # Generated by Salt.
 {% if values.logging.log_appender %}
-DAEMON_ARGS="--log-config-append=/etc/nova/logging/logging-{{ service_name }}.conf"
+DAEMON_ARGS="${DAEMON_ARGS} --log-config-append=/etc/nova/logging/logging-{{ service_name }}.conf"
 {% endif %}