saurabh | 467c411 | 2013-07-08 17:08:31 +0530 | [diff] [blame^] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2013 OpenStack Foundation |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. You may obtain |
| 8 | # a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | # License for the specific language governing permissions and limitations |
| 16 | # under the License. |
| 17 | |
| 18 | import logging |
| 19 | import re |
| 20 | import subprocess |
| 21 | |
| 22 | import tempest.cli |
| 23 | |
| 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 | |
| 35 | def test_cinder_fake_action(self): |
| 36 | self.assertRaises(subprocess.CalledProcessError, |
| 37 | self.cinder, |
| 38 | 'this-does-not-exist') |
| 39 | |
| 40 | def test_cinder_absolute_limit_list(self): |
| 41 | roles = self.parser.listing(self.cinder('absolute-limits')) |
| 42 | self.assertTableStruct(roles, ['Name', 'Value']) |
| 43 | |
| 44 | def test_cinder_backup_list(self): |
| 45 | self.cinder('backup-list') |
| 46 | |
| 47 | def test_cinder_extra_specs_list(self): |
| 48 | self.cinder('extra-specs-list') |
| 49 | |
| 50 | def test_cinder_volumes_list(self): |
| 51 | self.cinder('list') |
| 52 | |
| 53 | def test_cinder_quota_class_show(self): |
| 54 | """This CLI can accept and string as param.""" |
| 55 | roles = self.parser.listing(self.cinder('quota-class-show', |
| 56 | params='abc')) |
| 57 | self.assertTableStruct(roles, ['Property', 'Value']) |
| 58 | |
| 59 | def test_cinder_quota_defaults(self): |
| 60 | """This CLI can accept and string as param.""" |
| 61 | roles = self.parser.listing(self.cinder('quota-defaults', |
| 62 | params=self.identity. |
| 63 | admin_tenant_name)) |
| 64 | self.assertTableStruct(roles, ['Property', 'Value']) |
| 65 | |
| 66 | def test_cinder_quota_show(self): |
| 67 | """This CLI can accept and string as param.""" |
| 68 | roles = self.parser.listing(self.cinder('quota-show', |
| 69 | params=self.identity. |
| 70 | admin_tenant_name)) |
| 71 | self.assertTableStruct(roles, ['Property', 'Value']) |
| 72 | |
| 73 | def test_cinder_rate_limits(self): |
| 74 | self.cinder('rate-limits') |
| 75 | |
| 76 | def test_cinder_snapshot_list(self): |
| 77 | self.cinder('snapshot-list') |
| 78 | |
| 79 | def test_cinder_type_list(self): |
| 80 | self.cinder('type-list') |
| 81 | |
| 82 | def test_cinder_list_extensions(self): |
| 83 | self.cinder('list-extensions') |
| 84 | roles = self.parser.listing(self.cinder('list-extensions')) |
| 85 | self.assertTableStruct(roles, ['Name', 'Summary', 'Alias', 'Updated']) |
| 86 | |
| 87 | def test_admin_help(self): |
| 88 | help_text = self.cinder('help') |
| 89 | lines = help_text.split('\n') |
| 90 | self.assertTrue(lines[0].startswith('usage: cinder')) |
| 91 | |
| 92 | commands = [] |
| 93 | cmds_start = lines.index('Positional arguments:') |
| 94 | cmds_end = lines.index('Optional arguments:') |
| 95 | command_pattern = re.compile('^ {4}([a-z0-9\-\_]+)') |
| 96 | for line in lines[cmds_start:cmds_end]: |
| 97 | match = command_pattern.match(line) |
| 98 | if match: |
| 99 | commands.append(match.group(1)) |
| 100 | commands = set(commands) |
| 101 | wanted_commands = set(('absolute-limits', 'list', 'help', |
| 102 | 'quota-show', 'type-list', 'snapshot-list')) |
| 103 | self.assertFalse(wanted_commands - commands) |
| 104 | |
| 105 | # Optional arguments: |
| 106 | |
| 107 | def test_cinder_version(self): |
| 108 | self.cinder('', flags='--version') |
| 109 | |
| 110 | def test_cinder_debug_list(self): |
| 111 | self.cinder('list', flags='--debug') |
| 112 | |
| 113 | def test_cinder_retries_list(self): |
| 114 | self.cinder('list', flags='--retries 3') |
| 115 | |
| 116 | def test_cinder_region_list(self): |
| 117 | self.cinder('list', flags='--os-region-name ' + self.identity.region) |