cyclades.py 29.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Copyright 2012-2013 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
#   1. Redistributions of source code must retain the above
#      copyright notice, this list of conditions and the following
#      disclaimer.
#
#   2. Redistributions in binary form must reproduce the above
#      copyright notice, this list of conditions and the following
#      disclaimer in the documentation and/or other materials
#      provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.

34
import time
35

36
37
from kamaki.clients import livetest, ClientError
from kamaki.clients.cyclades import CycladesClient
38
from kamaki.clients.astakos import AstakosClient
39

40
41
42

class Cyclades(livetest.Generic):
    """Set up a Cyclades test"""
43
    def setUp(self):
44
        print
45
        with open(self['cmpimage', 'details']) as f:
46
47
48
49
50
51
52
53
54
55
56
            self.img_details = eval(f.read())
        self.img = self.img_details['id']
        with open(self['flavor', 'details']) as f:
            self._flavor_details = eval(f.read())
        self.PROFILES = ('ENABLED', 'DISABLED', 'PROTECTED')

        self.servers = {}
        self.now = time.mktime(time.gmtime())
        self.servname1 = 'serv' + unicode(self.now)
        self.servname2 = self.servname1 + '_v2'
        self.servname1 += '_v1'
57
        self.flavorid = self._flavor_details['id']
58
59
60
61
62
        #servers have to be created at the begining...
        self.networks = {}
        self.netname1 = 'net' + unicode(self.now)
        self.netname2 = 'net' + unicode(self.now) + '_v2'

63
64
        self.cloud = 'cloud.%s' % self['testcloud']
        aurl, self.token = self[self.cloud, 'url'], self[self.cloud, 'token']
65
66
67
        self.auth_base = AstakosClient(aurl, self.token)
        curl = self.auth_base.get_service_endpoints('compute')['publicURL']
        self.client = CycladesClient(curl, self.token)
68
69

    def tearDown(self):
70
71
72
73
74
75
76
77
78
79
        """Destoy servers used in testing"""
        for net in self.networks.keys():
            self._delete_network(net)
        for server in self.servers.values():
            self._delete_server(server['id'])
            print('DEL VM %s (%s)' % (server['id'], server['name']))

    def test_000(self):
        "Prepare a full Cyclades test scenario"
        self.server1 = self._create_server(
80
            self.servname1, self.flavorid, self.img)
81
        self.server2 = self._create_server(
82
            self.servname2, self.flavorid, self.img)
83
84
85
86
        super(self.__class__, self).test_000()

    def _create_server(self, servername, flavorid, imageid, personality=None):
        server = self.client.create_server(
87
            servername, flavorid, imageid, personality)
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
        print('CREATE VM %s (%s)' % (server['id'], server['name']))
        self.servers[servername] = server
        return server

    def _delete_server(self, servid):
        try:
            current_state = self.client.get_server_details(servid)
            current_state = current_state['status']
            if current_state == 'DELETED':
                return
            self.client.delete_server(servid)
            self._wait_for_status(servid, current_state)
            self.client.delete_server(servid)
        except:
            return

    def _create_network(self, netname, **kwargs):
        net = self.client.create_network(netname, **kwargs)
        self.networks[net['id']] = net
        return net

    def _delete_network(self, netid):
        if not netid in self.networks:
            return None
        print('Disconnect nics of network %s' % netid)
        self.client.disconnect_network_nics(netid)

        def netwait(wait):
            try:
                self.client.delete_network(netid)
            except ClientError:
                time.sleep(wait)
        self.do_with_progress_bar(
            netwait,
            'Delete network %s' % netid,
            self._waits[:7])
        return self.networks.pop(netid)

    def _wait_for_network(self, netid, status):

        def netwait(wait):
            r = self.client.get_network_details(netid)
            if r['status'] == status:
                return
            time.sleep(wait)
        self.do_with_progress_bar(
            netwait,
            'Wait network %s to reach status %s' % (netid, status),
            self._waits[:5])

    def _wait_for_nic(self, netid, servid, in_creation=True):
        self._wait_for_network(netid, 'ACTIVE')

        def nicwait(wait):
            nics = self.client.list_server_nics(servid)
            for net in nics:
                found_nic = net['network_id'] == netid
                if (in_creation and found_nic) or not (
                        in_creation or found_nic):
                    return
            time.sleep(wait)
        self.do_with_progress_bar(
            nicwait,
            'Wait nic-%s-%s to %sconnect' % (
                netid,
                servid,
                '' if in_creation else 'dis'),
            self._waits[:5])
        for net in self.client.list_server_nics(servid):
            if netid == net['network_id']:
                return True
        return False

    def _has_status(self, servid, status):
        r = self.client.get_server_details(servid)
