summaryrefslogtreecommitdiff
path: root/novaclient/tests/unit/v2/test_servers.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/tests/unit/v2/test_servers.py')
-rw-r--r--novaclient/tests/unit/v2/test_servers.py704
1 files changed, 704 insertions, 0 deletions
diff --git a/novaclient/tests/unit/v2/test_servers.py b/novaclient/tests/unit/v2/test_servers.py
new file mode 100644
index 0000000..c9b15f3
--- /dev/null
+++ b/novaclient/tests/unit/v2/test_servers.py
@@ -0,0 +1,704 @@
1# -*- coding: utf-8 -*-
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15import mock
16from oslo.serialization import jsonutils
17import six
18
19from novaclient import exceptions
20from novaclient.tests.unit.fixture_data import client
21from novaclient.tests.unit.fixture_data import floatingips
22from novaclient.tests.unit.fixture_data import servers as data
23from novaclient.tests.unit import utils
24from novaclient.v2 import servers
25
26
27class ServersTest(utils.FixturedTestCase):
28
29 client_fixture_class = client.V1
30 data_fixture_class = data.V1
31
32 def setUp(self):
33 super(ServersTest, self).setUp()
34 self.useFixture(floatingips.FloatingFixture(self.requests))
35
36 def test_list_servers(self):
37 sl = self.cs.servers.list()
38 self.assert_called('GET', '/servers/detail')
39 [self.assertIsInstance(s, servers.Server) for s in sl]
40
41 def test_list_servers_undetailed(self):
42 sl = self.cs.servers.list(detailed=False)
43 self.assert_called('GET', '/servers')
44 [self.assertIsInstance(s, servers.Server) for s in sl]
45
46 def test_list_servers_with_marker_limit(self):
47 sl = self.cs.servers.list(marker=1234, limit=2)
48 self.assert_called('GET', '/servers/detail?limit=2&marker=1234')
49 for s in sl:
50 self.assertIsInstance(s, servers.Server)
51
52 def test_list_servers_sort_single(self):
53 sl = self.cs.servers.list(sort_keys=['display_name'],
54 sort_dirs=['asc'])
55 self.assert_called(
56 'GET',
57 '/servers/detail?sort_dir=asc&sort_key=display_name')
58 for s in sl:
59 self.assertIsInstance(s, servers.Server)
60
61 def test_list_servers_sort_multiple(self):
62 sl = self.cs.servers.list(sort_keys=['display_name', 'id'],
63 sort_dirs=['asc', 'desc'])
64 self.assert_called(
65 'GET',
66 ('/servers/detail?sort_dir=asc&sort_dir=desc&'
67 'sort_key=display_name&sort_key=id'))
68 for s in sl:
69 self.assertIsInstance(s, servers.Server)
70
71 def test_get_server_details(self):
72 s = self.cs.servers.get(1234)
73 self.assert_called('GET', '/servers/1234')
74 self.assertIsInstance(s, servers.Server)
75 self.assertEqual(1234, s.id)
76 self.assertEqual('BUILD', s.status)
77
78 def test_get_server_promote_details(self):
79 s1 = self.cs.servers.list(detailed=False)[0]
80 s2 = self.cs.servers.list(detailed=True)[0]
81 self.assertNotEqual(s1._info, s2._info)
82 s1.get()
83 self.assertEqual(s1._info, s2._info)
84
85 def test_create_server(self):
86 s = self.cs.servers.create(
87 name="My server",
88 image=1,
89 flavor=1,
90 meta={'foo': 'bar'},
91 userdata="hello moto",
92 key_name="fakekey",
93 files={
94 '/etc/passwd': 'some data', # a file
95 '/tmp/foo.txt': six.StringIO('data'), # a stream
96 }
97 )
98 self.assert_called('POST', '/servers')
99 self.assertIsInstance(s, servers.Server)
100
101 def test_create_server_boot_from_volume_with_nics(self):
102 old_boot = self.cs.servers._boot
103
104 nics = [{'net-id': '11111111-1111-1111-1111-111111111111',
105 'v4-fixed-ip': '10.0.0.7'}]
106 bdm = {"volume_size": "1",
107 "volume_id": "11111111-1111-1111-1111-111111111111",
108 "delete_on_termination": "0",
109 "device_name": "vda"}
110
111 def wrapped_boot(url, key, *boot_args, **boot_kwargs):
112 self.assertEqual(boot_kwargs['block_device_mapping'], bdm)
113 self.assertEqual(boot_kwargs['nics'], nics)
114 return old_boot(url, key, *boot_args, **boot_kwargs)
115
116 @mock.patch.object(self.cs.servers, '_boot', wrapped_boot)
117 def test_create_server_from_volume():
118 s = self.cs.servers.create(
119 name="My server",
120 image=1,
121 flavor=1,
122 meta={'foo': 'bar'},
123 userdata="hello moto",
124 key_name="fakekey",
125 block_device_mapping=bdm,
126 nics=nics
127 )
128 self.assert_called('POST', '/os-volumes_boot')
129 self.assertIsInstance(s, servers.Server)
130
131 test_create_server_from_volume()
132
133 def test_create_server_boot_with_nics_ipv6(self):
134 old_boot = self.cs.servers._boot
135 nics = [{'net-id': '11111111-1111-1111-1111-111111111111',
136 'v6-fixed-ip': '2001:db9:0:1::10'}]
137
138 def wrapped_boot(url, key, *boot_args, **boot_kwargs):
139 self.assertEqual(boot_kwargs['nics'], nics)
140 return old_boot(url, key, *boot_args, **boot_kwargs)
141
142 with mock.patch.object(self.cs.servers, '_boot', wrapped_boot):
143 s = self.cs.servers.create(
144 name="My server",
145 image=1,
146 flavor=1,
147 meta={'foo': 'bar'},
148 userdata="hello moto",
149 key_name="fakekey",
150 nics=nics
151 )
152 self.assert_called('POST', '/servers')
153 self.assertIsInstance(s, servers.Server)
154
155 def test_create_server_userdata_file_object(self):
156 s = self.cs.servers.create(
157 name="My server",
158 image=1,
159 flavor=1,
160 meta={'foo': 'bar'},
161 userdata=six.StringIO('hello moto'),
162 files={
163 '/etc/passwd': 'some data', # a file
164 '/tmp/foo.txt': six.StringIO('data'), # a stream
165 },
166 )
167 self.assert_called('POST', '/servers')
168 self.assertIsInstance(s, servers.Server)
169
170 def test_create_server_userdata_unicode(self):
171 s = self.cs.servers.create(
172 name="My server",
173 image=1,
174 flavor=1,
175 meta={'foo': 'bar'},
176 userdata=six.u('こんにちは'),
177 key_name="fakekey",
178 files={
179 '/etc/passwd': 'some data', # a file
180 '/tmp/foo.txt': six.StringIO('data'), # a stream
181 },
182 )
183 self.assert_called('POST', '/servers')
184 self.assertIsInstance(s, servers.Server)
185
186 def test_create_server_userdata_utf8(self):
187 s = self.cs.servers.create(
188 name="My server",
189 image=1,
190 flavor=1,
191 meta={'foo': 'bar'},
192 userdata='こんにちは',
193 key_name="fakekey",
194 files={
195 '/etc/passwd': 'some data', # a file
196 '/tmp/foo.txt': six.StringIO('data'), # a stream
197 },
198 )
199 self.assert_called('POST', '/servers')
200 self.assertIsInstance(s, servers.Server)
201
202 def _create_disk_config(self, disk_config):
203 s = self.cs.servers.create(
204 name="My server",
205 image=1,
206 flavor=1,
207 disk_config=disk_config
208 )
209 self.assert_called('POST', '/servers')
210 self.assertIsInstance(s, servers.Server)
211
212 # verify disk config param was used in the request:
213 body = jsonutils.loads(self.requests.last_request.body)
214 server = body['server']
215 self.assertTrue('OS-DCF:diskConfig' in server)
216 self.assertEqual(disk_config, server['OS-DCF:diskConfig'])
217
218 def test_create_server_disk_config_auto(self):
219 self._create_disk_config('AUTO')
220
221 def test_create_server_disk_config_manual(self):
222 self._create_disk_config('MANUAL')
223
224 def test_update_server(self):
225 s = self.cs.servers.get(1234)
226
227 # Update via instance
228 s.update(name='hi')
229 self.assert_called('PUT', '/servers/1234')
230 s.update(name='hi')
231 self.assert_called('PUT', '/servers/1234')
232
233 # Silly, but not an error
234 s.update()
235
236 # Update via manager
237 self.cs.servers.update(s, name='hi')
238 self.assert_called('PUT', '/servers/1234')
239
240 def test_delete_server(self):
241 s = self.cs.servers.get(1234)
242 s.delete()
243 self.assert_called('DELETE', '/servers/1234')
244 self.cs.servers.delete(1234)
245 self.assert_called('DELETE', '/servers/1234')
246 self.cs.servers.delete(s)
247 self.assert_called('DELETE', '/servers/1234')
248
249 def test_delete_server_meta(self):
250 self.cs.servers.delete_meta(1234, ['test_key'])
251 self.assert_called('DELETE', '/servers/1234/metadata/test_key')
252
253 def test_set_server_meta(self):
254 self.cs.servers.set_meta(1234, {'test_key': 'test_value'})
255 self.assert_called('POST', '/servers/1234/metadata',
256 {'metadata': {'test_key': 'test_value'}})
257
258 def test_set_server_meta_item(self):
259 self.cs.servers.set_meta_item(1234, 'test_key', 'test_value')
260 self.assert_called('PUT', '/servers/1234/metadata/test_key',
261 {'meta': {'test_key': 'test_value'}})
262
263 def test_find(self):
264 server = self.cs.servers.find(name='sample-server')
265 self.assert_called('GET', '/servers/1234')
266 self.assertEqual('sample-server', server.name)
267
268 self.assertRaises(exceptions.NoUniqueMatch, self.cs.servers.find,
269 flavor={"id": 1, "name": "256 MB Server"})
270
271 sl = self.cs.servers.findall(flavor={"id": 1, "name": "256 MB Server"})
272 self.assertEqual([1234, 5678, 9012], [s.id for s in sl])
273
274 def test_reboot_server(self):
275 s = self.cs.servers.get(1234)
276 s.reboot()
277 self.assert_called('POST', '/servers/1234/action')
278 self.cs.servers.reboot(s, reboot_type='HARD')
279 self.assert_called('POST', '/servers/1234/action')
280
281 def test_rebuild_server(self):
282 s = self.cs.servers.get(1234)
283 s.rebuild(image=1)
284 self.assert_called('POST', '/servers/1234/action')
285 self.cs.servers.rebuild(s, image=1)
286 self.assert_called('POST', '/servers/1234/action')
287 s.rebuild(image=1, password='5678')
288 self.assert_called('POST', '/servers/1234/action')
289 self.cs.servers.rebuild(s, image=1, password='5678')
290 self.assert_called('POST', '/servers/1234/action')
291
292 def _rebuild_resize_disk_config(self, disk_config, operation="rebuild"):
293 s = self.cs.servers.get(1234)
294
295 if operation == "rebuild":
296 s.rebuild(image=1, disk_config=disk_config)
297 elif operation == "resize":
298 s.resize(flavor=1, disk_config=disk_config)
299 self.assert_called('POST', '/servers/1234/action')
300
301 # verify disk config param was used in the request:
302 body = jsonutils.loads(self.requests.last_request.body)
303
304 d = body[operation]
305 self.assertTrue('OS-DCF:diskConfig' in d)
306 self.assertEqual(disk_config, d['OS-DCF:diskConfig'])
307
308 def test_rebuild_server_disk_config_auto(self):
309 self._rebuild_resize_disk_config('AUTO')
310
311 def test_rebuild_server_disk_config_manual(self):
312 self._rebuild_resize_disk_config('MANUAL')
313
314 def test_rebuild_server_preserve_ephemeral(self):
315 s = self.cs.servers.get(1234)
316 s.rebuild(image=1, preserve_ephemeral=True)
317 self.assert_called('POST', '/servers/1234/action')
318 body = jsonutils.loads(self.requests.last_request.body)
319 d = body['rebuild']
320 self.assertIn('preserve_ephemeral', d)
321 self.assertEqual(True, d['preserve_ephemeral'])
322
323 def test_rebuild_server_name_meta_files(self):
324 files = {'/etc/passwd': 'some data'}
325 s = self.cs.servers.get(1234)
326 s.rebuild(image=1, name='new', meta={'foo': 'bar'}, files=files)
327 body = jsonutils.loads(self.requests.last_request.body)
328 d = body['rebuild']
329 self.assertEqual('new', d['name'])
330 self.assertEqual({'foo': 'bar'}, d['metadata'])
331 self.assertEqual('/etc/passwd',
332 d['personality'][0]['path'])
333
334 def test_resize_server(self):
335 s = self.cs.servers.get(1234)
336 s.resize(flavor=1)
337 self.assert_called('POST', '/servers/1234/action')
338 self.cs.servers.resize(s, flavor=1)
339 self.assert_called('POST', '/servers/1234/action')
340
341 def test_resize_server_disk_config_auto(self):
342 self._rebuild_resize_disk_config('AUTO', 'resize')
343
344 def test_resize_server_disk_config_manual(self):
345 self._rebuild_resize_disk_config('MANUAL', 'resize')
346
347 def test_confirm_resized_server(self):
348 s = self.cs.servers.get(1234)
349 s.confirm_resize()
350 self.assert_called('POST', '/servers/1234/action')
351 self.cs.servers.confirm_resize(s)
352 self.assert_called('POST', '/servers/1234/action')
353
354 def test_revert_resized_server(self):
355 s = self.cs.servers.get(1234)
356 s.revert_resize()
357 self.assert_called('POST', '/servers/1234/action')
358 self.cs.servers.revert_resize(s)
359 self.assert_called('POST', '/servers/1234/action')
360
361 def test_migrate_server(self):
362 s = self.cs.servers.get(1234)
363 s.migrate()
364 self.assert_called('POST', '/servers/1234/action')
365 self.cs.servers.migrate(s)
366 self.assert_called('POST', '/servers/1234/action')
367
368 def test_add_fixed_ip(self):
369 s = self.cs.servers.get(1234)
370 s.add_fixed_ip(1)
371 self.assert_called('POST', '/servers/1234/action')
372 self.cs.servers.add_fixed_ip(s, 1)
373 self.assert_called('POST', '/servers/1234/action')
374
375 def test_remove_fixed_ip(self):
376 s = self.cs.servers.get(1234)
377 s.remove_fixed_ip('10.0.0.1')
378 self.assert_called('POST', '/servers/1234/action')
379 self.cs.servers.remove_fixed_ip(s, '10.0.0.1')
380 self.assert_called('POST', '/servers/1234/action')
381
382 def test_add_floating_ip(self):
383 s = self.cs.servers.get(1234)
384 s.add_floating_ip('11.0.0.1')
385 self.assert_called('POST', '/servers/1234/action')
386 self.cs.servers.add_floating_ip(s, '11.0.0.1')
387 self.assert_called('POST', '/servers/1234/action')
388 f = self.cs.floating_ips.list()[0]
389 self.cs.servers.add_floating_ip(s, f)
390 self.assert_called('POST', '/servers/1234/action')
391 s.add_floating_ip(f)
392 self.assert_called('POST', '/servers/1234/action')
393
394 def test_add_floating_ip_to_fixed(self):
395 s = self.cs.servers.get(1234)
396 s.add_floating_ip('11.0.0.1', fixed_address='12.0.0.1')
397 self.assert_called('POST', '/servers/1234/action')
398 self.cs.servers.add_floating_ip(s, '11.0.0.1',
399 fixed_address='12.0.0.1')
400 self.assert_called('POST', '/servers/1234/action')
401 f = self.cs.floating_ips.list()[0]
402 self.cs.servers.add_floating_ip(s, f)
403 self.assert_called('POST', '/servers/1234/action')
404 s.add_floating_ip(f)
405 self.assert_called('POST', '/servers/1234/action')
406
407 def test_remove_floating_ip(self):
408 s = self.cs.servers.get(1234)
409 s.remove_floating_ip('11.0.0.1')
410 self.assert_called('POST', '/servers/1234/action')
411 self.cs.servers.remove_floating_ip(s, '11.0.0.1')
412 self.assert_called('POST', '/servers/1234/action')
413 f = self.cs.floating_ips.list()[0]
414 self.cs.servers.remove_floating_ip(s, f)
415 self.assert_called('POST', '/servers/1234/action')
416 s.remove_floating_ip(f)
417 self.assert_called('POST', '/servers/1234/action')
418
419 def test_stop(self):
420 s = self.cs.servers.get(1234)
421 s.stop()
422 self.assert_called('POST', '/servers/1234/action')
423 self.cs.servers.stop(s)
424 self.assert_called('POST', '/servers/1234/action')
425
426 def test_force_delete(self):
427 s = self.cs.servers.get(1234)
428 s.force_delete()
429 self.assert_called('POST', '/servers/1234/action')
430 self.cs.servers.force_delete(s)
431 self.assert_called('POST', '/servers/1234/action')
432
433 def test_restore(self):
434 s = self.cs.servers.get(1234)
435 s.restore()
436 self.assert_called('POST', '/servers/1234/action')
437 self.cs.servers.restore(s)
438 self.assert_called('POST', '/servers/1234/action')
439
440 def test_start(self):
441 s = self.cs.servers.get(1234)
442 s.start()
443 self.assert_called('POST', '/servers/1234/action')
444 self.cs.servers.start(s)
445 self.assert_called('POST', '/servers/1234/action')
446
447 def test_rescue(self):
448 s = self.cs.servers.get(1234)
449 s.rescue()
450 self.assert_called('POST', '/servers/1234/action')
451 self.cs.servers.rescue(s)
452 self.assert_called('POST', '/servers/1234/action')
453
454 def test_rescue_password(self):
455 s = self.cs.servers.get(1234)
456 s.rescue(password='asdf')
457 self.assert_called('POST', '/servers/1234/action',
458 {'rescue': {'adminPass': 'asdf'}})
459 self.cs.servers.rescue(s, password='asdf')
460 self.assert_called('POST', '/servers/1234/action',
461 {'rescue': {'adminPass': 'asdf'}})
462
463 def test_rescue_image(self):
464 s = self.cs.servers.get(1234)
465 s.rescue(image=1)
466 self.assert_called('POST', '/servers/1234/action',
467 {'rescue': {'rescue_image_ref': 1}})
468 self.cs.servers.rescue(s, image=1)
469 self.assert_called('POST', '/servers/1234/action',
470 {'rescue': {'rescue_image_ref': 1}})
471
472 def test_unrescue(self):
473 s = self.cs.servers.get(1234)
474 s.unrescue()
475 self.assert_called('POST', '/servers/1234/action')
476 self.cs.servers.unrescue(s)
477 self.assert_called('POST', '/servers/1234/action')
478
479 def test_lock(self):
480 s = self.cs.servers.get(1234)
481 s.lock()
482 self.assert_called('POST', '/servers/1234/action')
483 self.cs.servers.lock(s)
484 self.assert_called('POST', '/servers/1234/action')
485
486 def test_unlock(self):
487 s = self.cs.servers.get(1234)
488 s.unlock()
489 self.assert_called('POST', '/servers/1234/action')
490 self.cs.servers.unlock(s)
491 self.assert_called('POST', '/servers/1234/action')
492
493 def test_backup(self):
494 s = self.cs.servers.get(1234)
495 s.backup('back1', 'daily', 1)
496 self.assert_called('POST', '/servers/1234/action')
497 self.cs.servers.backup(s, 'back1', 'daily', 2)
498 self.assert_called('POST', '/servers/1234/action')
499
500 def test_get_console_output_without_length(self):
501 success = 'foo'
502 s = self.cs.servers.get(1234)
503 s.get_console_output()
504 self.assertEqual(success, s.get_console_output())
505 self.assert_called('POST', '/servers/1234/action')
506
507 self.cs.servers.get_console_output(s)
508 self.assertEqual(success, self.cs.servers.get_console_output(s))
509 self.assert_called('POST', '/servers/1234/action')
510
511 def test_get_console_output_with_length(self):
512 success = 'foo'
513
514 s = self.cs.servers.get(1234)
515 s.get_console_output(length=50)
516 self.assertEqual(success, s.get_console_output(length=50))
517 self.assert_called('POST', '/servers/1234/action')
518
519 self.cs.servers.get_console_output(s, length=50)
520 self.assertEqual(success,
521 self.cs.servers.get_console_output(s, length=50))
522 self.assert_called('POST', '/servers/1234/action')
523
524 # Testing password methods with the following password and key
525 #
526 # Clear password: FooBar123
527 #
528 # RSA Private Key: novaclient/tests/unit/idfake.pem
529 #
530 # Encrypted password
531 # OIuEuQttO8Rk93BcKlwHQsziDAnkAm/V6V8VPToA8ZeUaUBWwS0gwo2K6Y61Z96r
532 # qG447iRz0uTEEYq3RAYJk1mh3mMIRVl27t8MtIecR5ggVVbz1S9AwXJQypDKl0ho
533 # QFvhCBcMWPohyGewDJOhDbtuN1IoFI9G55ZvFwCm5y7m7B2aVcoLeIsJZE4PLsIw
534 # /y5a6Z3/AoJZYGG7IH5WN88UROU3B9JZGFB2qtPLQTOvDMZLUhoPRIJeHiVSlo1N
535 # tI2/++UsXVg3ow6ItqCJGgdNuGG5JB+bslDHWPxROpesEIHdczk46HCpHQN8f1sk
536 # Hi/fmZZNQQqj1Ijq0caOIw==
537
538 def test_get_password(self):
539 s = self.cs.servers.get(1234)
540 self.assertEqual(b'FooBar123',
541 s.get_password('novaclient/tests/unit/idfake.pem'))
542 self.assert_called('GET', '/servers/1234/os-server-password')
543
544 def test_get_password_without_key(self):
545 s = self.cs.servers.get(1234)
546 self.assertEqual(
547 'OIuEuQttO8Rk93BcKlwHQsziDAnkAm/V6V8VPToA8ZeUaUBWwS0gwo2K6Y61Z96r'
548 'qG447iRz0uTEEYq3RAYJk1mh3mMIRVl27t8MtIecR5ggVVbz1S9AwXJQypDKl0ho'
549 'QFvhCBcMWPohyGewDJOhDbtuN1IoFI9G55ZvFwCm5y7m7B2aVcoLeIsJZE4PLsIw'
550 '/y5a6Z3/AoJZYGG7IH5WN88UROU3B9JZGFB2qtPLQTOvDMZLUhoPRIJeHiVSlo1N'
551 'tI2/++UsXVg3ow6ItqCJGgdNuGG5JB+bslDHWPxROpesEIHdczk46HCpHQN8f1sk'
552 'Hi/fmZZNQQqj1Ijq0caOIw==', s.get_password())
553 self.assert_called('GET', '/servers/1234/os-server-password')
554
555 def test_clear_password(self):
556 s = self.cs.servers.get(1234)
557 s.clear_password()
558 self.assert_called('DELETE', '/servers/1234/os-server-password')
559
560 def test_get_server_diagnostics(self):
561 s = self.cs.servers.get(1234)
562 diagnostics = s.diagnostics()
563 self.assertTrue(diagnostics is not None)
564 self.assert_called('GET', '/servers/1234/diagnostics')
565
566 diagnostics_from_manager = self.cs.servers.diagnostics(1234)
567 self.assertTrue(diagnostics_from_manager is not None)
568 self.assert_called('GET', '/servers/1234/diagnostics')
569
570 self.assertEqual(diagnostics[1], diagnostics_from_manager[1])
571
572 def test_get_vnc_console(self):
573 s = self.cs.servers.get(1234)
574 s.get_vnc_console('fake')
575 self.assert_called('POST', '/servers/1234/action')
576
577 self.cs.servers.get_vnc_console(s, 'fake')
578 self.assert_called('POST', '/servers/1234/action')
579
580 def test_get_spice_console(self):
581 s = self.cs.servers.get(1234)
582 s.get_spice_console('fake')
583 self.assert_called('POST', '/servers/1234/action')
584
585 self.cs.servers.get_spice_console(s, 'fake')
586 self.assert_called('POST', '/servers/1234/action')
587
588 def test_get_serial_console(self):
589 s = self.cs.servers.get(1234)
590 s.get_serial_console('fake')
591 self.assert_called('POST', '/servers/1234/action')
592
593 self.cs.servers.get_serial_console(s, 'fake')
594 self.assert_called('POST', '/servers/1234/action')
595
596 def test_get_rdp_console(self):
597 s = self.cs.servers.get(1234)
598 s.get_rdp_console('fake')
599 self.assert_called('POST', '/servers/1234/action')
600
601 self.cs.servers.get_rdp_console(s, 'fake')
602 self.assert_called('POST', '/servers/1234/action')
603
604 def test_create_image(self):
605 s = self.cs.servers.get(1234)
606 s.create_image('123')
607 self.assert_called('POST', '/servers/1234/action')
608 s.create_image('123', {})
609 self.assert_called('POST', '/servers/1234/action')
610 self.cs.servers.create_image(s, '123')
611 self.assert_called('POST', '/servers/1234/action')
612 self.cs.servers.create_image(s, '123', {})
613
614 def test_live_migrate_server(self):
615 s = self.cs.servers.get(1234)
616 s.live_migrate(host='hostname', block_migration=False,
617 disk_over_commit=False)
618 self.assert_called('POST', '/servers/1234/action')
619 self.cs.servers.live_migrate(s, host='hostname', block_migration=False,
620 disk_over_commit=False)
621 self.assert_called('POST', '/servers/1234/action')
622
623 def test_reset_state(self):
624 s = self.cs.servers.get(1234)
625 s.reset_state('newstate')
626 self.assert_called('POST', '/servers/1234/action')
627 self.cs.servers.reset_state(s, 'newstate')
628 self.assert_called('POST', '/servers/1234/action')
629
630 def test_reset_network(self):
631 s = self.cs.servers.get(1234)
632 s.reset_network()
633 self.assert_called('POST', '/servers/1234/action')
634 self.cs.servers.reset_network(s)
635 self.assert_called('POST', '/servers/1234/action')
636
637 def test_add_security_group(self):
638 s = self.cs.servers.get(1234)
639 s.add_security_group('newsg')
640 self.assert_called('POST', '/servers/1234/action')
641 self.cs.servers.add_security_group(s, 'newsg')
642 self.assert_called('POST', '/servers/1234/action')
643
644 def test_remove_security_group(self):
645 s = self.cs.servers.get(1234)
646 s.remove_security_group('oldsg')
647 self.assert_called('POST', '/servers/1234/action')
648 self.cs.servers.remove_security_group(s, 'oldsg')
649 self.assert_called('POST', '/servers/1234/action')
650
651 def test_list_security_group(self):
652 s = self.cs.servers.get(1234)
653 s.list_security_group()
654 self.assert_called('GET', '/servers/1234/os-security-groups')
655
656 def test_evacuate(self):
657 s = self.cs.servers.get(1234)
658 s.evacuate('fake_target_host', 'True')
659 self.assert_called('POST', '/servers/1234/action')
660 self.cs.servers.evacuate(s, 'fake_target_host',
661 'False', 'NewAdminPassword')
662 self.assert_called('POST', '/servers/1234/action')
663
664 def test_interface_list(self):
665 s = self.cs.servers.get(1234)
666 s.interface_list()
667 self.assert_called('GET', '/servers/1234/os-interface')
668
669 def test_interface_list_result_string_representable(self):
670 """Test for bugs.launchpad.net/python-novaclient/+bug/1280453."""
671 # According to https://github.com/openstack/nova/blob/master/
672 # nova/api/openstack/compute/contrib/attach_interfaces.py#L33,
673 # the attach_interface extension get method will return a json
674 # object partly like this:
675 interface_list = [{
676 'net_id': 'd7745cf5-63f9-4883-b0ae-983f061e4f23',
677 'port_id': 'f35079da-36d5-4513-8ec1-0298d703f70e',
678 'mac_addr': 'fa:16:3e:4c:37:c8',
679 'port_state': 'ACTIVE',
680 'fixed_ips': [
681 {
682 'subnet_id': 'f1ad93ad-2967-46ba-b403-e8cbbe65f7fa',
683 'ip_address': '10.2.0.96'
684 }]
685 }]
686 # If server is not string representable, it will raise an exception,
687 # because attribute named 'name' cannot be found.
688 # Parameter 'loaded' must be True or it will try to get attribute
689 # 'id' then fails (lazy load detail), this is exactly same as
690 # novaclient.base.Manager._list()
691 s = servers.Server(servers.ServerManager, interface_list[0],
692 loaded=True)
693 # Trigger the __repr__ magic method
694 self.assertEqual('<Server: unknown-name>', '%r' % s)
695
696 def test_interface_attach(self):
697 s = self.cs.servers.get(1234)
698 s.interface_attach(None, None, None)
699 self.assert_called('POST', '/servers/1234/os-interface')
700
701 def test_interface_detach(self):
702 s = self.cs.servers.get(1234)
703 s.interface_detach('port-id')
704 self.assert_called('DELETE', '/servers/1234/os-interface/port-id')