blob: 4b14c3cfd0447f5667733d07b0bdae20add54356 [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
18import logging
19import re
20import subprocess
21
22import cli
23
24
25LOG = logging.getLogger(__name__)
26
27
28class SimpleReadOnlyKeystoneClientTest(cli.ClientTestBase):
29 """Basic, read-only tests for Keystone 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_admin_fake_action(self):
37 self.assertRaises(subprocess.CalledProcessError,
38 self.keystone,
39 'this-does-not-exist')
40
41 def test_admin_catalog_list(self):
42 out = self.keystone('catalog')
43 catalog = self.parser.details_multiple(out, with_label=True)
44 for svc in catalog:
45 self.assertTrue(svc['__label'].startswith('Service:'))
46
47 def test_admin_endpoint_list(self):
48 out = self.keystone('endpoint-list')
49 endpoints = self.parser.listing(out)
50 self.assertTableStruct(endpoints, [
51 'id', 'region', 'publicurl', 'internalurl',
52 'adminurl', 'service_id'])
53
54 def test_admin_endpoint_service_match(self):
55 endpoints = self.parser.listing(self.keystone('endpoint-list'))
56 services = self.parser.listing(self.keystone('service-list'))
57 svc_by_id = {}
58 for svc in services:
59 svc_by_id[svc['id']] = svc
60 for endpoint in endpoints:
61 self.assertIn(endpoint['service_id'], svc_by_id)
62
63 def test_admin_role_list(self):
64 roles = self.parser.listing(self.keystone('role-list'))
65 self.assertTableStruct(roles, ['id', 'name'])
66
67 def test_admin_service_list(self):
68 services = self.parser.listing(self.keystone('service-list'))
69 self.assertTableStruct(services, ['id', 'name', 'type', 'description'])
70
71 def test_admin_tenant_list(self):
72 tenants = self.parser.listing(self.keystone('tenant-list'))
73 self.assertTableStruct(tenants, ['id', 'name', 'enabled'])
74
75 def test_admin_user_list(self):
76 users = self.parser.listing(self.keystone('user-list'))
77 self.assertTableStruct(users, [
78 'id', 'name', 'enabled', 'email'])
79
80 def test_admin_user_role_list(self):
81 user_roles = self.parser.listing(self.keystone('user-role-list'))
82 self.assertTableStruct(user_roles, [
83 'id', 'name', 'user_id', 'tenant_id'])
84
85 def test_admin_discover(self):
86 discovered = self.keystone('discover')
87 self.assertIn('Keystone found at http', discovered)
88 self.assertIn('supports version', discovered)
89
90 def test_admin_help(self):
91 help_text = self.keystone('help')
92 lines = help_text.split('\n')
93 self.assertTrue(lines[0].startswith('usage: keystone'))
94
95 commands = []
96 cmds_start = lines.index('Positional arguments:')
97 cmds_end = lines.index('Optional arguments:')
98 command_pattern = re.compile('^ {4}([a-z0-9\-\_]+)')
99 for line in lines[cmds_start:cmds_end]:
100 match = command_pattern.match(line)
101 if match:
102 commands.append(match.group(1))
103 commands = set(commands)
104 wanted_commands = set(('catalog', 'endpoint-list', 'help',
105 'token-get', 'discover', 'bootstrap'))
106 self.assertFalse(wanted_commands - commands)
107
108 def test_admin_bashcompletion(self):
109 self.keystone('bash-completion')