~ubuntu-branches/ubuntu/utopic/python-quantumclient/utopic

« back to all changes in this revision

Viewing changes to quantumclient/tests/unit/test_cli.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-08-16 12:45:43 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120816124543-5m96n37eik89sr2j
Tags: 1:2.0-0ubuntu1
* New upstream version.
* debian/control: Update build dependencies.
* debian/rules: Enable testsuite.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
 
 
3
 
# Copyright 2010-2011 ????
4
 
# All Rights Reserved.
5
 
#
6
 
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
7
 
#    not use this file except in compliance with the License. You may obtain
8
 
#    a copy of the License at
9
 
#
10
 
#         http://www.apache.org/licenses/LICENSE-2.0
11
 
#
12
 
#    Unless required by applicable law or agreed to in writing, software
13
 
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
 
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
 
#    License for the specific language governing permissions and limitations
16
 
#    under the License.
17
 
#    @author: Salvatore Orlando, Citrix Systems
18
 
 
19
 
""" Module containing unit tests for Quantum
20
 
    command line interface
21
 
 
22
 
"""
23
 
 
24
 
import logging
25
 
import sys
26
 
import unittest
27
 
 
28
 
from quantum import api as server
29
 
from quantumclient import ClientV11
30
 
from quantumclient import cli_lib as cli
31
 
from quantum.db import api as db
32
 
from quantum.openstack.common import cfg
33
 
from quantumclient.tests.unit import stubs as client_stubs
34
 
 
35
 
LOG = logging.getLogger('quantumclient.tests.test_cli')
36
 
API_VERSION = "1.1"
37
 
FORMAT = 'json'
38
 
 
39
 
 
40
 
class CLITest(unittest.TestCase):
41
 
 
42
 
    def setUp(self):
43
 
        """Prepare the test environment"""
44
 
        #TODO: make the version of the API router configurable
45
 
        cfg.CONF.core_plugin = 'quantum.plugins.sample.SamplePlugin.FakePlugin'
46
 
        self.api = server.APIRouterV11()
47
 
 
48
 
        self.tenant_id = "test_tenant"
49
 
        self.network_name_1 = "test_network_1"
50
 
        self.network_name_2 = "test_network_2"
51
 
        self.version = API_VERSION
52
 
        # Prepare client and plugin manager
53
 
        self.client = ClientV11(tenant=self.tenant_id,
54
 
                                format=FORMAT,
55
 
                                testingStub=client_stubs.FakeHTTPConnection,
56
 
                                version=self.version)
57
 
        # Redirect stdout
58
 
        self.fake_stdout = client_stubs.FakeStdout()
59
 
        sys.stdout = self.fake_stdout
60
 
 
61
 
    def tearDown(self):
62
 
        """Clear the test environment"""
63
 
        db.clear_db()
64
 
        sys.stdout = sys.__stdout__
65
 
 
66
 
    def _verify_list_networks(self):
67
 
            # Verification - get raw result from db
68
 
            nw_list = db.network_list(self.tenant_id)
69
 
            networks = [{'id': nw.uuid, 'name': nw.name}
70
 
                        for nw in nw_list]
71
 
            # Fill CLI template
72
 
            output = cli.prepare_output('list_nets',
73
 
                                        self.tenant_id,
74
 
                                        dict(networks=networks),
75
 
                                        self.version)
76
 
            # Verify!
77
 
            # Must add newline at the end to match effect of print call
78
 
            self.assertEquals(self.fake_stdout.make_string(), output + '\n')
79
 
 
80
 
    def _verify_list_networks_details(self):
81
 
            # Verification - get raw result from db
82
 
            nw_list = db.network_list(self.tenant_id)
83
 
            networks = [dict(id=nw.uuid, name=nw.name) for nw in nw_list]
84
 
            # Fill CLI template
85
 
            output = cli.prepare_output('list_nets_detail',
86
 
                                        self.tenant_id,
87
 
                                        dict(networks=networks),
88
 
                                        self.version)
89
 
            # Verify!
90
 
            # Must add newline at the end to match effect of print call
91
 
            self.assertEquals(self.fake_stdout.make_string(), output + '\n')
92
 
 
93
 
    def _verify_list_networks_details_name_filter(self, name):
94
 
            # Verification - get raw result from db
95
 
            nw_list = db.network_list(self.tenant_id)
96
 
            nw_filtered = []
97
 
            for nw in nw_list:
98
 
                if nw.name == name:
99
 
                    nw_filtered.append(nw)
100
 
            networks = [dict(id=nw.uuid, name=nw.name) for nw in nw_filtered]
101
 
            # Fill CLI template
