From 5476c9ef4f0802e9a97c806a94e94b7e247ba887 Mon Sep 17 00:00:00 2001 From: Gary Kotton Date: Tue, 17 Feb 2015 05:51:59 -0800 Subject: [PATCH] Fix parameters in exception handling 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 | 34 +++++++++++++------ .../tests/unit/agent/linux/test_keepalived.py | 2 +- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/neutron/agent/linux/keepalived.py b/neutron/agent/linux/keepalived.py index 904aefeb9..028681555 100644 --- a/neutron/agent/linux/keepalived.py +++ b/neutron/agent/linux/keepalived.py @@ -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) diff --git a/neutron/tests/unit/agent/linux/test_keepalived.py b/neutron/tests/unit/agent/linux/test_keepalived.py index 624ccd2f8..874449b28 100644 --- a/neutron/tests/unit/agent/linux/test_keepalived.py +++ b/neutron/tests/unit/agent/linux/test_keepalived.py @@ -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') -- 2.45.2