Replace nova client calls with openstack sdk 23/62123/12
authorStamatis Katsaounis <mokats@intracom-telecom.com>
Wed, 12 Sep 2018 10:00:09 +0000 (13:00 +0300)
committerStamatis Katsaounis <mokats@intracom-telecom.com>
Mon, 8 Oct 2018 10:40:34 +0000 (13:40 +0300)
JIRA: SDNVPN-220

This patch replaces all calls of nova client with openstack sdk.

Change-Id: I9e3a0fe08ba36bfb64483238cd286acad829ae90
Signed-off-by: Stamatis Katsaounis <mokats@intracom-telecom.com>
15 files changed:
requirements.txt
sdnvpn/lib/openstack_utils.py
sdnvpn/lib/results.py
sdnvpn/lib/utils.py
sdnvpn/test/functest/run_sdnvpn_tests.py
sdnvpn/test/functest/testcase_1.py
sdnvpn/test/functest/testcase_10.py
sdnvpn/test/functest/testcase_11.py
sdnvpn/test/functest/testcase_12.py
sdnvpn/test/functest/testcase_13.py
sdnvpn/test/functest/testcase_2.py
sdnvpn/test/functest/testcase_3.py
sdnvpn/test/functest/testcase_4.py
sdnvpn/test/functest/testcase_7.py
sdnvpn/test/functest/testcase_8.py

index 3e9956e..6b49dc5 100644 (file)
@@ -10,6 +10,5 @@ python-cinderclient>=3.3.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
index 44da383..bf78ef1 100644 (file)
@@ -8,6 +8,7 @@
 # http://www.apache.org/licenses/LICENSE-2.0
 #
 
+import base64
 import logging
 import os.path
 import shutil
@@ -19,10 +20,10 @@ from keystoneauth1 import loading
 from keystoneauth1 import session
 from cinderclient import client as cinderclient
 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 openstack import cloud as os_cloud
 
 from functest.utils import env
 
@@ -48,6 +49,10 @@ def get_os_connection():
     return connection.from_config()
 
 
+def get_os_cloud():
+    return os_cloud.openstack_cloud()
+
+
 def is_keystone_v3():
     keystone_api_version = os.getenv('OS_IDENTITY_API_VERSION')
     if (keystone_api_version is None or
@@ -160,20 +165,6 @@ def get_keystone_client(other_creds={}):
                                  interface=os.getenv('OS_INTERFACE', 'admin'))
 
 
-def get_nova_client_version():
-    api_version = os.getenv('OS_COMPUTE_API_VERSION')
-    if api_version is not None:
-        logger.info("OS_COMPUTE_API_VERSION is set in env as '%s'",
-                    api_version)
-        return api_version
-    return DEFAULT_API_VERSION
-
-
-def get_nova_client(other_creds={}):
-    sess = get_session(other_creds)
-    return novaclient.Client(get_nova_client_version(), session=sess)
-
-
 def get_cinder_client_version():
     api_version = os.getenv('OS_VOLUME_API_VERSION')
     if api_version is not None:
@@ -259,36 +250,37 @@ def download_and_add_image_on_glance(conn, image_name, image_url, data_dir):
 # *********************************************
 #   NOVA
 # *********************************************
-def get_instances(nova_client):
+def get_instances(conn):
     try:
-        instances = nova_client.servers.list(search_opts={'all_tenants': 1})
+        instances = conn.compute.servers(all_tenants=1)
         return instances
     except Exception as e:
-        logger.error("Error [get_instances(nova_client)]: %s" % e)
+        logger.error("Error [get_instances(compute)]: %s" % e)
         return None
 
 
-def get_instance_status(nova_client, instance):
+def get_instance_status(conn, instance):
     try:
-        instance = nova_client.servers.get(instance.id)
+        instance = conn.compute.get_server(instance.id)
         return instance.status
     except Exception as e:
-        logger.error("Error [get_instance_status(nova_client)]: %s" % e)
+        logger.error("Error [get_instance_status(compute)]: %s" % e)
         return None
 
 
-def get_instance_by_name(nova_client, instance_name):
+def get_instance_by_name(conn, instance_name):
     try:
-        instance = nova_client.servers.find(name=instance_name)
+        instance = conn.compute.find_server(instance_name,
+                                            ignore_missing=False)
         return instance
     except Exception as e:
