Add consumes quota field support

Cinder microversion v3.65 adds consumes_quota key to volume and
snapshots as a way to differentiate between use generated resources and
temporary ones.

This patch adds support for this microversion and presents the
consumes_quota field when the server sends it (which only happens when
we request this microversion).

Change-Id: I524490aa988fa4d654bfa8050d89cf99ce50bb4b
Depends-On: I655a47fc75ddc11caf1defe984d9a66a9ad5a2e7
Implements: blueprint temp-resources
This commit is contained in:
Gorka Eguileor
2021-04-21 16:01:11 +02:00
committed by Brian Rosmaita
parent fe1a377527
commit f94908008e
3 changed files with 17 additions and 16 deletions

View File

@@ -26,7 +26,7 @@ LOG = logging.getLogger(__name__)
# key is unsupported version, value is appropriate supported alternative # key is unsupported version, value is appropriate supported alternative
REPLACEMENT_VERSIONS = {"1": "3", "2": "3"} REPLACEMENT_VERSIONS = {"1": "3", "2": "3"}
MAX_VERSION = "3.64" MAX_VERSION = "3.65"
MIN_VERSION = "3.0" MIN_VERSION = "3.0"
_SUBSTITUTIONS = {} _SUBSTITUTIONS = {}

View File

@@ -1318,12 +1318,14 @@ class ShellTest(utils.TestCase):
self.assert_called('POST', '/backups', body=expected) self.assert_called('POST', '/backups', body=expected)
@mock.patch("cinderclient.utils.print_list") @mock.patch("cinderclient.utils.print_list")
def test_snapshot_list_with_userid(self, mock_print_list): def test_snapshot_list(self, mock_print_list):
"""Ensure 3.41 provides User ID header.""" """Ensure we always present all existing fields when listing snaps."""
self.run_command('--os-volume-api-version 3.41 snapshot-list') self.run_command('--os-volume-api-version 3.65 snapshot-list')
self.assert_called('GET', '/snapshots/detail') self.assert_called('GET', '/snapshots/detail')
columns = ['ID', 'Volume ID', 'Status', 'Name', 'Size', 'User ID'] columns = ['ID', 'Volume ID', 'Status', 'Name', 'Size',
'Consumes Quota', 'User ID']
mock_print_list.assert_called_once_with(mock.ANY, columns, mock_print_list.assert_called_once_with(mock.ANY, columns,
exclude_unavailable=True,
sortby_index=0) sortby_index=0)
@mock.patch('cinderclient.v3.volumes.Volume.migrate_volume') @mock.patch('cinderclient.v3.volumes.Volume.migrate_volume')

View File

@@ -507,8 +507,8 @@ def do_list(cs, args):
[x.title().strip() for x in field_titles]) if k != 'Id'] [x.title().strip() for x in field_titles]) if k != 'Id']
key_list.extend(unique_titles) key_list.extend(unique_titles)
else: else:
key_list = ['ID', 'Status', 'Name', 'Size', 'Volume Type', key_list = ['ID', 'Status', 'Name', 'Size', 'Consumes Quota',
'Bootable', 'Attached to'] 'Volume Type', 'Bootable', 'Attached to']
# If all_tenants is specified, print # If all_tenants is specified, print
# Tenant ID as well. # Tenant ID as well.
if search_opts['all_tenants']: if search_opts['all_tenants']:
@@ -2173,15 +2173,14 @@ def do_snapshot_list(cs, args):
shell_utils.translate_volume_snapshot_keys(snapshots) shell_utils.translate_volume_snapshot_keys(snapshots)
sortby_index = None if args.sort else 0 sortby_index = None if args.sort else 0
if cs.api_version >= api_versions.APIVersion("3.41"): # It's the server's responsibility to return the appropriate fields for the
utils.print_list(snapshots, # requested microversion, we present all known fields and skip those that
['ID', 'Volume ID', 'Status', # are missing.
'Name', 'Size', 'User ID'], utils.print_list(snapshots,
sortby_index=sortby_index) ['ID', 'Volume ID', 'Status', 'Name', 'Size',
else: 'Consumes Quota', 'User ID'],
utils.print_list(snapshots, exclude_unavailable=True,
['ID', 'Volume ID', 'Status', 'Name', 'Size'], sortby_index=sortby_index)
sortby_index=sortby_index)
if show_count: if show_count:
print("Snapshot in total: %s" % total_count) print("Snapshot in total: %s" % total_count)