From 3128537a863dfd821680b07a3f85f3d725d606b4 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Tue, 8 Dec 2015 12:47:44 -0600 Subject: [PATCH] Fix format of existing network in _get_or_create_network() When running scenarios with the existing_networks plugin, _get_or_create_network() returned the network object itself rather than the Neutron-like return value of a dict with a single "network" key, whose value was the network object. This fixes that error, and adds an assertion to ensure that all return values from _get_or_create_network() are of the correct format. Change-Id: I94a6bf6c1dae8060f7644dad36ea72a81a8b0701 --- rally/plugins/openstack/scenarios/neutron/utils.py | 3 ++- .../plugins/openstack/scenarios/neutron/test_utils.py | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/rally/plugins/openstack/scenarios/neutron/utils.py b/rally/plugins/openstack/scenarios/neutron/utils.py index 0d74d629..951de381 100644 --- a/rally/plugins/openstack/scenarios/neutron/utils.py +++ b/rally/plugins/openstack/scenarios/neutron/utils.py @@ -283,7 +283,8 @@ class NeutronScenario(scenario.OpenStackScenario): :returns: Network dict """ if "networks" in self.context["tenant"]: - return random.choice(self.context["tenant"]["networks"]) + return {"network": + random.choice(self.context["tenant"]["networks"])} else: LOG.warning(_("Running this scenario without either the 'network' " "or 'existing_network' context is deprecated")) diff --git a/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py b/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py index 299d415d..59986294 100644 --- a/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/neutron/test_utils.py @@ -436,12 +436,17 @@ class NeutronScenarioTestCase(test.ScenarioTestCase): if context is None: context = {"tenant": {}} scenario = utils.NeutronScenario(context=context) - scenario._create_network = mock.Mock() + scenario._create_network = mock.Mock( + return_value={"network": mock.Mock()}) network = scenario._get_or_create_network(network_create_args) + # ensure that the return value is the proper type either way + self.assertIn("network", network) + if "networks" in context["tenant"]: - self.assertEqual(network, context["tenant"]["networks"][0]) + self.assertEqual(network, + {"network": context["tenant"]["networks"][0]}) self.assertFalse(scenario._create_network.called) else: self.assertEqual(network, scenario._create_network.return_value)