-        logger.error("Error [get_instance_by_name(nova_client, '%s')]: %s"
+        logger.error("Error [get_instance_by_name(compute, '%s')]: %s"
                      % (instance_name, e))
         return None
 
 
-def get_flavor_id(nova_client, flavor_name):
-    flavors = nova_client.flavors.list(detailed=True)
+def get_flavor_id(conn, flavor_name):
+    flavors = conn.compute.flavors()
     id = ''
     for f in flavors:
         if f.name == flavor_name:
@@ -297,8 +289,8 @@ def get_flavor_id(nova_client, flavor_name):
     return id
 
 
-def get_flavor_id_by_ram_range(nova_client, min_ram, max_ram):
-    flavors = nova_client.flavors.list(detailed=True)
+def get_flavor_id_by_ram_range(conn, min_ram, max_ram):
+    flavors = conn.compute.flavors()
     id = ''
     for f in flavors:
         if min_ram <= f.ram and f.ram <= max_ram:
@@ -307,51 +299,52 @@ def get_flavor_id_by_ram_range(nova_client, min_ram, max_ram):
     return id
 
 
-def get_aggregates(nova_client):
+def get_aggregates(cloud):
     try:
-        aggregates = nova_client.aggregates.list()
+        aggregates = cloud.list_aggregates()
         return aggregates
     except Exception as e:
-        logger.error("Error [get_aggregates(nova_client)]: %s" % e)
+        logger.error("Error [get_aggregates(compute)]: %s" % e)
         return None
 
 
-def get_aggregate_id(nova_client, aggregate_name):
+def get_aggregate_id(cloud, aggregate_name):
     try:
-        aggregates = get_aggregates(nova_client)
+        aggregates = get_aggregates(cloud)
         _id = [ag.id for ag in aggregates if ag.name == aggregate_name][0]
         return _id
     except Exception as e:
-        logger.error("Error [get_aggregate_id(nova_client, %s)]:"
+        logger.error("Error [get_aggregate_id(compute, %s)]:"
                      " %s" % (aggregate_name, e))
         return None
 
 
-def get_availability_zones(nova_client):
+def get_availability_zones(conn):
     try:
-        availability_zones = nova_client.availability_zones.list()
+        availability_zones = conn.compute.availability_zones()
         return availability_zones
     except Exception as e:
-        logger.error("Error [get_availability_zones(nova_client)]: %s" % e)
+        logger.error("Error [get_availability_zones(compute)]: %s" % e)
         return None
 
 
-def get_availability_zone_names(nova_client):
+def get_availability_zone_names(conn):
     try:
-        az_names = [az.zoneName for az in get_availability_zones(nova_client)]
+        az_names = [az.zoneName for az in get_availability_zones(conn)]
         return az_names
     except Exception as e:
-        logger.error("Error [get_availability_zone_names(nova_client)]:"
+        logger.error("Error [get_availability_zone_names(compute)]:"
                      " %s" % e)
         return None
 
 
-def create_flavor(nova_client, flavor_name, ram, disk, vcpus, public=True):
+def create_flavor(conn, flavor_name, ram, disk, vcpus, public=True):
     try:
-        flavor = nova_client.flavors.create(
-            flavor_name, ram, vcpus, disk, is_public=public)
+        flavor = conn.compute.create_flavor(
+            name=flavor_name, ram=ram, disk=disk, vcpus=vcpus,
+            is_public=public)
     except Exception as e:
-        logger.error("Error [create_flavor(nova_client, '%s', '%s', '%s', "
+        logger.error("Error [create_flavor(compute, '%s', '%s', '%s', "
                      "'%s')]: %s" % (flavor_name, ram, disk, vcpus, e))
         return None
     return flavor.id
@@ -359,9 +352,9 @@ def create_flavor(nova_client, flavor_name, ram, disk, vcpus, public=True):
 
 def get_or_create_flavor(flavor_name, ram, disk, vcpus, public=True):
     flavor_exists = False
-    nova_client = get_nova_client()
+    conn = get_os_connection()
 
-    flavor_id = get_flavor_id(nova_client, flavor_name)
+    flavor_id = get_flavor_id(conn, flavor_name)
     if flavor_id != '':
         logger.info("Using existing flavor '%s'..." % flavor_name)
         flavor_exists = True
@@ -369,7 +362,7 @@ def get_or_create_flavor(flavor_name, ram, disk, vcpus, public=True):
         logger.info("Creating flavor '%s' with '%s' RAM, '%s' disk size, "
                     "'%s' vcpus..." % (flavor_name, ram, disk, vcpus))
         flavor_id = create_flavor(
-            nova_client, flavor_name, ram, disk, vcpus, public=public)
+            conn, flavor_name, ram, disk, vcpus, public=public)
         if not flavor_id:
             raise Exception("Failed to create flavor '%s'..." % (flavor_name))
         else:
@@ -388,49 +381,49 @@ def get_floating_ips(neutron_client):
         return None
 
 
-def get_hypervisors(nova_client):
+def get_hypervisors(conn):
     try:
         nodes = []
-        hypervisors = nova_client.hypervisors.list()
+        hypervisors = conn.compute.hypervisors()
         for hypervisor in hypervisors:
             if hypervisor.state == "up":
-                nodes.append(hypervisor.hypervisor_hostname)
+                nodes.append(hypervisor.name)
         return nodes
     except Exception as e:
-        logger.error("Error [get_hypervisors(nova_client)]: %s" % e)
+        logger.error("Error [get_hypervisors(compute)]: %s" % e)
         return None
 
 
-def create_aggregate(nova_client, aggregate_name, av_zone):
+def create_aggregate(cloud, aggregate_name, av_zone):
     try:
-        nova_client.aggregates.create(aggregate_name, av_zone)
+        cloud.create_aggregate(aggregate_name, av_zone)
         return True
     except Exception as e:
-        logger.error("Error [create_aggregate(nova_client, %s, %s)]: %s"
+        logger.error("Error [create_aggregate(compute, %s, %s)]: %s"
                      % (aggregate_name, av_zone, e))
         return None
 
 
-def add_host_to_aggregate(nova_client, aggregate_name, compute_host):
+def add_host_to_aggregate(cloud, aggregate_name, compute_host):
     try:
-        aggregate_id = get_aggregate_id(nova_client, aggregate_name)
-        nova_client.aggregates.add_host(aggregate_id, compute_host)
+        aggregate_id = get_aggregate_id(cloud, aggregate_name)
+        cloud.add_host_to_aggregate(aggregate_id, compute_host)
         return True
     except Exception as e:
-        logger.error("Error [add_host_to_aggregate(nova_client, %s, %s)]: %s"
+        logger.error("Error [add_host_to_aggregate(compute, %s, %s)]: %s"
                      % (aggregate_name, compute_host, e))
         return None
 
 
 def create_aggregate_with_host(
-        nova_client, aggregate_name, av_zone, compute_host):
+        cloud, aggregate_name, av_zone, compute_host):
     try:
-        create_aggregate(nova_client, aggregate_name, av_zone)
-        add_host_to_aggregate(nova_client, aggregate_name, compute_host)
+        create_aggregate(cloud, aggregate_name, av_zone)
+        add_host_to_aggregate(cloud, aggregate_name, compute_host)
         return True
     except Exception as e:
         logger.error("Error [create_aggregate_with_host("
-                     "nova_client, %s, %s, %s)]: %s"
+                     "compute, %s, %s, %s)]: %s"
                      % (aggregate_name, av_zone, compute_host, e))
         return None
 
@@ -441,41 +434,36 @@ def create_instance(flavor_name,
                     instance_name="functest-vm",
                     confdrive=True,
                     userdata=None,
-                    av_zone='',
+                    av_zone=None,
                     fixed_ip=None,
-                    files=None):
-    nova_client = get_nova_client()
+                    files=[]):
+    conn = get_os_connection()
     try:
-        flavor = nova_client.flavors.find(name=flavor_name)
+        flavor = conn.compute.find_flavor(flavor_name, ignore_missing=False)
     except:
-        flavors = nova_client.flavors.list()
+        flavors = [flavor.name for flavor in conn.compute.flavors()]
         logger.error("Error: Flavor '%s' not found. Available flavors are: "
                      "\n%s" % (flavor_name, flavors))
         return None
     if fixed_ip is not None:
-        nics = {"net-id": network_id, "v4-fixed-ip": fixed_ip}
+        networks = {"uuid": network_id, "fixed_ip": fixed_ip}
     else:
-        nics = {"net-id": network_id}
-    if userdata is None:
-        instance = nova_client.servers.create(
-            name=instance_name,
-            flavor=flavor,
-            image=image_id,
-            nics=[nics],
-            availability_zone=av_zone,
-            files=files
-        )
-    else:
-        instance = nova_client.servers.create(
-            name=instance_name,
-            flavor=flavor,
-            image=image_id,
-            nics=[nics],
-            config_drive=confdrive,
-            userdata=userdata,
-            availability_zone=av_zone,
-            files=files
-        )
+        networks = {"uuid": network_id}
+
+    server_attrs = {
+        'name': instance_name,
+        'flavor_id': flavor.id,
+        'image_id': image_id,
+        'networks': [networks],
+        'personality': files
+    }
+    if userdata is not None:
+        server_attrs['config_drive'] = confdrive
+        server_attrs['user_data'] = base64.b64encode(userdata.encode())
+    if av_zone is not None:
+        server_attrs['availability_zone'] = av_zone
+
+    instance = conn.compute.create_server(**server_attrs)
     return instance
 
 
@@ -485,12 +473,12 @@ def create_instance_and_wait_for_active(flavor_name,
                                         instance_name="",
                                         config_drive=False,
                                         userdata="",
-                                        av_zone='',
+                                        av_zone=None,
                                         fixed_ip=None,
-                                        files=None):
+                                        files=[]):
     SLEEP = 3
     VM_BOOT_TIMEOUT = 180
-    nova_client = get_nova_client()
+    conn = get_os_connection()
     instance = create_instance(flavor_name,
                                image_id,
                                network_id,
@@ -502,7 +490,7 @@ def create_instance_and_wait_for_active(flavor_name,
                                files=files)
     count = VM_BOOT_TIMEOUT / SLEEP
     for n in range(count, -1, -1):
-        status = get_instance_status(nova_client, instance)
+        status = get_instance_status(conn, instance)
         if status is None:
             time.sleep(SLEEP)
             continue
@@ -542,22 +530,22 @@ def attach_floating_ip(neutron_client, port_id):
         return None
 
 
-def add_floating_ip(nova_client, server_id, floatingip_addr):
+def add_floating_ip(conn, server_id, floatingip_addr):
     try:
-        nova_client.servers.add_floating_ip(server_id, floatingip_addr)
+        conn.compute.add_floating_ip_to_server(server_id, floatingip_addr)
         return True
     except Exception as e:
-        logger.error("Error [add_floating_ip(nova_client, '%s', '%s')]: %s"
+        logger.error("Error [add_floating_ip(compute, '%s', '%s')]: %s"
                      % (server_id, floatingip_addr, e))
         return False
 
 
-def delete_instance(nova_client, instance_id):
+def delete_instance(conn, instance_id):
     try:
-        nova_client.servers.force_delete(instance_id)
+        conn.compute.delete_server(instance_id, force=True)
         return True
     except Exception as e:
-        logger.error("Error [delete_instance(nova_client, '%s')]: %s"
+        logger.error("Error [delete_instance(compute, '%s')]: %s"
                      % (instance_id, e))
         return False
 
@@ -572,32 +560,32 @@ def delete_floating_ip(neutron_client, floatingip_id):
         return False
 
 
-def remove_host_from_aggregate(nova_client, aggregate_name, compute_host):
+def remove_host_from_aggregate(cloud, aggregate_name, compute_host):
     try:
-        aggregate_id = get_aggregate_id(nova_client, aggregate_name)
-        nova_client.aggregates.remove_host(aggregate_id, compute_host)
+        aggregate_id = get_aggregate_id(cloud, aggregate_name)
+        cloud.remove_host_from_aggregate(aggregate_id, compute_host)
         return True
     except Exception as e:
-        logger.error("Error [remove_host_from_aggregate(nova_client, %s, %s)]:"
+        logger.error("Error [remove_host_from_aggregate(compute, %s, %s)]:"
                      " %s" % (aggregate_name, compute_host, e))
         return False
 
 
-def remove_hosts_from_aggregate(nova_client, aggregate_name):
-    aggregate_id = get_aggregate_id(nova_client, aggregate_name)
-    hosts = nova_client.aggregates.get(aggregate_id).hosts
+def remove_hosts_from_aggregate(cloud, aggregate_name):
+    aggregate_id = get_aggregate_id(cloud, aggregate_name)
+    hosts = cloud.get_aggregate(aggregate_id).hosts
     assert(
-        all(remove_host_from_aggregate(nova_client, aggregate_name, host)
+        all(remove_host_from_aggregate(cloud, aggregate_name, host)
             for host in hosts))
 
 
-def delete_aggregate(nova_client, aggregate_name):
+def delete_aggregate(cloud, aggregate_name):
     try:
-        remove_hosts_from_aggregate(nova_client, aggregate_name)
-        nova_client.aggregates.delete(aggregate_name)
+        remove_hosts_from_aggregate(cloud, aggregate_name)
+        cloud.delete_aggregate(aggregate_name)
         return True
     except Exception as e:
-        logger.error("Error [delete_aggregate(nova_client, %s)]: %s"
+        logger.error("Error [delete_aggregate(compute, %s)]: %s"
                      % (aggregate_name, e))
         return False
 
@@ -1095,12 +1083,12 @@ def create_security_group_full(neutron_client,
     return sg_id
 
 
-def add_secgroup_to_instance(nova_client, instance_id, secgroup_id):
+def add_secgroup_to_instance(conn, instance_id, secgroup_id):
     try:
-        nova_client.servers.add_security_group(instance_id, secgroup_id)
+        conn.compute.add_security_group_to_server(instance_id, secgroup_id)
         return True
     except Exception as e:
-        logger.error("Error [add_secgroup_to_instance(nova_client, '%s', "
+        logger.error("Error [add_secgroup_to_instance(compute, '%s', "
                      "'%s')]: %s" % (instance_id, secgroup_id, e))
         return False
 
index e1a5e5a..924b921 100644 (file)
@@ -17,7 +17,8 @@ logger = logging.getLogger('sdnvpn-results')
 
 class Results(object):
 
-    def __init__(self, line_length):
+    def __init__(self, line_length, conn=None):
+        self.conn = conn
         self.line_length = line_length
         self.test_result = "PASS"
         self.summary = ""
@@ -29,7 +30,8 @@ class Results(object):
                         vm_source,
                         vm_target,
                         expected="PASS", timeout=30):
-        ip_target = vm_target.networks.itervalues().next()[0]
+        ip_target = self.conn.compute.get_server(vm_target).\
+            addresses.values()[0][0]['addr']
         self.get_ping_status_target_ip(vm_source, vm_target.name,
                                        ip_target, expected, timeout)
 
@@ -38,8 +40,10 @@ class Results(object):
                                   target_name,
                                   ip_target,
                                   expected="PASS", timeout=30):
-        console_log = vm_source.get_console_output()
-        ip_source = vm_source.networks.itervalues().next()[0]
+        console_log = self.conn.compute.\
+            get_server_console_output(vm_source)['output']
+        ip_source = self.conn.compute.get_server(vm_source).\
+            addresses.values()[0][0]['addr']
         if "request failed" in console_log:
             # Normally, cirros displays this message when userdata fails
             logger.debug("It seems userdata is not supported in "
@@ -59,7 +63,8 @@ class Results(object):
                             tab, target_name, ip_target,
                             tab, expected_result))
             while True:
-                console_log = vm_source.get_console_output()
+                console_log = self.conn.compute.\
+                    get_server_console_output(vm_source)['output']
                 # the console_log is a long string, we want to take
                 # the last 4 lines (for example)
                 lines = console_log.split('\n')
@@ -128,9 +133,12 @@ class Results(object):
 
     def check_ssh_output(self, vm_source, vm_target,
                          expected, timeout=30):
-        console_log = vm_source.get_console_output()
-        ip_source = vm_source.networks.itervalues().next()[0]
-        ip_target = vm_target.networks.itervalues().next()[0]
+        console_log = self.conn.compute.\
+            get_server_console_output(vm_source)['output']
+        ip_source = self.conn.compute.get_server(vm_source).\
+            addresses.values()[0][0]['addr']
+        ip_target = self.conn.compute.get_server(vm_target).\
+            addresses.values()[0][0]['addr']
 
         if "request failed" in console_log:
             # Normally, cirros displays this message when userdata fails
@@ -148,7 +156,8 @@ class Results(object):
                             tab, vm_target.name, ip_target,
                             tab, expected))
             while True:
-                console_log = vm_source.get_console_output()
+                console_log = self.conn.compute.\
+                    get_server_console_output(vm_source)['output']
                 # the console_log is a long string, we want to take
                 # the last 4 lines (for example)
                 lines = console_log.split('\n')
index 9b0673d..900092c 100644 (file)
@@ -155,16 +155,16 @@ def update_port_allowed_address_pairs(neutron_client, port_id, address_pairs):
         return None
 
 
-def create_instance(nova_client,
+def create_instance(conn,
                     name,
                     image_id,
                     network_id,
                     sg_id,
                     secgroup_name=None,
                     fixed_ip=None,
-                    compute_node='',
+                    compute_node=None,
                     userdata=None,
-                    files=None,
+                    files=[],
                     **kwargs
                     ):
     if 'flavor' not in kwargs:
@@ -192,10 +192,12 @@ def create_instance(nova_client,
         logger.error("Error while booting instance.")
         raise Exception("Error while booting instance {}".format(name))
     else:
+        # Retrieve IP of INSTANCE
+        network_name = conn.network.get_network(network_id).name
+        instance_ip = conn.compute.get_server(instance).\
+            addresses.get(network_name)[0]['addr']
         logger.debug("Instance '%s' booted successfully. IP='%s'." %
-                     (name, instance.networks.itervalues().next()[0]))
-    # Retrieve IP of INSTANCE
-    # instance_ip = instance.networks.get(network_id)[0]
+                     (name, instance_ip))
 
     if secgroup_name:
         logger.debug("Adding '%s' to security group '%s'..."
@@ -203,7 +205,7 @@ def create_instance(nova_client,
     else:
         logger.debug("Adding '%s' to security group '%s'..."
                      % (name, sg_id))
-    os_utils.add_secgroup_to_instance(nova_client, instance.id, sg_id)
+    os_utils.add_secgroup_to_instance(conn, instance.id, sg_id)
 
     return instance
 
@@ -321,18 +323,21 @@ def get_installer_ip():
     return str(os.environ['INSTALLER_IP'])
 
 
-def get_instance_ip(instance):
-    instance_ip = instance.networks.itervalues().next()[0]
+def get_instance_ip(conn, instance):
+    instance_ip = conn.compute.get_server(instance).\
+        addresses.values()[0][0]['addr']
     return instance_ip
 
 
 def wait_for_instance(instance, pattern=".* login:", tries=40):
     logger.info("Waiting for instance %s to boot up" % instance.id)
+    conn = os_utils.get_os_connection()
     sleep_time = 2
     expected_regex = re.compile(pattern)
     console_log = ""
     while tries > 0 and not expected_regex.search(console_log):
-        console_log = instance.get_console_output()
+        console_log = conn.compute.\
+            get_server_console_output(instance)['output']
         time.sleep(sleep_time)
         tries -= 1
 
@@ -371,14 +376,14 @@ def async_Wait_for_instances(instances, tries=40):
         logger.error("one or more instances is not yet booted up")
 
 
-def wait_for_instance_delete(nova_client, instance_id, tries=30):
+def wait_for_instance_delete(conn, instance_id, tries=30):
     sleep_time = 2
     instances = [instance_id]
     logger.debug("Waiting for instance %s to be deleted"
                  % (instance_id))
     while tries > 0 and instance_id in instances:
         instances = [instance.id for instance in
-                     os_utils.get_instances(nova_client)]
+                     os_utils.get_instances(conn)]
         time.sleep(sleep_time)
         tries -= 1
     if instance_id in instances:
@@ -441,10 +446,10 @@ def wait_before_subtest(*args, **kwargs):
     time.sleep(30)
 
 
-def assert_and_get_compute_nodes(nova_client, required_node_number=2):
+def assert_and_get_compute_nodes(conn, required_node_number=2):
     """Get the compute nodes in the deployment
     Exit if the deployment doesn't have enough compute nodes"""
-    compute_nodes = os_utils.get_hypervisors(nova_client)
+    compute_nodes = os_utils.get_hypervisors(conn)
 
     num_compute_nodes = len(compute_nodes)
     if num_compute_nodes < 2:
@@ -561,7 +566,7 @@ def run_odl_cmd(odl_node, cmd):
     return odl_node.run_cmd(karaf_cmd)
 
 
-def wait_for_cloud_init(instance):
+def wait_for_cloud_init(conn, instance):
     success = True
     # ubuntu images take a long time to start
     tries = 20
@@ -569,7 +574,8 @@ def wait_for_cloud_init(instance):
     logger.info("Waiting for cloud init of instance: {}"
                 "".format(instance.name))
     while tries > 0:
-        instance_log = instance.get_console_output()
+        instance_log = conn.compute.\
+            get_server_console_output(instance)['output']
         if "Failed to run module" in instance_log:
             success = False
             logger.error("Cloud init failed to run. Reason: %s",
@@ -592,7 +598,7 @@ def wait_for_cloud_init(instance):
 
 
 def attach_instance_to_ext_br(instance, compute_node):
-    libvirt_instance_name = getattr(instance, "OS-EXT-SRV-ATTR:instance_name")
+    libvirt_instance_name = instance.instance_name
     installer_type = str(os.environ['INSTALLER_TYPE'].lower())
     if installer_type == "fuel":
         bridge = "br-ex"
@@ -621,7 +627,7 @@ def attach_instance_to_ext_br(instance, compute_node):
 
 
 def detach_instance_from_ext_br(instance, compute_node):
-    libvirt_instance_name = getattr(instance, "OS-EXT-SRV-ATTR:instance_name")
+    libvirt_instance_name = instance.instance_name
     mac = compute_node.run_cmd("for vm in $(sudo virsh list | "
                                "grep running | awk '{print $2}'); "
                                "do echo -n ; sudo virsh dumpxml $vm| "
@@ -707,18 +713,18 @@ def cleanup_neutron(neutron_client, floatingip_ids, bgpvpn_ids, interfaces,
     return True
 
 
-def cleanup_nova(nova_client, instance_ids, flavor_ids=None):
+def cleanup_nova(conn, instance_ids, flavor_ids=None):
     if flavor_ids is not None and len(flavor_ids) != 0:
         for flavor_id in flavor_ids:
-            nova_client.flavors.delete(flavor_id)
+            conn.compute.delete_flavor(flavor_id)
     if len(instance_ids) != 0:
         for instance_id in instance_ids:
-            if not os_utils.delete_instance(nova_client, instance_id):
+            if not os_utils.delete_instance(conn, instance_id):
                 logger.error('Fail to delete all instances. '
                              'Instance with id {} was not deleted.'.
                              format(instance_id))
             else:
-                wait_for_instance_delete(nova_client, instance_id)
+                wait_for_instance_delete(conn, instance_id)
     return True
 
 
@@ -826,12 +832,12 @@ def update_nw_subnet_port_quota(neutron_client, tenant_id, nw_quota,
         return False
 
 
-def update_instance_quota_class(nova_client, instances_quota):
+def update_instance_quota_class(cloud, instances_quota):
     try:
-        nova_client.quota_classes.update("default", instances=instances_quota)
+        cloud.set_compute_quotas('admin', instances=instances_quota)
         return True
     except Exception as e:
-        logger.error("Error [update_instance_quota_class(nova_client,"
+        logger.error("Error [update_instance_quota_class(compute,"
                      " '%s' )]: %s" % (instances_quota, e))
         return False
 
@@ -845,9 +851,9 @@ def get_neutron_quota(neutron_client, tenant_id):
         raise
 
 
-def get_nova_instances_quota(nova_client):
+def get_nova_instances_quota(cloud):
     try:
-        return nova_client.quota_classes.get("default").instances
+        return cloud.get_compute_quotas('admin').instances
     except Exception as e:
         logger.error("Error in getting nova instances quota: %s" % e)
         raise
index c05876d..3f3b519 100644 (file)
@@ -31,7 +31,7 @@ class SdnvpnFunctest(feature.Feature):
 
     def execute(self):
 
-        nova_client = os_utils.get_nova_client()
+        cloud = os_utils.get_os_cloud()
         neutron_client = os_utils.get_neutron_client()
 
         tenant_id = os_utils.get_tenant_id(os_utils.get_keystone_client(),
@@ -42,7 +42,7 @@ class SdnvpnFunctest(feature.Feature):
          neutron_router_quota) = (
             neutron_quota['network'], neutron_quota['subnet'],
             neutron_quota['port'], neutron_quota['router'])
-        instances_quota = test_utils.get_nova_instances_quota(nova_client)
+        instances_quota = test_utils.get_nova_instances_quota(cloud)
 
         logger.info("Setting net/subnet/port/router "
                     "quota to unlimited")
@@ -59,8 +59,7 @@ class SdnvpnFunctest(feature.Feature):
         # https://jira.opnfv.org/projects/SDNVPN/issues/SDNVPN-115
         logger.info("Setting instances quota class to unlimited")
         test_utils.update_instance_quota_class(
-            nova_client,
-            COMMON_CONFIG.nova_instances_quota_class)
+            cloud, COMMON_CONFIG.nova_instances_quota_class)
 
         # Clean up the stale floating ip's so that required
         # ip addresses are available for sdnvpn testcases
@@ -141,7 +140,7 @@ class SdnvpnFunctest(feature.Feature):
                                                neutron_router_quota)
 
         logger.info("Resetting instances quota class")
-        test_utils.update_instance_quota_class(nova_client, instances_quota)
+        test_utils.update_instance_quota_class(cloud, instances_quota)
 
         try:
             installer_type = str(os.environ['INSTALLER_TYPE'].lower())
index 7c0cb43..1ba90af 100644 (file)
@@ -25,13 +25,13 @@ TESTCASE_CONFIG = sdnvpn_config.TestcaseConfig(
 
 
 def main():
-    results = Results(COMMON_CONFIG.line_length)
+    conn = os_utils.get_os_connection()
+    results = Results(COMMON_CONFIG.line_length, conn)
 
     results.add_to_summary(0, "=")
     results.add_to_summary(2, "STATUS", "SUBTEST")
     results.add_to_summary(0, "=")
 
-    nova_client = os_utils.get_nova_client()
     neutron_client = os_utils.get_neutron_client()
     conn = os_utils.get_os_connection()
 
@@ -66,46 +66,46 @@ def main():
             neutron_client, TESTCASE_CONFIG.secgroup_name,
             TESTCASE_CONFIG.secgroup_descr)
 
-        compute_nodes = test_utils.assert_and_get_compute_nodes(nova_client)
+        compute_nodes = test_utils.assert_and_get_compute_nodes(conn)
 
         av_zone_1 = "nova:" + compute_nodes[0]
         av_zone_2 = "nova:" + compute_nodes[1]
 
         # boot INTANCES
         vm_2 = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_2_name,
             image_id,
             network_1_id,
             sg_id,
             secgroup_name=TESTCASE_CONFIG.secgroup_name,
             compute_node=av_zone_1)
-        vm_2_ip = test_utils.get_instance_ip(vm_2)
+        vm_2_ip = test_utils.get_instance_ip(conn, vm_2)
 
         vm_3 = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_3_name,
             image_id,
             network_1_id,
             sg_id,
             secgroup_name=TESTCASE_CONFIG.secgroup_name,
             compute_node=av_zone_2)
-        vm_3_ip = test_utils.get_instance_ip(vm_3)
+        vm_3_ip = test_utils.get_instance_ip(conn, vm_3)
 
         vm_5 = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_5_name,
             image_id,
             network_2_id,
             sg_id,
             secgroup_name=TESTCASE_CONFIG.secgroup_name,
             compute_node=av_zone_2)
-        vm_5_ip = test_utils.get_instance_ip(vm_5)
+        vm_5_ip = test_utils.get_instance_ip(conn, vm_5)
 
         # We boot vm5 first because we need vm5_ip for vm4 userdata
         u4 = test_utils.generate_ping_userdata([vm_5_ip])
         vm_4 = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_4_name,
             image_id,
             network_2_id,
@@ -113,7 +113,7 @@ def main():
             secgroup_name=TESTCASE_CONFIG.secgroup_name,
             compute_node=av_zone_1,
             userdata=u4)
-        vm_4_ip = test_utils.get_instance_ip(vm_4)
+        vm_4_ip = test_utils.get_instance_ip(conn, vm_4)
 
         # We boot VM1 at the end because we need to get the IPs first
         # to generate the userdata
@@ -122,7 +122,7 @@ def main():
                                                 vm_4_ip,
                                                 vm_5_ip])
         vm_1 = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_1_name,
             image_id,
             network_1_id,
@@ -244,7 +244,7 @@ def main():
         logger.error("exception occurred while executing testcase_1: %s", e)
         raise
     finally:
-        test_utils.cleanup_nova(nova_client, instance_ids)
+        test_utils.cleanup_nova(conn, instance_ids)
         test_utils.cleanup_glance(conn, image_ids)
         test_utils.cleanup_neutron(neutron_client, floatingip_ids,
                                    bgpvpn_ids, interfaces, subnet_ids,
index 78d5684..a315c32 100644 (file)
@@ -28,14 +28,15 @@ TESTCASE_CONFIG = sdnvpn_config.TestcaseConfig(
     'sdnvpn.test.functest.testcase_10')
 
 
-def monitor(in_data, out_data, vm):
+def monitor(conn, in_data, out_data, vm):
     # At the beginning of ping we might have some
     # failures, so we ignore the first 10 pings
     lines_offset = 20
     while in_data["stop_thread"] is False:
         try:
             time.sleep(1)
-            vm_console_out_lines = vm.get_console_output().split('\n')
+            vm_console_out_lines = conn.compute.\
+                get_server_console_output(vm)['output'].split('\n')
             if lines_offset < len(vm_console_out_lines):
                 for console_line in vm_console_out_lines[lines_offset:-1]:
                     is_ping_error = re.match(r'ping.*KO', console_line)
@@ -64,13 +65,13 @@ def monitor(in_data, out_data, vm):
 
 
 def main():
-    results = Results(COMMON_CONFIG.line_length)
+    conn = os_utils.get_os_connection()
+    results = Results(COMMON_CONFIG.line_length, conn)
 
     results.add_to_summary(0, "=")
     results.add_to_summary(2, "STATUS", "SUBTEST")
     results.add_to_summary(0, "=")
 
-    nova_client = os_utils.get_nova_client()
     neutron_client = os_utils.get_neutron_client()
     conn = os_utils.get_os_connection()
 
@@ -98,24 +99,24 @@ def main():
                                                 TESTCASE_CONFIG.secgroup_name,
                                                 TESTCASE_CONFIG.secgroup_descr)
 
-    compute_nodes = test_utils.assert_and_get_compute_nodes(nova_client)
+    compute_nodes = test_utils.assert_and_get_compute_nodes(conn)
     av_zone_1 = "nova:" + compute_nodes[0]
     av_zone_2 = "nova:" + compute_nodes[1]
 
     # boot INSTANCES
     vm_2 = test_utils.create_instance(
-        nova_client,
+        conn,
         TESTCASE_CONFIG.instance_2_name,
         image_id,
         network_1_id,
         sg_id,
         secgroup_name=TESTCASE_CONFIG.secgroup_name,
         compute_node=av_zone_1)
-    vm2_ip = test_utils.get_instance_ip(vm_2)
+    vm2_ip = test_utils.get_instance_ip(conn, vm_2)
 
     u1 = test_utils.generate_ping_userdata([vm2_ip])
     vm_1 = test_utils.create_instance(
-        nova_client,
+        conn,
         TESTCASE_CONFIG.instance_1_name,
         image_id,
         network_1_id,
@@ -123,11 +124,11 @@ def main():
         secgroup_name=TESTCASE_CONFIG.secgroup_name,
         compute_node=av_zone_1,
         userdata=u1)
-    vm1_ip = test_utils.get_instance_ip(vm_1)
+    vm1_ip = test_utils.get_instance_ip(conn, vm_1)
 
     u3 = test_utils.generate_ping_userdata([vm1_ip, vm2_ip])
     vm_3 = test_utils.create_instance(
-        nova_client,
+        conn,
         TESTCASE_CONFIG.instance_3_name,
         image_id,
         network_1_id,
@@ -135,7 +136,7 @@ def main():
         secgroup_name=TESTCASE_CONFIG.secgroup_name,
         compute_node=av_zone_2,
         userdata=u3)
-    vm3_ip = test_utils.get_instance_ip(vm_3)
+    vm3_ip = test_utils.get_instance_ip(conn, vm_3)
     # We do not put vm_2 id in instance_ids table because we will
     # delete the current instance during the testing process
     instance_ids.extend([vm_1.id, vm_3.id])
@@ -153,19 +154,19 @@ def main():
     monitor_output1 = m.dict()
     monitor_input1["stop_thread"] = False
     monitor_output1["error_msg"] = ""
-    monitor_thread1 = Process(target=monitor, args=(monitor_input1,
+    monitor_thread1 = Process(target=monitor, args=(conn, monitor_input1,
                                                     monitor_output1, vm_1,))
     monitor_input2 = m.dict()
     monitor_output2 = m.dict()
     monitor_input2["stop_thread"] = False
     monitor_output2["error_msg"] = ""
-    monitor_thread2 = Process(target=monitor, args=(monitor_input2,
+    monitor_thread2 = Process(target=monitor, args=(conn, monitor_input2,
                                                     monitor_output2, vm_2,))
     monitor_input3 = m.dict()
     monitor_output3 = m.dict()
     monitor_input3["stop_thread"] = False
     monitor_output3["error_msg"] = ""
-    monitor_thread3 = Process(target=monitor, args=(monitor_input3,
+    monitor_thread3 = Process(target=monitor, args=(conn, monitor_input3,
                                                     monitor_output3, vm_3,))
     # Lists of all monitor threads and their inputs and outputs.
     threads = [monitor_thread1, monitor_thread2, monitor_thread3]
@@ -191,7 +192,7 @@ def main():
             results.add_failure(monitor_err_msg)
         # Stop monitor thread 2 and delete instance vm_2
         thread_inputs[1]["stop_thread"] = True
-        if not os_utils.delete_instance(nova_client, vm_2.id):
+        if not os_utils.delete_instance(conn, vm_2.id):
             logger.error("Fail to delete vm_2 instance during "
                          "testing process")
             raise Exception("Fail to delete instance vm_2.")
@@ -205,7 +206,7 @@ def main():
         # Create a new vm (vm_4) on compute 1 node
         u4 = test_utils.generate_ping_userdata([vm1_ip, vm3_ip])
         vm_4 = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_4_name,
             image_id,
             network_1_id,
@@ -225,7 +226,7 @@ def main():
         monitor_output4 = m.dict()
         monitor_input4["stop_thread"] = False
         monitor_output4["error_msg"] = ""
-        monitor_thread4 = Process(target=monitor, args=(monitor_input4,
+        monitor_thread4 = Process(target=monitor, args=(conn, monitor_input4,
                                                         monitor_output4,
                                                         vm_4,))
         threads.append(monitor_thread4)
@@ -259,7 +260,7 @@ def main():
         for thread in threads:
             thread.join()
 
-        test_utils.cleanup_nova(nova_client, instance_ids)
+        test_utils.cleanup_nova(conn, instance_ids)
         test_utils.cleanup_glance(conn, image_ids)
         test_utils.cleanup_neutron(neutron_client, floatingip_ids, bgpvpn_ids,
                                    interfaces, subnet_ids, router_ids,
index 85dea19..78f01a9 100644 (file)
@@ -24,13 +24,13 @@ TESTCASE_CONFIG = sdnvpn_config.TestcaseConfig(
 
 
 def main():
-    results = Results(COMMON_CONFIG.line_length)
+    conn = os_utils.get_os_connection()
+    results = Results(COMMON_CONFIG.line_length, conn)
 
     results.add_to_summary(0, "=")
     results.add_to_summary(2, "STATUS", "SUBTEST")
     results.add_to_summary(0, "=")
 
-    nova_client = os_utils.get_nova_client()
     neutron_client = os_utils.get_neutron_client()
     conn = os_utils.get_os_connection()
     openstack_nodes = test_utils.get_nodes()
@@ -60,8 +60,7 @@ def main():
             TESTCASE_CONFIG.secgroup_descr)
 
         # Check required number of compute nodes
-        compute_hostname = (
-            nova_client.hypervisors.list()[0].hypervisor_hostname)
+        compute_hostname = conn.compute.hypervisors().next().name
         compute_nodes = [node for node in openstack_nodes
                          if node.is_compute()]
 
@@ -74,7 +73,7 @@ def main():
 
         # boot INSTANCES
         vm_2 = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_2_name,
             image_id,
             network_1_id,
@@ -83,7 +82,7 @@ def main():
             compute_node=av_zone_1)
 
         vm_1 = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_1_name,
             image_id,
             network_1_id,
@@ -128,7 +127,7 @@ def main():
         raise
     finally:
         # Cleanup topology
-        test_utils.cleanup_nova(nova_client, instance_ids)
+        test_utils.cleanup_nova(conn, instance_ids)
         test_utils.cleanup_glance(conn, image_ids)
         test_utils.cleanup_neutron(neutron_client, floatingip_ids, bgpvpn_ids,
                                    interfaces, subnet_ids, router_ids,
index be32d1d..53e5ab9 100644 (file)
@@ -24,13 +24,13 @@ TESTCASE_CONFIG = sdnvpn_config.TestcaseConfig(
 
 
 def main():
-    results = Results(COMMON_CONFIG.line_length)
+    conn = os_utils.get_os_connection()
+    results = Results(COMMON_CONFIG.line_length, conn)
 
     results.add_to_summary(0, "=")
     results.add_to_summary(2, "STATUS", "SUBTEST")
     results.add_to_summary(0, "=")
 
-    nova_client = os_utils.get_nova_client()
     neutron_client = os_utils.get_neutron_client()
     conn = os_utils.get_os_connection()
     openstack_nodes = test_utils.get_nodes()
@@ -60,8 +60,7 @@ def main():
             TESTCASE_CONFIG.secgroup_descr)
 
         # Check required number of compute nodes
-        compute_hostname = (
-            nova_client.hypervisors.list()[0].hypervisor_hostname)
+        compute_hostname = conn.compute.hypervisors().next().name
         compute_nodes = [node for node in openstack_nodes
                          if node.is_compute()]
 
@@ -76,7 +75,7 @@ def main():
 
         # boot INSTANCES
         vm_2 = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_2_name,
             image_id,
             network_1_id,
@@ -85,7 +84,7 @@ def main():
             compute_node=av_zone_1)
 
         vm_1 = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_1_name,
             image_id,
             network_1_id,
@@ -185,7 +184,7 @@ def main():
         raise
     finally:
         # Cleanup topology
-        test_utils.cleanup_nova(nova_client, instance_ids)
+        test_utils.cleanup_nova(conn, instance_ids)
         test_utils.cleanup_glance(conn, image_ids)
         test_utils.cleanup_neutron(neutron_client, floatingip_ids, bgpvpn_ids,
                                    interfaces, subnet_ids, router_ids,
index 2d79b45..4152c67 100644 (file)
@@ -26,7 +26,8 @@ TESTCASE_CONFIG = sdnvpn_config.TestcaseConfig(
 
 
 def main():
-    results = Results(COMMON_CONFIG.line_length)
+    conn = os_utils.get_os_connection()
+    results = Results(COMMON_CONFIG.line_length, conn)
 
     results.add_to_summary(0, "=")
     results.add_to_summary(2, "STATUS", "SUBTEST")
@@ -43,7 +44,6 @@ def main():
     else:
         logger.info("Using old image")
 
-    nova_client = os_utils.get_nova_client()
     neutron_client = os_utils.get_neutron_client()
     conn = os_utils.get_os_connection()
 
@@ -79,7 +79,7 @@ def main():
             neutron_client, TESTCASE_CONFIG.secgroup_name,
             TESTCASE_CONFIG.secgroup_descr)
 
-        compute_nodes = test_utils.assert_and_get_compute_nodes(nova_client)
+        compute_nodes = test_utils.assert_and_get_compute_nodes(conn)
 
         av_zone_1 = "nova:" + compute_nodes[0]
         av_zone_2 = "nova:" + compute_nodes[1]
@@ -91,7 +91,7 @@ def main():
             TESTCASE_CONFIG.extra_route_subnet_mask)
         # boot INTANCES
         vm_1 = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_1_name,
             image_id,
             network_1_id,
@@ -100,7 +100,7 @@ def main():
             secgroup_name=TESTCASE_CONFIG.secgroup_name,
             compute_node=av_zone_1,
             userdata=u1)
-        vm_1_ip = test_utils.get_instance_ip(vm_1)
+        vm_1_ip = test_utils.get_instance_ip(conn, vm_1)
 
         vm1_port = test_utils.get_port(neutron_client, vm_1.id)
         test_utils.update_port_allowed_address_pairs(
@@ -111,7 +111,7 @@ def main():
                 vm1_port['mac_address'])])
 
         vm_2 = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_2_name,
             image_id,
             network_1_id,
@@ -120,7 +120,7 @@ def main():
             secgroup_name=TESTCASE_CONFIG.secgroup_name,
             compute_node=av_zone_1,
             userdata=u1)
-        vm_2_ip = test_utils.get_instance_ip(vm_2)
+        vm_2_ip = test_utils.get_instance_ip(conn, vm_2)
 
         vm2_port = test_utils.get_port(neutron_client, vm_2.id)
         test_utils.update_port_allowed_address_pairs(
@@ -144,7 +144,7 @@ def main():
         u3 = test_utils.generate_ping_userdata(
             [TESTCASE_CONFIG.extra_route_ip])
         vm_3 = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_3_name,
             image_2_id,
             network_1_id,
@@ -208,7 +208,7 @@ def main():
         raise
     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_nova(conn, instance_ids, flavor_ids)
         test_utils.cleanup_glance(conn, image_ids)
         test_utils.cleanup_neutron(neutron_client, floatingip_ids,
                                    bgpvpn_ids, interfaces, subnet_ids,
index 4955f7e..12f3cc4 100644 (file)
@@ -8,6 +8,7 @@
 # http://www.apache.org/licenses/LICENSE-2.0
 #
 
+import base64
 import logging
 import sys
 
@@ -25,13 +26,13 @@ TESTCASE_CONFIG = sdnvpn_config.TestcaseConfig(
 
 
 def main():
-    results = Results(COMMON_CONFIG.line_length)
+    conn = os_utils.get_os_connection()
+    results = Results(COMMON_CONFIG.line_length, conn)
 
     results.add_to_summary(0, "=")
     results.add_to_summary(2, "STATUS", "SUBTEST")
     results.add_to_summary(0, "=")
 
-    nova_client = os_utils.get_nova_client()
     neutron_client = os_utils.get_neutron_client()
     conn = os_utils.get_os_connection()
 
@@ -44,7 +45,8 @@ def main():
         keyfile = open(COMMON_CONFIG.keyfile_path, 'r')
         key = keyfile.read()
         keyfile.close()
-        files = {"/home/cirros/id_rsa": key}
+        files = [{'path': '/home/cirros/id_rsa',
+                  'contents': base64.b64encode(key)}]
 
         image_id = os_utils.create_glance_image(
             conn, TESTCASE_CONFIG.image_name,
@@ -91,7 +93,7 @@ def main():
             neutron_client, TESTCASE_CONFIG.secgroup_name,
             TESTCASE_CONFIG.secgroup_descr)
 
-        compute_nodes = test_utils.assert_and_get_compute_nodes(nova_client)
+        compute_nodes = test_utils.assert_and_get_compute_nodes(conn)
 
         av_zone_1 = "nova:" + compute_nodes[0]
         # av_zone_2 = "nova:" + compute_nodes[1]
@@ -99,7 +101,7 @@ def main():
         # boot INTANCES
         userdata_common = test_utils.generate_userdata_common()
         vm_2 = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_2_name,
             image_id,
             network_1_id,
@@ -111,7 +113,7 @@ def main():
 
 
 #         vm_3 = test_utils.create_instance(
-#             nova_client,
+#             conn,
 #             TESTCASE_CONFIG.instance_3_name,
 #             image_id,
 #             network_1_id,
@@ -122,7 +124,7 @@ def main():
 #             userdata=userdata_common)
 #
 #         vm_5 = test_utils.create_instance(
-#             nova_client,
+#             conn,
 #             TESTCASE_CONFIG.instance_5_name,
 #             image_id,
 #             network_2_id,
@@ -139,7 +141,7 @@ def main():
              # TESTCASE_CONFIG.instance_5_ip
              ])
         vm_4 = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_4_name,
             image_id,
             network_2_id,
@@ -159,7 +161,7 @@ def main():
              # TESTCASE_CONFIG.instance_5_ip
              ])
         vm_1 = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_1_name,
             image_id,
             network_1_id,
@@ -267,7 +269,7 @@ def main():
         logger.error("exception occurred while executing testcase_2: %s", e)
         raise
     finally:
-        test_utils.cleanup_nova(nova_client, instance_ids)
+        test_utils.cleanup_nova(conn, instance_ids)
         test_utils.cleanup_glance(conn, image_ids)
         test_utils.cleanup_neutron(neutron_client, floatingip_ids,
                                    bgpvpn_ids, interfaces, subnet_ids,
index 3d202c5..796feeb 100644 (file)
@@ -34,7 +34,8 @@ TESTCASE_CONFIG = sdnvpn_config.TestcaseConfig(
 
 
 def main():
-    results = Results(COMMON_CONFIG.line_length)
+    conn = os_utils.get_os_connection()
+    results = Results(COMMON_CONFIG.line_length, conn)
     results.add_to_summary(0, "=")
     results.add_to_summary(2, "STATUS", "SUBTEST")
     results.add_to_summary(0, "=")
@@ -180,7 +181,6 @@ def main():
         logger.info("Using old image")
 
     conn = os_utils.get_os_connection()
-    nova_client = os_utils.get_nova_client()
     neutron_client = os_utils.get_neutron_client()
 
     (floatingip_ids, instance_ids, router_ids, network_ids, image_ids,
@@ -259,8 +259,9 @@ def main():
         fake_fip = os_utils.create_floating_ip(neutron_client)
         # pin quagga to some compute
         floatingip_ids.append(fake_fip['fip_id'])
-        compute_node = nova_client.hypervisors.list()[0]
-        quagga_compute_node = "nova:" + compute_node.hypervisor_hostname
+        compute_node = conn.compute.hypervisors().next()
+        compute_node = conn.compute.get_hypervisor(compute_node)
+        quagga_compute_node = "nova:" + compute_node.name
         # Map the hypervisor used above to a compute handle
         # returned by releng's manager
         for comp in computes:
@@ -277,7 +278,7 @@ def main():
             TESTCASE_CONFIG.export_targets)
 
         quagga_vm = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.quagga_instance_name,
             ubuntu_image_id,
             quagga_net_id,
@@ -287,7 +288,7 @@ def main():
             userdata=quagga_bootstrap_script,
             compute_node=quagga_compute_node)
 
-        instance_ids.append(quagga_vm)
+        instance_ids.append(quagga_vm.id)
 
         quagga_vm_port = test_utils.get_port(neutron_client,
                                              quagga_vm.id)
@@ -305,7 +306,7 @@ def main():
         test_utils.attach_instance_to_ext_br(quagga_vm, compute)
 
         testcase = "Bootstrap quagga inside an OpenStack instance"
-        cloud_init_success = test_utils.wait_for_cloud_init(quagga_vm)
+        cloud_init_success = test_utils.wait_for_cloud_init(conn, quagga_vm)
         if cloud_init_success:
             results.add_success(testcase)
         else:
@@ -355,10 +356,10 @@ def main():
         userdata_common = test_utils.generate_ping_userdata(
             [TESTCASE_CONFIG.external_network_ip])
 
-        compute_node = nova_client.hypervisors.list()[0]
-        av_zone_1 = "nova:" + compute_node.hypervisor_hostname
+        compute_node = conn.compute.hypervisors().next()
+        av_zone_1 = "nova:" + compute_node.name
         vm_bgpvpn = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_1_name,
             image_id,
             net_1_id,
@@ -367,7 +368,7 @@ def main():
             secgroup_name=TESTCASE_CONFIG.secgroup_name,
             compute_node=av_zone_1,
             userdata=userdata_common)
-        instance_ids.append(vm_bgpvpn)
+        instance_ids.append(vm_bgpvpn.id)
 
         # wait for VM to get IP
         instance_up = test_utils.wait_for_instances_up(vm_bgpvpn)
@@ -409,7 +410,7 @@ def main():
     finally:
         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_nova(conn, instance_ids, flavor_ids)
         test_utils.cleanup_glance(conn, image_ids)
         test_utils.cleanup_neutron(neutron_client, floatingip_ids,
                                    bgpvpn_ids, interfaces, subnet_ids,
index a29dc12..4c7cc40 100644 (file)
@@ -26,13 +26,13 @@ TESTCASE_CONFIG = sdnvpn_config.TestcaseConfig(
 
 
 def main():
-    results = Results(COMMON_CONFIG.line_length)
+    conn = os_utils.get_os_connection()
+    results = Results(COMMON_CONFIG.line_length, conn)
 
     results.add_to_summary(0, "=")
     results.add_to_summary(2, "STATUS", "SUBTEST")
     results.add_to_summary(0, "=")
 
-    nova_client = os_utils.get_nova_client()
     neutron_client = os_utils.get_neutron_client()
     conn = os_utils.get_os_connection()
 
@@ -72,46 +72,46 @@ def main():
             TESTCASE_CONFIG.secgroup_name,
             TESTCASE_CONFIG.secgroup_descr)
 
-        compute_nodes = test_utils.assert_and_get_compute_nodes(nova_client)
+        compute_nodes = test_utils.assert_and_get_compute_nodes(conn)
 
         av_zone_1 = "nova:" + compute_nodes[0]
         av_zone_2 = "nova:" + compute_nodes[1]
 
         # boot INTANCES
         vm_2 = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_2_name,
             image_id,
             network_1_id,
             sg_id,
             secgroup_name=TESTCASE_CONFIG.secgroup_name,
             compute_node=av_zone_1)
-        vm_2_ip = test_utils.get_instance_ip(vm_2)
+        vm_2_ip = test_utils.get_instance_ip(conn, vm_2)
 
         vm_3 = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_3_name,
             image_id,
             network_1_id,
             sg_id,
             secgroup_name=TESTCASE_CONFIG.secgroup_name,
             compute_node=av_zone_2)
-        vm_3_ip = test_utils.get_instance_ip(vm_3)
+        vm_3_ip = test_utils.get_instance_ip(conn, vm_3)
 
         vm_5 = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_5_name,
             image_id,
             network_2_id,
             sg_id,
             secgroup_name=TESTCASE_CONFIG.secgroup_name,
             compute_node=av_zone_2)
-        vm_5_ip = test_utils.get_instance_ip(vm_5)
+        vm_5_ip = test_utils.get_instance_ip(conn, vm_5)
 
         # We boot vm5 first because we need vm5_ip for vm4 userdata
         u4 = test_utils.generate_ping_userdata([vm_5_ip])
         vm_4 = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_4_name,
             image_id,
             network_2_id,
@@ -119,7 +119,7 @@ def main():
             secgroup_name=TESTCASE_CONFIG.secgroup_name,
             compute_node=av_zone_1,
             userdata=u4)
-        vm_4_ip = test_utils.get_instance_ip(vm_4)
+        vm_4_ip = test_utils.get_instance_ip(conn, vm_4)
 
         # We boot VM1 at the end because we need to get the IPs
         # first to generate the userdata
@@ -128,7 +128,7 @@ def main():
                                                 vm_4_ip,
                                                 vm_5_ip])
         vm_1 = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_1_name,
             image_id,
             network_1_id,
@@ -258,7 +258,7 @@ def main():
         logger.error("exception occurred while executing testcase_4: %s", e)
         raise
     finally:
-        test_utils.cleanup_nova(nova_client, instance_ids)
+        test_utils.cleanup_nova(conn, instance_ids)
         test_utils.cleanup_glance(conn, image_ids)
         test_utils.cleanup_neutron(neutron_client, floatingip_ids,
                                    bgpvpn_ids, interfaces, subnet_ids,
index 381b98b..715b55a 100644 (file)
@@ -35,13 +35,13 @@ TESTCASE_CONFIG = sdnvpn_config.TestcaseConfig(
 
 
 def main():
-    results = Results(COMMON_CONFIG.line_length)
+    conn = os_utils.get_os_connection()
+    results = Results(COMMON_CONFIG.line_length, conn)
 
     results.add_to_summary(0, "=")
     results.add_to_summary(2, "STATUS", "SUBTEST")
     results.add_to_summary(0, "=")
 
-    nova_client = os_utils.get_nova_client()
     neutron_client = os_utils.get_neutron_client()
     conn = os_utils.get_os_connection()
 
@@ -82,17 +82,17 @@ def main():
         test_utils.open_http_port(neutron_client, sg_id)
 
         vm_2 = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_2_name,
             image_id,
             network_2_id,
             sg_id,
             secgroup_name=TESTCASE_CONFIG.secgroup_name)
-        vm_2_ip = test_utils.get_instance_ip(vm_2)
+        vm_2_ip = test_utils.get_instance_ip(conn, vm_2)
 
         u1 = test_utils.generate_ping_userdata([vm_2_ip])
         vm_1 = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_1_name,
             image_id,
             network_1_id,
@@ -168,7 +168,7 @@ def main():
         logger.error("exception occurred while executing testcase_7: %s", e)
         raise
     finally:
-        test_utils.cleanup_nova(nova_client, instance_ids)
+        test_utils.cleanup_nova(conn, instance_ids)
         test_utils.cleanup_glance(conn, image_ids)
         test_utils.cleanup_neutron(neutron_client, floatingip_ids,
                                    bgpvpn_ids, interfaces, subnet_ids,
index cfdb950..adf09e4 100644 (file)
@@ -33,13 +33,13 @@ TESTCASE_CONFIG = sdnvpn_config.TestcaseConfig(
 
 
 def main():
-    results = Results(COMMON_CONFIG.line_length)
+    conn = os_utils.get_os_connection()
+    results = Results(COMMON_CONFIG.line_length, conn)
 
     results.add_to_summary(0, "=")
     results.add_to_summary(2, "STATUS", "SUBTEST")
     results.add_to_summary(0, "=")
 
-    nova_client = os_utils.get_nova_client()
     neutron_client = os_utils.get_neutron_client()
     conn = os_utils.get_os_connection()
 
@@ -79,24 +79,24 @@ def main():
         test_utils.open_icmp(neutron_client, sg_id)
         test_utils.open_http_port(neutron_client, sg_id)
 
-        compute_nodes = test_utils.assert_and_get_compute_nodes(nova_client)
+        compute_nodes = test_utils.assert_and_get_compute_nodes(conn)
         av_zone_1 = "nova:" + compute_nodes[0]
         # spawning the VMs on the same compute because fib flow (21) entries
         # are not created properly if vm1 and vm2 are attached to two
         # different computes
         vm_2 = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_2_name,
             image_id,
             network_2_id,
             sg_id,
             secgroup_name=TESTCASE_CONFIG.secgroup_name,
             compute_node=av_zone_1)
-        vm_2_ip = test_utils.get_instance_ip(vm_2)
+        vm_2_ip = test_utils.get_instance_ip(conn, vm_2)
 
         u1 = test_utils.generate_ping_userdata([vm_2_ip])
         vm_1 = test_utils.create_instance(
-            nova_client,
+            conn,
             TESTCASE_CONFIG.instance_1_name,
             image_id,
             network_1_id,
@@ -176,7 +176,7 @@ def main():
         logger.error("exception occurred while executing testcase_8: %s", e)
         raise
     finally:
-        test_utils.cleanup_nova(nova_client, instance_ids)
+        test_utils.cleanup_nova(conn, instance_ids)
         test_utils.cleanup_glance(conn, image_ids)
         test_utils.cleanup_neutron(neutron_client, floatingip_ids,
                                    bgpvpn_ids, interfaces, subnet_ids,