Auto assign nic for servers context

Servers context now uses nova scenarios's _boot_servers. Enable
auto_assign_nic in servers context could avoid "Multiple possible
networks found" error from Nova.

Change-Id: I15a4f1595344331971078cb1e4f17162e764ac8e
Closes-Bug: #1477583
This commit is contained in:
Kun Huang 2015-09-17 18:29:52 +08:00
parent 715e45a213
commit 5999dbe799
3 changed files with 29 additions and 6 deletions

View File

@ -279,6 +279,8 @@
image:
name: {{image_name}}
servers_per_tenant: 2
network:
networks_per_tenant: 2
sla:
failure_rate:
max: 0

View File

@ -30,7 +30,7 @@ LOG = logging.getLogger(__name__)
class ServerGenerator(context.Context):
"""Context class for adding temporary servers for benchmarks.
Servers are added for each tenant.
Servers are added for each tenant.
"""
CONFIG_SCHEMA = {
@ -57,19 +57,24 @@ class ServerGenerator(context.Context):
"type": "integer",
"minimum": 1
},
"auto_assign_nic": {
"type": "boolean",
}
},
"required": ["image", "flavor"],
"additionalProperties": False
}
DEFAULT_CONFIG = {
"servers_per_tenant": 5
"servers_per_tenant": 5,
"auto_assign_nic": False
}
@rutils.log_task_wrapper(LOG.info, _("Enter context: `Servers`"))
def setup(self):
image = self.config["image"]
flavor = self.config["flavor"]
auto_nic = self.config["auto_assign_nic"]
servers_per_tenant = self.config["servers_per_tenant"]
clients = osclients.Clients(self.context["users"][0]["endpoint"])
@ -78,11 +83,14 @@ class ServerGenerator(context.Context):
flavor_id = types.FlavorResourceType.transform(clients=clients,
resource_config=flavor)
for user, tenant_id in rutils.iterate_per_tenants(
self.context["users"]):
for iter_, (user, tenant_id) in enumerate(rutils.iterate_per_tenants(
self.context["users"])):
LOG.debug("Booting servers for user tenant %s "
% (user["tenant_id"]))
nova_scenario = nova_utils.NovaScenario({"user": user})
tenant = self.context["tenants"][tenant_id]
nova_scenario = nova_utils.NovaScenario({"user": user,
"tenant": tenant,
"iteration": iter_})
LOG.debug("Calling _boot_servers with image_id=%(image_id)s "
"flavor_id=%(flavor_id)s "
@ -92,7 +100,8 @@ class ServerGenerator(context.Context):
"servers_per_tenant": servers_per_tenant})
servers = nova_scenario._boot_servers(image_id, flavor_id,
servers_per_tenant)
requests=servers_per_tenant,
auto_assign_nic=auto_nic)
current_servers = [server.id for server in servers]

View File

@ -85,6 +85,7 @@ class ServerGeneratorTestCase(test.ScenarioTestCase):
"concurrent": 10,
},
"servers": {
"auto_assign_nic": True,
"servers_per_tenant": 5,
"image": {
"name": "cirros-0.3.4-x86_64-uec",
@ -111,6 +112,17 @@ class ServerGeneratorTestCase(test.ScenarioTestCase):
servers_ctx = servers.ServerGenerator(real_context)
servers_ctx.setup()
self.assertEqual(new_context, real_context)
image_id = mock_image_resource_type_transform.return_value
flavor_id = mock_flavor_resource_type_transform.return_value
servers_ctx_config = real_context["config"]["servers"]
expected_auto_nic = servers_ctx_config.get("auto_assign_nic", False)
expected_requests = servers_ctx_config.get("servers_per_tenant", False)
called_times = len(tenants)
mock_calls = [mock.call(image_id, flavor_id,
auto_assign_nic=expected_auto_nic,
requests=expected_requests)
for i in range(called_times)]
mock_nova_scenario__boot_servers.assert_has_calls(mock_calls)
@mock.patch("%s.servers.osclients" % CTX)
@mock.patch("%s.servers.resource_manager.cleanup" % CTX)