From 7a260dd549277716061290be68ebe4fa074eedb3 Mon Sep 17 00:00:00 2001 From: Adit Sarfaty Date: Tue, 19 Jul 2016 10:53:53 +0300 Subject: [PATCH] NSX|v Add default availability zone to l2 gateway router creation L2 gateway router creation needs to get the default availability zone Also added missing tests for this router creation Change-Id: I27e519f016d6f0da513d6baedaaff441a99ca7dc --- vmware_nsx/services/l2gateway/nsx_v/driver.py | 7 +++- .../services/l2gateway/test_nsxv_driver.py | 37 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/vmware_nsx/services/l2gateway/nsx_v/driver.py b/vmware_nsx/services/l2gateway/nsx_v/driver.py index 29c147e9d9..168dc21299 100644 --- a/vmware_nsx/services/l2gateway/nsx_v/driver.py +++ b/vmware_nsx/services/l2gateway/nsx_v/driver.py @@ -28,6 +28,7 @@ from vmware_nsx.common import exceptions as nsx_exc from vmware_nsx.common import nsxv_constants from vmware_nsx.db import db as nsx_db from vmware_nsx.db import nsxv_db +from vmware_nsx.plugins.nsx_v import availability_zones as nsx_az from vmware_nsx.plugins.nsx_v.vshield.common import exceptions LOG = logging.getLogger(__name__) @@ -107,8 +108,12 @@ class NsxvL2GatewayDriver(l2gateway_db.L2GatewayMixin): # Create a dedicated DLR lrouter = {'name': nsxv_constants.L2_GATEWAY_EDGE, 'id': uuidutils.generate_uuid()} + # Create the router on the default availability zone + availability_zone = (nsx_az.ConfiguredAvailabilityZones(). + get_default_availability_zone()) self._edge_manager.create_lrouter(context, - lrouter, lswitch=None, dist=True) + lrouter, lswitch=None, dist=True, + availability_zone=availability_zone) edge_binding = nsxv_db.get_nsxv_router_binding(context.session, lrouter['id']) if not edge_binding: diff --git a/vmware_nsx/tests/unit/services/l2gateway/test_nsxv_driver.py b/vmware_nsx/tests/unit/services/l2gateway/test_nsxv_driver.py index 6527f3746a..7ac16c1e03 100644 --- a/vmware_nsx/tests/unit/services/l2gateway/test_nsxv_driver.py +++ b/vmware_nsx/tests/unit/services/l2gateway/test_nsxv_driver.py @@ -21,7 +21,12 @@ from networking_l2gw.db.l2gateway import l2gateway_db from neutron_lib import exceptions as n_exc from vmware_nsx.common import exceptions as nsx_exc from vmware_nsx.db import nsxv_db +from vmware_nsx.dvs import dvs +from vmware_nsx.dvs import dvs_utils from vmware_nsx.services.l2gateway.nsx_v import driver as nsx_v_driver +from vmware_nsx.tests.unit.nsx_v import test_plugin + +CORE_PLUGIN = "vmware_nsx.plugins.nsx_v.plugin.NsxVPluginV2" class TestL2gatewayDriver(base.BaseTestCase): @@ -170,3 +175,35 @@ class TestL2gatewayDriver(base.BaseTestCase): get_devices.assert_called_with(self.context, 'fake_l2gw_id') get_nsxv_router.assert_called_with(self.context.session, "fake_edge_name") + + +class TestL2GatewayDriverRouter(test_plugin.NsxVPluginV2TestCase): + + @mock.patch.object(dvs_utils, 'dvs_create_session') + @mock.patch.object(dvs.DvsManager, '_get_dvs_moref') + def setUp(self, *mocks): + # init the nsxv plugin, edge manager and fake vcns + super(TestL2GatewayDriverRouter, self).setUp(plugin=CORE_PLUGIN, + ext_mgr=None) + self.context = context.get_admin_context() + # init the L2 gateway driver + self.driver = nsx_v_driver.NsxvL2GatewayDriver(mock.MagicMock()) + + @mock.patch('vmware_nsx.services.l2gateway.' + 'nsx_v.driver.NsxvL2GatewayDriver._validate_device_list') + @mock.patch('vmware_nsx.services.l2gateway.' + 'nsx_v.driver.NsxvL2GatewayDriver._validate_interface_list') + def test_create_l2_gateway_router(self, val_inter, val_dev): + # Verify that creating the router doesn't fail + fake_l2gw_dict = {"l2_gateway": + {"tenant_id": "fake_teannt_id", + "name": "fake_l2gw", + "devices": [{"interfaces": + [{"name": "fake_inter"}], + "device_name": "fake_dev"}]}} + self.driver.create_l2_gateway(self.context, fake_l2gw_dict) + + def test_create_l2_gateway_router_edge(self): + # Verify that the router edge is really created + edge_id = self.driver._create_l2_gateway_edge(self.context) + self.assertEqual('edge-1', edge_id)