diff --git a/rally/plugins/openstack/context/nova/servers.py b/rally/plugins/openstack/context/nova/servers.py index 60dc7f2f..f135d722 100755 --- a/rally/plugins/openstack/context/nova/servers.py +++ b/rally/plugins/openstack/context/nova/servers.py @@ -39,18 +39,14 @@ class ServerGenerator(context.Context): "description": "Name of image to boot server(s) from.", "type": "object", "properties": { - "name": { - "type": "string" - } + "name": {"type": "string"} } }, "flavor": { "description": "Name of flavor to boot server(s) with.", "type": "object", "properties": { - "name": { - "type": "string" - } + "name": {"type": "string"} } }, "servers_per_tenant": { @@ -70,7 +66,8 @@ class ServerGenerator(context.Context): "properties": {"net-id": {"type": "string"}}, "description": "Network ID in a format like OpenStack API" " expects to see."}, - {"type": "string", "description": "Network ID."}]} + {"type": "string", "description": "Network ID."}]}, + "minItems": 1 } }, "required": ["image", "flavor"], @@ -88,7 +85,14 @@ class ServerGenerator(context.Context): flavor = self.config["flavor"] auto_nic = self.config["auto_assign_nic"] servers_per_tenant = self.config["servers_per_tenant"] - kwargs = {"nics": self.config.get("nics", [])} + kwargs = {} + if self.config.get("nics"): + if isinstance(self.config["nics"][0], dict): + # it is format that Nova expects + kwargs["nics"] = self.config["nics"] + else: + kwargs["nics"] = [{"net-id": nic} + for nic in self.config["nics"]] clients = osclients.Clients(self.context["users"][0]["credential"]) image_id = types.GlanceImage.transform(clients=clients, diff --git a/tests/unit/plugins/openstack/context/nova/test_servers.py b/tests/unit/plugins/openstack/context/nova/test_servers.py index af7e86d3..2bddcc09 100755 --- a/tests/unit/plugins/openstack/context/nova/test_servers.py +++ b/tests/unit/plugins/openstack/context/nova/test_servers.py @@ -93,6 +93,7 @@ class ServerGeneratorTestCase(test.ScenarioTestCase): "flavor": { "name": "m1.tiny", }, + "nics": ["foo", "bar"] }, }, "admin": { @@ -115,12 +116,11 @@ class ServerGeneratorTestCase(test.ScenarioTestCase): flavor_id = mock_flavor_transform.return_value servers_ctx_config = self.context["config"]["servers"] expected_auto_nic = servers_ctx_config.get("auto_assign_nic", False) - expected_nics = servers_ctx_config.get("nics", []) 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, - nics=expected_nics, + nics=[{"net-id": "foo"}, {"net-id": "bar"}], requests=expected_requests) for i in range(called_times)] mock_nova_scenario__boot_servers.assert_has_calls(mock_calls)