Correct parsing of volume metadata
Volume metadata supplied via the command line is incorrectly parsed, converting each character into a key with “None” as the corresponding value. This bug fix corrects the parsing and also includes regression tests when metadata is provided when creating a volume. Change-Id: I8c093df59ea4de2e2a1b7cf3ac7c4624c159fb66 Implements: blueprint encrypt-cinder-volumes
This commit is contained in:
@@ -94,7 +94,7 @@ def _translate_volume_snapshot_keys(collection):
|
|||||||
|
|
||||||
def _extract_metadata(args):
|
def _extract_metadata(args):
|
||||||
metadata = {}
|
metadata = {}
|
||||||
for metadatum in args.metadata[0]:
|
for metadatum in args.metadata:
|
||||||
# unset doesn't require a val, so we have the if/else
|
# unset doesn't require a val, so we have the if/else
|
||||||
if '=' in metadatum:
|
if '=' in metadatum:
|
||||||
(key, value) = metadatum.split('=', 1)
|
(key, value) = metadatum.split('=', 1)
|
||||||
@@ -288,7 +288,6 @@ def do_rename(cs, args):
|
|||||||
@utils.arg('metadata',
|
@utils.arg('metadata',
|
||||||
metavar='<key=value>',
|
metavar='<key=value>',
|
||||||
nargs='+',
|
nargs='+',
|
||||||
action='append',
|
|
||||||
default=[],
|
default=[],
|
||||||
help='Metadata to set/unset (only key is necessary on unset)')
|
help='Metadata to set/unset (only key is necessary on unset)')
|
||||||
@utils.service_type('volume')
|
@utils.service_type('volume')
|
||||||
|
@@ -21,6 +21,7 @@ import fixtures
|
|||||||
|
|
||||||
from cinderclient import client
|
from cinderclient import client
|
||||||
from cinderclient import shell
|
from cinderclient import shell
|
||||||
|
from cinderclient.v1 import shell as shell_v1
|
||||||
from tests.v1 import fakes
|
from tests.v1 import fakes
|
||||||
from tests import utils
|
from tests import utils
|
||||||
|
|
||||||
@@ -70,6 +71,25 @@ class ShellTest(utils.TestCase):
|
|||||||
def assert_called_anytime(self, method, url, body=None):
|
def assert_called_anytime(self, method, url, body=None):
|
||||||
return self.shell.cs.assert_called_anytime(method, url, body)
|
return self.shell.cs.assert_called_anytime(method, url, body)
|
||||||
|
|
||||||
|
def test_extract_metadata(self):
|
||||||
|
# mimic the result of argparse's parse_args() method
|
||||||
|
class Arguments:
|
||||||
|
def __init__(self, metadata=[]):
|
||||||
|
self.metadata = metadata
|
||||||
|
|
||||||
|
inputs = [
|
||||||
|
([], {}),
|
||||||
|
(["key=value"], {"key": "value"}),
|
||||||
|
(["key"], {"key": None}),
|
||||||
|
(["k1=v1", "k2=v2"], {"k1": "v1", "k2": "v2"}),
|
||||||
|
(["k1=v1", "k2"], {"k1": "v1", "k2": None}),
|
||||||
|
(["k1", "k2=v2"], {"k1": None, "k2": "v2"})
|
||||||
|
]
|
||||||
|
|
||||||
|
for input in inputs:
|
||||||
|
args = Arguments(metadata=input[0])
|
||||||
|
self.assertEquals(shell_v1._extract_metadata(args), input[1])
|
||||||
|
|
||||||
def test_list(self):
|
def test_list(self):
|
||||||
self.run_command('list')
|
self.run_command('list')
|
||||||
# NOTE(jdg): we default to detail currently
|
# NOTE(jdg): we default to detail currently
|
||||||
|
Reference in New Issue
Block a user