Statistics
| Branch: | Tag: | Revision:

root / kamaki / clients / tests / cyclades.py @ d1f78278

History | View | Annotate | Download (26.3 kB)

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

    
34
import time
35

    
36
from kamaki.clients import tests, ClientError
37
from kamaki.clients.cyclades import CycladesClient
38

    
39

    
40
class Cyclades(tests.Generic):
41
    """Set up a Cyclades thorough test"""
42
    def setUp(self):
43
        print
44
        with open(self['image', 'details']) as f:
45
            self.img_details = eval(f.read())
46
        self.img = self.img_details['id']
47
        with open(self['flavor', 'details']) as f:
48
            self._flavor_details = eval(f.read())
49
        self.PROFILES = ('ENABLED', 'DISABLED', 'PROTECTED')
50

    
51
        self.servers = {}
52
        self.now = time.mktime(time.gmtime())
53
        self.servname1 = 'serv' + unicode(self.now)
54
        self.servname2 = self.servname1 + '_v2'
55
        self.servname1 += '_v1'
56
        self.flavorid = 1
57
        #servers have to be created at the begining...
58
        self.networks = {}
59
        self.netname1 = 'net' + unicode(self.now)
60
        self.netname2 = 'net' + unicode(self.now) + '_v2'
61

    
62
        self.client = CycladesClient(self['compute', 'url'], self['token'])
63

    
64
    def tearDown(self):
65
        """Destoy servers used in testing"""
66
        for net in self.networks.keys():
67
            self._delete_network(net)
68
        #self.do_with_progress_bar(
69
        #    self._delete_network,
70
        #    'Delete %s networks' % len(self.networks),
71
        #    self.networks.keys())
72
        for server in self.servers.values():
73
            self._delete_server(server['id'])
74
            print('DEL VM %s (%s)' % (server['id'], server['name']))
75

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

    
86
    def _create_server(self, servername, flavorid, imageid, personality=None):
87
        server = self.client.create_server(servername,
88
            flavorid,
89
            imageid,
90
            personality)
91
        print('CREATE VM %s (%s)' % (server['id'], server['name']))
92
        self.servers[servername] = server
93
        return server
94

    
95
    def _delete_server(self, servid):
96
        try:
97
            current_state = self.client.get_server_details(servid)
98
            current_state = current_state['status']
99
            if current_state == 'DELETED':
100
                return
101
            self.client.delete_server(servid)
102
            self._wait_for_status(servid, current_state)
103
            self.client.delete_server(servid)
104
        except:
105
            return
106

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

    
112
    def _delete_network(self, netid):
113
        print('Disconnect nics of network %s' % netid)
114
        self.client.disconnect_network_nics(netid)
115

    
116
        def netwait(wait):
117
            try:
118
                self.client.delete_network(netid)
119
            except ClientError:
120
                time.sleep(wait)
121
        self.do_with_progress_bar(
122
            netwait,
123
            'Delete network %s' % netid,
124
            self._waits[:7])
125

    
126
    def _wait_for_network(self, netid, status):
127

    
128
        def netwait(wait):
129
            r = self.client.get_network_details(netid)
130
            if r['status'] == status:
131
                return
132
            time.sleep(wait)
133
        self.do_with_progress_bar(
134
            netwait,
135
            'Wait network %s to reach status %s' % (netid, status),
136
            self._waits[:5])
137

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

    
141
        def nicwait(wait):
142
            nics = self.client.list_server_nics(servid)
143
            for net in nics:
144
                found_nic = net['network_id'] == netid
145
                if (in_creation and found_nic)\
146
                or not (in_creation or found_nic):
147
                    return
148
            time.sleep(wait)
149
        self.do_with_progress_bar(
150
            nicwait,
151
            'Wait nic-%s-%s to %sconnect' % (
152
                netid,
153
                servid,
154
                '' if in_creation else 'dis'),
155
            self._waits[:5])
156
        return netid in [net['network_id']\
157
            for net in self.client.list_server_nics(servid)]
158

    
159
    def _has_status(self, servid, status):
160
        r = self.client.get_server_details(servid)