102
 
            output = cli.prepare_output('list_nets_detail',
103
 
                                        self.tenant_id,
104
 
                                        dict(networks=networks),
105
 
                                        self.version)
106
 
            # Verify!
107
 
            # Must add newline at the end to match effect of print call
108
 
            self.assertEquals(self.fake_stdout.make_string(), output + '\n')
109
 
 
110
 
    def _verify_create_network(self):
111
 
            # Verification - get raw result from db
112
 
            nw_list = db.network_list(self.tenant_id)
113
 
            if len(nw_list) != 1:
114
 
                self.fail("No network created")
115
 
            network_id = nw_list[0].uuid
116
 
            # Fill CLI template
117
 
            output = cli.prepare_output('create_net',
118
 
                                        self.tenant_id,
119
 
                                        dict(network_id=network_id),
120
 
                                        self.version)
121
 
            # Verify!
122
 
            # Must add newline at the end to match effect of print call
123
 
            self.assertEquals(self.fake_stdout.make_string(), output + '\n')
124
 
 
125
 
    def _verify_delete_network(self, network_id):
126
 
            # Verification - get raw result from db
127
 
            nw_list = db.network_list(self.tenant_id)
128
 
            if len(nw_list) != 0:
129
 
                self.fail("DB should not contain any network")
130
 
            # Fill CLI template
131
 
            output = cli.prepare_output('delete_net',
132
 
                                        self.tenant_id,
133
 
                                        dict(network_id=network_id),
134
 
                                        self.version)
135
 
            # Verify!
136
 
            # Must add newline at the end to match effect of print call
137
 
            self.assertEquals(self.fake_stdout.make_string(), output + '\n')
138
 
 
139
 
    def _verify_update_network(self):
140
 
            # Verification - get raw result from db
141
 
            nw_list = db.network_list(self.tenant_id)
142
 
            network_data = {'id': nw_list[0].uuid,
143
 
                            'name': nw_list[0].name,
144
 
                            'op-status': nw_list[0].op_status}
145
 
            # Fill CLI template
146
 
            output = cli.prepare_output('update_net',
147
 
                                        self.tenant_id,
148
 
                                        dict(network=network_data),
149
 
                                        self.version)
150
 
            # Verify!
151
 
            # Must add newline at the end to match effect of print call
152
 
            self.assertEquals(self.fake_stdout.make_string(), output + '\n')
153
 
 
154
 
    def _verify_show_network(self):
155
 
            # Verification - get raw result from db
156
 
            nw = db.network_list(self.tenant_id)[0]
157
 
            network = {'id': nw.uuid,
158
 
                       'name': nw.name,
159
 
                       'op-status': nw.op_status}
160
 
            # Fill CLI template
161
 
            output = cli.prepare_output('show_net',
162
 
                                        self.tenant_id,
163
 
                                        dict(network=network),
164
 
                                        self.version)
165
 
            # Verify!
166
 
            # Must add newline at the end to match effect of print call
167
 
            self.assertEquals(self.fake_stdout.make_string(), output + '\n')
168
 
 
169
 
    def _verify_show_network_details(self):
170
 
            # Verification - get raw result from db
171
 
            nw = db.network_list(self.tenant_id)[0]
172
 
            network = {'id': nw.uuid,
173
 
                       'name': nw.name,
174
 
                       'op-status': nw.op_status}
175
 
            port_list = db.port_list(nw.uuid)
176
 
            if not port_list:
177
 
                network['ports'] = [
178
 
                    {'id': '<none>',
179
 
                     'state': '<none>',
180
 
                     'attachment': {
181
 
                     'id': '<none>', }, }, ]
182
 
            else:
183
 
                network['ports'] = []
184
 
                for port in port_list:
185
 
                    network['ports'].append({
186
 
                        'id': port.uuid,
187
 
                        'state': port.state,
188
 
                        'attachment': {
189
 
                            'id': port.interface_id or '<none>', }, })
190
 
 
191
 
            # Fill CLI template
192
 
            output = cli.prepare_output('show_net_detail',
193
 
                                        self.tenant_id,
194
 
                                        dict(network=network),
195
 
                                        self.version)
196
 
            # Verify!
197
 
            # Must add newline at the end to match effect of print call
198
 
            self.assertEquals(self.fake_stdout.make_string(), output + '\n')
199
 
 
200
 
    def _verify_list_ports(self, network_id):
201
 
            # Verification - get raw result from db
202
 
            port_list = db.port_list(network_id)
203
 
            ports = [dict(id=port.uuid, state=port.state)
204
 
                     for port in port_list]
205
 
            # Fill CLI template
206
 
            output = cli.prepare_output('list_ports',
207
 
                                        self.tenant_id,
208
 
                                        dict(network_id=network_id,
209
 
                                             ports=ports),
210
 
                                        self.version)
