blob: 271a18c05fd24df4562c5babc1a33323a655fdeb [file] [log] [blame]
Pavel Sedlák5ce5c032013-02-25 18:41:30 +01001# Copyright 2013 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
Pavel Sedlák5ce5c032013-02-25 18:41:30 +010016import re
17import subprocess
18
Matt Riedemannab038c92013-08-06 06:56:48 -070019from oslo.config import cfg
20
Sean Daguef6825792013-05-08 13:51:26 -040021import tempest.cli
Matthew Treinishf4a9b0f2013-07-26 16:58:26 -040022from tempest.openstack.common import log as logging
Pavel Sedlák5ce5c032013-02-25 18:41:30 +010023
Matt Riedemannab038c92013-08-06 06:56:48 -070024CONF = cfg.CONF
25
Pavel Sedlák5ce5c032013-02-25 18:41:30 +010026
27LOG = logging.getLogger(__name__)
28
29
Sean Daguef6825792013-05-08 13:51:26 -040030class SimpleReadOnlyKeystoneClientTest(tempest.cli.ClientTestBase):
Pavel Sedlák5ce5c032013-02-25 18:41:30 +010031 """Basic, read-only tests for Keystone CLI client.
32
33 Checks return values and output of read-only commands.
34 These tests do not presume any content, nor do they create
35 their own. They only verify the structure of output if present.
36 """
37
38 def test_admin_fake_action(self):
39 self.assertRaises(subprocess.CalledProcessError,
40 self.keystone,
41 'this-does-not-exist')
42
43 def test_admin_catalog_list(self):
44 out = self.keystone('catalog')
45 catalog = self.parser.details_multiple(out, with_label=True)
46 for svc in catalog:
Matthew Treinish49681802013-08-28 19:07:30 -040047 if svc.get('__label'):
48 self.assertTrue(svc['__label'].startswith('Service:'),
49 msg=('Invalid beginning of service block: '
50 '%s' % svc['__label']))
Dirk Muellereb1a3ff2013-09-30 19:27:38 +020051 # check that region and publicURL exists. One might also
52 # check for adminURL and internalURL. id seems to be optional
53 # and is missing in the catalog backend
54 self.assertIn('publicURL', svc.keys())
Matthew Treinish49681802013-08-28 19:07:30 -040055 self.assertIn('region', svc.keys())
Pavel Sedlák5ce5c032013-02-25 18:41:30 +010056
57 def test_admin_endpoint_list(self):
58 out = self.keystone('endpoint-list')
59 endpoints = self.parser.listing(out)
60 self.assertTableStruct(endpoints, [
61 'id', 'region', 'publicurl', 'internalurl',
62 'adminurl', 'service_id'])
63
64 def test_admin_endpoint_service_match(self):
65 endpoints = self.parser.listing(self.keystone('endpoint-list'))
66 services = self.parser.listing(self.keystone('service-list'))
67 svc_by_id = {}
68 for svc in services:
69 svc_by_id[svc['id']] = svc
70 for endpoint in endpoints:
71 self.assertIn(endpoint['service_id'], svc_by_id)
72
73 def test_admin_role_list(self):
74 roles = self.parser.listing(self.keystone('role-list'))
75 self.assertTableStruct(roles, ['id', 'name'])
76
77 def test_admin_service_list(self):
78 services = self.parser.listing(self.keystone('service-list'))
79 self.assertTableStruct(services, ['id', 'name', 'type', 'description'])
80
81 def test_admin_tenant_list(self):
82 tenants = self.parser.listing(self.keystone('tenant-list'))
83 self.assertTableStruct(tenants, ['id', 'name', 'enabled'])
84
85 def test_admin_user_list(self):
86 users = self.parser.listing(self.keystone('user-list'))
87 self.assertTableStruct(users, [
88 'id', 'name', 'enabled', 'email'])
89
90 def test_admin_user_role_list(self):
91 user_roles = self.parser.listing(self.keystone('user-role-list'))
92 self.assertTableStruct(user_roles, [
93 'id', 'name', 'user_id', 'tenant_id'])
94
95 def test_admin_discover(self):
96 discovered = self.keystone('discover')
97 self.assertIn('Keystone found at http', discovered)
98 self.assertIn('supports version', discovered)
99
100 def test_admin_help(self):
101 help_text = self.keystone('help')
102 lines = help_text.split('\n')
Pavel Sedlák4c18fa12013-08-22 21:29:45 +0200103 self.assertFirstLineStartsWith(lines, 'usage: keystone')
Pavel Sedlák5ce5c032013-02-25 18:41:30 +0100104
105 commands = []
106 cmds_start = lines.index('Positional arguments:')
107 cmds_end = lines.index('Optional arguments:')
108 command_pattern = re.compile('^ {4}([a-z0-9\-\_]+)')
109 for line in lines[cmds_start:cmds_end]:
110 match = command_pattern.match(line)
111 if match:
112 commands.append(match.group(1))
113 commands = set(commands)
114 wanted_commands = set(('catalog', 'endpoint-list', 'help',
115 'token-get', 'discover', 'bootstrap'))
116 self.assertFalse(wanted_commands - commands)
117
118 def test_admin_bashcompletion(self):
119 self.keystone('bash-completion')
Joe Gordonc4862da2013-06-03 11:18:52 -0700120
121 # Optional arguments:
122
123 def test_admin_version(self):
124 self.keystone('', flags='--version')
125
126 def test_admin_debug_list(self):
127 self.keystone('catalog', flags='--debug')
128
129 def test_admin_timeout(self):
Matt Riedemannab038c92013-08-06 06:56:48 -0700130 self.keystone('catalog', flags='--timeout %d' % CONF.cli.timeout)