Merge "subnet host route support"

This commit is contained in:
Jenkins 2016-03-31 13:34:22 +00:00 committed by Gerrit Code Review
commit 6e5663600c
3 changed files with 37 additions and 48 deletions

View File

@ -1273,6 +1273,31 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
self.metadata_proxy_handler and self.metadata_proxy_handler and
cfg.CONF.nsxv.dhcp_force_metadata) cfg.CONF.nsxv.dhcp_force_metadata)
def _validate_host_routes_input(self, subnet_input,
orig_enable_dhcp=None,
orig_host_routes=None):
s = subnet_input['subnet']
request_host_routes = (attr.is_attr_set(s.get('host_routes')) and
s['host_routes'])
clear_host_routes = (attr.is_attr_set(s.get('host_routes')) and
not s['host_routes'])
request_enable_dhcp = s.get('enable_dhcp')
if request_enable_dhcp is False:
if (request_host_routes or
not clear_host_routes and orig_host_routes):
err_msg = _("Can't disable DHCP while using host routes")
raise n_exc.InvalidInput(error_message=err_msg)
if request_host_routes:
if not request_enable_dhcp and orig_enable_dhcp is False:
err_msg = _("Host routes can only be supported when DHCP "
"is enabled")
raise n_exc.InvalidInput(error_message=err_msg)
if not self.edge_manager.is_dhcp_opt_enabled:
err_msg = _("Host routes can only be supported at NSX version "
"6.2.3 or higher")
raise n_exc.InvalidInput(error_message=err_msg)
def create_subnet(self, context, subnet): def create_subnet(self, context, subnet):
"""Create subnet on nsx_v provider network. """Create subnet on nsx_v provider network.
@ -1280,9 +1305,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
the subnet is attached is not bound to an DHCP Edge, nsx_v will the subnet is attached is not bound to an DHCP Edge, nsx_v will
create the Edge and make sure the network is bound to the Edge create the Edge and make sure the network is bound to the Edge
""" """
if subnet['subnet']['host_routes'] != attr.ATTR_NOT_SPECIFIED: self._validate_host_routes_input(subnet)
err_msg = _("Host routes not supported by plugin")
raise n_exc.InvalidInput(error_message=err_msg)
if subnet['subnet']['enable_dhcp']: if subnet['subnet']['enable_dhcp']:
filters = {'id': [subnet['subnet']['network_id']], filters = {'id': [subnet['subnet']['network_id']],
'router:external': [True]} 'router:external': [True]}
@ -1351,17 +1374,19 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
def update_subnet(self, context, id, subnet): def update_subnet(self, context, id, subnet):
s = subnet['subnet'] s = subnet['subnet']
if "host_routes" in s and s["host_routes"]:
err_msg = _("Host routes not supported by plugin")
raise n_exc.InvalidInput(error_message=err_msg)
orig = self._get_subnet(context, id) orig = self._get_subnet(context, id)
gateway_ip = orig['gateway_ip'] gateway_ip = orig['gateway_ip']
enable_dhcp = orig['enable_dhcp'] enable_dhcp = orig['enable_dhcp']
orig_host_routes = orig['routes']
self._validate_host_routes_input(subnet,
orig_enable_dhcp=enable_dhcp,
orig_host_routes=orig_host_routes)
subnet = super(NsxVPluginV2, self).update_subnet(context, id, subnet) subnet = super(NsxVPluginV2, self).update_subnet(context, id, subnet)
update_dns_search_domain = self._process_subnet_ext_attr_update( update_dns_search_domain = self._process_subnet_ext_attr_update(
context.session, subnet, s) context.session, subnet, s)
if (gateway_ip != subnet['gateway_ip'] or update_dns_search_domain or if (gateway_ip != subnet['gateway_ip'] or update_dns_search_domain or
set(orig['dns_nameservers']) != set(subnet['dns_nameservers']) or set(orig['dns_nameservers']) != set(subnet['dns_nameservers']) or
orig_host_routes != subnet['host_routes'] or
enable_dhcp and not subnet['enable_dhcp']): enable_dhcp and not subnet['enable_dhcp']):
# Need to ensure that all of the subnet attributes will be reloaded # Need to ensure that all of the subnet attributes will be reloaded
# when creating the edge bindings. Without adding this the original # when creating the edge bindings. Without adding this the original

View File

@ -741,6 +741,11 @@ class EdgeManager(object):
static_config['domainName'] = sub_binding.dns_search_domain static_config['domainName'] = sub_binding.dns_search_domain
self.handle_meta_static_route( self.handle_meta_static_route(
context, subnet_id, [static_config]) context, subnet_id, [static_config])
for host_route in subnet['routes']:
self.add_host_route_on_static_bindings(
[static_config],
host_route['destination'],
host_route['nexthop'])
static_bindings.append(static_config) static_bindings.append(static_config)
return static_bindings return static_bindings

View File

@ -122,6 +122,7 @@ class NsxVPluginV2TestCase(test_plugin.NeutronDbPluginV2TestCase):
plugin_instance = manager.NeutronManager.get_plugin() plugin_instance = manager.NeutronManager.get_plugin()
plugin_instance._get_edge_id_by_rtr_id = mock.Mock() plugin_instance._get_edge_id_by_rtr_id = mock.Mock()
plugin_instance._get_edge_id_by_rtr_id.return_value = False plugin_instance._get_edge_id_by_rtr_id.return_value = False
plugin_instance.edge_manager.is_dhcp_opt_enabled = True
def test_get_vlan_network_name(self): def test_get_vlan_network_name(self):
p = manager.NeutronManager.get_plugin() p = manager.NeutronManager.get_plugin()
@ -1264,27 +1265,6 @@ class TestSubnetsV2(NsxVPluginV2TestCase,
kwargs.update({'override': overrides}) kwargs.update({'override': overrides})
return self._create_bulk(fmt, number, 'subnet', base_data, **kwargs) return self._create_bulk(fmt, number, 'subnet', base_data, **kwargs)
def test_create_subnet_with_two_host_routes(self):
self.skipTest("Skip test for not implemented host_routes feature")
def test_delete_subnet_with_route(self):
self.skipTest("Skip test for not implemented host_routes feature")
def test_update_subnet_adding_additional_host_routes_and_dns(self):
self.skipTest("Skip test for not implemented host_routes feature")
def test_delete_subnet_with_dns_and_route(self):
self.skipTest("Skip test for not implemented host_routes feature")
def test_update_subnet_route(self):
self.skipTest("Skip test for not implemented host_routes feature")
def test_update_subnet_route_to_None(self):
self.skipTest("Skip test for not implemented host_routes feature")
def test_create_subnet_with_one_host_route(self):
self.skipTest("Skip test for not implemented host_routes feature")
def test_create_subnet_nonzero_cidr(self): def test_create_subnet_nonzero_cidr(self):
awkward_cidrs = [{'nonezero': '10.129.122.5/8', awkward_cidrs = [{'nonezero': '10.129.122.5/8',
'corrected': '10.0.0.0/8'}, 'corrected': '10.0.0.0/8'},
@ -1459,12 +1439,6 @@ class TestSubnetPoolsV2(NsxVPluginV2TestCase, test_plugin.TestSubnetsV2):
def test_create_subnet_only_ip_version_v6(self): def test_create_subnet_only_ip_version_v6(self):
self.skipTest('Not supported') self.skipTest('Not supported')
def test_create_subnet_with_one_host_route(self):
self.skipTest("Skip test for not implemented host_routes feature")
def test_create_subnet_with_two_host_routes(self):
self.skipTest("Skip test for not implemented host_routes feature")
def test_create_subnet_with_v6_allocation_pool(self): def test_create_subnet_with_v6_allocation_pool(self):
self.skipTest('Not supported') self.skipTest('Not supported')
@ -1477,15 +1451,6 @@ class TestSubnetPoolsV2(NsxVPluginV2TestCase, test_plugin.TestSubnetsV2):
def test_delete_subnet_ipv6_slaac_router_port_exists(self): def test_delete_subnet_ipv6_slaac_router_port_exists(self):
self.skipTest('Not supported') self.skipTest('Not supported')
def test_delete_subnet_with_dns_and_route(self):
self.skipTest("Skip test for not implemented host_routes feature")
def test_delete_subnet_with_route(self):
self.skipTest("Skip test for not implemented host_routes feature")
def test_update_subnet_adding_additional_host_routes_and_dns(self):
self.skipTest("Skip test for not implemented host_routes feature")
def test_update_subnet_inconsistent_ipv6_gatewayv4(self): def test_update_subnet_inconsistent_ipv6_gatewayv4(self):
self.skipTest('Not supported') self.skipTest('Not supported')
@ -1507,12 +1472,6 @@ class TestSubnetPoolsV2(NsxVPluginV2TestCase, test_plugin.TestSubnetsV2):
def test_update_subnet_ipv6_ra_mode_fails(self): def test_update_subnet_ipv6_ra_mode_fails(self):
self.skipTest('Not supported') self.skipTest('Not supported')
def test_update_subnet_route(self):
self.skipTest("Skip test for not implemented host_routes feature")
def test_update_subnet_route_to_None(self):
self.skipTest("Skip test for not implemented host_routes feature")
def test_create_subnet_only_ip_version_v6_old(self): def test_create_subnet_only_ip_version_v6_old(self):
self.skipTest('Currently not supported') self.skipTest('Currently not supported')