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 | |
afazekas | f35f940 | 2013-03-25 14:51:13 +0100 | [diff] [blame] | 18 | import re |
| 19 | import subprocess |
| 20 | |
wingwj | 5d59662 | 2013-10-11 18:05:29 +0800 | [diff] [blame] | 21 | from oslo.config import cfg |
| 22 | |
Sean Dague | f682579 | 2013-05-08 13:51:26 -0400 | [diff] [blame] | 23 | import tempest.cli |
Matthew Treinish | f4a9b0f | 2013-07-26 16:58:26 -0400 | [diff] [blame] | 24 | from tempest.openstack.common import log as logging |
afazekas | f35f940 | 2013-03-25 14:51:13 +0100 | [diff] [blame] | 25 | |
wingwj | 5d59662 | 2013-10-11 18:05:29 +0800 | [diff] [blame] | 26 | CONF = cfg.CONF |
| 27 | |
afazekas | f35f940 | 2013-03-25 14:51:13 +0100 | [diff] [blame] | 28 | |
| 29 | LOG = logging.getLogger(__name__) |
| 30 | |
| 31 | |
Sean Dague | f682579 | 2013-05-08 13:51:26 -0400 | [diff] [blame] | 32 | class SimpleReadOnlyGlanceClientTest(tempest.cli.ClientTestBase): |
afazekas | f35f940 | 2013-03-25 14:51:13 +0100 | [diff] [blame] | 33 | """Basic, read-only tests for Glance CLI client. |
| 34 | |
| 35 | Checks return values and output of read-only commands. |
| 36 | These tests do not presume any content, nor do they create |
| 37 | their own. They only verify the structure of output if present. |
| 38 | """ |
| 39 | |
| 40 | def test_glance_fake_action(self): |
| 41 | self.assertRaises(subprocess.CalledProcessError, |
| 42 | self.glance, |
| 43 | 'this-does-not-exist') |
| 44 | |
| 45 | def test_glance_image_list(self): |
| 46 | out = self.glance('image-list') |
| 47 | endpoints = self.parser.listing(out) |
| 48 | self.assertTableStruct(endpoints, [ |
| 49 | 'ID', 'Name', 'Disk Format', 'Container Format', |
| 50 | 'Size', 'Status']) |
| 51 | |
wingwj | 5d59662 | 2013-10-11 18:05:29 +0800 | [diff] [blame] | 52 | def test_glance_member_list(self): |
| 53 | tenant_name = '--tenant-id %s' % self.identity.admin_tenant_name |
| 54 | out = self.glance('member-list', |
| 55 | params=tenant_name) |
| 56 | endpoints = self.parser.listing(out) |
| 57 | self.assertTableStruct(endpoints, |
| 58 | ['Image ID', 'Member ID', 'Can Share']) |
| 59 | |
afazekas | f35f940 | 2013-03-25 14:51:13 +0100 | [diff] [blame] | 60 | def test_glance_help(self): |
| 61 | help_text = self.glance('help') |
| 62 | lines = help_text.split('\n') |
Pavel Sedlák | 4c18fa1 | 2013-08-22 21:29:45 +0200 | [diff] [blame] | 63 | self.assertFirstLineStartsWith(lines, 'usage: glance') |
afazekas | f35f940 | 2013-03-25 14:51:13 +0100 | [diff] [blame] | 64 | |
| 65 | commands = [] |
| 66 | cmds_start = lines.index('Positional arguments:') |
| 67 | cmds_end = lines.index('Optional arguments:') |
| 68 | command_pattern = re.compile('^ {4}([a-z0-9\-\_]+)') |
| 69 | for line in lines[cmds_start:cmds_end]: |
| 70 | match = command_pattern.match(line) |
| 71 | if match: |
| 72 | commands.append(match.group(1)) |
| 73 | commands = set(commands) |
| 74 | wanted_commands = set(('image-create', 'image-delete', 'help', |
| 75 | 'image-download', 'image-show', 'image-update', |
| 76 | 'member-add', 'member-create', 'member-delete', |
| 77 | 'member-list')) |
| 78 | self.assertFalse(wanted_commands - commands) |
wingwj | 5d59662 | 2013-10-11 18:05:29 +0800 | [diff] [blame] | 79 | |
| 80 | # Optional arguments: |
| 81 | |
| 82 | def test_glance_version(self): |
| 83 | self.glance('', flags='--version') |
| 84 | |
| 85 | def test_glance_debug_list(self): |
| 86 | self.glance('image-list', flags='--debug') |
| 87 | |
| 88 | def test_glance_timeout(self): |
| 89 | self.glance('image-list', flags='--timeout %d' % CONF.cli.timeout) |