Debian Codegraph @

glanceclient/tests/functional/v2/test_readonly_glance.py

raw symbols SCIP
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 import re
14
15 from tempest.lib import exceptions
16
17 from glanceclient.tests.functional import base
18
19
20 class SimpleReadOnlyGlanceClientTest(base.ClientTestBase):
21
22 """Read only functional python-glanceclient tests.
23
24 This only exercises client commands that are read only.
25 """
26
27 def test_list_v2(self):
28 out = self.glance('--os-image-api-version 2 image-list')
29 endpoints = self.parser.listing(out)
30 self.assertTableStruct(endpoints, ['ID', 'Name'])
31
32 def test_fake_action(self):
33 self.assertRaises(exceptions.CommandFailed,
34 self.glance,
35 'this-does-not-exist')
36
37 def test_member_list_v2(self):
38 try:
39 # NOTE(flwang): If set disk-format and container-format, Jenkins
40 # will raise an error said can't recognize the params, though it
41 # works fine at local. Without the two params, Glance will
42 # complain. So we just catch the exception can skip it.
43 self.glance('--os-image-api-version 2 image-create --name temp')
44 except Exception:
45 pass
46 out = self.glance('--os-image-api-version 2 image-list'
47 ' --visibility private')
48 image_list = self.parser.listing(out)
49 # NOTE(flwang): Because the member-list command of v2 is using
50 # image-id as required parameter, so we have to get a valid image id
51 # based on current environment. If there is no valid image id, we will
52 # pass in a fake one and expect a 404 error.
53 if len(image_list) > 0:
54 param_image_id = '--image-id %s' % image_list[0]['ID']
55 out = self.glance('--os-image-api-version 2 member-list',
56 params=param_image_id)
57 endpoints = self.parser.listing(out)
58 self.assertTableStruct(endpoints,
59 ['Image ID', 'Member ID', 'Status'])
60 else:
61 param_image_id = '--image-id fake_image_id'
62 self.assertRaises(exceptions.CommandFailed,
63 self.glance,
64 '--os-image-api-version 2 member-list',
65 params=param_image_id)
66
67 def test_help(self):
68 help_text = self.glance('--os-image-api-version 2 help')
69 lines = help_text.split('\n')
70 self.assertFirstLineStartsWith(lines, 'usage: glance')
71
72 commands = []
73 cmds_start = lines.index('Positional arguments:')
74 try:
75 # Starting in Python 3.10, argparse displays options in the
76 # "Options:" section...
77 cmds_end = lines.index('Options:')
78 except ValueError:
79 # ... but before Python 3.10, options were displayed in the
80 # "Optional arguments:" section.
81 cmds_end = lines.index('Optional arguments:')
82 command_pattern = re.compile(r'^ {4}([a-z0-9\-\_]+)')
83 for line in lines[cmds_start:cmds_end]:
84 match = command_pattern.match(line)
85 if match:
86 commands.append(match.group(1))
87 commands = set(commands)
88 wanted_commands = {'bash-completion', 'help',
89 'image-create', 'image-deactivate', 'image-delete',
90 'image-download', 'image-list', 'image-reactivate',
91 'image-show', 'image-tag-delete',
92 'image-tag-update', 'image-update', 'image-upload',
93 'location-add', 'location-delete',
94 'location-update', 'member-create', 'member-delete',
95 'member-list', 'member-update', 'task-create',
96 'task-list', 'task-show'}
97 self.assertFalse(wanted_commands - commands)
98
99 def test_version(self):
100 self.glance('', flags='--version')
101
102 def test_debug_list(self):
103 self.glance('--os-image-api-version 2 image-list', flags='--debug')