saurabh | 467c411 | 2013-07-08 17:08:31 +0530 | [diff] [blame] | 1 | # 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 | |
| 16 | import logging |
| 17 | import re |
| 18 | import subprocess |
| 19 | |
| 20 | import tempest.cli |
Matthew Treinish | d52645a | 2014-01-21 23:44:44 +0000 | [diff] [blame] | 21 | from tempest import config |
saurabh | 467c411 | 2013-07-08 17:08:31 +0530 | [diff] [blame] | 22 | |
Matthew Treinish | d52645a | 2014-01-21 23:44:44 +0000 | [diff] [blame] | 23 | CONF = config.CONF |
saurabh | 467c411 | 2013-07-08 17:08:31 +0530 | [diff] [blame] | 24 | LOG = logging.getLogger(__name__) |
| 25 | |
| 26 | |
| 27 | class 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 Treinish | d52645a | 2014-01-21 23:44:44 +0000 | [diff] [blame] | 35 | @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 | |
saurabh | 467c411 | 2013-07-08 17:08:31 +0530 | [diff] [blame] | 42 | 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 Chen | 134734d | 2014-01-15 15:40:09 +0800 | [diff] [blame] | 59 | 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') |
saurabh | 467c411 | 2013-07-08 17:08:31 +0530 | [diff] [blame] | 65 | |
| 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 Treinish | e2b56b5 | 2014-01-29 19:25:50 +0000 | [diff] [blame] | 75 | params=CONF.identity. |
saurabh | 467c411 | 2013-07-08 17:08:31 +0530 | [diff] [blame] | 76 | 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 Treinish | e2b56b5 | 2014-01-29 19:25:50 +0000 | [diff] [blame] | 82 | params=CONF.identity. |
saurabh | 467c411 | 2013-07-08 17:08:31 +0530 | [diff] [blame] | 83 | 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 | |
wingwj | 69f09bb | 2013-10-10 11:31:10 +0800 | [diff] [blame] | 100 | 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 | |
saurabh | 467c411 | 2013-07-08 17:08:31 +0530 | [diff] [blame] | 118 | def test_admin_help(self): |
| 119 | help_text = self.cinder('help') |
| 120 | lines = help_text.split('\n') |
Pavel Sedlák | 4c18fa1 | 2013-08-22 21:29:45 +0200 | [diff] [blame] | 121 | self.assertFirstLineStartsWith(lines, 'usage: cinder') |
saurabh | 467c411 | 2013-07-08 17:08:31 +0530 | [diff] [blame] | 122 | |
| 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 Treinish | e2b56b5 | 2014-01-29 19:25:50 +0000 | [diff] [blame] | 148 | region = CONF.volume.region |
Arata Notsu | 8f44039 | 2013-09-13 16:14:20 +0900 | [diff] [blame] | 149 | if not region: |
Matthew Treinish | e2b56b5 | 2014-01-29 19:25:50 +0000 | [diff] [blame] | 150 | region = CONF.identity.region |
Arata Notsu | 8f44039 | 2013-09-13 16:14:20 +0900 | [diff] [blame] | 151 | self.cinder('list', flags='--os-region-name ' + region) |