summaryrefslogtreecommitdiffstats
path: root/snaps/domain
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2017-07-13 09:02:40 -0600
committerspisarski <s.pisarski@cablelabs.com>2017-07-13 09:02:40 -0600
commit7f989290a14c836b4982e1548d24c9c09f9a0068 (patch)
tree838f47b7af5137f5b0dd1b841a70642d7169e783 /snaps/domain
parente6326cd5e826d19e4dd2b096c17aff35da1757b3 (diff)
Created domain class for routers.
Created Router domain class so neutron_utils.py functions returning router objects will not be leaking out implementation details as each API version can change these data structures and this should all be handled by the SNAPS neutron utility. JIRA: SNAPS-115 & SNAPS-14 Change-Id: Ib6d36a735d835a6ed4ede489b14e33a261458fed Signed-off-by: spisarski <s.pisarski@cablelabs.com>
Diffstat (limited to 'snaps/domain')
-rw-r--r--snaps/domain/network.py44
-rw-r--r--snaps/domain/test/network_tests.py55
2 files changed, 96 insertions, 3 deletions
diff --git a/snaps/domain/network.py b/snaps/domain/network.py
index 8ac5300..0ba9e99 100644
--- a/snaps/domain/network.py
+++ b/snaps/domain/network.py
@@ -37,6 +37,50 @@ class Port:
self.ips == other.ips, self.mac_address == other.mac_address)
+class Router:
+ """
+ SNAPS domain object for routers. Should contain attributes that are shared
+ amongst cloud providers
+ """
+ def __init__(self, **kwargs):
+ """
+ Constructor
+ :param name: the router's name
+ :param id: the router's id
+ """
+ self.name = kwargs.get('name')
+ self.id = kwargs.get('id')
+ self.status = kwargs.get('status')
+ self.tenant_id = kwargs.get('tenant_id')
+ self.admin_state_up = kwargs.get('admin_state_up')
+ self.external_gateway_info = kwargs.get('external_gateway_info')
+
+ def __eq__(self, other):
+ return (self.name == other.name and self.id == other.id and
+ self.status == other.status and
+ self.tenant_id == other.tenant_id and
+ self.admin_state_up == other.admin_state_up and
+ self.external_gateway_info == other.external_gateway_info)
+
+
+class InterfaceRouter:
+ """
+ SNAPS domain object for interface routers. Should contain attributes that
+ are shared amongst cloud providers
+ """
+ def __init__(self, **kwargs):
+ """
+ Constructor
+ """
+ self.id = kwargs.get('id')
+ self.subnet_id = kwargs.get('subnet_id')
+ self.port_id = kwargs.get('port_id')
+
+ def __eq__(self, other):
+ return (self.id == other.id and self.subnet_id == other.subnet_id and
+ self.port_id == other.port_id)
+
+
class SecurityGroup:
"""
SNAPS domain object for SecurityGroups. Should contain attributes that
diff --git a/snaps/domain/test/network_tests.py b/snaps/domain/test/network_tests.py
index 13015b2..c394b4a 100644
--- a/snaps/domain/test/network_tests.py
+++ b/snaps/domain/test/network_tests.py
@@ -14,7 +14,8 @@
# limitations under the License.
import unittest
-from snaps.domain.network import Port, SecurityGroup, SecurityGroupRule
+from snaps.domain.network import (
+ Port, SecurityGroup, SecurityGroupRule, Router, InterfaceRouter)
class PortDomainObjectTests(unittest.TestCase):
@@ -38,9 +39,57 @@ class PortDomainObjectTests(unittest.TestCase):
self.assertEqual(ips, port.ips)
+class RouterDomainObjectTests(unittest.TestCase):
+ """
+ Tests the construction of the snaps.domain.network.Router class
+ """
+
+ def test_construction_kwargs(self):
+ sec_grp = Router(
+ **{'name': 'name', 'id': 'id', 'status': 'hello',
+ 'tenant_id': '1234', 'admin_state_up': 'yes',
+ 'external_gateway_info': 'no'})
+ self.assertEqual('name', sec_grp.name)
+ self.assertEqual('id', sec_grp.id)
+ self.assertEqual('hello', sec_grp.status)
+ self.assertEqual('1234', sec_grp.tenant_id)
+ self.assertEqual('yes', sec_grp.admin_state_up)
+ self.assertEqual('no', sec_grp.external_gateway_info)
+
+ def test_construction_named(self):
+ sec_grp = Router(
+ external_gateway_info='no', admin_state_up='yes', tenant_id='1234',
+ status='hello', id='id', name='name')
+ self.assertEqual('name', sec_grp.name)
+ self.assertEqual('id', sec_grp.id)
+ self.assertEqual('hello', sec_grp.status)
+ self.assertEqual('1234', sec_grp.tenant_id)
+ self.assertEqual('yes', sec_grp.admin_state_up)
+ self.assertEqual('no', sec_grp.external_gateway_info)
+
+
+class InterfaceRouterDomainObjectTests(unittest.TestCase):
+ """
+ Tests the construction of the snaps.domain.network.InterfaceRouter class
+ """
+
+ def test_construction_kwargs(self):
+ sec_grp = InterfaceRouter(
+ **{'id': 'id', 'subnet_id': 'foo', 'port_id': 'bar'})
+ self.assertEqual('id', sec_grp.id)
+ self.assertEqual('foo', sec_grp.subnet_id)
+ self.assertEqual('bar', sec_grp.port_id)
+
+ def test_construction_named(self):
+ sec_grp = InterfaceRouter(port_id='bar', subnet_id='foo', id='id')
+ self.assertEqual('id', sec_grp.id)
+ self.assertEqual('foo', sec_grp.subnet_id)
+ self.assertEqual('bar', sec_grp.port_id)
+
+
class SecurityGroupDomainObjectTests(unittest.TestCase):
"""
- Tests the construction of the snaps.domain.test.SecurityGroup class
+ Tests the construction of the snaps.domain.network.SecurityGroup class
"""
def test_construction_proj_id_kwargs(self):
@@ -68,7 +117,7 @@ class SecurityGroupDomainObjectTests(unittest.TestCase):
class SecurityGroupRuleDomainObjectTests(unittest.TestCase):
"""
- Tests the construction of the snaps.domain.test.SecurityGroupRule class
+ Tests the construction of the snaps.domain.network.SecurityGroupRule class
"""
def test_construction_kwargs(self):