]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Remove wrong reference to object attribute in nvplib
authorarmando-migliaccio <amigliaccio@nicira.com>
Tue, 11 Jun 2013 07:05:13 +0000 (00:05 -0700)
committerarmando-migliaccio <amigliaccio@nicira.com>
Wed, 12 Jun 2013 19:48:36 +0000 (12:48 -0700)
Plus, added negative tests that were not covering the
exception handling bits.

Fixes bug #1189730

Change-Id: I5df914c6b748a03816217336431c2b0b597481b5

quantum/plugins/nicira/nvplib.py
quantum/tests/unit/nicira/test_nvplib.py

index 58054882b969377b53b5ca8edc7789463da8b125..ed98800b9b59f35815c36891b719e8df9d874482 100644 (file)
@@ -381,8 +381,9 @@ def create_l2_gw_service(cluster, tenant_id, display_name, devices):
             json.dumps(gwservice_obj), cluster=cluster))
     except NvpApiClient.NvpApiException:
         # just log and re-raise - let the caller handle it
-        LOG.exception(_("An exception occured while communicating with "
-                        "the NVP controller for cluster:%s"), cluster.name)
+        LOG.exception(_("Unable to create L2 Gateway Service "
+                        "%(name)s for tenant %(id)s.")
+                      % {'name': display_name, 'id': tenant_id})
         raise
 
 
@@ -419,8 +420,9 @@ def create_lrouter(cluster, tenant_id, display_name, nexthop):
                                             cluster=cluster))
     except NvpApiClient.NvpApiException:
         # just log and re-raise - let the caller handle it
-        LOG.exception(_("An exception occured while communicating with "
-                        "the NVP controller for cluster:%s"), cluster.name)
+        LOG.exception(_("Unable to create Router "
+                        "%(name)s for tenant %(id)s.")
+                      % {'name': display_name, 'id': tenant_id})
         raise
 
 
@@ -432,8 +434,8 @@ def delete_lrouter(cluster, lrouter_id):
                           cluster=cluster)
     except NvpApiClient.NvpApiException:
         # just log and re-raise - let the caller handle it
-        LOG.exception(_("An exception occured while communicating with "
-                        "the NVP controller for cluster:%s"), cluster.name)
+        LOG.exception(_("Unable to delete Router "
+                        "Service %s."), lrouter_id)
         raise
 
 
@@ -445,8 +447,8 @@ def delete_l2_gw_service(cluster, gateway_id):
                           cluster=cluster)
     except NvpApiClient.NvpApiException:
         # just log and re-raise - let the caller handle it
-        LOG.exception(_("An exception occured while communicating with "
-                        "the NVP controller for cluster:%s"), cluster.name)
+        LOG.exception(_("Unable to delete L2 Gateway "
+                        "Service %s."), gateway_id)
         raise
 
 
@@ -459,8 +461,8 @@ def get_lrouter(cluster, lrouter_id):
                           cluster=cluster))
     except NvpApiClient.NvpApiException:
         # just log and re-raise - let the caller handle it
-        LOG.exception(_("An exception occured while communicating with "
-                        "the NVP controller for cluster:%s"), cluster.name)
+        LOG.exception(_("Unable to get Router "
+                        "Service %s."), lrouter_id)
         raise
 
 
@@ -472,8 +474,8 @@ def get_l2_gw_service(cluster, gateway_id):
                           cluster=cluster))
     except NvpApiClient.NvpApiException:
         # just log and re-raise - let the caller handle it
-        LOG.exception(_("An exception occured while communicating with "
-                        "the NVP controller for cluster:%s"), cluster.name)
+        LOG.exception(_("Unable to get L2 Gateway "
+                        "Service %s."), gateway_id)
         raise
 
 
@@ -520,8 +522,9 @@ def update_l2_gw_service(cluster, gateway_id, display_name):
                           cluster=cluster))
     except NvpApiClient.NvpApiException:
         # just log and re-raise - let the caller handle it
-        LOG.exception(_("An exception occured while communicating with "
-                        "the NVP controller for cluster:%s"), cluster.name)
+        LOG.exception(_("Unable to update L2 Gateway Service "
+                        "%(id)s with name %(name)s.") %
+                      {'id': gateway_id, 'name': display_name})
         raise
 
 
@@ -546,8 +549,9 @@ def update_lrouter(cluster, lrouter_id, display_name, nexthop):
                           cluster=cluster))
     except NvpApiClient.NvpApiException:
         # just log and re-raise - let the caller handle it
