1 # Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
2 # and others. All rights reserved.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 from snaps.domain.network import (
18 Port, SecurityGroup, SecurityGroupRule, Router, InterfaceRouter, Network,
22 class NetworkObjectTests(unittest.TestCase):
24 Tests the construction of the snaps.domain.network.Network class
27 def test_construction_kwargs(self):
29 **{'name': 'name', 'id': 'id', 'provider:network_type': 'flat'})
30 self.assertEqual('name', network.name)
31 self.assertEqual('id', network.id)
32 self.assertEqual('flat', network.type)
34 def test_construction_named(self):
35 network = Network(id='id', name='name')
36 self.assertEqual('name', network.name)
37 self.assertEqual('id', network.id)
38 self.assertIsNone(network.type)
41 class SubnetObjectTests(unittest.TestCase):
43 Tests the construction of the snaps.domain.network.Subnet class
46 def test_construction_kwargs(self):
48 **{'name': 'name', 'id': 'id', 'cidr': '10.0.0.0/24'})
49 self.assertEqual('name', subnet.name)
50 self.assertEqual('id', subnet.id)
51 self.assertEqual('10.0.0.0/24', subnet.cidr)
53 def test_construction_named(self):
54 subnet = Subnet(cidr='10.0.0.0/24', id='id', name='name')
55 self.assertEqual('name', subnet.name)
56 self.assertEqual('id', subnet.id)
57 self.assertEqual('10.0.0.0/24', subnet.cidr)
60 class PortDomainObjectTests(unittest.TestCase):
62 Tests the construction of the snaps.domain.network.Port class
65 def test_construction_kwargs(self):
68 **{'name': 'name', 'id': 'id', 'ips': ips})
69 self.assertEqual('name', port.name)
70 self.assertEqual('id', port.id)
71 self.assertEqual(ips, port.ips)
73 def test_construction_named(self):
75 port = Port(ips=ips, id='id', name='name')
76 self.assertEqual('name', port.name)
77 self.assertEqual('id', port.id)
78 self.assertEqual(ips, port.ips)
81 class RouterDomainObjectTests(unittest.TestCase):
83 Tests the construction of the snaps.domain.network.Router class
86 def test_construction_kwargs(self):
88 **{'name': 'name', 'id': 'id', 'status': 'hello',
89 'tenant_id': '1234', 'admin_state_up': 'yes',
90 'external_gateway_info': 'no'})
91 self.assertEqual('name', router.name)
92 self.assertEqual('id', router.id)
93 self.assertEqual('hello', router.status)
94 self.assertEqual('1234', router.tenant_id)
95 self.assertEqual('yes', router.admin_state_up)
96 self.assertEqual('no', router.external_gateway_info)
98 def test_construction_named(self):
100 external_gateway_info='no', admin_state_up='yes', tenant_id='1234',
101 status='hello', id='id', name='name')
102 self.assertEqual('name', router.name)
103 self.assertEqual('id', router.id)
104 self.assertEqual('hello', router.status)
105 self.assertEqual('1234', router.tenant_id)
106 self.assertEqual('yes', router.admin_state_up)
107 self.assertEqual('no', router.external_gateway_info)
110 class InterfaceRouterDomainObjectTests(unittest.TestCase):
112 Tests the construction of the snaps.domain.network.InterfaceRouter class
115 def test_construction_kwargs(self):
116 intf_router = InterfaceRouter(
117 **{'id': 'id', 'subnet_id': 'foo', 'port_id': 'bar'})
118 self.assertEqual('id', intf_router.id)
119 self.assertEqual('foo', intf_router.subnet_id)
120 self.assertEqual('bar', intf_router.port_id)
122 def test_construction_named(self):
123 intf_router = InterfaceRouter(port_id='bar', subnet_id='foo', id='id')
124 self.assertEqual('id', intf_router.id)
125 self.assertEqual('foo', intf_router.subnet_id)
126 self.assertEqual('bar', intf_router.port_id)
129 class SecurityGroupDomainObjectTests(unittest.TestCase):
131 Tests the construction of the snaps.domain.network.SecurityGroup class
134 def test_construction_proj_id_kwargs(self):
135 sec_grp = SecurityGroup(
136 **{'name': 'name', 'id': 'id', 'project_id': 'foo',
137 'description': 'test desc'})
138 self.assertEqual('name', sec_grp.name)
139 self.assertEqual('id', sec_grp.id)
140 self.assertEqual('test desc', sec_grp.description)
141 self.assertEqual('foo', sec_grp.project_id)
143 def test_construction_tenant_id_kwargs(self):
144 sec_grp = SecurityGroup(
145 **{'name': 'name', 'id': 'id',
147 self.assertEqual('name', sec_grp.name)
148 self.assertEqual('id', sec_grp.id)
149 self.assertEqual('foo', sec_grp.project_id)
150 self.assertIsNone(sec_grp.description)
152 def test_construction_named(self):
153 sec_grp = SecurityGroup(description='test desc', tenant_id='foo',
154 id='id', name='name')
155 self.assertEqual('name', sec_grp.name)
156 self.assertEqual('id', sec_grp.id)
157 self.assertEqual('test desc', sec_grp.description)
158 self.assertEqual('foo', sec_grp.project_id)
161 class SecurityGroupRuleDomainObjectTests(unittest.TestCase):
163 Tests the construction of the snaps.domain.network.SecurityGroupRule class
166 def test_construction_kwargs(self):
167 sec_grp_rule = SecurityGroupRule(
168 **{'id': 'id', 'security_group_id': 'grp_id',
169 'description': 'desc', 'direction': 'dir', 'ethertype': 'eType',
170 'port_range_min': '10.0.0.100', 'port_range_max': '10.0.0.200',
171 'protocol': 'proto', 'remote_group_id': 'group_id',
172 'remote_ip_prefix': 'ip_prefix'})
173 self.assertEqual('id', sec_grp_rule.id)
174 self.assertEqual('grp_id', sec_grp_rule.security_group_id)
175 self.assertEqual('desc', sec_grp_rule.description)
176 self.assertEqual('dir', sec_grp_rule.direction)
177 self.assertEqual('eType', sec_grp_rule.ethertype)
178 self.assertEqual('10.0.0.100', sec_grp_rule.port_range_min)
179 self.assertEqual('10.0.0.200', sec_grp_rule.port_range_max)
180 self.assertEqual('proto', sec_grp_rule.protocol)
181 self.assertEqual('group_id', sec_grp_rule.remote_group_id)
182 self.assertEqual('ip_prefix', sec_grp_rule.remote_ip_prefix)
184 def test_construction_named(self):
185 sec_grp_rule = SecurityGroupRule(
186 remote_ip_prefix='ip_prefix', remote_group_id='group_id',
187 protocol='proto', port_range_min='10.0.0.100',
188 port_range_max='10.0.0.200', ethertype='eType',
189 direction='dir', description='desc', security_group_id='grp_id',
191 self.assertEqual('id', sec_grp_rule.id)
192 self.assertEqual('grp_id', sec_grp_rule.security_group_id)
193 self.assertEqual('desc', sec_grp_rule.description)
194 self.assertEqual('dir', sec_grp_rule.direction)
195 self.assertEqual('eType', sec_grp_rule.ethertype)
196 self.assertEqual('10.0.0.100', sec_grp_rule.port_range_min)
197 self.assertEqual('10.0.0.200', sec_grp_rule.port_range_max)
198 self.assertEqual('proto', sec_grp_rule.protocol)
199 self.assertEqual('group_id', sec_grp_rule.remote_group_id)
200 self.assertEqual('ip_prefix', sec_grp_rule.remote_ip_prefix)