Merge "NSXv3: Fix typo in URI while setting GW for router"
This commit is contained in:
commit
e5c24c01ef
|
@ -353,14 +353,14 @@ class LogicalRouterPort(AbstractRESTResource):
|
|||
return self._client.url_delete(logical_port_id)
|
||||
|
||||
def get_by_lswitch_id(self, logical_switch_id):
|
||||
resource = ('logical-router-ports?logical_switch_id=%s' %
|
||||
logical_switch_id)
|
||||
resource = '?logical_switch_id=%s' % logical_switch_id
|
||||
router_ports = self._client.url_get(resource)
|
||||
if int(router_ports['result_count']) >= 2:
|
||||
result_count = int(router_ports.get('result_count', "0"))
|
||||
if result_count >= 2:
|
||||
raise nsx_exc.NsxPluginException(
|
||||
err_msg=_("Can't support more than one logical router ports "
|
||||
"on same logical switch %s ") % logical_switch_id)
|
||||
elif int(router_ports['result_count']) == 1:
|
||||
elif result_count == 1:
|
||||
return router_ports['results'][0]
|
||||
else:
|
||||
err_msg = (_("Logical router link port not found on logical "
|
||||
|
@ -377,8 +377,7 @@ class LogicalRouterPort(AbstractRESTResource):
|
|||
self.delete(port['id'])
|
||||
|
||||
def get_by_router_id(self, logical_router_id):
|
||||
resource = ('logical-router-ports/?logical_router_id=%s' %
|
||||
logical_router_id)
|
||||
resource = '?logical_router_id=%s' % logical_router_id
|
||||
logical_router_ports = self._client.url_get(resource)
|
||||
return logical_router_ports['results']
|
||||
|
||||
|
|
|
@ -52,8 +52,7 @@ class RouterLib(object):
|
|||
return
|
||||
err_msg = None
|
||||
try:
|
||||
resource = 'logical-routers/%s' % tier0_uuid
|
||||
lrouter = self._router_client.get(resource)
|
||||
lrouter = self._router_client.get(tier0_uuid)
|
||||
except nsx_exc.ResourceNotFound:
|
||||
err_msg = _("Failed to validate tier0 router %s since it is "
|
||||
"not found at the backend") % tier0_uuid
|
||||
|
|
|
@ -73,11 +73,6 @@ class NsxV3PluginTestCaseMixin(test_plugin.NeutronDbPluginV2TestCase,
|
|||
super(NsxV3PluginTestCaseMixin, self).setUp(plugin=plugin,
|
||||
ext_mgr=ext_mgr)
|
||||
|
||||
if getattr(self.plugin, '_nsx_client', None):
|
||||
self.plugin._nsx_client = self.client
|
||||
if getattr(self.plugin, '_port_client', None):
|
||||
self.plugin._port_client._client._session = self.mock_api
|
||||
|
||||
self.maxDiff = None
|
||||
|
||||
def tearDown(self):
|
||||
|
|
|
@ -152,17 +152,39 @@ class NsxClientTestCase(NsxLibTestCase):
|
|||
return client_fn(*args, **kwargs)
|
||||
return _client
|
||||
|
||||
def _mock_client_init(*args, **kwargs):
|
||||
return with_client
|
||||
def _proxy_new_client_for(client):
|
||||
|
||||
new_client_fn = client.new_client_for
|
||||
|
||||
def _new_client_for(*uri_segs):
|
||||
new_client = new_client_fn(*uri_segs)
|
||||
new_client._session = mock_session
|
||||
new_client.new_client_for = _proxy_new_client_for(new_client)
|
||||
return new_client
|
||||
return _new_client_for
|
||||
|
||||
def _proxy_init(class_name):
|
||||
client_init = getattr(nsx_client, class_name)
|
||||
|
||||
def _init_client(*args, **kwargs):
|
||||
if (not args and not kwargs and
|
||||
with_client.__class__.__name__ == class_name):
|
||||
return with_client
|
||||
|
||||
client = client_init(*args, **kwargs)
|
||||
client._session = mock_session
|
||||
return client
|
||||
|
||||
return _init_client
|
||||
|
||||
fn_map = {}
|
||||
for fn in BRIDGE_FNS:
|
||||
fn_map[fn] = _call_client(fn)
|
||||
|
||||
fn_map['NSX3Client'] = _mock_client_init
|
||||
fn_map['JSONRESTClient'] = _mock_client_init
|
||||
fn_map['RESTClient'] = _mock_client_init
|
||||
fn_map['NSX3Client'] = _proxy_init('NSX3Client')
|
||||
fn_map['JSONRESTClient'] = _proxy_init('JSONRESTClient')
|
||||
fn_map['RESTClient'] = _proxy_init('RESTClient')
|
||||
|
||||
with_client.new_client_for = _mock_client_init
|
||||
with_client.new_client_for = _proxy_new_client_for(with_client)
|
||||
|
||||
return cls.patch_client_module(in_module, fn_map)
|
||||
|
|
|
@ -346,7 +346,7 @@ class LogicalRouterPortTestCase(nsxlib_testcase.NsxClientTestCase):
|
|||
|
||||
def test_create_logical_router_port(self):
|
||||
"""
|
||||
Test creating a router returns the correct response and 201 status
|
||||
Test creating a router port returns the correct response and 201 status
|
||||
"""
|
||||
fake_router_port = test_constants_v3.FAKE_ROUTER_PORT.copy()
|
||||
|
||||
|
@ -394,3 +394,54 @@ class LogicalRouterPortTestCase(nsxlib_testcase.NsxClientTestCase):
|
|||
None,
|
||||
client.JSONRESTClient._DEFAULT_HEADERS,
|
||||
nsxlib_testcase.NSX_CERT)
|
||||
|
||||
def test_get_logical_router_port_by_router_id(self):
|
||||
"""
|
||||
Test getting a router port by router id
|
||||
"""
|
||||
fake_router_port = test_constants_v3.FAKE_ROUTER_PORT.copy()
|
||||
resp_resources = {'results': [fake_router_port]}
|
||||
|
||||
api = resources.LogicalRouterPort(client.NSX3Client())
|
||||
with self.mocked_resource(api) as mocked:
|
||||
mocked.get('get').return_value = mocks.MockRequestsResponse(
|
||||
200, jsonutils.dumps(resp_resources))
|
||||
|
||||
router_id = fake_router_port['logical_router_id']
|
||||
result = api.get_by_router_id(router_id)
|
||||
self.assertEqual(fake_router_port, result[0])
|
||||
test_client.assert_session_call(
|
||||
mocked.get('get'),
|
||||
'https://1.2.3.4/api/v1/logical-router-ports/?'
|
||||
'logical_router_id=%s' % router_id,
|
||||
False,
|
||||
None,
|
||||
client.JSONRESTClient._DEFAULT_HEADERS,
|
||||
nsxlib_testcase.NSX_CERT)
|
||||
|
||||
def test_get_logical_router_port_by_switch_id(self):
|
||||
"""
|
||||
Test getting a router port by switch id
|
||||
"""
|
||||
fake_router_port = test_constants_v3.FAKE_ROUTER_PORT.copy()
|
||||
resp_resources = {
|
||||
'result_count': 1,
|
||||
'results': [fake_router_port]
|
||||
}
|
||||
|
||||
api = resources.LogicalRouterPort(client.NSX3Client())
|
||||
with self.mocked_resource(api) as mocked:
|
||||
mocked.get('get').return_value = mocks.MockRequestsResponse(
|
||||
200, jsonutils.dumps(resp_resources))
|
||||
|
||||
switch_id = test_constants_v3.FAKE_SWITCH_UUID
|
||||
result = api.get_by_lswitch_id(switch_id)
|
||||
self.assertEqual(fake_router_port, result)
|
||||
test_client.assert_session_call(
|
||||
mocked.get('get'),
|
||||
'https://1.2.3.4/api/v1/logical-router-ports/?'
|
||||
'logical_switch_id=%s' % switch_id,
|
||||
False,
|
||||
None,
|
||||
client.JSONRESTClient._DEFAULT_HEADERS,
|
||||
nsxlib_testcase.NSX_CERT)
|
||||
|
|
Loading…
Reference in New Issue