diff options
Diffstat (limited to 'functest/utils')
-rw-r--r--[-rwxr-xr-x] | functest/utils/config.py | 14 | ||||
-rw-r--r--[-rwxr-xr-x] | functest/utils/constants.py | 19 | ||||
-rw-r--r-- | functest/utils/decorators.py | 8 | ||||
-rw-r--r-- | functest/utils/env.py | 9 | ||||
-rw-r--r-- | functest/utils/functest_logger.py | 83 | ||||
-rw-r--r-- | functest/utils/functest_utils.py | 26 | ||||
-rw-r--r-- | functest/utils/openstack/cinder.py | 7 | ||||
-rw-r--r-- | functest/utils/openstack/glance.py | 7 | ||||
-rw-r--r-- | functest/utils/openstack/keystone.py | 7 | ||||
-rw-r--r-- | functest/utils/openstack/neutron.py | 7 | ||||
-rw-r--r-- | functest/utils/openstack/nova.py | 7 | ||||
-rwxr-xr-x | functest/utils/openstack_clean.py | 5 | ||||
-rwxr-xr-x | functest/utils/openstack_snapshot.py | 5 | ||||
-rw-r--r-- | functest/utils/openstack_tacker.py | 4 | ||||
-rw-r--r-- | functest/utils/openstack_utils.py | 135 |
15 files changed, 114 insertions, 229 deletions
diff --git a/functest/utils/config.py b/functest/utils/config.py index b5b84501..d91f63ac 100755..100644 --- a/functest/utils/config.py +++ b/functest/utils/config.py @@ -1,8 +1,11 @@ -import os +#!/usr/bin/env python +import os import yaml -import env +import six + +from functest.utils import env class Config(object): @@ -16,7 +19,7 @@ class Config(object): self._set_others() def _parse(self, attr_now, left_parametes): - for param_n, param_v in left_parametes.iteritems(): + for param_n, param_v in six.iteritems(left_parametes): attr_further = self._get_attr_further(attr_now, param_n) if attr_further: self.__setattr__(attr_further, param_v) @@ -32,8 +35,3 @@ class Config(object): CONF = Config() - -if __name__ == "__main__": - print CONF.vnf_cloudify_ims - print CONF.vnf_cloudify_ims_tenant_images - print CONF.vnf_cloudify_ims_tenant_images_centos_7 diff --git a/functest/utils/constants.py b/functest/utils/constants.py index 2e8eb3f4..75c97c76 100755..100644 --- a/functest/utils/constants.py +++ b/functest/utils/constants.py @@ -1,20 +1,17 @@ -import config -import env +#!/usr/bin/env python + +import six + +from functest.utils import config +from functest.utils import env class Constants(object): def __init__(self): - for attr_n, attr_v in config.CONF.__dict__.iteritems(): + for attr_n, attr_v in six.iteritems(config.CONF.__dict__): self.__setattr__(attr_n, attr_v) - for env_n, env_v in env.ENV.__dict__.iteritems(): + for env_n, env_v in six.iteritems(env.ENV.__dict__): self.__setattr__(env_n, env_v) CONST = Constants() - -if __name__ == '__main__': - print CONST.__dict__ - print CONST.NODE_NAME - print CONST.vIMS_clearwater_blueprint_url - print CONST.vIMS_clearwater_blueprint_file_name - print CONST.vIMS_clearwater_blueprint_name diff --git a/functest/utils/decorators.py b/functest/utils/decorators.py index 46ffe35d..73e0a352 100644 --- a/functest/utils/decorators.py +++ b/functest/utils/decorators.py @@ -3,18 +3,19 @@ # pylint: disable=missing-docstring import errno +import functools import os -import urlparse import mock import requests.sessions +from six.moves import urllib def can_dump_request_to_file(method): def dump_preparedrequest(request, **kwargs): # pylint: disable=unused-argument - parseresult = urlparse.urlparse(request.url) + parseresult = urllib.parse.urlparse(request.url) if parseresult.scheme == "file": try: dirname = os.path.dirname(parseresult.path) @@ -33,7 +34,7 @@ def can_dump_request_to_file(method): def patch_request(method, url, **kwargs): with requests.sessions.Session() as session: - parseresult = urlparse.urlparse(url) + parseresult = urllib.parse.urlparse(url) if parseresult.scheme == "file": with mock.patch.object(session, 'send', side_effect=dump_preparedrequest): @@ -41,6 +42,7 @@ def can_dump_request_to_file(method): else: return session.request(method=method, url=url, **kwargs) + @functools.wraps(method) def hook(*args, **kwargs): with mock.patch('requests.api.request', side_effect=patch_request): return method(*args, **kwargs) diff --git a/functest/utils/env.py b/functest/utils/env.py index 7e4df2ea..c9629e15 100644 --- a/functest/utils/env.py +++ b/functest/utils/env.py @@ -1,6 +1,11 @@ +#!/usr/bin/env python + import os import re +import six + + default_envs = { 'NODE_NAME': 'unknown_pod', 'CI_DEBUG': 'false', @@ -17,9 +22,9 @@ default_envs = { class Environment(object): def __init__(self): - for k, v in os.environ.iteritems(): + for k, v in six.iteritems(os.environ): self.__setattr__(k, v) - for k, v in default_envs.iteritems(): + for k, v in six.iteritems(default_envs): if k not in os.environ: self.__setattr__(k, v) self._set_ci_run() diff --git a/functest/utils/functest_logger.py b/functest/utils/functest_logger.py deleted file mode 100644 index ba52829f..00000000 --- a/functest/utils/functest_logger.py +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/env python -# -# jose.lausuch@ericsson.com -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Logging levels: -# Level Numeric value -# CRITICAL 50 -# ERROR 40 -# WARNING 30 -# INFO 20 -# DEBUG 10 -# NOTSET 0 -# -# Usage: -# import functest_logger as fl -# logger = fl.Logger("script_name").getLogger() -# logger.info("message to be shown with - INFO - ") -# logger.debug("message to be shown with - DEBUG -") -import logging -import logging.config -import os - -import json - -from functest.utils.constants import CONST - -ignore = ["paramiko", - "stevedore.extension", - "keystoneauth.session", - "keystoneauth.identity.v3.base", - "novaclient.v2.client", - "neutronclient.v2_0.client", - "glanceclient.common.http", - "cinderclient.v2.client", - "cinderclient.client"] - - -class Logger(object): - - instance = None - - def __new__(cls, logger_name): - if cls.instance is None: - cls.instance = object.__new__(cls) - return cls.instance - - def __init__(self, logger_name): - self.setup_logging() - self.logger = logging.getLogger(logger_name) - for module_name in ignore: - logging.getLogger(module_name).setLevel(logging.WARNING) - - def getLogger(self): - return self.logger - - def is_debug(self): - if CONST.CI_DEBUG and CONST.CI_DEBUG.lower() == "true": - return True - return False - - def setup_logging(self, default_path=CONST.dir_functest_logging_cfg, - default_level=logging.INFO, - env_key='LOG_CFG'): - path = default_path - value = os.getenv(env_key, None) - if value: - path = value - if os.path.exists(path): - with open(path, 'rt') as f: - config = json.load(f) - if (config['handlers'] and - config['handlers']['console']): - stream_level = logging.INFO - if self.is_debug(): - stream_level = logging.DEBUG - config['handlers']['console']['level'] = stream_level - logging.config.dictConfig(config) - else: - logging.basicConfig(level=default_level) diff --git a/functest/utils/functest_utils.py b/functest/utils/functest_utils.py index 7d993cbf..bf30f56e 100644 --- a/functest/utils/functest_utils.py +++ b/functest/utils/functest_utils.py @@ -9,24 +9,24 @@ # import functools import json +import logging import os import re import shutil import subprocess import sys import time -import urllib2 from datetime import datetime as dt import dns.resolver import requests +from six.moves import urllib import yaml from git import Repo from functest.utils import decorators -import functest.utils.functest_logger as ft_logger -logger = ft_logger.Logger("functest_utils").getLogger() +logger = logging.getLogger(__name__) # ---------------------------------------------------------- @@ -39,9 +39,9 @@ def check_internet_connectivity(url='http://www.opnfv.org/'): Check if there is access to the internet """ try: - urllib2.urlopen(url, timeout=5) + urllib.request.urlopen(url, timeout=5) return True - except urllib2.URLError: + except urllib.error.URLError: return False @@ -52,8 +52,8 @@ def download_url(url, dest_path): name = url.rsplit('/')[-1] dest = dest_path + "/" + name try: - response = urllib2.urlopen(url) - except (urllib2.HTTPError, urllib2.URLError): + response = urllib.request.urlopen(url) + except (urllib.error.HTTPError, urllib.error.URLError): return False with open(dest, 'wb') as f: @@ -318,7 +318,7 @@ def execute_command(cmd, info=False, error_msg="", f.write(line) else: line = line.replace('\n', '') - print line + print(line) sys.stdout.flush() if output_file: f.close() @@ -379,16 +379,6 @@ def get_functest_config(parameter): return get_parameter_from_yaml(parameter, yaml_) -def check_success_rate(case_name, result): - # It should be removed as TestCase tests criteria - # and result. - logger.warning('check_success_rate will be removed soon') - criteria = get_criteria_by_test(case_name) - if type(criteria) == int and result >= criteria: - return 'PASS' - return 'FAIL' - - def merge_dicts(dict1, dict2): for k in set(dict1.keys()).union(dict2.keys()): if k in dict1 and k in dict2: diff --git a/functest/utils/openstack/cinder.py b/functest/utils/openstack/cinder.py deleted file mode 100644 index f966468a..00000000 --- a/functest/utils/openstack/cinder.py +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env python -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -# diff --git a/functest/utils/openstack/glance.py b/functest/utils/openstack/glance.py deleted file mode 100644 index f966468a..00000000 --- a/functest/utils/openstack/glance.py +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env python -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -# diff --git a/functest/utils/openstack/keystone.py b/functest/utils/openstack/keystone.py deleted file mode 100644 index f966468a..00000000 --- a/functest/utils/openstack/keystone.py +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env python -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -# diff --git a/functest/utils/openstack/neutron.py b/functest/utils/openstack/neutron.py deleted file mode 100644 index f966468a..00000000 --- a/functest/utils/openstack/neutron.py +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env python -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -# diff --git a/functest/utils/openstack/nova.py b/functest/utils/openstack/nova.py deleted file mode 100644 index f966468a..00000000 --- a/functest/utils/openstack/nova.py +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env python -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -# diff --git a/functest/utils/openstack_clean.py b/functest/utils/openstack_clean.py index ce61fcac..29106d9e 100755 --- a/functest/utils/openstack_clean.py +++ b/functest/utils/openstack_clean.py @@ -24,13 +24,13 @@ import time +import logging import yaml -import functest.utils.functest_logger as ft_logger import functest.utils.openstack_utils as os_utils from functest.utils.constants import CONST -logger = ft_logger.Logger("openstack_clean").getLogger() +logger = logging.getLogger(__name__) OS_SNAPSHOT_FILE = CONST.openstack_snapshot_file @@ -428,4 +428,5 @@ def main(): if __name__ == '__main__': + logging.basicConfig() main() diff --git a/functest/utils/openstack_snapshot.py b/functest/utils/openstack_snapshot.py index e64030f7..952fb7bb 100755 --- a/functest/utils/openstack_snapshot.py +++ b/functest/utils/openstack_snapshot.py @@ -20,13 +20,13 @@ # http://www.apache.org/licenses/LICENSE-2.0 # +import logging import yaml -import functest.utils.functest_logger as ft_logger import functest.utils.openstack_utils as os_utils from functest.utils.constants import CONST -logger = ft_logger.Logger("openstack_snapshot").getLogger() +logger = logging.getLogger(__name__) OS_SNAPSHOT_FILE = CONST.openstack_snapshot_file @@ -162,4 +162,5 @@ def main(): if __name__ == '__main__': + logging.basicConfig() main() diff --git a/functest/utils/openstack_tacker.py b/functest/utils/openstack_tacker.py index 8327fdbe..9fd9d5c4 100644 --- a/functest/utils/openstack_tacker.py +++ b/functest/utils/openstack_tacker.py @@ -11,13 +11,13 @@ # http://www.apache.org/licenses/LICENSE-2.0 ########################################################################## +import logging from tackerclient.v1_0 import client as tackerclient -import functest.utils.functest_logger as ft_logger import functest.utils.openstack_utils as os_utils import time -logger = ft_logger.Logger("tacker_utils").getLogger() +logger = logging.getLogger(__name__) def get_tacker_client(other_creds={}): diff --git a/functest/utils/openstack_utils.py b/functest/utils/openstack_utils.py index 929a761e..8bd95052 100644 --- a/functest/utils/openstack_utils.py +++ b/functest/utils/openstack_utils.py @@ -8,7 +8,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 # -import os +import logging import os.path import re import sys @@ -23,10 +23,9 @@ from novaclient import client as novaclient from keystoneclient import client as keystoneclient from neutronclient.neutron import client as neutronclient -import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as ft_utils -logger = ft_logger.Logger("openstack_utils").getLogger() +logger = logging.getLogger(__name__) DEFAULT_API_VERSION = '2' DEFAULT_HEAT_API_VERSION = '1' @@ -139,11 +138,11 @@ def get_credentials_for_rally(): endpoint_types = [('internalURL', 'internal'), ('publicURL', 'public'), ('adminURL', 'admin')] - endpoint_type = os.getenv('OS_ENDPOINT_TYPE') + endpoint_type = get_endpoint_type_from_env() if endpoint_type is not None: cred_key = env_cred_dict.get('OS_ENDPOINT_TYPE') for k, v in endpoint_types: - if endpoint_type == k: + if endpoint_type == v: rally_conf[cred_key] = v region_name = os.getenv('OS_REGION_NAME') @@ -158,6 +157,14 @@ def get_credentials_for_rally(): return rally_conf +def get_endpoint_type_from_env(): + endpoint_type = os.environ.get("OS_ENDPOINT_TYPE", + os.environ.get("OS_INTERFACE")) + if endpoint_type and "URL" in endpoint_type: + endpoint_type = endpoint_type.replace("URL", "") + return endpoint_type + + def get_session_auth(other_creds={}): loader = loading.get_plugin_loader('password') creds = get_credentials(other_creds) @@ -198,7 +205,9 @@ def get_keystone_client_version(): def get_keystone_client(other_creds={}): sess = get_session(other_creds) - return keystoneclient.Client(get_keystone_client_version(), session=sess) + return keystoneclient.Client(get_keystone_client_version(), + session=sess, + interface=os.getenv('OS_INTERFACE', 'admin')) def get_nova_client_version(): @@ -277,7 +286,7 @@ def get_instances(nova_client): try: instances = nova_client.servers.list(search_opts={'all_tenants': 1}) return instances - except Exception, e: + except Exception as e: logger.error("Error [get_instances(nova_client)]: %s" % e) return None @@ -286,7 +295,7 @@ def get_instance_status(nova_client, instance): try: instance = nova_client.servers.get(instance.id) return instance.status - except Exception, e: + except Exception as e: logger.error("Error [get_instance_status(nova_client)]: %s" % e) return None @@ -295,7 +304,7 @@ def get_instance_by_name(nova_client, instance_name): try: instance = nova_client.servers.find(name=instance_name) return instance - except Exception, e: + except Exception as e: logger.error("Error [get_instance_by_name(nova_client, '%s')]: %s" % (instance_name, e)) return None @@ -325,7 +334,7 @@ def get_aggregates(nova_client): try: aggregates = nova_client.aggregates.list() return aggregates - except Exception, e: + except Exception as e: logger.error("Error [get_aggregates(nova_client)]: %s" % e) return None @@ -335,7 +344,7 @@ def get_aggregate_id(nova_client, aggregate_name): aggregates = get_aggregates(nova_client) _id = [ag.id for ag in aggregates if ag.name == aggregate_name][0] return _id - except Exception, e: + except Exception as e: logger.error("Error [get_aggregate_id(nova_client, %s)]:" " %s" % (aggregate_name, e)) return None @@ -345,7 +354,7 @@ def get_availability_zones(nova_client): try: availability_zones = nova_client.availability_zones.list() return availability_zones - except Exception, e: + except Exception as e: logger.error("Error [get_availability_zones(nova_client)]: %s" % e) return None @@ -354,7 +363,7 @@ def get_availability_zone_names(nova_client): try: az_names = [az.zoneName for az in get_availability_zones(nova_client)] return az_names - except Exception, e: + except Exception as e: logger.error("Error [get_availability_zone_names(nova_client)]:" " %s" % e) return None @@ -372,7 +381,7 @@ def create_flavor(nova_client, flavor_name, ram, disk, vcpus, public=True): # flavor extra specs are not configured, therefore skip the update pass - except Exception, e: + except Exception as e: logger.error("Error [create_flavor(nova_client, '%s', '%s', '%s', " "'%s')]: %s" % (flavor_name, ram, disk, vcpus, e)) return None @@ -405,7 +414,7 @@ def get_floating_ips(nova_client): try: floating_ips = nova_client.floating_ips.list() return floating_ips - except Exception, e: + except Exception as e: logger.error("Error [get_floating_ips(nova_client)]: %s" % e) return None @@ -418,7 +427,7 @@ def get_hypervisors(nova_client): if hypervisor.state == "up": nodes.append(hypervisor.hypervisor_hostname) return nodes - except Exception, e: + except Exception as e: logger.error("Error [get_hypervisors(nova_client)]: %s" % e) return None @@ -427,7 +436,7 @@ def create_aggregate(nova_client, aggregate_name, av_zone): try: nova_client.aggregates.create(aggregate_name, av_zone) return True - except Exception, e: + except Exception as e: logger.error("Error [create_aggregate(nova_client, %s, %s)]: %s" % (aggregate_name, av_zone, e)) return None @@ -438,7 +447,7 @@ def add_host_to_aggregate(nova_client, aggregate_name, compute_host): aggregate_id = get_aggregate_id(nova_client, aggregate_name) nova_client.aggregates.add_host(aggregate_id, compute_host) return True - except Exception, e: + except Exception as e: logger.error("Error [add_host_to_aggregate(nova_client, %s, %s)]: %s" % (aggregate_name, compute_host, e)) return None @@ -450,7 +459,7 @@ def create_aggregate_with_host( create_aggregate(nova_client, aggregate_name, av_zone) add_host_to_aggregate(nova_client, aggregate_name, compute_host) return True - except Exception, e: + except Exception as e: logger.error("Error [create_aggregate_with_host(" "nova_client, %s, %s, %s)]: %s" % (aggregate_name, av_zone, compute_host, e)) @@ -543,7 +552,7 @@ def create_floating_ip(neutron_client): ip_json = neutron_client.create_floatingip({'floatingip': props}) fip_addr = ip_json['floatingip']['floating_ip_address'] fip_id = ip_json['floatingip']['id'] - except Exception, e: + except Exception as e: logger.error("Error [create_floating_ip(neutron_client)]: %s" % e) return None return {'fip_addr': fip_addr, 'fip_id': fip_id} @@ -553,7 +562,7 @@ def add_floating_ip(nova_client, server_id, floatingip_addr): try: nova_client.servers.add_floating_ip(server_id, floatingip_addr) return True - except Exception, e: + except Exception as e: logger.error("Error [add_floating_ip(nova_client, '%s', '%s')]: %s" % (server_id, floatingip_addr, e)) return False @@ -563,7 +572,7 @@ def delete_instance(nova_client, instance_id): try: nova_client.servers.force_delete(instance_id) return True - except Exception, e: + except Exception as e: logger.error("Error [delete_instance(nova_client, '%s')]: %s" % (instance_id, e)) return False @@ -573,7 +582,7 @@ def delete_floating_ip(nova_client, floatingip_id): try: nova_client.floating_ips.delete(floatingip_id) return True - except Exception, e: + except Exception as e: logger.error("Error [delete_floating_ip(nova_client, '%s')]: %s" % (floatingip_id, e)) return False @@ -584,7 +593,7 @@ def remove_host_from_aggregate(nova_client, aggregate_name, compute_host): aggregate_id = get_aggregate_id(nova_client, aggregate_name) nova_client.aggregates.remove_host(aggregate_id, compute_host) return True - except Exception, e: + except Exception as e: logger.error("Error [remove_host_from_aggregate(nova_client, %s, %s)]:" " %s" % (aggregate_name, compute_host, e)) return False @@ -603,7 +612,7 @@ def delete_aggregate(nova_client, aggregate_name): remove_hosts_from_aggregate(nova_client, aggregate_name) nova_client.aggregates.delete(aggregate_name) return True - except Exception, e: + except Exception as e: logger.error("Error [delete_aggregate(nova_client, %s)]: %s" % (aggregate_name, e)) return False @@ -706,7 +715,7 @@ def create_neutron_net(neutron_client, name): network = neutron_client.create_network(body=json_body) network_dict = network['network'] return network_dict['id'] - except Exception, e: + except Exception as e: logger.error("Error [create_neutron_net(neutron_client, '%s')]: %s" % (name, e)) return None @@ -718,7 +727,7 @@ def create_neutron_subnet(neutron_client, name, cidr, net_id): try: subnet = neutron_client.create_subnet(body=json_body) return subnet['subnets'][0]['id'] - except Exception, e: + except Exception as e: logger.error("Error [create_neutron_subnet(neutron_client, '%s', " "'%s', '%s')]: %s" % (name, cidr, net_id, e)) return None @@ -729,7 +738,7 @@ def create_neutron_router(neutron_client, name): try: router = neutron_client.create_router(json_body) return router['router']['id'] - except Exception, e: + except Exception as e: logger.error("Error [create_neutron_router(neutron_client, '%s')]: %s" % (name, e)) return None @@ -745,7 +754,7 @@ def create_neutron_port(neutron_client, name, network_id, ip): try: port = neutron_client.create_port(body=json_body) return port['port']['id'] - except Exception, e: + except Exception as e: logger.error("Error [create_neutron_port(neutron_client, '%s', '%s', " "'%s')]: %s" % (name, network_id, ip, e)) return None @@ -756,7 +765,7 @@ def update_neutron_net(neutron_client, network_id, shared=False): try: neutron_client.update_network(network_id, body=json_body) return True - except Exception, e: + except Exception as e: logger.error("Error [update_neutron_net(neutron_client, '%s', '%s')]: " "%s" % (network_id, str(shared), e)) return False @@ -770,7 +779,7 @@ def update_neutron_port(neutron_client, port_id, device_owner): port = neutron_client.update_port(port=port_id, body=json_body) return port['port']['id'] - except Exception, e: + except Exception as e: logger.error("Error [update_neutron_port(neutron_client, '%s', '%s')]:" " %s" % (port_id, device_owner, e)) return None @@ -781,7 +790,7 @@ def add_interface_router(neutron_client, router_id, subnet_id): try: neutron_client.add_interface_router(router=router_id, body=json_body) return True - except Exception, e: + except Exception as e: logger.error("Error [add_interface_router(neutron_client, '%s', " "'%s')]: %s" % (router_id, subnet_id, e)) return False @@ -793,7 +802,7 @@ def add_gateway_router(neutron_client, router_id): try: neutron_client.add_gateway_router(router_id, router_dict) return True - except Exception, e: + except Exception as e: logger.error("Error [add_gateway_router(neutron_client, '%s')]: %s" % (router_id, e)) return False @@ -803,7 +812,7 @@ def delete_neutron_net(neutron_client, network_id): try: neutron_client.delete_network(network_id) return True - except Exception, e: + except Exception as e: logger.error("Error [delete_neutron_net(neutron_client, '%s')]: %s" % (network_id, e)) return False @@ -813,7 +822,7 @@ def delete_neutron_subnet(neutron_client, subnet_id): try: neutron_client.delete_subnet(subnet_id) return True - except Exception, e: + except Exception as e: logger.error("Error [delete_neutron_subnet(neutron_client, '%s')]: %s" % (subnet_id, e)) return False @@ -823,7 +832,7 @@ def delete_neutron_router(neutron_client, router_id): try: neutron_client.delete_router(router=router_id) return True - except Exception, e: + except Exception as e: logger.error("Error [delete_neutron_router(neutron_client, '%s')]: %s" % (router_id, e)) return False @@ -833,7 +842,7 @@ def delete_neutron_port(neutron_client, port_id): try: neutron_client.delete_port(port_id) return True - except Exception, e: + except Exception as e: logger.error("Error [delete_neutron_port(neutron_client, '%s')]: %s" % (port_id, e)) return False @@ -845,7 +854,7 @@ def remove_interface_router(neutron_client, router_id, subnet_id): neutron_client.remove_interface_router(router=router_id, body=json_body) return True - except Exception, e: + except Exception as e: logger.error("Error [remove_interface_router(neutron_client, '%s', " "'%s')]: %s" % (router_id, subnet_id, e)) return False @@ -855,7 +864,7 @@ def remove_gateway_router(neutron_client, router_id): try: neutron_client.remove_gateway_router(router_id) return True - except Exception, e: + except Exception as e: logger.error("Error [remove_gateway_router(neutron_client, '%s')]: %s" % (router_id, e)) return False @@ -985,7 +994,7 @@ def get_security_groups(neutron_client): security_groups = neutron_client.list_security_groups()[ 'security_groups'] return security_groups - except Exception, e: + except Exception as e: logger.error("Error [get_security_groups(neutron_client)]: %s" % e) return None @@ -1006,7 +1015,7 @@ def create_security_group(neutron_client, sg_name, sg_description): try: secgroup = neutron_client.create_security_group(json_body) return secgroup['security_group'] - except Exception, e: + except Exception as e: logger.error("Error [create_security_group(neutron_client, '%s', " "'%s')]: %s" % (sg_name, sg_description, e)) return None @@ -1061,7 +1070,7 @@ def get_security_group_rules(neutron_client, sg_id): security_rules = [rule for rule in security_rules if rule["security_group_id"] == sg_id] return security_rules - except Exception, e: + except Exception as e: logger.error("Error [get_security_group_rules(neutron_client, sg_id)]:" " %s" % e) return None @@ -1080,7 +1089,7 @@ def check_security_group_rules(neutron_client, sg_id, direction, protocol, return True else: return False - except Exception, e: + except Exception as e: logger.error("Error [check_security_group_rules(" " neutron_client, sg_id, direction," " protocol, port_min=None, port_max=None)]: " @@ -1132,7 +1141,7 @@ def add_secgroup_to_instance(nova_client, instance_id, secgroup_id): try: nova_client.servers.add_security_group(instance_id, secgroup_id) return True - except Exception, e: + except Exception as e: logger.error("Error [add_secgroup_to_instance(nova_client, '%s', " "'%s')]: %s" % (instance_id, secgroup_id, e)) return False @@ -1148,7 +1157,7 @@ def update_sg_quota(neutron_client, tenant_id, sg_quota, sg_rule_quota): neutron_client.update_quota(tenant_id=tenant_id, body=json_body) return True - except Exception, e: + except Exception as e: logger.error("Error [update_sg_quota(neutron_client, '%s', '%s', " "'%s')]: %s" % (tenant_id, sg_quota, sg_rule_quota, e)) return False @@ -1158,7 +1167,7 @@ def delete_security_group(neutron_client, secgroup_id): try: neutron_client.delete_security_group(secgroup_id) return True - except Exception, e: + except Exception as e: logger.error("Error [delete_security_group(neutron_client, '%s')]: %s" % (secgroup_id, e)) return False @@ -1171,7 +1180,7 @@ def get_images(nova_client): try: images = nova_client.images.list() return images - except Exception, e: + except Exception as e: logger.error("Error [get_images]: %s" % e) return None @@ -1207,7 +1216,7 @@ def create_glance_image(glance_client, image_name, file_path, disk="qcow2", with open(file_path) as image_data: glance_client.images.upload(image_id, image_data) return image_id - except Exception, e: + except Exception as e: logger.error("Error [create_glance_image(glance_client, '%s', '%s', " "'%s')]: %s" % (image_name, file_path, public, e)) return None @@ -1237,7 +1246,7 @@ def delete_glance_image(nova_client, image_id): try: nova_client.images.delete(image_id) return True - except Exception, e: + except Exception as e: logger.error("Error [delete_glance_image(nova_client, '%s')]: %s" % (image_id, e)) return False @@ -1250,7 +1259,7 @@ def get_volumes(cinder_client): try: volumes = cinder_client.volumes.list(search_opts={'all_tenants': 1}) return volumes - except Exception, e: + except Exception as e: logger.error("Error [get_volumes(cinder_client)]: %s" % e) return None @@ -1263,7 +1272,7 @@ def list_volume_types(cinder_client, public=True, private=True): if not private: volume_types = [vt for vt in volume_types if vt.is_public] return volume_types - except Exception, e: + except Exception as e: logger.error("Error [list_volume_types(cinder_client)]: %s" % e) return None @@ -1272,7 +1281,7 @@ def create_volume_type(cinder_client, name): try: volume_type = cinder_client.volume_types.create(name) return volume_type - except Exception, e: + except Exception as e: logger.error("Error [create_volume_type(cinder_client, '%s')]: %s" % (name, e)) return None @@ -1287,7 +1296,7 @@ def update_cinder_quota(cinder_client, tenant_id, vols_quota, try: cinder_client.quotas.update(tenant_id, **quotas_values) return True - except Exception, e: + except Exception as e: logger.error("Error [update_cinder_quota(cinder_client, '%s', '%s', " "'%s' '%s')]: %s" % (tenant_id, vols_quota, snapshots_quota, gigabytes_quota, e)) @@ -1305,7 +1314,7 @@ def delete_volume(cinder_client, volume_id, forced=False): else: cinder_client.volumes.delete(volume_id) return True - except Exception, e: + except Exception as e: logger.error("Error [delete_volume(cinder_client, '%s', '%s')]: %s" % (volume_id, str(forced), e)) return False @@ -1315,7 +1324,7 @@ def delete_volume_type(cinder_client, volume_type): try: cinder_client.volume_types.delete(volume_type) return True - except Exception, e: + except Exception as e: logger.error("Error [delete_volume_type(cinder_client, '%s')]: %s" % (volume_type, e)) return False @@ -1331,7 +1340,7 @@ def get_tenants(keystone_client): else: tenants = keystone_client.tenants.list() return tenants - except Exception, e: + except Exception as e: logger.error("Error [get_tenants(keystone_client)]: %s" % e) return None @@ -1340,7 +1349,7 @@ def get_users(keystone_client): try: users = keystone_client.users.list() return users - except Exception, e: + except Exception as e: logger.error("Error [get_users(keystone_client)]: %s" % e) return None @@ -1388,7 +1397,7 @@ def create_tenant(keystone_client, tenant_name, tenant_description): tenant_description, enabled=True) return tenant.id - except Exception, e: + except Exception as e: logger.error("Error [create_tenant(keystone_client, '%s', '%s')]: %s" % (tenant_name, tenant_description, e)) return None @@ -1419,7 +1428,7 @@ def create_user(keystone_client, user_name, user_password, tenant_id, enabled=True) return user.id - except Exception, e: + except Exception as e: logger.error("Error [create_user(keystone_client, '%s', '%s', '%s'" "'%s')]: %s" % (user_name, user_password, user_email, tenant_id, e)) @@ -1444,7 +1453,7 @@ def add_role_user(keystone_client, user_id, role_id, tenant_id): else: keystone_client.roles.add_user_role(user_id, role_id, tenant_id) return True - except Exception, e: + except Exception as e: logger.error("Error [add_role_user(keystone_client, '%s', '%s'" "'%s')]: %s " % (user_id, role_id, tenant_id, e)) return False @@ -1457,7 +1466,7 @@ def delete_tenant(keystone_client, tenant_id): else: keystone_client.tenants.delete(tenant_id) return True - except Exception, e: + except Exception as e: logger.error("Error [delete_tenant(keystone_client, '%s')]: %s" % (tenant_id, e)) return False @@ -1467,7 +1476,7 @@ def delete_user(keystone_client, user_id): try: keystone_client.users.delete(user_id) return True - except Exception, e: + except Exception as e: logger.error("Error [delete_user(keystone_client, '%s')]: %s" % (user_id, e)) return False @@ -1480,6 +1489,6 @@ def get_resource(heat_client, stack_id, resource): try: resources = heat_client.resources.get(stack_id, resource) return resources - except Exception, e: + except Exception as e: logger.error("Error [get_resource]: %s" % e) return None |