161
        return r['status'] == status
162

    
163
    def _wait_for_status(self, servid, status):
164
        (wait_bar, wait_cb) = self._safe_progress_bar(
165
            'Server %s in %s' % (servid, status))
166
        self.client.wait_server(servid, status, wait_cb=wait_cb)
167
        self._safe_progress_bar_finish(wait_bar)
168

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

    
215
    def test_create_server(self):
216
        """Test create_server"""
217
        self.server1 = self._create_server(self.servname1,
218
            self.flavorid,
219
            self.img)
220
        self._wait_for_status(self.server1['id'], 'BUILD')
221
        self._test_0010_create_server()
222

    
223
    def _test_0010_create_server(self):
224
        self.assertEqual(self.server1["name"], self.servname1)
225
        self.assertEqual(self.server1["flavorRef"], self.flavorid)
226
        self.assertEqual(self.server1["imageRef"], self.img)
227
        self.assertEqual(self.server1["status"], "BUILD")
228

    
229
    def test_list_servers(self):
230
        """Test list servers"""
231
        self.server1 = self._create_server(
232
            self.servname1,
233
            self.flavorid,
234
            self.img)
235
        self.server2 = self._create_server(
236
            self.servname2,
237
            self.flavorid + 2,
238
            self.img)
239
        self._test_0020_list_servers()
240

    
241
    def _test_0020_list_servers(self):
242
        servers = self.client.list_servers()
243
        dservers = self.client.list_servers(detail=True)
244

    
245
        """detailed and simple are same size"""
246
        self.assertEqual(len(dservers), len(servers))
247
        for i in range(len(servers)):
248
            for field in (
249
                'created',
250
                'flavorRef',
251
                'hostId',
252
                'imageRef',
253
                'progress',
254
                'status',
255
                'updated'):
256
                self.assertFalse(field in servers[i])
257
                self.assertTrue(field in dservers[i])
258

    
259
        """detailed and simple contain same names"""
260
        names = sorted(map(lambda x: x["name"], servers))
261
        dnames = sorted(map(lambda x: x["name"], dservers))
262
        self.assertEqual(names, dnames)
263

    
264
    def _test_0030_wait_test_servers_to_build(self):
265
        """Pseudo-test to wait for VMs to load"""
266
        print('')
267
        self._wait_for_status(self.server1['id'], 'BUILD')
268
        self._wait_for_status(self.server2['id'], 'BUILD')
269

    
270
    def test_get_server_details(self):
271
        """Test get_server_details"""
272
        self.server1 = self._create_server(self.servname1,
273
            self.flavorid,
274
            self.img)
275
        self._wait_for_status(self.server1['id'], 'BUILD')
276
        self._test_0040_get_server_details()
277

    
278
    def _test_0040_get_server_details(self):
279
        r = self.client.get_server_details(self.server1['id'])
280
        self.assertEqual(r["name"], self.servname1)
281
        self.assertEqual(r["flavorRef"], self.flavorid)
282
        self.assertEqual(r["imageRef"], self.img)
283
        self.assertEqual(r["status"], "ACTIVE")
284

    
285
    def test_update_server_name(self):
286
        """Test update_server_name"""
287
        self.server1 = self._create_server(self.servname1,
288
            self.flavorid,
289
            self.img)
290
        self._test_0050_update_server_name()
291

    
292
    def _test_0050_update_server_name(self):
293
        new_name = self.servname1 + '_new_name'
294
        self.client.update_server_name(self.server1['id'], new_name)
295
        r = self.client.get_server_details(self.server1['id'],
296
         success=(200, 400))
297
        self.assertEqual(r['name'], new_name)
298
        changed = self.servers.pop(self.servname1)
299
        changed['name'] = new_name
300
        self.servers[new_name] = changed
301

    
302
    def test_reboot_server(self):
303
        """Test reboot server"""
304
        self.server1 = self._create_server(self.servname1,
305
            self.flavorid,
306
            self.img)
307
        self._wait_for_status(self.server1['id'], 'BUILD')
