Merge pull request #124 from gnuoy/nova-launch-noop-fixes

Fixes related to guest creation tests.
This commit is contained in:
David Ames
2018-09-12 08:14:34 -07:00
committed by GitHub
5 changed files with 67 additions and 18 deletions
@@ -302,6 +302,20 @@ class TestOpenStackUtils(ut_utils.BaseTestCase):
self.build_opener.assert_called_once_with(ProxyHandler_mock)
self.ProxyHandler.assert_called_once_with({'http': 'http://squidy'})
def test_get_images_by_name(self):
image_mock1 = mock.MagicMock()
image_mock1.name = 'bob'
image_mock2 = mock.MagicMock()
image_mock2.name = 'bill'
glance_client = mock.MagicMock()
glance_client.images.list.return_value = [image_mock1, image_mock2]
self.assertEqual(
openstack_utils.get_images_by_name(glance_client, 'bob'),
[image_mock1])
self.assertEqual(
openstack_utils.get_images_by_name(glance_client, 'frank'),
[])
def test_find_cirros_image(self):
urllib_opener_mock = mock.MagicMock()
self.patch_object(openstack_utils, "get_urllib_opener")
+34 -15
View File
@@ -14,8 +14,13 @@
"""Code for configuring glance."""
import logging
import zaza.utilities.openstack as openstack_utils
CIRROS_IMAGE_NAME = "cirros"
LTS_RELEASE = "bionic"
LTS_IMAGE_NAME = "bionic"
def basic_setup():
"""Run setup for testing glance.
@@ -25,38 +30,52 @@ def basic_setup():
"""
def add_cirros_image(glance_client=None):
def add_cirros_image(glance_client=None, image_name=None):
"""Add a cirros image to the current deployment.
:param glance: Authenticated glanceclient
:type glance: glanceclient.Client
:param image_name: Label for the image in glance
:type image_name: str
"""
image_name = image_name or CIRROS_IMAGE_NAME
if not glance_client:
keystone_session = openstack_utils.get_overcloud_keystone_session()
glance_client = openstack_utils.get_glance_session_client(
keystone_session)
image_url = openstack_utils.find_cirros_image(arch='x86_64')
openstack_utils.create_image(
glance_client,
image_url,
'cirros')
if openstack_utils.get_images_by_name(glance_client, image_name):
logging.warning('Using existing glance image')
else:
image_url = openstack_utils.find_cirros_image(arch='x86_64')
openstack_utils.create_image(
glance_client,
image_url,
image_name)
def add_lts_image(glance_client=None):
def add_lts_image(glance_client=None, image_name=None, release=None):
"""Add an Ubuntu LTS image to the current deployment.
:param glance: Authenticated glanceclient
:type glance: glanceclient.Client
:param image_name: Label for the image in glance
:type image_name: str
:param release: Name of ubuntu release.
:type release: str
"""
image_name = image_name or LTS_IMAGE_NAME
release = release or LTS_RELEASE
if not glance_client:
keystone_session = openstack_utils.get_overcloud_keystone_session()
glance_client = openstack_utils.get_glance_session_client(
keystone_session)
image_url = openstack_utils.find_ubuntu_image(
release='bionic',
arch='amd64')
print(image_url)
openstack_utils.create_image(
glance_client,
image_url,
'bionic')
if openstack_utils.get_images_by_name(glance_client, image_name):
logging.warning('Using existing glance image')
else:
image_url = openstack_utils.find_ubuntu_image(
release=release,
arch='amd64')
openstack_utils.create_image(
glance_client,
image_url,
image_name)
+4 -3
View File
@@ -23,6 +23,7 @@ import unittest
import zaza.model as model
import zaza.utilities.openstack as openstack_utils
import zaza.charm_tests.nova.utils as nova_utils
import zaza.charm_tests.glance.setup as glance_setup
class BaseGuestCreateTest(unittest.TestCase):
@@ -30,7 +31,7 @@ class BaseGuestCreateTest(unittest.TestCase):
boot_tests = {
'cirros': {
'image_name': 'cirrosimage',
'image_name': 'cirros',
'flavor_name': 'm1.tiny',
'username': 'cirros',
'bootstring': 'gocubsgo',
@@ -113,7 +114,7 @@ class CirrosGuestCreateTest(BaseGuestCreateTest):
def test_launch_small_cirros_instance(self):
"""Launch a cirros instance and test connectivity."""
self.launch_instance('cirros')
self.launch_instance(glance_setup.CIRROS_IMAGE_NAME)
class LTSGuestCreateTest(BaseGuestCreateTest):
@@ -121,4 +122,4 @@ class LTSGuestCreateTest(BaseGuestCreateTest):
def test_launch_small_cirros_instance(self):
"""Launch a cirros instance and test connectivity."""
self.launch_instance('bionic')
self.launch_instance(glance_setup.LTS_IMAGE_NAME)
+1
View File
@@ -114,6 +114,7 @@ def setup_sdn(network_config, keystone_session=None):
project_id = openstack_utils.get_project_id(
keystone_client,
"admin",
domain_name="admin_domain",
)
# Network Setup
subnetpools = False
+14
View File
@@ -1366,6 +1366,20 @@ def get_urllib_opener():
return urllib.request.build_opener(handler)
def get_images_by_name(glance, image_name):
"""Get all glance image objects with the given name.
:param glance: Authenticated glanceclient
:type glance: glanceclient.Client
:param image_name: Name of image
:type image_name: str
:returns: List of glance images
:rtype: [glanceclient.v2.image, ...]
"""
return [i for i in glance.images.list() if image_name == i.name]
def find_cirros_image(arch):
"""Return the url for the latest cirros image for the given architecture.