blob: afbd732f9c10b46c2c4c7c9338dc75de9465125a [file] [log] [blame]
saurabh467c4112013-07-08 17:08:31 +05301# Copyright 2013 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16import logging
17import re
18import subprocess
19
20import tempest.cli
Matthew Treinishd52645a2014-01-21 23:44:44 +000021from tempest import config
saurabh467c4112013-07-08 17:08:31 +053022
Matthew Treinishd52645a2014-01-21 23:44:44 +000023CONF = config.CONF
saurabh467c4112013-07-08 17:08:31 +053024LOG = logging.getLogger(__name__)
25
26
27class SimpleReadOnlyCinderClientTest(tempest.cli.ClientTestBase):
28 """Basic, read-only tests for Cinder CLI client.
29
30 Checks return values and output of read-only commands.
31 These tests do not presume any content, nor do they create
32 their own. They only verify the structure of output if present.
33 """
34
Matthew Treinishd52645a2014-01-21 23:44:44 +000035 @classmethod
36 def setUpClass(cls):
37 if not CONF.service_available.cinder:
38 msg = ("%s skipped as Cinder is not available" % cls.__name__)
39 raise cls.skipException(msg)
40 super(SimpleReadOnlyCinderClientTest, cls).setUpClass()
41
saurabh467c4112013-07-08 17:08:31 +053042 def test_cinder_fake_action(self):
43 self.assertRaises(subprocess.CalledProcessError,
44 self.cinder,
45 'this-does-not-exist')
46
47 def test_cinder_absolute_limit_list(self):
48 roles = self.parser.listing(self.cinder('absolute-limits'))
49 self.assertTableStruct(roles, ['Name', 'Value'])
50
51 def test_cinder_backup_list(self):
52 self.cinder('backup-list')
53
54 def test_cinder_extra_specs_list(self):
55 self.cinder('extra-specs-list')
56
57 def test_cinder_volumes_list(self):
58 self.cinder('list')
Xiao Chen134734d2014-01-15 15:40:09 +080059 self.cinder('list', params='--all-tenants 1')
60 self.cinder('list', params='--all-tenants 0')
61 self.assertRaises(subprocess.CalledProcessError,
62 self.cinder,
63 'list',
64 params='--all-tenants bad')
saurabh467c4112013-07-08 17:08:31 +053065
66 def test_cinder_quota_class_show(self):
67 """This CLI can accept and string as param."""
68 roles = self.parser.listing(self.cinder('quota-class-show',
69 params='abc'))
70 self.assertTableStruct(roles, ['Property', 'Value'])
71
72 def test_cinder_quota_defaults(self):
73 """This CLI can accept and string as param."""
74 roles = self.parser.listing(self.cinder('quota-defaults',
Matthew Treinishe2b56b52014-01-29 19:25:50 +000075 params=CONF.identity.
saurabh467c4112013-07-08 17:08:31 +053076 admin_tenant_name))
77 self.assertTableStruct(roles, ['Property', 'Value'])
78
79 def test_cinder_quota_show(self):
80 """This CLI can accept and string as param."""
81 roles = self.parser.listing(self.cinder('quota-show',
Matthew Treinishe2b56b52014-01-29 19:25:50 +000082 params=CONF.identity.
saurabh467c4112013-07-08 17:08:31 +053083 admin_tenant_name))
84 self.assertTableStruct(roles, ['Property', 'Value'])
85
86 def test_cinder_rate_limits(self):
87 self.cinder('rate-limits')
88
89 def test_cinder_snapshot_list(self):
90 self.cinder('snapshot-list')
91
92 def test_cinder_type_list(self):
93 self.cinder('type-list')
94
95 def test_cinder_list_extensions(self):
96 self.cinder('list-extensions')
97 roles = self.parser.listing(self.cinder('list-extensions'))
98 self.assertTableStruct(roles, ['Name', 'Summary', 'Alias', 'Updated'])
99
wingwj69f09bb2013-10-10 11:31:10 +0800100 def test_cinder_credentials(self):
101 self.cinder('credentials')
102
103 def test_cinder_availability_zone_list(self):
104 self.cinder('availability-zone-list')
105
106 def test_cinder_endpoints(self):
107 self.cinder('endpoints')
108
109 def test_cinder_service_list(self):
110 self.cinder('service-list')
111
112 def test_cinder_transfer_list(self):
113 self.cinder('transfer-list')
114
115 def test_cinder_bash_completion(self):
116 self.cinder('bash-completion')
117
saurabh467c4112013-07-08 17:08:31 +0530118 def test_admin_help(self):
119 help_text = self.cinder('help')
120 lines = help_text.split('\n')
Pavel Sedlák4c18fa12013-08-22 21:29:45 +0200121 self.assertFirstLineStartsWith(lines, 'usage: cinder')
saurabh467c4112013-07-08 17:08:31 +0530122
123 commands = []
124 cmds_start = lines.index('Positional arguments:')
125 cmds_end = lines.index('Optional arguments:')
126 command_pattern = re.compile('^ {4}([a-z0-9\-\_]+)')
127 for line in lines[cmds_start:cmds_end]:
128 match = command_pattern.match(line)
129 if match:
130 commands.append(match.group(1))
131 commands = set(commands)
132 wanted_commands = set(('absolute-limits', 'list', 'help',
133 'quota-show', 'type-list', 'snapshot-list'))
134 self.assertFalse(wanted_commands - commands)
135
136 # Optional arguments:
137
138 def test_cinder_version(self):
139 self.cinder('', flags='--version')
140
141 def test_cinder_debug_list(self):
142 self.cinder('list', flags='--debug')
143
144 def test_cinder_retries_list(self):
145 self.cinder('list', flags='--retries 3')
146
147 def test_cinder_region_list(self):
Matthew Treinishe2b56b52014-01-29 19:25:50 +0000148 region = CONF.volume.region
Arata Notsu8f440392013-09-13 16:14:20 +0900149 if not region:
Matthew Treinishe2b56b52014-01-29 19:25:50 +0000150 region = CONF.identity.region
Arata Notsu8f440392013-09-13 16:14:20 +0900151 self.cinder('list', flags='--os-region-name ' + region)