]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
make assertRaises() test for specific exceptions
authorMark McClain <mark.mcclain@dreamhost.com>
Tue, 13 Aug 2013 19:49:55 +0000 (15:49 -0400)
committerMark McClain <mark.mcclain@dreamhost.com>
Tue, 13 Aug 2013 19:49:55 +0000 (15:49 -0400)
fixes bug: 1211951

Change-Id: Icf1401cc29e0a9c7fc68089e4c38f278181779be

neutron/plugins/nicira/common/exceptions.py
neutron/plugins/nicira/nvplib.py
neutron/tests/unit/nicira/test_nvplib.py

index 0c34010406a5fc3719382f0693b9cc0afd72b211..841655ca1c8cc039d64859911fa03d44b17566e7 100644 (file)
@@ -52,3 +52,7 @@ class NvpNatRuleMismatch(NvpPluginException):
     message = _("While retrieving NAT rules, %(actual_rules)s were found "
                 "whereas rules in the (%(min_rules)s,%(max_rules)s) interval "
                 "were expected")
+
+
+class NvpInvalidAttachmentType(NvpPluginException):
+    message = _("Invalid NVP attachment type '%(attachment_type)s'")
index 00a184f0625af1d81737303c4076487b652b77d0..0eecd8118b8becadf7d65778673fadf5d1d6bfe8 100644 (file)
@@ -866,9 +866,8 @@ def plug_router_port_attachment(cluster, router_id, port_id,
         if attachment_vlan:
             attach_obj['vlan_id'] = attachment_vlan
     else:
-        # TODO(salv-orlando): avoid raising generic exception
-        raise Exception(_("Invalid NVP attachment type '%s'"),
-                        nvp_attachment_type)
+        raise nvp_exc.NvpInvalidAttachmentType(
+            attachment_type=nvp_attachment_type)
     return do_request(HTTP_PUT, uri, json.dumps(attach_obj), cluster=cluster)
 
 
index e3c4a97a150796ae231c5c13866bb5616a35b360..fef5b5ca86dae5d4181f62776e7681b2621dbe80 100644 (file)
@@ -902,7 +902,7 @@ class TestNvplibLogicalRouters(NvplibTestCase):
         lrouter_port = nvplib.create_router_lport(
             self.fake_cluster, lrouter['uuid'], 'pippo', 'neutron_port_id',
             'name', True, ['192.168.0.1'])
-        self.assertRaises(Exception,
+        self.assertRaises(nvp_exc.NvpInvalidAttachmentType,
                           nvplib.plug_router_port_attachment,
                           self.fake_cluster, lrouter['uuid'],
                           lrouter_port['uuid'], 'gw_att', 'BadType')
@@ -965,7 +965,7 @@ class TestNvplibLogicalRouters(NvplibTestCase):
         with mock.patch.object(self.fake_cluster.api_client,
                                'get_nvp_version',
                                new=lambda: '2.0'):
-            self.assertRaises(Exception,
+            self.assertRaises(AttributeError,
                               nvplib.create_lrouter_snat_rule,
                               self.fake_cluster, lrouter['uuid'],
                               '10.0.0.2', '10.0.0.2', order=200,