Merge "Restricted dependency of the novaclient."
[snaps.git] / snaps / openstack / tests / openstack_tests.py
index dab2ea2..c11d1aa 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2016 Cable Television Laboratories, Inc. ("CableLabs")
+# Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
 #                    and others.  All rights reserved.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,6 +15,7 @@
 import re
 
 from snaps import file_utils
+from snaps.openstack.utils import glance_utils
 from snaps.openstack.create_network import NetworkSettings, SubnetSettings
 from snaps.openstack.create_router import RouterSettings
 from snaps.openstack.os_credentials import OSCreds, ProxySettings
@@ -77,6 +78,10 @@ def get_credentials(os_env_file=None, proxy_settings_str=None, ssh_proxy_cmd=Non
         if not identity_api_version:
             identity_api_version = 2
 
+        image_api_version = config.get('image_api_version')
+        if not image_api_version:
+            image_api_version = glance_utils.VERSION_2
+
         proxy_settings = None
         proxy_str = config.get('http_proxy')
         if proxy_str:
@@ -85,34 +90,133 @@ def get_credentials(os_env_file=None, proxy_settings_str=None, ssh_proxy_cmd=Non
 
         os_creds = OSCreds(username=config['username'], password=config['password'],
                            auth_url=config['os_auth_url'], project_name=config['project_name'],
-                           identity_api_version=identity_api_version,
+                           identity_api_version=identity_api_version, image_api_version=image_api_version,
                            proxy_settings=proxy_settings)
 
     logger.info('OS Credentials = ' + str(os_creds))
     return os_creds
 
 
-def cirros_url_image(name):
-    return ImageSettings(name=name, image_user='cirros', img_format='qcow2',
-                         url='http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img')
+def cirros_image_settings(name, url=None, image_metadata=None, kernel_settings=None, ramdisk_settings=None):
+    """
+    Returns the image settings for a Cirros QCOW2 image
+    :param name: the name of the image
+    :param url: the image's URL
+    :param image_metadata: dict() values to override URLs for disk, kernel, and ramdisk
+    :param kernel_settings: override to the kernel settings from the image_metadata
+    :param ramdisk_settings: override to the ramdisk settings from the image_metadata
+    :return:
+    """
+    if image_metadata and 'cirros' in image_metadata:
+        metadata = image_metadata['cirros']
+    else:
+        metadata = image_metadata
+
+    if metadata and 'disk_url' in metadata:
+        url = metadata['disk_url']
+    if not url:
+        url = 'http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img'
+
+    if metadata and 'kernel_url' in metadata and kernel_settings is None:
+        kernel_image_settings = ImageSettings(name=name + '-kernel', image_user='cirros', img_format='qcow2',
+                                              url=metadata['kernel_url'])
+    else:
+        kernel_image_settings = kernel_settings
+
+    if metadata and 'ramdisk_url' in metadata and ramdisk_settings is None:
+        ramdisk_image_settings = ImageSettings(name=name + '-ramdisk', image_user='cirros', img_format='qcow2',
+                                               url=metadata['ramdisk_url'])
+    else:
+        ramdisk_image_settings = ramdisk_settings
+
+    extra_properties = None
+    if metadata and 'extra_properties' in metadata:
+        extra_properties = metadata['extra_properties']
+
+    return ImageSettings(name=name, image_user='cirros', img_format='qcow2', url=url,
+                         extra_properties=extra_properties,
+                         kernel_image_settings=kernel_image_settings,
+                         ramdisk_image_settings=ramdisk_image_settings)
+
 
+def file_image_test_settings(name, file_path, image_user='cirros'):
+    return ImageSettings(name=name, image_user=image_user, img_format='qcow2', image_file=file_path)
 
-def file_image_test_settings(name, file_path):
-    return ImageSettings(name=name, image_user='cirros', img_format='qcow2',
-                         image_file=file_path)
 
+def centos_image_settings(name, url=None, image_metadata=None):
+    """
+    Returns the image settings for a Centos QCOW2 image
+    :param name: the name of the image
+    :param url: the image's URL
+    :param image_metadata: dict() values to override URLs for disk, kernel, and ramdisk
+    :return:
+    """
+    if image_metadata and 'centos' in image_metadata:
+        metadata = image_metadata['centos']
+    else:
+        metadata = image_metadata
+
+    if metadata and 'disk_url' in metadata:
+        url = metadata['disk_url']
+    if not url:
+        url = 'http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2'
+
+    kernel_image_settings = None
+    if metadata and 'kernel_url' in metadata:
+        kernel_image_settings = ImageSettings(name=name + '-kernel', image_user='centos', img_format='qcow2',
+                                              url=metadata['kernel_url'])
+    ramdisk_image_settings = None
+    if metadata and 'ramdisk_url' in metadata:
+        ramdisk_image_settings = ImageSettings(name=name + '-ramdisk', image_user='centos', img_format='qcow2',
+                                               url=metadata['ramdisk_url'])
+
+    extra_properties = None
+    if metadata and 'extra_properties' in metadata:
+        extra_properties = metadata['extra_properties']
+
+    return ImageSettings(
+        name=name, image_user='centos', img_format='qcow2',
+        extra_properties=extra_properties, url=url,
+        nic_config_pb_loc='./provisioning/ansible/centos-network-setup/playbooks/configure_host.yml',
+        kernel_image_settings=kernel_image_settings,
+        ramdisk_image_settings=ramdisk_image_settings)
+
+
+def ubuntu_image_settings(name, url=None, image_metadata=None):
+    """
+    Returns the image settings for a Ubuntu QCOW2 image
+    :param name: the name of the image
+    :param url: the image's URL
+    :param image_metadata: dict() values to override URLs for disk, kernel, and ramdisk
+    :return:
+    """
+    if image_metadata and 'ubuntu' in image_metadata:
+        metadata = image_metadata['ubuntu']
+    else:
+        metadata = image_metadata
+
+    if metadata and 'disk_url' in metadata:
+        url = metadata['disk_url']
+    if not url:
+        url = 'http://uec-images.ubuntu.com/releases/trusty/14.04/ubuntu-14.04-server-cloudimg-amd64-disk1.img'
 
-def centos_url_image(name):
-    return ImageSettings(name=name, image_user='centos', img_format='qcow2',
-                         url='http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2',
-                         nic_config_pb_loc='./provisioning/ansible/centos-network-setup/playbooks/configure_host.yml')
+    kernel_image_settings = None
+    if metadata and 'kernel_url' in metadata:
+        kernel_image_settings = ImageSettings(name=name + '-kernel', url=metadata['kernel_url'])
+    ramdisk_image_settings = None
+    if metadata and 'ramdisk_url' in metadata:
+        ramdisk_image_settings = ImageSettings(name=name + '-ramdisk', url=metadata['ramdisk_url'])
 
+    extra_properties = None
+    if metadata and 'extra_properties' in metadata:
+        extra_properties = metadata['extra_properties']
 
-def ubuntu_url_image(name):
     return ImageSettings(
         name=name, image_user='ubuntu', img_format='qcow2',
-        url='http://uec-images.ubuntu.com/releases/trusty/14.04/ubuntu-14.04-server-cloudimg-amd64-disk1.img',
-        nic_config_pb_loc='./provisioning/ansible/ubuntu-network-setup/playbooks/configure_host.yml')
+        extra_properties=extra_properties, url=url,
+        nic_config_pb_loc='./provisioning/ansible/ubuntu-network-setup/playbooks/configure_host.yml',
+        kernel_image_settings=kernel_image_settings,
+        ramdisk_image_settings=ramdisk_image_settings)
 
 
 def get_priv_net_config(net_name, subnet_name, router_name=None, cidr='10.55.0.0/24', external_net=None):