diff options
24 files changed, 97 insertions, 81 deletions
diff --git a/conductor/conductor/api/controllers/v1/plans.py b/conductor/conductor/api/controllers/v1/plans.py index 8be24d8..9fb7240 100644 --- a/conductor/conductor/api/controllers/v1/plans.py +++ b/conductor/conductor/api/controllers/v1/plans.py @@ -349,8 +349,9 @@ def verify_user(authstr): user_dict = dict() auth_str = authstr user_pw = auth_str.split(' ')[1] + user_pw = user_pw.encode() # below function needs user_pw in bytes object in python 3 so converting that decode_user_pw = base64.b64decode(user_pw) - list_id_pw = decode_user_pw.split(':') + list_id_pw = decode_user_pw.decode().split(':') user_dict['username'] = str(list_id_pw[0]) user_dict['password'] = str(list_id_pw[1]) password = CONF.conductor_api.password diff --git a/conductor/conductor/api/middleware.py b/conductor/conductor/api/middleware.py index a04ea30..69b6264 100644 --- a/conductor/conductor/api/middleware.py +++ b/conductor/conductor/api/middleware.py @@ -159,7 +159,7 @@ class ParsableErrorMiddleware(object): if six.PY3: app_data = app_data.decode('utf-8') try: - fault = json.loads(app_data) + fault = list(json.loads(app_data)) if error is not None and 'faultstring' in fault: fault['faultstring'] = i18n.translate(error, user_locale) diff --git a/conductor/conductor/common/models/group_rules.py b/conductor/conductor/common/models/group_rules.py index fb7453f..453842c 100644 --- a/conductor/conductor/common/models/group_rules.py +++ b/conductor/conductor/common/models/group_rules.py @@ -80,7 +80,7 @@ class GroupRules(base.Base): return \ api.MUSIC_API.row_insert_by_condition( self.__keyspace__, self.__tablename__, self.pk_name(), - self.pk_value(), self.values(), self.PARKED) + self.pk_value(),self.values(), self.PARKED) def __init__(self, id=None, group=None,rule=None,_insert=False): """Initializer""" diff --git a/conductor/conductor/common/music/api.py b/conductor/conductor/common/music/api.py index 5929b58..ebde6a3 100644 --- a/conductor/conductor/common/music/api.py +++ b/conductor/conductor/common/music/api.py @@ -155,8 +155,8 @@ class MusicAPI(object): self.rest.session.headers['ns'] = CONF.music_api.aafns self.rest.session.headers['userId'] = CONF.music_api.aafuser self.rest.session.headers['password'] = music_pwd - self.rest.session.headers['Authorization'] = basic_auth_util.encode(CONF.music_api.aafuser, - CONF.music_api.aafpass) + self.rest.session.headers['Authorization'] = str(basic_auth_util.encode(CONF.music_api.aafuser, + CONF.music_api.aafpass)) self.lock_ids = {} @@ -178,7 +178,7 @@ class MusicAPI(object): def __del__(self): """Deletion.""" if type(self.lock_ids) is dict: - for lock_name in self.lock_ids.keys(): + for lock_name in list(self.lock_ids.keys()): # Python 3 Conversion -- dict object to list object self.lock_delete(lock_name) @staticmethod @@ -250,7 +250,7 @@ class MusicAPI(object): #lock_id = self.lock_ids.get(lock_name) data = { 'consistencyInfo': { - 'type': 'atomic' if condition else 'eventual', + 'type': 'atomic', } } diff --git a/conductor/conductor/common/music/messaging/component.py b/conductor/conductor/common/music/messaging/component.py index 6ecbe18..d761488 100644 --- a/conductor/conductor/common/music/messaging/component.py +++ b/conductor/conductor/common/music/messaging/component.py @@ -300,9 +300,9 @@ class RPCService(cotyledon.Service): msgs = self.RPC.query.all() for msg in msgs: if msg.enqueued: - if 'plan_name' in msg.ctxt.keys(): + if 'plan_name' in list(msg.ctxt.keys()): # Python 3 Conversion -- dict object to list object LOG.info('Plan name: {}'.format(msg.ctxt['plan_name'])) - elif 'plan_name' in msg.args.keys(): + elif 'plan_name' in list(msg.args.keys()): # Python 3 Conversion -- dict object to list object LOG.info('Plan name: {}'.format(msg.args['plan_name'])) msg.delete() @@ -352,9 +352,9 @@ class RPCService(cotyledon.Service): if not msg.enqueued: continue - if 'plan_name' in msg.ctxt.keys(): + if 'plan_name' in list(msg.ctxt.keys()): # Python 3 Conversion -- dict object to list object LOG.info('Plan name: {}'.format(msg.ctxt['plan_name'])) - elif 'plan_name' in msg.args.keys(): + elif 'plan_name' in list(msg.args.keys()): # Python 3 Conversion -- dict object to list object LOG.info('Plan name: {}'.format(msg.args['plan_name'])) # Change the status to WORKING (operation with a lock) @@ -394,7 +394,7 @@ class RPCService(cotyledon.Service): return # All methods must take a ctxt and args param. - if inspect.getargspec(method).args != ['self', 'ctx', 'arg']: + if inspect.getfullargspec(method).args != ['self', 'ctx', 'arg']: error_msg = _LE("Method {} must take three args: " "self, ctx, arg").format(msg.method) self._log_error_and_update_msg(msg, error_msg) diff --git a/conductor/conductor/common/rest.py b/conductor/conductor/common/rest.py index 585a628..d5ab8c8 100644 --- a/conductor/conductor/common/rest.py +++ b/conductor/conductor/common/rest.py @@ -109,7 +109,7 @@ class REST(object): } if headers: full_headers.update(headers) - full_url = '{}/{}'.format(self.server_url, path.lstrip('/')) + full_url = '{}/{}'.format(self.server_url, path.lstrip('/').rstrip('/')) # Prepare the request args try: @@ -162,10 +162,11 @@ class REST(object): json.dumps(response_dict))) except ValueError: LOG.debug("Response Body: {}".format(response.text)) + #response._content = response._content.decode() if response.ok: break except requests.exceptions.RequestException as err: - LOG.error("Exception: %s", err.message) + LOG.error("Exception: %s", err.args) # Response.__bool__ returns false if status is not ok. Ruh roh! # That means we must check the object type vs treating it as a bool. diff --git a/conductor/conductor/common/threshold.py b/conductor/conductor/common/threshold.py index 4ab81fd..0ebbb49 100644 --- a/conductor/conductor/common/threshold.py +++ b/conductor/conductor/common/threshold.py @@ -67,7 +67,7 @@ class Threshold(object): if base_unit not in self.UNITS: raise ThresholdException( "Base unit {} unsupported, must be one of: {}".format( - base_unit, ', '.join(self.UNITS.keys()))) + base_unit, ', '.join(list(self.UNITS.keys())))) # Python 3 Conversion -- dict object to list object self._expression = expression self._base_unit = base_unit @@ -80,7 +80,7 @@ class Threshold(object): def _all_units(self): """Returns a single list of all supported units""" - unit_lists = [self.UNITS[k].keys() for k in self.UNITS.keys()] + unit_lists = [list(self.UNITS[k].keys()) for k in list(self.UNITS.keys())] # Python 3 Conversion -- dict object to list object return list(itertools.chain.from_iterable(unit_lists)) def _default_for_base_unit(self, base_unit): diff --git a/conductor/conductor/common/utils/basic_auth_util.py b/conductor/conductor/common/utils/basic_auth_util.py index d4cdbac..039384f 100644 --- a/conductor/conductor/common/utils/basic_auth_util.py +++ b/conductor/conductor/common/utils/basic_auth_util.py @@ -28,7 +28,11 @@ LOG = log.getLogger(__name__) def encode(user_id, password): """ Provide the basic authencation encoded value in an 'Authorization' Header """ - user_pass = str(user_id) + ":" + str(password) + user_pass = user_id + ":" + password + # Here user_pass is str type but in python 3.x version, base64.b64encode is expecting byte + # like object so we need to convert the str into bytes + + user_pass = user_pass.encode() # converting str into bytes form base64_val = base64.b64encode(user_pass) authorization_val = _LE("Basic {}".format(base64_val)) diff --git a/conductor/conductor/common/utils/cipherUtils.py b/conductor/conductor/common/utils/cipherUtils.py index 6ee6c58..21a33b4 100644 --- a/conductor/conductor/common/utils/cipherUtils.py +++ b/conductor/conductor/common/utils/cipherUtils.py @@ -52,7 +52,9 @@ class AESCipher(object): self.bs = 32 if key is None: - key = CONF.auth.appkey.encode() + key = CONF.auth.appkey # ---> python3.8 Code version code + # key= CONF.auth.appkey.encode() ---> Python 2.7 version code + # in Python 3+ key is already a b'' type so no need to encode it again. self.key = hashlib.sha256(key.encode()).digest() diff --git a/conductor/conductor/controller/translator.py b/conductor/conductor/controller/translator.py index 45e0ee2..8184639 100644 --- a/conductor/conductor/controller/translator.py +++ b/conductor/conductor/controller/translator.py @@ -225,8 +225,8 @@ class Translator(object): "{} {} has an invalid key {}".format( name, content_name, key)) - demand_keys = self._demands.keys() - location_keys = self._locations.keys() + demand_keys = list(self._demands.keys()) # Python 3 Conversion -- dict object to list object + location_keys = list(self._locations.keys()) # Python 3 Conversion -- dict object to list object for constraint_name, constraint in self._constraints.items(): # Require a single demand (string), or a list of one or more. @@ -279,7 +279,7 @@ class Translator(object): # Traverse a dict elif type(obj) is dict: # Did we find a "{get_param: ...}" intrinsic? - if obj.keys() == ['get_param']: + if list(obj.keys()) == ['get_param']: param_name = obj['get_param'] # The parameter name must be a string. @@ -300,7 +300,7 @@ class Translator(object): return self._parameters.get(param_name) # Not an intrinsic. Traverse as usual. - for key in obj.keys(): + for key in list(obj.keys()): # Add path to the breadcrumb trail. new_path = list(path) new_path.append(key) @@ -393,7 +393,7 @@ class Translator(object): "not a dictionary".format(name)) # Must have only supported keys - for key in candidate.keys(): + for key in list(candidate.keys()): if key not in CANDIDATE_KEYS: raise TranslatorException( "Candidate with invalid key {} found " @@ -657,7 +657,7 @@ class Translator(object): # Make sure all required properties are present required = constraint_def.get('required', []) for req_prop in required: - if req_prop not in value.keys(): + if req_prop not in list(value.keys()): raise TranslatorException( "Required property '{}' not found in " "constraint named '{}'".format( @@ -674,7 +674,7 @@ class Translator(object): # Make sure there are no unknown properties optional = constraint_def.get('optional', []) - for prop_name in value.keys(): + for prop_name in list(value.keys()): if prop_name not in required + optional: raise TranslatorException( "Unknown property '{}' in " @@ -685,7 +685,7 @@ class Translator(object): # sure its value is one of the allowed ones. allowed = constraint_def.get('allowed', {}) for prop_name, allowed_values in allowed.items(): - if prop_name in value.keys(): + if prop_name in list(value.keys()): prop_value = value.get(prop_name, '') if prop_value not in allowed_values: raise TranslatorException( @@ -697,7 +697,7 @@ class Translator(object): # Break all threshold-formatted values into parts thresholds = constraint_def.get('thresholds', {}) for thr_prop, base_units in thresholds.items(): - if thr_prop in value.keys(): + if thr_prop in list(value.keys()): expression = value.get(thr_prop) thr = threshold.Threshold(expression, base_units) value[thr_prop] = thr.parts @@ -751,12 +751,12 @@ class Translator(object): if type(optimization_copy) is not dict: raise TranslatorException("Optimization must be a dictionary.") - goals = optimization_copy.keys() + goals = list(optimization_copy.keys()) if goals != ['minimize']: raise TranslatorException( "Optimization must contain a single goal of 'minimize'.") - funcs = optimization_copy['minimize'].keys() + funcs = list(optimization_copy['minimize'].keys()) if funcs != ['sum']: raise TranslatorException( "Optimization goal 'minimize' must " @@ -779,9 +779,9 @@ class Translator(object): got_demand = False got_location = False for arg in args: - if not got_demand and arg in self._demands.keys(): + if not got_demand and arg in list(self._demands.keys()): got_demand = True - if not got_location and arg in self._locations.keys(): + if not got_location and arg in list(self._locations.keys()): got_location = True if not got_demand or not got_location: raise TranslatorException( @@ -801,9 +801,9 @@ class Translator(object): got_demand = False got_location = False for arg in args: - if not got_demand and arg in self._demands.keys(): + if not got_demand and arg in list(self._demands.keys()): got_demand = True - if not got_location and arg in self._locations.keys(): + if not got_location and arg in list(self._locations.keys()): got_location = True if not got_demand or not got_location: raise TranslatorException( @@ -818,47 +818,47 @@ class Translator(object): args = None nested = False - if operand.keys() == ['distance_between']: + if list(operand.keys()) == ['distance_between']: # Value must be a list of length 2 with one # location and one demand function = 'distance_between' args = get_distance_between_args(operand) - elif operand.keys() == ['product']: + elif list(operand.keys()) == ['product']: for product_op in operand['product']: if threshold.is_number(product_op): weight = product_op elif isinstance(product_op, dict): - if product_op.keys() == ['latency_between']: + if list(product_op.keys()) == ['latency_between']: function = 'latency_between' args = get_latency_between_args(product_op) - elif product_op.keys() == ['distance_between']: + elif list(product_op.keys()) == ['distance_between']: function = 'distance_between' args = get_distance_between_args(product_op) - elif product_op.keys() == ['aic_version']: + elif list(product_op.keys()) == ['aic_version']: function = 'aic_version' args = product_op.get('aic_version') - elif product_op.keys() == ['hpa_score']: + elif list(product_op.keys()) == ['hpa_score']: function = 'hpa_score' args = product_op.get('hpa_score') if not self.is_hpa_policy_exists(args): raise TranslatorException( "HPA Score Optimization must include a " "HPA Policy constraint ") - elif product_op.keys() == ['sum']: + elif list(product_op.keys()) == ['sum']: nested = True nested_operands = product_op.get('sum') for nested_operand in nested_operands: - if nested_operand.keys() == ['product']: + if list(nested_operand.keys()) == ['product']: nested_weight = weight for nested_product_op in nested_operand['product']: if threshold.is_number(nested_product_op): nested_weight = nested_weight * int(nested_product_op) elif isinstance(nested_product_op, dict): - if nested_product_op.keys() == ['latency_between']: + if list(nested_product_op.keys()) == ['latency_between']: function = 'latency_between' args = get_latency_between_args(nested_product_op) - elif nested_product_op.keys() == ['distance_between']: + elif list(nested_product_op.keys()) == ['distance_between']: function = 'distance_between' args = get_distance_between_args(nested_product_op) parsed['operands'].append( @@ -920,7 +920,7 @@ class Translator(object): if not reservation_details.get('properties'): reservation_details['properties'] = {} for demand in reservation_details.get('demands', []): - if demand in demands.keys(): + if demand in list(demands.keys()): reservation_demand = name + '_' + demand parsed['demands'][reservation_demand] = copy.deepcopy(reservation_details) parsed['demands'][reservation_demand]['name'] = name @@ -963,7 +963,7 @@ class Translator(object): self.do_translation() self._ok = True except Exception as exc: - self._error_message = exc.message + self._error_message = exc.args @property def valid(self): diff --git a/conductor/conductor/data/plugins/inventory_provider/aai.py b/conductor/conductor/data/plugins/inventory_provider/aai.py index f49d526..cf764e5 100644 --- a/conductor/conductor/data/plugins/inventory_provider/aai.py +++ b/conductor/conductor/data/plugins/inventory_provider/aai.py @@ -290,7 +290,7 @@ class AAI(base.InventoryProviderBase): keys = ('latitude', 'longitude', 'city', 'country', 'complex_name') missing_keys = \ - list(set(keys).difference(complex_info.keys())) + list(set(keys).difference(list(complex_info.keys()))) # Python 3 Conversion -- dict object to list object LOG.error(_LE("Complex {} is missing {}, link: {}"). format(complex_id, missing_keys, complex_link)) LOG.debug("Complex {}: {}". @@ -418,7 +418,7 @@ class AAI(base.InventoryProviderBase): if not (latitude and longitude and city and country): keys = ('latitude', 'longitude', 'city', 'country') missing_keys = \ - list(set(keys).difference(complex_info.keys())) + list(set(keys).difference(set(complex_info.keys()))) LOG.error(_LE("Complex {} is missing {}, link: {}"). format(complex_id, missing_keys, complex_link)) LOG.debug("Complex {}: {}". diff --git a/conductor/conductor/data/plugins/triage_translator/triage_translator.py b/conductor/conductor/data/plugins/triage_translator/triage_translator.py index f660ad5..697c64a 100644 --- a/conductor/conductor/data/plugins/triage_translator/triage_translator.py +++ b/conductor/conductor/data/plugins/triage_translator/triage_translator.py @@ -23,7 +23,11 @@ import json from conductor.common.models.triage_tool import TriageTool from conductor.common.music.model import base from oslo_config import cfg -from StringIO import StringIO +try: + from StringIO import StringIO ## for Python 2 +except ImportError: + from io import StringIO ## for Python 3 + CONF = cfg.CONF io = StringIO() @@ -36,7 +40,7 @@ class TraigeTranslator(object): triage_translator_data['plan_name'] = plan_name triage_translator_data['plan_id'] = plan_id def addDemandsTriageTranslator(self, name, triage_translator_data): - if not 'dropped_candidates' in triage_translator_data.keys(): + if not 'dropped_candidates' in list(triage_translator_data.keys()): # Python 3 Conversion -- dict object to list object triage_translator_data['dropped_candidates'] = [] dropped_candidate_details = {} dropped_candidate_details['name'] = name @@ -45,7 +49,7 @@ class TraigeTranslator(object): triage_translator_data['dropped_candidates'].append(dropped_candidate_details) else: for dc in triage_translator_data['dropped_candidates']: - print name + print(name) # Python 3 conversion as print statement changed from python 2 if not dc['name'] == name: dropped_candidate_details = {} dropped_candidate_details['name'] = name diff --git a/conductor/conductor/data/service.py b/conductor/conductor/data/service.py index 0b66b22..ab1a331 100644 --- a/conductor/conductor/data/service.py +++ b/conductor/conductor/data/service.py @@ -664,6 +664,7 @@ class DataEndpoint(object): host_name = arg.get('host_name') clli_code = arg.get('clli_code') + if host_name: results = self.ip_ext_manager.map_method( 'resolve_host_location', diff --git a/conductor/conductor/reservation/service.py b/conductor/conductor/reservation/service.py index 01a7453..6a990f5 100644 --- a/conductor/conductor/reservation/service.py +++ b/conductor/conductor/reservation/service.py @@ -400,7 +400,7 @@ class ReservationService(cotyledon.Service): # order_lock spin-up rollback for decision in solution.get('recommendations'): - candidate = decision.values()[0].get('candidate') + candidate = list(decision.values())[0].get('candidate') # Python 3 Conversion -- dict object to list object if candidate.get('inventory_type') == 'cloud': # TODO(larry) change the code to get('conflict_id') instead of 'location_id' conflict_id = candidate.get('conflict_id') @@ -452,7 +452,7 @@ class ReservationService(cotyledon.Service): # order_lock spin-up rollback for decision in solution.get('recommendations'): - candidate = decision.values()[0].get('candidate') + candidate = list(decision.values())[0].get('candidate') # Python 3 Conversion -- dict object to list object if candidate.get('inventory_type') == 'cloud': conflict_id = candidate.get('conflict_id') order_record = self.OrderLock.query.get_plan_by_col("id", conflict_id)[0] diff --git a/conductor/conductor/solver/optimizer/best_first.py b/conductor/conductor/solver/optimizer/best_first.py index 3b579c6..2ac6387 100755 --- a/conductor/conductor/solver/optimizer/best_first.py +++ b/conductor/conductor/solver/optimizer/best_first.py @@ -88,7 +88,7 @@ class BestFirst(search.Search): # check closeness for this decision np.set_decision_id(p, candidate.name) - if np.decision_id in close_paths.keys(): + if np.decision_id in list(close_paths.keys()): # Python 3 Conversion -- dict object to list object valid_candidate = False ''' for base comparison heuristic ''' @@ -112,7 +112,7 @@ class BestFirst(search.Search): def _get_new_demand(self, _p, _demand_list): for demand in _demand_list: - if demand.name not in _p.decisions.keys(): + if demand.name not in list(_p.decisions.keys()): # Python 3 Conversion -- dict object to list object return demand return None diff --git a/conductor/conductor/solver/optimizer/constraints/inventory_group.py b/conductor/conductor/solver/optimizer/constraints/inventory_group.py index f0f8089..a0d1095 100755 --- a/conductor/conductor/solver/optimizer/constraints/inventory_group.py +++ b/conductor/conductor/solver/optimizer/constraints/inventory_group.py @@ -21,7 +21,7 @@ from oslo_log import log -from constraint import Constraint +from .constraint import Constraint # Python 3 import statement relative imports LOG = log.getLogger(__name__) diff --git a/conductor/conductor/solver/optimizer/constraints/zone.py b/conductor/conductor/solver/optimizer/constraints/zone.py index c95b085..ef9889c 100755 --- a/conductor/conductor/solver/optimizer/constraints/zone.py +++ b/conductor/conductor/solver/optimizer/constraints/zone.py @@ -22,7 +22,7 @@ import operator from oslo_log import log -from constraint import Constraint +from .constraint import Constraint # Python 3 import statement relative imports LOG = log.getLogger(__name__) diff --git a/conductor/conductor/solver/optimizer/optimizer.py b/conductor/conductor/solver/optimizer/optimizer.py index 7909c15..97e0c88 100755 --- a/conductor/conductor/solver/optimizer/optimizer.py +++ b/conductor/conductor/solver/optimizer/optimizer.py @@ -239,7 +239,7 @@ class Optimizer(object): if op.function.func_type == "latency_between": #TODO if op.function.loc_a.name == d.name: if op.function.loc_z.name in \ - _request.demands.keys(): + list(_request.demands.keys()): # Python 3 Conversion -- dict object to list object if _request.demands[ op.function.loc_z.name].sort_base != 1: _request.demands[ @@ -247,7 +247,7 @@ class Optimizer(object): _open_demand_list.append(op.function.loc_z) elif op.function.loc_z.name == d.name: if op.function.loc_a.name in \ - _request.demands.keys(): + list(_request.demands.keys()): # Python 3 Conversion -- dict object to list object if _request.demands[ op.function.loc_a.name].sort_base != 1: _request.demands[ @@ -257,7 +257,7 @@ class Optimizer(object): elif op.function.func_type == "distance_between": if op.function.loc_a.name == d.name: if op.function.loc_z.name in \ - _request.demands.keys(): + list(_request.demands.keys()): # Python 3 Conversion -- dict object to list object if _request.demands[ op.function.loc_z.name].sort_base != 1: _request.demands[ @@ -265,7 +265,7 @@ class Optimizer(object): _open_demand_list.append(op.function.loc_z) elif op.function.loc_z.name == d.name: if op.function.loc_a.name in \ - _request.demands.keys(): + list(_request.demands.keys()): # Python 3 Conversion -- dict object to list object if _request.demands[ op.function.loc_a.name].sort_base != 1: _request.demands[ diff --git a/conductor/conductor/solver/request/objective.py b/conductor/conductor/solver/request/objective.py index 526a889..70882ec 100755 --- a/conductor/conductor/solver/request/objective.py +++ b/conductor/conductor/solver/request/objective.py @@ -55,7 +55,7 @@ class Operand(object): if self.function.func_type == "latency_between": if isinstance(self.function.loc_a, demand.Location): if self.function.loc_z.name in \ - _decision_path.decisions.keys(): + list(_decision_path.decisions.keys()): # Python 3 Conversion -- dict object to list object resource = \ _decision_path.decisions[self.function.loc_z.name] candidate_cost = resource.get('cost') @@ -70,7 +70,7 @@ class Operand(object): + candidate_cost elif isinstance(self.function.loc_z, demand.Location): if self.function.loc_a.name in \ - _decision_path.decisions.keys(): + list(_decision_path.decisions.keys()): # Python 3 Conversion -- dict object to list object resource = \ _decision_path.decisions[self.function.loc_a.name] candidate_cost = resource.get('cost') @@ -85,9 +85,9 @@ class Operand(object): + candidate_cost else: if self.function.loc_a.name in \ - _decision_path.decisions.keys() and \ + list(_decision_path.decisions.keys()) and \ self.function.loc_z.name in \ - _decision_path.decisions.keys(): + list(_decision_path.decisions.keys()): # Python 3 Conversion -- dict object to list object resource_a = \ _decision_path.decisions[self.function.loc_a.name] loc_a = None @@ -122,7 +122,7 @@ class Operand(object): elif self.function.func_type == "distance_between": if isinstance(self.function.loc_a, demand.Location): if self.function.loc_z.name in \ - _decision_path.decisions.keys(): + list(_decision_path.decisions.keys()): # Python 3 Conversion -- dict object to list object resource = \ _decision_path.decisions[self.function.loc_z.name] candidate_cost = resource.get('cost') @@ -137,7 +137,7 @@ class Operand(object): + candidate_cost elif isinstance(self.function.loc_z, demand.Location): if self.function.loc_a.name in \ - _decision_path.decisions.keys(): + list(_decision_path.decisions.keys()): # Python 3 Conversion -- dict object to list object resource = \ _decision_path.decisions[self.function.loc_a.name] candidate_cost = resource.get('cost') @@ -152,9 +152,9 @@ class Operand(object): + candidate_cost else: if self.function.loc_a.name in \ - _decision_path.decisions.keys() and \ + list(_decision_path.decisions.keys()) and \ self.function.loc_z.name in \ - _decision_path.decisions.keys(): + list(_decision_path.decisions.keys()): # Python 3 Conversion -- dict object to list object resource_a = \ _decision_path.decisions[self.function.loc_a.name] loc_a = None diff --git a/conductor/conductor/solver/request/parser.py b/conductor/conductor/solver/request/parser.py index 0b3fb76..0ce3290 100755 --- a/conductor/conductor/solver/request/parser.py +++ b/conductor/conductor/solver/request/parser.py @@ -331,7 +331,7 @@ class Parser(object): candidate_countries = '' for demand_id, demands in self.demands.items(): candidate_countries += demand_id - for candidte in demands.resources.values(): + for candidte in list(demands.resources.values()): # Python 3 Conversion -- dict object to list object candidate_country_list.append(candidte["country"]) candidate_countries += candidte["country"] candidate_countries += ',' @@ -401,7 +401,7 @@ class Parser(object): for demand_id, demands in self.demands.items(): LOG.info("demand id " + demand_id) - for candidte in demands.resources.values(): + for candidte in list(demands.resources.values()): # Python 3 Conversion -- dict object to list object LOG.info("candidate id " + candidte['candidate_id']) dem_candidate = {demand_id: demands} temp_candidates.update(dem_candidate) @@ -409,7 +409,7 @@ class Parser(object): droped_candidates = '' for demand_id, demands in temp_candidates.items(): droped_candidates += demand_id - for candidate in demands.resources.values(): + for candidate in list(demands.resources.values()): # Python 3 Conversion -- dict object to list object if demand_id in self.obj_func_param and candidate["country"] in diff_bw_candidates_and_countries: droped_candidates += candidate['candidate_id'] droped_candidates += ',' @@ -541,6 +541,6 @@ class Parser(object): self.reorder_constraint() for constraint_name, constraint in self.constraints.items(): for d in constraint.demand_list: - if d in self.demands.keys(): + if d in list(self.demands.keys()): # Python 3 Conversion -- dict object to list object self.demands[d].constraint_list.append(constraint) self.sort_constraint_by_rank() diff --git a/conductor/conductor/solver/service.py b/conductor/conductor/solver/service.py index fb7b2f0..2ed0c4a 100644 --- a/conductor/conductor/solver/service.py +++ b/conductor/conductor/solver/service.py @@ -420,7 +420,7 @@ class SolverService(cotyledon.Service): except Exception as err: message = _LE("Plan {} status encountered a " - "parsing error: {}").format(p.id, err.message) + "parsing error: {}").format(p.id, err) LOG.error(traceback.print_exc()) p.status = self.Plan.ERROR p.message = message @@ -766,7 +766,7 @@ class SolverService(cotyledon.Service): :param flavor_map: flavor map get :param directives: All the directives get from request ''' - keys = flavor_map.keys() + keys = list(flavor_map.keys()) # Python 3 Conversion -- dict object to list object for ele in directives.get("directives"): for item in ele.get("directives"): if "flavor_directives" in item.get("type"): diff --git a/conductor/conductor/solver/triage_tool/traige_latency.py b/conductor/conductor/solver/triage_tool/traige_latency.py index 3a7fb0c..a93f558 100644 --- a/conductor/conductor/solver/triage_tool/traige_latency.py +++ b/conductor/conductor/solver/triage_tool/traige_latency.py @@ -24,7 +24,10 @@ import unicodedata from conductor.common.models.triage_tool import TriageTool from conductor.common.music.model import base from oslo_config import cfg -from StringIO import StringIO +try: + from StringIO import StringIO ## for Python 2 +except ImportError: + from io import StringIO ## for Python 3 CONF = cfg.CONF io = StringIO() diff --git a/conductor/conductor/solver/triage_tool/triage_data.py b/conductor/conductor/solver/triage_tool/triage_data.py index 007efcb..03a29bf 100644 --- a/conductor/conductor/solver/triage_tool/triage_data.py +++ b/conductor/conductor/solver/triage_tool/triage_data.py @@ -98,7 +98,7 @@ class TriageData(object): ca['type'] ='dropped' for cca in ca['constraints']: for dl in dc['constraints']: - if 'constraint_name_dropped' in dl.keys(): + if 'constraint_name_dropped' in list(dl.keys()): # Python 3 Conversion -- dict object to list object if(cca['name'] == dl['constraint_name_dropped']): dc['status'] = "dropped" return self.triage @@ -108,7 +108,7 @@ class TriageData(object): count = self.sorted_demand.index(demanHadNoCandidate.name) count = count-1 if count == 0: - decision_rolba = decisionWeneedtoRollback.decisions.values() + decision_rolba = list(decisionWeneedtoRollback.decisions.values()) # Python 3 Conversion -- dict object to list object for x in decision_rolba: for canrb in self.triage['candidates']: if x['node_id'] == canrb['node_id'] : @@ -145,10 +145,10 @@ class TriageData(object): counter = 0 d1 = []; d2 = []; d3 = []; d4 = []; d5 = []; d6 = [] for fc in decision_list: - for final_cand in fc.values(): + for final_cand in list(fc.values()): # Python 3 Conversion -- dict object to list object for final_resou in self.triage['candidates']: if final_cand['node_id'] == final_resou['node_id']: - if 'type' in final_resou.keys() : + if 'type' in list(final_resou.keys()) : # Python 3 Conversion -- dict object to list object if not final_resou['type'] == "dropped": final_resou['type'] = 'solution' final_resou['children'] = [] @@ -156,7 +156,7 @@ class TriageData(object): final_resou['type'] = 'solution' final_resou['children'] = [] - elif not 'type' in final_resou.keys(): + elif not 'type' in list(final_resou.keys()): # Python 3 Conversion -- dict object to list object final_resou['type'] = 'not tried' # for cand in self.triage['candidates']: @@ -59,7 +59,7 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> - <version>2.7</version> + <version>3.8</version> <configuration> <retryFailedDeploymentCount>2</retryFailedDeploymentCount> </configuration> |