308
        self.server2 = self._create_server(self.servname2,
309
            self.flavorid + 1,
310
            self.img)
311
        self._wait_for_status(self.server2['id'], 'BUILD')
312
        self._test_0060_reboot_server()
313
        self._wait_for_status(self.server1['id'], 'REBOOT')
314
        self._wait_for_status(self.server2['id'], 'REBOOT')
315

    
316
    def _test_0060_reboot_server(self):
317
        self.client.reboot_server(self.server1['id'])
318
        self.assertTrue(self._has_status(self.server1['id'], 'REBOOT'))
319
        self.client.reboot_server(self.server2['id'], hard=True)
320
        self.assertTrue(self._has_status(self.server2['id'], 'REBOOT'))
321

    
322
    def _test_0070_wait_test_servers_to_reboot(self):
323
        """Pseudo-test to wait for VMs to load"""
324
        print('')
325
        self._wait_for_status(self.server1['id'], 'REBOOT')
326
        self._wait_for_status(self.server2['id'], 'REBOOT')
327

    
328
    def test_create_server_metadata(self):
329
        """Test create_server_metadata"""
330
        self.server1 = self._create_server(self.servname1,
331
            self.flavorid,
332
            self.img)
333
        self._test_0080_create_server_metadata()
334

    
335
    def _test_0080_create_server_metadata(self):
336
        r1 = self.client.create_server_metadata(self.server1['id'],
337
            'mymeta',
338
            'mymeta val')
339
        self.assertTrue('mymeta' in r1)
340
        r2 = self.client.get_server_metadata(self.server1['id'], 'mymeta')
341
        self.assert_dicts_are_deeply_equal(r1, r2)
342

    
343
    def test_get_server_metadata(self):
344
        """Test get server_metadata"""
345
        self.server1 = self._create_server(self.servname1,
346
            self.flavorid,
347
            self.img)
348
        self._test_0090_get_server_metadata()
349

    
350
    def _test_0090_get_server_metadata(self):
351
        self.client.create_server_metadata(self.server1['id'],
352
            'mymeta_0',
353
            'val_0')
354
        r = self.client.get_server_metadata(self.server1['id'], 'mymeta_0')
355
        self.assertEqual(r['mymeta_0'], 'val_0')
356

    
357
    def test_update_server_metadata(self):
358
        """Test update_server_metadata"""
359
        self.server1 = self._create_server(self.servname1,
360
            self.flavorid,
361
            self.img)
362
        self._test_0100_update_server_metadata()
363

    
364
    def _test_0100_update_server_metadata(self):
365
        r1 = self.client.create_server_metadata(self.server1['id'],
366
            'mymeta3',
367
            'val2')
368
        self.assertTrue('mymeta3'in r1)
369
        r2 = self.client.update_server_metadata(self.server1['id'],
370
            mymeta3='val3')
371
        self.assertTrue(r2['mymeta3'], 'val3')
372

    
373
    def test_delete_server_metadata(self):
374
        """Test delete_server_metadata"""
375
        self.server1 = self._create_server(self.servname1,
376
            self.flavorid,
377
            self.img)
378
        self._test_0110_delete_server_metadata()
379

    
380
    def _test_0110_delete_server_metadata(self):
381
        r1 = self.client.create_server_metadata(self.server1['id'],
382
            'mymeta',
383
            'val')
384
        self.assertTrue('mymeta' in r1)
385
        self.client.delete_server_metadata(self.server1['id'], 'mymeta')
386
        try:
387
            self.client.get_server_metadata(self.server1['id'], 'mymeta')
388
            raise ClientError('Wrong Error', status=100)
389
        except ClientError as err:
390
            self.assertEqual(err.status, 404)
391

    
392
    def test_list_flavors(self):
393
        """Test flavors_get"""
394
        self._test_0120_list_flavors()
395

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

    
402
    def test_get_flavor_details(self):
403
        """Test test_get_flavor_details"""
404
        self._test_0130_get_flavor_details()
405

    
406
    def _test_0130_get_flavor_details(self):
407
        r = self.client.get_flavor_details(self.flavorid)