163
        #print 'MY STATUS IS ', r['status']
164
165
166
167
168
169
170
        return r['status'] == status

    def _wait_for_status(self, servid, status):
        (wait_bar, wait_cb) = self._safe_progress_bar(
            'Server %s in %s' % (servid, status))
        self.client.wait_server(servid, status, wait_cb=wait_cb)
        self._safe_progress_bar_finish(wait_bar)
171

172
    def test_parallel_creation(self):
173
        """test create with multiple threads
174
        Do not use this in regular livetest
175
        """
176
        from kamaki.clients import SilentEvent
177
178
        c1 = SilentEvent(
            self._create_server,
179
180
181
            self.servname1,
            self.flavorid,
            self.img)
182
183
        c2 = SilentEvent(
            self._create_server,
184
            self.servname2,
185
            self.flavorid,
186
            self.img)
187
188
        c3 = SilentEvent(
            self._create_server,
189
190
191
            self.servname1,
            self.flavorid,
            self.img)
192
193
        c4 = SilentEvent(
            self._create_server,
194
            self.servname2,
195
            self.flavorid,
196
            self.img)
197
198
        c5 = SilentEvent(
            self._create_server,
199
200
201
            self.servname1,
            self.flavorid,
            self.img)
202
203
        c6 = SilentEvent(
            self._create_server,
204
            self.servname2,
205
            self.flavorid,
206
            self.img)
207
208
        c7 = SilentEvent(
            self._create_server,
209
210
211
            self.servname1,
            self.flavorid,
            self.img)
212
213
        c8 = SilentEvent(
            self._create_server,
214
            self.servname2,
215
            self.flavorid,
216
217
218
219
220
221
222
223
224
225
226
            self.img)
        c1.start()
        c2.start()
        c3.start()
        c4.start()
        c5.start()
        c6.start()
        c7.start()
        c8.start()

    def test_create_server(self):
227
        """Test create_server"""
228
229
        self.server1 = self._create_server(
            self.servname1,
230
231
232
233
234
235
236
            self.flavorid,
            self.img)
        self._wait_for_status(self.server1['id'], 'BUILD')
        self._test_0010_create_server()

    def _test_0010_create_server(self):
        self.assertEqual(self.server1["name"], self.servname1)
237
238
        self.assertEqual(self.server1["flavor"]["id"], self.flavorid)
        self.assertEqual(self.server1["image"]["id"], self.img)
239
240
        self.assertEqual(self.server1["status"], "BUILD")

241
    def test_list_servers(self):
242
        """Test list servers"""
243
244
245
246
247
248
        self.server1 = self._create_server(
            self.servname1,
            self.flavorid,
            self.img)
        self.server2 = self._create_server(
            self.servname2,
249
            self.flavorid,
250
            self.img)
251
        self._test_0020_list_servers()
252

253
    def _test_0020_list_servers(self):
254
255
256
        servers = self.client.list_servers()
        dservers = self.client.list_servers(detail=True)

257
        """detailed and simple are same size"""
258
259
        self.assertEqual(len(dservers), len(servers))
        for i in range(len(servers)):
260
            for field in (
261
                    'created',
262
                    'flavor',
263
                    'hostId',
264
                    'image',
265
266
267
                    'progress',
                    'status',
                    'updated'):
268
269
270
                self.assertFalse(field in servers[i])
                self.assertTrue(field in dservers[i])

271
        """detailed and simple contain same names"""
272
273
274
        names = sorted(map(lambda x: x["name"], servers))
        dnames = sorted(map(lambda x: x["name"], dservers))
        self.assertEqual(names, dnames)
275
276

    def _test_0030_wait_test_servers_to_build(self):
277
        """Pseudo-test to wait for VMs to load"""
278
        print('')