-        LOG.exception(_("An exception occured while communicating with "
-                        "the NVP controller for cluster:%s"), cluster.name)
+        LOG.exception(_("Unable to update Router "
+                        "%(id)s with name %(name)s.") %
+                      {'id': lrouter_id, 'name': display_name})
         raise
 
 
index 8628aab350d69847cd3f48f0725f58b700b45d3b..87a694dd166c253f462ef533e304112e402ee13e 100644 (file)
@@ -94,6 +94,91 @@ class TestNvplibNatRules(NvplibTestCase):
                          resp_obj['match']['destination_ip_addresses'])
 
 
+class NvplibNegativeTests(base.BaseTestCase):
+
+    def setUp(self):
+        # mock nvp api client
+        etc_path = os.path.join(os.path.dirname(__file__), 'etc')
+        self.fc = fake_nvpapiclient.FakeClient(etc_path)
+        self.mock_nvpapi = mock.patch('%s.NvpApiClient.NVPApiHelper'
+                                      % NICIRA_PKG_PATH, autospec=True)
+        instance = self.mock_nvpapi.start()
+        instance.return_value.login.return_value = "the_cookie"
+
+        def _faulty_request(*args, **kwargs):
+            raise nvplib.NvpApiClient.NvpApiException
+
+        instance.return_value.request.side_effect = _faulty_request
+        self.fake_cluster = nvp_cluster.NVPCluster(
+            name='fake-cluster', nvp_controllers=['1.1.1.1:999'],
+            default_tz_uuid=_uuid(), nvp_user='foo', nvp_password='bar')
+        self.fake_cluster.api_client = NvpApiClient.NVPApiHelper(
+            ('1.1.1.1', '999', True),
+            self.fake_cluster.nvp_user, self.fake_cluster.nvp_password,
+            self.fake_cluster.req_timeout, self.fake_cluster.http_timeout,
+            self.fake_cluster.retries, self.fake_cluster.redirects)
+
+        super(NvplibNegativeTests, self).setUp()
+        self.addCleanup(self.fc.reset_all)
+        self.addCleanup(self.mock_nvpapi.stop)
+
+    def test_create_l2_gw_service_on_failure(self):
+        self.assertRaises(nvplib.NvpApiClient.NvpApiException,
+                          nvplib.create_l2_gw_service,
+                          self.fake_cluster,
+                          'fake-tenant',
+                          'fake-gateway',
+                          [{'id': _uuid(),
+                          'interface_name': 'xxx'}])
+
+    def test_delete_l2_gw_service_on_failure(self):
+        self.assertRaises(nvplib.NvpApiClient.NvpApiException,
+                          nvplib.delete_l2_gw_service,
+                          self.fake_cluster,
+                          'fake-gateway')
+
+    def test_get_l2_gw_service_on_failure(self):
+        self.assertRaises(nvplib.NvpApiClient.NvpApiException,
+                          nvplib.get_l2_gw_service,
+                          self.fake_cluster,
+                          'fake-gateway')
+
+    def test_update_l2_gw_service_on_failure(self):
+        self.assertRaises(nvplib.NvpApiClient.NvpApiException,
+                          nvplib.update_l2_gw_service,
+                          self.fake_cluster,
+                          'fake-gateway',
+                          'pluto')
+
+    def test_create_lrouter_on_failure(self):
+        self.assertRaises(nvplib.NvpApiClient.NvpApiException,
+                          nvplib.create_lrouter,
+                          self.fake_cluster,
+                          'pluto',
+                          'fake_router',
+                          'my_hop')
+
+    def test_delete_lrouter_on_failure(self):
+        self.assertRaises(nvplib.NvpApiClient.NvpApiException,
+                          nvplib.delete_lrouter,
+                          self.fake_cluster,
+                          'fake_router')
+
+    def test_get_lrouter_on_failure(self):
+        self.assertRaises(nvplib.NvpApiClient.NvpApiException,
+                          nvplib.get_lrouter,
+                          self.fake_cluster,
+                          'fake_router')
+
+    def test_update_lrouter_on_failure(self):
+        self.assertRaises(nvplib.NvpApiClient.NvpApiException,
+                          nvplib.update_lrouter,
+                          self.fake_cluster,
+                          'fake_router',
+                          'pluto',
+                          'new_hop')
+
+
 class NvplibL2GatewayTestCase(NvplibTestCase):
 
     def _create_gw_service(self, node_uuid, display_name):