vishal mahajan | 6251b78 | 2014-05-29 13:15:58 +0530 | [diff] [blame] | 1 | # Copyright 2014 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 re |
| 17 | import subprocess |
| 18 | |
| 19 | import tempest.cli |
| 20 | from tempest import config |
| 21 | |
| 22 | CONF = config.CONF |
| 23 | |
| 24 | |
| 25 | class SimpleReadOnlySwiftClientTest(tempest.cli.ClientTestBase): |
| 26 | """Basic, read-only tests for Swift 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 | @classmethod |
| 34 | def setUpClass(cls): |
| 35 | if not CONF.service_available.swift: |
| 36 | msg = ("%s skipped as Swift is not available" % cls.__name__) |
| 37 | raise cls.skipException(msg) |
| 38 | super(SimpleReadOnlySwiftClientTest, cls).setUpClass() |
| 39 | |
| 40 | def test_swift_fake_action(self): |
| 41 | self.assertRaises(subprocess.CalledProcessError, |
| 42 | self.swift, |
| 43 | 'this-does-not-exist') |
| 44 | |
| 45 | def test_swift_list(self): |
| 46 | self.swift('list') |
| 47 | |
| 48 | def test_swift_stat(self): |
| 49 | output = self.swift('stat') |
| 50 | entries = ['Account', 'Containers', 'Objects', 'Bytes', 'Content-Type', |
| 51 | 'X-Timestamp', 'X-Trans-Id'] |
| 52 | for entry in entries: |
| 53 | self.assertTrue(entry in output) |
| 54 | |
| 55 | def test_swift_capabilities(self): |
| 56 | output = self.swift('capabilities') |
| 57 | entries = ['account_listing_limit', 'container_listing_limit', |
| 58 | 'max_file_size', 'Additional middleware'] |
| 59 | for entry in entries: |
| 60 | self.assertTrue(entry in output) |
| 61 | |
| 62 | def test_swift_help(self): |
| 63 | help_text = self.swift('', flags='--help') |
| 64 | lines = help_text.split('\n') |
| 65 | self.assertFirstLineStartsWith(lines, 'Usage: swift') |
| 66 | |
| 67 | commands = [] |
| 68 | cmds_start = lines.index('Positional arguments:') |
| 69 | cmds_end = lines.index('Examples:') |
| 70 | command_pattern = re.compile('^ {4}([a-z0-9\-\_]+)') |
| 71 | for line in lines[cmds_start:cmds_end]: |
| 72 | match = command_pattern.match(line) |
| 73 | if match: |
| 74 | commands.append(match.group(1)) |
| 75 | commands = set(commands) |
| 76 | wanted_commands = set(('stat', 'list', 'delete', |
| 77 | 'download', 'post', 'upload')) |
| 78 | self.assertFalse(wanted_commands - commands) |
| 79 | |
| 80 | # Optional arguments: |
| 81 | |
| 82 | def test_swift_version(self): |
| 83 | self.swift('', flags='--version') |
| 84 | |
| 85 | def test_swift_debug_list(self): |
| 86 | self.swift('list', flags='--debug') |
| 87 | |
| 88 | def test_swift_retries_list(self): |
| 89 | self.swift('list', flags='--retries 3') |
| 90 | |
| 91 | def test_swift_region_list(self): |
| 92 | region = CONF.object_storage.region |
| 93 | if not region: |
| 94 | region = CONF.identity.region |
| 95 | self.swift('list', flags='--os-region-name ' + region) |