summaryrefslogtreecommitdiffstats
path: root/snaps/domain
diff options
context:
space:
mode:
authorSteven Pisarski <s.pisarski@cablelabs.com>2017-07-13 19:55:08 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-07-13 19:55:08 +0000
commitb490e8dc9fb01c6f9c44dd9a585ca1a1ae00bf19 (patch)
treea7545c34d10803375b606f0abcf88d2b2f955268 /snaps/domain
parent317a6f8c44efbefaeb800edafcc6fb4cb88bedea (diff)
parent7f989290a14c836b4982e1548d24c9c09f9a0068 (diff)
Merge "Created domain class for routers."
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):