211
 
            # Verify!
212
 
            # Must add newline at the end to match effect of print call
213
 
            self.assertEquals(self.fake_stdout.make_string(), output + '\n')
214
 
 
215
 
    def _verify_list_ports_details(self, network_id):
216
 
            # Verification - get raw result from db
217
 
            port_list = db.port_list(network_id)
218
 
            ports = [dict(id=port.uuid, state=port.state)
219
 
                     for port in port_list]
220
 
            # Fill CLI template
221
 
            output = cli.prepare_output('list_ports_detail',
222
 
                                        self.tenant_id,
223
 
                                        dict(network_id=network_id,
224
 
                                             ports=ports),
225
 
                                        self.version)
226
 
            # Verify!
227
 
            # Must add newline at the end to match effect of print call
228
 
            self.assertEquals(self.fake_stdout.make_string(), output + '\n')
229
 
 
230
 
    def _verify_create_port(self, network_id):
231
 
            # Verification - get raw result from db
232
 
            port_list = db.port_list(network_id)
233
 
            if len(port_list) != 1:
234
 
                self.fail("No port created")
235
 
            port_id = port_list[0].uuid
236
 
            # Fill CLI template
237
 
            output = cli.prepare_output('create_port',
238
 
                                        self.tenant_id,
239
 
                                        dict(network_id=network_id,
240
 
                                             port_id=port_id),
241
 
                                        self.version)
242
 
            # Verify!
243
 
            # Must add newline at the end to match effect of print call
244
 
            self.assertEquals(self.fake_stdout.make_string(), output + '\n')
245
 
 
246
 
    def _verify_delete_port(self, network_id, port_id):
247
 
            # Verification - get raw result from db
248
 
            port_list = db.port_list(network_id)
249
 
            if len(port_list) != 0:
250
 
                self.fail("DB should not contain any port")
251
 
            # Fill CLI template
252
 
            output = cli.prepare_output('delete_port',
253
 
                                        self.tenant_id,
254
 
                                        dict(network_id=network_id,
255
 
                                             port_id=port_id),
256
 
                                        self.version)
257
 
            # Verify!
258
 
            # Must add newline at the end to match effect of print call
259
 
            self.assertEquals(self.fake_stdout.make_string(), output + '\n')
260
 
 
261
 
    def _verify_update_port(self, network_id, port_id):
262
 
            # Verification - get raw result from db
263
 
            port = db.port_get(port_id, network_id)
264
 
            port_data = {'id': port.uuid,
265
 
                         'state': port.state,
266
 
                         'op-status': port.op_status}
267
 
            # Fill CLI template
268
 
            output = cli.prepare_output('update_port',
269
 
                                        self.tenant_id,
270
 
                                        dict(network_id=network_id,
271
 
                                             port=port_data),
272
 
                                        self.version)
273
 
            # Verify!
274
 
            # Must add newline at the end to match effect of print call
275
 
            self.assertEquals(self.fake_stdout.make_string(), output + '\n')
276
 
 
277
 
    def _verify_show_port(self, network_id, port_id):
278
 
            # Verification - get raw result from db
279
 
            port = db.port_get(port_id, network_id)
280
 
            port_data = {'id': port.uuid,
281
 
                         'state': port.state,
282
 
                         'attachment': {'id': port.interface_id or '<none>'},
283
 
                         'op-status': port.op_status}
284
 
 
285
 
            # Fill CLI template
286
 
            output = cli.prepare_output('show_port',
287
 
                                        self.tenant_id,
288
 
                                        dict(network_id=network_id,
289
 
                                             port=port_data),
290
 
                                        self.version)
291
 
            # Verify!
292
 
            # Must add newline at the end to match effect of print call
293
 
            self.assertEquals(self.fake_stdout.make_string(), output + '\n')
294
 
 
295
 
    def _verify_show_port_details(self, network_id, port_id):
296
 
            # Verification - get raw result from db
297
 
            # TODO(salvatore-orlando): Must resolve this issue with
298
 
            # attachment in separate bug fix.
299
 
            port = db.port_get(port_id, network_id)
300
 
            port_data = {'id': port.uuid,
301
 
                         'state': port.state,
302
 
                         'attachment': {'id': port.interface_id or '<none>'},
303
 
                         'op-status': port.op_status}
304
 
 
305
 
            # Fill CLI template
306
 
            output = cli.prepare_output('show_port_detail',
307
 
                                        self.tenant_id,
308
 
                                        dict(network_id=network_id,
309
 
                                             port=port_data),
310
 
                                        self.version)
311
 
            # Verify!
312
 
            # Must add newline at the end to match effect of print call
