blob: 1e8009f41316b8471032c4857ddd61606d4323c2 [file] [log] [blame]
Pavel Sedlák5ce5c032013-02-25 18:41:30 +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
Pavel Sedlák5ce5c032013-02-25 18:41:30 +010018import re
19import subprocess
20
Matt Riedemannab038c92013-08-06 06:56:48 -070021from 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
Pavel Sedlák5ce5c032013-02-25 18:41:30 +010025
Matt Riedemannab038c92013-08-06 06:56:48 -070026CONF = cfg.CONF
27
Pavel Sedlák5ce5c032013-02-25 18:41:30 +010028
29LOG = logging.getLogger(__name__)
30
31
Sean Daguef6825792013-05-08 13:51:26 -040032class SimpleReadOnlyKeystoneClientTest(tempest.cli.ClientTestBase):
Pavel Sedlák5ce5c032013-02-25 18:41:30 +010033 """Basic, read-only tests for Keystone 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_admin_fake_action(self):
41 self.assertRaises(subprocess.CalledProcessError,
42 self.keystone,
43 'this-does-not-exist')
44
45 def test_admin_catalog_list(self):
46 out = self.keystone('catalog')
47 catalog = self.parser.details_multiple(out, with_label=True)
48 for svc in catalog:
Pavel Sedlák4c18fa12013-08-22 21:29:45 +020049 self.assertTrue(svc['__label'].startswith('Service:'),
50 msg=('Invalid beginning of service block: %s' %
51 svc['__label']))
Pavel Sedlák5ce5c032013-02-25 18:41:30 +010052
53 def test_admin_endpoint_list(self):
54 out = self.keystone('endpoint-list')
55 endpoints = self.parser.listing(out)
56 self.assertTableStruct(endpoints, [
57 'id', 'region', 'publicurl', 'internalurl',
58 'adminurl', 'service_id'])
59
60 def test_admin_endpoint_service_match(self):
61 endpoints = self.parser.listing(self.keystone('endpoint-list'))
62 services = self.parser.listing(self.keystone('service-list'))
63 svc_by_id = {}
64 for svc in services:
65 svc_by_id[svc['id']] = svc
66 for endpoint in endpoints:
67 self.assertIn(endpoint['service_id'], svc_by_id)
68
69 def test_admin_role_list(self):
70 roles = self.parser.listing(self.keystone('role-list'))
71 self.assertTableStruct(roles, ['id', 'name'])
72
73 def test_admin_service_list(self):
74 services = self.parser.listing(self.keystone('service-list'))
75 self.assertTableStruct(services, ['id', 'name', 'type', 'description'])
76
77 def test_admin_tenant_list(self):
78 tenants = self.parser.listing(self.keystone('tenant-list'))
79 self.assertTableStruct(tenants, ['id', 'name', 'enabled'])
80
81 def test_admin_user_list(self):
82 users = self.parser.listing(self.keystone('user-list'))
83 self.assertTableStruct(users, [
84 'id', 'name', 'enabled', 'email'])
85
86 def test_admin_user_role_list(self):
87 user_roles = self.parser.listing(self.keystone('user-role-list'))
88 self.assertTableStruct(user_roles, [
89 'id', 'name', 'user_id', 'tenant_id'])
90
91 def test_admin_discover(self):
92 discovered = self.keystone('discover')
93 self.assertIn('Keystone found at http', discovered)
94 self.assertIn('supports version', discovered)
95
96 def test_admin_help(self):
97 help_text = self.keystone('help')
98 lines = help_text.split('\n')
Pavel Sedlák4c18fa12013-08-22 21:29:45 +020099 self.assertFirstLineStartsWith(lines, 'usage: keystone')
Pavel Sedlák5ce5c032013-02-25 18:41:30 +0100100
101 commands = []
102 cmds_start = lines.index('Positional arguments:')
103 cmds_end = lines.index('Optional arguments:')
104 command_pattern = re.compile('^ {4}([a-z0-9\-\_]+)')
105 for line in lines[cmds_start:cmds_end]:
106 match = command_pattern.match(line)
107 if match:
108 commands.append(match.group(1))
109 commands = set(commands)
110 wanted_commands = set(('catalog', 'endpoint-list', 'help',
111 'token-get', 'discover', 'bootstrap'))
112 self.assertFalse(wanted_commands - commands)
113
114 def test_admin_bashcompletion(self):
115 self.keystone('bash-completion')
Joe Gordonc4862da2013-06-03 11:18:52 -0700116
117 # Optional arguments:
118
119 def test_admin_version(self):
120 self.keystone('', flags='--version')
121
122 def test_admin_debug_list(self):
123 self.keystone('catalog', flags='--debug')
124
125 def test_admin_timeout(self):
Matt Riedemannab038c92013-08-06 06:56:48 -0700126 self.keystone('catalog', flags='--timeout %d' % CONF.cli.timeout)