Make Neutron router scenarios work with network context

Usage of NeutronNetworks.create_and_*_routers without network context
is deprecated (ref. https://goo.gl/peijFT), however these scenario can
not be run with network context due to a bug.

This patch fixes the bug and also enables the network context in gates
for all Neutron scenarios that should be using it.

Change-Id: I5783ea110290332234b94ed8adbdbe8a1d9d0f14
Co-Authored-By: Alexander Maretskiy <amaretskiy@mirantis.com>
Closes-Bug: #1523417
This commit is contained in:
Chris St. Pierre 2015-12-14 10:47:36 -06:00
parent 8e374ae1c1
commit f1e28c3dc6
4 changed files with 22 additions and 59 deletions

View File

@ -523,6 +523,7 @@
times: 1
concurrency: 1
context:
network: {}
users:
tenants: 1
users_per_tenant: 1
@ -547,6 +548,7 @@
times: 1
concurrency: 1
context:
network: {}
users:
tenants: 1
users_per_tenant: 1
@ -570,6 +572,7 @@
times: 1
concurrency: 1
context:
network: {}
users:
tenants: 1
users_per_tenant: 1
@ -620,6 +623,7 @@
times: 1
concurrency: 1
context:
network: {}
users:
tenants: 5
users_per_tenant: 5
@ -647,6 +651,7 @@
times: 1
concurrency: 1
context:
network: {}
users:
tenants: 1
users_per_tenant: 1
@ -675,6 +680,7 @@
times: 1
concurrency: 1
context:
network: {}
users:
tenants: 1
users_per_tenant: 1
@ -718,6 +724,7 @@
times: 1
concurrency: 1
context:
network: {}
users:
tenants: 1
users_per_tenant: 1
@ -740,6 +747,7 @@
times: 1
concurrency: 1
context:
network: {}
users:
tenants: 1
users_per_tenant: 1

View File

@ -33,6 +33,7 @@
times: {{smoke or 20 }}
concurrency: {{smoke or 10}}
context:
network: {}
users:
tenants: {{smoke or 3}}
users_per_tenant: {{smoke or 2}}
@ -135,6 +136,7 @@
times: {{smoke or 15}}
concurrency: {{smoke or 5}}
context:
network: {}
users:
tenants: {{smoke or 3}}
users_per_tenant: {{smoke or 2}}
@ -158,6 +160,7 @@
times: {{smoke or 15}}
concurrency: {{smoke or 5}}
context:
network: {}
users:
tenants: {{smoke or 3}}
users_per_tenant: {{smoke or 2}}
@ -409,6 +412,7 @@
times: {{smoke or 20}}
concurrency: {{smoke or 10}}
context:
network: {}
users:
tenants: {{smoke or 3}}
users_per_tenant: {{smoke or 2}}
@ -436,6 +440,7 @@
times: {{smoke or 15}}
concurrency: {{smoke or 5}}
context:
network: {}
users:
tenants: {{smoke or 3}}
users_per_tenant: {{smoke or 2}}
@ -464,6 +469,7 @@
times: {{smoke or 20}}
concurrency: {{smoke or 10}}
context:
network: {}
users:
tenants: {{smoke or 3}}
users_per_tenant: {{smoke or 2}}
@ -507,6 +513,7 @@
times: {{smoke or 20}}
concurrency: {{smoke or 10}}
context:
network: {}
users:
tenants: {{smoke or 3}}
users_per_tenant: {{smoke or 2}}
@ -551,6 +558,7 @@
times: {{smoke or 15}}
concurrency: {{smoke or 5}}
context:
network: {}
users:
tenants: {{smoke or 3}}
users_per_tenant: {{smoke or 2}}
@ -574,6 +582,7 @@
times: {{smoke or 8}}
concurrency: {{smoke or 4}}
context:
network: {}
users:
tenants: {{smoke or 3}}
users_per_tenant: {{smoke or 2}}

View File

@ -290,30 +290,6 @@ class NeutronScenario(scenario.OpenStackScenario):
"or 'existing_network' context is deprecated"))
return self._create_network(network_create_args or {})
def _get_or_create_subnets(self, network,
subnet_create_args=None,
subnet_cidr_start=None,
subnets_per_network=1):
"""Get subnets from a network, or create new subnets.
Existing subnets are preferred to creating new ones.
:param network: network to create subnets in
:param subnet_create_args: dict, POST /v2.0/subnets request options
:param subnet_cidr_start: str, start value for subnets CIDR
:param subnets_per_network: int, number of subnets for one network
:returns: List of subnet dicts
"""
subnets = network.get("subnets")
if subnets:
# NOTE(amaretskiy): I believe this method will be reworked
# or even removed at all since structure of this return
# value is incomplete (subnet ids only) in comparison with
# self._create_subnets() below
return [{"subnet": {"id": subnet}} for subnet in subnets]
return self._create_subnets(network, subnet_create_args,
subnet_cidr_start, subnets_per_network)
def _create_subnets(self, network,
subnet_create_args=None,
subnet_cidr_start=None,
@ -363,9 +339,9 @@ class NeutronScenario(scenario.OpenStackScenario):
:returns: tuple of (network, subnets, routers)
"""
network = self._get_or_create_network(network_create_args)
subnets = self._get_or_create_subnets(network, subnet_create_args,
subnet_cidr_start,
subnets_per_network)
subnets = self._create_subnets(network, subnet_create_args,
subnet_cidr_start,
subnets_per_network)
routers = []
for subnet in subnets:

View File

@ -454,36 +454,6 @@ class NeutronScenarioTestCase(test.ScenarioTestCase):
scenario._create_network.assert_called_once_with(
network_create_args or {})
@ddt.data(
{"subnets": ["foo-id", "bar-id"],
"expected": [{"subnet": {"id": "foo-id"}},
{"subnet": {"id": "bar-id"}}]},
{"subnets": ["foo-id", "bar-id"],
"subnet_create_args": {"fakearg": "fake"},
"subnet_cidr_start": "cidr",
"subnets_per_network": 5,
"expected": [{"subnet": {"id": "foo-id"}},
{"subnet": {"id": "bar-id"}}]},
{"subnets": [],
"subnet_create_args": {"fakearg": "fake"},
"subnet_cidr_start": "cidr",
"subnets_per_network": 5,
"expected": {
"create_subnets": [({"subnets": []}, {"fakearg": "fake"},
"cidr", 5), {}]}})
@ddt.unpack
def test_get_or_create_subnets(self, subnets=None,
subnet_create_args=None,
subnet_cidr_start=None,
subnets_per_network=1, expected=None):
self.scenario._create_subnets = mock.Mock(
side_effect=lambda *args, **kw: {"create_subnets": [args, kw]})
result = self.scenario._get_or_create_subnets({"subnets": subnets},
subnet_create_args,
subnet_cidr_start,
subnets_per_network)
self.assertEqual(expected, result)
@mock.patch(NEUTRON_UTILS + "NeutronScenario._create_subnet",
return_value={
"subnet": {
@ -581,7 +551,7 @@ class NeutronScenarioTestCase(test.ScenarioTestCase):
scenario = utils.NeutronScenario()
scenario._get_or_create_network = mock.Mock(return_value=network)
scenario._get_or_create_subnets = mock.Mock(return_value=subnets)
scenario._create_subnets = mock.Mock(return_value=subnets)
scenario._create_router = mock.Mock(side_effect=routers)
scenario._add_interface_router = mock.Mock()
@ -593,7 +563,7 @@ class NeutronScenarioTestCase(test.ScenarioTestCase):
self.assertEqual(actual, (network, subnets, routers))
scenario._get_or_create_network.assert_called_once_with(
network_create_args)
scenario._get_or_create_subnets.assert_called_once_with(
scenario._create_subnets.assert_called_once_with(
network,
subnet_create_args,
subnet_cidr_start,