Extract kolla exceptions into a single exception.py file

Change-Id: I03388360b6ac735d5a6f380a7956cd91ab449131
This commit is contained in:
lijing 2016-11-11 17:57:10 +08:00 committed by Jeremy Liu
parent dbb0ade6d1
commit f6a525ed85
3 changed files with 37 additions and 22 deletions

29
kolla/exception.py Normal file
View File

@ -0,0 +1,29 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Kolla exception subclasses"""
class KollaDirNotFoundException(Exception):
pass
class KollaUnknownBuildTypeException(Exception):
pass
class KollaMismatchBaseTypeException(Exception):
pass
class KollaRpmSetupUnknownConfig(Exception):
pass

View File

@ -47,6 +47,7 @@ if PROJECT_ROOT not in sys.path:
from kolla.common import config as common_config
from kolla.common import task
from kolla import exception
from kolla.template import filters as jinja_filters
from kolla.template import methods as jinja_methods
from kolla import version
@ -75,23 +76,6 @@ def make_a_logger(conf=None, image_name=None):
LOG = make_a_logger()
class KollaDirNotFoundException(Exception):
pass
class KollaUnknownBuildTypeException(Exception):
pass
class KollaMismatchBaseTypeException(Exception):
pass
class KollaRpmSetupUnknownConfig(Exception):
pass
# Image status constants.
#
# TODO(harlowja): use enum lib in the future??
@ -521,7 +505,7 @@ class KollaWorker(object):
if not ((self.base in rh_base and self.install_type in rh_type) or
(self.base in deb_base and self.install_type in deb_type)):
raise KollaMismatchBaseTypeException(
raise exception.KollaMismatchBaseTypeException(
'{} is unavailable for {}'.format(self.install_type, self.base)
)
@ -536,7 +520,7 @@ class KollaWorker(object):
self.install_type = 'binary'
self.install_metatype = 'rhos'
else:
raise KollaUnknownBuildTypeException(
raise exception.KollaUnknownBuildTypeException(
'Unknown install type'
)
@ -565,7 +549,8 @@ class KollaWorker(object):
LOG.info('Found the docker image folder at %s', image_path)
return image_path
else:
raise KollaDirNotFoundException('Image dir can not be found')
raise exception.KollaDirNotFoundException('Image dir can not '
'be found')
def build_rpm_setup(self, rpm_setup_config):
"""Generates a list of docker commands based on provided configuration.
@ -589,7 +574,7 @@ class KollaWorker(object):
# Copy .repo file from filesystem
cmd = "COPY {} /etc/yum.repos.d/".format(config)
else:
raise KollaRpmSetupUnknownConfig(
raise exception.KollaRpmSetupUnknownConfig(
'RPM setup must be provided as .rpm or .repo files.'
' Attempted configuration was {}'.format(config)
)

View File

@ -17,6 +17,7 @@ import os
import requests
from kolla.cmd import build as build_cmd
from kolla import exception
from kolla.image import build
from kolla.tests import base
@ -170,7 +171,7 @@ class KollaWorkerTest(base.TestCase):
['ubuntu', 'debian'], ['rdo', 'rhos']):
self.conf.set_override('base', base_distro)
self.conf.set_override('install_type', install_type)
self.assertRaises(build.KollaMismatchBaseTypeException,
self.assertRaises(exception.KollaMismatchBaseTypeException,
build.KollaWorker, self.conf)
def test_build_image_list_adds_plugins(self):