Merge "Nova: Support auto_assign_nic when booting multiple servers"
This commit is contained in:
commit
a39ade84a6
@ -486,7 +486,7 @@ class NovaScenario(scenario.OpenStackScenario):
|
|||||||
|
|
||||||
@atomic.action_timer("nova.boot_servers")
|
@atomic.action_timer("nova.boot_servers")
|
||||||
def _boot_servers(self, image_id, flavor_id, requests, name_prefix=None,
|
def _boot_servers(self, image_id, flavor_id, requests, name_prefix=None,
|
||||||
instances_amount=1, **kwargs):
|
instances_amount=1, auto_assign_nic=False, **kwargs):
|
||||||
"""Boot multiple servers.
|
"""Boot multiple servers.
|
||||||
|
|
||||||
Returns when all the servers are actually booted and are in the
|
Returns when all the servers are actually booted and are in the
|
||||||
@ -498,11 +498,19 @@ class NovaScenario(scenario.OpenStackScenario):
|
|||||||
:param name_prefix: The prefix to use while naming the created servers.
|
:param name_prefix: The prefix to use while naming the created servers.
|
||||||
The rest of the server names will be '_<number>'
|
The rest of the server names will be '_<number>'
|
||||||
:param instances_amount: Number of instances to boot per each request
|
:param instances_amount: Number of instances to boot per each request
|
||||||
|
:param auto_assign_nic: bool, whether or not to auto assign NICs
|
||||||
|
:param kwargs: other optional parameters to initialize the servers
|
||||||
|
|
||||||
:returns: List of created server objects
|
:returns: List of created server objects
|
||||||
"""
|
"""
|
||||||
if not name_prefix:
|
if not name_prefix:
|
||||||
name_prefix = self._generate_random_name()
|
name_prefix = self._generate_random_name()
|
||||||
|
|
||||||
|
if auto_assign_nic and not kwargs.get("nics", False):
|
||||||
|
nic = self._pick_random_nic()
|
||||||
|
if nic:
|
||||||
|
kwargs["nics"] = nic
|
||||||
|
|
||||||
for i in range(requests):
|
for i in range(requests):
|
||||||
self.clients("nova").servers.create("%s_%d" % (name_prefix, i),
|
self.clients("nova").servers.create("%s_%d" % (name_prefix, i),
|
||||||
image_id, flavor_id,
|
image_id, flavor_id,
|
||||||
|
@ -416,33 +416,58 @@ class NovaScenarioTestCase(test.ScenarioTestCase):
|
|||||||
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
|
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
|
||||||
"nova.delete_image")
|
"nova.delete_image")
|
||||||
|
|
||||||
def test__boot_servers(self):
|
@ddt.data(
|
||||||
self.clients("nova").servers.list.return_value = [self.server,
|
{"requests": 1},
|
||||||
self.server1]
|
{"requests": 25},
|
||||||
nova_scenario = utils.NovaScenario()
|
{"requests": 2, "name_prefix": "foo", "instances_amount": 100,
|
||||||
nova_scenario._boot_servers("image", "flavor", 2)
|
"auto_assign_nic": True, "fakearg": "fake"},
|
||||||
expected = [
|
{"auto_assign_nic": True, "nics": [{"net-id": "foo"}]},
|
||||||
|
{"auto_assign_nic": False, "nics": [{"net-id": "foo"}]})
|
||||||
|
@ddt.unpack
|
||||||
|
def test__boot_servers(self, image_id="image", flavor_id="flavor",
|
||||||
|
requests=1, name_prefix=None, instances_amount=1,
|
||||||
|
auto_assign_nic=False, **kwargs):
|
||||||
|
servers = [mock.Mock() for i in range(instances_amount)]
|
||||||
|
self.clients("nova").servers.list.return_value = servers
|
||||||
|
scenario = utils.NovaScenario()
|
||||||
|
scenario._generate_random_name = mock.Mock()
|
||||||
|
scenario._pick_random_nic = mock.Mock()
|
||||||
|
|
||||||
|
scenario._boot_servers(image_id, flavor_id, requests,
|
||||||
|
name_prefix=name_prefix,
|
||||||
|
instances_amount=instances_amount,
|
||||||
|
auto_assign_nic=auto_assign_nic,
|
||||||
|
**kwargs)
|
||||||
|
|
||||||
|
expected_kwargs = dict(kwargs)
|
||||||
|
if auto_assign_nic and "nics" not in kwargs:
|
||||||
|
expected_kwargs["nics"] = scenario._pick_random_nic.return_value
|
||||||
|
|
||||||
|
if name_prefix is None:
|
||||||
|
name_prefix = scenario._generate_random_name.return_value
|
||||||
|
|
||||||
|
create_calls = [
|
||||||
|
mock.call("%s_%d" % (name_prefix, i), image_id, flavor_id,
|
||||||
|
min_count=instances_amount, max_count=instances_amount,
|
||||||
|
**expected_kwargs)
|
||||||
|
for i in range(requests)]
|
||||||
|
self.clients("nova").servers.create.assert_has_calls(create_calls)
|
||||||
|
|
||||||
|
wait_for_calls = [
|
||||||
mock.call(
|
mock.call(
|
||||||
self.server,
|
servers[i],
|
||||||
is_ready=self.mock_resource_is.mock.return_value,
|
is_ready=self.mock_resource_is.mock.return_value,
|
||||||
update_resource=self.mock_get_from_manager.mock.return_value,
|
update_resource=self.mock_get_from_manager.mock.return_value,
|
||||||
check_interval=CONF.benchmark.nova_server_boot_poll_interval,
|
check_interval=CONF.benchmark.nova_server_boot_poll_interval,
|
||||||
timeout=CONF.benchmark.nova_server_boot_timeout
|
timeout=CONF.benchmark.nova_server_boot_timeout)
|
||||||
),
|
for i in range(instances_amount)]
|
||||||
mock.call(
|
self.mock_wait_for.mock.assert_has_calls(wait_for_calls)
|
||||||
self.server1,
|
|
||||||
is_ready=self.mock_resource_is.mock.return_value,
|
self.mock_resource_is.mock.assert_has_calls([
|
||||||
update_resource=self.mock_get_from_manager.mock.return_value,
|
mock.call("ACTIVE") for i in range(instances_amount)])
|
||||||
check_interval=CONF.benchmark.nova_server_boot_poll_interval,
|
self.mock_get_from_manager.mock.assert_has_calls(
|
||||||
timeout=CONF.benchmark.nova_server_boot_timeout
|
[mock.call() for i in range(instances_amount)])
|
||||||
)
|
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||||
]
|
|
||||||
self.mock_wait_for.mock.assert_has_calls(expected)
|
|
||||||
self.mock_resource_is.mock.assert_has_calls([mock.call("ACTIVE"),
|
|
||||||
mock.call("ACTIVE")])
|
|
||||||
self.mock_get_from_manager.mock.assert_has_calls([mock.call(),
|
|
||||||
mock.call()])
|
|
||||||
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
|
|
||||||
"nova.boot_servers")
|
"nova.boot_servers")
|
||||||
|
|
||||||
def test__associate_floating_ip(self):
|
def test__associate_floating_ip(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user