]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Throw exception instances instead of classes
authorEugene Nikanorov <enikanorov@mirantis.com>
Tue, 2 Sep 2014 13:22:34 +0000 (17:22 +0400)
committerEugene Nikanorov <enikanorov@mirantis.com>
Sun, 7 Sep 2014 08:56:30 +0000 (12:56 +0400)
Prefer single style of throwing instances and not classes.

Change-Id: If159afcd092de5381309cbe217d64145ed5b45b4
Closes-Bug: #1364392

19 files changed:
neutron/agent/linux/dhcp.py
neutron/api/v2/base.py
neutron/extensions/agent.py
neutron/neutron_plugin_base_v2.py
neutron/plugins/cisco/cfg_agent/device_drivers/csr1kv/csr1kv_routing_driver.py
neutron/plugins/cisco/db/n1kv_db_v2.py
neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py
neutron/plugins/metaplugin/meta_neutron_plugin.py
neutron/plugins/ml2/drivers/helpers.py
neutron/plugins/ml2/drivers/type_tunnel.py
neutron/plugins/ml2/drivers/type_vlan.py
neutron/plugins/vmware/common/sync.py
neutron/plugins/vmware/extensions/qos.py
neutron/service.py
neutron/tests/unit/agent/linux/test_ovs_lib.py
neutron/tests/unit/cisco/l3/device_handling_test_support.py
neutron/tests/unit/test_linux_dhcp.py
neutron/tests/unit/vmware/extensions/test_networkgw.py
neutron/tests/unit/vmware/nsxlib/base.py

index cd6ffdb51f5edcba3607e49b866a8c6db235af6f..36bce4ee2e925cc3d0a71e017cb4c4c3c53837ee 100644 (file)
@@ -167,23 +167,23 @@ class DhcpBase(object):
     def existing_dhcp_networks(cls, conf, root_helper):
         """Return a list of existing networks ids that we have configs for."""
 
-        raise NotImplementedError
+        raise NotImplementedError()
 
     @classmethod
     def check_version(cls):
         """Execute version checks on DHCP server."""
 
-        raise NotImplementedError
+        raise NotImplementedError()
 
     @classmethod
     def get_isolated_subnets(cls, network):
         """Returns a dict indicating whether or not a subnet is isolated"""
-        raise NotImplementedError
+        raise NotImplementedError()
 
     @classmethod
     def should_enable_metadata(cls, conf, network):
         """True if the metadata-proxy should be enabled for the network."""
-        raise NotImplementedError
+        raise NotImplementedError()
 
 
 class DhcpLocalProcess(DhcpBase):
index 92acdc311123398e791364f48b7c8cf50c93f2b8..48c6072569d1e33e3bc2332d09516dab790ba235 100644 (file)
@@ -200,7 +200,7 @@ class Controller(object):
                 return getattr(self._plugin, name)(*arg_list, **kwargs)
             return _handle_action
         else:
-            raise AttributeError
+            raise AttributeError()
 
     def _get_pagination_helper(self, request):
         if self._allow_pagination and self._native_pagination:
index 0dc0acd05650b13568bb6f00430c2b9230381995..0d4224787a31fb0b6daa1d8a8b0a2e0456630817 100644 (file)
@@ -130,7 +130,7 @@ class AgentPluginBase(object):
         This operation is not allow in REST API.
         @raise exceptions.BadRequest:
         """
-        raise exceptions.BadRequest
+        raise exceptions.BadRequest()
 
     @abc.abstractmethod
     def delete_agent(self, context, id):
index 8c0c7804dceea3a395ed5ed51a6f8231c127ebe9..1310d4e028f0d07763322c408e30c7906c52fef1 100644 (file)
@@ -116,7 +116,7 @@ class NeutronPluginBaseV2(object):
         .. note:: this method is optional, as it was not part of the originally
                   defined plugin API.
         """
-        raise NotImplementedError
+        raise NotImplementedError()
 
     @abc.abstractmethod
     def delete_subnet(self, context, id):
@@ -217,7 +217,7 @@ class NeutronPluginBaseV2(object):
         NOTE: this method is optional, as it was not part of the originally
               defined plugin API.
         """
-        raise NotImplementedError
+        raise NotImplementedError()
 
     @abc.abstractmethod
     def delete_network(self, context, id):
@@ -313,7 +313,7 @@ class NeutronPluginBaseV2(object):
         .. note:: this method is optional, as it was not part of the originally
                   defined plugin API.
         """
-        raise NotImplementedError
+        raise NotImplementedError()
 
     @abc.abstractmethod
     def delete_port(self, context, id):
@@ -334,7 +334,7 @@ class NeutronPluginBaseV2(object):
         .. note:: this method is optional, as it was not part of the originally
                   defined plugin API.
         """
-        raise NotImplementedError
+        raise NotImplementedError()
 
     def rpc_workers_supported(self):
         """Return whether the plugin supports multiple RPC workers.