408
        self.assert_dicts_are_deeply_equal(self._flavor_details, r)
409

    
410
    def test_list_images(self):
411
        """Test list_images"""
412
        self._test_0140_list_images()
413

    
414
    def _test_0140_list_images(self):
415
        r = self.client.list_images()
416
        self.assertTrue(len(r) > 1)
417
        r = self.client.list_images(detail=True)
418
        for detailed_img in r:
419
            if detailed_img['id'] == self.img:
420
                break
421
        self.assert_dicts_are_deeply_equal(detailed_img, self.img_details)
422

    
423
    def test_get_image_details(self):
424
        """Test image_details"""
425
        self._test_0150_get_image_details()
426

    
427
    def _test_0150_get_image_details(self):
428
        r = self.client.get_image_details(self.img)
429
        r.pop('updated')
430
        self.assert_dicts_are_deeply_equal(r, self.img_details)
431

    
432
    def test_get_image_metadata(self):
433
        """Test get_image_metadata"""
434
        self._test_0160_get_image_metadata()
435

    
436
    def _test_0160_get_image_metadata(self):
437
        r = self.client.get_image_metadata(self.img)
438
        self.assert_dicts_are_deeply_equal(
439
            self.img_details['metadata']['values'], r)
440
        for key, val in self.img_details['metadata']['values'].items():
441
            r = self.client.get_image_metadata(self.img, key)
442
            self.assertEqual(r[key], val)
443

    
444
    def test_shutdown_server(self):
445
        """Test shutdown_server"""
446
        self.server1 = self._create_server(self.servname1,
447
            self.flavorid,
448
            self.img)
449
        self._wait_for_status(self.server1['id'], 'BUILD')
450
        self._test_0170_shutdown_server()
451

    
452
    def _test_0170_shutdown_server(self):
453
        self.client.shutdown_server(self.server1['id'])
454
        self._wait_for_status(self.server1['id'], 'ACTIVE')
455
        r = self.client.get_server_details(self.server1['id'])
456
        self.assertEqual(r['status'], 'STOPPED')
457

    
458
    def test_start_server(self):
459
        """Test start_server"""
460
        self.server1 = self._create_server(self.servname1,
461
            self.flavorid,
462
            self.img)
463
        self._wait_for_status(self.server1['id'], 'BUILD')
464
        self.client.shutdown_server(self.server1['id'])
465
        self._wait_for_status(self.server1['id'], 'ACTIVE')
466
        self._test_0180_start_server()
467

    
468
    def _test_0180_start_server(self):
469
        self.client.start_server(self.server1['id'])
470
        self._wait_for_status(self.server1['id'], 'STOPPED')
471
        r = self.client.get_server_details(self.server1['id'])
472
        self.assertEqual(r['status'], 'ACTIVE')
473

    
474
    def test_get_server_console(self):
475
        """Test get_server_console"""
476
        self.server2 = self._create_server(self.servname2,
477
            self.flavorid + 2,
478
            self.img)
479
        self._wait_for_status(self.server2['id'], 'BUILD')
480
        self._test_0190_get_server_console()
481

    
482
    def _test_0190_get_server_console(self):
483
        r = self.client.get_server_console(self.server2['id'])
484
        self.assertTrue('host' in r)
485
        self.assertTrue('password' in r)
486
        self.assertTrue('port' in r)
487
        self.assertTrue('type' in r)
488

    
489
    def test_get_firewall_profile(self):
490
        """Test get_firewall_profile"""
491
        self.server1 = self._create_server(self.servname1,
492
            self.flavorid,
493
            self.img)
494
        self._test_0200_get_firewall_profile()
495

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

    
501
    def test_set_firewall_profile(self):
502
        """Test set_firewall_profile"""
503
        self.server1 = self._create_server(self.servname1,
504
            self.flavorid,
505
            self.img)
506
        self._test_0210_set_firewall_profile()
507

    
508
    def _test_0210_set_firewall_profile(self):
509

    
510
        self._wait_for_status(self.server1['id'], 'BUILD')
511
        PROFILES = ['DISABLED', 'ENABLED', 'DISABLED', 'PROTECTED']
