blob: 723333b096597f18b3ab909a6502fa645edc8e30 [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):
99 self.cinder('list-extensions')
100 roles = self.parser.listing(self.cinder('list-extensions'))
101 self.assertTableStruct(roles, ['Name', 'Summary', 'Alias', 'Updated'])
102
wingwj69f09bb2013-10-10 11:31:10 +0800103 def test_cinder_credentials(self):
104 self.cinder('credentials')
105
106 def test_cinder_availability_zone_list(self):
107 self.cinder('availability-zone-list')
108
109 def test_cinder_endpoints(self):
110 self.cinder('endpoints')
111
112 def test_cinder_service_list(self):
113 self.cinder('service-list')
114
115 def test_cinder_transfer_list(self):
116 self.cinder('transfer-list')
117
118 def test_cinder_bash_completion(self):
119 self.cinder('bash-completion')
120
saurabh467c4112013-07-08 17:08:31 +0530121 def test_admin_help(self):
122 help_text = self.cinder('help')
123 lines = help_text.split('\n')
Pavel Sedlák4c18fa12013-08-22 21:29:45 +0200124 self.assertFirstLineStartsWith(lines, 'usage: cinder')
saurabh467c4112013-07-08 17:08:31 +0530125
126 commands = []
127 cmds_start = lines.index('Positional arguments:')
128 cmds_end = lines.index('Optional arguments:')
129 command_pattern = re.compile('^ {4}([a-z0-9\-\_]+)')
130 for line in lines[cmds_start:cmds_end]:
131 match = command_pattern.match(line)
132 if match:
133 commands.append(match.group(1))
134 commands = set(commands)
135 wanted_commands = set(('absolute-limits', 'list', 'help',
136 'quota-show', 'type-list', 'snapshot-list'))
137 self.assertFalse(wanted_commands - commands)
138
139 # Optional arguments:
140
141 def test_cinder_version(self):
142 self.cinder('', flags='--version')
143
144 def test_cinder_debug_list(self):
145 self.cinder('list', flags='--debug')
146
147 def test_cinder_retries_list(self):
148 self.cinder('list', flags='--retries 3')
149
150 def test_cinder_region_list(self):
Matthew Treinishe2b56b52014-01-29 19:25:50 +0000151 region = CONF.volume.region
Arata Notsu8f440392013-09-13 16:14:20 +0900152 if not region:
Matthew Treinishe2b56b52014-01-29 19:25:50 +0000153 region = CONF.identity.region
Arata Notsu8f440392013-09-13 16:14:20 +0900154 self.cinder('list', flags='--os-region-name ' + region)