index 68f8fac77d08dd8f4e4f95b7eb02dd2e647110b6..191f1ee09a5f55705b36648886e05bf001e4ec3c 100644 (file)
@@ -63,7 +63,7 @@ class CSR1kvRoutingDriver(devicedriver_api.RoutingDriverBase):
         except KeyError as e:
             LOG.error(_("Missing device parameter:%s. Aborting "
                         "CSR1kvRoutingDriver initialization"), e)
-            raise cfg_exc.CSR1kvInitializationException
+            raise cfg_exc.CSR1kvInitializationException()
 
     ###### Public Functions ########
     def router_added(self, ri):
@@ -149,10 +149,10 @@ class CSR1kvRoutingDriver(devicedriver_api.RoutingDriverBase):
             self._set_ha_HSRP(subinterface, vrf_name, priority, group, ip)
 
     def _csr_add_ha_VRRP(self, ri, port):
-        raise NotImplementedError
+        raise NotImplementedError()
 
     def _csr_add_ha_GBLP(self, ri, port):
-        raise NotImplementedError
+        raise NotImplementedError()
 
     def _csr_remove_ha(self, ri, port):
         pass
index 4bd9f6664f7e1be4c31315ca2554c27e44023f76..83f62e9bdadf5cefacde3d70625ee69eb881369d 100644 (file)
@@ -564,7 +564,7 @@ def reserve_specific_vlan(db_session, physical_network, vlan_id):
             alloc.allocated = True
             db_session.add(alloc)
         except exc.NoResultFound:
-            raise c_exc.VlanIDOutsidePool
+            raise c_exc.VlanIDOutsidePool()
 
 
 def release_vlan(db_session, physical_network, vlan_id):
@@ -643,7 +643,7 @@ def reserve_specific_vxlan(db_session, vxlan_id):
             alloc.allocated = True
             db_session.add(alloc)
         except exc.NoResultFound:
-            raise c_exc.VxlanIDOutsidePool
+            raise c_exc.VxlanIDOutsidePool()
 
 
 def release_vxlan(db_session, vxlan_id):
index 7889125b9fab04f07096c38230a985bcf11f4d3f..07331053a273e5e62fef362a8c05391df4ec3cc0 100644 (file)
@@ -355,7 +355,7 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
                                                                  segment2),
                                                                 encap_profile)
             else:
-                raise cisco_exceptions.NoClusterFound
+                raise cisco_exceptions.NoClusterFound()
 
         for profile in encap_dict:
             n1kvclient.update_encapsulation_profile(context, profile,
@@ -922,7 +922,7 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
                     seg_min, seg_max = self._get_segment_range(
                         network_profile['segment_range'])
                     if not seg_min <= segmentation_id <= seg_max:
-                        raise cisco_exceptions.VlanIDOutsidePool
+                        raise cisco_exceptions.VlanIDOutsidePool()
                     n1kv_db_v2.reserve_specific_vlan(session,
                                                      physical_network,
                                                      segmentation_id)
index 5adc86087edaa2adaa3b20f6420a7b11aba1d7a9..f0b4ae45f752eba384769a25c4e50d7b561081dd 100644 (file)
@@ -191,7 +191,7 @@ class MetaPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
                 return getattr(plugin, key)
 
         # if no plugin support the method, then raise
-        raise AttributeError
+        raise AttributeError()
 
     def _extend_network_dict(self, context, network):
         flavor = self._get_flavor_by_network_id(context, network['id'])
@@ -281,7 +281,7 @@ class MetaPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
     def create_port(self, context, port):
         p = port['port']
         if 'network_id' not in p:
-            raise exc.NotFound
+            raise exc.NotFound()
         plugin = self._get_plugin_by_network_id(context, p['network_id'])
         return plugin.create_port(context, port)
 
@@ -328,7 +328,7 @@ class MetaPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
     def create_subnet(self, context, subnet):
         s = subnet['subnet']
         if 'network_id' not in s:
-            raise exc.NotFound
+            raise exc.NotFound()
         plugin = self._get_plugin_by_network_id(context,
                                                 s['network_id'])
         return plugin.create_subnet(context, subnet)
index 5ab0e7f2d17817403789cdb457ae91ca5601890c..d3050989ddd71338e52336aebee2a36e6d8a9879 100644 (file)
@@ -140,4 +140,4 @@ class TypeDriverHelper(api.TypeDriver):
         LOG.warning(_("Allocate %(type)s segment from pool failed "
                       "after %(number)s failed attempts"),
                     {"type": network_type, "number": DB_MAX_RETRIES})
-        raise exc.NoNetworkFoundInMaximumAllowedAttempts
+        raise exc.NoNetworkFoundInMaximumAllowedAttempts()
index 7b6a2bf036d726019413761789a3c5f30606bb66..819cd7e739394a886748c7f4cc1d18af9b95c2e3 100644 (file)
@@ -100,7 +100,7 @@ class TunnelTypeDriver(helpers.TypeDriverHelper):
         if self.is_partial_segment(segment):
             alloc = self.allocate_partially_specified_segment(session)
             if not alloc:
-                raise exc.NoNetworkAvailable
+                raise exc.NoNetworkAvailable()
         else:
             segmentation_id = segment.get(api.SEGMENTATION_ID)
             alloc = self.allocate_fully_specified_segment(
index 35cbace21cf236cd8b93cc125823c09487bb4757..5cd3c3c8be5f802df9b43fed107b63745bb221ff 100644 (file)
@@ -205,7 +205,7 @@ class VlanTypeDriver(helpers.TypeDriverHelper):
             alloc = self.allocate_partially_specified_segment(
                 session, **filters)
             if not alloc:
-                raise exc.NoNetworkAvailable
+                raise exc.NoNetworkAvailable()
         else:
             alloc = self.allocate_fully_specified_segment(
                 session, **filters)
index a35ae07a4c9403df992fc184bc9f9b239f65c64f..c7fa6aeec2b93df328a0053088ba3a851219dc84 100644 (file)
@@ -601,7 +601,7 @@ class NsxSynchronizer():
     def _synchronize_state(self, sp):
         # If the plugin has been destroyed, stop the LoopingCall
         if not self._plugin:
-            raise loopingcall.LoopingCallDone
+            raise loopingcall.LoopingCallDone()
         start = timeutils.utcnow()
         # Reset page cursor variables if necessary
         if sp.current_chunk == 0:
index 1904bcfd27a085fbfc6004635e00d7c0581f2d47..ecc12e0b20f716c66c690f71cbfddd2167559bb3 100644 (file)
@@ -75,7 +75,7 @@ def convert_to_unsigned_int_or_none(val):
     try:
         val = int(val)
         if val < 0:
-            raise ValueError
+            raise ValueError()
     except (ValueError, TypeError):
         msg = _("'%s' must be a non negative integer.") % val
         raise qexception.InvalidInput(error_message=msg)
index cf357d16fa351ee33266b3477ed547c3f01eb5fe..0cac907b33a0d4b59b409673561313d3983f1317 100644 (file)
@@ -146,7 +146,7 @@ def serve_rpc():
             msg = _("'rpc_workers = %d' ignored because start_rpc_listeners "
                     "is not implemented.")
             LOG.error(msg, cfg.CONF.rpc_workers)
-        raise NotImplementedError
+        raise NotImplementedError()
 
     try:
         rpc = RpcWorker(plugin)
index 3fbf8137825dc121b6ff85fe5d1db6c23cfcd0f2..8d2444acce922b22d15d909ead749eedf7853435 100644 (file)
@@ -934,7 +934,7 @@ class TestDeferredOVSBridge(base.BaseTestCase):
                 deferred_br.add_flow(**self.add_flow_dict1)
                 deferred_br.mod_flow(**self.mod_flow_dict1)
                 deferred_br.delete_flows(**self.del_flow_dict1)
-                raise Exception
+                raise Exception()
         except Exception:
             self._verify_mock_call([])
         else:
index e8fad7b885d18c976280b99e3aa5012dc2851d34..1921e56acbb3cbb58caad9c290586a25a87b1b24 100644 (file)
@@ -100,7 +100,7 @@ class DeviceHandlingTestSupportMixin(object):
                     LOG.error('Failed to delete port %(p_id)s for vm instance '
                               '%(v_id)s due to %(err)s',
                               {'p_id': port['id'], 'v_id': vm_id, 'err': e})
-                    raise nova_exc.InternalServerError
+                    raise nova_exc.InternalServerError()
 
     def _mock_svc_vm_create_delete(self, plugin):
         # Mock novaclient methods for creation/deletion of service VMs
index c23af7402ecfee975b439ded16b302f900107d08..d06a7139e2a145fb33443754ef986d2de4eb4910 100644 (file)
@@ -732,7 +732,7 @@ class TestDnsmasq(TestBase):
             if index == 0:
                 return '/usr/local/bin/neutron-dhcp-agent'
             else:
-                raise IndexError
+                raise IndexError()
 
         expected = [
             'ip',
index 3d223e9584b85b1f2620d1a883e25d36f0f2f9f6..7427527545e57021d48f115f7bfcbff9d1e8a3a6 100644 (file)
@@ -974,7 +974,7 @@ class TestNetworkGateway(test_nsx_plugin.NsxPluginV2TestCase,
 
     def test_create_network_gateway_nsx_error_returns_500(self):
         def raise_nsx_api_exc(*args, **kwargs):
-            raise api_exc.NsxApiException
+            raise api_exc.NsxApiException()
 
         with mock.patch.object(nsxlib.l2gateway,
                                'create_l2_gw_service',
index baff3e9c63a7d9e1d83d162799e10c68cbd49ce3..679db7b73b2f65a26f839bcdd2e3b46ee309457c 100644 (file)
@@ -72,7 +72,7 @@ class NsxlibNegativeBaseTestCase(base.BaseTestCase):
             version.Version(fake_version))
 
         def _faulty_request(*args, **kwargs):
-            raise exception.NsxApiException
+            raise exception.NsxApiException()
 
         instance.return_value.request.side_effect = _faulty_request
         self.fake_cluster = cluster.NSXCluster(