512
        fprofile = self.client.get_firewall_profile(self.server1['id'])
513
        print('')
514
        count_success = 0
515
        for counter, fprofile in enumerate(PROFILES):
516
            npos = counter + 1
517
            try:
518
                nprofile = PROFILES[npos]
519
            except IndexError:
520
                nprofile = PROFILES[0]
521
            print('\tprofile swap %s: %s -> %s' % (npos, fprofile, nprofile))
522
            self.client.set_firewall_profile(self.server1['id'], nprofile)
523
            time.sleep(0.5)
524
            self.client.reboot_server(self.server1['id'], hard=True)
525
            time.sleep(1)
526
            self._wait_for_status(self.server1['id'], 'REBOOT')
527
            time.sleep(0.5)
528
            changed = self.client.get_firewall_profile(self.server1['id'])
529
            try:
530
                self.assertEqual(changed, nprofile)
531
            except AssertionError as err:
532
                if count_success:
533
                    print('\tFAIL in swap #%s' % npos)
534
                    break
535
                else:
536
                    raise err
537
            count_success += 1
538

    
539
    def test_get_server_stats(self):
540
        self.server1 = self._create_server(self.servname1,
541
            self.flavorid,
542
            self.img)
543
        self._test_0220_get_server_stats()
544

    
545
    def _test_0220_get_server_stats(self):
546
        r = self.client.get_server_stats(self.server1['id'])
547
        for term in ('cpuBar',
548
        'cpuTimeSeries',
549
        'netBar',
550
        'netTimeSeries',
551
        'refresh'):
552
            self.assertTrue(term in r)
553

    
554
    def test_create_network(self):
555
        """Test create_network"""
556
        self._test_0230_create_network()
557

    
558
    def _test_0230_create_network(self):
559
        self.network1 = self._create_network(self.netname1)
560
        self._wait_for_network(self.network1['id'], 'ACTIVE')
561
        self.network1 = self.client.get_network_details(self.network1['id'])
562
        nets = self.client.list_networks(self.network1['id'])
563
        chosen = [net for net in nets if net['id'] == self.network1['id']][0]
564
        chosen.pop('updated')
565
        net1 = dict(self.network1)
566
        net1.pop('updated')
567
        self.assert_dicts_are_deeply_equal(chosen, net1)
568

    
569
    def test_connect_server(self):
570
        """Test connect_server"""
571
        self.server1 = self._create_server(self.servname1,
572
            self.flavorid,
573
            self.img)
574
        self.network1 = self._create_network(self.netname1)
575
        self._wait_for_status(self.server1['id'], 'BUILD')
576
        self._wait_for_network(self.network1['id'], 'ACTIVE')
577
        self._test_0240_connect_server()
578

    
579
    def _test_0250_connect_server(self):
580
        self.client.connect_server(self.server1['id'], self.network1['id'])
581
        self.assertTrue(self._wait_for_nic(
582
            self.network1['id'],
583
            self.server1['id']))
584

    
585
    def test_disconnect_server(self):
586
        """Test disconnect_server"""
587
        self.test_connect_server()
588
        self._test_0250_disconnect_server()
589

    
590
    def _test_0250_disconnect_server(self):
591
        self.client.disconnect_server(self.server1['id'], self.network1['id'])
592
        self.assertTrue(self._wait_for_nic(self.network1['id'],
593
            self.server1['id'],
594
            in_creation=False))
595

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

    
600
    def test_list_server_nics(self):
601
        """Test list_server_nics"""
602
        self.server1 = self._create_server(self.servname1,
603
            self.flavorid,
604
            self.img)
605
        self.network2 = self._create_network(self.netname2)
606
        self._wait_for_status(self.server1['id'], 'BUILD')
607
        self._wait_for_network(self.network2['id'], 'ACTIVE')
608
        self._test_0280_list_server_nics()
609

    
610
    def _test_0280_list_server_nics(self):
611
        r = self.client.list_server_nics(self.server1['id'])
612
        len0 = len(r)
613
        self.client.connect_server(self.server1['id'], self.network2['id'])
