Fix unicode issue for Python 2/3 compatible code.
replace unicode with six.text_type Story: 2003433 Task: 27695 Change-Id: Ie7bc1b649b94fb1695eac51b65294d30e01f26f2 Signed-off-by: Sun Austin <austin.sun@intel.com>
This commit is contained in:
parent
30b5b97208
commit
f999509bca
|
@ -10,6 +10,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import six
|
||||
import sys
|
||||
|
||||
|
||||
|
@ -207,7 +208,7 @@ class CgtsclientException(Exception):
|
|||
if self.__class__.__name__.endswith('_Remote'):
|
||||
return self.args[0]
|
||||
else:
|
||||
return unicode(self)
|
||||
return six.text_type(self)
|
||||
|
||||
|
||||
class AmbiguousEndpoints(CgtsclientException):
|
||||
|
|
|
@ -140,7 +140,7 @@ class HostProvisionState(state.State):
|
|||
|
||||
class HostProvisionStateController(rest.RestController):
|
||||
# GET ihosts/<uuid>/state/provision
|
||||
@wsme_pecan.wsexpose(HostProvisionState, unicode)
|
||||
@wsme_pecan.wsexpose(HostProvisionState, six.text_type)
|
||||
def get(self, ihost_id):
|
||||
ihost = objects.host.get_by_uuid(pecan.request.context,
|
||||
ihost_id)
|
||||
|
@ -149,7 +149,7 @@ class HostProvisionStateController(rest.RestController):
|
|||
return provision_state
|
||||
|
||||
# PUT ihosts/<uuid>/state/provision
|
||||
@wsme_pecan.wsexpose(HostProvisionState, unicode, unicode, status=202)
|
||||
@wsme_pecan.wsexpose(HostProvisionState, six.text_type, six.text_type, status=202)
|
||||
def put(self, ihost_id, target):
|
||||
"""Set the provision state of the machine."""
|
||||
# TODO(lucasagomes): Test if target is a valid state and if it's able
|
||||
|
@ -188,7 +188,7 @@ class HostStatesController(rest.RestController):
|
|||
}
|
||||
|
||||
# GET ihosts/<uuid>/state
|
||||
@wsme_pecan.wsexpose(HostStates, unicode)
|
||||
@wsme_pecan.wsexpose(HostStates, six.text_type)
|
||||
def get(self, ihost_id):
|
||||
"""List or update the state of a ihost."""
|
||||
ihost = objects.host.get_by_uuid(pecan.request.context,
|
||||
|
@ -207,7 +207,7 @@ class HostStatesController(rest.RestController):
|
|||
|
||||
# PUT ihosts/<uuid>/state/update_install_uuid
|
||||
@cutils.synchronized(LOCK_NAME_STATE)
|
||||
@wsme_pecan.wsexpose(HostStates, types.uuid, body=unicode)
|
||||
@wsme_pecan.wsexpose(HostStates, types.uuid, body=six.text_type)
|
||||
def update_install_uuid(self, host_uuid, install_uuid):
|
||||
""" Update install_uuid in /etc/platform/platform.conf
|
||||
on the specified host.
|
||||
|
@ -223,7 +223,7 @@ class HostStatesController(rest.RestController):
|
|||
|
||||
# PUT ihosts/<uuid>/state/host_cpus_modify
|
||||
@cutils.synchronized(cpu_api.LOCK_NAME)
|
||||
@wsme_pecan.wsexpose(cpu_api.CPUCollection, types.uuid, body=[unicode])
|
||||
@wsme_pecan.wsexpose(cpu_api.CPUCollection, types.uuid, body=[six.text_type])
|
||||
def host_cpus_modify(self, host_uuid, capabilities):
|
||||
""" Perform bulk host cpus modify.
|
||||
:param host_uuid: UUID of the host
|
||||
|
@ -1170,8 +1170,8 @@ class HostController(rest.RestController):
|
|||
activity = 'Controller-Standby'
|
||||
host['capabilities'].update({'Personality': activity})
|
||||
|
||||
@wsme_pecan.wsexpose(HostCollection, unicode, unicode, int, unicode,
|
||||
unicode, unicode)
|
||||
@wsme_pecan.wsexpose(HostCollection, six.text_type, six.text_type, int, six.text_type,
|
||||
six.text_type, six.text_type)
|
||||
def get_all(self, isystem_id=None, marker=None, limit=None,
|
||||
personality=None,
|
||||
sort_key='id', sort_dir='asc'):
|
||||
|
@ -1182,7 +1182,7 @@ class HostController(rest.RestController):
|
|||
sort_key=sort_key,
|
||||
sort_dir=sort_dir)
|
||||
|
||||
@wsme_pecan.wsexpose(unicode, unicode, body=unicode)
|
||||
@wsme_pecan.wsexpose(six.text_type, six.text_type, body=six.text_type)
|
||||
def install_progress(self, uuid, install_state,
|
||||
install_state_info=None):
|
||||
""" Update the install status for the given host."""
|
||||
|
@ -1200,8 +1200,8 @@ class HostController(rest.RestController):
|
|||
'install_state_info':
|
||||
install_state_info})
|
||||
|
||||
@wsme_pecan.wsexpose(HostCollection, unicode, unicode, int, unicode,
|
||||
unicode, unicode)
|
||||
@wsme_pecan.wsexpose(HostCollection, six.text_type, six.text_type, int, six.text_type,
|
||||
six.text_type, six.text_type)
|
||||
def detail(self, isystem_id=None, marker=None, limit=None,
|
||||
personality=None,
|
||||
sort_key='id', sort_dir='asc'):
|
||||
|
@ -1220,7 +1220,7 @@ class HostController(rest.RestController):
|
|||
sort_key=sort_key,
|
||||
sort_dir=sort_dir)
|
||||
|
||||
@wsme_pecan.wsexpose(Host, unicode)
|
||||
@wsme_pecan.wsexpose(Host, six.text_type)
|
||||
def get_one(self, uuid):
|
||||
"""Retrieve information about the given ihost."""
|
||||
if self._from_isystem:
|
||||
|
@ -1708,7 +1708,7 @@ class HostController(rest.RestController):
|
|||
|
||||
return self._do_post(ihost_dict)
|
||||
|
||||
@wsme_pecan.wsexpose(Host, unicode, body=[unicode])
|
||||
@wsme_pecan.wsexpose(Host, six.text_type, body=[six.text_type])
|
||||
def patch(self, uuid, patch):
|
||||
""" Update an existing ihost.
|
||||
"""
|
||||
|
@ -2230,7 +2230,7 @@ class HostController(rest.RestController):
|
|||
return True
|
||||
|
||||
@cutils.synchronized(LOCK_NAME)
|
||||
@wsme_pecan.wsexpose(None, unicode, status_code=204)
|
||||
@wsme_pecan.wsexpose(None, six.text_type, status_code=204)
|
||||
def delete(self, ihost_id):
|
||||
"""Delete an ihost.
|
||||
"""
|
||||
|
@ -2487,7 +2487,7 @@ class HostController(rest.RestController):
|
|||
target_load)
|
||||
|
||||
@cutils.synchronized(LOCK_NAME)
|
||||
@wsme_pecan.wsexpose(Host, unicode, body=unicode)
|
||||
@wsme_pecan.wsexpose(Host, six.text_type, body=six.text_type)
|
||||
def upgrade(self, uuid, body):
|
||||
"""Upgrade the host to the specified load"""
|
||||
|
||||
|
@ -2571,7 +2571,7 @@ class HostController(rest.RestController):
|
|||
return Host.convert_with_links(rpc_ihost)
|
||||
|
||||
@cutils.synchronized(LOCK_NAME)
|
||||
@wsme_pecan.wsexpose(Host, unicode, body=unicode)
|
||||
@wsme_pecan.wsexpose(Host, six.text_type, body=six.text_type)
|
||||
def downgrade(self, uuid, body):
|
||||
"""Downgrade the host to the specified load"""
|
||||
|
||||
|
|
|
@ -827,7 +827,7 @@ def _check_interface_vlan_id(op, interface, ihost, from_profile=False):
|
|||
if interface['vlan_id'] < 1 or interface['vlan_id'] > 4094:
|
||||
raise wsme.exc.ClientSideError(_("VLAN id must be between 1 and 4094."))
|
||||
else:
|
||||
interface['vlan_id'] = unicode(interface['vlan_id'])
|
||||
interface['vlan_id'] = six.text_type(interface['vlan_id'])
|
||||
return interface
|
||||
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import jsonpatch
|
|||
import socket
|
||||
|
||||
import pecan
|
||||
import six
|
||||
from pecan import rest
|
||||
|
||||
import wsme
|
||||
|
@ -192,7 +193,7 @@ class LoadController(rest.RestController):
|
|||
return self._get_loads_collection(marker, limit, sort_key, sort_dir,
|
||||
expand, resource_url)
|
||||
|
||||
@wsme_pecan.wsexpose(Load, unicode)
|
||||
@wsme_pecan.wsexpose(Load, six.text_type)
|
||||
def get_one(self, load_uuid):
|
||||
"""Retrieve information about the given Load."""
|
||||
|
||||
|
@ -285,8 +286,8 @@ class LoadController(rest.RestController):
|
|||
return Load.convert_with_links(new_load)
|
||||
|
||||
@cutils.synchronized(LOCK_NAME)
|
||||
@wsme.validate(unicode, [LoadPatchType])
|
||||
@wsme_pecan.wsexpose(Load, unicode,
|
||||
@wsme.validate(six.text_type, [LoadPatchType])
|
||||
@wsme_pecan.wsexpose(Load, six.text_type,
|
||||
body=[LoadPatchType])
|
||||
def patch(self, load_id, patch):
|
||||
"""Update an existing load."""
|
||||
|
@ -317,7 +318,7 @@ class LoadController(rest.RestController):
|
|||
return Load.convert_with_links(rpc_load)
|
||||
|
||||
@cutils.synchronized(LOCK_NAME)
|
||||
@wsme_pecan.wsexpose(None, unicode, status_code=204)
|
||||
@wsme_pecan.wsexpose(None, six.text_type, status_code=204)
|
||||
def delete(self, load_id):
|
||||
"""Delete a load."""
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import jsonpatch
|
|||
import pecan
|
||||
from pecan import rest
|
||||
|
||||
import six
|
||||
import wsme
|
||||
from wsme import types as wtypes
|
||||
import wsmeext.pecan as wsme_pecan
|
||||
|
@ -259,7 +260,7 @@ class InfraNetworkController(rest.RestController):
|
|||
raise wsme.exc.ClientSideError(_(
|
||||
"VLAN id must be between 1 and 4094."))
|
||||
else:
|
||||
infra['infra_vlan_id'] = unicode(infra['infra_vlan_id'])
|
||||
infra['infra_vlan_id'] = six.text_type(infra['infra_vlan_id'])
|
||||
return infra
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -809,8 +809,8 @@ class ProfileController(rest.RestController):
|
|||
|
||||
return stor_profiles
|
||||
|
||||
@wsme_pecan.wsexpose(ProfileCollection, unicode, unicode, int,
|
||||
unicode, unicode)
|
||||
@wsme_pecan.wsexpose(ProfileCollection, six.text_type, six.text_type, int,
|
||||
six.text_type, six.text_type)
|
||||
def get_all(self, chassis_id=None, marker=None, limit=None,
|
||||
sort_key='id', sort_dir='asc'):
|
||||
"""Retrieve a list of ihosts."""
|
||||
|
@ -820,8 +820,8 @@ class ProfileController(rest.RestController):
|
|||
sort_key=sort_key,
|
||||
sort_dir=sort_dir)
|
||||
|
||||
@wsme_pecan.wsexpose(ProfileCollection, unicode, unicode, int,
|
||||
unicode, unicode)
|
||||
@wsme_pecan.wsexpose(ProfileCollection, six.text_type, six.text_type, int,
|
||||
six.text_type, six.text_type)
|
||||
def detail(self, chassis_id=None, marker=None, limit=None,
|
||||
sort_key='id', sort_dir='asc'):
|
||||
"""Retrieve a list of ihosts with detail."""
|
||||
|
@ -839,7 +839,7 @@ class ProfileController(rest.RestController):
|
|||
sort_key=sort_key,
|
||||
sort_dir=sort_dir)
|
||||
|
||||
@wsme_pecan.wsexpose(Profile, unicode)
|
||||
@wsme_pecan.wsexpose(Profile, six.text_type)
|
||||
def get_one(self, uuid):
|
||||
"""Retrieve information about the given ihost."""
|
||||
if self._from_chassis:
|
||||
|
@ -944,7 +944,7 @@ class ProfileController(rest.RestController):
|
|||
return iprofile.convert_with_links(new_ihost)
|
||||
|
||||
@cutils.synchronized(LOCK_NAME)
|
||||
@wsme_pecan.wsexpose(Profile, unicode, body=[unicode])
|
||||
@wsme_pecan.wsexpose(Profile, six.text_type, body=[six.text_type])
|
||||
def patch(self, uuid, patch):
|
||||
"""Update an existing iprofile.
|
||||
"""
|
||||
|
@ -999,7 +999,7 @@ class ProfileController(rest.RestController):
|
|||
raise wsme.exc.ClientSideError(msg)
|
||||
|
||||
@cutils.synchronized(LOCK_NAME)
|
||||
@wsme_pecan.wsexpose(None, unicode, status_code=204)
|
||||
@wsme_pecan.wsexpose(None, six.text_type, status_code=204)
|
||||
def delete(self, ihost_id):
|
||||
"""Delete an ihost profile.
|
||||
"""
|
||||
|
@ -2694,9 +2694,9 @@ def ifprofile_apply_to_host(host, profile):
|
|||
uses_list = []
|
||||
usedby_list = []
|
||||
for u in iinterfaces:
|
||||
if unicode(u.ifname) in i.uses or u.uuid in i.uses:
|
||||
if six.text_type(u.ifname) in i.uses or u.uuid in i.uses:
|
||||
uses_list.append(u.uuid)
|
||||
if unicode(u.ifname) in i.used_by or u.uuid in i.used_by:
|
||||
if six.text_type(u.ifname) in i.used_by or u.uuid in i.used_by:
|
||||
usedby_list.append(u.uuid)
|
||||
|
||||
idict['uses'] = uses_list
|
||||
|
|
|
@ -414,7 +414,7 @@ class SensorGroupController(rest.RestController):
|
|||
raise wsme.exc.ClientSideError("_get_host_uuid lookup failed")
|
||||
return host.uuid
|
||||
|
||||
@wsme_pecan.wsexpose('json', body=unicode)
|
||||
@wsme_pecan.wsexpose('json', body=six.text_type)
|
||||
def relearn(self, body):
|
||||
""" Handle Sensor Model Relearn Request."""
|
||||
host_uuid = self._get_host_uuid(body)
|
||||
|
|
|
@ -150,7 +150,7 @@ LOCK_NAME = 'SMServiceController'
|
|||
|
||||
class SMServiceController(rest.RestController):
|
||||
|
||||
@wsme_pecan.wsexpose(SMService, unicode)
|
||||
@wsme_pecan.wsexpose(SMService, six.text_type)
|
||||
def get_one(self, uuid):
|
||||
sm_service = sm_api.service_show(uuid)
|
||||
if sm_service is None:
|
||||
|
@ -172,7 +172,7 @@ class SMServiceController(rest.RestController):
|
|||
"Bad response from SM API"))
|
||||
|
||||
@cutils.synchronized(LOCK_NAME)
|
||||
@wsme_pecan.wsexpose(Service, wtypes.text, body=[unicode])
|
||||
@wsme_pecan.wsexpose(Service, wtypes.text, body=[six.text_type])
|
||||
def patch(self, service_name, patch):
|
||||
"""Update the service configuration."""
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import copy
|
|||
import netaddr
|
||||
import pecan
|
||||
from pecan import rest
|
||||
import six
|
||||
import wsme
|
||||
from wsme import types as wtypes
|
||||
import wsmeext.pecan as wsme_pecan
|
||||
|
@ -996,7 +997,7 @@ class ServiceParameterController(rest.RestController):
|
|||
return service
|
||||
|
||||
@cutils.synchronized(LOCK_NAME)
|
||||
@wsme_pecan.wsexpose('json', body=unicode)
|
||||
@wsme_pecan.wsexpose('json', body=six.text_type)
|
||||
def apply(self, body):
|
||||
""" Apply the service parameters."""
|
||||
service = self._get_service(body)
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
# this file is used for service group requests. Keeping naming consistent with sm client
|
||||
|
||||
from pecan import rest
|
||||
import six
|
||||
import wsme
|
||||
from wsme import types as wtypes
|
||||
import wsmeext.pecan as wsme_pecan
|
||||
|
@ -55,7 +56,7 @@ class SMServiceGroupCollection(base.APIBase):
|
|||
|
||||
class SMServiceGroupController(rest.RestController):
|
||||
|
||||
@wsme_pecan.wsexpose(SMServiceGroup, unicode)
|
||||
@wsme_pecan.wsexpose(SMServiceGroup, six.text_type)
|
||||
def get_one(self, uuid):
|
||||
sm_servicegroup = sm_api.sm_servicegroup_show(uuid)
|
||||
if sm_servicegroup is None:
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#
|
||||
|
||||
from pecan import rest
|
||||
import six
|
||||
import wsme
|
||||
from wsme import types as wtypes
|
||||
import wsmeext.pecan as wsme_pecan
|
||||
|
@ -51,7 +52,7 @@ class SMServiceNodeCollection(base.APIBase):
|
|||
|
||||
class SMServiceNodeController(rest.RestController):
|
||||
|
||||
@wsme_pecan.wsexpose(SMServiceNode, unicode)
|
||||
@wsme_pecan.wsexpose(SMServiceNode, six.text_type)
|
||||
def get_one(self, uuid):
|
||||
sm_servicenode = sm_api.servicenode_show(uuid)
|
||||
if sm_servicenode is None:
|
||||
|
|
|
@ -358,7 +358,7 @@ class SystemController(rest.RestController):
|
|||
raise exception.OperationNotPermitted
|
||||
|
||||
@cutils.synchronized(LOCK_NAME)
|
||||
@wsme_pecan.wsexpose(System, types.uuid, body=[unicode])
|
||||
@wsme_pecan.wsexpose(System, types.uuid, body=[six.text_type])
|
||||
def patch(self, isystem_uuid, patch):
|
||||
"""Update an existing isystem.
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
import pecan
|
||||
from pecan import rest, expose
|
||||
import os
|
||||
import six
|
||||
import socket
|
||||
import wsme
|
||||
from wsme import types as wtypes
|
||||
|
@ -185,7 +186,7 @@ class UpgradeController(rest.RestController):
|
|||
return Upgrade.convert_with_links(rpc_upgrade)
|
||||
|
||||
@cutils.synchronized(LOCK_NAME)
|
||||
@wsme_pecan.wsexpose(Upgrade, body=unicode)
|
||||
@wsme_pecan.wsexpose(Upgrade, body=six.text_type)
|
||||
def post(self, body):
|
||||
"""Create a new Software Upgrade instance and start upgrade."""
|
||||
|
||||
|
@ -420,7 +421,7 @@ class UpgradeController(rest.RestController):
|
|||
|
||||
return Upgrade.convert_with_links(upgrade)
|
||||
|
||||
@wsme_pecan.wsexpose(wtypes.text, unicode)
|
||||
@wsme_pecan.wsexpose(wtypes.text, six.text_type)
|
||||
def in_upgrade(self, uuid):
|
||||
# uuid is added here for potential future use
|
||||
try:
|
||||
|
|
|
@ -26,6 +26,7 @@ SHOULD include dedicated exception logging.
|
|||
"""
|
||||
|
||||
import functools
|
||||
import six
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
|
@ -158,7 +159,7 @@ class SysinvException(Exception):
|
|||
if self.__class__.__name__.endswith('_Remote'):
|
||||
return self.args[0]
|
||||
else:
|
||||
return unicode(self)
|
||||
return six.text_type(self)
|
||||
|
||||
|
||||
class NotAuthorized(SysinvException):
|
||||
|
|
|
@ -536,7 +536,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.string_types):
|
||||
hostname = hostname.encode('latin-1', 'ignore')
|
||||
|
||||
hostname = re.sub('[ _]', '-', hostname)
|
||||
|
|
Loading…
Reference in New Issue