diff --git a/IM/connectors/OpenStack.py b/IM/connectors/OpenStack.py index de8febb65..a2b8d685c 100644 --- a/IM/connectors/OpenStack.py +++ b/IM/connectors/OpenStack.py @@ -1614,7 +1614,7 @@ def alter_public_ips(self, vm, radl, auth_data): return self.add_elastic_ip_from_pool(vm, node, None, pool_name) if not new_has_public_ip and current_public_ip: - floating_ip = node.driver.get_floating_ip(current_public_ip) + floating_ip = node.driver.ex_get_floating_ip(current_public_ip) if node.driver.ex_detach_floating_ip_from_node(node, floating_ip): floating_ip.delete() diff --git a/IM/tosca/Tosca.py b/IM/tosca/Tosca.py index d69429db4..7414024a1 100644 --- a/IM/tosca/Tosca.py +++ b/IM/tosca/Tosca.py @@ -2,6 +2,7 @@ import logging import yaml import copy +import operator import requests try: @@ -692,12 +693,10 @@ def _remove_recipe_header(script_content): try: yamlo = yaml.safe_load(script_content) if not isinstance(yamlo, list): - Tosca.logger.warn("Error parsing YAML: " + - script_content + "\n.Do not remove header.") + Tosca.logger.warn("Error parsing YAML: " + script_content + "\n.Do not remove header.") return script_content except Exception: - Tosca.logger.exception( - "Error parsing YAML: " + script_content + "\n.Do not remove header.") + Tosca.logger.exception("Error parsing YAML: " + script_content + "\n.Do not remove header.") return script_content for elem in yamlo: @@ -841,7 +840,7 @@ def _get_attribute_result(self, func, node, inf_info): if len(func.args) == 3: try: index = int(func.args[2]) - except: + except Exception: capability_name = func.args[1] attribute_name = func.args[2] elif len(func.args) == 4: @@ -849,7 +848,7 @@ def _get_attribute_result(self, func, node, inf_info): attribute_name = func.args[2] try: index = int(func.args[3]) - except: + except Exception: Tosca.logger.exception("Error getting get_attribute index.") if node_name == "HOST": @@ -1099,50 +1098,33 @@ def _node_fulfill_filter(self, node, node_filter): filter_props[p_name] = ("equal", p_value) operator_map = { - 'equal': '==', - 'greater_than': '>', - 'greater_or_equal': '>=', - 'less_than': '<', - 'less_or_equal': '<=' + 'equal': operator.eq, + 'greater_than': operator.gt, + 'greater_or_equal': operator.ge, + 'less_than': operator.lt, + 'less_or_equal': operator.le } # Compare the properties for name, value in filter_props.items(): - operator, filter_value = value + op, filter_value = value if name in ['disk_size', 'mem_size']: filter_value, _ = Tosca._get_size_and_unit(filter_value) if name in node_props: node_value, _ = node_props[name] - - if isinstance(node_value, str) or isinstance(node_value, unicode): - str_node_value = "'" + node_value + "'" - else: - str_node_value = str(node_value) - - conv_operator = operator_map.get(operator, None) + conv_operator = operator_map.get(op, None) if conv_operator: - if isinstance(filter_value, str) or isinstance(filter_value, unicode): - str_filter_value = "'" + filter_value + "'" - else: - str_filter_value = str(filter_value) - - comparation = str_node_value + conv_operator + str_filter_value + comparation = conv_operator(node_value, filter_value) else: - if operator == "in_range": - minv = filter_value[0] - maxv = filter_value[1] - comparation = str_node_value + ">=" + \ - str(minv) + " and " + \ - str_node_value + "<=" + str(maxv) - elif operator == "valid_values": - comparation = str_node_value + \ - " in " + str(filter_value) + if op == "in_range": + comparation = node_value >= filter_value[0] and node_value <= filter_value[1] + elif op == "valid_values": + comparation = node_value in filter_value else: - Tosca.logger.warn( - "Logical operator %s not supported." % operator) + Tosca.logger.warn("Logical operator %s not supported." % op) - if not eval(comparation): + if not comparation: return False else: # if this property is not specified in the node, return False @@ -1484,7 +1466,7 @@ def _get_root_parent_type(node): """ try: node_type = node.type_definition - except: + except AttributeError: node_type = node.definition while True: diff --git a/IM/tts/tts.py b/IM/tts/tts.py index a50199e49..70a2255f9 100644 --- a/IM/tts/tts.py +++ b/IM/tts/tts.py @@ -25,7 +25,7 @@ def __init__(self, token, host, port=None, uri_scheme=None, ssl_verify=False): self.uri_scheme = "http" self.ssl_verify = ssl_verify - def _perform_get(self, url, headers={}): + def _perform_get(self, url, headers=None): """ Perform the GET operation on the TTS with the specified URL """ diff --git a/test/unit/connectors/OpenStack.py b/test/unit/connectors/OpenStack.py index 80679cf0a..1954b6bc8 100755 --- a/test/unit/connectors/OpenStack.py +++ b/test/unit/connectors/OpenStack.py @@ -616,7 +616,7 @@ def test_55_alter(self, add_elastic_ip_from_pool, get_driver): fip = MagicMock() fip.delete.return_value = True - driver.get_floating_ip.return_value = fip + driver.ex_get_floating_ip.return_value = fip driver.ex_detach_floating_ip_from_node.return_value = True success, _ = ost_cloud.alterVM(vm, new_radl, auth)