313
 
            self.assertEquals(self.fake_stdout.make_string(), output + '\n')
314
 
 
315
 
    def _verify_plug_iface(self, network_id, port_id):
316
 
            # Verification - get raw result from db
317
 
            port = db.port_get(port_id, network_id)
318
 
            # Fill CLI template
319
 
            output = cli.prepare_output("plug_iface",
320
 
                                        self.tenant_id,
321
 
                                        dict(network_id=network_id,
322
 
                                             port_id=port['uuid'],
323
 
                                             attachment=port['interface_id']),
324
 
                                        self.version)
325
 
            # Verify!
326
 
            # Must add newline at the end to match effect of print call
327
 
            self.assertEquals(self.fake_stdout.make_string(), output + '\n')
328
 
 
329
 
    def _verify_unplug_iface(self, network_id, port_id):
330
 
            # Verification - get raw result from db
331
 
            port = db.port_get(port_id, network_id)
332
 
            # Fill CLI template
333
 
            output = cli.prepare_output("unplug_iface",
334
 
                                        self.tenant_id,
335
 
                                        dict(network_id=network_id,
336
 
                                             port_id=port['uuid']),
337
 
                                        self.version)
338
 
            # Verify!
339
 
            # Must add newline at the end to match effect of print call
340
 
            self.assertEquals(self.fake_stdout.make_string(), output + '\n')
341
 
 
342
 
    def _verify_show_iface(self, network_id, port_id):
343
 
            # Verification - get raw result from db
344
 
            port = db.port_get(port_id, network_id)
345
 
            iface = {'id': port.interface_id or '<none>'}
346
 
 
347
 
            # Fill CLI template
348
 
            output = cli.prepare_output('show_iface',
349
 
                                        self.tenant_id,
350
 
                                        dict(network_id=network_id,
351
 
                                             port_id=port.uuid,
352
 
                                             iface=iface),
353
 
                                        self.version)
354
 
            # Verify!
355
 
            # Must add newline at the end to match effect of print call
356
 
            self.assertEquals(self.fake_stdout.make_string(), output + '\n')
357
 
 
358
 
    def test_list_networks_v10(self):
359
 
        try:
360
 
            # Pre-populate data for testing using db api
361
 
            db.network_create(self.tenant_id, self.network_name_1)
362
 
            db.network_create(self.tenant_id, self.network_name_2)
363
 
 
364
 
            cli.list_nets(self.client,
365
 
                          self.tenant_id,
366
 
                          self.version)
367
 
        except:
368
 
            LOG.exception("Exception caught: %s", sys.exc_info())
369
 
            self.fail("test_list_networks_v10 failed due to an exception")
370
 
 
371
 
        LOG.debug("Operation completed. Verifying result")
372
 
        LOG.debug(self.fake_stdout.content)
373
 
        self._verify_list_networks()
374
 
 
375
 
    def test_list_networks_details_v10(self):
376
 
        try:
377
 
            # Pre-populate data for testing using db api
378
 
            db.network_create(self.tenant_id, self.network_name_1)
379
 
            db.network_create(self.tenant_id, self.network_name_2)
380
 
 
381
 
            cli.list_nets_detail(self.client,
382
 
                                 self.tenant_id,
383
 
                                 self.version)
384
 
        except:
385
 
            LOG.exception("Exception caught: %s", sys.exc_info())
386
 
            self.fail("test_list_networks_details_v10 failed due to" +
387
 
                      " an exception")
388
 
 
389
 
        LOG.debug("Operation completed. Verifying result")
390
 
        LOG.debug(self.fake_stdout.content)
391
 
        self._verify_list_networks_details()
392
 
 
393
 
    def test_list_networks_v11(self):
394
 
        try:
395
 
            # Pre-populate data for testing using db api
396
 
            db.network_create(self.tenant_id, self.network_name_1)
397
 
            db.network_create(self.tenant_id, self.network_name_2)
398
 
            #TODO: test filters
399
 
            cli.list_nets_v11(self.client,
400
 
                              self.tenant_id,
401
 
                              self.version)
402
 
        except:
403
 
            LOG.exception("Exception caught: %s", sys.exc_info())
404
 
            self.fail("test_list_networks_v11 failed due to an exception")
405
 
 
406
 
        LOG.debug("Operation completed. Verifying result")
407
 
        LOG.debug(self.fake_stdout.content)
408
 
        self._verify_list_networks()
409
 
 
410
 
    def test_list_networks_details_v11(self):
411
 
        try:
412
 
            # Pre-populate data for testing using db api
413
 
            db.network_create(self.tenant_id, self.network_name_1)
414
 
            db.network_create(self.tenant_id, self.network_name_2)
415
 
            #TODO: test filters
416
 
            cli.list_nets_detail_v11(self.client,
417
 
                                     self.tenant_id,
418
 
                                     self.version)
419
 
        except:
420
 
            LOG.exception("Exception caught: %s", sys.exc_info())
421
 
            self.fail("test_list_networks_details_v11 failed due to " +
422
 
                      "an exception")
423
 
 
424
 
        LOG.debug("Operation completed. Verifying result")
425
 
        LOG.debug(self.fake_stdout.content)
426
 
        self._verify_list_networks_details()
427
 
 
428
 
    def test_list_networks_details_v11_name_filter(self):
429
 
        try:
430
 
            # Pre-populate data for testing using db api
431
 
            db.network_create(self.tenant_id, self.network_name_1)
432
 
            db.network_create(self.tenant_id, self.network_name_2)
433
 
            #TODO: test filters
434
 
            cli.list_nets_detail_v11(self.client,
435
 
                                     self.tenant_id,
436
 
                                     self.version,
437
 
                                     {'name': self.network_name_1, })
438
 
        except:
439
 
            LOG.exception("Exception caught: %s", sys.exc_info())
440
 
            self.fail("test_list_networks_details_v11 failed due to " +
441
 
                      "an exception")
442
 
 
443
 
        LOG.debug("Operation completed. Verifying result")
444
 
        LOG.debug(self.fake_stdout.content)
445
 
        self._verify_list_networks_details_name_filter(self.network_name_1)
446
 
 
447
 
    def test_create_network(self):
448
 
        try:
449
 
            cli.create_net(self.client,
450
 
                           self.tenant_id,
451
 
                           "test",
452
 
                           self.version)
453
 
        except:
454
 
            LOG.exception("Exception caught: %s", sys.exc_info())
455
 
            self.fail("test_create_network failed due to an exception")
456
 
 
457
 
        LOG.debug("Operation completed. Verifying result")
458
 
        LOG.debug(self.fake_stdout.content)
459
 
        self._verify_create_network()
460
 
 
461
 
    def test_delete_network(self):
462
 
        try:
463
 
            db.network_create(self.tenant_id, self.network_name_1)
464
 
            network_id = db.network_list(self.tenant_id)[0]['uuid']
465
 
            cli.delete_net(self.client,
466
 
                           self.tenant_id,
467
 
                           network_id,
468
 
                           self.version)
469
 
        except:
470
 
            LOG.exception("Exception caught: %s", sys.exc_info())
471
 
            self.fail("test_delete_network failed due to an exception")
472
 
 
473
 
        LOG.debug("Operation completed. Verifying result")
474
 
        LOG.debug(self.fake_stdout.content)
475
 
        self._verify_delete_network(network_id)
476
 
 
477
 
    def test_show_network(self):
478
 
        try:
479
 
            # Load some data into the datbase
480
 
            net = db.network_create(self.tenant_id, self.network_name_1)
481
 
            cli.show_net(self.client,
482
 
                         self.tenant_id,
483
 
                         net['uuid'],
484
 
                         self.version)
485
 
        except:
486
 
            LOG.exception("Exception caught: %s", sys.exc_info())
487
 
            self.fail("test_detail_network failed due to an exception")
488
 
 
489
 
        LOG.debug("Operation completed. Verifying result")
490
 
        LOG.debug(self.fake_stdout.content)
491
 
        self._verify_show_network()
492
 
 
493
 
    def test_show_network_details_no_ports(self):
494
 
        try:
495
 
            # Load some data into the datbase
496
 
            net = db.network_create(self.tenant_id, self.network_name_1)
497
 
            network_id = net['uuid']
498
 
            cli.show_net_detail(self.client,
499
 
                                self.tenant_id,
500
 
                                network_id,
501
 
                                self.version)
502
 
        except:
503
 
            LOG.exception("Exception caught: %s", sys.exc_info())
504
 
            self.fail("test_show_network_details_no_ports failed due to" +
505
 
                      " an exception")
506
 
 
507
 
        LOG.debug("Operation completed. Verifying result")
508
 
        LOG.debug(self.fake_stdout.content)
509
 
        self._verify_show_network_details()
510
 
 
511
 
    def test_show_network_details(self):
512
 
        iface_id = "flavor crystals"
513
 
        try:
514
 
            # Load some data into the datbase
515
 
            net = db.network_create(self.tenant_id, self.network_name_1)
516
 
            network_id = net['uuid']
517
 
            port = db.port_create(network_id)
518
 
            port_id = port['uuid']
519
 
            db.port_set_attachment(port_id, network_id, iface_id)
520
 
            port = db.port_create(network_id)
521
 
            cli.show_net_detail(self.client,
522
 
                                self.tenant_id,
523
 
                                network_id,
524
 
                                self.version)
525
 
        except:
526
 
            LOG.exception("Exception caught: %s", sys.exc_info())
527
 
            self.fail("test_show_network_details failed due to an exception")
528
 
 
529
 
        LOG.debug("Operation completed. Verifying result")
530
 
        LOG.debug(self.fake_stdout.content)
531
 
        self._verify_show_network_details()
532
 
 
533
 
    def test_update_network(self):
534
 
        try:
535
 
            net = db.network_create(self.tenant_id, self.network_name_1)
536
 
            network_id = net['uuid']
537
 
            cli.update_net(self.client,
538
 
                           self.tenant_id,
539
 
                           network_id,
540
 
                           'name=%s' % self.network_name_2,
541
 
                           self.version)
542
 
        except:
543
 
            LOG.exception("Exception caught: %s", sys.exc_info())
544
 
            self.fail("test_update_network failed due to an exception")
545
 
 
546
 
        LOG.debug("Operation completed. Verifying result")
547
 
        LOG.debug(self.fake_stdout.content)
548
 
        self._verify_update_network()
549
 
 
550
 
    def test_list_ports_v10(self):
551
 
        try:
552
 
            # Pre-populate data for testing using db api
553
 
            net = db.network_create(self.tenant_id, self.network_name_1)
554
 
            network_id = net['uuid']
555
 
            db.port_create(network_id)
556
 
            db.port_create(network_id)
557
 
            cli.list_ports(self.client,
558
 
                           self.tenant_id,
559
 
                           network_id,
560
 
                           self.version)
561
 
        except:
562
 
            LOG.exception("Exception caught: %s", sys.exc_info())
563
 
            self.fail("test_list_ports failed due to an exception")
564
 
 
565
 
        LOG.debug("Operation completed. Verifying result")
566
 
        LOG.debug(self.fake_stdout.content)
567
 
        self._verify_list_ports(network_id)
568
 
 
569
 
    def test_list_ports_details_v10(self):
570
 
        try:
571
 
            # Pre-populate data for testing using db api
572
 
            net = db.network_create(self.tenant_id, self.network_name_1)
573
 
            network_id = net['uuid']
574
 
            db.port_create(network_id)
575
 
            db.port_create(network_id)
576
 
            cli.list_ports_detail(self.client,
577
 
                                  self.tenant_id,
578
 
                                  network_id,
579
 
                                  self.version)
580
 
        except:
581
 
            LOG.exception("Exception caught: %s", sys.exc_info())
582
 
            self.fail("test_list_ports_details_v10 failed due to" +
583
 
                      " an exception")
584
 
 
585
 
        LOG.debug("Operation completed. Verifying result")
586
 
        LOG.debug(self.fake_stdout.content)
587
 
        self._verify_list_ports_details(network_id)
588
 
 
589
 
    def test_list_ports_v11(self):
590
 
        try:
591
 
            # Pre-populate data for testing using db api
592
 
            net = db.network_create(self.tenant_id, self.network_name_1)
593
 
            network_id = net['uuid']
594
 
            db.port_create(network_id)
595
 
            db.port_create(network_id)
596
 
            #TODO: test filters
597
 
            cli.list_ports_v11(self.client,
598
 
                               self.tenant_id,
599
 
                               network_id,
600
 
                               self.version)
601
 
        except:
602
 
            LOG.exception("Exception caught: %s", sys.exc_info())
603
 
            self.fail("test_list_ports_v11 failed due to an exception")
604
 
 
605
 
        LOG.debug("Operation completed. Verifying result")
606
 
        LOG.debug(self.fake_stdout.content)
607
 
        self._verify_list_ports(network_id)
608
 
 
609
 
    def test_list_ports_details_v11(self):
610
 
        try:
611
 
            # Pre-populate data for testing using db api
612
 
            net = db.network_create(self.tenant_id, self.network_name_1)
613
 
            network_id = net['uuid']
614
 
            db.port_create(network_id)
615
 
            db.port_create(network_id)
616
 
            #TODO: test filters
617
 
            cli.list_ports_detail_v11(self.client,
618
 
                                      self.tenant_id,
619
 
                                      network_id,
620
 
                                      self.version)
621
 
        except:
622
 
            LOG.exception("Exception caught: %s", sys.exc_info())
623
 
            self.fail("test_list_ports_details_v11 failed due to " +
624
 
                      "an exception")
625
 
 
626
 
        LOG.debug("Operation completed. Verifying result")
627
 
        LOG.debug(self.fake_stdout.content)
628
 
        self._verify_list_ports_details(network_id)
629
 
 
630
 
    def test_create_port(self):
631
 
        network_id = None
632
 
        try:
633
 
            # Pre-populate data for testing using db api
634
 
            net = db.network_create(self.tenant_id, self.network_name_1)
635
 
            network_id = net['uuid']
636
 
            cli.create_port(self.client,
637
 
                            self.tenant_id,
638
 
                            network_id,
639
 
                            self.version)
640
 
        except:
641
 
            LOG.exception("Exception caught: %s", sys.exc_info())
642
 
            self.fail("test_create_port failed due to an exception")
643
 
 
644
 
        LOG.debug("Operation completed. Verifying result")
645
 
        LOG.debug(self.fake_stdout.content)
646
 
        self._verify_create_port(network_id)
647
 
 
648
 
    def test_delete_port(self):
649
 
        network_id = None
650
 
        port_id = None
651
 
        try:
652
 
            # Pre-populate data for testing using db api
653
 
            net = db.network_create(self.tenant_id, self.network_name_1)
654
 
            network_id = net['uuid']
655
 
            port = db.port_create(network_id)
656
 
            port_id = port['uuid']
657
 
            cli.delete_port(self.client,
658
 
                            self.tenant_id,
659
 
                            network_id,
660
 
                            port_id,
661
 
                            self.version)
662
 
        except:
663
 
            LOG.exception("Exception caught: %s", sys.exc_info())
664
 
            self.fail("test_delete_port failed due to an exception")
665
 
 
666
 
        LOG.debug("Operation completed. Verifying result")
667
 
        LOG.debug(self.fake_stdout.content)
668
 
        self._verify_delete_port(network_id, port_id)
669
 
 
670
 
    def test_update_port(self):
671
 
        try:
672
 
            net = db.network_create(self.tenant_id, self.network_name_1)
673
 
            network_id = net['uuid']
674
 
            port = db.port_create(network_id)
675
 
            port_id = port['uuid']
676
 
            # Default state is DOWN - change to ACTIVE.
677
 
            cli.update_port(self.client,
678
 
                            self.tenant_id,
679
 
                            network_id,
680
 
                            port_id,
681
 
                            'state=ACTIVE',
682
 
                            self.version)
683
 
        except:
684
 
            LOG.exception("Exception caught: %s", sys.exc_info())
685
 
            self.fail("test_update_port failed due to an exception")
686
 
 
687
 
        LOG.debug("Operation completed. Verifying result")
688
 
        LOG.debug(self.fake_stdout.content)
689
 
        self._verify_update_port(network_id, port_id)
690
 
 
691
 
    def test_show_port(self):
692
 
        network_id = None
693
 
        port_id = None
694
 
        try:
695
 
            # Pre-populate data for testing using db api
696
 
            net = db.network_create(self.tenant_id, self.network_name_1)
697
 
            network_id = net['uuid']
698
 
            port = db.port_create(network_id)
699
 
            port_id = port['uuid']
700
 
            cli.show_port(self.client,
701
 
                          self.tenant_id,
702
 
                          network_id,
703
 
                          port_id,
704
 
                          self.version)
705
 
        except:
706
 
            LOG.exception("Exception caught: %s", sys.exc_info())
707
 
            self.fail("test_show_port failed due to an exception")
708
 
 
709
 
        LOG.debug("Operation completed. Verifying result")
710
 
        LOG.debug(self.fake_stdout.content)
711
 
        self._verify_show_port(network_id, port_id)
712
 
 
713
 
    def test_show_port_details_no_attach(self):
714
 
        network_id = None
715
 
        port_id = None
716
 
        try:
717
 
            # Pre-populate data for testing using db api
718
 
            net = db.network_create(self.tenant_id, self.network_name_1)
719
 
            network_id = net['uuid']
720
 
            port = db.port_create(network_id)
721
 
            port_id = port['uuid']
722
 
            cli.show_port_detail(self.client,
723
 
                                 self.tenant_id,
724
 
                                 network_id,
725
 
                                 port_id,
726
 
                                 self.version)
727
 
        except:
728
 
            LOG.exception("Exception caught: %s", sys.exc_info())
729
 
            self.fail("test_show_port_details_no_attach failed due to" +
730
 
                      " an exception")
731
 
 
732
 
        LOG.debug("Operation completed. Verifying result")
733
 
        LOG.debug(self.fake_stdout.content)
734
 
        self._verify_show_port_details(network_id, port_id)
735
 
 
736
 
    def test_show_port_details_with_attach(self):
737
 
        network_id = None
738
 
        port_id = None
739
 
        iface_id = "flavor crystals"
740
 
        try:
741
 
            # Pre-populate data for testing using db api
742
 
            net = db.network_create(self.tenant_id, self.network_name_1)
743
 
            network_id = net['uuid']
744
 
            port = db.port_create(network_id)
