Check the volume metadata value is a string or not
When creating or updating the metadata for a volume, if user give a nested value, cinder-api will raise a 500 error, the root cause is a syntax error in sql statement. According to cinder api ref [1], the metadata value should be a string. [1] https://developer.openstack.org/api-ref/block-storage/v3/?expanded=update-a-volume-s-metadata-detail#update-a-volume-s-metadata Change-Id: I6febfe177fb49372bb6413d3b6478cb762170b2a Closes-Bug: #1690363
This commit is contained in:
parent
07857fb572
commit
4c230df10e
cinder
@ -1494,3 +1494,20 @@ class TestLogLevels(test.TestCase):
|
||||
utils.set_log_levels(prefix, 'debug')
|
||||
levels = utils.get_log_levels(prefix)
|
||||
self.assertEqual('DEBUG', levels[prefix])
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class TestCheckMetadataProperties(test.TestCase):
|
||||
@ddt.data(
|
||||
{'a': {'foo': 'bar'}}, # value is a nested dict
|
||||
{'a': 123}, # value is an integer
|
||||
{'a': 123.4}, # value is a float
|
||||
{'a': True}, # value is a bool
|
||||
{'a': ('foo', 'bar')}, # value is a tuple
|
||||
{'a': []}, # value is a list
|
||||
{'a': None} # value is None
|
||||
)
|
||||
def test_metadata_value_not_string_raise(self, meta):
|
||||
self.assertRaises(exception.InvalidVolumeMetadata,
|
||||
utils.check_metadata_properties,
|
||||
meta)
|
||||
|
@ -165,22 +165,19 @@ def check_metadata_properties(metadata=None):
|
||||
metadata = {}
|
||||
|
||||
for k, v in metadata.items():
|
||||
if len(k) == 0:
|
||||
msg = _("Metadata property key blank.")
|
||||
LOG.debug(msg)
|
||||
raise exception.InvalidVolumeMetadata(reason=msg)
|
||||
try:
|
||||
check_string_length(k, "Metadata key: %s" % k, min_length=1)
|
||||
check_string_length(v, "Value for metadata key: %s" % k)
|
||||
except exception.InvalidInput as exc:
|
||||
raise exception.InvalidVolumeMetadata(reason=exc)
|
||||
# for backward compatibility
|
||||
if len(k) > 255:
|
||||
msg = _("Metadata property key %s greater than 255 "
|
||||
"characters.") % k
|
||||
LOG.debug(msg)
|
||||
raise exception.InvalidVolumeMetadataSize(reason=msg)
|
||||
if v is None:
|
||||
msg = _("Metadata property key '%s' value is None.") % k
|
||||
raise exception.InvalidVolumeMetadata(reason=msg)
|
||||
if len(v) > 255:
|
||||
msg = _("Metadata property key %s value greater than "
|
||||
"255 characters.") % k
|
||||
LOG.debug(msg)
|
||||
raise exception.InvalidVolumeMetadataSize(reason=msg)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user