]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix parameters in exception handling
authorGary Kotton <gkotton@vmware.com>
Tue, 17 Feb 2015 13:51:59 +0000 (05:51 -0800)
committerGary Kotton <gkotton@vmware.com>
Sun, 22 Feb 2015 06:31:31 +0000 (22:31 -0800)
The commit d9155521539e5e67f0984c180267fc91cc17c738 added
exceptions with one too many %.

The format should be as follows:

class ExceptionExample(exceptions.NeutronException):
    message = _('Invalid input %(input)s')

It is called by raise.ExceptionExample(input=input)

The patch also fixes a typo with InvalidAuthenticationTypeExecption.

Change-Id: I0f796fbe0eb029277250ae82c3d7f75842364f76

neutron/agent/linux/keepalived.py
neutron/tests/unit/agent/linux/test_keepalived.py

index 904aefeb9b0d35e0099705ed045b86375ffb1f79..0286815558fe1e8e42c2c23f6bd3792345ab4119 100644 (file)
@@ -60,21 +60,33 @@ def get_free_range(parent_range, excluded_ranges, size=PRIMARY_VIP_RANGE_SIZE):
 
 
 class InvalidInstanceStateException(exceptions.NeutronException):
-    message = (_('Invalid instance state: %%(state)s, valid states are: '
-                 '%(valid_states)s') %
-               {'valid_states': ', '.join(VALID_STATES)})
+    message = _('Invalid instance state: %(state)s, valid states are: '
+                '%(valid_states)s')
+
+    def __init__(self, **kwargs):
+        if 'valid_states' not in kwargs:
+            kwargs['valid_states'] = ', '.join(VALID_STATES)
+        super(InvalidInstanceStateException, self).__init__(**kwargs)
 
 
 class InvalidNotifyStateException(exceptions.NeutronException):
-    message = (_('Invalid notify state: %%(state)s, valid states are: '
-                 '%(valid_notify_states)s') %
-               {'valid_notify_states': ', '.join(VALID_NOTIFY_STATES)})
+    message = _('Invalid notify state: %(state)s, valid states are: '
+                '%(valid_notify_states)s')
+
+    def __init__(self, **kwargs):
+        if 'valid_notify_states' not in kwargs:
+            kwargs['valid_notify_states'] = ', '.join(VALID_NOTIFY_STATES)
+        super(InvalidNotifyStateException, self).__init__(**kwargs)
+
 
+class InvalidAuthenticationTypeException(exceptions.NeutronException):
+    message = _('Invalid authentication type: %(auth_type)s, '
+                'valid types are: %(valid_auth_types)s')
 
-class InvalidAuthenticationTypeExecption(exceptions.NeutronException):
-    message = (_('Invalid authentication type: %%(auth_type)s, '
-                 'valid types are: %(valid_auth_types)s') %
-               {'valid_auth_types': ', '.join(VALID_AUTH_TYPES)})
+    def __init__(self, **kwargs):
+        if 'valid_auth_types' not in kwargs:
+            kwargs['valid_auth_types'] = ', '.join(VALID_AUTH_TYPES)
+        super(InvalidAuthenticationTypeException, self).__init__(**kwargs)
 
 
 class KeepalivedVipAddress(object):
@@ -140,7 +152,7 @@ class KeepalivedInstance(object):
 
     def set_authentication(self, auth_type, password):
         if auth_type not in VALID_AUTH_TYPES:
-            raise InvalidAuthenticationTypeExecption(auth_type=auth_type)
+            raise InvalidAuthenticationTypeException(auth_type=auth_type)
 
         self.authentication = (auth_type, password)
 
index 624ccd2f851ea68a81ee024ae256fc4d061a4ff0..874449b286e560952449605cb75a4f54795fda04 100644 (file)
@@ -192,7 +192,7 @@ class KeepalivedStateExceptionTestCase(base.BaseTestCase):
         invalid_auth_type = '[hip, hip]'
         instance = keepalived.KeepalivedInstance('MASTER', 'eth0', 1,
                                                  '169.254.192.0/18')
-        self.assertRaises(keepalived.InvalidAuthenticationTypeExecption,
+        self.assertRaises(keepalived.InvalidAuthenticationTypeException,
                           instance.set_authentication,
                           invalid_auth_type, 'some_password')