Improve service validation during upgrade Manila
* Added modules which allows to check and manage services statuses.
* Added states which allows enable/disable one/all services by host name.
Change-Id: I078d089b221180ff2355087bc0601f904f8dbd94
Related-PROD: PROD-25158
diff --git a/_modules/manilang/__init__.py b/_modules/manilang/__init__.py
index 4d0b401..d8b7f90 100644
--- a/_modules/manilang/__init__.py
+++ b/_modules/manilang/__init__.py
@@ -21,18 +21,21 @@
REQUIREMENTS_MET = False
from manilang import share_types
+from manilang import services
list_share_types = share_types.list_share_types
create_share_type = share_types.create_share_type
set_share_type_extra_specs = share_types.set_share_type_extra_specs
unset_share_type_extra_specs = share_types.unset_share_type_extra_specs
delete_share_type = share_types.delete_share_type
-
+service_list = services.service_list
+service_update = services.service_update
+service_wait = services.wait_for_service
__all__ = (
'list_share_types', 'create_share_type',
'set_share_type_extra_specs', 'unset_share_type_extra_specs',
- 'delete_share_type',
+ 'delete_share_type','service_list', 'service_update', 'service_wait',
)
diff --git a/_modules/manilang/services.py b/_modules/manilang/services.py
new file mode 100644
index 0000000..ded8e95
--- /dev/null
+++ b/_modules/manilang/services.py
@@ -0,0 +1,70 @@
+# 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 six.moves.urllib.parse as urllib_parse
+import time
+
+from salt.exceptions import CommandExecutionError
+from manilang.common import send, MANILA_HEADER
+
+@send('get', MANILA_HEADER)
+def service_list(*args, **kwargs):
+ """Return list of Manila services."""
+
+ # TODO For API versions 2.6 and prior, replace services in the URLs with os-services.
+ # https://developer.openstack.org/api-ref/shared-file-system/#list-services
+ url = '/os-services?{}'.format(urllib_parse.urlencode(kwargs))
+ return url, {}
+
+
+@send('put', MANILA_HEADER)
+def service_update(host, binary, action, **kwargs):
+ """Enable/Disable Manila service"""
+
+ url = '/services/{}'.format(action)
+ req = {"host": host, "binary": binary}
+
+ return url, req
+
+def wait_for_service(cloud_name, host=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 timeout: number of seconds to wait before retries
+ :param retries: number of retries
+ """
+ if admin_up_only:
+ kwargs['status'] = 'enabled'
+
+ kwargs['state'] = 'down'
+
+ for _i in range(retries):
+
+ services = service_list(cloud_name=cloud_name, **kwargs)['services']
+
+ # You are able to wait status either certain manila-share instance by host@driver
+ # or all existed instances on a node by host.
+ # Also you are able to wait status of all instances from every node if you don't define host.
+ if host:
+ if '@' in str(host):
+ down_services = [s for s in services if host == s['host']]
+ else:
+ down_services = [s for s in services if host == s['host'].split('@')[0]]
+ else:
+ down_services = [s for s in services]
+
+ if len(down_services) == 0:
+ return 'Manila services with admin_up_only={} are up or disabled administratively'.format(admin_up_only)
+ time.sleep(timeout)
+
+ raise CommandExecutionError("Manila services {} are still down or disabled".format(down_services))