Fix parameters in exception handling

The commit d915552153 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
This commit is contained in:
Gary Kotton 2015-02-17 05:51:59 -08:00
parent 992784cc8d
commit 5476c9ef4f
2 changed files with 24 additions and 12 deletions

View 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 InvalidAuthenticationTypeExecption(exceptions.NeutronException):
message = (_('Invalid authentication type: %%(auth_type)s, '
'valid types are: %(valid_auth_types)s') %
{'valid_auth_types': ', '.join(VALID_AUTH_TYPES)})
class InvalidAuthenticationTypeException(exceptions.NeutronException):
message = _('Invalid authentication type: %(auth_type)s, '
'valid types are: %(valid_auth_types)s')
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)

View 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')