summaryrefslogtreecommitdiffstats
path: root/snaps/openstack
diff options
context:
space:
mode:
Diffstat (limited to 'snaps/openstack')
-rw-r--r--snaps/openstack/create_project.py8
-rw-r--r--snaps/openstack/create_router.py24
-rw-r--r--snaps/openstack/create_security_group.py34
-rw-r--r--snaps/openstack/tests/create_project_tests.py7
-rw-r--r--snaps/openstack/tests/create_router_tests.py13
-rw-r--r--snaps/openstack/tests/create_security_group_tests.py18
6 files changed, 72 insertions, 32 deletions
diff --git a/snaps/openstack/create_project.py b/snaps/openstack/create_project.py
index 0384ccc..a20033e 100644
--- a/snaps/openstack/create_project.py
+++ b/snaps/openstack/create_project.py
@@ -131,5 +131,11 @@ class ProjectSettings:
self.enabled = True
if not self.name:
- raise Exception(
+ raise ProjectSettingsError(
"The attribute name is required for ProjectSettings")
+
+
+class ProjectSettingsError(Exception):
+ """
+ Exception to be thrown when project settings attributes are incorrect
+ """
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/create_security_group.py b/snaps/openstack/create_security_group.py
index 3dbf559..4291796 100644
--- a/snaps/openstack/create_security_group.py
+++ b/snaps/openstack/create_security_group.py
@@ -240,11 +240,11 @@ class SecurityGroupSettings:
**rule_setting))
if not self.name:
- raise Exception('The attribute name is required')
+ raise SecurityGroupSettingsError('The attribute name is required')
for rule_setting in self.rule_settings:
if rule_setting.sec_grp_name is not self.name:
- raise Exception(
+ raise SecurityGroupSettingsError(
'Rule settings must correspond with the name of this '
'security group')
@@ -272,7 +272,7 @@ class SecurityGroupSettings:
if project_id:
out['project_id'] = project_id
else:
- raise Exception(
+ raise SecurityGroupSettingsError(
'Could not find project ID for project named - ' +
self.project_name)
@@ -305,6 +305,13 @@ class Ethertype(enum.Enum):
IPv6 = 6
+class SecurityGroupSettingsError(Exception):
+ """
+ Exception to be thrown when security group settings attributes are
+ invalid
+ """
+
+
class SecurityGroupRuleSettings:
"""
Class representing a keypair configuration
@@ -368,7 +375,8 @@ class SecurityGroupRuleSettings:
self.remote_ip_prefix = kwargs.get('remote_ip_prefix')
if not self.direction or not self.sec_grp_name:
- raise Exception('direction and sec_grp_name are required')
+ raise SecurityGroupRuleSettingsError(
+ 'direction and sec_grp_name are required')
def dict_for_neutron(self, neutron):
"""
@@ -399,7 +407,7 @@ class SecurityGroupRuleSettings:
if sec_grp:
out['security_group_id'] = sec_grp.id
else:
- raise Exception(
+ raise SecurityGroupRuleSettingsError(
'Cannot locate security group with name - ' +
self.sec_grp_name)
if self.remote_group_id:
@@ -490,7 +498,8 @@ def map_direction(direction):
elif dir_str == 'ingress':
return Direction.ingress
else:
- raise Exception('Invalid Direction - ' + dir_str)
+ raise SecurityGroupRuleSettingsError(
+ 'Invalid Direction - ' + dir_str)
def map_protocol(protocol):
@@ -516,7 +525,8 @@ def map_protocol(protocol):
elif proto_str == 'null':
return Protocol.null
else:
- raise Exception('Invalid Protocol - ' + proto_str)
+ raise SecurityGroupRuleSettingsError(
+ 'Invalid Protocol - ' + proto_str)
def map_ethertype(ethertype):
@@ -538,4 +548,12 @@ def map_ethertype(ethertype):
elif eth_str == 'IPv4':
return Ethertype.IPv4
else:
- raise Exception('Invalid Ethertype - ' + eth_str)
+ raise SecurityGroupRuleSettingsError(
+ 'Invalid Ethertype - ' + eth_str)
+
+
+class SecurityGroupRuleSettingsError(Exception):
+ """
+ Exception to be thrown when security group rule settings attributes are
+ invalid
+ """
diff --git a/snaps/openstack/tests/create_project_tests.py b/snaps/openstack/tests/create_project_tests.py
index 3c6b2d1..f2af0d9 100644
--- a/snaps/openstack/tests/create_project_tests.py
+++ b/snaps/openstack/tests/create_project_tests.py
@@ -15,7 +15,8 @@
import unittest
import uuid
-from snaps.openstack.create_project import OpenStackProject, ProjectSettings
+from snaps.openstack.create_project import (
+ OpenStackProject, ProjectSettings, ProjectSettingsError)
from snaps.openstack.create_security_group import OpenStackSecurityGroup
from snaps.openstack.create_security_group import SecurityGroupSettings
from snaps.openstack.create_user import OpenStackUser
@@ -32,11 +33,11 @@ class ProjectSettingsUnitTests(unittest.TestCase):
"""
def test_no_params(self):
- with self.assertRaises(Exception):
+ with self.assertRaises(ProjectSettingsError):
ProjectSettings()
def test_empty_config(self):
- with self.assertRaises(Exception):
+ with self.assertRaises(ProjectSettingsError):
ProjectSettings(**dict())
def test_name_only(self):
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(
diff --git a/snaps/openstack/tests/create_security_group_tests.py b/snaps/openstack/tests/create_security_group_tests.py
index 75c6387..dd28d7d 100644
--- a/snaps/openstack/tests/create_security_group_tests.py
+++ b/snaps/openstack/tests/create_security_group_tests.py
@@ -19,7 +19,9 @@ from snaps.openstack import create_security_group
from snaps.openstack.create_security_group import (SecurityGroupSettings,
SecurityGroupRuleSettings,
Direction, Ethertype,
- Protocol)
+ Protocol,
+ SecurityGroupRuleSettingsError,
+ SecurityGroupSettingsError)
from snaps.openstack.tests import validation_utils
from snaps.openstack.tests.os_source_file_test import OSIntegrationTestCase
from snaps.openstack.utils import neutron_utils
@@ -33,19 +35,19 @@ class SecurityGroupRuleSettingsUnitTests(unittest.TestCase):
"""
def test_no_params(self):
- with self.assertRaises(Exception):
+ with self.assertRaises(SecurityGroupRuleSettingsError):
SecurityGroupRuleSettings()
def test_empty_config(self):
- with self.assertRaises(Exception):
+ with self.assertRaises(SecurityGroupRuleSettingsError):
SecurityGroupRuleSettings(**dict())
def test_name_only(self):
- with self.assertRaises(Exception):
+ with self.assertRaises(SecurityGroupRuleSettingsError):
SecurityGroupRuleSettings(sec_grp_name='foo')
def test_config_with_name_only(self):
- with self.assertRaises(Exception):
+ with self.assertRaises(SecurityGroupRuleSettingsError):
SecurityGroupRuleSettings(**{'sec_grp_name': 'foo'})
def test_name_and_direction(self):
@@ -105,11 +107,11 @@ class SecurityGroupSettingsUnitTests(unittest.TestCase):
"""
def test_no_params(self):
- with self.assertRaises(Exception):
+ with self.assertRaises(SecurityGroupSettingsError):
SecurityGroupSettings()
def test_empty_config(self):
- with self.assertRaises(Exception):
+ with self.assertRaises(SecurityGroupSettingsError):
SecurityGroupSettings(**dict())
def test_name_only(self):
@@ -123,7 +125,7 @@ class SecurityGroupSettingsUnitTests(unittest.TestCase):
def test_invalid_rule(self):
rule_setting = SecurityGroupRuleSettings(sec_grp_name='bar',
direction=Direction.ingress)
- with self.assertRaises(Exception):
+ with self.assertRaises(SecurityGroupSettingsError):
SecurityGroupSettings(name='foo', rule_settings=[rule_setting])
def test_all(self):