afazekas | f35f940 | 2013-03-25 14:51:13 +0100 | [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 cli |
| 23 | |
| 24 | |
| 25 | LOG = logging.getLogger(__name__) |
| 26 | |
| 27 | |
| 28 | class SimpleReadOnlyGlanceClientTest(cli.ClientTestBase): |
| 29 | """Basic, read-only tests for Glance 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 | |
| 36 | def test_glance_fake_action(self): |
| 37 | self.assertRaises(subprocess.CalledProcessError, |
| 38 | self.glance, |
| 39 | 'this-does-not-exist') |
| 40 | |
| 41 | def test_glance_image_list(self): |
| 42 | out = self.glance('image-list') |
| 43 | endpoints = self.parser.listing(out) |
| 44 | self.assertTableStruct(endpoints, [ |
| 45 | 'ID', 'Name', 'Disk Format', 'Container Format', |
| 46 | 'Size', 'Status']) |
| 47 | |
| 48 | def test_glance_help(self): |
| 49 | help_text = self.glance('help') |
| 50 | lines = help_text.split('\n') |
| 51 | self.assertTrue(lines[0].startswith('usage: glance')) |
| 52 | |
| 53 | commands = [] |
| 54 | cmds_start = lines.index('Positional arguments:') |
| 55 | cmds_end = lines.index('Optional arguments:') |
| 56 | command_pattern = re.compile('^ {4}([a-z0-9\-\_]+)') |
| 57 | for line in lines[cmds_start:cmds_end]: |
| 58 | match = command_pattern.match(line) |
| 59 | if match: |
| 60 | commands.append(match.group(1)) |
| 61 | commands = set(commands) |
| 62 | wanted_commands = set(('image-create', 'image-delete', 'help', |
| 63 | 'image-download', 'image-show', 'image-update', |
| 64 | 'member-add', 'member-create', 'member-delete', |
| 65 | 'member-list')) |
| 66 | self.assertFalse(wanted_commands - commands) |