NSX|V3: validate transport zone at provider net creation
Validate the existence ant type of the transport zone when creating a provider network Change-Id: I90fe67fb46903ec316440225b0c26609a223fe9c Depends-on: Ibe674ac95f794b5c01dc9fd5d3566f98b7b05d05
This commit is contained in:
parent
6f82be2341
commit
05b2dfd3e9
@ -655,6 +655,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
|
||||
err_msg = None
|
||||
net_type = network_data.get(pnet.NETWORK_TYPE)
|
||||
tz_type = self.nsxlib.transport_zone.TRANSPORT_TYPE_VLAN
|
||||
if validators.is_attr_set(net_type):
|
||||
if net_type == utils.NsxV3NetworkTypes.FLAT:
|
||||
if vlan_id is not None:
|
||||
@ -696,6 +697,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
err_msg = (_("Segmentation ID cannot be specified with "
|
||||
"%s network type") %
|
||||
utils.NsxV3NetworkTypes.VXLAN)
|
||||
tz_type = self.nsxlib.transport_zone.TRANSPORT_TYPE_OVERLAY
|
||||
else:
|
||||
err_msg = (_('%(net_type_param)s %(net_type_value)s not '
|
||||
'supported') %
|
||||
@ -710,13 +712,27 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
else:
|
||||
net_type = None
|
||||
|
||||
if err_msg:
|
||||
raise n_exc.InvalidInput(error_message=err_msg)
|
||||
|
||||
if physical_net is None:
|
||||
# Default to transport type overlay
|
||||
physical_net = az._default_overlay_tz_uuid
|
||||
|
||||
# validate the transport zone existence and type
|
||||
if not err_msg and is_provider_net and physical_net:
|
||||
try:
|
||||
backend_type = self.nsxlib.transport_zone.get_transport_type(
|
||||
physical_net)
|
||||
except nsx_lib_exc.ResourceNotFound:
|
||||
err_msg = (_('Transport zone %s does not exist') %
|
||||
physical_net)
|
||||
else:
|
||||
if backend_type != tz_type:
|
||||
err_msg = (_('%(tz)s transport zone is required for '
|
||||
'creating a %(net)s provider network') %
|
||||
{'tz': tz_type, 'net': net_type})
|
||||
|
||||
if err_msg:
|
||||
raise n_exc.InvalidInput(error_message=err_msg)
|
||||
|
||||
return is_provider_net, net_type, physical_net, vlan_id
|
||||
|
||||
def _get_edge_cluster(self, tier0_uuid):
|
||||
|
@ -290,10 +290,13 @@ class NsxNativeDhcpTestCase(test_plugin.NsxV3PluginTestCaseMixin):
|
||||
povidernet_args = {pnet.NETWORK_TYPE: 'vlan',
|
||||
pnet.PHYSICAL_NETWORK: 'tzuuid',
|
||||
pnet.SEGMENTATION_ID: 100}
|
||||
with self.network(providernet_args=povidernet_args,
|
||||
arg_list=(pnet.NETWORK_TYPE,
|
||||
pnet.PHYSICAL_NETWORK,
|
||||
pnet.SEGMENTATION_ID)) as network:
|
||||
with mock.patch(
|
||||
'vmware_nsxlib.v3.core_resources.NsxLibTransportZone.'
|
||||
'get_transport_type', return_value='VLAN'),\
|
||||
self.network(providernet_args=povidernet_args,
|
||||
arg_list=(pnet.NETWORK_TYPE,
|
||||
pnet.PHYSICAL_NETWORK,
|
||||
pnet.SEGMENTATION_ID)) as network:
|
||||
subnet = {'subnet': {'network_id': network['network']['id'],
|
||||
'cidr': '10.0.0.0/24',
|
||||
'enable_dhcp': True}}
|
||||
|
Loading…
Reference in New Issue
Block a user