* Added modules which allow to check and manage services statuses.
Change-Id: Ib51fd5b65c332aa1d9cae2ebcf9ebb7d510a4df3
Related-PROD: PROD-25157
from cinderv3 import volumes
from cinderv3 import volume_types
from cinderv3 import volume_actions
+from cinderv3 import services
volume_list = lists.volume_list
volume_list_get_details = lists.volume_list_get_details
keys_volume_type_get = volume_types.keys_volume_type_get
keys_volume_type_set = volume_types.keys_volume_type_set
image_upload_volume = volume_actions.image_upload_volume
+service_list = lists.service_list
+service_update = services.service_update
+service_wait = services.wait_for_service
__all__ = ('volume_list', 'volume_create', 'volume_delete',
'volume_get_details', 'volume_list_get_details', 'volume_update',
'volume_type_list', 'volume_type_get_details',
'volume_type_create', 'keys_volume_type_get',
'keys_volume_type_set', 'volume_type_delete',
- 'image_upload_volume',)
-
+ 'image_upload_volume', 'service_list', 'service_update', 'service_wait')
def __virtual__():
if REQUIREMENTS_MET:
except ImportError:
from urllib import urlencode
+
@send("get")
def volume_list(**kwargs):
"""
"""
url = '/types?{}'.format(urlencode(kwargs))
return url, None
+
+
+@send("get")
+def service_list(**kwargs):
+ """
+ Return list of Cinder services.
+ """
+ url = '/os-services?{}'.format(urlencode(kwargs))
+ return url, None
--- /dev/null
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import time
+from salt.exceptions import CommandExecutionError
+from cinderv3.common import send
+from cinderv3.lists import service_list
+
+@send("put")
+def service_update(host, binary, action, **kwargs):
+ """
+ Enable/Disable Cinder service
+ """
+ req = {"host": host, "binary": binary}
+ if kwargs.get('disabled_reason') and action == 'disable':
+ url = '/os-services/disable-log-reason'
+ req['disabled_reason'] = kwargs['disabled_reason']
+ else:
+ url = '/os-services/{}'.format(action)
+
+ return url, req
+
+
+def wait_for_service(cloud_name, host=None, binary=None, admin_up_only=True, retries=18, timeout=10, **kwargs):
+ """
+ Ensure the service is up and running on specified host.
+
+ :param host: name of a host where service is running
+ :param admin_up_only: do not check status for admin disabled service
+ :param binary: name of the service
+ :param timeout: number of seconds to wait before retries
+ :param retries: number of retries
+ """
+
+ if host:
+ kwargs['host'] = host
+ if binary:
+ kwargs['binary'] = binary
+
+ for _i in range(retries):
+ services = service_list(cloud_name=cloud_name, **kwargs)['services']
+
+ down_services = [s for s in services if s['state'] == 'down']
+
+ if admin_up_only:
+ down_services = [s for s in down_services if s['status'] == 'enabled']
+
+ if not down_services:
+ return 'Cinder services with admin_up_only=%s are up or disabled administratively' % (admin_up_only)
+
+ time.sleep(timeout)
+
+ raise CommandExecutionError("Cinder services {} are still down or disabled".format(down_services))
return _succeeded('delete', name, resource)
+def service_enabled(name, binary, cloud_name):
+ """Ensures that the service is enabled on the host
+
+ :param name: name of a host where service is running
+ :param binary: name of the service have to be run
+ """
+ changes = {}
+
+ 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']
+
+ 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
+
+
+def service_disabled(name, binary, cloud_name, disabled_reason=None):
+ """Ensures that the service is disabled on the host
+
+ :param name: name of a host where service is running
+ :param binary: name of the service have to be disabled
+ """
+ changes = {}
+ kwargs = {}
+
+ if disabled_reason is not None:
+ 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']
+
+ 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
+
+
def volume_type_present(name, cloud_name, **kwargs):
return _resource_present('volume_type', name, cloud_name, **kwargs)
'comment': msg_map[op].format(resource, name),
'changes': {},
}
- return changes_dict
\ No newline at end of file
+ return changes_dict
--- /dev/null
+cinder_task_uprade_verify_service:
+ test.show_notification:
+ - text: "Running cinder.upgrade.verify.service"
+
+{% set host_id = salt['network.get_hostname']() %}
+
+wait_for_service:
+ module.run:
+ - name: cinderv3.service_wait
+ - cloud_name: admin_identity
+ - host: {{ host_id }}
+ - retries: 30
+ - timeout: 10
include:
- - cinder.upgrade.verify._api
+ - cinder.upgrade.verify._service
+ - cinder.upgrade.verify._api