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.vm_inst import VmInst, FloatingIp
20 class VmInstDomainObjectTests(unittest.TestCase):
22 Tests the construction of the snaps.domain.test.Image class
25 def test_construction_positional(self):
26 vm_inst = VmInst('name', 'id', '456', '123', list(), 'kp-name',
27 ['foo', 'bar'], ['123', '456'])
28 self.assertEqual('name', vm_inst.name)
29 self.assertEqual('id', vm_inst.id)
30 self.assertEqual('456', vm_inst.image_id)
31 self.assertEqual('123', vm_inst.flavor_id)
32 self.assertEqual(list(), vm_inst.ports)
33 self.assertEqual('kp-name', vm_inst.keypair_name)
34 self.assertEqual(['foo', 'bar'], vm_inst.sec_grp_names)
35 self.assertEqual(['123', '456'], vm_inst.volume_ids)
37 def test_construction_named(self):
39 volume_ids=['123', '456'], sec_grp_names=['foo', 'bar'],
40 ports=list(), inst_id='id', name='name', flavor_id='123',
41 image_id='456', keypair_name='kp-name')
42 self.assertEqual('name', vm_inst.name)
43 self.assertEqual('id', vm_inst.id)
44 self.assertEqual('456', vm_inst.image_id)
45 self.assertEqual('123', vm_inst.flavor_id)
46 self.assertEqual(list(), vm_inst.ports)
47 self.assertEqual('kp-name', vm_inst.keypair_name)
48 self.assertEqual(['foo', 'bar'], vm_inst.sec_grp_names)
49 self.assertEqual(['123', '456'], vm_inst.volume_ids)
52 class FloatingIpDomainObjectTests(unittest.TestCase):
54 Tests the construction of the snaps.domain.test.Image class
57 def test_construction_kwargs_ip_proj(self):
58 kwargs = {'id': 'foo', 'description': 'bar', 'ip': '192.168.122.3',
59 'fixed_ip_address': '10.0.0.3',
60 'floating_network_id': 'id_of_net', 'port_id': 'id_of_port',
61 'router_id': 'id_of_router', 'project_id': 'id_of_proj'}
62 vm_inst = FloatingIp(**kwargs)
63 self.assertEqual('foo', vm_inst.id)
64 self.assertEqual('bar', vm_inst.description)
65 self.assertEqual('192.168.122.3', vm_inst.ip)
66 self.assertEqual('10.0.0.3', vm_inst.fixed_ip_address)
67 self.assertEqual('id_of_net', vm_inst.floating_network_id)
68 self.assertEqual('id_of_port', vm_inst.port_id)
69 self.assertEqual('id_of_router', vm_inst.router_id)
70 self.assertEqual('id_of_proj', vm_inst.project_id)
72 def test_construction_kwargs_fixed_ip_tenant(self):
73 kwargs = {'id': 'foo', 'description': 'bar',
74 'floating_ip_address': '192.168.122.3',
75 'fixed_ip_address': '10.0.0.3',
76 'floating_network_id': 'id_of_net', 'port_id': 'id_of_port',
77 'router_id': 'id_of_router', 'tenant_id': 'id_of_proj'}
78 vm_inst = FloatingIp(**kwargs)
79 self.assertEqual('foo', vm_inst.id)
80 self.assertEqual('bar', vm_inst.description)
81 self.assertEqual('192.168.122.3', vm_inst.ip)
82 self.assertEqual('10.0.0.3', vm_inst.fixed_ip_address)
83 self.assertEqual('id_of_net', vm_inst.floating_network_id)
84 self.assertEqual('id_of_port', vm_inst.port_id)
85 self.assertEqual('id_of_router', vm_inst.router_id)
86 self.assertEqual('id_of_proj', vm_inst.project_id)
88 def test_construction_named_ip_proj(self):
90 id='foo', description='bar', ip='192.168.122.3',
91 fixed_ip_address='10.0.0.3', floating_network_id='id_of_net',
92 port_id='id_of_port', router_id='id_of_router',
93 project_id='id_of_proj')
94 self.assertEqual('foo', vm_inst.id)
95 self.assertEqual('bar', vm_inst.description)
96 self.assertEqual('192.168.122.3', vm_inst.ip)
97 self.assertEqual('10.0.0.3', vm_inst.fixed_ip_address)
98 self.assertEqual('id_of_net', vm_inst.floating_network_id)
99 self.assertEqual('id_of_port', vm_inst.port_id)
100 self.assertEqual('id_of_router', vm_inst.router_id)
101 self.assertEqual('id_of_proj', vm_inst.project_id)
103 def test_construction_kwargs_named_fixed_ip_tenant(self):
104 vm_inst = FloatingIp(
105 id='foo', description='bar', floating_ip_address='192.168.122.3',
106 fixed_ip_address='10.0.0.3', floating_network_id='id_of_net',
107 port_id='id_of_port', router_id='id_of_router',
108 tenant_id='id_of_proj')
109 self.assertEqual('foo', vm_inst.id)
110 self.assertEqual('bar', vm_inst.description)
111 self.assertEqual('192.168.122.3', vm_inst.ip)
112 self.assertEqual('10.0.0.3', vm_inst.fixed_ip_address)
113 self.assertEqual('id_of_net', vm_inst.floating_network_id)
114 self.assertEqual('id_of_port', vm_inst.port_id)
115 self.assertEqual('id_of_router', vm_inst.router_id)
116 self.assertEqual('id_of_proj', vm_inst.project_id)