279
280
281
282
        self._wait_for_status(self.server1['id'], 'BUILD')
        self._wait_for_status(self.server2['id'], 'BUILD')

    def test_get_server_details(self):
283
        """Test get_server_details"""
284
285
        self.server1 = self._create_server(
            self.servname1,
286
287
288
289
290
291
292
293
            self.flavorid,
            self.img)
        self._wait_for_status(self.server1['id'], 'BUILD')
        self._test_0040_get_server_details()

    def _test_0040_get_server_details(self):
        r = self.client.get_server_details(self.server1['id'])
        self.assertEqual(r["name"], self.servname1)
294
295
        self.assertEqual(r["flavor"]["id"], self.flavorid)
        self.assertEqual(r["image"]["id"], self.img)
296
297
298
        self.assertEqual(r["status"], "ACTIVE")

    def test_update_server_name(self):
299
        """Test update_server_name"""
300
301
        self.server1 = self._create_server(
            self.servname1,
302
303
304
305
306
307
308
            self.flavorid,
            self.img)
        self._test_0050_update_server_name()

    def _test_0050_update_server_name(self):
        new_name = self.servname1 + '_new_name'
        self.client.update_server_name(self.server1['id'], new_name)
309
310
311
        r = self.client.get_server_details(
            self.server1['id'],
            success=(200, 400))
312
313
314
315
316
317
        self.assertEqual(r['name'], new_name)
        changed = self.servers.pop(self.servname1)
        changed['name'] = new_name
        self.servers[new_name] = changed

    def test_reboot_server(self):
318
        """Test reboot server"""
319
320
        self.server1 = self._create_server(
            self.servname1,
321
322
323
            self.flavorid,
            self.img)
        self._wait_for_status(self.server1['id'], 'BUILD')
324
325
        self.server2 = self._create_server(
            self.servname2,
326
327
328
329
330
331
332
333
334
335
336
337
338
            self.flavorid + 1,
            self.img)
        self._wait_for_status(self.server2['id'], 'BUILD')
        self._test_0060_reboot_server()
        self._wait_for_status(self.server1['id'], 'REBOOT')
        self._wait_for_status(self.server2['id'], 'REBOOT')

    def _test_0060_reboot_server(self):
        self.client.reboot_server(self.server1['id'])
        self.assertTrue(self._has_status(self.server1['id'], 'REBOOT'))
        self.client.reboot_server(self.server2['id'], hard=True)
        self.assertTrue(self._has_status(self.server2['id'], 'REBOOT'))

339
340
341
342
343
344
345
346
347
348
349
350
351
352
    def test_resize_server(self):
        """Modify the flavor of a server"""
        self.server1 = self._create_server(
            self.servname1, self.flavorid, self.img)
        self._test_0065_resize_server()
        self.delete_server(self.server1['id'])
        self.server1 = self._create_server(
            self.servname1, self.flavorid, self.img)

    def test_0065_resize_server(self):
        self.client.resize_server(self.servname1, self.flavorid + 1, self.img)
        srv = self.client.get_flavor_details(self.server1['id'])
        self.assertEqual(srv['flavor']['id'], self.flavorid + 1)

353
    def _test_0070_wait_test_servers_to_reboot(self):
354
        """Pseudo-test to wait for VMs to load"""
355
        print('')
356
357
358
359
        self._wait_for_status(self.server1['id'], 'REBOOT')
        self._wait_for_status(self.server2['id'], 'REBOOT')

    def test_create_server_metadata(self):
360
        """Test create_server_metadata"""
361
362
        self.server1 = self._create_server(
            self.servname1,
363
364
365
366
367
            self.flavorid,
            self.img)
        self._test_0080_create_server_metadata()

    def _test_0080_create_server_metadata(self):
368
369
        r1 = self.client.create_server_metadata(
            self.server1['id'],
370
371
372
373
            'mymeta',
            'mymeta val')
        self.assertTrue('mymeta' in r1)
        r2 = self.client.get_server_metadata(self.server1['id'], 'mymeta')
374
        self.assert_dicts_are_equal(r1, r2)
375
376

    def test_get_server_metadata(self):
377
        """Test get server_metadata"""
378
379
        self.server1 = self._create_server(
            self.servname1,
380
381
382
383
384
            self.flavorid,
            self.img)
        self._test_0090_get_server_metadata()

    def _test_0090_get_server_metadata(self):
385
386
        self.client.update_server_metadata(
            self.server1['id'], mymeta_0='val_0')
387
388
389
390
        r = self.client.get_server_metadata(self.server1['id'], 'mymeta_0')
        self.assertEqual(r['mymeta_0'], 'val_0')

    def test_update_server_metadata(self):
391
        """Test update_server_metadata"""
392
393
        self.server1 = self._create_server(
            self.servname1,
394
395
396
397
398
            self.flavorid,
            self.img)
        self._test_0100_update_server_metadata()

    def _test_0100_update_server_metadata(self):
399
400
        r1 = self.client.update_server_metadata(
            self.server1['id'], mymeta3='val2')
401
        self.assertTrue('mymeta3'in r1)
402
        r2 = self.client.update_server_metadata(
403
            self.server1['id'], mymeta3='val3')
404
405
406
        self.assertTrue(r2['mymeta3'], 'val3')

    def test_delete_server_metadata(self):
407
        """Test delete_server_metadata"""
408
        self.server1 = self._create_server(
409
            self.servname1, self.flavorid, self.img)
410
411
412
        self._test_0110_delete_server_metadata()

    def _test_0110_delete_server_metadata(self):
413
414
        r1 = self.client.update_server_metadata(
            self.server1['id'], mymeta='val')
415
416
417
418
419
420
421
422
423
        self.assertTrue('mymeta' in r1)
        self.client.delete_server_metadata(self.server1['id'], 'mymeta')
        try:
            self.client.get_server_metadata(self.server1['id'], 'mymeta')
            raise ClientError('Wrong Error', status=100)
        except ClientError as err:
            self.assertEqual(err.status, 404)

    def test_list_flavors(self):
424
        """Test flavors_get"""
425
426
427
428
429
430
431
432
433
        self._test_0120_list_flavors()

    def _test_0120_list_flavors(self):
        r = self.client.list_flavors()
        self.assertTrue(len(r) > 1)
        r = self.client.list_flavors(detail=True)
        self.assertTrue('SNF:disk_template' in r[0])

    def test_get_flavor_details(self):
434
        """Test test_get_flavor_details"""
435
436
437
438
        self._test_0130_get_flavor_details()

    def _test_0130_get_flavor_details(self):
        r = self.client.get_flavor_details(self.flavorid)
439
        self.assert_dicts_are_equal(self._flavor_details, r)
440

441
442
443
444
445
446
447
448
449
450
451
452
    def test_list_images(self):
        """Test list_images"""
        self._test_0140_list_images()

    def _test_0140_list_images(self):
        r = self.client.list_images()
        self.assertTrue(len(r) > 1)
        r = self.client.list_images(detail=True)
        for detailed_img in r:
            if detailed_img['id'] == self.img:
                break
        self.assert_dicts_are_equal(detailed_img, self.img_details)
453
454

    def test_get_image_details(self):
455
        """Test image_details"""
456
457
458
459
        self._test_0150_get_image_details()

    def _test_0150_get_image_details(self):
        r = self.client.get_image_details(self.img)
460
        self.assert_dicts_are_equal(r, self.img_details)
461
462

    def test_get_image_metadata(self):
463
        """Test get_image_metadata"""
464
465
466
467
        self._test_0160_get_image_metadata()

    def _test_0160_get_image_metadata(self):
        r = self.client.get_image_metadata(self.img)
468
        self.assert_dicts_are_equal(
469
470
            self.img_details['metadata'], r)
        for key, val in self.img_details['metadata'].items():
471
472
473
474
            r = self.client.get_image_metadata(self.img, key)
            self.assertEqual(r[key], val)

    def test_shutdown_server(self):
475
        """Test shutdown_server"""
476
477
        self.server1 = self._create_server(
            self.servname1,
478
479
480
481
482
483
484
485
486
487
488
489
            self.flavorid,
            self.img)
        self._wait_for_status(self.server1['id'], 'BUILD')
        self._test_0170_shutdown_server()

    def _test_0170_shutdown_server(self):
        self.client.shutdown_server(self.server1['id'])
        self._wait_for_status(self.server1['id'], 'ACTIVE')
        r = self.client.get_server_details(self.server1['id'])
        self.assertEqual(r['status'], 'STOPPED')

    def test_start_server(self):
490
        """Test start_server"""
491
492
        self.server1 = self._create_server(
            self.servname1,
493
494
495
496
497
498
499
500
501
502
503
504
            self.flavorid,
            self.img)
        self._wait_for_status(self.server1['id'], 'BUILD')
        self.client.shutdown_server(self.server1['id'])
        self._wait_for_status(self.server1['id'], 'ACTIVE')
        self._test_0180_start_server()

    def _test_0180_start_server(self):
        self.client.start_server(self.server1['id'])
        self._wait_for_status(self.server1['id'], 'STOPPED')
        r = self.client.get_server_details(self.server1['id'])
        self.assertEqual(r['status'], 'ACTIVE')
505
506

    def test_get_server_console(self):
507
        """Test get_server_console"""
508
509
        self.server2 = self._create_server(
            self.servname2,
510
            self.flavorid,
511
512
513
514
515
516
517
518
519
520
521
522
            self.img)
        self._wait_for_status(self.server2['id'], 'BUILD')
        self._test_0190_get_server_console()

    def _test_0190_get_server_console(self):
        r = self.client.get_server_console(self.server2['id'])
        self.assertTrue('host' in r)
        self.assertTrue('password' in r)
        self.assertTrue('port' in r)
        self.assertTrue('type' in r)

    def test_get_firewall_profile(self):
523
        """Test get_firewall_profile"""
524
525
        self.server1 = self._create_server(
            self.servname1,
526
527
528
529
530
531
532
533
534
535
            self.flavorid,
            self.img)
        self._test_0200_get_firewall_profile()

    def _test_0200_get_firewall_profile(self):
        self._wait_for_status(self.server1['id'], 'BUILD')
        fprofile = self.client.get_firewall_profile(self.server1['id'])
        self.assertTrue(fprofile in self.PROFILES)

    def test_set_firewall_profile(self):
536
        """Test set_firewall_profile"""
537
538
        self.server1 = self._create_server(
            self.servname1,
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
            self.flavorid,
            self.img)
        self._test_0210_set_firewall_profile()

    def _test_0210_set_firewall_profile(self):

        self._wait_for_status(self.server1['id'], 'BUILD')
        PROFILES = ['DISABLED', 'ENABLED', 'DISABLED', 'PROTECTED']
        fprofile = self.client.get_firewall_profile(self.server1['id'])
        print('')
        count_success = 0
        for counter, fprofile in enumerate(PROFILES):
            npos = counter + 1
            try:
                nprofile = PROFILES[npos]
            except IndexError:
                nprofile = PROFILES[0]
            print('\tprofile swap %s: %s -> %s' % (npos, fprofile, nprofile))
            self.client.set_firewall_profile(self.server1['id'], nprofile)
            time.sleep(0.5)
            self.client.reboot_server(self.server1['id'], hard=True)
            time.sleep(1)
            self._wait_for_status(self.server1['id'], 'REBOOT')
            time.sleep(0.5)
            changed = self.client.get_firewall_profile(self.server1['id'])
            try:
                self.assertEqual(changed, nprofile)
            except AssertionError as err:
                if count_success:
                    print('\tFAIL in swap #%s' % npos)
                    break
                else:
                    raise err
            count_success += 1

    def test_get_server_stats(self):
575
576
        self.server1 = self._create_server(
            self.servname1,
577
578
579
580
581
582
            self.flavorid,
            self.img)
        self._test_0220_get_server_stats()

    def _test_0220_get_server_stats(self):
        r = self.client.get_server_stats(self.server1['id'])
583
584
        it = ('cpuBar', 'cpuTimeSeries', 'netBar', 'netTimeSeries', 'refresh')
        for term in it:
585
586
587
            self.assertTrue(term in r)

    def test_create_network(self):
588
        """Test create_network"""
589
590
591
        self._test_0230_create_network()

    def _test_0230_create_network(self):
592
        print('\twith no params')
593
594
        self.network1 = self._create_network(self.netname1)
        self._wait_for_network(self.network1['id'], 'ACTIVE')
