diff options
author | Stamatis Katsaounis <mokats@intracom-telecom.com> | 2018-09-14 14:07:02 +0300 |
---|---|---|
committer | Stamatis Katsaounis <mokats@intracom-telecom.com> | 2018-10-03 14:50:01 +0300 |
commit | f1c92528c528626052bf4d73dbf09e2bc9de5ad9 (patch) | |
tree | 32722f139e32ee234c01ad9067f3bb1c32cd70c7 | |
parent | 46cb9e081cb7cb64201d739f46cc1fc2fecf2a12 (diff) |
Replace glance client calls with openstack sdk
JIRA: SDNVPN-220
This patch replaces all calls of glance client with openstack sdk.
Change-Id: I8bf9913e3be9615c462791a20267e4dc71ffd727
Signed-off-by: Stamatis Katsaounis <mokats@intracom-telecom.com>
-rw-r--r-- | requirements.txt | 2 | ||||
-rw-r--r-- | sdnvpn/lib/openstack_utils.py | 58 | ||||
-rw-r--r-- | sdnvpn/lib/utils.py | 4 | ||||
-rw-r--r-- | sdnvpn/test/functest/testcase_1.py | 6 | ||||
-rw-r--r-- | sdnvpn/test/functest/testcase_10.py | 6 | ||||
-rw-r--r-- | sdnvpn/test/functest/testcase_11.py | 6 | ||||
-rw-r--r-- | sdnvpn/test/functest/testcase_12.py | 6 | ||||
-rw-r--r-- | sdnvpn/test/functest/testcase_13.py | 8 | ||||
-rw-r--r-- | sdnvpn/test/functest/testcase_2.py | 6 | ||||
-rw-r--r-- | sdnvpn/test/functest/testcase_3.py | 8 | ||||
-rw-r--r-- | sdnvpn/test/functest/testcase_4.py | 6 | ||||
-rw-r--r-- | sdnvpn/test/functest/testcase_7.py | 6 | ||||
-rw-r--r-- | sdnvpn/test/functest/testcase_8.py | 6 |
13 files changed, 59 insertions, 69 deletions
diff --git a/requirements.txt b/requirements.txt index 2689b31..3e9956e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,9 +7,9 @@ opnfv PyYAML>=3.12 # MIT networking-bgpvpn>=7.0.0 # Apache-2.0 python-cinderclient>=3.3.0 # Apache-2.0 -python-glanceclient>=2.8.0 # Apache-2.0 python-heatclient>=1.10.0 # Apache-2.0 python-keystoneclient>=3.8.0 # Apache-2.0 python-neutronclient>=6.7.0 # Apache-2.0 python-novaclient>=9.1.0 # Apache-2.0 xtesting # Apache-2.0 +openstacksdk>=0.11.3 # Apache-2.0 diff --git a/sdnvpn/lib/openstack_utils.py b/sdnvpn/lib/openstack_utils.py index 29843f0..44da383 100644 --- a/sdnvpn/lib/openstack_utils.py +++ b/sdnvpn/lib/openstack_utils.py @@ -18,11 +18,11 @@ import urllib from keystoneauth1 import loading from keystoneauth1 import session from cinderclient import client as cinderclient -from glanceclient import client as glanceclient from heatclient import client as heatclient from novaclient import client as novaclient from keystoneclient import client as keystoneclient from neutronclient.neutron import client as neutronclient +from openstack import connection from functest.utils import env @@ -44,6 +44,10 @@ class MissingEnvVar(Exception): return str.format("Please set the mandatory env var: {}", self.var) +def get_os_connection(): + return connection.from_config() + + def is_keystone_v3(): keystone_api_version = os.getenv('OS_IDENTITY_API_VERSION') if (keystone_api_version is None or @@ -198,19 +202,6 @@ def get_neutron_client(other_creds={}): return neutronclient.Client(get_neutron_client_version(), session=sess) -def get_glance_client_version(): - api_version = os.getenv('OS_IMAGE_API_VERSION') - if api_version is not None: - logger.info("OS_IMAGE_API_VERSION is set in env as '%s'", api_version) - return api_version - return DEFAULT_API_VERSION - - -def get_glance_client(other_creds={}): - sess = get_session(other_creds) - return glanceclient.Client(get_glance_client_version(), session=sess) - - def get_heat_client_version(): api_version = os.getenv('OS_ORCHESTRATION_API_VERSION') if api_version is not None: @@ -241,7 +232,7 @@ def download_url(url, dest_path): return True -def download_and_add_image_on_glance(glance, image_name, image_url, data_dir): +def download_and_add_image_on_glance(conn, image_name, image_url, data_dir): try: dest_path = data_dir if not os.path.exists(dest_path): @@ -255,7 +246,7 @@ def download_and_add_image_on_glance(glance, image_name, image_url, data_dir): try: image = create_glance_image( - glance, image_name, dest_path + file_name) + conn, image_name, dest_path + file_name) if not image: return False else: @@ -1143,17 +1134,17 @@ def delete_security_group(neutron_client, secgroup_id): # ********************************************* # GLANCE # ********************************************* -def get_images(glance_client): +def get_images(conn): try: - images = glance_client.images.list() + images = conn.image.images() return images except Exception as e: logger.error("Error [get_images]: %s" % e) return None -def get_image_id(glance_client, image_name): - images = glance_client.images.list() +def get_image_id(conn, image_name): + images = conn.image.images() id = '' for i in images: if i.name == image_name: @@ -1162,7 +1153,7 @@ def get_image_id(glance_client, image_name): return id -def create_glance_image(glance_client, +def create_glance_image(conn, image_name, file_path, disk="qcow2", @@ -1173,39 +1164,38 @@ def create_glance_image(glance_client, logger.error("Error: file %s does not exist." % file_path) return None try: - image_id = get_image_id(glance_client, image_name) + image_id = get_image_id(conn, image_name) if image_id != '': logger.info("Image %s already exists." % image_name) else: logger.info("Creating image '%s' from '%s'..." % (image_name, file_path)) - - image = glance_client.images.create(name=image_name, - visibility=public, + with open(file_path) as image_data: + image = conn.image.upload_image(name=image_name, + is_public=public, disk_format=disk, container_format=container, + data=image_data, **extra_properties) image_id = image.id - with open(file_path) as image_data: - glance_client.images.upload(image_id, image_data) return image_id except Exception as e: - logger.error("Error [create_glance_image(glance_client, '%s', '%s', " + logger.error("Error [create_glance_image(image, '%s', '%s', " "'%s')]: %s" % (image_name, file_path, public, e)) return None def get_or_create_image(name, path, format, extra_properties): image_exists = False - glance_client = get_glance_client() + conn = get_os_connection() - image_id = get_image_id(glance_client, name) + image_id = get_image_id(conn, name) if image_id != '': logger.info("Using existing image '%s'..." % name) image_exists = True else: logger.info("Creating image '%s' from '%s'..." % (name, path)) - image_id = create_glance_image(glance_client, + image_id = create_glance_image(conn, name, path, format, @@ -1219,12 +1209,12 @@ def get_or_create_image(name, path, format, extra_properties): return image_exists, image_id -def delete_glance_image(glance_client, image_id): +def delete_glance_image(conn, image_id): try: - glance_client.images.delete(image_id) + conn.image.delete_image(image_id) return True except Exception as e: - logger.error("Error [delete_glance_image(glance_client, '%s')]: %s" + logger.error("Error [delete_glance_image(image, '%s')]: %s" % (image_id, e)) return False diff --git a/sdnvpn/lib/utils.py b/sdnvpn/lib/utils.py index 9f4c883..9b0673d 100644 --- a/sdnvpn/lib/utils.py +++ b/sdnvpn/lib/utils.py @@ -722,10 +722,10 @@ def cleanup_nova(nova_client, instance_ids, flavor_ids=None): return True -def cleanup_glance(glance_client, image_ids): +def cleanup_glance(conn, image_ids): if len(image_ids) != 0: for image_id in image_ids: - if not os_utils.delete_glance_image(glance_client, image_id): + if not os_utils.delete_glance_image(conn, image_id): logger.error('Fail to delete all images. ' 'Image with id {} was not deleted.'. format(image_id)) diff --git a/sdnvpn/test/functest/testcase_1.py b/sdnvpn/test/functest/testcase_1.py index 35e32b2..7c0cb43 100644 --- a/sdnvpn/test/functest/testcase_1.py +++ b/sdnvpn/test/functest/testcase_1.py @@ -33,14 +33,14 @@ def main(): nova_client = os_utils.get_nova_client() neutron_client = os_utils.get_neutron_client() - glance_client = os_utils.get_glance_client() + conn = os_utils.get_os_connection() (floatingip_ids, instance_ids, router_ids, network_ids, image_ids, subnet_ids, interfaces, bgpvpn_ids) = ([] for i in range(8)) try: image_id = os_utils.create_glance_image( - glance_client, TESTCASE_CONFIG.image_name, + conn, TESTCASE_CONFIG.image_name, COMMON_CONFIG.image_path, disk=COMMON_CONFIG.image_format, container="bare", public='public') image_ids.append(image_id) @@ -245,7 +245,7 @@ def main(): raise finally: test_utils.cleanup_nova(nova_client, instance_ids) - test_utils.cleanup_glance(glance_client, image_ids) + test_utils.cleanup_glance(conn, image_ids) test_utils.cleanup_neutron(neutron_client, floatingip_ids, bgpvpn_ids, interfaces, subnet_ids, router_ids, network_ids) diff --git a/sdnvpn/test/functest/testcase_10.py b/sdnvpn/test/functest/testcase_10.py index aebc146..78d5684 100644 --- a/sdnvpn/test/functest/testcase_10.py +++ b/sdnvpn/test/functest/testcase_10.py @@ -72,11 +72,11 @@ def main(): nova_client = os_utils.get_nova_client() neutron_client = os_utils.get_neutron_client() - glance_client = os_utils.get_glance_client() + conn = os_utils.get_os_connection() (floatingip_ids, instance_ids, router_ids, network_ids, image_ids, subnet_ids, interfaces, bgpvpn_ids) = ([] for i in range(8)) - image_id = os_utils.create_glance_image(glance_client, + image_id = os_utils.create_glance_image(conn, TESTCASE_CONFIG.image_name, COMMON_CONFIG.image_path, disk=COMMON_CONFIG.image_format, @@ -260,7 +260,7 @@ def main(): thread.join() test_utils.cleanup_nova(nova_client, instance_ids) - test_utils.cleanup_glance(glance_client, image_ids) + test_utils.cleanup_glance(conn, image_ids) test_utils.cleanup_neutron(neutron_client, floatingip_ids, bgpvpn_ids, interfaces, subnet_ids, router_ids, network_ids) diff --git a/sdnvpn/test/functest/testcase_11.py b/sdnvpn/test/functest/testcase_11.py index c597c4d..85dea19 100644 --- a/sdnvpn/test/functest/testcase_11.py +++ b/sdnvpn/test/functest/testcase_11.py @@ -32,7 +32,7 @@ def main(): nova_client = os_utils.get_nova_client() neutron_client = os_utils.get_neutron_client() - glance_client = os_utils.get_glance_client() + conn = os_utils.get_os_connection() openstack_nodes = test_utils.get_nodes() (floatingip_ids, instance_ids, router_ids, network_ids, image_ids, @@ -40,7 +40,7 @@ def main(): try: image_id = os_utils.create_glance_image( - glance_client, TESTCASE_CONFIG.image_name, + conn, TESTCASE_CONFIG.image_name, COMMON_CONFIG.image_path, disk=COMMON_CONFIG.image_format, container="bare", public='public') image_ids.append(image_id) @@ -129,7 +129,7 @@ def main(): finally: # Cleanup topology test_utils.cleanup_nova(nova_client, instance_ids) - test_utils.cleanup_glance(glance_client, image_ids) + test_utils.cleanup_glance(conn, image_ids) test_utils.cleanup_neutron(neutron_client, floatingip_ids, bgpvpn_ids, interfaces, subnet_ids, router_ids, network_ids) diff --git a/sdnvpn/test/functest/testcase_12.py b/sdnvpn/test/functest/testcase_12.py index 3e13d69..be32d1d 100644 --- a/sdnvpn/test/functest/testcase_12.py +++ b/sdnvpn/test/functest/testcase_12.py @@ -32,7 +32,7 @@ def main(): nova_client = os_utils.get_nova_client() neutron_client = os_utils.get_neutron_client() - glance_client = os_utils.get_glance_client() + conn = os_utils.get_os_connection() openstack_nodes = test_utils.get_nodes() (floatingip_ids, instance_ids, router_ids, network_ids, image_ids, @@ -40,7 +40,7 @@ def main(): try: image_id = os_utils.create_glance_image( - glance_client, TESTCASE_CONFIG.image_name, + conn, TESTCASE_CONFIG.image_name, COMMON_CONFIG.image_path, disk=COMMON_CONFIG.image_format, container="bare", public='public') image_ids.append(image_id) @@ -186,7 +186,7 @@ def main(): finally: # Cleanup topology test_utils.cleanup_nova(nova_client, instance_ids) - test_utils.cleanup_glance(glance_client, image_ids) + test_utils.cleanup_glance(conn, image_ids) test_utils.cleanup_neutron(neutron_client, floatingip_ids, bgpvpn_ids, interfaces, subnet_ids, router_ids, network_ids) diff --git a/sdnvpn/test/functest/testcase_13.py b/sdnvpn/test/functest/testcase_13.py index 8beb1db..2d79b45 100644 --- a/sdnvpn/test/functest/testcase_13.py +++ b/sdnvpn/test/functest/testcase_13.py @@ -45,14 +45,14 @@ def main(): nova_client = os_utils.get_nova_client() neutron_client = os_utils.get_neutron_client() - glance_client = os_utils.get_glance_client() + conn = os_utils.get_os_connection() (floatingip_ids, instance_ids, router_ids, network_ids, image_ids, subnet_ids, interfaces, bgpvpn_ids, flavor_ids) = ([] for i in range(9)) try: image_id = os_utils.create_glance_image( - glance_client, + conn, COMMON_CONFIG.ubuntu_image_name, COMMON_CONFIG.ubuntu_image_path, disk="qcow2", @@ -133,7 +133,7 @@ def main(): test_utils.async_Wait_for_instances([vm_1, vm_2]) image_2_id = os_utils.create_glance_image( - glance_client, TESTCASE_CONFIG.image_name, + conn, TESTCASE_CONFIG.image_name, COMMON_CONFIG.image_path, disk=COMMON_CONFIG.image_format, container="bare", public='public') image_ids.append(image_2_id) @@ -209,7 +209,7 @@ def main(): finally: test_utils.update_router_no_extra_route(neutron_client, router_ids) test_utils.cleanup_nova(nova_client, instance_ids, flavor_ids) - test_utils.cleanup_glance(glance_client, image_ids) + test_utils.cleanup_glance(conn, image_ids) test_utils.cleanup_neutron(neutron_client, floatingip_ids, bgpvpn_ids, interfaces, subnet_ids, router_ids, network_ids) diff --git a/sdnvpn/test/functest/testcase_2.py b/sdnvpn/test/functest/testcase_2.py index ee74d8d..4955f7e 100644 --- a/sdnvpn/test/functest/testcase_2.py +++ b/sdnvpn/test/functest/testcase_2.py @@ -33,7 +33,7 @@ def main(): nova_client = os_utils.get_nova_client() neutron_client = os_utils.get_neutron_client() - glance_client = os_utils.get_glance_client() + conn = os_utils.get_os_connection() (floatingip_ids, instance_ids, router_ids, network_ids, image_ids, subnet_ids, interfaces, bgpvpn_ids) = ([] for i in range(8)) @@ -47,7 +47,7 @@ def main(): files = {"/home/cirros/id_rsa": key} image_id = os_utils.create_glance_image( - glance_client, TESTCASE_CONFIG.image_name, + conn, TESTCASE_CONFIG.image_name, COMMON_CONFIG.image_path, disk=COMMON_CONFIG.image_format, container="bare", public='public') image_ids.append(image_id) @@ -268,7 +268,7 @@ def main(): raise finally: test_utils.cleanup_nova(nova_client, instance_ids) - test_utils.cleanup_glance(glance_client, image_ids) + test_utils.cleanup_glance(conn, image_ids) test_utils.cleanup_neutron(neutron_client, floatingip_ids, bgpvpn_ids, interfaces, subnet_ids, router_ids, network_ids) diff --git a/sdnvpn/test/functest/testcase_3.py b/sdnvpn/test/functest/testcase_3.py index b06915a..c942f0b 100644 --- a/sdnvpn/test/functest/testcase_3.py +++ b/sdnvpn/test/functest/testcase_3.py @@ -168,7 +168,7 @@ def main(): else: logger.info("Using old image") - glance_client = os_utils.get_glance_client() + conn = os_utils.get_os_connection() nova_client = os_utils.get_nova_client() neutron_client = os_utils.get_neutron_client() @@ -190,7 +190,7 @@ def main(): test_utils.open_bgp_port(neutron_client, sg_id) image_id = os_utils.create_glance_image( - glance_client, TESTCASE_CONFIG.image_name, + conn, TESTCASE_CONFIG.image_name, COMMON_CONFIG.image_path, disk=COMMON_CONFIG.image_format, container="bare", public='public') image_ids.append(image_id) @@ -225,7 +225,7 @@ def main(): logger.error("Incompatible installer type") ubuntu_image_id = os_utils.create_glance_image( - glance_client, + conn, COMMON_CONFIG.ubuntu_image_name, COMMON_CONFIG.ubuntu_image_path, disk, @@ -399,7 +399,7 @@ def main(): if quagga_vm is not None: test_utils.detach_instance_from_ext_br(quagga_vm, compute) test_utils.cleanup_nova(nova_client, instance_ids, flavor_ids) - test_utils.cleanup_glance(glance_client, image_ids) + test_utils.cleanup_glance(conn, image_ids) test_utils.cleanup_neutron(neutron_client, floatingip_ids, bgpvpn_ids, interfaces, subnet_ids, router_ids, network_ids) diff --git a/sdnvpn/test/functest/testcase_4.py b/sdnvpn/test/functest/testcase_4.py index 9b11cc3..a29dc12 100644 --- a/sdnvpn/test/functest/testcase_4.py +++ b/sdnvpn/test/functest/testcase_4.py @@ -34,14 +34,14 @@ def main(): nova_client = os_utils.get_nova_client() neutron_client = os_utils.get_neutron_client() - glance_client = os_utils.get_glance_client() + conn = os_utils.get_os_connection() (floatingip_ids, instance_ids, router_ids, network_ids, image_ids, subnet_ids, interfaces, bgpvpn_ids) = ([] for i in range(8)) try: image_id = os_utils.create_glance_image( - glance_client, TESTCASE_CONFIG.image_name, + conn, TESTCASE_CONFIG.image_name, COMMON_CONFIG.image_path, disk=COMMON_CONFIG.image_format, container="bare", public='public') image_ids.append(image_id) @@ -259,7 +259,7 @@ def main(): raise finally: test_utils.cleanup_nova(nova_client, instance_ids) - test_utils.cleanup_glance(glance_client, image_ids) + test_utils.cleanup_glance(conn, image_ids) test_utils.cleanup_neutron(neutron_client, floatingip_ids, bgpvpn_ids, interfaces, subnet_ids, router_ids, network_ids) diff --git a/sdnvpn/test/functest/testcase_7.py b/sdnvpn/test/functest/testcase_7.py index 1ad0538..381b98b 100644 --- a/sdnvpn/test/functest/testcase_7.py +++ b/sdnvpn/test/functest/testcase_7.py @@ -43,14 +43,14 @@ def main(): nova_client = os_utils.get_nova_client() neutron_client = os_utils.get_neutron_client() - glance_client = os_utils.get_glance_client() + conn = os_utils.get_os_connection() (floatingip_ids, instance_ids, router_ids, network_ids, image_ids, subnet_ids, interfaces, bgpvpn_ids) = ([] for i in range(8)) try: image_id = os_utils.create_glance_image( - glance_client, TESTCASE_CONFIG.image_name, + conn, TESTCASE_CONFIG.image_name, COMMON_CONFIG.image_path, disk=COMMON_CONFIG.image_format, container="bare", public='public') image_ids.append(image_id) @@ -169,7 +169,7 @@ def main(): raise finally: test_utils.cleanup_nova(nova_client, instance_ids) - test_utils.cleanup_glance(glance_client, image_ids) + test_utils.cleanup_glance(conn, image_ids) test_utils.cleanup_neutron(neutron_client, floatingip_ids, bgpvpn_ids, interfaces, subnet_ids, router_ids, network_ids) diff --git a/sdnvpn/test/functest/testcase_8.py b/sdnvpn/test/functest/testcase_8.py index 6336f46..cfdb950 100644 --- a/sdnvpn/test/functest/testcase_8.py +++ b/sdnvpn/test/functest/testcase_8.py @@ -41,14 +41,14 @@ def main(): nova_client = os_utils.get_nova_client() neutron_client = os_utils.get_neutron_client() - glance_client = os_utils.get_glance_client() + conn = os_utils.get_os_connection() (floatingip_ids, instance_ids, router_ids, network_ids, image_ids, subnet_ids, interfaces, bgpvpn_ids) = ([] for i in range(8)) try: image_id = os_utils.create_glance_image( - glance_client, TESTCASE_CONFIG.image_name, + conn, TESTCASE_CONFIG.image_name, COMMON_CONFIG.image_path, disk=COMMON_CONFIG.image_format, container="bare", public='public') image_ids.append(image_id) @@ -177,7 +177,7 @@ def main(): raise finally: test_utils.cleanup_nova(nova_client, instance_ids) - test_utils.cleanup_glance(glance_client, image_ids) + test_utils.cleanup_glance(conn, image_ids) test_utils.cleanup_neutron(neutron_client, floatingip_ids, bgpvpn_ids, interfaces, subnet_ids, router_ids, network_ids) |