Merge "Ability to specify external gateway info for router while creating network context"

This commit is contained in:
Zuul 2018-02-02 11:50:25 +00:00 committed by Gerrit Code Review
commit 9085d47386
6 changed files with 42 additions and 8 deletions

View File

@ -657,6 +657,8 @@
dns_nameservers: dns_nameservers:
- "8.8.8.8" - "8.8.8.8"
- "8.8.4.4" - "8.8.4.4"
router:
external: false
sla: sla:
failure_rate: failure_rate:
max: 0 max: 0

View File

@ -59,6 +59,24 @@ class Network(context.Context):
"type": "array", "type": "array",
"items": {"type": "string"}, "items": {"type": "string"},
"uniqueItems": True "uniqueItems": True
},
"router": {
"type": "object",
"properties": {
"external": {
"type": "boolean"
},
"external_gateway_info": {
"description": "The external gateway information .",
"type": "object",
"properties": {
"network_id": {"type": "string"},
"enable_snat": {"type": "boolean"}
},
"additionalProperties": False
}
},
"additionalProperties": False
} }
}, },
"additionalProperties": False "additionalProperties": False
@ -69,7 +87,8 @@ class Network(context.Context):
"networks_per_tenant": 1, "networks_per_tenant": 1,
"subnets_per_network": 1, "subnets_per_network": 1,
"network_create_args": {}, "network_create_args": {},
"dns_nameservers": None "dns_nameservers": None,
"router": {"external": True}
} }
def setup(self): def setup(self):
@ -92,9 +111,9 @@ class Network(context.Context):
network_create_args = self.config["network_create_args"].copy() network_create_args = self.config["network_create_args"].copy()
network = net_wrapper.create_network( network = net_wrapper.create_network(
tenant_id, tenant_id,
add_router=True,
subnets_num=self.config["subnets_per_network"], subnets_num=self.config["subnets_per_network"],
network_create_args=network_create_args, network_create_args=network_create_args,
router_create_args=self.config["router"],
**kwargs) **kwargs)
self.context["tenants"][tenant_id]["networks"].append(network) self.context["tenants"][tenant_id]["networks"].append(network)

View File

@ -194,12 +194,14 @@ class NeutronWrapper(NetworkWrapper):
The following keyword arguments are accepted: The following keyword arguments are accepted:
* add_router: Create an external router and add an interface to each * add_router: Deprecated, please use router_create_args instead.
Create an external router and add an interface to each
subnet created. Default: False subnet created. Default: False
* subnets_num: Number of subnets to create per network. Default: 0 * subnets_num: Number of subnets to create per network. Default: 0
* dns_nameservers: Nameservers for each subnet. Default: * dns_nameservers: Nameservers for each subnet. Default:
8.8.8.8, 8.8.4.4 8.8.8.8, 8.8.4.4
* network_create_args: Additional network creation arguments. * network_create_args: Additional network creation arguments.
* router_create_args: Additional router creation arguments.
:param tenant_id: str, tenant ID :param tenant_id: str, tenant ID
:param kwargs: Additional options, left open-ended for compatbilitiy. :param kwargs: Additional options, left open-ended for compatbilitiy.
@ -213,8 +215,13 @@ class NeutronWrapper(NetworkWrapper):
network = self.client.create_network(network_args)["network"] network = self.client.create_network(network_args)["network"]
router = None router = None
if kwargs.get("add_router", False): router_args = dict(kwargs.get("router_create_args", {}))
router = self.create_router(external=True, tenant_id=tenant_id) add_router = kwargs.get("add_router", False)
if router_args or add_router:
router_args["external"] = (
router_args.get("external", False) or add_router)
router_args["tenant_id"] = tenant_id
router = self.create_router(**router_args)
subnets = [] subnets = []
subnets_num = kwargs.get("subnets_num", 0) subnets_num = kwargs.get("subnets_num", 0)

View File

@ -36,7 +36,10 @@
"networks_per_tenant": 1, "networks_per_tenant": 1,
"subnets_per_network": 1, "subnets_per_network": 1,
"network_create_args": {}, "network_create_args": {},
"dns_nameservers": ["10.2.0.1"] "dns_nameservers": ["10.2.0.1"],
"router": {
"external": false
}
} }
} }
} }

View File

@ -30,3 +30,5 @@
network_create_args: {} network_create_args: {}
dns_nameservers: dns_nameservers:
- "10.2.0.1" - "10.2.0.1"
router:
external: false

View File

@ -86,8 +86,9 @@ class NetworkTestCase(test.TestCase):
dns_kwargs["dns_nameservers"] = tuple( dns_kwargs["dns_nameservers"] = tuple(
dns_kwargs["dns_nameservers"]) dns_kwargs["dns_nameservers"])
create_calls = [ create_calls = [
mock.call(tenant, add_router=True, mock.call(tenant,
subnets_num=1, network_create_args={"fakearg": "fake"}, subnets_num=1, network_create_args={"fakearg": "fake"},
router_create_args={"external": True},
**dns_kwargs) **dns_kwargs)
for user, tenant in mock_utils.iterate_per_tenants.return_value] for user, tenant in mock_utils.iterate_per_tenants.return_value]
mock_create.assert_has_calls(create_calls) mock_create.assert_has_calls(create_calls)