595
596
        n1id = self.network1['id']
        self.network1 = self.client.get_network_details(n1id)
597
        nets = self.client.list_networks(self.network1['id'])
598
        chosen = [net for net in nets if net['id'] == n1id][0]
599
600
601
        chosen.pop('updated')
        net1 = dict(self.network1)
        net1.pop('updated')
602
        self.assert_dicts_are_equal(chosen, net1)
603
604
605
        full_args = dict(
                cidr='192.168.1.0/24',
                gateway='192.168.1.1',
606
                type='MAC_FILTERED',
607
608
609
610
                dhcp=True)
        try_args = dict(all=True)
        try_args.update(full_args)
        for param, val in try_args.items():
611
612
            print('\tdelete %s to avoid max net limit' % n1id)
            self._delete_network(n1id)
613
            kwargs = full_args if param == 'all' else {param: val}
614
615
616
617
618
            print('\twith %s=%s' % (param, val))
            self.network1 = self._create_network(self.netname1, **kwargs)
            n1id = self.network1['id']
            self._wait_for_network(n1id, 'ACTIVE')
            self.network1 = self.client.get_network_details(n1id)
619
620
621
622
623
            if param == 'all':
                for p, v in full_args.items():
                    self.assertEqual(self.network1[p], v)
            else:
                self.assertEqual(self.network1[param], val)
624
625

    def test_connect_server(self):
626
        """Test connect_server"""
627
628
        self.server1 = self._create_server(
            self.servname1,
629
630
631
632
633
634
635
636
637
638
639
640
641
642
            self.flavorid,
            self.img)
        self.network1 = self._create_network(self.netname1)
        self._wait_for_status(self.server1['id'], 'BUILD')
        self._wait_for_network(self.network1['id'], 'ACTIVE')
        self._test_0240_connect_server()

    def _test_0250_connect_server(self):
        self.client.connect_server(self.server1['id'], self.network1['id'])
        self.assertTrue(self._wait_for_nic(
            self.network1['id'],
            self.server1['id']))

    def test_disconnect_server(self):
643
        """Test disconnect_server"""
644
645
646
647
648
        self.test_connect_server()
        self._test_0250_disconnect_server()

    def _test_0250_disconnect_server(self):
        self.client.disconnect_server(self.server1['id'], self.network1['id'])
649
650
        self.assertTrue(self._wait_for_nic(
            self.network1['id'],
651
652
653
654
655
656
657
658
            self.server1['id'],
            in_creation=False))

    def _test_0260_wait_for_second_network(self):
        self.network2 = self._create_network(self.netname2)
        self._wait_for_network(self.network2['id'], 'ACTIVE')

    def test_list_server_nics(self):
659
        """Test list_server_nics"""
660
661
        self.server1 = self._create_server(
            self.servname1,
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
            self.flavorid,
            self.img)
        self.network2 = self._create_network(self.netname2)
        self._wait_for_status(self.server1['id'], 'BUILD')
        self._wait_for_network(self.network2['id'], 'ACTIVE')
        self._test_0280_list_server_nics()

    def _test_0280_list_server_nics(self):
        r = self.client.list_server_nics(self.server1['id'])
        len0 = len(r)
        self.client.connect_server(self.server1['id'], self.network2['id'])
        self.assertTrue(self._wait_for_nic(
            self.network2['id'],
            self.server1['id']))
        r = self.client.list_server_nics(self.server1['id'])
        self.assertTrue(len(r) > len0)

    def test_list_networks(self):
680
        """Test list_network"""
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
        self.network1 = self._create_network(self.netname1)
        self._wait_for_network(self.network1['id'], 'ACTIVE')
        self._test_0290_list_networks()

    def _test_0290_list_networks(self):
        r = self.client.list_networks()
        self.assertTrue(len(r) > 1)
        ids = [net['id'] for net in r]
        names = [net['name'] for net in r]
        self.assertTrue('1' in ids)
        #self.assertTrue('public' in names)
        self.assertTrue(self.network1['id'] in ids)
        self.assertTrue(self.network1['name'] in names)

        r = self.client.list_networks(detail=True)
        ids = [net['id'] for net in r]
        names = [net['name'] for net in r]
        for net in r:
            self.assertTrue(net['id'] in ids)
            self.assertTrue(net['name'] in names)
            for term in ('status', 'updated', 'created'):
                self.assertTrue(term in net.keys())

