blob: 63ad0e3b0f120b79b0c3e1cb027566a619d11139 [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
JordanPbce55532014-03-19 12:10:32 +010019import testtools
saurabh467c4112013-07-08 17:08:31 +053020
21import tempest.cli
Matthew Treinishd52645a2014-01-21 23:44:44 +000022from tempest import config
saurabh467c4112013-07-08 17:08:31 +053023
Matthew Treinishd52645a2014-01-21 23:44:44 +000024CONF = config.CONF
saurabh467c4112013-07-08 17:08:31 +053025LOG = logging.getLogger(__name__)
26
27
28class SimpleReadOnlyCinderClientTest(tempest.cli.ClientTestBase):
29 """Basic, read-only tests for Cinder CLI client.
30
31 Checks return values and output of read-only commands.
32 These tests do not presume any content, nor do they create
33 their own. They only verify the structure of output if present.
34 """
35
Matthew Treinishd52645a2014-01-21 23:44:44 +000036 @classmethod
37 def setUpClass(cls):
38 if not CONF.service_available.cinder:
39 msg = ("%s skipped as Cinder is not available" % cls.__name__)
40 raise cls.skipException(msg)
41 super(SimpleReadOnlyCinderClientTest, cls).setUpClass()
42
saurabh467c4112013-07-08 17:08:31 +053043 def test_cinder_fake_action(self):
44 self.assertRaises(subprocess.CalledProcessError,
45 self.cinder,
46 'this-does-not-exist')
47
48 def test_cinder_absolute_limit_list(self):
49 roles = self.parser.listing(self.cinder('absolute-limits'))
50 self.assertTableStruct(roles, ['Name', 'Value'])
51
52 def test_cinder_backup_list(self):
53 self.cinder('backup-list')
54
55 def test_cinder_extra_specs_list(self):
56 self.cinder('extra-specs-list')
57
58 def test_cinder_volumes_list(self):
59 self.cinder('list')
Xiao Chen134734d2014-01-15 15:40:09 +080060 self.cinder('list', params='--all-tenants 1')
61 self.cinder('list', params='--all-tenants 0')
62 self.assertRaises(subprocess.CalledProcessError,
63 self.cinder,
64 'list',
65 params='--all-tenants bad')
saurabh467c4112013-07-08 17:08:31 +053066
67 def test_cinder_quota_class_show(self):
68 """This CLI can accept and string as param."""
69 roles = self.parser.listing(self.cinder('quota-class-show',
70 params='abc'))
71 self.assertTableStruct(roles, ['Property', 'Value'])
72
73 def test_cinder_quota_defaults(self):
74 """This CLI can accept and string as param."""
75 roles = self.parser.listing(self.cinder('quota-defaults',
Matthew Treinishe2b56b52014-01-29 19:25:50 +000076 params=CONF.identity.
saurabh467c4112013-07-08 17:08:31 +053077 admin_tenant_name))
78 self.assertTableStruct(roles, ['Property', 'Value'])
79
80 def test_cinder_quota_show(self):
81 """This CLI can accept and string as param."""
82 roles = self.parser.listing(self.cinder('quota-show',
Matthew Treinishe2b56b52014-01-29 19:25:50 +000083 params=CONF.identity.
saurabh467c4112013-07-08 17:08:31 +053084 admin_tenant_name))
85 self.assertTableStruct(roles, ['Property', 'Value'])
86
87 def test_cinder_rate_limits(self):
88 self.cinder('rate-limits')
89
JordanPbce55532014-03-19 12:10:32 +010090 @testtools.skipUnless(CONF.volume_feature_enabled.snapshot,
91 'Volume snapshot not available.')
saurabh467c4112013-07-08 17:08:31 +053092 def test_cinder_snapshot_list(self):
93 self.cinder('snapshot-list')
94
95 def test_cinder_type_list(self):
96 self.cinder('type-list')
97
98 def test_cinder_list_extensions(self):
saurabh467c4112013-07-08 17:08:31 +053099 roles = self.parser.listing(self.cinder('list-extensions'))
100 self.assertTableStruct(roles, ['Name', 'Summary', 'Alias', 'Updated'])
101
wingwj69f09bb2013-10-10 11:31:10 +0800102 def test_cinder_credentials(self):
103 self.cinder('credentials')
104
105 def test_cinder_availability_zone_list(self):
106 self.cinder('availability-zone-list')
107
108 def test_cinder_endpoints(self):
109 self.cinder('endpoints')
110
111 def test_cinder_service_list(self):
112 self.cinder('service-list')
113
114 def test_cinder_transfer_list(self):
115 self.cinder('transfer-list')
116
117 def test_cinder_bash_completion(self):
118 self.cinder('bash-completion')
119
Ajay Yadav4ec0de22014-06-03 10:21:06 +0530120 def test_cinder_qos_list(self):
121 self.cinder('qos-list')
122
123 def test_cinder_encryption_type_list(self):
124 self.cinder('encryption-type-list')
125
saurabh467c4112013-07-08 17:08:31 +0530126 def test_admin_help(self):
127 help_text = self.cinder('help')
128 lines = help_text.split('\n')
Pavel Sedlák4c18fa12013-08-22 21:29:45 +0200129 self.assertFirstLineStartsWith(lines, 'usage: cinder')
saurabh467c4112013-07-08 17:08:31 +0530130
131 commands = []
132 cmds_start = lines.index('Positional arguments:')
133 cmds_end = lines.index('Optional arguments:')
134 command_pattern = re.compile('^ {4}([a-z0-9\-\_]+)')
135 for line in lines[cmds_start:cmds_end]:
136 match = command_pattern.match(line)
137 if match:
138 commands.append(match.group(1))
139 commands = set(commands)
140 wanted_commands = set(('absolute-limits', 'list', 'help',
141 'quota-show', 'type-list', 'snapshot-list'))
142 self.assertFalse(wanted_commands - commands)
143
Matthew Treinishc795b9e2014-06-09 17:01:10 -0400144 # Optional arguments:
saurabh467c4112013-07-08 17:08:31 +0530145
146 def test_cinder_version(self):
147 self.cinder('', flags='--version')
148
149 def test_cinder_debug_list(self):
150 self.cinder('list', flags='--debug')
151
152 def test_cinder_retries_list(self):
153 self.cinder('list', flags='--retries 3')
154
155 def test_cinder_region_list(self):
Matthew Treinishe2b56b52014-01-29 19:25:50 +0000156 region = CONF.volume.region
Arata Notsu8f440392013-09-13 16:14:20 +0900157 if not region:
Matthew Treinishe2b56b52014-01-29 19:25:50 +0000158 region = CONF.identity.region
Arata Notsu8f440392013-09-13 16:14:20 +0900159 self.cinder('list', flags='--os-region-name ' + region)