Nova: Refactor utils._boot_servers to generate its own name prefix
Previously, _boot_servers() required a server name prefix; it now generates its own if one is not provided, moving name generation into the utility instead of needing to put it in the scenario. Change-Id: Ie3b6a8ff06d7f05e15fdff4e338c3705f6d0124a
This commit is contained in:
parent
ee7e936dd3
commit
222f39b02f
@ -115,6 +115,4 @@ class GlanceImages(utils.GlanceScenario, nova_utils.NovaScenario):
|
||||
image_location,
|
||||
disk_format)
|
||||
image_id = image.id
|
||||
server_name = self._generate_random_name(prefix="rally_novaserver_")
|
||||
self._boot_servers(server_name, image_id,
|
||||
flavor, number_instances, **kwargs)
|
||||
self._boot_servers(image_id, flavor, number_instances, **kwargs)
|
||||
|
@ -459,22 +459,24 @@ class NovaScenario(base.Scenario):
|
||||
self.clients("nova").keypairs.delete(keypair_name)
|
||||
|
||||
@base.atomic_action_timer("nova.boot_servers")
|
||||
def _boot_servers(self, name_prefix, image_id, flavor_id,
|
||||
requests, instances_amount=1, **kwargs):
|
||||
def _boot_servers(self, image_id, flavor_id, requests, name_prefix=None,
|
||||
instances_amount=1, **kwargs):
|
||||
"""Boot multiple servers.
|
||||
|
||||
Returns when all the servers are actually booted and are in the
|
||||
"Active" state.
|
||||
|
||||
:param name_prefix: The prefix to use while naming the created servers.
|
||||
The rest of the server names will be '_No.'
|
||||
:param image_id: ID of the image to be used for server creation
|
||||
:param flavor_id: ID of the flavor to be used for server creation
|
||||
:param requests: Number of booting requests to perform
|
||||
:param name_prefix: The prefix to use while naming the created servers.
|
||||
The rest of the server names will be '_<number>'
|
||||
:param instances_amount: Number of instances to boot per each request
|
||||
|
||||
:returns: List of created server objects
|
||||
"""
|
||||
if not name_prefix:
|
||||
name_prefix = self._generate_random_name()
|
||||
for i in range(requests):
|
||||
self.clients("nova").servers.create("%s_%d" % (name_prefix, i),
|
||||
image_id, flavor_id,
|
||||
|
@ -62,15 +62,13 @@ class GlanceImagesTestCase(test.TestCase):
|
||||
"url", "df", fakearg="f")
|
||||
mock_delete.assert_called_once_with(fake_image)
|
||||
|
||||
@mock.patch(GLANCE_IMAGES + "._generate_random_name")
|
||||
@mock.patch(GLANCE_IMAGES + "._boot_servers")
|
||||
@mock.patch(GLANCE_IMAGES + "._create_image")
|
||||
@mock.patch("rally.benchmark.runners.base.osclients")
|
||||
def test_create_image_and_boot_instances(self,
|
||||
mock_osclients,
|
||||
mock_create_image,
|
||||
mock_boot_servers,
|
||||
mock_random_name):
|
||||
mock_boot_servers):
|
||||
glance_scenario = images.GlanceImages()
|
||||
nova_scenario = servers.NovaServers()
|
||||
fc = fakes.FakeClients()
|
||||
@ -85,7 +83,6 @@ class GlanceImagesTestCase(test.TestCase):
|
||||
fake_servers = [object() for i in range(5)]
|
||||
mock_create_image.return_value = fake_image
|
||||
mock_boot_servers.return_value = fake_servers
|
||||
mock_random_name.return_value = "random_name"
|
||||
kwargs = {"fakearg": "f"}
|
||||
with mock.patch("rally.plugins.openstack.scenarios."
|
||||
"glance.utils.time.sleep"):
|
||||
@ -94,6 +91,5 @@ class GlanceImagesTestCase(test.TestCase):
|
||||
5, **kwargs)
|
||||
mock_create_image.assert_called_once_with("cf",
|
||||
"url", "df")
|
||||
mock_boot_servers.assert_called_once_with("random_name",
|
||||
"image-id-0",
|
||||
mock_boot_servers.assert_called_once_with("image-id-0",
|
||||
"fid", 5, **kwargs)
|
||||
|
@ -433,7 +433,7 @@ class NovaScenarioTestCase(test.TestCase):
|
||||
mock_clients("nova").servers.list.return_value = [self.server,
|
||||
self.server1]
|
||||
nova_scenario = utils.NovaScenario()
|
||||
nova_scenario._boot_servers("prefix", "image", "flavor", 2)
|
||||
nova_scenario._boot_servers("image", "flavor", 2)
|
||||
expected = [
|
||||
mock.call(
|
||||
self.server, is_ready=self.res_is.mock(),
|
||||
|
Loading…
Reference in New Issue
Block a user