summaryrefslogtreecommitdiffstats
path: root/snaps/domain
diff options
context:
space:
mode:
authorSteven Pisarski <s.pisarski@cablelabs.com>2017-08-11 14:46:05 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-08-11 14:46:05 +0000
commit887c0c9010e8b23bf7c955c0809c1b761ddf2096 (patch)
tree0ed4c94b74830052e76b7e67aa04a67f41437137 /snaps/domain
parent9830e986f374fb0fbb7f5b42af09793606ea2a92 (diff)
parent2b9b2d64c5be98405aaaf98db58f06b35b8af983 (diff)
Merge "SNAPS Stack creators can now return SNAPS network creators."
Diffstat (limited to 'snaps/domain')
-rw-r--r--snaps/domain/network.py40
-rw-r--r--snaps/domain/stack.py14
-rw-r--r--snaps/domain/test/network_tests.py73
-rw-r--r--snaps/domain/test/stack_tests.py20
4 files changed, 127 insertions, 20 deletions
diff --git a/snaps/domain/network.py b/snaps/domain/network.py
index 2c71db8..0b56c43 100644
--- a/snaps/domain/network.py
+++ b/snaps/domain/network.py
@@ -25,11 +25,16 @@ class Network:
"""
self.name = kwargs.get('name')
self.id = kwargs.get('id')
- self.type = kwargs.get('provider:network_type')
+ self.admin_state_up = kwargs.get('admin_state_up')
+ self.shared = kwargs.get('shared')
+ self.external = kwargs.get('router:external', kwargs.get('external'))
+ self.type = kwargs.get('provider:network_type', kwargs.get('type'))
def __eq__(self, other):
return (self.name == other.name and self.id == other.id and
- self.type == other.type)
+ self.admin_state_up == other.admin_state_up and
+ self.shared == other.shared and
+ self.external == other.external and self.type == other.type)
class Subnet:
@@ -44,10 +49,37 @@ class Subnet:
self.name = kwargs.get('name')
self.id = kwargs.get('id')
self.cidr = kwargs.get('cidr')
+ self.ip_version = kwargs.get('ip_version')
+ self.gateway_ip = kwargs.get('gateway_ip')
+ self.enable_dhcp = kwargs.get('enable_dhcp')
+ self.dns_nameservers = kwargs.get('dns_nameservers')
+ self.host_routes = kwargs.get('host_routes')
+ self.ipv6_ra_mode = kwargs.get('ipv6_ra_mode')
+ self.ipv6_address_mode = kwargs.get('ipv6_address_mode')
+
+ self.start = None
+ self.end = None
+ if ('allocation_pools' in kwargs and
+ len(kwargs['allocation_pools']) > 0):
+ # Will need to ultimately support a list of pools
+ pools = kwargs['allocation_pools'][0]
+ if 'start' in pools:
+ self.start = pools['start']
+ if 'end' in pools:
+ self.end = pools['end']
def __eq__(self, other):
- return (self.name == other.name and self.id == other.id and
- self.cidr == other.cidr)
+ return (self.name == other.name and
+ self.id == other.id and
+ self.cidr == other.cidr and
+ self.ip_version == other.ip_version and
+ self.gateway_ip == other.gateway_ip and
+ self.enable_dhcp == other.enable_dhcp and
+ self.dns_nameservers == other.dns_nameservers and
+ self.host_routes == other.host_routes and
+ self.ipv6_ra_mode == other.ipv6_ra_mode and
+ self.ipv6_address_mode == other.ipv6_address_mode and
+ self.start == other.start and self.end == other.end)
class Port:
diff --git a/snaps/domain/stack.py b/snaps/domain/stack.py
index 0302184..df4d4e4 100644
--- a/snaps/domain/stack.py
+++ b/snaps/domain/stack.py
@@ -31,3 +31,17 @@ class Stack:
def __eq__(self, other):
return (self.name == other.name and
self.id == other.id)
+
+
+class Resource:
+ """
+ SNAPS domain object for resources created by a heat template
+ """
+ def __init__(self, resource_type, resource_id):
+ """
+ Constructor
+ :param resource_type: the type
+ :param resource_id: the ID attached to the resource of the given type
+ """
+ self.type = resource_type
+ self.id = resource_id
diff --git a/snaps/domain/test/network_tests.py b/snaps/domain/test/network_tests.py
index 4fd20d4..0534b49 100644
--- a/snaps/domain/test/network_tests.py
+++ b/snaps/domain/test/network_tests.py
@@ -24,18 +24,40 @@ class NetworkObjectTests(unittest.TestCase):
Tests the construction of the snaps.domain.network.Network class
"""
- def test_construction_kwargs(self):
+ def test_construction_kwargs_1(self):
+ network = Network(
+ **{'name': 'foo', 'id': 'bar', 'provider:network_type': 'flat',
+ 'admin_state_up': False, 'shared': True,
+ 'router:external': False})
+ self.assertEqual('foo', network.name)
+ self.assertEqual('bar', network.id)
+ self.assertEqual('flat', network.type)
+ self.assertFalse(network.admin_state_up)
+ self.assertFalse(network.external)
+ self.assertTrue(network.shared)
+
+ def test_construction_kwargs_2(self):
network = Network(
- **{'name': 'name', 'id': 'id', 'provider:network_type': 'flat'})
- self.assertEqual('name', network.name)
- self.assertEqual('id', network.id)
+ **{'name': 'foo', 'id': 'bar', 'type': 'flat',
+ 'admin_state_up': False, 'shared': True,
+ 'external': False})
+ self.assertEqual('foo', network.name)
+ self.assertEqual('bar', network.id)
self.assertEqual('flat', network.type)
+ self.assertFalse(network.admin_state_up)
+ self.assertFalse(network.external)
+ self.assertTrue(network.shared)
def test_construction_named(self):
- network = Network(id='id', name='name')
- self.assertEqual('name', network.name)
- self.assertEqual('id', network.id)
- self.assertIsNone(network.type)
+ network = Network(
+ name='foo', id='bar', type='flat', admin_state_up=False,
+ shared=True, external=False)
+ self.assertEqual('foo', network.name)
+ self.assertEqual('bar', network.id)
+ self.assertEqual('flat', network.type)
+ self.assertFalse(network.admin_state_up)
+ self.assertFalse(network.external)
+ self.assertTrue(network.shared)
class SubnetObjectTests(unittest.TestCase):
@@ -45,16 +67,39 @@ class SubnetObjectTests(unittest.TestCase):
def test_construction_kwargs(self):
subnet = Subnet(
- **{'name': 'name', 'id': 'id', 'cidr': '10.0.0.0/24'})
- self.assertEqual('name', subnet.name)
- self.assertEqual('id', subnet.id)
+ **{'name': 'foo', 'id': 'bar', 'cidr': '10.0.0.0/24',
+ 'ip_version': 4, 'gateway_ip': '10.0.0.1', 'enable_dhcp': True,
+ 'dns_nameservers': ['8.8.8.8'], 'host_routes': list(),
+ 'ipv6_ra_mode': 'hello', 'ipv6_address_mode': 'world'})
+ self.assertEqual('foo', subnet.name)
+ self.assertEqual('bar', subnet.id)
self.assertEqual('10.0.0.0/24', subnet.cidr)
+ self.assertEqual(4, subnet.ip_version)
+ self.assertEqual('10.0.0.1', subnet.gateway_ip)
+ self.assertTrue(subnet.enable_dhcp)
+ self.assertEqual(1, len(subnet.dns_nameservers))
+ self.assertEqual('8.8.8.8', subnet.dns_nameservers[0])
+ self.assertEqual(list(), subnet.host_routes)
+ self.assertEqual('hello', subnet.ipv6_ra_mode)
+ self.assertEqual('world', subnet.ipv6_address_mode)
def test_construction_named(self):
- subnet = Subnet(cidr='10.0.0.0/24', id='id', name='name')
- self.assertEqual('name', subnet.name)
- self.assertEqual('id', subnet.id)
+ subnet = Subnet(
+ name='foo', id='bar', cidr='10.0.0.0/24',
+ ip_version=4, gateway_ip='10.0.0.1', enable_dhcp=True,
+ dns_nameservers=['8.8.8.8'], host_routes=list(),
+ ipv6_ra_mode='hello', ipv6_address_mode='world')
+ self.assertEqual('foo', subnet.name)
+ self.assertEqual('bar', subnet.id)
self.assertEqual('10.0.0.0/24', subnet.cidr)
+ self.assertEqual(4, subnet.ip_version)
+ self.assertEqual('10.0.0.1', subnet.gateway_ip)
+ self.assertTrue(subnet.enable_dhcp)
+ self.assertEqual(1, len(subnet.dns_nameservers))
+ self.assertEqual('8.8.8.8', subnet.dns_nameservers[0])
+ self.assertEqual(list(), subnet.host_routes)
+ self.assertEqual('hello', subnet.ipv6_ra_mode)
+ self.assertEqual('world', subnet.ipv6_address_mode)
class PortDomainObjectTests(unittest.TestCase):
diff --git a/snaps/domain/test/stack_tests.py b/snaps/domain/test/stack_tests.py
index a6fd8a3..e0e1ae7 100644
--- a/snaps/domain/test/stack_tests.py
+++ b/snaps/domain/test/stack_tests.py
@@ -14,12 +14,12 @@
# limitations under the License.
import unittest
-from snaps.domain.stack import Stack
+from snaps.domain.stack import Stack, Resource
class StackDomainObjectTests(unittest.TestCase):
"""
- Tests the construction of the snaps.domain.test.Stack class
+ Tests the construction of the snaps.domain.Stack class
"""
def test_construction_positional(self):
@@ -31,3 +31,19 @@ class StackDomainObjectTests(unittest.TestCase):
stack = Stack(stack_id='id', name='name')
self.assertEqual('name', stack.name)
self.assertEqual('id', stack.id)
+
+
+class ResourceDomainObjectTests(unittest.TestCase):
+ """
+ Tests the construction of the snaps.domain.Resource class
+ """
+
+ def test_construction_positional(self):
+ resource = Resource('foo', 'bar')
+ self.assertEqual('foo', resource.type)
+ self.assertEqual('bar', resource.id)
+
+ def test_construction_named(self):
+ resource = Resource(resource_id='bar', resource_type='foo')
+ self.assertEqual('foo', resource.type)
+ self.assertEqual('bar', resource.id)