root / snf-cyclades-app / synnefo / api / tests / ports.py @ f32e8021
History | View | Annotate | Download (13.4 kB)
1 | 5db2001a | Marios Kogias | # Copyright 2011-2013 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | 5db2001a | Marios Kogias | #
|
3 | 5db2001a | Marios Kogias | # Redistribution and use in source and binary forms, with or
|
4 | 5db2001a | Marios Kogias | # without modification, are permitted provided that the following
|
5 | 5db2001a | Marios Kogias | # conditions are met:
|
6 | 5db2001a | Marios Kogias | #
|
7 | 5db2001a | Marios Kogias | # 1. Redistributions of source code must retain the above
|
8 | 5db2001a | Marios Kogias | # copyright notice, this list of conditions and the following
|
9 | 5db2001a | Marios Kogias | # disclaimer.
|
10 | 5db2001a | Marios Kogias | #
|
11 | 5db2001a | Marios Kogias | # 2. Redistributions in binary form must reproduce the above
|
12 | 5db2001a | Marios Kogias | # copyright notice, this list of conditions and the following
|
13 | 5db2001a | Marios Kogias | # disclaimer in the documentation and/or other materials
|
14 | 5db2001a | Marios Kogias | # provided with the distribution.
|
15 | 5db2001a | Marios Kogias | #
|
16 | 5db2001a | Marios Kogias | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | 5db2001a | Marios Kogias | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | 5db2001a | Marios Kogias | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | 5db2001a | Marios Kogias | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | 5db2001a | Marios Kogias | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | 5db2001a | Marios Kogias | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | 5db2001a | Marios Kogias | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | 5db2001a | Marios Kogias | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | 5db2001a | Marios Kogias | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | 5db2001a | Marios Kogias | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | 5db2001a | Marios Kogias | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | 5db2001a | Marios Kogias | # POSSIBILITY OF SUCH DAMAGE.
|
28 | 5db2001a | Marios Kogias | #
|
29 | 5db2001a | Marios Kogias | # The views and conclusions contained in the software and
|
30 | 5db2001a | Marios Kogias | # documentation are those of the authors and should not be
|
31 | 5db2001a | Marios Kogias | # interpreted as representing official policies, either expressed
|
32 | 5db2001a | Marios Kogias | # or implied, of GRNET S.A.i
|
33 | 5db2001a | Marios Kogias | |
34 | f32e8021 | Christos Stavrakakis | from django.conf import settings |
35 | f32e8021 | Christos Stavrakakis | from snf_django.utils.testing import BaseAPITest, override_settings |
36 | 593851e0 | Buildbot | from django.utils import simplejson as json |
37 | 593851e0 | Buildbot | from synnefo.cyclades_settings import cyclades_services |
38 | 593851e0 | Buildbot | from synnefo.lib.services import get_service_path |
39 | 593851e0 | Buildbot | from synnefo.lib import join_urls |
40 | 2c2d4f0a | Christos Stavrakakis | from mock import patch |
41 | 593851e0 | Buildbot | import synnefo.db.models_factory as dbmf |
42 | 593851e0 | Buildbot | |
43 | 593851e0 | Buildbot | COMPUTE_URL = get_service_path(cyclades_services, 'compute',
|
44 | 593851e0 | Buildbot | version='v2.0')
|
45 | 593851e0 | Buildbot | PORTS_URL = join_urls(COMPUTE_URL, "ports/")
|
46 | 593851e0 | Buildbot | |
47 | 593851e0 | Buildbot | |
48 | 593851e0 | Buildbot | class PortTest(BaseAPITest): |
49 | 593851e0 | Buildbot | def test_get_ports(self): |
50 | 593851e0 | Buildbot | url = join_urls(PORTS_URL) |
51 | 593851e0 | Buildbot | response = self.get(url)
|
52 | 593851e0 | Buildbot | self.assertEqual(response.status_code, 200) |
53 | 593851e0 | Buildbot | ports = json.loads(response.content) |
54 | 593851e0 | Buildbot | self.assertEqual(ports, {"ports": []}) |
55 | 593851e0 | Buildbot | |
56 | 593851e0 | Buildbot | def test_get_port_unfound(self): |
57 | 593851e0 | Buildbot | url = join_urls(PORTS_URL, "123")
|
58 | 593851e0 | Buildbot | response = self.get(url)
|
59 | 593851e0 | Buildbot | self.assertEqual(response.status_code, 404) |
60 | 593851e0 | Buildbot | |
61 | 593851e0 | Buildbot | def test_get_port(self): |
62 | f32e8021 | Christos Stavrakakis | nic = dbmf.NetworkInterfaceFactory() |
63 | 593851e0 | Buildbot | url = join_urls(PORTS_URL, str(nic.id))
|
64 | 593851e0 | Buildbot | response = self.get(url, user=nic.network.userid)
|
65 | 593851e0 | Buildbot | self.assertEqual(response.status_code, 200) |
66 | 593851e0 | Buildbot | |
67 | 2c2d4f0a | Christos Stavrakakis | @patch("synnefo.db.models.get_rapi_client") |
68 | 2c2d4f0a | Christos Stavrakakis | def test_delete_port(self, mrapi): |
69 | f32e8021 | Christos Stavrakakis | nic = dbmf.NetworkInterfaceFactory(device_owner='vm')
|
70 | 593851e0 | Buildbot | url = join_urls(PORTS_URL, str(nic.id))
|
71 | 8c15a209 | Christos Stavrakakis | mrapi().ModifyInstance.return_value = 42
|
72 | f32e8021 | Christos Stavrakakis | with override_settings(settings, GANETI_USE_HOTPLUG=True): |
73 | f32e8021 | Christos Stavrakakis | response = self.delete(url, user=nic.network.userid)
|
74 | 593851e0 | Buildbot | self.assertEqual(response.status_code, 204) |
75 | f32e8021 | Christos Stavrakakis | with override_settings(settings, GANETI_USE_HOTPLUG=False): |
76 | f32e8021 | Christos Stavrakakis | response = self.delete(url, user=nic.network.userid)
|
77 | f32e8021 | Christos Stavrakakis | self.assertEqual(response.status_code, 400) |
78 | 593851e0 | Buildbot | |
79 | 7bff4d2f | Marios Kogias | def test_delete_port_from_nonvm(self): |
80 | f32e8021 | Christos Stavrakakis | nic = dbmf.NetworkInterfaceFactory(device_owner='router')
|
81 | 7bff4d2f | Marios Kogias | url = join_urls(PORTS_URL, str(nic.id))
|
82 | 7bff4d2f | Marios Kogias | response = self.delete(url, user=nic.network.userid)
|
83 | 7bff4d2f | Marios Kogias | self.assertEqual(response.status_code, 400) |
84 | 7bff4d2f | Marios Kogias | |
85 | a3b8aaf6 | Marios Kogias | def test_remove_nic_malformed(self): |
86 | a3b8aaf6 | Marios Kogias | url = join_urls(PORTS_URL, "123")
|
87 | a3b8aaf6 | Marios Kogias | response = self.delete(url)
|
88 | a3b8aaf6 | Marios Kogias | self.assertItemNotFound(response)
|
89 | a3b8aaf6 | Marios Kogias | |
90 | 593851e0 | Buildbot | def test_update_port_name(self): |
91 | f32e8021 | Christos Stavrakakis | nic = dbmf.NetworkInterfaceFactory(device_owner='vm')
|
92 | 593851e0 | Buildbot | url = join_urls(PORTS_URL, str(nic.id))
|
93 | 593851e0 | Buildbot | request = {'port': {"name": "test-name"}} |
94 | 593851e0 | Buildbot | response = self.put(url, params=json.dumps(request),
|
95 | 593851e0 | Buildbot | user=nic.network.userid) |
96 | 593851e0 | Buildbot | self.assertEqual(response.status_code, 200) |
97 | 593851e0 | Buildbot | res = json.loads(response.content) |
98 | 593851e0 | Buildbot | self.assertEqual(res['port']['name'], "test-name") |
99 | 593851e0 | Buildbot | |
100 | 593851e0 | Buildbot | def test_update_port_sg_unfound(self): |
101 | f32e8021 | Christos Stavrakakis | sg1 = dbmf.SecurityGroupFactory() |
102 | f32e8021 | Christos Stavrakakis | nic = dbmf.NetworkInterfaceFactory(device_owner='vm')
|
103 | 593851e0 | Buildbot | nic.security_groups.add(sg1) |
104 | 593851e0 | Buildbot | nic.save() |
105 | 593851e0 | Buildbot | url = join_urls(PORTS_URL, str(nic.id))
|
106 | 593851e0 | Buildbot | request = {'port': {"security_groups": ["123"]}} |
107 | 593851e0 | Buildbot | response = self.put(url, params=json.dumps(request),
|
108 | 593851e0 | Buildbot | user=nic.network.userid) |
109 | 593851e0 | Buildbot | self.assertEqual(response.status_code, 404) |
110 | 593851e0 | Buildbot | |
111 | 593851e0 | Buildbot | def test_update_port_sg(self): |
112 | f32e8021 | Christos Stavrakakis | sg1 = dbmf.SecurityGroupFactory() |
113 | f32e8021 | Christos Stavrakakis | sg2 = dbmf.SecurityGroupFactory() |
114 | f32e8021 | Christos Stavrakakis | sg3 = dbmf.SecurityGroupFactory() |
115 | f32e8021 | Christos Stavrakakis | nic = dbmf.NetworkInterfaceFactory(device_owner='vm')
|
116 | 593851e0 | Buildbot | nic.security_groups.add(sg1) |
117 | 593851e0 | Buildbot | nic.save() |
118 | 593851e0 | Buildbot | url = join_urls(PORTS_URL, str(nic.id))
|
119 | 593851e0 | Buildbot | request = {'port': {"security_groups": [str(sg2.id), str(sg3.id)]}} |
120 | 593851e0 | Buildbot | response = self.put(url, params=json.dumps(request),
|
121 | 593851e0 | Buildbot | user=nic.network.userid) |
122 | 593851e0 | Buildbot | res = json.loads(response.content) |
123 | 593851e0 | Buildbot | self.assertEqual(res['port']['security_groups'], |
124 | 593851e0 | Buildbot | [str(sg2.id), str(sg3.id)]) |
125 | 593851e0 | Buildbot | |
126 | 593851e0 | Buildbot | def test_create_port_no_network(self): |
127 | 593851e0 | Buildbot | request = { |
128 | 593851e0 | Buildbot | "port": {
|
129 | 593851e0 | Buildbot | "device_id": "123", |
130 | 593851e0 | Buildbot | "name": "port1", |
131 | 593851e0 | Buildbot | "network_id": "123" |
132 | 593851e0 | Buildbot | } |
133 | 593851e0 | Buildbot | } |
134 | 593851e0 | Buildbot | response = self.post(PORTS_URL, params=json.dumps(request))
|
135 | 593851e0 | Buildbot | self.assertEqual(response.status_code, 404) |
136 | 593851e0 | Buildbot | |
137 | 2c2d4f0a | Christos Stavrakakis | @patch("synnefo.db.models.get_rapi_client") |
138 | 2c2d4f0a | Christos Stavrakakis | def test_create_port_private_net(self, mrapi): |
139 | f32e8021 | Christos Stavrakakis | net = dbmf.NetworkFactory(public=False)
|
140 | f32e8021 | Christos Stavrakakis | dbmf.IPv4SubnetFactory(network=net) |
141 | f32e8021 | Christos Stavrakakis | dbmf.IPv6SubnetFactory(network=net) |
142 | f32e8021 | Christos Stavrakakis | sg1 = dbmf.SecurityGroupFactory() |
143 | f32e8021 | Christos Stavrakakis | sg2 = dbmf.SecurityGroupFactory() |
144 | f32e8021 | Christos Stavrakakis | vm = dbmf.VirtualMachineFactory(userid=net.userid) |
145 | 593851e0 | Buildbot | request = { |
146 | 593851e0 | Buildbot | "port": {
|
147 | 593851e0 | Buildbot | "name": "port1", |
148 | 593851e0 | Buildbot | "network_id": str(net.id), |
149 | 593851e0 | Buildbot | "device_id": str(vm.id), |
150 | 593851e0 | Buildbot | "security_groups": [str(sg1.id), str(sg2.id)] |
151 | 593851e0 | Buildbot | } |
152 | 593851e0 | Buildbot | } |
153 | 8c15a209 | Christos Stavrakakis | mrapi().ModifyInstance.return_value = 42
|
154 | f32e8021 | Christos Stavrakakis | with override_settings(settings, GANETI_USE_HOTPLUG=False): |
155 | f32e8021 | Christos Stavrakakis | response = self.post(PORTS_URL, params=json.dumps(request),
|
156 | f32e8021 | Christos Stavrakakis | user=net.userid) |
157 | f32e8021 | Christos Stavrakakis | self.assertEqual(response.status_code, 400) |
158 | f32e8021 | Christos Stavrakakis | with override_settings(settings, GANETI_USE_HOTPLUG=True): |
159 | f32e8021 | Christos Stavrakakis | response = self.post(PORTS_URL, params=json.dumps(request),
|
160 | f32e8021 | Christos Stavrakakis | user=net.userid) |
161 | 593851e0 | Buildbot | self.assertEqual(response.status_code, 201) |
162 | a3b8aaf6 | Marios Kogias | |
163 | 9c74cc19 | Marios Kogias | def test_create_port_public_net_no_ip(self): |
164 | f32e8021 | Christos Stavrakakis | net = dbmf.NetworkFactory(public=True)
|
165 | f32e8021 | Christos Stavrakakis | vm = dbmf.VirtualMachineFactory(userid=net.userid) |
166 | 9c74cc19 | Marios Kogias | request = { |
167 | 9c74cc19 | Marios Kogias | "port": {
|
168 | 9c74cc19 | Marios Kogias | "name": "port1", |
169 | 9c74cc19 | Marios Kogias | "network_id": str(net.id), |
170 | 9c74cc19 | Marios Kogias | "device_id": str(vm.id), |
171 | 9c74cc19 | Marios Kogias | } |
172 | 9c74cc19 | Marios Kogias | } |
173 | 9c74cc19 | Marios Kogias | response = self.post(PORTS_URL, params=json.dumps(request),
|
174 | 9c74cc19 | Marios Kogias | user=net.userid) |
175 | 9c74cc19 | Marios Kogias | self.assertEqual(response.status_code, 400) |
176 | 9c74cc19 | Marios Kogias | |
177 | 9c74cc19 | Marios Kogias | def test_create_port_public_net_wrong_ip(self): |
178 | f32e8021 | Christos Stavrakakis | net = dbmf.NetworkFactory(public=True)
|
179 | f32e8021 | Christos Stavrakakis | vm = dbmf.VirtualMachineFactory(userid=net.userid) |
180 | 9c74cc19 | Marios Kogias | request = { |
181 | 9c74cc19 | Marios Kogias | "port": {
|
182 | 9c74cc19 | Marios Kogias | "name": "port1", |
183 | 9c74cc19 | Marios Kogias | "network_id": str(net.id), |
184 | 9c74cc19 | Marios Kogias | "device_id": str(vm.id), |
185 | 2c2d4f0a | Christos Stavrakakis | "fixed_ips": [{"ip_address": "8.8.8.8"}] |
186 | 9c74cc19 | Marios Kogias | } |
187 | 9c74cc19 | Marios Kogias | } |
188 | 9c74cc19 | Marios Kogias | response = self.post(PORTS_URL, params=json.dumps(request),
|
189 | 9c74cc19 | Marios Kogias | user=net.userid) |
190 | 9c74cc19 | Marios Kogias | self.assertEqual(response.status_code, 404) |
191 | 9c74cc19 | Marios Kogias | |
192 | 9c74cc19 | Marios Kogias | def test_create_port_public_net_conflict(self): |
193 | f32e8021 | Christos Stavrakakis | net = dbmf.NetworkFactory(public=True)
|
194 | 9c74cc19 | Marios Kogias | fip = dbmf.FloatingIPFactory(nic=None, userid=net.userid)
|
195 | f32e8021 | Christos Stavrakakis | vm = dbmf.VirtualMachineFactory(userid=net.userid) |
196 | 9c74cc19 | Marios Kogias | request = { |
197 | 9c74cc19 | Marios Kogias | "port": {
|
198 | 9c74cc19 | Marios Kogias | "name": "port1", |
199 | 9c74cc19 | Marios Kogias | "network_id": str(net.id), |
200 | 9c74cc19 | Marios Kogias | "device_id": str(vm.id), |
201 | 2c2d4f0a | Christos Stavrakakis | "fixed_ips": [{"ip_address": fip.address}] |
202 | 9c74cc19 | Marios Kogias | } |
203 | 9c74cc19 | Marios Kogias | } |
204 | 9c74cc19 | Marios Kogias | response = self.post(PORTS_URL, params=json.dumps(request),
|
205 | 9c74cc19 | Marios Kogias | user=net.userid) |
206 | 9c74cc19 | Marios Kogias | self.assertEqual(response.status_code, 409) |
207 | 9c74cc19 | Marios Kogias | |
208 | 9c74cc19 | Marios Kogias | def test_create_port_public_net_taken_ip(self): |
209 | f32e8021 | Christos Stavrakakis | net = dbmf.NetworkFactory(public=True)
|
210 | 9c74cc19 | Marios Kogias | fip = dbmf.FloatingIPFactory(network=net, userid=net.userid) |
211 | f32e8021 | Christos Stavrakakis | vm = dbmf.VirtualMachineFactory(userid=net.userid) |
212 | 9c74cc19 | Marios Kogias | request = { |
213 | 9c74cc19 | Marios Kogias | "port": {
|
214 | 9c74cc19 | Marios Kogias | "name": "port1", |
215 | 9c74cc19 | Marios Kogias | "network_id": str(net.id), |
216 | 9c74cc19 | Marios Kogias | "device_id": str(vm.id), |
217 | 2c2d4f0a | Christos Stavrakakis | "fixed_ips": [{"ip_address": fip.address}] |
218 | 9c74cc19 | Marios Kogias | } |
219 | 9c74cc19 | Marios Kogias | } |
220 | 9c74cc19 | Marios Kogias | response = self.post(PORTS_URL, params=json.dumps(request),
|
221 | 9c74cc19 | Marios Kogias | user=net.userid) |
222 | f32e8021 | Christos Stavrakakis | self.assertEqual(response.status_code, 409) |
223 | 9c74cc19 | Marios Kogias | |
224 | 2c2d4f0a | Christos Stavrakakis | @patch("synnefo.db.models.get_rapi_client") |
225 | f32e8021 | Christos Stavrakakis | def test_create_port_with_floating_ip(self, mrapi): |
226 | f32e8021 | Christos Stavrakakis | vm = dbmf.VirtualMachineFactory() |
227 | f32e8021 | Christos Stavrakakis | fip = dbmf.FloatingIPFactory(network__public=True, nic=None, |
228 | f32e8021 | Christos Stavrakakis | userid=vm.userid) |
229 | 9c74cc19 | Marios Kogias | request = { |
230 | 9c74cc19 | Marios Kogias | "port": {
|
231 | 9c74cc19 | Marios Kogias | "name": "port1", |
232 | f32e8021 | Christos Stavrakakis | "network_id": str(fip.network_id), |
233 | 9c74cc19 | Marios Kogias | "device_id": str(vm.id), |
234 | 2c2d4f0a | Christos Stavrakakis | "fixed_ips": [{"ip_address": fip.address}] |
235 | 9c74cc19 | Marios Kogias | } |
236 | 9c74cc19 | Marios Kogias | } |
237 | 8c15a209 | Christos Stavrakakis | mrapi().ModifyInstance.return_value = 42
|
238 | f32e8021 | Christos Stavrakakis | with override_settings(settings, GANETI_USE_HOTPLUG=True): |
239 | f32e8021 | Christos Stavrakakis | response = self.post(PORTS_URL, params=json.dumps(request),
|
240 | f32e8021 | Christos Stavrakakis | user=vm.userid) |
241 | 2c2d4f0a | Christos Stavrakakis | self.assertEqual(response.status_code, 201) |
242 | 9c74cc19 | Marios Kogias | |
243 | a3b8aaf6 | Marios Kogias | def test_add_nic_to_deleted_network(self): |
244 | a3b8aaf6 | Marios Kogias | user = 'userr'
|
245 | a3b8aaf6 | Marios Kogias | vm = dbmf.VirtualMachineFactory(name='yo', userid=user,
|
246 | 2c2d4f0a | Christos Stavrakakis | operstate="ACTIVE")
|
247 | a3b8aaf6 | Marios Kogias | net = dbmf.NetworkFactory(state='ACTIVE', userid=user,
|
248 | 2c2d4f0a | Christos Stavrakakis | deleted=True)
|
249 | a3b8aaf6 | Marios Kogias | request = { |
250 | a3b8aaf6 | Marios Kogias | "port": {
|
251 | a3b8aaf6 | Marios Kogias | "device_id": str(vm.id), |
252 | a3b8aaf6 | Marios Kogias | "name": "port1", |
253 | a3b8aaf6 | Marios Kogias | "network_id": str(net.id) |
254 | a3b8aaf6 | Marios Kogias | } |
255 | a3b8aaf6 | Marios Kogias | } |
256 | a3b8aaf6 | Marios Kogias | response = self.post(PORTS_URL, params=json.dumps(request),
|
257 | a3b8aaf6 | Marios Kogias | user=net.userid) |
258 | a3b8aaf6 | Marios Kogias | self.assertBadRequest(response)
|
259 | a3b8aaf6 | Marios Kogias | |
260 | a3b8aaf6 | Marios Kogias | def test_add_nic_to_public_network(self): |
261 | a3b8aaf6 | Marios Kogias | user = 'userr'
|
262 | a3b8aaf6 | Marios Kogias | vm = dbmf.VirtualMachineFactory(name='yo', userid=user)
|
263 | a3b8aaf6 | Marios Kogias | net = dbmf.NetworkFactory(state='ACTIVE', userid=user, public=True) |
264 | a3b8aaf6 | Marios Kogias | request = { |
265 | a3b8aaf6 | Marios Kogias | "port": {
|
266 | a3b8aaf6 | Marios Kogias | "device_id": str(vm.id), |
267 | a3b8aaf6 | Marios Kogias | "name": "port1", |
268 | a3b8aaf6 | Marios Kogias | "network_id": str(net.id) |
269 | a3b8aaf6 | Marios Kogias | } |
270 | a3b8aaf6 | Marios Kogias | } |
271 | a3b8aaf6 | Marios Kogias | response = self.post(PORTS_URL, params=json.dumps(request),
|
272 | a3b8aaf6 | Marios Kogias | user=net.userid) |
273 | 2c2d4f0a | Christos Stavrakakis | self.assertBadRequest(response)
|
274 | 2c2d4f0a | Christos Stavrakakis | #self.assertFault(response, 403, 'forbidden')
|
275 | a3b8aaf6 | Marios Kogias | |
276 | a3b8aaf6 | Marios Kogias | def test_add_nic_malformed_1(self): |
277 | a3b8aaf6 | Marios Kogias | user = 'userr'
|
278 | 2c2d4f0a | Christos Stavrakakis | dbmf.VirtualMachineFactory(name='yo', userid=user)
|
279 | a3b8aaf6 | Marios Kogias | net = dbmf.NetworkFactory(state='ACTIVE', userid=user)
|
280 | a3b8aaf6 | Marios Kogias | request = { |
281 | a3b8aaf6 | Marios Kogias | "port": {
|
282 | a3b8aaf6 | Marios Kogias | "name": "port1", |
283 | a3b8aaf6 | Marios Kogias | "network_id": str(net.id) |
284 | a3b8aaf6 | Marios Kogias | } |
285 | a3b8aaf6 | Marios Kogias | } |
286 | a3b8aaf6 | Marios Kogias | response = self.post(PORTS_URL, params=json.dumps(request),
|
287 | a3b8aaf6 | Marios Kogias | user=net.userid) |
288 | a3b8aaf6 | Marios Kogias | self.assertBadRequest(response)
|
289 | a3b8aaf6 | Marios Kogias | |
290 | a3b8aaf6 | Marios Kogias | def test_add_nic_malformed_2(self): |
291 | a3b8aaf6 | Marios Kogias | user = 'userr'
|
292 | a3b8aaf6 | Marios Kogias | vm = dbmf.VirtualMachineFactory(name='yo', userid=user)
|
293 | a3b8aaf6 | Marios Kogias | net = dbmf.NetworkFactory(state='ACTIVE', userid=user)
|
294 | a3b8aaf6 | Marios Kogias | request = { |
295 | a3b8aaf6 | Marios Kogias | "port": {
|
296 | a3b8aaf6 | Marios Kogias | "device_id": str(vm.id), |
297 | a3b8aaf6 | Marios Kogias | "name": "port1" |
298 | a3b8aaf6 | Marios Kogias | } |
299 | a3b8aaf6 | Marios Kogias | } |
300 | a3b8aaf6 | Marios Kogias | response = self.post(PORTS_URL, params=json.dumps(request),
|
301 | a3b8aaf6 | Marios Kogias | user=net.userid) |
302 | a3b8aaf6 | Marios Kogias | self.assertBadRequest(response)
|
303 | a3b8aaf6 | Marios Kogias | |
304 | a3b8aaf6 | Marios Kogias | def test_add_nic_not_active(self): |
305 | a3b8aaf6 | Marios Kogias | """Test connecting VM to non-active network"""
|
306 | a3b8aaf6 | Marios Kogias | user = 'dummy'
|
307 | a3b8aaf6 | Marios Kogias | vm = dbmf.VirtualMachineFactory(name='yo', userid=user)
|
308 | a3b8aaf6 | Marios Kogias | net = dbmf.NetworkFactory(state='PENDING', userid=user)
|
309 | a3b8aaf6 | Marios Kogias | request = { |
310 | a3b8aaf6 | Marios Kogias | "port": {
|
311 | a3b8aaf6 | Marios Kogias | "device_id": str(vm.id), |
312 | a3b8aaf6 | Marios Kogias | "name": "port1", |
313 | a3b8aaf6 | Marios Kogias | "network_id": str(net.id) |
314 | a3b8aaf6 | Marios Kogias | } |
315 | a3b8aaf6 | Marios Kogias | } |
316 | a3b8aaf6 | Marios Kogias | response = self.post(PORTS_URL, params=json.dumps(request),
|
317 | a3b8aaf6 | Marios Kogias | user=net.userid) |
318 | a3b8aaf6 | Marios Kogias | # Test that returns BuildInProgress
|
319 | a3b8aaf6 | Marios Kogias | self.assertEqual(response.status_code, 409) |
320 | a3b8aaf6 | Marios Kogias | |
321 | a3b8aaf6 | Marios Kogias | # def test_add_nic_full_network(self, mrapi):
|
322 | a3b8aaf6 | Marios Kogias | # """Test connecting VM to a full network"""
|
323 | a3b8aaf6 | Marios Kogias | # user = 'userr'
|
324 | a3b8aaf6 | Marios Kogias | # vm = dbmf.VirtualMachineFactory(name='yo', userid=user,
|
325 | a3b8aaf6 | Marios Kogias | # operstate="STARTED")
|
326 | a3b8aaf6 | Marios Kogias | # net = dbmf.NetworkFactory(state='ACTIVE', subnet='10.0.0.0/30',
|
327 | a3b8aaf6 | Marios Kogias | # userid=user, dhcp=True)
|
328 | a3b8aaf6 | Marios Kogias | # pool = net.get_pool()
|
329 | a3b8aaf6 | Marios Kogias | # while not pool.empty():
|
330 | a3b8aaf6 | Marios Kogias | # pool.get()
|
331 | a3b8aaf6 | Marios Kogias | # pool.save()
|
332 | a3b8aaf6 | Marios Kogias | # pool = net.get_pool()
|
333 | a3b8aaf6 | Marios Kogias | # self.assertTrue(pool.empty())
|
334 | a3b8aaf6 | Marios Kogias | # request = {'add': {'serverRef': vm.id}}
|
335 | a3b8aaf6 | Marios Kogias | # response = self.mypost('networks/%d/action' % net.id,
|
336 | a3b8aaf6 | Marios Kogias | # net.userid, json.dumps(request), 'json')
|
337 | a3b8aaf6 | Marios Kogias | # # Test that returns OverLimit
|
338 | a3b8aaf6 | Marios Kogias | # self.assertEqual(response.status_code, 413)
|
339 | a3b8aaf6 | Marios Kogias | # self.assertFalse(mrapi.called) |