]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
NSX: Fix fake_api_client to raise NotFound
authorAaron Rosen <aaronorosen@gmail.com>
Tue, 22 Apr 2014 19:46:08 +0000 (12:46 -0700)
committerThomas Goirand <thomas@goirand.fr>
Mon, 9 Jun 2014 15:06:54 +0000 (23:06 +0800)
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
neutron/tests/unit/vmware/nsxlib/test_switch.py

index 2ca35ea407aee37ab94eb3ed1755d3c0d3dd8e6c..4d54a1824a3e1c2f0166d0164fae73d9795d690b 100644 (file)
@@ -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:
index 9735df448f30ab8189736cdb840b379b7dd28a11..987360c915183196a7754b8bfc7068de3c0f5948 100644 (file)
@@ -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):