| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 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 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 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 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 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 |
|
| 76 |
|
| 77 |
cmds_end = lines.index('Options:') |
| 78 |
except ValueError: |
| 79 |
|
| 80 |
|
| 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') |