Merge "Add kitchen tests for logging"
diff --git a/.kitchen.yml b/.kitchen.yml
index ebc69d5..c8f40b8 100644
--- a/.kitchen.yml
+++ b/.kitchen.yml
@@ -41,9 +41,9 @@
   sudo: true
 
 platforms:
-  - name: <%= ENV['PLATFORM'] || 'ubuntu-xenial' %>
+  - name: <%=ENV['PLATFORM'] ||  'saltstack-ubuntu-xenial-salt-stable' %>
     driver_config:
-      image: <%= ENV['PLATFORM'] || 'trevorj/salty-whales:xenial' %>
+      image: <%=ENV['PLATFORM'] || 'epcim/salt-formulas:saltstack-ubuntu-xenial-salt-stable'%>
       platform: ubuntu
 
 suites:
diff --git a/.travis.yml b/.travis.yml
index 51f3437..1d65abb 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -17,22 +17,24 @@
   - bundle install
 
 env:
-  - PLATFORM=trevorj/salty-whales:trusty-2017.7 OS_VERSION=mitaka SUITE=compute-cluster
-  - PLATFORM=trevorj/salty-whales:trusty-2017.7 OS_VERSION=mitaka SUITE=control-cluster
-  - PLATFORM=trevorj/salty-whales:xenial-2017.7 OS_VERSION=mitaka SUITE=compute-cluster
-  - PLATFORM=trevorj/salty-whales:xenial-2017.7 OS_VERSION=mitaka SUITE=control-cluster
-  - PLATFORM=trevorj/salty-whales:xenial-2017.7 OS_VERSION=newton SUITE=compute-cluster
-  - PLATFORM=trevorj/salty-whales:xenial-2017.7 OS_VERSION=newton SUITE=control-cluster
-  - PLATFORM=trevorj/salty-whales:xenial-2017.7 OS_VERSION=ocata SUITE=compute-cluster
-  - PLATFORM=trevorj/salty-whales:xenial-2017.7 OS_VERSION=ocata SUITE=control-cluster
-  - PLATFORM=trevorj/salty-whales:trusty OS_VERSION=mitaka SUITE=compute-cluster
-  - PLATFORM=trevorj/salty-whales:trusty OS_VERSION=mitaka SUITE=control-cluster
-  - PLATFORM=trevorj/salty-whales:xenial OS_VERSION=mitaka SUITE=compute-cluster
-  - PLATFORM=trevorj/salty-whales:xenial OS_VERSION=mitaka SUITE=control-cluster
-  - PLATFORM=trevorj/salty-whales:xenial OS_VERSION=newton SUITE=compute-cluster
-  - PLATFORM=trevorj/salty-whales:xenial OS_VERSION=newton SUITE=control-cluster
-  - PLATFORM=trevorj/salty-whales:xenial OS_VERSION=ocata SUITE=compute-cluster
-  - PLATFORM=trevorj/salty-whales:xenial OS_VERSION=ocata SUITE=control-cluster
+  - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2016.3 OS_VERSION=mitaka SUITE=compute-cluster
+  - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2016.3 OS_VERSION=mitaka SUITE=control-cluster
+  - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2017.7 OS_VERSION=mitaka SUITE=compute-cluster
+  - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2017.7 OS_VERSION=mitaka SUITE=control-cluster
+  - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2016.3 OS_VERSION=newton SUITE=compute-cluster
+  - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2016.3 OS_VERSION=newton SUITE=control-cluster
+  - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2017.7 OS_VERSION=newton SUITE=compute-cluster
+  - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2017.7 OS_VERSION=newton SUITE=control-cluster
+  - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2016.3 OS_VERSION=ocata SUITE=compute-cluster
+  - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2016.3 OS_VERSION=ocata SUITE=control-cluster
+  - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2017.7 OS_VERSION=ocata SUITE=compute-cluster
+  - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-xenial-salt-2017.7 OS_VERSION=ocata SUITE=control-cluster
+  # - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-bionic-salt-2017.7 OS_VERSION=mitaka SUITE=compute-cluster
+  # - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-bionic-salt-2017.7 OS_VERSION=mitaka SUITE=control-cluster
+  # - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-bionic-salt-2017.7 OS_VERSION=newton SUITE=compute-cluster
+  # - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-bionic-salt-2017.7 OS_VERSION=newton SUITE=control-cluster
+  # - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-bionic-salt-2017.7 OS_VERSION=ocata SUITE=compute-cluster
+  # - PLATFORM=epcim/salt-formulas:saltstack-ubuntu-bionic-salt-2017.7 OS_VERSION=ocata SUITE=control-cluster
 
 before_script:
   - set -o pipefail
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 %}