From 7556e12f9340e8d149599e9cf037dde5b79997d5 Mon Sep 17 00:00:00 2001 From: Aaron Rosen Date: Tue, 22 Apr 2014 12:46:08 -0700 Subject: [PATCH] NSX: Fix fake_api_client to raise NotFound If one quries NSX doing GET /ws.v1/lswitch/LS_UUID/lport and LS_UUID is a UUID that does not exist in NSX. NSX raises a 404. If LS_UUID is * NSX returns an empty result string. This patch fixes the fake_api_client so that it's behavior is correct. Change-Id: Id66299d6ae3cfa43a65d4cb28f34348d64d8ed65 Closes-bug: 1311291 (cherry picked from commit dd143a619900792a0563b9ac4fe1f78197291d94) --- neutron/tests/unit/vmware/apiclient/fake.py | 3 +++ neutron/tests/unit/vmware/nsxlib/test_switch.py | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/neutron/tests/unit/vmware/apiclient/fake.py b/neutron/tests/unit/vmware/apiclient/fake.py index 2ca35ea407..4d54a1824a 100644 --- a/neutron/tests/unit/vmware/apiclient/fake.py +++ b/neutron/tests/unit/vmware/apiclient/fake.py @@ -381,6 +381,9 @@ class FakeClient: res_dict = getattr(self, '_fake_%s_dict' % resource_type) if parent_uuid == '*': parent_uuid = None + # NSX raises ResourceNotFound if lswitch doesn't exist and is not * + elif not res_dict and resource_type == self.LSWITCH_LPORT_RESOURCE: + raise api_exc.ResourceNotFound() def _attr_match(res_uuid): if not attr_filter: diff --git a/neutron/tests/unit/vmware/nsxlib/test_switch.py b/neutron/tests/unit/vmware/nsxlib/test_switch.py index 9735df448f..987360c915 100644 --- a/neutron/tests/unit/vmware/nsxlib/test_switch.py +++ b/neutron/tests/unit/vmware/nsxlib/test_switch.py @@ -183,7 +183,7 @@ class LogicalPortsTestCase(base.NsxlibTestCase): self.assertIsNotNone(lport2) self.assertEqual(lport['uuid'], lport2['uuid']) - def test_get_port_by_tag_not_found_returns_None(self): + def test_get_port_by_tag_not_found_with_switch_id_raises_not_found(self): tenant_id = 'pippo' neutron_port_id = 'whatever' transport_zones_config = [{'zone_uuid': _uuid(), @@ -191,8 +191,21 @@ class LogicalPortsTestCase(base.NsxlibTestCase): lswitch = switchlib.create_lswitch( self.fake_cluster, tenant_id, _uuid(), 'fake-switch', transport_zones_config) + self.assertRaises(exceptions.NotFound, + switchlib.get_port_by_neutron_tag, + self.fake_cluster, lswitch['uuid'], + neutron_port_id) + + def test_get_port_by_tag_not_find_wildcard_lswitch_returns_none(self): + tenant_id = 'pippo' + neutron_port_id = 'whatever' + transport_zones_config = [{'zone_uuid': _uuid(), + 'transport_type': 'stt'}] + switchlib.create_lswitch( + self.fake_cluster, tenant_id, _uuid(), + 'fake-switch', transport_zones_config) lport = switchlib.get_port_by_neutron_tag( - self.fake_cluster, lswitch['uuid'], neutron_port_id) + self.fake_cluster, '*', neutron_port_id) self.assertIsNone(lport) def test_get_port_status(self):