704
705
706
707
708
709
710
711
712
713
714
    def test_list_network_nics(self):
        """Test list_server_nics"""
        self.server1 = self._create_server(
            self.servname1,
            self.flavorid,
            self.img)
        self.network1 = self._create_network(self.netname1)
        self.network2 = self._create_network(self.netname2)
        self._wait_for_status(self.server1['id'], 'BUILD')
        self._wait_for_network(self.network1['id'], 'ACTIVE')
        self._wait_for_network(self.network2['id'], 'ACTIVE')
715
        self.client.connect_server(self.server1['id'], self.network1['id'])
716
        self.client.connect_server(self.server1['id'], self.network2['id'])
717
        self._wait_for_nic(self.network1['id'], self.server1['id'])
718
719
720
721
722
723
724
        self._wait_for_nic(self.network2['id'], self.server1['id'])
        self._test_0293_list_network_nics()

    def _test_0293_list_network_nics(self):
        netid1 = self.network1['id']
        netid2 = self.network2['id']
        r = self.client.list_network_nics(netid1)
725
        expected = ['nic-%s-1' % self.server1['id']]
726
727
        self.assertEqual(r, expected)
        r = self.client.list_network_nics(netid2)
728
        expected = ['nic-%s-2' % self.server1['id']]
729
730
        self.assertEqual(r, expected)

731
    def test_get_network_details(self):
732
        """Test get_network_details"""
733
734
735
736
737
738
739
740
741
742
743
744
        self.network1 = self._create_network(self.netname1)
        self._test_0300_get_network_details()

    def _test_0300_get_network_details(self):
        r = self.client.get_network_details(self.network1['id'])
        net1 = dict(self.network1)
        net1.pop('status')
        net1.pop('updated', None)
        net1.pop('attachments')
        r.pop('status')
        r.pop('updated', None)
        r.pop('attachments')
745
        self.assert_dicts_are_equal(net1, r)
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767

    def test_update_network_name(self):
        self.network2 = self._create_network(self.netname2)
        self._test_0310_update_network_name()

    def _test_0310_update_network_name(self):
        updated_name = self.netname2 + '_upd'
        self.client.update_network_name(self.network2['id'], updated_name)

        def netwait(wait):
            r = self.client.get_network_details(self.network2['id'])
            if r['name'] == updated_name:
                return
            time.sleep(wait)
        self.do_with_progress_bar(
            netwait,
            'Network %s name is changing:' % self.network2['id'],
            self._waits[:5])

        r = self.client.get_network_details(self.network2['id'])
        self.assertEqual(r['name'], updated_name)

768
    """ Don't have auth to test this
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
    def test_delete_image(self):
        ""Test delete_image""
        self._test_0330_delete_image()
    def _test_0330_delete_image(self):
        images = self.client.list_images()
        self.client.delete_image(images[2]['id'])
        try:
            r = self.client.get_image_details(images[2]['id'], success=(400))
        except ClientError as err:
            self.assertEqual(err.status, 404)

    def test_create_image_metadata(self):
        ""Test create_image_metadata""
        self._test_0340_create_image_metadata()
    def _test_0340_create_image_metadata(self):
        r = self.client.create_image_metadata(self.img, 'mykey', 'myval')
        self.assertEqual(r['mykey'], 'myval')

    def test_update_image_metadata(self):
        ""Test update_image_metadata""
        self._test_0350_update_image_metadata()
    def _test_0350_update_image_metadata(self):
        r = self.client.create_image_metadata(self.img, 'mykey0', 'myval')
        r = self.client.update_image_metadata(self.img, 'mykey0', 'myval0')
        self.assertEqual(r['mykey0'], 'myval0')

    def test_delete_image_metadata(self):
        ""Test delete_image_metadata""
        self._test_0360_delete_image_metadata()
    def _test_0360_delete_image_metadata(self):
        self.client.create_image_metadata(self.img, 'mykey1', 'myval1')
        self.client.delete_image_metadata(self.img, 'mykey1')
        r = self.client.get_image_metadata(self.img)
        self.assertNotEqual('mykey1' in r)
    """