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

This patch permit to specify an external gateway info to router while creating
network context instead that is specified in internal.

Change-Id: Icbf2c207fdcb6b288ae81dc7a09fa96898131d59
This commit is contained in:
chenhb 2018-01-08 09:47:00 +08:00
parent c2b57d6a63
commit 37a83f4338
6 changed files with 42 additions and 8 deletions

View File

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

View File

@ -59,6 +59,24 @@ class Network(context.Context):
"type": "array",
"items": {"type": "string"},
"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
@ -69,7 +87,8 @@ class Network(context.Context):
"networks_per_tenant": 1,
"subnets_per_network": 1,
"network_create_args": {},
"dns_nameservers": None
"dns_nameservers": None,
"router": {"external": True}
}
def setup(self):
@ -92,9 +111,9 @@ class Network(context.Context):
network_create_args = self.config["network_create_args"].copy()
network = net_wrapper.create_network(
tenant_id,
add_router=True,
subnets_num=self.config["subnets_per_network"],
network_create_args=network_create_args,
router_create_args=self.config["router"],
**kwargs)
self.context["tenants"][tenant_id]["networks"].append(network)

View File

@ -194,12 +194,14 @@ class NeutronWrapper(NetworkWrapper):
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
* subnets_num: Number of subnets to create per network. Default: 0
* dns_nameservers: Nameservers for each subnet. Default:
8.8.8.8, 8.8.4.4
* network_create_args: Additional network creation arguments.
* router_create_args: Additional router creation arguments.
:param tenant_id: str, tenant ID
:param kwargs: Additional options, left open-ended for compatbilitiy.
@ -213,8 +215,13 @@ class NeutronWrapper(NetworkWrapper):
network = self.client.create_network(network_args)["network"]
router = None
if kwargs.get("add_router", False):
router = self.create_router(external=True, tenant_id=tenant_id)
router_args = dict(kwargs.get("router_create_args", {}))
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_num = kwargs.get("subnets_num", 0)

View File

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

View File

@ -29,4 +29,6 @@
subnets_per_network: 1
network_create_args: {}
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"])
create_calls = [
mock.call(tenant, add_router=True,
mock.call(tenant,
subnets_num=1, network_create_args={"fakearg": "fake"},
router_create_args={"external": True},
**dns_kwargs)
for user, tenant in mock_utils.iterate_per_tenants.return_value]
mock_create.assert_has_calls(create_calls)