summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Pisarski <s.pisarski@cablelabs.com>2017-07-24 15:09:03 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-07-24 15:09:03 +0000
commita2b4763d5fe13bfe47de0d44e7d7c519f1084215 (patch)
treef625e5d86eaa351867b11cc1d9176b034b43a4d6
parentad9354631208bc565dbbade119c6be89b4a6a5d4 (diff)
parent8eb8d2fa3490aaae111717f445300eac8b3e6ed4 (diff)
Merge "Created new classes RouterSettingsError & RouterCreationError."
-rw-r--r--snaps/openstack/create_router.py24
-rw-r--r--snaps/openstack/tests/create_router_tests.py13
2 files changed, 25 insertions, 12 deletions
diff --git a/snaps/openstack/create_router.py b/snaps/openstack/create_router.py
index db6ffe3..e50009c 100644
--- a/snaps/openstack/create_router.py
+++ b/snaps/openstack/create_router.py
@@ -39,7 +39,7 @@ class OpenStackRouter:
self.__os_creds = os_creds
if not router_settings:
- raise Exception('router_settings is required')
+ raise RouterCreationError('router_settings is required')
self.router_settings = router_settings
self.__neutron = None
@@ -84,7 +84,7 @@ class OpenStackRouter:
self.__internal_router_interface = neutron_utils.add_interface_router(
self.__neutron, self.__router, subnet=internal_subnet)
else:
- raise Exception(
+ raise RouterCreationError(
'Subnet not found with name ' + internal_subnet_name)
for port_setting in self.router_settings.port_settings:
@@ -108,7 +108,7 @@ class OpenStackRouter:
self.__router,
port=port)
else:
- raise Exception(
+ raise RouterCreationError(
'Error creating port with name - ' + port_setting.name)
return self.__router
@@ -163,6 +163,12 @@ class OpenStackRouter:
return self.__internal_router_interface
+class RouterCreationError(Exception):
+ """
+ Exception to be thrown when an router instance cannot be created
+ """
+
+
class RouterSettings:
"""
Class representing a router configuration
@@ -209,7 +215,7 @@ class RouterSettings:
PortSettings(**interface['port']))
if not self.name:
- raise Exception('Name is required')
+ raise RouterSettingsError('Name is required')
def dict_for_neutron(self, neutron, os_creds):
"""
@@ -239,7 +245,7 @@ class RouterSettings:
if project_id:
out['project_id'] = project_id
else:
- raise Exception(
+ raise RouterSettingsError(
'Could not find project ID for project named - ' +
self.project_name)
if self.admin_state_up is not None:
@@ -251,7 +257,7 @@ class RouterSettings:
ext_gw['network_id'] = ext_net.id
out['external_gateway_info'] = ext_gw
else:
- raise Exception(
+ raise RouterSettingsError(
'Could not find the external network named - ' +
self.external_gateway)
@@ -259,3 +265,9 @@ class RouterSettings:
# TODO: Add external_fixed_ips Tests
return {'router': out}
+
+
+class RouterSettingsError(Exception):
+ """
+ Exception to be thrown when router settings attributes are incorrect
+ """
diff --git a/snaps/openstack/tests/create_router_tests.py b/snaps/openstack/tests/create_router_tests.py
index 5f2534d..efa0993 100644
--- a/snaps/openstack/tests/create_router_tests.py
+++ b/snaps/openstack/tests/create_router_tests.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2016 Cable Television Laboratories, Inc. ("CableLabs")
+# Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
# and others. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,7 +20,8 @@ from snaps.openstack import create_router
from snaps.openstack.create_network import (
NetworkSettings, PortSettings)
from snaps.openstack.create_network import OpenStackNetwork
-from snaps.openstack.create_router import RouterSettings
+from snaps.openstack.create_router import (
+ RouterSettings, RouterSettingsError, RouterCreationError)
from snaps.openstack.tests.os_source_file_test import OSIntegrationTestCase
from snaps.openstack.utils import neutron_utils
@@ -38,11 +39,11 @@ class RouterSettingsUnitTests(unittest.TestCase):
"""
def test_no_params(self):
- with self.assertRaises(Exception):
+ with self.assertRaises(RouterSettingsError):
RouterSettings()
def test_empty_config(self):
- with self.assertRaises(Exception):
+ with self.assertRaises(RouterSettingsError):
RouterSettings(**dict())
def test_name_only(self):
@@ -338,7 +339,7 @@ class CreateRouterNegativeTests(OSIntegrationTestCase):
"""
Test creating a router without a name.
"""
- with self.assertRaises(Exception):
+ with self.assertRaises(RouterSettingsError):
router_settings = RouterSettings(
name=None, external_gateway=self.ext_net_name)
self.router_creator = create_router.OpenStackRouter(
@@ -349,7 +350,7 @@ class CreateRouterNegativeTests(OSIntegrationTestCase):
"""
Test creating a router without a valid network gateway name.
"""
- with self.assertRaises(Exception):
+ with self.assertRaises(RouterSettingsError):
router_settings = RouterSettings(name=self.guid + '-pub-router',
external_gateway="Invalid_name")
self.router_creator = create_router.OpenStackRouter(