Enable availability zone for network

With neutron AZ awareness enablement in Mitaka, NSX|T driver could
also support AZ for L2. We can put dhcp agent into different zone,
and create networks with availability zone.

Change-Id: I87a257742a9ea3a39bb3fc9591d3f8164ac70691
This commit is contained in:
yuyangbj 2015-12-17 17:31:45 +08:00 committed by Kobi Samoray
parent 71d2738292
commit d68d0f436d
3 changed files with 55 additions and 5 deletions

View File

@ -42,6 +42,7 @@ from neutron.db import portbindings_db
from neutron.db import portsecurity_db
from neutron.db import securitygroups_db
from neutron.extensions import allowedaddresspairs as addr_pair
from neutron.extensions import availability_zone as az_ext
from neutron.extensions import external_net as ext_net_extn
from neutron.extensions import extra_dhcp_opt as ext_edo
from neutron.extensions import l3
@ -87,7 +88,7 @@ class NsxV3Plugin(addr_pair_db.AllowedAddressPairsMixin,
l3_gwmode_db.L3_NAT_db_mixin,
portbindings_db.PortBindingMixin,
portsecurity_db.PortSecurityDbMixin,
agentschedulers_db.DhcpAgentSchedulerDbMixin,
agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
extradhcpopt_db.ExtraDhcpOptMixin):
__native_bulk_support = True
@ -106,7 +107,9 @@ class NsxV3Plugin(addr_pair_db.AllowedAddressPairsMixin,
"provider",
"external-net",
"extraroute",
"router"]
"router",
"availability_zone",
"network_availability_zone"]
def __init__(self):
super(NsxV3Plugin, self).__init__()
@ -426,6 +429,17 @@ class NsxV3Plugin(addr_pair_db.AllowedAddressPairsMixin,
self._process_network_port_security_create(
context, net_data, created_net)
self._process_l3_create(context, created_net, net_data)
if az_ext.AZ_HINTS in net_data:
self.validate_availability_zones(context, 'network',
net_data[az_ext.AZ_HINTS])
az_hints = az_ext.convert_az_list_to_string(
net_data[az_ext.AZ_HINTS])
net_id = created_net['id']
super(NsxV3Plugin, self).update_network(context,
net_id, {'network': {az_ext.AZ_HINTS: az_hints}})
created_net[az_ext.AZ_HINTS] = az_hints
except Exception:
with excutils.save_and_reraise_exception():
# Undo creation on the backend

View File

@ -19,6 +19,8 @@ from neutron.api.v2 import attributes
from neutron.common import constants
from neutron.common import exceptions as n_exc
from neutron import context
from neutron.db import models_v2
from neutron.extensions import availability_zone as az_ext
from neutron.extensions import external_net
from neutron.extensions import extraroute
from neutron.extensions import l3
@ -34,6 +36,8 @@ from neutron.tests.unit.extensions import test_extraroute as test_ext_route
from neutron.tests.unit.extensions import test_l3 as test_l3_plugin
from neutron.tests.unit.extensions \
import test_l3_ext_gw_mode as test_ext_gw_mode
from neutron.tests.unit.scheduler \
import test_dhcp_agent_scheduler as test_dhcpagent
from neutron import version
from oslo_config import cfg
@ -138,8 +142,8 @@ class NsxV3PluginTestCaseMixin(test_plugin.NeutronDbPluginV2TestCase,
attrs = kwargs
if providernet_args:
attrs.update(providernet_args)
for arg in (('admin_state_up', 'tenant_id', 'shared') +
(arg_list or ())):
for arg in (('admin_state_up', 'tenant_id', 'shared',
'availability_zone_hints') + (arg_list or ())):
# Arg must be present
if arg in kwargs:
data['network'][arg] = kwargs[arg]
@ -150,9 +154,25 @@ class NsxV3PluginTestCaseMixin(test_plugin.NeutronDbPluginV2TestCase,
'', kwargs['tenant_id'])
return network_req.get_response(self.api)
def _save_networks(self, networks):
ctx = context.get_admin_context()
for network_id in networks:
with ctx.session.begin(subtransactions=True):
ctx.session.add(models_v2.Network(id=network_id))
class TestNetworksV2(test_plugin.TestNetworksV2, NsxV3PluginTestCaseMixin):
pass
@mock.patch.object(nsx_plugin.NsxV3Plugin, 'validate_availability_zones')
def test_create_network_with_zone(self, mock_validate_az):
name = 'net-with-zone'
zone = ['zone1']
mock_validate_az.return_value = None
with self.network(name=name, availability_zone_hints=zone) as net:
az_hints = net['network']['availability_zone_hints']
az_hints_list = az_ext.convert_az_string_to_list(az_hints)
self.assertListEqual(az_hints_list, zone)
class TestPortsV2(test_plugin.TestPortsV2, NsxV3PluginTestCaseMixin,
@ -190,6 +210,20 @@ class DHCPOptsTestCase(test_dhcpopts.TestExtraDhcpOpt,
plugin=PLUGIN_NAME)
class NSXv3DHCPAgentAZAwareWeightSchedulerTestCase(
test_dhcpagent.DHCPAgentAZAwareWeightSchedulerTestCase,
NsxV3PluginTestCaseMixin):
def setUp(self):
super(NSXv3DHCPAgentAZAwareWeightSchedulerTestCase, self).setUp()
self.plugin = manager.NeutronManager.get_plugin()
self.ctx = context.get_admin_context()
def setup_coreplugin(self, core_plugin=None):
super(NSXv3DHCPAgentAZAwareWeightSchedulerTestCase,
self).setup_coreplugin(core_plugin=PLUGIN_NAME)
class TestL3ExtensionManager(object):
def get_resources(self):

View File

@ -44,6 +44,8 @@ class NsxLibTestCase(unittest.TestCase):
cfg.CONF.set_override('nsx_api_managers', [NSX_MANAGER], 'nsx_v3')
cfg.CONF.set_override('insecure', NSX_INSECURE, 'nsx_v3')
cfg.CONF.set_override('ca_file', NSX_CERT, 'nsx_v3')
cfg.CONF.set_override('network_scheduler_driver',
'neutron.scheduler.dhcp_agent_scheduler.AZAwareWeightScheduler')
def setUp(self, *args, **kwargs):
super(NsxLibTestCase, self).setUp()