Upgrade state updated
* This change provides enable/disable one/all services by host name.
Change-Id: Ib0b7ebaaac7e269c1f7790b636433f54a5590fab
Related-PROD: PROD-25157
diff --git a/_states/cinderv3.py b/_states/cinderv3.py
index 3e2e21c..c954c12 100644
--- a/_states/cinderv3.py
+++ b/_states/cinderv3.py
@@ -85,18 +85,18 @@
:param binary: name of the service have to be run
"""
changes = {}
+ ret = []
services = _cinder_call('service_list', host=name, binary=binary, cloud_name=cloud_name)['services']
- enabled_service = [s for s in services if s['status'] == 'enabled']
+ disabled_service = [s for s in services if s['status'] == 'disabled']
- if len(enabled_service) > 0:
- ret = _succeeded('no_changes', name, binary)
- else:
- changes = _cinder_call('service_update', name, binary, 'enable', cloud_name=cloud_name)
- ret = _succeeded('update', name, binary, changes)
-
- return ret
+ if len(disabled_service):
+ for service in disabled_service:
+ changes = _cinder_call('service_update', service['host'], binary, 'enable', cloud_name=cloud_name)
+ ret.append(changes)
+ return _succeeded('update', name, binary, {'changes':ret})
+ return _succeeded('no_changes', name, binary)
def service_disabled(name, binary, cloud_name, disabled_reason=None):
@@ -105,23 +105,22 @@
:param name: name of a host where service is running
:param binary: name of the service have to be disabled
"""
- changes = {}
kwargs = {}
+ ret = []
- if disabled_reason is not None:
+ if disabled_reason:
kwargs['disabled_reason'] = disabled_reason
services = _cinder_call('service_list', host=name, binary=binary, cloud_name=cloud_name)['services']
- disabled_service = [s for s in services if s['status'] == 'disabled']
+ enabled_services = [s for s in services if s['status'] == 'enabled']
- if len(disabled_service) > 0:
- ret = _succeeded('no_changes', name, binary)
- else:
- changes = _cinder_call('service_update', name, binary, 'disable', cloud_name=cloud_name, **kwargs)
- ret = _succeeded('update', name, binary, changes)
-
- return ret
+ if len(enabled_services):
+ for service in enabled_services:
+ changes = _cinder_call('service_update', service['host'], binary, 'disable', cloud_name=cloud_name, **kwargs)
+ ret.append(changes)
+ return _succeeded('update', name, binary, {'changes':ret})
+ return _succeeded('no_changes', name, binary)
def volume_type_present(name, cloud_name, **kwargs):
diff --git a/cinder/upgrade/upgrade/post.sls b/cinder/upgrade/upgrade/post.sls
index 940a957..7add350 100644
--- a/cinder/upgrade/upgrade/post.sls
+++ b/cinder/upgrade/upgrade/post.sls
@@ -1,3 +1,28 @@
-cinder_upgrade_uprade_post:
+{%- from "cinder/map.jinja" import controller, volume with context %}
+
+cinder_upgrade_upgrade_post:
test.show_notification:
+ - name: "dump_message_upgrade_cinder_post"
- text: "Running cinder.upgrade.upgrade.post"
+
+{% set host_id = salt['network.get_hostname']() %}
+
+{%- if controller.get('enabled') %}
+
+cinder_controller_service_enabled:
+ cinderv3.service_enabled:
+ - binary: cinder-scheduler
+ - cloud_name: admin_identity
+ - name: {{ host_id }}
+
+{%- endif %}
+
+{%- if volume.get('enabled') %}
+
+cinder_volume_service_enabled:
+ cinderv3.service_enabled:
+ - binary: cinder-volume
+ - cloud_name: admin_identity
+ - name: {{ host_id }}
+
+{%- endif %}
diff --git a/cinder/upgrade/upgrade/pre.sls b/cinder/upgrade/upgrade/pre.sls
index 2892843..9ec451c 100644
--- a/cinder/upgrade/upgrade/pre.sls
+++ b/cinder/upgrade/upgrade/pre.sls
@@ -1,3 +1,30 @@
+{%- from "cinder/map.jinja" import controller, volume with context %}
+
cinder_upgrade_upgrade_pre:
test.show_notification:
+ - name: "dump_message_upgrade_cinder_pre"
- text: "Running cinder.upgrade.upgrade.pre"
+
+{% set host_id = salt['network.get_hostname']() %}
+
+{%- if controller.get('enabled') %}
+
+cinder_controller_service_disabled:
+ cinderv3.service_disabled:
+ - binary: cinder-scheduler
+ - cloud_name: admin_identity
+ - name: {{ host_id }}
+ - disabled_reason: "Disabled for upgrade"
+
+{%- endif %}
+
+{%- if volume.get('enabled') %}
+
+cinder_volume_service_disabled:
+ cinderv3.service_disabled:
+ - binary: cinder-volume
+ - cloud_name: admin_identity
+ - name: {{ host_id }}
+ - disabled_reason: "Disabled for upgrade"
+
+{%- endif %}