Merge "Add keystoneng support"
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/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..0946d2e 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 %}
 
@@ -309,7 +313,7 @@
 
 {%- if grains.get('init', None) == 'systemd' %}
 
-libvirt_restart_systemd:
+nova_libvirt_restart_systemd:
   module.wait:
   - name: service.systemctl_reload
   - watch:
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 %}
diff --git a/nova/files/mitaka/nova-compute.conf.Debian b/nova/files/mitaka/nova-compute.conf.Debian
index f6aa190..ef05fa0 100644
--- a/nova/files/mitaka/nova-compute.conf.Debian
+++ b/nova/files/mitaka/nova-compute.conf.Debian
@@ -26,6 +26,7 @@
 {%- if compute.image.use_cow is defined %}
 use_cow_images = {{ compute.image.use_cow }}
 {%- endif %}
+force_raw_images={{ compute.get('image', {}).get('force_raw', True)|lower }}
 {%- if compute.my_ip is defined %}
 my_ip={{ compute.my_ip }}
 {%- endif %}
diff --git a/nova/files/newton/nova-compute.conf.Debian b/nova/files/newton/nova-compute.conf.Debian
index 622c832..830f8f9 100644
--- a/nova/files/newton/nova-compute.conf.Debian
+++ b/nova/files/newton/nova-compute.conf.Debian
@@ -14,7 +14,7 @@
 config_drive_format={{ compute.get('config_drive_format', compute.get('config_drive', {}).get('format', 'vfat')) }}
 force_config_drive={{ compute.get('config_drive', {}).get('forced', True)|lower }}
 config_drive_inject_password={{ compute.get('config_drive', {}).get('inject_password', False)|lower }}
-force_raw_images=True
+force_raw_images={{ compute.get('image', {}).get('force_raw', True)|lower }}
 notify_api_faults=False
 security_group_api=neutron
 vif_plugging_is_fatal=True
diff --git a/nova/files/ocata/nova-compute.conf.Debian b/nova/files/ocata/nova-compute.conf.Debian
index a58482b..3eb807b 100644
--- a/nova/files/ocata/nova-compute.conf.Debian
+++ b/nova/files/ocata/nova-compute.conf.Debian
@@ -399,7 +399,7 @@
 # * ``compute_driver``: Only the libvirt driver uses this option.
 #  (boolean value)
 #force_raw_images=true
-force_raw_images=true
+force_raw_images={{ compute.get('image', {}).get('force_raw', True)|lower }}
 
 #
 # Name of the mkfs commands for ephemeral device.
diff --git a/nova/files/pike/nova-compute.conf.Debian b/nova/files/pike/nova-compute.conf.Debian
index a58482b..3eb807b 100644
--- a/nova/files/pike/nova-compute.conf.Debian
+++ b/nova/files/pike/nova-compute.conf.Debian
@@ -399,7 +399,7 @@
 # * ``compute_driver``: Only the libvirt driver uses this option.
 #  (boolean value)
 #force_raw_images=true
-force_raw_images=true
+force_raw_images={{ compute.get('image', {}).get('force_raw', True)|lower }}
 
 #
 # Name of the mkfs commands for ephemeral device.
diff --git a/tests/pillar/compute_cluster.sls b/tests/pillar/compute_cluster.sls
index b6ad010..28ded0c 100644
--- a/tests/pillar/compute_cluster.sls
+++ b/tests/pillar/compute_cluster.sls
@@ -32,6 +32,15 @@
       user: nova
       password: password
       tenant: service
+    logging:
+      log_appender: false
+      log_handlers:
+        watchedfile:
+          enabled: true
+        fluentd:
+          enabled: false
+        ossyslog:
+          enabled: false
     message_queue:
       engine: rabbitmq
       members:
diff --git a/tests/pillar/compute_single.sls b/tests/pillar/compute_single.sls
index bba29a0..abaa7ad 100644
--- a/tests/pillar/compute_single.sls
+++ b/tests/pillar/compute_single.sls
@@ -26,6 +26,15 @@
       user: nova
       password: password
       tenant: service
+    logging:
+      log_appender: false
+      log_handlers:
+        watchedfile:
+          enabled: true
+        fluentd:
+          enabled: false
+        ossyslog:
+          enabled: false
     message_queue:
       engine: rabbitmq
       host: 127.0.0.1
diff --git a/tests/pillar/compute_single_config_drive_options.sls b/tests/pillar/compute_single_config_drive_options.sls
index a181f8b..75840b7 100644
--- a/tests/pillar/compute_single_config_drive_options.sls
+++ b/tests/pillar/compute_single_config_drive_options.sls
@@ -26,6 +26,15 @@
       user: nova
       password: password
       tenant: service
+    logging:
+      log_appender: false
+      log_handlers:
+        watchedfile:
+          enabled: true
+        fluentd:
+          enabled: false
+        ossyslog:
+          enabled: false
     message_queue:
       engine: rabbitmq
       host: 127.0.0.1
diff --git a/tests/pillar/control_cluster.sls b/tests/pillar/control_cluster.sls
index d057d1b..c708f81 100644
--- a/tests/pillar/control_cluster.sls
+++ b/tests/pillar/control_cluster.sls
@@ -32,6 +32,15 @@
       user: nova
       password: password
       tenant: service
+    logging:
+      log_appender: false
+      log_handlers:
+        watchedfile:
+          enabled: true
+        fluentd:
+          enabled: false
+        ossyslog:
+          enabled: false
     message_queue:
       engine: rabbitmq
       members:
diff --git a/tests/pillar/control_single.sls b/tests/pillar/control_single.sls
index 78eaa40..da4cd10 100644
--- a/tests/pillar/control_single.sls
+++ b/tests/pillar/control_single.sls
@@ -32,6 +32,15 @@
       user: nova
       password: password
       tenant: service
+    logging:
+      log_appender: false
+      log_handlers:
+        watchedfile:
+          enabled: true
+        fluentd:
+          enabled: false
+        ossyslog:
+          enabled: false
     message_queue:
       engine: rabbitmq
       host: 127.0.0.1