req,
body)
- def test_volume_update(self):
- self.stubs.Set(db, 'volume_get', stubs.stub_volume_get_db)
- self.stubs.Set(volume_api.API, "update", stubs.stub_volume_update)
-
+ @mock.patch.object(db, 'volume_admin_metadata_get',
+ return_value={'attached_mode': 'rw',
+ 'readonly': 'False'})
+ @mock.patch.object(db, 'volume_get', side_effect=stubs.stub_volume_get_db)
+ @mock.patch.object(volume_api.API, 'update',
+ side_effect=stubs.stub_volume_update)
+ def test_volume_update(self, *args):
updates = {
"display_name": "Updated Test Name",
}
self.assertEqual(res_dict, expected)
self.assertEqual(len(self.notifier.notifications), 2)
- def test_volume_update_metadata(self):
- self.stubs.Set(db, 'volume_get', stubs.stub_volume_get_db)
- self.stubs.Set(volume_api.API, "update", stubs.stub_volume_update)
-
+ @mock.patch.object(db, 'volume_admin_metadata_get',
+ return_value={"qos_max_iops": 2000,
+ "readonly": "False",
+ "attached_mode": "rw"})
+ @mock.patch.object(db, 'volume_get', side_effect=stubs.stub_volume_get_db)
+ @mock.patch.object(volume_api.API, 'update',
+ side_effect=stubs.stub_volume_update)
+ def test_volume_update_metadata(self, *args):
updates = {
"metadata": {"qos_max_iops": 2000}
}
self.assertEqual(len(self.notifier.notifications), 2)
def test_volume_update_with_admin_metadata(self):
+ def stubs_volume_admin_metadata_get(context, volume_id):
+ return {'key': 'value',
+ 'readonly': 'True'}
+ self.stubs.Set(db, 'volume_admin_metadata_get',
+ stubs_volume_admin_metadata_get)
self.stubs.Set(volume_api.API, "update", stubs.stub_volume_update)
volume = stubs.stub_volume("1")
req, '1', body)
def test_volume_list(self):
+ def stubs_volume_admin_metadata_get(context, volume_id):
+ return {'attached_mode': 'rw',
+ 'readonly': 'False'}
+ self.stubs.Set(db, 'volume_admin_metadata_get',
+ stubs_volume_admin_metadata_get)
self.stubs.Set(db, 'volume_get', stubs.stub_volume_get_db)
self.stubs.Set(volume_api.API, 'get_all',
stubs.stub_volume_get_all_by_project)
'size': 1}]}
self.assertEqual(res_dict, expected)
- def test_volume_show(self):
- self.stubs.Set(db, 'volume_get', stubs.stub_volume_get_db)
-
+ @mock.patch.object(db, 'volume_admin_metadata_get',
+ return_value={'attached_mode': 'rw',
+ 'readonly': 'False'})
+ @mock.patch.object(db, 'volume_get', side_effect=stubs.stub_volume_get_db)
+ def test_volume_show(self, *args):
req = fakes.HTTPRequest.blank('/v1/volumes/1')
res_dict = self.controller.show(req, '1')
expected = {'volume': {'status': 'fakestatus',
def stub_volume_get(self, context, volume_id, viewable_admin_meta=False):
- return stub_volume(volume_id)
+ if viewable_admin_meta:
+ return stub_volume(volume_id)
+ else:
+ volume = stub_volume(volume_id)
+ del volume['volume_admin_metadata']
+ return volume
def stub_volume_get_notfound(self, context,
def stub_volume_get_db(context, volume_id):
- return stub_volume(volume_id)
+ if context.is_admin:
+ return stub_volume(volume_id)
+ else:
+ volume = stub_volume(volume_id)
+ del volume['volume_admin_metadata']
+ return volume
def stub_volume_get_all(context, search_opts=None, marker=None, limit=None,
filters=None,
viewable_admin_meta=False):
filters = filters or {}
- return [stub_volume_get(self, context, '1')]
+ return [stub_volume_get(self, context, '1', viewable_admin_meta=True)]
def stub_snapshot(id, **kwargs):
visible_admin_meta = {}
if volume.get('volume_admin_metadata'):
- for item in volume['volume_admin_metadata']:
- if item['key'] in _visible_admin_metadata_keys:
- visible_admin_meta[item['key']] = item['value']
+ if isinstance(volume['volume_admin_metadata'], dict):
+ volume_admin_metadata = volume['volume_admin_metadata']
+ for key in volume_admin_metadata:
+ if key in _visible_admin_metadata_keys:
+ visible_admin_meta[key] = volume_admin_metadata[key]
+ else:
+ for item in volume['volume_admin_metadata']:
+ if item['key'] in _visible_admin_metadata_keys:
+ visible_admin_meta[item['key']] = item['value']
# avoid circular ref when volume is a Volume instance
elif (volume.get('admin_metadata') and
isinstance(volume.get('admin_metadata'), dict)):