root / snf-cyclades-app / synnefo / api / tests / ports.py @ b9364b15
History | View | Annotate | Download (12.8 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 | 593851e0 | Buildbot | from snf_django.utils.testing import BaseAPITest |
35 | 593851e0 | Buildbot | from django.utils import simplejson as json |
36 | 593851e0 | Buildbot | from synnefo.cyclades_settings import cyclades_services |
37 | 593851e0 | Buildbot | from synnefo.lib.services import get_service_path |
38 | 593851e0 | Buildbot | from synnefo.lib import join_urls |
39 | 2c2d4f0a | Christos Stavrakakis | from mock import patch |
40 | 593851e0 | Buildbot | import synnefo.db.models_factory as dbmf |
41 | 593851e0 | Buildbot | |
42 | 593851e0 | Buildbot | COMPUTE_URL = get_service_path(cyclades_services, 'compute',
|
43 | 593851e0 | Buildbot | version='v2.0')
|
44 | 593851e0 | Buildbot | PORTS_URL = join_urls(COMPUTE_URL, "ports/")
|
45 | 593851e0 | Buildbot | |
46 | 593851e0 | Buildbot | |
47 | 593851e0 | Buildbot | class PortTest(BaseAPITest): |
48 | 593851e0 | Buildbot | def test_get_ports(self): |
49 | 593851e0 | Buildbot | url = join_urls(PORTS_URL) |
50 | 593851e0 | Buildbot | response = self.get(url)
|
51 | 593851e0 | Buildbot | self.assertEqual(response.status_code, 200) |
52 | 593851e0 | Buildbot | ports = json.loads(response.content) |
53 | 593851e0 | Buildbot | self.assertEqual(ports, {"ports": []}) |
54 | 593851e0 | Buildbot | |
55 | 593851e0 | Buildbot | def test_get_port_unfound(self): |
56 | 593851e0 | Buildbot | url = join_urls(PORTS_URL, "123")
|
57 | 593851e0 | Buildbot | response = self.get(url)
|
58 | 593851e0 | Buildbot | self.assertEqual(response.status_code, 404) |
59 | 593851e0 | Buildbot | |
60 | 593851e0 | Buildbot | def test_get_port(self): |
61 | 593851e0 | Buildbot | nic = dbmf.NetworkInterfaceFactory.create() |
62 | 593851e0 | Buildbot | url = join_urls(PORTS_URL, str(nic.id))
|
63 | 593851e0 | Buildbot | response = self.get(url, user=nic.network.userid)
|
64 | 593851e0 | Buildbot | self.assertEqual(response.status_code, 200) |
65 | 593851e0 | Buildbot | |
66 | 2c2d4f0a | Christos Stavrakakis | @patch("synnefo.db.models.get_rapi_client") |
67 | 2c2d4f0a | Christos Stavrakakis | def test_delete_port(self, mrapi): |
68 | 593851e0 | Buildbot | nic = dbmf.NetworkInterfaceFactory.create(device_owner='vm')
|
69 | 593851e0 | Buildbot | url = join_urls(PORTS_URL, str(nic.id))
|
70 | 593851e0 | Buildbot | response = self.delete(url, user=nic.network.userid)
|
71 | 593851e0 | Buildbot | self.assertEqual(response.status_code, 204) |
72 | 593851e0 | Buildbot | |
73 | 7bff4d2f | Marios Kogias | def test_delete_port_from_nonvm(self): |
74 | 7bff4d2f | Marios Kogias | nic = dbmf.NetworkInterfaceFactory.create(device_owner='router')
|
75 | 7bff4d2f | Marios Kogias | url = join_urls(PORTS_URL, str(nic.id))
|
76 | 7bff4d2f | Marios Kogias | response = self.delete(url, user=nic.network.userid)
|
77 | 7bff4d2f | Marios Kogias | self.assertEqual(response.status_code, 400) |
78 | 7bff4d2f | Marios Kogias | |
79 | a3b8aaf6 | Marios Kogias | def test_remove_nic_malformed(self): |
80 | a3b8aaf6 | Marios Kogias | url = join_urls(PORTS_URL, "123")
|
81 | a3b8aaf6 | Marios Kogias | response = self.delete(url)
|
82 | a3b8aaf6 | Marios Kogias | self.assertItemNotFound(response)
|
83 | a3b8aaf6 | Marios Kogias | |
84 | 593851e0 | Buildbot | def test_update_port_name(self): |
85 | 593851e0 | Buildbot | nic = dbmf.NetworkInterfaceFactory.create(device_owner='vm')
|
86 | 593851e0 | Buildbot | url = join_urls(PORTS_URL, str(nic.id))
|
87 | 593851e0 | Buildbot | request = {'port': {"name": "test-name"}} |
88 | 593851e0 | Buildbot | response = self.put(url, params=json.dumps(request),
|
89 | 593851e0 | Buildbot | user=nic.network.userid) |
90 | 593851e0 | Buildbot | self.assertEqual(response.status_code, 200) |
91 | 593851e0 | Buildbot | res = json.loads(response.content) |
92 | 593851e0 | Buildbot | self.assertEqual(res['port']['name'], "test-name") |
93 | 593851e0 | Buildbot | |
94 | 593851e0 | Buildbot | def test_update_port_sg_unfound(self): |
95 | 593851e0 | Buildbot | sg1 = dbmf.SecurityGroupFactory.create() |
96 | 5db2001a | Marios Kogias | nic = dbmf.NetworkInterfaceFactory.create(device_owner='vm')
|
97 | 593851e0 | Buildbot | nic.security_groups.add(sg1) |
98 | 593851e0 | Buildbot | nic.save() |
99 | 593851e0 | Buildbot | url = join_urls(PORTS_URL, str(nic.id))
|
100 | 593851e0 | Buildbot | request = {'port': {"security_groups": ["123"]}} |
101 | 593851e0 | Buildbot | response = self.put(url, params=json.dumps(request),
|
102 | 593851e0 | Buildbot | user=nic.network.userid) |
103 | 593851e0 | Buildbot | self.assertEqual(response.status_code, 404) |
104 | 593851e0 | Buildbot | |
105 | 593851e0 | Buildbot | def test_update_port_sg(self): |
106 | 593851e0 | Buildbot | sg1 = dbmf.SecurityGroupFactory.create() |
107 | 593851e0 | Buildbot | sg2 = dbmf.SecurityGroupFactory.create() |
108 | 593851e0 | Buildbot | sg3 = dbmf.SecurityGroupFactory.create() |
109 | 593851e0 | Buildbot | nic = dbmf.NetworkInterfaceFactory.create(device_owner='vm')
|
110 | 593851e0 | Buildbot | nic.security_groups.add(sg1) |
111 | 593851e0 | Buildbot | nic.save() |
112 | 593851e0 | Buildbot | url = join_urls(PORTS_URL, str(nic.id))
|
113 | 593851e0 | Buildbot | request = {'port': {"security_groups": [str(sg2.id), str(sg3.id)]}} |
114 | 593851e0 | Buildbot | response = self.put(url, params=json.dumps(request),
|
115 | 593851e0 | Buildbot | user=nic.network.userid) |
116 | 593851e0 | Buildbot | res = json.loads(response.content) |
117 | 593851e0 | Buildbot | self.assertEqual(res['port']['security_groups'], |
118 | 593851e0 | Buildbot | [str(sg2.id), str(sg3.id)]) |
119 | 593851e0 | Buildbot | |
120 | 593851e0 | Buildbot | def test_create_port_no_network(self): |
121 | 593851e0 | Buildbot | request = { |
122 | 593851e0 | Buildbot | "port": {
|
123 | 593851e0 | Buildbot | "device_id": "123", |
124 | 593851e0 | Buildbot | "name": "port1", |
125 | 593851e0 | Buildbot | "network_id": "123" |
126 | 593851e0 | Buildbot | } |
127 | 593851e0 | Buildbot | } |
128 | 593851e0 | Buildbot | response = self.post(PORTS_URL, params=json.dumps(request))
|
129 | 593851e0 | Buildbot | self.assertEqual(response.status_code, 404) |
130 | 593851e0 | Buildbot | |
131 | 2c2d4f0a | Christos Stavrakakis | @patch("synnefo.db.models.get_rapi_client") |
132 | 2c2d4f0a | Christos Stavrakakis | def test_create_port_private_net(self, mrapi): |
133 | 9c74cc19 | Marios Kogias | net = dbmf.NetworkFactory.create(public=False)
|
134 | 2c2d4f0a | Christos Stavrakakis | dbmf.IPv4SubnetFactory.create(network=net) |
135 | 2c2d4f0a | Christos Stavrakakis | dbmf.IPv6SubnetFactory.create(network=net) |
136 | 593851e0 | Buildbot | sg1 = dbmf.SecurityGroupFactory.create() |
137 | 593851e0 | Buildbot | sg2 = dbmf.SecurityGroupFactory.create() |
138 | 593851e0 | Buildbot | vm = dbmf.VirtualMachineFactory.create(userid=net.userid) |
139 | 593851e0 | Buildbot | request = { |
140 | 593851e0 | Buildbot | "port": {
|
141 | 593851e0 | Buildbot | "name": "port1", |
142 | 593851e0 | Buildbot | "network_id": str(net.id), |
143 | 593851e0 | Buildbot | "device_id": str(vm.id), |
144 | 593851e0 | Buildbot | "security_groups": [str(sg1.id), str(sg2.id)] |
145 | 593851e0 | Buildbot | } |
146 | 593851e0 | Buildbot | } |
147 | 593851e0 | Buildbot | response = self.post(PORTS_URL, params=json.dumps(request),
|
148 | 593851e0 | Buildbot | user=net.userid) |
149 | 593851e0 | Buildbot | self.assertEqual(response.status_code, 201) |
150 | a3b8aaf6 | Marios Kogias | |
151 | 9c74cc19 | Marios Kogias | def test_create_port_public_net_no_ip(self): |
152 | 9c74cc19 | Marios Kogias | net = dbmf.NetworkFactory.create(public=True)
|
153 | 9c74cc19 | Marios Kogias | vm = dbmf.VirtualMachineFactory.create(userid=net.userid) |
154 | 9c74cc19 | Marios Kogias | request = { |
155 | 9c74cc19 | Marios Kogias | "port": {
|
156 | 9c74cc19 | Marios Kogias | "name": "port1", |
157 | 9c74cc19 | Marios Kogias | "network_id": str(net.id), |
158 | 9c74cc19 | Marios Kogias | "device_id": str(vm.id), |
159 | 9c74cc19 | Marios Kogias | } |
160 | 9c74cc19 | Marios Kogias | } |
161 | 9c74cc19 | Marios Kogias | response = self.post(PORTS_URL, params=json.dumps(request),
|
162 | 9c74cc19 | Marios Kogias | user=net.userid) |
163 | 9c74cc19 | Marios Kogias | self.assertEqual(response.status_code, 400) |
164 | 9c74cc19 | Marios Kogias | |
165 | 9c74cc19 | Marios Kogias | def test_create_port_public_net_wrong_ip(self): |
166 | 9c74cc19 | Marios Kogias | net = dbmf.NetworkFactory.create(public=True)
|
167 | 9c74cc19 | Marios Kogias | vm = dbmf.VirtualMachineFactory.create(userid=net.userid) |
168 | 9c74cc19 | Marios Kogias | request = { |
169 | 9c74cc19 | Marios Kogias | "port": {
|
170 | 9c74cc19 | Marios Kogias | "name": "port1", |
171 | 9c74cc19 | Marios Kogias | "network_id": str(net.id), |
172 | 9c74cc19 | Marios Kogias | "device_id": str(vm.id), |
173 | 2c2d4f0a | Christos Stavrakakis | "fixed_ips": [{"ip_address": "8.8.8.8"}] |
174 | 9c74cc19 | Marios Kogias | } |
175 | 9c74cc19 | Marios Kogias | } |
176 | 9c74cc19 | Marios Kogias | response = self.post(PORTS_URL, params=json.dumps(request),
|
177 | 9c74cc19 | Marios Kogias | user=net.userid) |
178 | 9c74cc19 | Marios Kogias | self.assertEqual(response.status_code, 404) |
179 | 9c74cc19 | Marios Kogias | |
180 | 9c74cc19 | Marios Kogias | def test_create_port_public_net_conflict(self): |
181 | 9c74cc19 | Marios Kogias | net = dbmf.NetworkFactory.create(public=True)
|
182 | 9c74cc19 | Marios Kogias | fip = dbmf.FloatingIPFactory(nic=None, userid=net.userid)
|
183 | 9c74cc19 | Marios Kogias | vm = dbmf.VirtualMachineFactory.create(userid=net.userid) |
184 | 9c74cc19 | Marios Kogias | request = { |
185 | 9c74cc19 | Marios Kogias | "port": {
|
186 | 9c74cc19 | Marios Kogias | "name": "port1", |
187 | 9c74cc19 | Marios Kogias | "network_id": str(net.id), |
188 | 9c74cc19 | Marios Kogias | "device_id": str(vm.id), |
189 | 2c2d4f0a | Christos Stavrakakis | "fixed_ips": [{"ip_address": fip.address}] |
190 | 9c74cc19 | Marios Kogias | } |
191 | 9c74cc19 | Marios Kogias | } |
192 | 9c74cc19 | Marios Kogias | response = self.post(PORTS_URL, params=json.dumps(request),
|
193 | 9c74cc19 | Marios Kogias | user=net.userid) |
194 | 9c74cc19 | Marios Kogias | self.assertEqual(response.status_code, 409) |
195 | 9c74cc19 | Marios Kogias | |
196 | 9c74cc19 | Marios Kogias | def test_create_port_public_net_taken_ip(self): |
197 | 9c74cc19 | Marios Kogias | net = dbmf.NetworkFactory.create(public=True)
|
198 | 9c74cc19 | Marios Kogias | fip = dbmf.FloatingIPFactory(network=net, userid=net.userid) |
199 | 9c74cc19 | Marios Kogias | vm = dbmf.VirtualMachineFactory.create(userid=net.userid) |
200 | 9c74cc19 | Marios Kogias | request = { |
201 | 9c74cc19 | Marios Kogias | "port": {
|
202 | 9c74cc19 | Marios Kogias | "name": "port1", |
203 | 9c74cc19 | Marios Kogias | "network_id": str(net.id), |
204 | 9c74cc19 | Marios Kogias | "device_id": str(vm.id), |
205 | 2c2d4f0a | Christos Stavrakakis | "fixed_ips": [{"ip_address": fip.address}] |
206 | 9c74cc19 | Marios Kogias | } |
207 | 9c74cc19 | Marios Kogias | } |
208 | 9c74cc19 | Marios Kogias | response = self.post(PORTS_URL, params=json.dumps(request),
|
209 | 9c74cc19 | Marios Kogias | user=net.userid) |
210 | 9c74cc19 | Marios Kogias | self.assertEqual(response.status_code, 400) |
211 | 9c74cc19 | Marios Kogias | |
212 | 2c2d4f0a | Christos Stavrakakis | @patch("synnefo.db.models.get_rapi_client") |
213 | 2c2d4f0a | Christos Stavrakakis | def test_create_port_public_net(self, mrapi): |
214 | 9c74cc19 | Marios Kogias | net = dbmf.NetworkFactory.create(public=True)
|
215 | 9c74cc19 | Marios Kogias | fip = dbmf.FloatingIPFactory(network=net, nic=None, userid=net.userid)
|
216 | 9c74cc19 | Marios Kogias | vm = dbmf.VirtualMachineFactory.create(userid=net.userid) |
217 | 9c74cc19 | Marios Kogias | request = { |
218 | 9c74cc19 | Marios Kogias | "port": {
|
219 | 9c74cc19 | Marios Kogias | "name": "port1", |
220 | 9c74cc19 | Marios Kogias | "network_id": str(net.id), |
221 | 9c74cc19 | Marios Kogias | "device_id": str(vm.id), |
222 | 2c2d4f0a | Christos Stavrakakis | "fixed_ips": [{"ip_address": fip.address}] |
223 | 9c74cc19 | Marios Kogias | } |
224 | 9c74cc19 | Marios Kogias | } |
225 | 9c74cc19 | Marios Kogias | response = self.post(PORTS_URL, params=json.dumps(request),
|
226 | 9c74cc19 | Marios Kogias | user=net.userid) |
227 | 2c2d4f0a | Christos Stavrakakis | self.assertEqual(response.status_code, 201) |
228 | 9c74cc19 | Marios Kogias | |
229 | a3b8aaf6 | Marios Kogias | def test_add_nic_to_deleted_network(self): |
230 | a3b8aaf6 | Marios Kogias | user = 'userr'
|
231 | a3b8aaf6 | Marios Kogias | vm = dbmf.VirtualMachineFactory(name='yo', userid=user,
|
232 | 2c2d4f0a | Christos Stavrakakis | operstate="ACTIVE")
|
233 | a3b8aaf6 | Marios Kogias | net = dbmf.NetworkFactory(state='ACTIVE', userid=user,
|
234 | 2c2d4f0a | Christos Stavrakakis | deleted=True)
|
235 | a3b8aaf6 | Marios Kogias | request = { |
236 | a3b8aaf6 | Marios Kogias | "port": {
|
237 | a3b8aaf6 | Marios Kogias | "device_id": str(vm.id), |
238 | a3b8aaf6 | Marios Kogias | "name": "port1", |
239 | a3b8aaf6 | Marios Kogias | "network_id": str(net.id) |
240 | a3b8aaf6 | Marios Kogias | } |
241 | a3b8aaf6 | Marios Kogias | } |
242 | a3b8aaf6 | Marios Kogias | response = self.post(PORTS_URL, params=json.dumps(request),
|
243 | a3b8aaf6 | Marios Kogias | user=net.userid) |
244 | a3b8aaf6 | Marios Kogias | self.assertBadRequest(response)
|
245 | a3b8aaf6 | Marios Kogias | |
246 | a3b8aaf6 | Marios Kogias | def test_add_nic_to_public_network(self): |
247 | a3b8aaf6 | Marios Kogias | user = 'userr'
|
248 | a3b8aaf6 | Marios Kogias | vm = dbmf.VirtualMachineFactory(name='yo', userid=user)
|
249 | a3b8aaf6 | Marios Kogias | net = dbmf.NetworkFactory(state='ACTIVE', userid=user, public=True) |
250 | a3b8aaf6 | Marios Kogias | request = { |
251 | a3b8aaf6 | Marios Kogias | "port": {
|
252 | a3b8aaf6 | Marios Kogias | "device_id": str(vm.id), |
253 | a3b8aaf6 | Marios Kogias | "name": "port1", |
254 | a3b8aaf6 | Marios Kogias | "network_id": str(net.id) |
255 | a3b8aaf6 | Marios Kogias | } |
256 | a3b8aaf6 | Marios Kogias | } |
257 | a3b8aaf6 | Marios Kogias | response = self.post(PORTS_URL, params=json.dumps(request),
|
258 | a3b8aaf6 | Marios Kogias | user=net.userid) |
259 | 2c2d4f0a | Christos Stavrakakis | self.assertBadRequest(response)
|
260 | 2c2d4f0a | Christos Stavrakakis | #self.assertFault(response, 403, 'forbidden')
|
261 | a3b8aaf6 | Marios Kogias | |
262 | a3b8aaf6 | Marios Kogias | def test_add_nic_malformed_1(self): |
263 | a3b8aaf6 | Marios Kogias | user = 'userr'
|
264 | 2c2d4f0a | Christos Stavrakakis | dbmf.VirtualMachineFactory(name='yo', userid=user)
|
265 | a3b8aaf6 | Marios Kogias | net = dbmf.NetworkFactory(state='ACTIVE', userid=user)
|
266 | a3b8aaf6 | Marios Kogias | request = { |
267 | a3b8aaf6 | Marios Kogias | "port": {
|
268 | a3b8aaf6 | Marios Kogias | "name": "port1", |
269 | a3b8aaf6 | Marios Kogias | "network_id": str(net.id) |
270 | a3b8aaf6 | Marios Kogias | } |
271 | a3b8aaf6 | Marios Kogias | } |
272 | a3b8aaf6 | Marios Kogias | response = self.post(PORTS_URL, params=json.dumps(request),
|
273 | a3b8aaf6 | Marios Kogias | user=net.userid) |
274 | a3b8aaf6 | Marios Kogias | self.assertBadRequest(response)
|
275 | a3b8aaf6 | Marios Kogias | |
276 | a3b8aaf6 | Marios Kogias | def test_add_nic_malformed_2(self): |
277 | a3b8aaf6 | Marios Kogias | user = 'userr'
|
278 | a3b8aaf6 | Marios Kogias | vm = 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 | "device_id": str(vm.id), |
283 | a3b8aaf6 | Marios Kogias | "name": "port1" |
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_not_active(self): |
291 | a3b8aaf6 | Marios Kogias | """Test connecting VM to non-active network"""
|
292 | a3b8aaf6 | Marios Kogias | user = 'dummy'
|
293 | a3b8aaf6 | Marios Kogias | vm = dbmf.VirtualMachineFactory(name='yo', userid=user)
|
294 | a3b8aaf6 | Marios Kogias | net = dbmf.NetworkFactory(state='PENDING', userid=user)
|
295 | a3b8aaf6 | Marios Kogias | request = { |
296 | a3b8aaf6 | Marios Kogias | "port": {
|
297 | a3b8aaf6 | Marios Kogias | "device_id": str(vm.id), |
298 | a3b8aaf6 | Marios Kogias | "name": "port1", |
299 | a3b8aaf6 | Marios Kogias | "network_id": str(net.id) |
300 | a3b8aaf6 | Marios Kogias | } |
301 | a3b8aaf6 | Marios Kogias | } |
302 | a3b8aaf6 | Marios Kogias | response = self.post(PORTS_URL, params=json.dumps(request),
|
303 | a3b8aaf6 | Marios Kogias | user=net.userid) |
304 | a3b8aaf6 | Marios Kogias | # Test that returns BuildInProgress
|
305 | a3b8aaf6 | Marios Kogias | self.assertEqual(response.status_code, 409) |
306 | a3b8aaf6 | Marios Kogias | |
307 | a3b8aaf6 | Marios Kogias | # def test_add_nic_full_network(self, mrapi):
|
308 | a3b8aaf6 | Marios Kogias | # """Test connecting VM to a full network"""
|
309 | a3b8aaf6 | Marios Kogias | # user = 'userr'
|
310 | a3b8aaf6 | Marios Kogias | # vm = dbmf.VirtualMachineFactory(name='yo', userid=user,
|
311 | a3b8aaf6 | Marios Kogias | # operstate="STARTED")
|
312 | a3b8aaf6 | Marios Kogias | # net = dbmf.NetworkFactory(state='ACTIVE', subnet='10.0.0.0/30',
|
313 | a3b8aaf6 | Marios Kogias | # userid=user, dhcp=True)
|
314 | a3b8aaf6 | Marios Kogias | # pool = net.get_pool()
|
315 | a3b8aaf6 | Marios Kogias | # while not pool.empty():
|
316 | a3b8aaf6 | Marios Kogias | # pool.get()
|
317 | a3b8aaf6 | Marios Kogias | # pool.save()
|
318 | a3b8aaf6 | Marios Kogias | # pool = net.get_pool()
|
319 | a3b8aaf6 | Marios Kogias | # self.assertTrue(pool.empty())
|
320 | a3b8aaf6 | Marios Kogias | # request = {'add': {'serverRef': vm.id}}
|
321 | a3b8aaf6 | Marios Kogias | # response = self.mypost('networks/%d/action' % net.id,
|
322 | a3b8aaf6 | Marios Kogias | # net.userid, json.dumps(request), 'json')
|
323 | a3b8aaf6 | Marios Kogias | # # Test that returns OverLimit
|
324 | a3b8aaf6 | Marios Kogias | # self.assertEqual(response.status_code, 413)
|
325 | a3b8aaf6 | Marios Kogias | # self.assertFalse(mrapi.called) |