def snapshot_metadata_update(context, snapshot_id, metadata, delete):
"""Update metadata if it exists, otherwise create it."""
- IMPL.snapshot_metadata_update(context, snapshot_id, metadata, delete)
+ return IMPL.snapshot_metadata_update(context, snapshot_id,
+ metadata, delete)
####################
meta_ref.update(item)
meta_ref.save(session=session)
- return metadata
+ return snapshot_metadata_get(context, snapshot_id)
###################
return stub_snapshot_metadata()
+def return_create_snapshot_metadata_insensitive(context, snapshot_id,
+ metadata, delete):
+ return stub_snapshot_metadata_insensitive()
+
+
+def return_new_snapshot_metadata(context, snapshot_id, metadata, delete):
+ return stub_new_snapshot_metadata()
+
+
def return_snapshot_metadata(context, snapshot_id):
if not isinstance(snapshot_id, str) or not len(snapshot_id) == 36:
msg = 'id %s must be a uuid in return snapshot metadata' % snapshot_id
return {}
+def return_empty_container_metadata(context, snapshot_id, metadata, delete):
+ return {}
+
+
def delete_snapshot_metadata(context, snapshot_id, key):
pass
return metadata
+def stub_snapshot_metadata_insensitive():
+ metadata = {
+ "key1": "value1",
+ "key2": "value2",
+ "key3": "value3",
+ "KEY4": "value4",
+ }
+ return metadata
+
+
+def stub_new_snapshot_metadata():
+ metadata = {
+ 'key10': 'value10',
+ 'key99': 'value99',
+ 'KEY20': 'value20',
+ }
+ return metadata
+
+
def stub_max_snapshot_metadata():
metadata = {"metadata": {}}
for num in range(CONF.quota_metadata_items):
req = fakes.HTTPRequest.blank('/v1/snapshot_metadata')
req.method = 'POST'
req.content_type = "application/json"
- body = {"metadata": {"key9": "value9"}}
+ body = {"metadata": {"key1": "value1",
+ "key2": "value2",
+ "key3": "value3"}}
req.body = jsonutils.dumps(body)
res_dict = self.controller.create(req, self.req_id, body)
self.assertEqual(body, res_dict)
+ def test_create_with_keys_in_uppercase_and_lowercase(self):
+ # if the keys in uppercase_and_lowercase, should return the one
+ # which server added
+ self.stubs.Set(cinder.db, 'snapshot_metadata_get',
+ return_empty_snapshot_metadata)
+ self.stubs.Set(cinder.db, 'snapshot_metadata_update',
+ return_create_snapshot_metadata_insensitive)
+
+ req = fakes.HTTPRequest.blank('/v1/snapshot_metadata')
+ req.method = 'POST'
+ req.content_type = "application/json"
+ body = {"metadata": {"key1": "value1",
+ "KEY1": "value1",
+ "key2": "value2",
+ "KEY2": "value2",
+ "key3": "value3",
+ "KEY4": "value4"}}
+ expected = {"metadata": {"key1": "value1",
+ "key2": "value2",
+ "key3": "value3",
+ "KEY4": "value4"}}
+ req.body = jsonutils.dumps(body)
+ res_dict = self.controller.create(req, self.req_id, body)
+ self.assertEqual(expected, res_dict)
+
def test_create_empty_body(self):
self.stubs.Set(cinder.db, 'snapshot_metadata_update',
return_create_snapshot_metadata)
self.controller.create, req, self.req_id, body)
def test_update_all(self):
- self.stubs.Set(cinder.db, 'snapshot_metadata_update',
+ self.stubs.Set(cinder.db, 'snapshot_metadata_get',
return_create_snapshot_metadata)
+ self.stubs.Set(cinder.db, 'snapshot_metadata_update',
+ return_new_snapshot_metadata)
req = fakes.HTTPRequest.blank(self.url)
req.method = 'PUT'
req.content_type = "application/json"
'metadata': {
'key10': 'value10',
'key99': 'value99',
+ 'KEY20': 'value20',
},
}
req.body = jsonutils.dumps(expected)
self.assertEqual(expected, res_dict)
+ def test_update_all_with_keys_in_uppercase_and_lowercase(self):
+ self.stubs.Set(cinder.db, 'snapshot_metadata_get',
+ return_create_snapshot_metadata)
+ self.stubs.Set(cinder.db, 'snapshot_metadata_update',
+ return_new_snapshot_metadata)
+ req = fakes.HTTPRequest.blank(self.url)
+ req.method = 'PUT'
+ req.content_type = "application/json"
+ body = {
+ 'metadata': {
+ 'key10': 'value10',
+ 'KEY10': 'value10',
+ 'key99': 'value99',
+ 'KEY20': 'value20',
+ },
+ }
+ expected = {
+ 'metadata': {
+ 'key10': 'value10',
+ 'key99': 'value99',
+ 'KEY20': 'value20',
+ },
+ }
+ req.body = jsonutils.dumps(expected)
+ res_dict = self.controller.update_all(req, self.req_id, body)
+
+ self.assertEqual(expected, res_dict)
+
def test_update_all_empty_container(self):
self.stubs.Set(cinder.db, 'snapshot_metadata_update',
- return_create_snapshot_metadata)
+ return_empty_container_metadata)
req = fakes.HTTPRequest.blank(self.url)
req.method = 'PUT'
req.content_type = "application/json"
return stub_snapshot_metadata()
+def return_create_snapshot_metadata_insensitive(context, snapshot_id,
+ metadata, delete):
+ return stub_snapshot_metadata_insensitive()
+
+
+def return_new_snapshot_metadata(context, snapshot_id, metadata, delete):
+ return stub_new_snapshot_metadata()
+
+
def return_snapshot_metadata(context, snapshot_id):
if not isinstance(snapshot_id, str) or not len(snapshot_id) == 36:
msg = 'id %s must be a uuid in return snapshot metadata' % snapshot_id
return {}
+def return_empty_container_metadata(context, snapshot_id, metadata, delete):
+ return {}
+
+
def delete_snapshot_metadata(context, snapshot_id, key):
pass
return metadata
+def stub_snapshot_metadata_insensitive():
+ metadata = {
+ "key1": "value1",
+ "key2": "value2",
+ "key3": "value3",
+ "KEY4": "value4",
+ }
+ return metadata
+
+
+def stub_new_snapshot_metadata():
+ metadata = {
+ 'key10': 'value10',
+ 'key99': 'value99',
+ 'KEY20': 'value20',
+ }
+ return metadata
+
+
def stub_max_snapshot_metadata():
metadata = {"metadata": {}}
for num in range(CONF.quota_metadata_items):
req = fakes.HTTPRequest.blank('/v2/snapshot_metadata')
req.method = 'POST'
req.content_type = "application/json"
- body = {"metadata": {"key9": "value9"}}
+ body = {"metadata": {"key1": "value1",
+ "key2": "value2",
+ "key3": "value3"}}
req.body = jsonutils.dumps(body)
res_dict = self.controller.create(req, self.req_id, body)
self.assertEqual(body, res_dict)
+ def test_create_with_keys_in_uppercase_and_lowercase(self):
+ # if the keys in uppercase_and_lowercase, should return the one
+ # which server added
+ self.stubs.Set(cinder.db, 'snapshot_metadata_get',
+ return_empty_snapshot_metadata)
+ self.stubs.Set(cinder.db, 'snapshot_metadata_update',
+ return_create_snapshot_metadata_insensitive)
+
+ req = fakes.HTTPRequest.blank('/v1/snapshot_metadata')
+ req.method = 'POST'
+ req.content_type = "application/json"
+ body = {"metadata": {"key1": "value1",
+ "KEY1": "value1",
+ "key2": "value2",
+ "KEY2": "value2",
+ "key3": "value3",
+ "KEY4": "value4"}}
+ expected = {"metadata": {"key1": "value1",
+ "key2": "value2",
+ "key3": "value3",
+ "KEY4": "value4"}}
+ req.body = jsonutils.dumps(body)
+ res_dict = self.controller.create(req, self.req_id, body)
+ self.assertEqual(expected, res_dict)
+
def test_create_empty_body(self):
self.stubs.Set(cinder.db, 'snapshot_metadata_update',
return_create_snapshot_metadata)
def test_update_all(self):
self.stubs.Set(cinder.db, 'snapshot_metadata_update',
- return_create_snapshot_metadata)
+ return_new_snapshot_metadata)
req = fakes.HTTPRequest.blank(self.url)
req.method = 'PUT'
req.content_type = "application/json"
'metadata': {
'key10': 'value10',
'key99': 'value99',
+ 'KEY20': 'value20',
},
}
req.body = jsonutils.dumps(expected)
self.assertEqual(expected, res_dict)
+ def test_update_all_with_keys_in_uppercase_and_lowercase(self):
+ self.stubs.Set(cinder.db, 'snapshot_metadata_get',
+ return_create_snapshot_metadata)
+ self.stubs.Set(cinder.db, 'snapshot_metadata_update',
+ return_new_snapshot_metadata)
+ req = fakes.HTTPRequest.blank(self.url)
+ req.method = 'PUT'
+ req.content_type = "application/json"
+ body = {
+ 'metadata': {
+ 'key10': 'value10',
+ 'KEY10': 'value10',
+ 'key99': 'value99',
+ 'KEY20': 'value20',
+ },
+ }
+ expected = {
+ 'metadata': {
+ 'key10': 'value10',
+ 'key99': 'value99',
+ 'KEY20': 'value20',
+ },
+ }
+ req.body = jsonutils.dumps(expected)
+ res_dict = self.controller.update_all(req, self.req_id, body)
+
+ self.assertEqual(expected, res_dict)
+
def test_update_all_empty_container(self):
self.stubs.Set(cinder.db, 'snapshot_metadata_update',
- return_create_snapshot_metadata)
+ return_empty_container_metadata)
req = fakes.HTTPRequest.blank(self.url)
req.method = 'PUT'
req.content_type = "application/json"
db.volume_create(self.ctxt, {'id': 1})
db.snapshot_create(self.ctxt,
{'id': 1, 'volume_id': 1, 'metadata': metadata1})
- db.snapshot_metadata_update(self.ctxt, 1, metadata2, False)
+ db_meta = db.snapshot_metadata_update(self.ctxt, 1, metadata2, False)
- self.assertEqual(should_be, db.snapshot_metadata_get(self.ctxt, 1))
+ self.assertEqual(should_be, db_meta)
def test_snapshot_metadata_update_delete(self):
metadata1 = {'a': '1', 'c': '2'}
db.volume_create(self.ctxt, {'id': 1})
db.snapshot_create(self.ctxt,
{'id': 1, 'volume_id': 1, 'metadata': metadata1})
- db.snapshot_metadata_update(self.ctxt, 1, metadata2, True)
+ db_meta = db.snapshot_metadata_update(self.ctxt, 1, metadata2, True)
- self.assertEqual(should_be, db.snapshot_metadata_get(self.ctxt, 1))
+ self.assertEqual(should_be, db_meta)
def test_snapshot_metadata_delete(self):
metadata = {'a': '1', 'c': '2'}
self._check_metadata_properties(context, _metadata)
- self.db.snapshot_metadata_update(context,
- snapshot['id'],
- _metadata,
- True)
+ db_meta = self.db.snapshot_metadata_update(context,
+ snapshot['id'],
+ _metadata,
+ True)
# TODO(jdg): Implement an RPC call for drivers that may use this info
- return _metadata
+ return db_meta
def get_snapshot_metadata_value(self, snapshot, key):
pass