Skip to content

Commit

Permalink
Merge pull request #958 from grycap/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
micafer authored Dec 12, 2019
2 parents 9fac725 + 7fa83fd commit 18aa0e9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 41 deletions.
2 changes: 1 addition & 1 deletion IM/connectors/OpenStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
58 changes: 20 additions & 38 deletions IM/tosca/Tosca.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import yaml
import copy
import operator
import requests

try:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -841,15 +840,15 @@ 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:
capability_name = func.args[1]
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":
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion IM/tts/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
2 changes: 1 addition & 1 deletion test/unit/connectors/OpenStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 18aa0e9

Please sign in to comment.