NSX plugin: fix get_gateway_devices

Fixes the error and adds relevant unit tests.
Also fixes get_gateway_devices signature for allowing
paging and sorting.

Closes-Bug: 1306301

Change-Id: Icb52a764e111365beaf4dc4fb4a5b8970a6cf887
This commit is contained in:
Salvatore Orlando 2014-04-10 16:55:51 -07:00
parent ee2bec2677
commit 40797ed653
3 changed files with 26 additions and 2 deletions

View File

@ -451,7 +451,6 @@ class NetworkGatewayMixin(networkgw.NetworkGatewayPluginBase):
query = self._get_collection_query(context, query = self._get_collection_query(context,
NetworkGatewayDevice, NetworkGatewayDevice,
filters=filters, filters=filters,
fields=fields,
sorts=sorts, sorts=sorts,
limit=limit, limit=limit,
marker_obj=marker_obj, marker_obj=marker_obj,

View File

@ -2231,7 +2231,9 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
gw_device['status'] = device_status gw_device['status'] = device_status
return gw_device return gw_device
def get_gateway_devices(self, context, filters=None, fields=None): def get_gateway_devices(self, context, filters=None, fields=None,
sorts=None, limit=None, marker=None,
page_reverse=False):
# Get devices from database # Get devices from database
devices = super(NsxPluginV2, self).get_gateway_devices( devices = super(NsxPluginV2, self).get_gateway_devices(
context, filters, fields, include_nsx_id=True) context, filters, fields, include_nsx_id=True)

View File

@ -800,6 +800,25 @@ class NetworkGatewayDbTestCase(test_db_plugin.NeutronDbPluginV2TestCase):
self.assertEqual(dev[self.dev_resource]['connector_ip'], '1.1.1.1') self.assertEqual(dev[self.dev_resource]['connector_ip'], '1.1.1.1')
self.assertEqual(dev[self.dev_resource]['status'], expected_status) self.assertEqual(dev[self.dev_resource]['status'], expected_status)
def test_list_gateway_devices(self):
with contextlib.nested(
self._gateway_device(name='test-dev-1',
connector_type='stt',
connector_ip='1.1.1.1',
client_certificate='xyz'),
self._gateway_device(name='test-dev-2',
connector_type='stt',
connector_ip='2.2.2.2',
client_certificate='qwe')) as (dev_1, dev_2):
req = self.new_list_request(networkgw.GATEWAY_DEVICES)
res = self.deserialize('json', req.get_response(self.ext_api))
devices = res[networkgw.GATEWAY_DEVICES.replace('-', '_')]
self.assertEqual(len(devices), 2)
dev_1 = devices[0]
dev_2 = devices[1]
self.assertEqual(dev_1['name'], 'test-dev-1')
self.assertEqual(dev_2['name'], 'test-dev-2')
def test_get_gateway_device( def test_get_gateway_device(
self, expected_status=networkgw_db.STATUS_UNKNOWN): self, expected_status=networkgw_db.STATUS_UNKNOWN):
with self._gateway_device(name='test-dev', with self._gateway_device(name='test-dev',
@ -862,11 +881,15 @@ class TestNetworkGateway(NsxPluginV2TestCase,
l2gwlib, 'delete_gateway_device') l2gwlib, 'delete_gateway_device')
get_gw_dev_status_patcher = mock.patch.object( get_gw_dev_status_patcher = mock.patch.object(
l2gwlib, 'get_gateway_device_status') l2gwlib, 'get_gateway_device_status')
get_gw_dev_statuses_patcher = mock.patch.object(
l2gwlib, 'get_gateway_devices_status')
self.mock_create_gw_dev = create_gw_dev_patcher.start() self.mock_create_gw_dev = create_gw_dev_patcher.start()
self.mock_create_gw_dev.return_value = {'uuid': 'callejon'} self.mock_create_gw_dev.return_value = {'uuid': 'callejon'}
self.mock_update_gw_dev = update_gw_dev_patcher.start() self.mock_update_gw_dev = update_gw_dev_patcher.start()
delete_gw_dev_patcher.start() delete_gw_dev_patcher.start()
self.mock_get_gw_dev_status = get_gw_dev_status_patcher.start() self.mock_get_gw_dev_status = get_gw_dev_status_patcher.start()
get_gw_dev_statuses = get_gw_dev_statuses_patcher.start()
get_gw_dev_statuses.return_value = {}
super(TestNetworkGateway, super(TestNetworkGateway,
self).setUp(plugin=plugin, ext_mgr=ext_mgr) self).setUp(plugin=plugin, ext_mgr=ext_mgr)