Merge "Shifting ._generate_random_name() call"

This commit is contained in:
Jenkins 2015-02-06 11:51:24 +00:00 committed by Gerrit Code Review
commit bdbc127294
8 changed files with 46 additions and 59 deletions

View File

@ -219,8 +219,7 @@ class CinderVolumes(utils.CinderScenario,
"use 'size' instead.") "use 'size' instead.")
size = kwargs["volume_size"] size = kwargs["volume_size"]
server = self._boot_server( server = self._boot_server(image, flavor, **kwargs)
self._generate_random_name(), image, flavor, **kwargs)
volume = self._create_volume(size, **kwargs) volume = self._create_volume(size, **kwargs)
self._attach_volume(server, volume) self._attach_volume(server, volume)

View File

@ -113,8 +113,8 @@ class NovaSecGroup(utils.NovaScenario):
rules_per_security_group) rules_per_security_group)
secgroups_names = [sg.name for sg in security_groups] secgroups_names = [sg.name for sg in security_groups]
server = self._boot_server(self._generate_random_name(), image, server = self._boot_server(image, flavor,
flavor, security_groups=secgroups_names) security_groups=secgroups_names)
action_name = "nova.get_attached_security_groups" action_name = "nova.get_attached_security_groups"
with base.AtomicAction(self, action_name): with base.AtomicAction(self, action_name):

View File

