[Verify] Fixing issue with discovering images

When we request a list of images to choose one of them for tests,
we should make sure all images are active, they have names and they
are PUBLIC. If images are not public, we will have failures of Tempest
tests as described in the bug.

Closes-Bug: #1564431

Change-Id: Ia2cc1586956dcf1fff4c7859faf39fdd98ba35e2
This commit is contained in:
Yaroslav Lobankov 2016-04-05 19:03:07 +03:00
parent ffe91c9c07
commit 78ab9d22f9
3 changed files with 32 additions and 38 deletions

View File

@ -650,13 +650,13 @@
# Image container format to use when creating the image (string value)
#container_format = bare
# Regular expression for name of an image to discover it in the cloud
# and use it for the tests. Note that when Rally is searching for the
# image, case insensitive matching is performed. Specify nothing
# ('name_regex =') if you want to disable discovering. In this case
# Rally will create needed resources by itself if the values for the
# corresponding config options are not specified in the Tempest config
# file (string value)
# Regular expression for name of a public image to discover it in the
# cloud and use it for the tests. Note that when Rally is searching
# for the image, case insensitive matching is performed. Specify
# nothing ('name_regex =') if you want to disable discovering. In this
# case Rally will create needed resources by itself if the values for
# the corresponding config options are not specified in the Tempest
# config file (string value)
#name_regex = ^.*(cirros|testvm).*$
@ -689,7 +689,7 @@
# How many concurrent threads use for serving users context (integer
# value)
#resource_management_workers = 30
#resource_management_workers = 20
# ID of domain in which projects will be created. (string value)
#project_domain = default

View File

@ -50,14 +50,14 @@ IMAGE_OPTS = [
help="Image container format to use when creating the image"),
cfg.StrOpt("name_regex",
default="^.*(cirros|testvm).*$",
help="Regular expression for name of an image to discover it "
"in the cloud and use it for the tests. Note that when "
"Rally is searching for the image, case insensitive "
"matching is performed. Specify nothing ('name_regex =') "
"if you want to disable discovering. In this case Rally "
"will create needed resources by itself if the values "
"for the corresponding config options are not specified "
"in the Tempest config file")
help="Regular expression for name of a public image to "
"discover it in the cloud and use it for the tests. "
"Note that when Rally is searching for the image, case "
"insensitive matching is performed. Specify nothing "
"('name_regex =') if you want to disable discovering. "
"In this case Rally will create needed resources by "
"itself if the values for the corresponding config "
"options are not specified in the Tempest config file")
]
ROLE_OPTS = [
@ -422,18 +422,20 @@ class TempestResourcesContext(utils.RandomNameGeneratorMixin):
glance_wrap = glance_wrapper.wrap(self.clients.glance, self)
if CONF.image.name_regex:
LOG.debug("Trying to discover an image with name matching "
LOG.debug("Trying to discover a public image with name matching "
"regular expression '%s'. Note that case insensitive "
"matching is performed" % CONF.image.name_regex)
img_list = [img for img in self.clients.glance().images.list()
if img.status.lower() == "active" and img.name]
for img in img_list:
if re.match(CONF.image.name_regex, img.name, re.IGNORECASE):
LOG.debug("The following image discovered: '{0}'. Using "
"image '{0}' for the tests".format(img.name))
images = glance_wrap.list_images(status="active",
visibility="public")
for img in images:
if img.name and re.match(CONF.image.name_regex,
img.name, re.IGNORECASE):
LOG.debug(
"The following public image discovered: '{0}'. "
"Using image '{0}' for the tests".format(img.name))
return img
LOG.debug("There is no image with name matching "
LOG.debug("There is no public image with name matching "
"regular expression '%s'" % CONF.image.name_regex)
params = {
@ -442,7 +444,7 @@ class TempestResourcesContext(utils.RandomNameGeneratorMixin):
"container_format": CONF.image.container_format,
"image_location": os.path.join(_create_or_get_data_dir(),
self.image_name),
"is_public": True
"visibility": "public"
}
LOG.debug("Creating image '%s'" % params["name"])
image = glance_wrap.create_image(**params)

View File

@ -404,22 +404,14 @@ class TempestResourcesContextTestCase(test.TestCase):
@mock.patch("rally.plugins.openstack.wrappers.glance.wrap")
def test__discover_or_create_image_when_image_exists(self, mock_wrap):
client = self.context.clients.glance()
client.images.list.return_value = [fakes.FakeImage(name="CirrOS",
status="active")]
client = mock_wrap.return_value
client.list_images.return_value = [fakes.FakeImage(name="CirrOS")]
image = self.context._discover_or_create_image()
self.assertEqual("CirrOS", image.name)
self.assertEqual(0, client.create_image.call_count)
self.assertEqual(0, len(self.context._created_images))
# @mock.patch("six.moves.builtins.open")
# def test__discover_or_create_image(self, mock_wrap, mock_open):
# client = self.context.clients.glance()
# client.images.create.side_effect = [fakes.FakeImage(id="id1")]
# image = self.context._discover_or_create_image()
# self.assertEqual("id1", image.id)
# self.assertEqual("id1", self.context._created_images[0].id)
@mock.patch("rally.plugins.openstack.wrappers.glance.wrap")
def test__discover_or_create_image(self, mock_wrap):
client = mock_wrap.return_value
@ -435,7 +427,7 @@ class TempestResourcesContextTestCase(test.TestCase):
image_location=mock.ANY,
disk_format=CONF.image.disk_format,
name=mock.ANY,
is_public=True)
visibility="public")
def test__discover_or_create_flavor_when_flavor_exists(self):
client = self.context.clients.nova()