745
 
            port_id = port['uuid']
746
 
            db.port_set_attachment(port_id, network_id, iface_id)
747
 
            cli.show_port_detail(self.client,
748
 
                                 self.tenant_id,
749
 
                                 network_id,
750
 
                                 port_id,
751
 
                                 self.version)
752
 
        except:
753
 
            LOG.exception("Exception caught: %s", sys.exc_info())
754
 
            self.fail("test_show_port_details_with_attach failed due" +
755
 
                      " to an exception")
756
 
 
757
 
        LOG.debug("Operation completed. Verifying result")
758
 
        LOG.debug(self.fake_stdout.content)
759
 
        self._verify_show_port_details(network_id, port_id)
760
 
 
761
 
    def test_plug_iface(self):
762
 
        network_id = None
763
 
        port_id = None
764
 
        try:
765
 
            # Load some data into the datbase
766
 
            net = db.network_create(self.tenant_id, self.network_name_1)
767
 
            network_id = net['uuid']
768
 
            port = db.port_create(net['uuid'])
769
 
            port_id = port['uuid']
770
 
            cli.plug_iface(self.client,
771
 
                           self.tenant_id,
772
 
                           network_id,
773
 
                           port_id,
774
 
                           "test_iface_id",
775
 
                           self.version)
776
 
        except:
777
 
            LOG.exception("Exception caught: %s", sys.exc_info())
778
 
            self.fail("test_plug_iface failed due to an exception")
779
 
 
780
 
        LOG.debug("Operation completed. Verifying result")
781
 
        LOG.debug(self.fake_stdout.content)
782
 
        self._verify_plug_iface(network_id, port_id)
783
 
 
784
 
    def test_unplug_iface(self):
785
 
        network_id = None
786
 
        port_id = None
787
 
        try:
788
 
            # Load some data into the datbase
789
 
            net = db.network_create(self.tenant_id, self.network_name_1)
790
 
            network_id = net['uuid']
791
 
            port = db.port_create(net['uuid'])
792
 
            port_id = port['uuid']
793
 
            db.port_set_attachment(port_id, network_id, "test_iface_id")
794
 
            cli.unplug_iface(self.client,
795
 
                             self.tenant_id,
796
 
                             network_id,
797
 
                             port_id,
798
 
                             self.version)
799
 
        except:
800
 
            LOG.exception("Exception caught: %s", sys.exc_info())
801
 
            self.fail("test_plug_iface failed due to an exception")
802
 
 
803
 
        LOG.debug("Operation completed. Verifying result")
804
 
        LOG.debug(self.fake_stdout.content)
805
 
        self._verify_unplug_iface(network_id, port_id)
806
 
 
807
 
    def test_show_iface_no_attach(self):
808
 
        network_id = None
809
 
        port_id = None
810
 
        try:
811
 
            # Pre-populate data for testing using db api
812
 
            net = db.network_create(self.tenant_id, self.network_name_1)
813
 
            network_id = net['uuid']
814
 
            port = db.port_create(network_id)
815
 
            port_id = port['uuid']
816
 
            cli.show_iface(self.client,
817
 
                           self.tenant_id,
818
 
                           network_id,
819
 
                           port_id,
820
 
                           self.version)
821
 
        except:
822
 
            LOG.exception("Exception caught: %s", sys.exc_info())
823
 
            self.fail("test_show_iface_no_attach failed due to" +
824
 
                      " an exception")
825
 
 
826
 
        LOG.debug("Operation completed. Verifying result")
827
 
        LOG.debug(self.fake_stdout.content)
828
 
        self._verify_show_iface(network_id, port_id)
829
 
 
830
 
    def test_show_iface_with_attach(self):
831
 
        network_id = None
832
 
        port_id = None
833
 
        iface_id = "flavor crystals"
834
 
        try:
835
 
            # Pre-populate data for testing using db api
836
 
            net = db.network_create(self.tenant_id, self.network_name_1)
837
 
            network_id = net['uuid']
838
 
            port = db.port_create(network_id)
839
 
            port_id = port['uuid']
840
 
            db.port_set_attachment(port_id, network_id, iface_id)
841
 
            cli.show_iface(self.client,
842
 
                           self.tenant_id,
843
 
                           network_id,
844
 
                           port_id,
845
 
                           self.version)
846
 
        except:
847
 
            LOG.exception("Exception caught: %s", sys.exc_info())
848
 
            self.fail("test_show_iface_with_attach failed due" +
849
 
                      " to an exception")
850
 
 
851
 
        LOG.debug("Operation completed. Verifying result")
852
 
        LOG.debug(self.fake_stdout.content)
853
 
        self._verify_show_iface(network_id, port_id)