diff --git a/service-mgmt-api/sm-api/sm_api/api/controllers/v1/nodes.py b/service-mgmt-api/sm-api/sm_api/api/controllers/v1/nodes.py index 404545d1..6d905e0e 100644 --- a/service-mgmt-api/sm-api/sm_api/api/controllers/v1/nodes.py +++ b/service-mgmt-api/sm-api/sm_api/api/controllers/v1/nodes.py @@ -9,6 +9,7 @@ import wsme from wsme import types as wsme_types import wsmeext.pecan as wsme_pecan import pecan +import six from pecan import rest from sm_api.api.controllers.v1 import base @@ -110,7 +111,7 @@ class NodesController(rest.RestController): sort_dir=sort_dir) return nodes - @wsme_pecan.wsexpose(Nodes, unicode) + @wsme_pecan.wsexpose(Nodes, six.text_type) def get_one(self, uuid): try: rpc_sg = objects.sm_node.get_by_uuid(pecan.request.context, uuid) @@ -119,8 +120,8 @@ class NodesController(rest.RestController): return Nodes.convert_with_links(rpc_sg) - @wsme_pecan.wsexpose(NodesCollection, unicode, int, - unicode, unicode) + @wsme_pecan.wsexpose(NodesCollection, six.text_type, int, + six.text_type, six.text_type) def get_all(self, marker=None, limit=None, sort_key='name', sort_dir='asc'): """Retrieve list of nodes.""" @@ -134,13 +135,13 @@ class NodesController(rest.RestController): sort_key=sort_key, sort_dir=sort_dir) - @wsme_pecan.wsexpose(NodesCommandResult, unicode, + @wsme_pecan.wsexpose(NodesCommandResult, six.text_type, body=NodesCommand) def put(self, hostname, command): raise NotImplementedError() - @wsme_pecan.wsexpose(NodesCommandResult, unicode, + @wsme_pecan.wsexpose(NodesCommandResult, six.text_type, body=NodesCommand) def patch(self, hostname, command): diff --git a/service-mgmt-api/sm-api/sm_api/api/controllers/v1/service_groups.py b/service-mgmt-api/sm-api/sm_api/api/controllers/v1/service_groups.py index ddb410be..36bcf0d3 100644 --- a/service-mgmt-api/sm-api/sm_api/api/controllers/v1/service_groups.py +++ b/service-mgmt-api/sm-api/sm_api/api/controllers/v1/service_groups.py @@ -9,6 +9,7 @@ import wsme from wsme import types as wsme_types import wsmeext.pecan as wsme_pecan import pecan +import six from pecan import rest from sm_api.api.controllers.v1 import base @@ -124,7 +125,7 @@ class ServiceGroupController(rest.RestController): return sm_sdas - @wsme_pecan.wsexpose(ServiceGroup, unicode) + @wsme_pecan.wsexpose(ServiceGroup, six.text_type) def get_one(self, uuid): try: rpc_sg = objects.sm_sda.get_by_uuid(pecan.request.context, uuid) @@ -133,8 +134,8 @@ class ServiceGroupController(rest.RestController): return ServiceGroup.convert_with_links(rpc_sg) - @wsme_pecan.wsexpose(ServiceGroupCollection, unicode, int, - unicode, unicode) + @wsme_pecan.wsexpose(ServiceGroupCollection, six.text_type, int, + six.text_type, six.text_type) def get_all(self, marker=None, limit=None, sort_key='name', sort_dir='asc'): """Retrieve list of servicegroups.""" @@ -148,13 +149,13 @@ class ServiceGroupController(rest.RestController): sort_key=sort_key, sort_dir=sort_dir) - @wsme_pecan.wsexpose(ServiceGroupCommandResult, unicode, + @wsme_pecan.wsexpose(ServiceGroupCommandResult, six.text_type, body=ServiceGroupCommand) def put(self, hostname, command): raise NotImplementedError() - @wsme_pecan.wsexpose(ServiceGroupCommandResult, unicode, + @wsme_pecan.wsexpose(ServiceGroupCommandResult, six.text_type, body=ServiceGroupCommand) def patch(self, hostname, command): diff --git a/service-mgmt-api/sm-api/sm_api/api/controllers/v1/servicenode.py b/service-mgmt-api/sm-api/sm_api/api/controllers/v1/servicenode.py index fd1d0479..69516b93 100755 --- a/service-mgmt-api/sm-api/sm_api/api/controllers/v1/servicenode.py +++ b/service-mgmt-api/sm-api/sm_api/api/controllers/v1/servicenode.py @@ -23,6 +23,7 @@ import pecan from pecan import rest import wsme +import six from wsme import types as wtypes import wsmeext.pecan as wsme_pecan import socket @@ -607,7 +608,7 @@ class ServiceNodeController(rest.RestController): else: raise wsme.exc.InvalidInput('action', command.action, "unknown") - @wsme_pecan.wsexpose(ServiceNode, unicode) + @wsme_pecan.wsexpose(ServiceNode, six.text_type) def get_one(self, hostname): try: @@ -642,7 +643,7 @@ class ServiceNodeController(rest.RestController): active_services=active_services, swactable_services=swactable_services) - @wsme_pecan.wsexpose(ServiceNodeCommandResult, unicode, + @wsme_pecan.wsexpose(ServiceNodeCommandResult, six.text_type, body=ServiceNodeCommand) def patch(self, hostname, command): diff --git a/service-mgmt-api/sm-api/sm_api/api/controllers/v1/services.py b/service-mgmt-api/sm-api/sm_api/api/controllers/v1/services.py index e5ba0a03..5592e4b1 100644 --- a/service-mgmt-api/sm-api/sm_api/api/controllers/v1/services.py +++ b/service-mgmt-api/sm-api/sm_api/api/controllers/v1/services.py @@ -9,6 +9,7 @@ import wsme from wsme import types as wsme_types import wsmeext.pecan as wsme_pecan import pecan +import six from pecan import rest from sm_api.api.controllers.v1 import base @@ -109,7 +110,7 @@ class ServicesController(rest.RestController): sort_dir=sort_dir) return services - @wsme_pecan.wsexpose(Services, unicode) + @wsme_pecan.wsexpose(Services, six.text_type) def get_one(self, uuid): try: rpc_sg = objects.service.get_by_uuid(pecan.request.context, uuid) @@ -118,7 +119,7 @@ class ServicesController(rest.RestController): return Services.convert_with_links(rpc_sg) - @wsme_pecan.wsexpose(Services, unicode) + @wsme_pecan.wsexpose(Services, six.text_type) def get_service(self, name): try: rpc_sg = objects.service.get_by_name(pecan.request.context, name) @@ -126,8 +127,8 @@ class ServicesController(rest.RestController): return None return Services.convert_with_links(rpc_sg) - @wsme_pecan.wsexpose(ServicesCollection, unicode, int, - unicode, unicode) + @wsme_pecan.wsexpose(ServicesCollection, six.text_type, int, + six.text_type, six.text_type) def get_all(self, marker=None, limit=None, sort_key='name', sort_dir='asc'): """Retrieve list of services.""" @@ -141,13 +142,13 @@ class ServicesController(rest.RestController): sort_key=sort_key, sort_dir=sort_dir) - @wsme_pecan.wsexpose(ServicesCommandResult, unicode, + @wsme_pecan.wsexpose(ServicesCommandResult, six.text_type, body=ServicesCommand) def put(self, hostname, command): raise NotImplementedError() - @wsme_pecan.wsexpose(ServicesCommandResult, unicode, + @wsme_pecan.wsexpose(ServicesCommandResult, six.text_type, body=ServicesCommand) def patch(self, hostname, command): diff --git a/service-mgmt-api/sm-api/sm_api/api/controllers/v1/sm_sda.py b/service-mgmt-api/sm-api/sm_api/api/controllers/v1/sm_sda.py index 6dc76363..2a074396 100755 --- a/service-mgmt-api/sm-api/sm_api/api/controllers/v1/sm_sda.py +++ b/service-mgmt-api/sm-api/sm_api/api/controllers/v1/sm_sda.py @@ -9,6 +9,7 @@ import wsme from wsme import types as wsme_types import wsmeext.pecan as wsme_pecan import pecan +import six from pecan import rest from sm_api.api.controllers.v1 import base @@ -123,7 +124,7 @@ class SmSdaController(rest.RestController): return sm_sdas - @wsme_pecan.wsexpose(SmSda, unicode) + @wsme_pecan.wsexpose(SmSda, six.text_type) def get_one(self, uuid): try: rpc_sda = objects.sm_sda.get_by_uuid(pecan.request.context, uuid) @@ -132,8 +133,8 @@ class SmSdaController(rest.RestController): return SmSda.convert_with_links(rpc_sda) - @wsme_pecan.wsexpose(SmSdaCollection, unicode, int, - unicode, unicode) + @wsme_pecan.wsexpose(SmSdaCollection, six.text_type, int, + six.text_type, six.text_type) def get_all(self, marker=None, limit=None, sort_key='name', sort_dir='asc'): """Retrieve list of sm_sdas.""" @@ -147,13 +148,13 @@ class SmSdaController(rest.RestController): sort_key=sort_key, sort_dir=sort_dir) - @wsme_pecan.wsexpose(SmSdaCommandResult, unicode, + @wsme_pecan.wsexpose(SmSdaCommandResult, six.text_type, body=SmSdaCommand) def put(self, hostname, command): raise NotImplementedError() - @wsme_pecan.wsexpose(SmSdaCommandResult, unicode, + @wsme_pecan.wsexpose(SmSdaCommandResult, six.text_type, body=SmSdaCommand) def patch(self, hostname, command): diff --git a/service-mgmt-api/sm-api/sm_api/common/exception.py b/service-mgmt-api/sm-api/sm_api/common/exception.py index 78d4543b..907b6dd3 100644 --- a/service-mgmt-api/sm-api/sm_api/common/exception.py +++ b/service-mgmt-api/sm-api/sm_api/common/exception.py @@ -29,7 +29,7 @@ SHOULD include dedicated exception logging. """ import functools - +import six from oslo_config import cfg from sm_api.common import safe_utils @@ -161,7 +161,7 @@ class SmApiException(Exception): if self.__class__.__name__.endswith('_Remote'): return self.args[0] else: - return unicode(self) + return six.text_type(self) class NotAuthorized(SmApiException): diff --git a/service-mgmt-api/sm-api/sm_api/common/utils.py b/service-mgmt-api/sm-api/sm_api/common/utils.py index 759495de..f9adccdb 100644 --- a/service-mgmt-api/sm-api/sm_api/common/utils.py +++ b/service-mgmt-api/sm-api/sm_api/common/utils.py @@ -404,7 +404,7 @@ def convert_to_list_dict(lst, label): def sanitize_hostname(hostname): """Return a hostname which conforms to RFC-952 and RFC-1123 specs.""" - if isinstance(hostname, unicode): + if isinstance(hostname, six.text_type): hostname = hostname.encode('latin-1', 'ignore') hostname = re.sub('[ _]', '-', hostname)