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 |
| 21 | |
| 22 | LOG = logging.getLogger(__name__) |
| 23 | |
| 24 | |
| 25 | class SimpleReadOnlyCinderClientTest(tempest.cli.ClientTestBase): |
| 26 | """Basic, read-only tests for Cinder CLI client. |
| 27 | |
| 28 | Checks return values and output of read-only commands. |
| 29 | These tests do not presume any content, nor do they create |
| 30 | their own. They only verify the structure of output if present. |
| 31 | """ |
| 32 | |
| 33 | def test_cinder_fake_action(self): |
| 34 | self.assertRaises(subprocess.CalledProcessError, |
| 35 | self.cinder, |
| 36 | 'this-does-not-exist') |
| 37 | |
| 38 | def test_cinder_absolute_limit_list(self): |
| 39 | roles = self.parser.listing(self.cinder('absolute-limits')) |
| 40 | self.assertTableStruct(roles, ['Name', 'Value']) |
| 41 | |
| 42 | def test_cinder_backup_list(self): |
| 43 | self.cinder('backup-list') |
| 44 | |
| 45 | def test_cinder_extra_specs_list(self): |
| 46 | self.cinder('extra-specs-list') |
| 47 | |
| 48 | def test_cinder_volumes_list(self): |
| 49 | self.cinder('list') |
Xiao Chen | 134734d | 2014-01-15 15:40:09 +0800 | [diff] [blame] | 50 | self.cinder('list', params='--all-tenants 1') |
| 51 | self.cinder('list', params='--all-tenants 0') |
| 52 | self.assertRaises(subprocess.CalledProcessError, |
| 53 | self.cinder, |
| 54 | 'list', |
| 55 | params='--all-tenants bad') |
saurabh | 467c411 | 2013-07-08 17:08:31 +0530 | [diff] [blame] | 56 | |
| 57 | def test_cinder_quota_class_show(self): |
| 58 | """This CLI can accept and string as param.""" |
| 59 | roles = self.parser.listing(self.cinder('quota-class-show', |
| 60 | params='abc')) |
| 61 | self.assertTableStruct(roles, ['Property', 'Value']) |
| 62 | |
| 63 | def test_cinder_quota_defaults(self): |
| 64 | """This CLI can accept and string as param.""" |
| 65 | roles = self.parser.listing(self.cinder('quota-defaults', |
| 66 | params=self.identity. |
| 67 | admin_tenant_name)) |
| 68 | self.assertTableStruct(roles, ['Property', 'Value']) |
| 69 | |
| 70 | def test_cinder_quota_show(self): |
| 71 | """This CLI can accept and string as param.""" |
| 72 | roles = self.parser.listing(self.cinder('quota-show', |
| 73 | params=self.identity. |
| 74 | admin_tenant_name)) |
| 75 | self.assertTableStruct(roles, ['Property', 'Value']) |
| 76 | |
| 77 | def test_cinder_rate_limits(self): |
| 78 | self.cinder('rate-limits') |
| 79 | |
| 80 | def test_cinder_snapshot_list(self): |
| 81 | self.cinder('snapshot-list') |
| 82 | |
| 83 | def test_cinder_type_list(self): |
| 84 | self.cinder('type-list') |
| 85 | |
| 86 | def test_cinder_list_extensions(self): |
| 87 | self.cinder('list-extensions') |
| 88 | roles = self.parser.listing(self.cinder('list-extensions')) |
| 89 | self.assertTableStruct(roles, ['Name', 'Summary', 'Alias', 'Updated']) |
| 90 | |
wingwj | 69f09bb | 2013-10-10 11:31:10 +0800 | [diff] [blame] | 91 | def test_cinder_credentials(self): |
| 92 | self.cinder('credentials') |
| 93 | |
| 94 | def test_cinder_availability_zone_list(self): |
| 95 | self.cinder('availability-zone-list') |
| 96 | |
| 97 | def test_cinder_endpoints(self): |
| 98 | self.cinder('endpoints') |
| 99 | |
| 100 | def test_cinder_service_list(self): |
| 101 | self.cinder('service-list') |
| 102 | |
| 103 | def test_cinder_transfer_list(self): |
| 104 | self.cinder('transfer-list') |
| 105 | |
| 106 | def test_cinder_bash_completion(self): |
| 107 | self.cinder('bash-completion') |
| 108 | |
saurabh | 467c411 | 2013-07-08 17:08:31 +0530 | [diff] [blame] | 109 | def test_admin_help(self): |
| 110 | help_text = self.cinder('help') |
| 111 | lines = help_text.split('\n') |
Pavel Sedlák | 4c18fa1 | 2013-08-22 21:29:45 +0200 | [diff] [blame] | 112 | self.assertFirstLineStartsWith(lines, 'usage: cinder') |
saurabh | 467c411 | 2013-07-08 17:08:31 +0530 | [diff] [blame] | 113 | |
| 114 | commands = [] |
| 115 | cmds_start = lines.index('Positional arguments:') |
| 116 | cmds_end = lines.index('Optional arguments:') |
| 117 | command_pattern = re.compile('^ {4}([a-z0-9\-\_]+)') |
| 118 | for line in lines[cmds_start:cmds_end]: |
| 119 | match = command_pattern.match(line) |
| 120 | if match: |
| 121 | commands.append(match.group(1)) |
| 122 | commands = set(commands) |
| 123 | wanted_commands = set(('absolute-limits', 'list', 'help', |
| 124 | 'quota-show', 'type-list', 'snapshot-list')) |
| 125 | self.assertFalse(wanted_commands - commands) |
| 126 | |
| 127 | # Optional arguments: |
| 128 | |
| 129 | def test_cinder_version(self): |
| 130 | self.cinder('', flags='--version') |
| 131 | |
| 132 | def test_cinder_debug_list(self): |
| 133 | self.cinder('list', flags='--debug') |
| 134 | |
| 135 | def test_cinder_retries_list(self): |
| 136 | self.cinder('list', flags='--retries 3') |
| 137 | |
| 138 | def test_cinder_region_list(self): |
Arata Notsu | 8f44039 | 2013-09-13 16:14:20 +0900 | [diff] [blame] | 139 | region = self.config.volume.region |
| 140 | if not region: |
| 141 | region = self.config.identity.region |
| 142 | self.cinder('list', flags='--os-region-name ' + region) |