Fixes related to guest creation tests.
* Make image creation a noop if image already exists * Two admin projects are created, one in the default domain and one in the admin domain. To differentiate between them specify the admin domain when searching for the project id. This, in turn, ensures that the security group rules are applied to the correct 'default' security group. * Fix cirros image name
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
"""Code for configuring glance."""
|
||||
|
||||
import logging
|
||||
import zaza.utilities.openstack as openstack_utils
|
||||
|
||||
|
||||
@@ -35,11 +36,14 @@ def add_cirros_image(glance_client=None):
|
||||
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, 'cirros'):
|
||||
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,
|
||||
'cirros')
|
||||
|
||||
|
||||
def add_lts_image(glance_client=None):
|
||||
@@ -52,11 +56,13 @@ def add_lts_image(glance_client=None):
|
||||
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, 'bionic'):
|
||||
logging.warning('Using existing glance image')
|
||||
else:
|
||||
image_url = openstack_utils.find_ubuntu_image(
|
||||
release='bionic',
|
||||
arch='amd64')
|
||||
openstack_utils.create_image(
|
||||
glance_client,
|
||||
image_url,
|
||||
'bionic')
|
||||
|
||||
@@ -30,7 +30,7 @@ class BaseGuestCreateTest(unittest.TestCase):
|
||||
|
||||
boot_tests = {
|
||||
'cirros': {
|
||||
'image_name': 'cirrosimage',
|
||||
'image_name': 'cirros',
|
||||
'flavor_name': 'm1.tiny',
|
||||
'username': 'cirros',
|
||||
'bootstring': 'gocubsgo',
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user