From 9c13b516fde15363a025f5f215607414d478ba58 Mon Sep 17 00:00:00 2001 From: Sergey Skripnick Date: Wed, 18 Nov 2015 21:23:02 +0200 Subject: [PATCH] Fix broken logic in some neutron scenarios _get_or_create_network: create networks only if there is no networks in context. _get_or_create_subnets: create subnets only if there is no subnets in context. Unit tests are passing because of bug in ddt [0] This issue was actually caught by rally-ci (rally-pg-py27-unit) but was ignored by revievers. Running tests without testr may be used as workaround: .tox/py27/bin/python -m unittest discover tests/unit [0] https://github.com/txels/ddt/issues/35 Change-Id: Ib77bd4f7eeaec2ed3a712e1d56a20d1f87325264 --- rally/plugins/openstack/scenarios/neutron/utils.py | 14 +++++++------- tests/unit/test.py | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/rally/plugins/openstack/scenarios/neutron/utils.py b/rally/plugins/openstack/scenarios/neutron/utils.py index 9768de01..13865bcc 100644 --- a/rally/plugins/openstack/scenarios/neutron/utils.py +++ b/rally/plugins/openstack/scenarios/neutron/utils.py @@ -282,13 +282,12 @@ class NeutronScenario(scenario.OpenStackScenario): context instead. :returns: Network dict """ - if "networks" not in self.context["tenant"]: + if "networks" in self.context["tenant"]: + return random.choice(self.context["tenant"]["networks"]) + else: LOG.warning(_("Running this scenario without either the 'network' " "or 'existing_network' context is deprecated")) - elif network_create_args is None: - return random.choice(self.context["tenant"]["networks"]) - - return self._create_network(network_create_args or {}) + return self._create_network(network_create_args or {}) def _get_or_create_subnets(self, network, subnet_create_args=None, @@ -304,8 +303,9 @@ class NeutronScenario(scenario.OpenStackScenario): :param subnets_per_network: int, number of subnets for one network :returns: List of subnet dicts """ - if len(network.get("subnets", [])): - return network["subnets"] + subnets = network.get("subnets") + if subnets: + return subnets else: return self._create_subnets(network, subnet_create_args, subnet_cidr_start, subnets_per_network) diff --git a/tests/unit/test.py b/tests/unit/test.py index 0814718d..00eaf999 100644 --- a/tests/unit/test.py +++ b/tests/unit/test.py @@ -50,8 +50,8 @@ class TestCase(base.BaseTestCase): self.assertIsNotNone(action_duration) self.assertIsInstance(action_duration, float) - def assertSequenceEqual(self, iterable_1, iterable_2): - self.assertEqual(tuple(iterable_1), tuple(iterable_2)) + def assertSequenceEqual(self, iterable_1, iterable_2, msg=None): + self.assertEqual(tuple(iterable_1), tuple(iterable_2), msg) class DBTestCase(TestCase):