@ -60,8 +60,7 @@ class NovaServers(utils.NovaScenario,
detailed information about all of them detailed information about all of them
:param kwargs: Optional additional arguments for server creation :param kwargs: Optional additional arguments for server creation
""" """
self._boot_server( self._boot_server(image, flavor, **kwargs)
self._generate_random_name(), image, flavor, **kwargs)
self._list_servers(detailed) self._list_servers(detailed)
@validation.required_services(consts.Service.NOVA) @validation.required_services(consts.Service.NOVA)
@ -100,8 +99,7 @@ class NovaServers(utils.NovaScenario,
:param force_delete: True if force_delete should be used :param force_delete: True if force_delete should be used
:param kwargs: Optional additional arguments for server creation :param kwargs: Optional additional arguments for server creation
""" """
server = self._boot_server( server = self._boot_server(image, flavor, **kwargs)
self._generate_random_name(), image, flavor, **kwargs)
self.sleep_between(min_sleep, max_sleep) self.sleep_between(min_sleep, max_sleep)
self._delete_server(server, force=force_delete) self._delete_server(server, force=force_delete)
@ -132,8 +130,7 @@ class NovaServers(utils.NovaScenario,
""" """
volume = self._create_volume(volume_size, imageRef=image) volume = self._create_volume(volume_size, imageRef=image)
block_device_mapping = {"vda": "%s:::1" % volume.id} block_device_mapping = {"vda": "%s:::1" % volume.id}
server = self._boot_server(self._generate_random_name(), server = self._boot_server(image, flavor,
image, flavor,
block_device_mapping=block_device_mapping, block_device_mapping=block_device_mapping,
**kwargs) **kwargs)
self.sleep_between(min_sleep, max_sleep) self.sleep_between(min_sleep, max_sleep)
@ -170,8 +167,7 @@ class NovaServers(utils.NovaScenario,
raise rally_exceptions.InvalidConfigException( raise rally_exceptions.InvalidConfigException(
"Invalid server actions configuration \'%(actions)s\' due to: " "Invalid server actions configuration \'%(actions)s\' due to: "
"%(error)s" % {"actions": str(actions), "error": str(error)}) "%(error)s" % {"actions": str(actions), "error": str(error)})
server = self._boot_server(self._generate_random_name(), server = self._boot_server(image, flavor, **kwargs)
image, flavor, **kwargs)
for action in action_builder.build_actions(actions, server): for action in action_builder.build_actions(actions, server):
action() action()
self._delete_server(server, force=force_delete) self._delete_server(server, force=force_delete)
@ -191,13 +187,12 @@ class NovaServers(utils.NovaScenario,
:param force_delete: True if force_delete should be used :param force_delete: True if force_delete should be used
:param kwargs: Optional additional arguments for server creation :param kwargs: Optional additional arguments for server creation
""" """
server_name = self._generate_random_name()
server = self._boot_server(server_name, image, flavor, **kwargs) server = self._boot_server(image, flavor, **kwargs)
image = self._create_image(server) image = self._create_image(server)
self._delete_server(server, force=force_delete) self._delete_server(server, force=force_delete)
server = self._boot_server(server_name, image.id, flavor, **kwargs) server = self._boot_server(image.id, flavor, **kwargs)
self._delete_server(server, force=force_delete) self._delete_server(server, force=force_delete)
self._delete_image(image) self._delete_image(image)
@ -217,9 +212,8 @@ class NovaServers(utils.NovaScenario,
:param auto_assign_nic: True if NICs should be assigned :param auto_assign_nic: True if NICs should be assigned
:param kwargs: Optional additional arguments for server creation :param kwargs: Optional additional arguments for server creation
""" """
server_name = self._generate_random_name() self._boot_server(image, flavor,
self._boot_server(server_name, image, flavor, auto_assign_nic, auto_assign_nic=auto_assign_nic, **kwargs)
**kwargs)
@types.set(image=types.ImageResourceType, @types.set(image=types.ImageResourceType,
flavor=types.FlavorResourceType) flavor=types.FlavorResourceType)
@ -242,8 +236,7 @@ class NovaServers(utils.NovaScenario,
""" """
volume = self._create_volume(volume_size, imageRef=image) volume = self._create_volume(volume_size, imageRef=image)
block_device_mapping = {"vda": "%s:::1" % volume.id} block_device_mapping = {"vda": "%s:::1" % volume.id}
self._boot_server(self._generate_random_name(), self._boot_server(image, flavor, auto_assign_nic=auto_assign_nic,
image, flavor, auto_assign_nic,
block_device_mapping=block_device_mapping, block_device_mapping=block_device_mapping,
**kwargs) **kwargs)
@ -308,8 +301,7 @@ class NovaServers(utils.NovaScenario,
:param force_delete: True if force_delete should be used :param force_delete: True if force_delete should be used
:param kwargs: Optional additional arguments for server creation :param kwargs: Optional additional arguments for server creation
""" """
server = self._boot_server(self._generate_random_name(), server = self._boot_server(image, flavor, **kwargs)
image, flavor, **kwargs)
self._resize(server, to_flavor) self._resize(server, to_flavor)
# by default we confirm # by default we confirm
confirm = kwargs.get("confirm", True) confirm = kwargs.get("confirm", True)
@ -341,8 +333,7 @@ class NovaServers(utils.NovaScenario,
on migrated instance or not on migrated instance or not
:param kwargs: Optional additional arguments for server creation :param kwargs: Optional additional arguments for server creation
""" """
server = self._boot_server(self._generate_random_name(), server = self._boot_server(image, flavor, **kwargs)
image, flavor, **kwargs)
new_host = self._find_host_to_migrate(server) new_host = self._find_host_to_migrate(server)
self._live_migrate(server, new_host, self._live_migrate(server, new_host,
@ -367,8 +358,7 @@ class NovaServers(utils.NovaScenario,
:param flavor: flavor to be used to boot an instance :param flavor: flavor to be used to boot an instance
:param kwargs: Optional additional arguments for server creation :param kwargs: Optional additional arguments for server creation
""" """
server = self._boot_server(self._generate_random_name(), server = self._boot_server(image, flavor, **kwargs)
image, flavor, **kwargs)
self._stop_server(server) self._stop_server(server)
self._migrate(server) self._migrate(server)
# NOTE(wtakase): This is required because cold migration and resize # NOTE(wtakase): This is required because cold migration and resize

View File

@ -79,8 +79,8 @@ class NovaScenario(base.Scenario):
return self.clients("nova").servers.list(detailed) return self.clients("nova").servers.list(detailed)
@base.atomic_action_timer("nova.boot_server") @base.atomic_action_timer("nova.boot_server")
def _boot_server(self, server_name, image_id, flavor_id, def _boot_server(self, image_id, flavor_id,
auto_assign_nic=False, **kwargs): auto_assign_nic=False, name=None, **kwargs):
"""Boot a server. """Boot a server.
Returns when the server is actually booted and in "ACTIVE" state. Returns when the server is actually booted and in "ACTIVE" state.
@ -88,13 +88,14 @@ class NovaScenario(base.Scenario):
If multiple networks are present, the first network found that If multiple networks are present, the first network found that
isn't associated with a floating IP pool is used. isn't associated with a floating IP pool is used.
:param server_name: str, server name
:param image_id: int, image ID for server creation :param image_id: int, image ID for server creation
:param flavor_id: int, flavor ID for server creation :param flavor_id: int, flavor ID for server creation
:param auto_assign_nic: bool, whether or not to auto assign NICs :param auto_assign_nic: bool, whether or not to auto assign NICs
:param name: str, server name
:param kwargs: other optional parameters to initialize the server :param kwargs: other optional parameters to initialize the server
:returns: nova Server instance :returns: nova Server instance
""" """
server_name = name or self._generate_random_name()
allow_ssh_secgroup = self.context.get("allow_ssh") allow_ssh_secgroup = self.context.get("allow_ssh")
if allow_ssh_secgroup: if allow_ssh_secgroup:
if "security_groups" not in kwargs: if "security_groups" not in kwargs:

View File

@ -82,9 +82,7 @@ class VMTasks(nova_utils.NovaScenario, vm_utils.VMScenario,
net_wrap = network_wrapper.wrap(self.clients) net_wrap = network_wrapper.wrap(self.clients)
kwargs.update({"auto_assign_nic": True, kwargs.update({"auto_assign_nic": True,
"key_name": keypair.Keypair.KEYPAIR_NAME}) "key_name": keypair.Keypair.KEYPAIR_NAME})
server = self._boot_server( server = self._boot_server(image, flavor, **kwargs)
self._generate_random_name("rally_novaserver_"),
image, flavor, **kwargs)
if not server.networks: if not server.networks:
raise RuntimeError( raise RuntimeError(

View File

@ -40,7 +40,7 @@ class NovaServersTestCase(test.TestCase):
scenario._delete_server = mock.MagicMock() scenario._delete_server = mock.MagicMock()
scenario.boot_and_bounce_server("img", 1, actions=actions) scenario.boot_and_bounce_server("img", 1, actions=actions)
scenario._boot_server.assert_called_once_with("name", "img", 1) scenario._boot_server.assert_called_once_with("img", 1)
server_calls = [] server_calls = []
for i in range(5): for i in range(5):
server_calls.append(mock.call(fake_server)) server_calls.append(mock.call(fake_server))
@ -65,7 +65,7 @@ class NovaServersTestCase(test.TestCase):
scenario.boot_and_bounce_server("img", 1, actions=actions) scenario.boot_and_bounce_server("img", 1, actions=actions)
scenario._boot_server.assert_called_once_with("name", "img", 1) scenario._boot_server.assert_called_once_with("img", 1)
server_calls = [] server_calls = []
for i in range(5): for i in range(5):
server_calls.append(mock.call(fake_server)) server_calls.append(mock.call(fake_server))
@ -90,7 +90,7 @@ class NovaServersTestCase(test.TestCase):
scenario._generate_random_name = mock.MagicMock(return_value="name") scenario._generate_random_name = mock.MagicMock(return_value="name")
scenario.boot_and_bounce_server("img", 1, actions=actions) scenario.boot_and_bounce_server("img", 1, actions=actions)
scenario._boot_server.assert_called_once_with("name", "img", 1) scenario._boot_server.assert_called_once_with("img", 1)
server_calls = [] server_calls = []
for i in range(5): for i in range(5):
server_calls.append(mock.call(fake_server)) server_calls.append(mock.call(fake_server))
@ -143,7 +143,7 @@ class NovaServersTestCase(test.TestCase):
scenario.boot_and_bounce_server("img", 1, actions=actions) scenario.boot_and_bounce_server("img", 1, actions=actions)
scenario._boot_server.assert_called_once_with("name", "img", 1) scenario._boot_server.assert_called_once_with("img", 1)
server_calls = [] server_calls = []
for i in range(5): for i in range(5):
server_calls.append(mock.call(fake_server)) server_calls.append(mock.call(fake_server))
@ -175,7 +175,7 @@ class NovaServersTestCase(test.TestCase):
scenario.boot_and_delete_server("img", 0, 10, 20, fakearg="fakearg") scenario.boot_and_delete_server("img", 0, 10, 20, fakearg="fakearg")
scenario._boot_server.assert_called_once_with("name", "img", 0, scenario._boot_server.assert_called_once_with("img", 0,
fakearg="fakearg") fakearg="fakearg")
scenario.sleep_between.assert_called_once_with(10, 20) scenario.sleep_between.assert_called_once_with(10, 20)
scenario._delete_server.assert_called_once_with(fake_server, scenario._delete_server.assert_called_once_with(fake_server,
@ -189,7 +189,7 @@ class NovaServersTestCase(test.TestCase):
scenario.boot_and_list_server("img", 0, fakearg="fakearg") scenario.boot_and_list_server("img", 0, fakearg="fakearg")
scenario._boot_server.assert_called_once_with("name", "img", 0, scenario._boot_server.assert_called_once_with("img", 0,
fakearg="fakearg") fakearg="fakearg")
scenario._list_servers.assert_called_once_with(True) scenario._list_servers.assert_called_once_with(True)
@ -216,8 +216,8 @@ class NovaServersTestCase(test.TestCase):
scenario._create_volume.assert_called_once_with(5, imageRef="img") scenario._create_volume.assert_called_once_with(5, imageRef="img")
scenario._boot_server.assert_called_once_with( scenario._boot_server.assert_called_once_with(
"name", "img", 0, "img", 0,
block_device_mapping={"vda": "volume_id:::1"}, block_device_mapping={'vda': 'volume_id:::1'},
fakearg="f") fakearg="f")
scenario.sleep_between.assert_called_once_with(10, 20) scenario.sleep_between.assert_called_once_with(10, 20)
scenario._delete_server.assert_called_once_with(fake_server, scenario._delete_server.assert_called_once_with(fake_server,
@ -259,8 +259,8 @@ class NovaServersTestCase(test.TestCase):
nic=nic, assert_nic=assert_nic) nic=nic, assert_nic=assert_nic)
scenario.boot_server("img", 0, **kwargs) scenario.boot_server("img", 0, **kwargs)
scenario._boot_server.assert_called_once_with("name", "img", 0, False, scenario._boot_server.assert_called_once_with(
**expected_kwargs) "img", 0, auto_assign_nic=False, **expected_kwargs)
@mock.patch("rally.benchmark.scenarios.nova.servers.NovaServers.clients") @mock.patch("rally.benchmark.scenarios.nova.servers.NovaServers.clients")
@mock.patch("rally.benchmark.runners.base.osclients") @mock.patch("rally.benchmark.runners.base.osclients")
@ -289,8 +289,8 @@ class NovaServersTestCase(test.TestCase):
scenario.snapshot_server("i", 0, fakearg=2) scenario.snapshot_server("i", 0, fakearg=2)
scenario._boot_server.assert_has_calls([ scenario._boot_server.assert_has_calls([
mock.call("name", "i", 0, fakearg=2), mock.call("i", 0, fakearg=2),
mock.call("name", "image_id", 0, fakearg=2)]) mock.call("image_id", 0, fakearg=2)])
scenario._create_image.assert_called_once_with(fake_server) scenario._create_image.assert_called_once_with(fake_server)
scenario._delete_server.assert_has_calls([ scenario._delete_server.assert_has_calls([
mock.call(fake_server, force=False), mock.call(fake_server, force=False),
@ -341,7 +341,7 @@ class NovaServersTestCase(test.TestCase):
scenario.boot_and_live_migrate_server("img", 0, fakearg="fakearg") scenario.boot_and_live_migrate_server("img", 0, fakearg="fakearg")
scenario._boot_server.assert_called_once_with("name", "img", 0, scenario._boot_server.assert_called_once_with("img", 0,
fakearg="fakearg") fakearg="fakearg")
scenario._find_host_to_migrate.assert_called_once_with(fake_server) scenario._find_host_to_migrate.assert_called_once_with(fake_server)
@ -367,7 +367,7 @@ class NovaServersTestCase(test.TestCase):
scenario.boot_and_migrate_server("img", 0, scenario.boot_and_migrate_server("img", 0,
fakearg="fakearg", **kwargs) fakearg="fakearg", **kwargs)
scenario._boot_server.assert_called_once_with("name", "img", 0, scenario._boot_server.assert_called_once_with("img", 0,
fakearg="fakearg", fakearg="fakearg",
confirm=confirm) confirm=confirm)

View File

@ -99,8 +99,8 @@ class NovaScenarioTestCase(test.TestCase):
def test__boot_server(self, mock_clients): def test__boot_server(self, mock_clients):
mock_clients("nova").servers.create.return_value = self.server mock_clients("nova").servers.create.return_value = self.server
nova_scenario = utils.NovaScenario(context={}) nova_scenario = utils.NovaScenario(context={})
return_server = nova_scenario._boot_server("server_name", "image_id", return_server = nova_scenario._boot_server('image_id',
"flavor_id") 'flavor_id')
self._test_assert_called_once_with( self._test_assert_called_once_with(
self.wait_for.mock, self.server, self.wait_for.mock, self.server,
CONF.benchmark.nova_server_boot_poll_interval, CONF.benchmark.nova_server_boot_poll_interval,
@ -120,7 +120,7 @@ class NovaScenarioTestCase(test.TestCase):
"iteration": 3, "iteration": 3,
"config": {"users": {"tenants": 2}}, "config": {"users": {"tenants": 2}},
"tenant": {"networks": networks}}) "tenant": {"networks": networks}})
return_server = nova_scenario._boot_server("server_name", "image_id", return_server = nova_scenario._boot_server("image_id",
"flavor_id", "flavor_id",
auto_assign_nic=True) auto_assign_nic=True)
self._test_assert_called_once_with( self._test_assert_called_once_with(
@ -138,15 +138,14 @@ class NovaScenarioTestCase(test.TestCase):
nova_scenario = utils.NovaScenario( nova_scenario = utils.NovaScenario(
context={"tenant": {"networks": None}}) context={"tenant": {"networks": None}})
self.assertRaises(TypeError, nova_scenario._boot_server, self.assertRaises(TypeError, nova_scenario._boot_server,
"server_name", "image_id", "flavor_id", "image_id", "flavor_id",
auto_assign_nic=True) auto_assign_nic=True)
@mock.patch(NOVA_UTILS + ".NovaScenario.clients") @mock.patch(NOVA_UTILS + ".NovaScenario.clients")
def test__boot_server_with_ssh(self, mock_clients): def test__boot_server_with_ssh(self, mock_clients):
mock_clients("nova").servers.create.return_value = self.server mock_clients("nova").servers.create.return_value = self.server
nova_scenario = utils.NovaScenario(context={"allow_ssh": "test"}) nova_scenario = utils.NovaScenario(context={"allow_ssh": "test"})
return_server = nova_scenario._boot_server("server_name", "image_id", return_server = nova_scenario._boot_server('image_id', 'flavor_id')
"flavor_id")
self._test_assert_called_once_with( self._test_assert_called_once_with(
self.wait_for.mock, self.server, self.wait_for.mock, self.server,
CONF.benchmark.nova_server_boot_poll_interval, CONF.benchmark.nova_server_boot_poll_interval,
@ -161,8 +160,8 @@ class NovaScenarioTestCase(test.TestCase):
mock_clients("nova").servers.create.return_value = self.server mock_clients("nova").servers.create.return_value = self.server
nova_scenario = utils.NovaScenario(context={"allow_ssh": "new"}) nova_scenario = utils.NovaScenario(context={"allow_ssh": "new"})
return_server = nova_scenario._boot_server( return_server = nova_scenario._boot_server(
"server_name", "image_id", "flavor_id", 'image_id', 'flavor_id',
security_groups=["test1"]) security_groups=['test1'])
self._test_assert_called_once_with( self._test_assert_called_once_with(
self.wait_for.mock, self.server, self.wait_for.mock, self.server,
CONF.benchmark.nova_server_boot_poll_interval, CONF.benchmark.nova_server_boot_poll_interval,
@ -177,8 +176,8 @@ class NovaScenarioTestCase(test.TestCase):
mock_clients("nova").servers.create.return_value = self.server mock_clients("nova").servers.create.return_value = self.server
nova_scenario = utils.NovaScenario(context={"allow_ssh": "test1"}) nova_scenario = utils.NovaScenario(context={"allow_ssh": "test1"})
return_server = nova_scenario._boot_server( return_server = nova_scenario._boot_server(
"server_name", "image_id", "flavor_id", 'image_id', 'flavor_id',
security_groups=["test1"]) security_groups=['test1'])
self._test_assert_called_once_with( self._test_assert_called_once_with(
self.wait_for.mock, self.server, self.wait_for.mock, self.server,
CONF.benchmark.nova_server_boot_poll_interval, CONF.benchmark.nova_server_boot_poll_interval,

View File

@ -75,7 +75,7 @@ class VMTasksTestCase(test.TestCase):
self.assertEqual(result, {"errors": "foo_err", "data": "foo_out"}) self.assertEqual(result, {"errors": "foo_err", "data": "foo_out"})
self.scenario._boot_server.assert_called_once_with( self.scenario._boot_server.assert_called_once_with(
"foo_name", "foo_image", "foo_flavor", "foo_image", "foo_flavor",
block_device_mapping={"vdrally": "foo_volume:::1"}, block_device_mapping={"vdrally": "foo_volume:::1"},
nics=[{"net-id": "foo_network"}], auto_assign_nic=True, nics=[{"net-id": "foo_network"}], auto_assign_nic=True,
key_name=keypair.Keypair.KEYPAIR_NAME) key_name=keypair.Keypair.KEYPAIR_NAME)
@ -101,7 +101,7 @@ class VMTasksTestCase(test.TestCase):
"foo_image", "foo_flavor", "foo_script", "foo_shell", "foo_user") "foo_image", "foo_flavor", "foo_script", "foo_shell", "foo_user")
self.scenario._boot_server.assert_called_once_with( self.scenario._boot_server.assert_called_once_with(
"foo_name", "foo_image", "foo_flavor", auto_assign_nic=True, "foo_image", "foo_flavor", auto_assign_nic=True,
key_name=keypair.Keypair.KEYPAIR_NAME) key_name=keypair.Keypair.KEYPAIR_NAME)
self.scenario._associate_floating_ip.assert_called_once_with( self.scenario._associate_floating_ip.assert_called_once_with(
self.server, "foo_fip", fixed_address="foo_addr") self.server, "foo_fip", fixed_address="foo_addr")
@ -117,7 +117,7 @@ class VMTasksTestCase(test.TestCase):
floating_network="bar_network") floating_network="bar_network")
self.scenario._boot_server.assert_called_once_with( self.scenario._boot_server.assert_called_once_with(
"foo_name", "foo_image", "foo_flavor", auto_assign_nic=True, "foo_image", "foo_flavor", auto_assign_nic=True,
key_name=keypair.Keypair.KEYPAIR_NAME) key_name=keypair.Keypair.KEYPAIR_NAME)
net_wrap.create_floating_ip.assert_called_once_with( net_wrap.create_floating_ip.assert_called_once_with(