614
        self.assertTrue(self._wait_for_nic(
615
            self.network2['id'],
616
            self.server1['id']))
617
        r = self.client.list_server_nics(self.server1['id'])
618
        self.assertTrue(len(r) > len0)
619

    
620
    def test_list_networks(self):
621
        """Test list_network"""
622
        self.network1 = self._create_network(self.netname1)
623
        self._wait_for_network(self.network1['id'], 'ACTIVE')
624
        self._test_0290_list_networks()
625

    
626
    def _test_0290_list_networks(self):
627
        r = self.client.list_networks()
628
        self.assertTrue(len(r) > 1)
629
        ids = [net['id'] for net in r]
630
        names = [net['name'] for net in r]
631
        self.assertTrue('1' in ids)
632
        #self.assertTrue('public' in names)
633
        self.assertTrue(self.network1['id'] in ids)
634
        self.assertTrue(self.network1['name'] in names)
635

    
636
        r = self.client.list_networks(detail=True)
637
        ids = [net['id'] for net in r]
638
        names = [net['name'] for net in r]
639
        for net in r:
640
            self.assertTrue(net['id'] in ids)
641
            self.assertTrue(net['name'] in names)
642
            for term in ('status', 'updated', 'created'):
643
                self.assertTrue(term in net.keys())
644

    
645
    def test_get_network_details(self):
646
        """Test get_network_details"""
647
        self.network1 = self._create_network(self.netname1)
648
        self._test_0300_get_network_details()
649

    
650
    def _test_0300_get_network_details(self):
651
        r = self.client.get_network_details(self.network1['id'])
652
        net1 = dict(self.network1)
653
        net1.pop('status')
654
        net1.pop('updated', None)
655
        net1.pop('attachments')
656
        r.pop('status')
657
        r.pop('updated', None)
658
        r.pop('attachments')
659
        self.assert_dicts_are_deeply_equal(net1, r)
660

    
661
    def test_update_network_name(self):
662
        self.network2 = self._create_network(self.netname2)
663
        self._test_0310_update_network_name()
664

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

    
669
        def netwait(wait):
670
            r = self.client.get_network_details(self.network2['id'])
671
            if r['name'] == updated_name:
672
                return
673
            time.sleep(wait)
674
        self.do_with_progress_bar(
675
            netwait,
676
            'Network %s name is changing:' % self.network2['id'],
677
            self._waits[:5])
678

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

    
682
    """ Don't have auth to test this
683
    def test_delete_image(self):
684
        ""Test delete_image""
685
        self._test_0330_delete_image()
686
    def _test_0330_delete_image(self):
687
        images = self.client.list_images()
688
        self.client.delete_image(images[2]['id'])
689
        try:
690
            r = self.client.get_image_details(images[2]['id'], success=(400))
691
        except ClientError as err:
692
            self.assertEqual(err.status, 404)
693

694
    def test_create_image_metadata(self):
695
        ""Test create_image_metadata""
696
        self._test_0340_create_image_metadata()
697
    def _test_0340_create_image_metadata(self):
698
        r = self.client.create_image_metadata(self.img, 'mykey', 'myval')
699
        self.assertEqual(r['mykey'], 'myval')
700

701
    def test_update_image_metadata(self):
702
        ""Test update_image_metadata""
703
        self._test_0350_update_image_metadata()
704
    def _test_0350_update_image_metadata(self):
705
        r = self.client.create_image_metadata(self.img, 'mykey0', 'myval')
706
        r = self.client.update_image_metadata(self.img, 'mykey0', 'myval0')
707
        self.assertEqual(r['mykey0'], 'myval0')
708

709
    def test_delete_image_metadata(self):
710
        ""Test delete_image_metadata""
711
        self._test_0360_delete_image_metadata()
712
    def _test_0360_delete_image_metadata(self):
713
        self.client.create_image_metadata(self.img, 'mykey1', 'myval1')
714
        self.client.delete_image_metadata(self.img, 'mykey1')
715
        r = self.client.get_image_metadata(self.img)
716
        self.assertNotEqual('mykey1' in r)
717
    """