Make exception more generic

This commit is contained in:
Nicolas Pochet
2018-08-08 23:21:07 +02:00
parent f0e0cdd3c2
commit d8f07e66ab
3 changed files with 15 additions and 6 deletions
@@ -665,7 +665,7 @@ class TestOpenStackUtils(ut_utils.BaseTestCase):
# No machine returned
self._get_machines.return_value = []
with self.assertRaises(exceptions.NoKeystoneFound):
with self.assertRaises(exceptions.ApplicationNotFound):
openstack_utils.get_current_os_release_pair()
# No series returned
+12 -3
View File
@@ -31,10 +31,19 @@ class NeutronBGPSpeakerMissing(Exception):
pass
class NoKeystoneFound(Exception):
"""No Keystone found in machines."""
class ApplicationNotFound(Exception):
"""Application not found in machines."""
pass
def __init__(self, application):
"""Create Application not found exception.
:param application: Name of the application
:type application: string
:returns: ApplicationNotFound Exception
"""
msg = ("{} application was not found in machines.".
format(application))
super(ApplicationNotFound, self).__init__(msg)
class SeriesNotFound(Exception):
+2 -2
View File
@@ -1131,7 +1131,7 @@ def get_current_os_release_pair(application='keystone'):
:type application: string
:returns: Name of the OpenStack release pair
:rtype: str
:raises: exceptions.NoKeystoneFound
:raises: exceptions.ApplicationNotFound
:raises: exceptions.SeriesNotFound
:raises: exceptions.OSVersionNotFound
"""
@@ -1139,7 +1139,7 @@ def get_current_os_release_pair(application='keystone'):
if len(machines) >= 1:
machine = machines[0]
else:
raise exceptions.NoKeystoneFound()
raise exceptions.ApplicationNotFound(application)
series = juju_utils.get_machine_series(machine)
if not series: