blob: a5a229c196eb170c72fd9f16adace78815ae5e18 [file] [log] [blame]
afazekasf35f9402013-03-25 14:51:13 +01001# 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
afazekasf35f9402013-03-25 14:51:13 +010018import re
19import subprocess
20
wingwj5d596622013-10-11 18:05:29 +080021from oslo.config import cfg
22
Sean Daguef6825792013-05-08 13:51:26 -040023import tempest.cli
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040024from tempest.openstack.common import log as logging
afazekasf35f9402013-03-25 14:51:13 +010025
wingwj5d596622013-10-11 18:05:29 +080026CONF = cfg.CONF
27
afazekasf35f9402013-03-25 14:51:13 +010028
29LOG = logging.getLogger(__name__)
30
31
Sean Daguef6825792013-05-08 13:51:26 -040032class SimpleReadOnlyGlanceClientTest(tempest.cli.ClientTestBase):
afazekasf35f9402013-03-25 14:51:13 +010033 """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
wingwj5d596622013-10-11 18:05:29 +080052 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
afazekasf35f9402013-03-25 14:51:13 +010060 def test_glance_help(self):
61 help_text = self.glance('help')
62 lines = help_text.split('\n')
Pavel Sedlák4c18fa12013-08-22 21:29:45 +020063 self.assertFirstLineStartsWith(lines, 'usage: glance')
afazekasf35f9402013-03-25 14:51:13 +010064
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)
wingwj5d596622013-10-11 18:05:29 +080079
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)