diff options
-rwxr-xr-x | ci/run_tests.py | 1 | ||||
-rwxr-xr-x | testcases/OpenStack/rally/run_rally-cert.py | 84 | ||||
-rwxr-xr-x | testcases/OpenStack/tempest/run_tempest.py | 28 | ||||
-rwxr-xr-x | testcases/OpenStack/vPing/vPing_ssh.py | 93 | ||||
-rwxr-xr-x | testcases/OpenStack/vPing/vPing_userdata.py | 80 | ||||
-rwxr-xr-x | utils/openstack_clean.py | 33 | ||||
-rwxr-xr-x | utils/openstack_snapshot.py | 26 | ||||
-rw-r--r-- | utils/openstack_utils.py | 10 |
8 files changed, 140 insertions, 215 deletions
diff --git a/ci/run_tests.py b/ci/run_tests.py index 29b01d7ff..050ef0c11 100755 --- a/ci/run_tests.py +++ b/ci/run_tests.py @@ -62,7 +62,6 @@ def source_rc_file(): def generate_os_snapshot(): - logger.debug("Generating OpenStack snapshot...") os_snapshot.main() diff --git a/testcases/OpenStack/rally/run_rally-cert.py b/testcases/OpenStack/rally/run_rally-cert.py index 47b826d6c..c4804739b 100755 --- a/testcases/OpenStack/rally/run_rally-cert.py +++ b/testcases/OpenStack/rally/run_rally-cert.py @@ -13,26 +13,21 @@ # 0.3 (19/10/2015) remove Tempest from run_rally # and push result into test DB # +""" tests configuration """ + import argparse -import iniparse import json import os import re import subprocess import time -import yaml - -from novaclient import client as novaclient -from glanceclient import client as glanceclient -from keystoneclient.v2_0 import client as keystoneclient -from neutronclient.v2_0 import client as neutronclient -from cinderclient import client as cinderclient - import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as functest_utils -import functest.utils.openstack_utils as openstack_utils +import functest.utils.openstack_utils as os_utils +import iniparse +import yaml + -""" tests configuration """ tests = ['authenticate', 'glance', 'cinder', 'heat', 'keystone', 'neutron', 'nova', 'quotas', 'requests', 'vm', 'all'] parser = argparse.ArgumentParser() @@ -65,7 +60,6 @@ parser.add_argument("-z", "--sanity", args = parser.parse_args() -client_dict = {} network_dict = {} if args.verbose: @@ -122,6 +116,7 @@ CINDER_VOLUME_TYPE_NAME = "volume_test" SUMMARY = [] +neutron_client = None def get_task_id(cmd_raw): @@ -187,7 +182,7 @@ def build_task_args(test_file_name): task_args['full_mode'] = True task_args['smoke'] = args.smoke - ext_net = openstack_utils.get_external_net(client_dict['neutron']) + ext_net = os_utils.get_external_net(neutron_client) if ext_net: task_args['floating_network'] = str(ext_net) else: @@ -378,6 +373,13 @@ def run_task(test_name): def main(): global SUMMARY global network_dict + global neutron_client + + nova_client = os_utils.get_nova_client() + neutron_client = os_utils.get_neutron_client() + glance_client = os_utils.get_glance_client() + cinder_client = os_utils.get_cinder_client() + start_time = time.time() stop_time = start_time @@ -387,29 +389,11 @@ def main(): exit(-1) SUMMARY = [] - creds_nova = openstack_utils.get_credentials("nova") - nova_client = novaclient.Client('2', **creds_nova) - creds_neutron = openstack_utils.get_credentials("neutron") - neutron_client = neutronclient.Client(**creds_neutron) - creds_keystone = openstack_utils.get_credentials("keystone") - keystone_client = keystoneclient.Client(**creds_keystone) - glance_endpoint = keystone_client.service_catalog.url_for( - service_type='image', endpoint_type='publicURL') - glance_client = glanceclient.Client(1, glance_endpoint, - token=keystone_client.auth_token) - creds_cinder = openstack_utils.get_credentials("cinder") - cinder_client = cinderclient.Client('2', creds_cinder['username'], - creds_cinder['api_key'], - creds_cinder['project_id'], - creds_cinder['auth_url'], - service_type="volume") - - client_dict['neutron'] = neutron_client - - volume_types = openstack_utils.list_volume_types(cinder_client, - private=False) + + volume_types = os_utils.list_volume_types(cinder_client, + private=False) if not volume_types: - volume_type = openstack_utils.create_volume_type( + volume_type = os_utils.create_volume_type( cinder_client, CINDER_VOLUME_TYPE_NAME) if not volume_type: logger.error("Failed to create volume type...") @@ -420,15 +404,15 @@ def main(): else: logger.debug("Using existing volume type(s)...") - image_id = openstack_utils.get_image_id(glance_client, GLANCE_IMAGE_NAME) + image_id = os_utils.get_image_id(glance_client, GLANCE_IMAGE_NAME) image_exists = False if image_id == '': logger.debug("Creating image '%s' from '%s'..." % (GLANCE_IMAGE_NAME, GLANCE_IMAGE_PATH)) - image_id = openstack_utils.create_glance_image(glance_client, - GLANCE_IMAGE_NAME, - GLANCE_IMAGE_PATH) + image_id = os_utils.create_glance_image(glance_client, + GLANCE_IMAGE_NAME, + GLANCE_IMAGE_PATH) if not image_id: logger.error("Failed to create the Glance image...") exit(-1) @@ -441,19 +425,19 @@ def main(): image_exists = True logger.debug("Creating network '%s'..." % PRIVATE_NET_NAME) - network_dict = openstack_utils.create_network_full(logger, - client_dict['neutron'], - PRIVATE_NET_NAME, - PRIVATE_SUBNET_NAME, - ROUTER_NAME, - PRIVATE_SUBNET_CIDR) + network_dict = os_utils.create_network_full(logger, + neutron_client, + PRIVATE_NET_NAME, + PRIVATE_SUBNET_NAME, + ROUTER_NAME, + PRIVATE_SUBNET_CIDR) if not network_dict: logger.error("Failed to create network...") exit(-1) else: - if not openstack_utils.update_neutron_net(client_dict['neutron'], - network_dict['net_id'], - shared=True): + if not os_utils.update_neutron_net(neutron_client, + network_dict['net_id'], + shared=True): logger.error("Failed to update network...") exit(-1) else: @@ -555,13 +539,13 @@ def main(): if not image_exists: logger.debug("Deleting image '%s' with ID '%s'..." % (GLANCE_IMAGE_NAME, image_id)) - if not openstack_utils.delete_glance_image(nova_client, image_id): + if not os_utils.delete_glance_image(nova_client, image_id): logger.error("Error deleting the glance image") if not volume_types: logger.debug("Deleting volume type '%s'..." % CINDER_VOLUME_TYPE_NAME) - if not openstack_utils.delete_volume_type(cinder_client, volume_type): + if not os_utils.delete_volume_type(cinder_client, volume_type): logger.error("Error in deleting volume type...") diff --git a/testcases/OpenStack/tempest/run_tempest.py b/testcases/OpenStack/tempest/run_tempest.py index ab79a8768..c773091bb 100755 --- a/testcases/OpenStack/tempest/run_tempest.py +++ b/testcases/OpenStack/tempest/run_tempest.py @@ -13,6 +13,7 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 # +import ConfigParser import argparse import os import re @@ -20,16 +21,12 @@ import shutil import subprocess import sys import time -import yaml -import ConfigParser - -import keystoneclient.v2_0.client as ksclient -from glanceclient import client as glanceclient -from neutronclient.v2_0 import client as neutronclient import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as ft_utils import functest.utils.openstack_utils as os_utils +import yaml + modes = ['full', 'smoke', 'baremetal', 'compute', 'data_processing', 'identity', 'image', 'network', 'object_storage', 'orchestration', @@ -123,23 +120,24 @@ def get_info(file_result): def create_tempest_resources(): - ks_creds = os_utils.get_credentials("keystone") + + keystone_client = os_utils.get_keystone_client() + neutron_client = os_utils.get_neutron_client() + glance_client = os_utils.get_glance_client() + logger.debug("Creating tenant and user for Tempest suite") - keystone = ksclient.Client(**ks_creds) - tenant_id = os_utils.create_tenant(keystone, + tenant_id = os_utils.create_tenant(keystone_client, TENANT_NAME, TENANT_DESCRIPTION) if tenant_id == '': logger.error("Error : Failed to create %s tenant" % TENANT_NAME) - user_id = os_utils.create_user(keystone, USER_NAME, USER_PASSWORD, + user_id = os_utils.create_user(keystone_client, USER_NAME, USER_PASSWORD, None, tenant_id) if user_id == '': logger.error("Error : Failed to create %s user" % USER_NAME) logger.debug("Creating private network for Tempest suite") - creds_neutron = os_utils.get_credentials("neutron") - neutron_client = neutronclient.Client(**creds_neutron) network_dic = os_utils.create_network_full(logger, neutron_client, PRIVATE_NET_NAME, @@ -159,10 +157,6 @@ def create_tempest_resources(): exit(-1) logger.debug("Creating image for Tempest suite") - glance_endpoint = keystone.service_catalog.url_for( - service_type='image', endpoint_type='publicURL') - glance_client = glanceclient.Client(1, glance_endpoint, - token=keystone.auth_token) # Check if the given image exists image_id = os_utils.get_image_id(glance_client, GLANCE_IMAGE_NAME) if image_id != '': @@ -367,7 +361,7 @@ def run_tempest(OPTION): error_logs = "" for match in re.findall('(.*?)[. ]*FAILED', output): - error_logs += match + error_logs += match # Generate json results for DB json_results = {"timestart": time_start, "duration": dur_sec_int, diff --git a/testcases/OpenStack/vPing/vPing_ssh.py b/testcases/OpenStack/vPing/vPing_ssh.py index 1609dd95b..2ef2dfc10 100755 --- a/testcases/OpenStack/vPing/vPing_ssh.py +++ b/testcases/OpenStack/vPing/vPing_ssh.py @@ -16,22 +16,17 @@ import argparse import datetime import os -import paramiko import pprint import re import sys import time -import yaml -from scp import SCPClient - -from novaclient import client as novaclient -from neutronclient.v2_0 import client as neutronclient -from keystoneclient.v2_0 import client as keystoneclient -from glanceclient import client as glanceclient - import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as functest_utils -import functest.utils.openstack_utils as openstack_utils +import functest.utils.openstack_utils as os_utils +import paramiko +from scp import SCPClient +import yaml + pp = pprint.PrettyPrinter(indent=4) @@ -93,7 +88,6 @@ SECGROUP_DESCR = functest_yaml.get("vping").get("vping_sg_descr") def pMsg(value): - """pretty printing""" pp.pprint(value) @@ -104,7 +98,7 @@ def waitVmActive(nova, vm): sleep_time = 3 count = VM_BOOT_TIMEOUT / sleep_time while True: - status = openstack_utils.get_instance_status(nova, vm) + status = os_utils.get_instance_status(nova, vm) logger.debug("Status: %s" % status) if status == "ACTIVE": return True @@ -124,7 +118,7 @@ def waitVmDeleted(nova, vm): sleep_time = 3 count = VM_DELETE_TIMEOUT / sleep_time while True: - status = openstack_utils.get_instance_status(nova, vm) + status = os_utils.get_instance_status(nova, vm) if not status: return True elif count == 0: @@ -138,15 +132,15 @@ def waitVmDeleted(nova, vm): def create_security_group(neutron_client): - sg_id = openstack_utils.get_security_group_id(neutron_client, - SECGROUP_NAME) + sg_id = os_utils.get_security_group_id(neutron_client, + SECGROUP_NAME) if sg_id != '': logger.info("Using existing security group '%s'..." % SECGROUP_NAME) else: logger.info("Creating security group '%s'..." % SECGROUP_NAME) - SECGROUP = openstack_utils.create_security_group(neutron_client, - SECGROUP_NAME, - SECGROUP_DESCR) + SECGROUP = os_utils.create_security_group(neutron_client, + SECGROUP_NAME, + SECGROUP_DESCR) if not SECGROUP: logger.error("Failed to create the security group...") return False @@ -158,19 +152,19 @@ def create_security_group(neutron_client): logger.debug("Adding ICMP rules in security group '%s'..." % SECGROUP_NAME) - if not openstack_utils.create_secgroup_rule(neutron_client, sg_id, - 'ingress', 'icmp'): + if not os_utils.create_secgroup_rule(neutron_client, sg_id, + 'ingress', 'icmp'): logger.error("Failed to create the security group rule...") return False logger.debug("Adding SSH rules in security group '%s'..." % SECGROUP_NAME) - if not openstack_utils.create_secgroup_rule( + if not os_utils.create_secgroup_rule( neutron_client, sg_id, 'ingress', 'tcp', '22', '22'): logger.error("Failed to create the security group rule...") return False - if not openstack_utils.create_secgroup_rule( + if not os_utils.create_secgroup_rule( neutron_client, sg_id, 'egress', 'tcp', '22', '22'): logger.error("Failed to create the security group rule...") return False @@ -178,24 +172,17 @@ def create_security_group(neutron_client): def main(): + nova_client = os_utils.get_nova_client() + neutron_client = os_utils.get_neutron_client() + glance_client = os_utils.get_glance_client() - creds_nova = openstack_utils.get_credentials("nova") - nova_client = novaclient.Client('2', **creds_nova) - creds_neutron = openstack_utils.get_credentials("neutron") - neutron_client = neutronclient.Client(**creds_neutron) - creds_keystone = openstack_utils.get_credentials("keystone") - keystone_client = keystoneclient.Client(**creds_keystone) - glance_endpoint = keystone_client.service_catalog.url_for( - service_type='image', endpoint_type='publicURL') - glance_client = glanceclient.Client(1, glance_endpoint, - token=keystone_client.auth_token) EXIT_CODE = -1 image_id = None flavor = None # Check if the given image exists - image_id = openstack_utils.get_image_id(glance_client, GLANCE_IMAGE_NAME) + image_id = os_utils.get_image_id(glance_client, GLANCE_IMAGE_NAME) if image_id != '': logger.info("Using existing image '%s'..." % GLANCE_IMAGE_NAME) global image_exists @@ -203,21 +190,21 @@ def main(): else: logger.info("Creating image '%s' from '%s'..." % (GLANCE_IMAGE_NAME, GLANCE_IMAGE_PATH)) - image_id = openstack_utils.create_glance_image(glance_client, - GLANCE_IMAGE_NAME, - GLANCE_IMAGE_PATH) + image_id = os_utils.create_glance_image(glance_client, + GLANCE_IMAGE_NAME, + GLANCE_IMAGE_PATH) if not image_id: logger.error("Failed to create a Glance image...") return(EXIT_CODE) logger.debug("Image '%s' with ID=%s created successfully." % (GLANCE_IMAGE_NAME, image_id)) - network_dic = openstack_utils.create_network_full(logger, - neutron_client, - PRIVATE_NET_NAME, - PRIVATE_SUBNET_NAME, - ROUTER_NAME, - PRIVATE_SUBNET_CIDR) + network_dic = os_utils.create_network_full(logger, + neutron_client, + PRIVATE_NET_NAME, + PRIVATE_SUBNET_NAME, + ROUTER_NAME, + PRIVATE_SUBNET_CIDR) if not network_dic: logger.error( "There has been a problem when creating the neutron network") @@ -265,7 +252,7 @@ def main(): # wait until VM status is active if not waitVmActive(nova_client, vm1): logger.error("Instance '%s' cannot be booted. Status is '%s'" % ( - NAME_VM_1, openstack_utils.get_instance_status(nova_client, vm1))) + NAME_VM_1, os_utils.get_instance_status(nova_client, vm1))) return (EXIT_CODE) else: logger.info("Instance '%s' is ACTIVE." % NAME_VM_1) @@ -276,7 +263,7 @@ def main(): logger.info("Adding '%s' to security group '%s'..." % (NAME_VM_1, SECGROUP_NAME)) - openstack_utils.add_secgroup_to_instance(nova_client, vm1.id, sg_id) + os_utils.add_secgroup_to_instance(nova_client, vm1.id, sg_id) # boot VM 2 logger.info("Creating instance '%s'..." % NAME_VM_2) @@ -292,17 +279,17 @@ def main(): if not waitVmActive(nova_client, vm2): logger.error("Instance '%s' cannot be booted. Status is '%s'" % ( - NAME_VM_2, openstack_utils.get_instance_status(nova_client, vm2))) + NAME_VM_2, os_utils.get_instance_status(nova_client, vm2))) return (EXIT_CODE) else: logger.info("Instance '%s' is ACTIVE." % NAME_VM_2) logger.info("Adding '%s' to security group '%s'..." % (NAME_VM_2, SECGROUP_NAME)) - openstack_utils.add_secgroup_to_instance(nova_client, vm2.id, sg_id) + os_utils.add_secgroup_to_instance(nova_client, vm2.id, sg_id) logger.info("Creating floating IP for VM '%s'..." % NAME_VM_2) - floatip_dic = openstack_utils.create_floating_ip(neutron_client) + floatip_dic = os_utils.create_floating_ip(neutron_client) floatip = floatip_dic['fip_addr'] # floatip_id = floatip_dic['fip_id'] @@ -313,7 +300,7 @@ def main(): logger.info("Associating floating ip: '%s' to VM '%s' " % (floatip, NAME_VM_2)) - if not openstack_utils.add_floating_ip(nova_client, vm2.id, floatip): + if not os_utils.add_floating_ip(nova_client, vm2.id, floatip): logger.error("Cannot associate floating IP to VM.") return (EXIT_CODE) @@ -358,11 +345,11 @@ def main(): # if dhcp doesnt work,it shows "No lease, failing".The test will fail if "No lease, failing" in console_log and not nolease and not got_ip: - nolease = True - logger.debug("Console-log '%s': No lease, failing..." - % NAME_VM_2) - logger.info("The instance failed to get an IP from the " - "DHCP agent. The test will probably timeout...") + nolease = True + logger.debug("Console-log '%s': No lease, failing..." + % NAME_VM_2) + logger.info("The instance failed to get an IP from the " + "DHCP agent. The test will probably timeout...") if timeout == 0: # 300 sec timeout (5 min) logger.error("Cannot establish connection to IP '%s'. Aborting" diff --git a/testcases/OpenStack/vPing/vPing_userdata.py b/testcases/OpenStack/vPing/vPing_userdata.py index cdc411948..8ea7d7905 100755 --- a/testcases/OpenStack/vPing/vPing_userdata.py +++ b/testcases/OpenStack/vPing/vPing_userdata.py @@ -21,16 +21,11 @@ import os import pprint import sys import time -import yaml - -from novaclient import client as novaclient -from neutronclient.v2_0 import client as neutronclient -from keystoneclient.v2_0 import client as keystoneclient -from glanceclient import client as glanceclient - import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as functest_utils -import functest.utils.openstack_utils as openstack_utils +import functest.utils.openstack_utils as os_utils +import yaml + pp = pprint.PrettyPrinter(indent=4) @@ -90,7 +85,6 @@ SECGROUP_DESCR = functest_yaml.get("vping").get("vping_sg_descr") def pMsg(value): - """pretty printing""" pp.pprint(value) @@ -101,7 +95,7 @@ def waitVmActive(nova, vm): sleep_time = 3 count = VM_BOOT_TIMEOUT / sleep_time while True: - status = openstack_utils.get_instance_status(nova, vm) + status = os_utils.get_instance_status(nova, vm) logger.debug("Status: %s" % status) if status == "ACTIVE": return True @@ -121,7 +115,7 @@ def waitVmDeleted(nova, vm): sleep_time = 3 count = VM_DELETE_TIMEOUT / sleep_time while True: - status = openstack_utils.get_instance_status(nova, vm) + status = os_utils.get_instance_status(nova, vm) if not status: return True elif count == 0: @@ -135,15 +129,15 @@ def waitVmDeleted(nova, vm): def create_security_group(neutron_client): - sg_id = openstack_utils.get_security_group_id(neutron_client, - SECGROUP_NAME) + sg_id = os_utils.get_security_group_id(neutron_client, + SECGROUP_NAME) if sg_id != '': logger.info("Using existing security group '%s'..." % SECGROUP_NAME) else: logger.info("Creating security group '%s'..." % SECGROUP_NAME) - SECGROUP = openstack_utils.create_security_group(neutron_client, - SECGROUP_NAME, - SECGROUP_DESCR) + SECGROUP = os_utils.create_security_group(neutron_client, + SECGROUP_NAME, + SECGROUP_DESCR) if not SECGROUP: logger.error("Failed to create the security group...") return False @@ -155,22 +149,22 @@ def create_security_group(neutron_client): logger.debug("Adding ICMP rules in security group '%s'..." % SECGROUP_NAME) - if not openstack_utils.create_secgroup_rule(neutron_client, sg_id, - 'ingress', 'icmp'): + if not os_utils.create_secgroup_rule(neutron_client, sg_id, + 'ingress', 'icmp'): logger.error("Failed to create the security group rule...") return False logger.debug("Adding SSH rules in security group '%s'..." % SECGROUP_NAME) - if not openstack_utils.create_secgroup_rule(neutron_client, sg_id, - 'ingress', 'tcp', - '22', '22'): + if not os_utils.create_secgroup_rule(neutron_client, sg_id, + 'ingress', 'tcp', + '22', '22'): logger.error("Failed to create the security group rule...") return False - if not openstack_utils.create_secgroup_rule(neutron_client, sg_id, - 'egress', 'tcp', - '22', '22'): + if not os_utils.create_secgroup_rule(neutron_client, sg_id, + 'egress', 'tcp', + '22', '22'): logger.error("Failed to create the security group rule...") return False return sg_id @@ -178,23 +172,17 @@ def create_security_group(neutron_client): def main(): - creds_nova = openstack_utils.get_credentials("nova") - nova_client = novaclient.Client('2', **creds_nova) - creds_neutron = openstack_utils.get_credentials("neutron") - neutron_client = neutronclient.Client(**creds_neutron) - creds_keystone = openstack_utils.get_credentials("keystone") - keystone_client = keystoneclient.Client(**creds_keystone) - glance_endpoint = keystone_client.service_catalog.url_for( - service_type='image', endpoint_type='publicURL') - glance_client = glanceclient.Client(1, glance_endpoint, - token=keystone_client.auth_token) + nova_client = os_utils.get_nova_client() + neutron_client = os_utils.get_neutron_client() + glance_client = os_utils.get_glance_client() + EXIT_CODE = -1 image_id = None flavor = None # Check if the given image exists - image_id = openstack_utils.get_image_id(glance_client, GLANCE_IMAGE_NAME) + image_id = os_utils.get_image_id(glance_client, GLANCE_IMAGE_NAME) if image_id != '': logger.info("Using existing image '%s'..." % GLANCE_IMAGE_NAME) global image_exists @@ -202,21 +190,21 @@ def main(): else: logger.info("Creating image '%s' from '%s'..." % (GLANCE_IMAGE_NAME, GLANCE_IMAGE_PATH)) - image_id = openstack_utils.create_glance_image(glance_client, - GLANCE_IMAGE_NAME, - GLANCE_IMAGE_PATH) + image_id = os_utils.create_glance_image(glance_client, + GLANCE_IMAGE_NAME, + GLANCE_IMAGE_PATH) if not image_id: logger.error("Failed to create a Glance image...") return(EXIT_CODE) logger.debug("Image '%s' with ID=%s created successfully." % (GLANCE_IMAGE_NAME, image_id)) - network_dic = openstack_utils.create_network_full(logger, - neutron_client, - PRIVATE_NET_NAME, - PRIVATE_SUBNET_NAME, - ROUTER_NAME, - PRIVATE_SUBNET_CIDR) + network_dic = os_utils.create_network_full(logger, + neutron_client, + PRIVATE_NET_NAME, + PRIVATE_SUBNET_NAME, + ROUTER_NAME, + PRIVATE_SUBNET_CIDR) if not network_dic: logger.error( "There has been a problem when creating the neutron network") @@ -270,7 +258,7 @@ def main(): if not waitVmActive(nova_client, vm1): logger.error("Instance '%s' cannot be booted. Status is '%s'" % ( - NAME_VM_1, openstack_utils.get_instance_status(nova_client, vm1))) + NAME_VM_1, os_utils.get_instance_status(nova_client, vm1))) return (EXIT_CODE) else: logger.info("Instance '%s' is ACTIVE." % NAME_VM_1) @@ -305,7 +293,7 @@ def main(): if not waitVmActive(nova_client, vm2): logger.error("Instance '%s' cannot be booted. Status is '%s'" % ( - NAME_VM_2, openstack_utils.get_instance_status(nova_client, vm2))) + NAME_VM_2, os_utils.get_instance_status(nova_client, vm2))) return (EXIT_CODE) else: logger.info("Instance '%s' is ACTIVE." % NAME_VM_2) diff --git a/utils/openstack_clean.py b/utils/openstack_clean.py index 3eb39a260..c266eeb35 100755 --- a/utils/openstack_clean.py +++ b/utils/openstack_clean.py @@ -20,17 +20,10 @@ # http://www.apache.org/licenses/LICENSE-2.0 # -""" logging configuration """ - import time - -from cinderclient import client as cinderclient import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as ft_utils import functest.utils.openstack_utils as os_utils -from keystoneclient.v2_0 import client as keystoneclient -from neutronclient.v2_0 import client as neutronclient -from novaclient import client as novaclient import yaml @@ -41,7 +34,7 @@ OS_SNAPSHOT_FILE = ft_utils.get_parameter_from_yaml( def separator(): - logger.info("-------------------------------------------") + logger.debug("-------------------------------------------") def remove_instances(nova_client, default_instances): @@ -360,9 +353,12 @@ def remove_tenants(keystone_client, default_tenants): def main(): - logger.info("+++++++++++++++++++++++++++++++") logger.info("Cleaning OpenStack resources...") - logger.info("+++++++++++++++++++++++++++++++") + + nova_client = os_utils.get_nova_client() + neutron_client = os_utils.get_neutron_client() + keystone_client = os_utils.get_keystone_client() + cinder_client = os_utils.get_cinder_client() try: with open(OS_SNAPSHOT_FILE) as f: @@ -382,23 +378,6 @@ def main(): default_users = snapshot_yaml.get('users') default_tenants = snapshot_yaml.get('tenants') - creds_nova = os_utils.get_credentials("nova") - nova_client = novaclient.Client('2', **creds_nova) - - creds_neutron = os_utils.get_credentials("neutron") - neutron_client = neutronclient.Client(**creds_neutron) - - creds_keystone = os_utils.get_credentials("keystone") - keystone_client = keystoneclient.Client(**creds_keystone) - - creds_cinder = os_utils.get_credentials("cinder") - # cinder_client = cinderclient.Client(**creds_cinder) - cinder_client = cinderclient.Client('1', creds_cinder['username'], - creds_cinder['api_key'], - creds_cinder['project_id'], - creds_cinder['auth_url'], - service_type="volume") - if not os_utils.check_credentials(): logger.error("Please source the openrc credentials and run " "the script again.") diff --git a/utils/openstack_snapshot.py b/utils/openstack_snapshot.py index 704ef5053..058f9ded3 100755 --- a/utils/openstack_snapshot.py +++ b/utils/openstack_snapshot.py @@ -20,17 +20,10 @@ # http://www.apache.org/licenses/LICENSE-2.0 # -""" logging configuration """ - import os - -from cinderclient import client as cinderclient import functest.utils.functest_logger as ft_logger import functest.utils.functest_utils as ft_utils import functest.utils.openstack_utils as os_utils -from keystoneclient.v2_0 import client as keystoneclient -from neutronclient.v2_0 import client as neutronclient -from novaclient import client as novaclient import yaml @@ -143,21 +136,12 @@ def get_tenants(keystone_client): def main(): - creds_nova = os_utils.get_credentials("nova") - nova_client = novaclient.Client('2', **creds_nova) - - creds_neutron = os_utils.get_credentials("neutron") - neutron_client = neutronclient.Client(**creds_neutron) - - creds_keystone = os_utils.get_credentials("keystone") - keystone_client = keystoneclient.Client(**creds_keystone) + logger.info("Generating OpenStack snapshot...") - creds_cinder = os_utils.get_credentials("cinder") - cinder_client = cinderclient.Client('1', creds_cinder['username'], - creds_cinder['api_key'], - creds_cinder['project_id'], - creds_cinder['auth_url'], - service_type="volume") + nova_client = os_utils.get_nova_client() + neutron_client = os_utils.get_neutron_client() + keystone_client = os_utils.get_keystone_client() + cinder_client = os_utils.get_cinder_client() if not os_utils.check_credentials(): logger.error("Please source the openrc credentials and run the" + diff --git a/utils/openstack_utils.py b/utils/openstack_utils.py index 2103c7fef..2af12e55f 100644 --- a/utils/openstack_utils.py +++ b/utils/openstack_utils.py @@ -14,6 +14,7 @@ import subprocess import sys import time +from cinderclient import client as cinderclient from glanceclient import client as glanceclient from keystoneclient.v2_0 import client as keystoneclient from neutronclient.v2_0 import client as neutronclient @@ -103,6 +104,15 @@ def get_nova_client(): return novaclient.Client('2', **creds_nova) +def get_cinder_client(): + creds_cinder = get_credentials("cinder") + return cinderclient.Client('2', creds_cinder['username'], + creds_cinder['api_key'], + creds_cinder['project_id'], + creds_cinder['auth_url'], + service_type="volume") + + def get_neutron_client(): creds_neutron = get_credentials("neutron") return neutronclient.Client(**creds_neutron) |