Merge "Add option to configure flavor disk size"

This commit is contained in:
Zuul 2019-12-12 15:08:43 +00:00 committed by Gerrit Code Review
commit e62315115a
3 changed files with 35 additions and 16 deletions

View File

@ -67,6 +67,15 @@ OPTS = {"openstack": [
deprecated_group="tempest",
help="Alternate reference flavor RAM size used by test that "
"need two flavors, like those that resize an instance"),
cfg.IntOpt("flavor_ref_disk",
default="5",
help="Primary flavor disk size in GiB used by most of the test "
"cases"),
cfg.IntOpt("flavor_ref_alt_disk",
default="5",
help="Alternate reference flavor disk size in GiB used by "
"tests that need two flavors, like those that resize an "
"instance"),
cfg.IntOpt("heat_instance_type_ram",
default="64",
deprecated_group="tempest",

View File

@ -76,10 +76,13 @@ class TempestContext(context.VerifierContext):
helper_method=self._discover_or_create_image)
self._configure_option("compute", "flavor_ref",
helper_method=self._discover_or_create_flavor,
flv_ram=conf.CONF.openstack.flavor_ref_ram)
flv_ram=conf.CONF.openstack.flavor_ref_ram,
flv_disk=conf.CONF.openstack.flavor_ref_disk)
self._configure_option("compute", "flavor_ref_alt",
helper_method=self._discover_or_create_flavor,
flv_ram=conf.CONF.openstack.flavor_ref_alt_ram)
flv_ram=conf.CONF.openstack.flavor_ref_alt_ram,
flv_disk=conf.CONF.openstack.flavor_ref_alt_disk
)
if "neutron" in self.available_services:
neutronclient = self.clients.neutron()
if neutronclient.list_networks(shared=True)["networks"]:
@ -242,14 +245,15 @@ class TempestContext(context.VerifierContext):
return image_obj
def _discover_or_create_flavor(self, flv_ram):
def _discover_or_create_flavor(self, flv_ram, flv_disk):
novaclient = self.clients.nova()
LOG.debug("Trying to discover a flavor with the following "
"properties: RAM = %dMB, VCPUs = 1, disk = 0GB." % flv_ram)
LOG.debug("Trying to discover a flavor with the following properties: "
"RAM = %(ram)dMB, VCPUs = 1, disk >= %(disk)dGiB." %
{"ram": flv_ram, "disk": flv_disk})
for flavor in novaclient.flavors.list():
if (flavor.ram == flv_ram and
flavor.vcpus == 1 and flavor.disk == 0):
flavor.vcpus == 1 and flavor.disk >= flv_disk):
LOG.debug("The following flavor discovered: '{0}'. "
"Using flavor '{0}' (ID = {1}) for the tests."
.format(flavor.name, flavor.id))
@ -261,10 +265,11 @@ class TempestContext(context.VerifierContext):
"name": self.generate_random_name(),
"ram": flv_ram,
"vcpus": 1,
"disk": 0
"disk": flv_disk
}
LOG.debug("Creating flavor '%s' with the following properties: RAM "
"= %dMB, VCPUs = 1, disk = 0GB." % (params["name"], flv_ram))
"= %dMB, VCPUs = 1, disk = %dGB." %
(params["name"], flv_ram, flv_disk))
flavor = novaclient.flavors.create(**params)
LOG.debug("Flavor '%s' (ID = %s) has been successfully created!"
% (flavor.name, flavor.id))

View File

@ -200,7 +200,8 @@ class TempestContextTestCase(test.TestCase):
self.context.conf.set("compute", "flavor_ref", "")
self.context._configure_option("compute", "flavor_ref",
helper_method=helper_method, flv_ram=64)
helper_method=helper_method, flv_ram=64,
flv_disk=5)
self.assertEqual(1, helper_method.call_count)
result = self.context.conf.get("compute", "flavor_ref")
@ -234,9 +235,9 @@ class TempestContextTestCase(test.TestCase):
def test__discover_or_create_flavor_when_flavor_exists(self):
client = self.context.clients.nova()
client.flavors.list.return_value = [fakes.FakeFlavor(id="id1", ram=64,
vcpus=1, disk=0)]
vcpus=1, disk=5)]
flavor = self.context._discover_or_create_flavor(64)
flavor = self.context._discover_or_create_flavor(64, 5)
self.assertEqual("id1", flavor.id)
self.assertEqual(0, len(self.context._created_flavors))
@ -245,7 +246,7 @@ class TempestContextTestCase(test.TestCase):
client.flavors.list.return_value = []
client.flavors.create.side_effect = [fakes.FakeFlavor(id="id1")]
flavor = self.context._discover_or_create_flavor(64)
flavor = self.context._discover_or_create_flavor(64, 5)
self.assertEqual("id1", flavor.id)
self.assertEqual("id1", self.context._created_flavors[0].id)
@ -363,10 +364,12 @@ class TempestContextTestCase(test.TestCase):
helper_method=ctx._discover_or_create_image),
mock.call("compute", "flavor_ref",
helper_method=ctx._discover_or_create_flavor,
flv_ram=config.CONF.openstack.flavor_ref_ram),
flv_ram=config.CONF.openstack.flavor_ref_ram,
flv_disk=config.CONF.openstack.flavor_ref_disk),
mock.call("compute", "flavor_ref_alt",
helper_method=ctx._discover_or_create_flavor,
flv_ram=config.CONF.openstack.flavor_ref_alt_ram)],
flv_ram=config.CONF.openstack.flavor_ref_alt_ram,
flv_disk=config.CONF.openstack.flavor_ref_alt_disk)],
mock__configure_option.call_args_list)
mock_create_dir.reset_mock()
@ -401,10 +404,12 @@ class TempestContextTestCase(test.TestCase):
helper_method=ctx._discover_or_create_image),
mock.call("compute", "flavor_ref",
helper_method=ctx._discover_or_create_flavor,
flv_ram=config.CONF.openstack.flavor_ref_ram),
flv_ram=config.CONF.openstack.flavor_ref_ram,
flv_disk=config.CONF.openstack.flavor_ref_disk),
mock.call("compute", "flavor_ref_alt",
helper_method=ctx._discover_or_create_flavor,
flv_ram=config.CONF.openstack.flavor_ref_alt_ram),
flv_ram=config.CONF.openstack.flavor_ref_alt_ram,
flv_disk=config.CONF.openstack.flavor_ref_alt_disk),
mock.call("compute", "fixed_network_name",
helper_method=ctx._create_network_resources),
mock.call("orchestration", "instance_type",