def stub_volume_get_all_by_project(context, project_id, marker, limit, sort_keys=None, sort_dirs=None, filters=None, viewable_admin_meta=False): return [ stubs.stub_volume(1, display_name='vol1'), stubs.stub_volume(2, display_name='vol2'), ]
def stub_volume_get(self, context, volume_id): volume = stubs.stub_volume(volume_id) if volume_id == 5: volume["status"] = "in-use" else: volume["status"] = "available" return volume
def stub_volume_get(self, context, volume_id): volume = stubs.stub_volume(volume_id) if volume_id == 5: volume['status'] = 'in-use' else: volume['status'] = 'available' return volume
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") del volume['name'] del volume['volume_type'] del volume['volume_type_id'] volume['metadata'] = {'key': 'value'} db.volume_create(context.get_admin_context(), volume) db.volume_admin_metadata_update(context.get_admin_context(), "1", {"readonly": "True", "invisible_key": "invisible_value"}, False) values = {'volume_id': '1', } attachment = db.volume_attach(context.get_admin_context(), values) db.volume_attached(context.get_admin_context(), attachment['id'], stubs.FAKE_UUID, None, '/') updates = { "display_name": "Updated Test Name", } body = {"volume": updates} req = fakes.HTTPRequest.blank('/v1/volumes/1') self.assertEqual(0, len(self.notifier.notifications)) admin_ctx = context.RequestContext('admin', 'fakeproject', True) req.environ['cinder.context'] = admin_ctx res_dict = self.controller.update(req, '1', body) expected = {'volume': { 'status': 'in-use', 'display_description': 'displaydesc', 'availability_zone': 'fakeaz', 'display_name': 'Updated Test Name', 'encrypted': False, 'attachments': [{ 'attachment_id': attachment['id'], 'id': '1', 'volume_id': '1', 'server_id': stubs.FAKE_UUID, 'host_name': None, 'device': '/' }], 'multiattach': 'false', 'bootable': 'false', 'volume_type': None, 'snapshot_id': None, 'source_volid': None, 'metadata': {'key': 'value', 'readonly': 'True'}, 'id': '1', 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': 1}} self.assertEqual(expected, res_dict) self.assertEqual(2, len(self.notifier.notifications))
def setUp(self): super(SchedulerHintsTestCase, self).setUp() self.fake_instance = stubs.stub_volume(1, uuid=UUID) self.fake_instance['created_at'] =\ datetime.datetime(2013, 1, 1, 1, 1, 1) self.fake_instance['launched_at'] =\ datetime.datetime(2013, 1, 1, 1, 1, 1) self.flags( osapi_volume_extension=['cinder.api.contrib.select_extensions'], osapi_volume_ext_list=['Scheduler_hints']) self.app = fakes.wsgi_app()
def setUp(self): super(SchedulerHintsTestCase, self).setUp() self.fake_instance = stubs.stub_volume(1, uuid=UUID) self.fake_instance['created_at'] =\ datetime.datetime(2013, 1, 1, 1, 1, 1) self.fake_instance['launched_at'] =\ datetime.datetime(2013, 1, 1, 1, 1, 1) self.flags( osapi_volume_extension=[ 'cinder.api.contrib.select_extensions'], osapi_volume_ext_list=['Scheduler_hints']) self.app = fakes.wsgi_app()
def setUp(self): super(SchedulerHintsTestCase, self).setUp() self.fake_instance = stubs.stub_volume(fake.VOLUME_ID, uuid=UUID) self.fake_instance['created_at'] =\ datetime.datetime(2013, 1, 1, 1, 1, 1) self.fake_instance['launched_at'] =\ datetime.datetime(2013, 1, 1, 1, 1, 1) self.flags( osapi_volume_extension=['cinder.api.contrib.select_extensions'], osapi_volume_ext_list=['Scheduler_hints']) self.user_ctxt = context.RequestContext(fake.USER_ID, fake.PROJECT_ID, auth_token=True) self.app = fakes.wsgi_app(fake_auth_context=self.user_ctxt)
def setUp(self): super(SchedulerHintsTestCase, self).setUp() self.fake_instance = stubs.stub_volume(fake.VOLUME_ID, uuid=UUID) self.fake_instance['created_at'] =\ datetime.datetime(2013, 1, 1, 1, 1, 1) self.fake_instance['launched_at'] =\ datetime.datetime(2013, 1, 1, 1, 1, 1) self.flags( osapi_volume_extension=[ 'cinder.api.contrib.select_extensions'], osapi_volume_ext_list=['Scheduler_hints']) self.user_ctxt = context.RequestContext( fake.USER_ID, fake.PROJECT_ID, auth_token=True) self.app = fakes.wsgi_app(fake_auth_context=self.user_ctxt)
def test_force_delete_snapshot(self, volume_get, snapshot_get, get_by_id, delete_snapshot): volume = stubs.stub_volume(fake.VOLUME_ID) snapshot = stubs.stub_snapshot(fake.SNAPSHOT_ID) snapshot_obj = fake_snapshot.fake_snapshot_obj(self.ctx, **snapshot) volume_get.return_value = volume snapshot_get.return_value = snapshot get_by_id.return_value = snapshot_obj path = "/v2/%s/snapshots/%s/action" % (fake.PROJECT_ID, snapshot["id"]) req = webob.Request.blank(path) req.method = "POST" req.headers["content-type"] = "application/json" req.body = jsonutils.dump_as_bytes({"os-force_delete": {}}) # attach admin context to request req.environ["cinder.context"] = self.ctx resp = req.get_response(app()) self.assertEqual(202, resp.status_int)
def test_force_delete_snapshot(self, volume_get, snapshot_get, get_by_id, delete_snapshot): ctx = context.RequestContext("admin", "fake", True) volume = stubs.stub_volume(1) snapshot = stubs.stub_snapshot(1) snapshot_obj = fake_snapshot.fake_snapshot_obj(ctx, **snapshot) volume_get.return_value = volume snapshot_get.return_value = snapshot get_by_id.return_value = snapshot_obj path = "/v2/fake/snapshots/%s/action" % snapshot["id"] req = webob.Request.blank(path) req.method = "POST" req.headers["content-type"] = "application/json" req.body = jsonutils.dumps({"os-force_delete": {}}) # attach admin context to request req.environ["cinder.context"] = ctx resp = req.get_response(app()) self.assertEqual(resp.status_int, 202)
def test_force_delete_snapshot(self, volume_get, snapshot_get, get_by_id, delete_snapshot): volume = stubs.stub_volume(1) snapshot = stubs.stub_snapshot(1) snapshot_obj = fake_snapshot.fake_snapshot_obj(self.ctx, **snapshot) volume_get.return_value = volume snapshot_get.return_value = snapshot get_by_id.return_value = snapshot_obj path = '/v2/fake/snapshots/%s/action' % snapshot['id'] req = webob.Request.blank(path) req.method = 'POST' req.headers['content-type'] = 'application/json' req.body = jsonutils.dump_as_bytes({'os-force_delete': {}}) # attach admin context to request req.environ['cinder.context'] = self.ctx resp = req.get_response(app()) self.assertEqual(202, resp.status_int)
def test_force_delete_snapshot(self, volume_get, snapshot_get, get_by_id, delete_snapshot): volume = stubs.stub_volume(fake.VOLUME_ID) snapshot = stubs.stub_snapshot(fake.SNAPSHOT_ID) snapshot_obj = fake_snapshot.fake_snapshot_obj(self.ctx, **snapshot) volume_get.return_value = volume snapshot_get.return_value = snapshot get_by_id.return_value = snapshot_obj path = '/v2/%s/snapshots/%s/action' % (fake.PROJECT_ID, snapshot['id']) req = webob.Request.blank(path) req.method = 'POST' req.headers['content-type'] = 'application/json' req.body = jsonutils.dump_as_bytes({'os-force_delete': {}}) # attach admin context to request req.environ['cinder.context'] = self.ctx resp = req.get_response(app()) self.assertEqual(202, resp.status_int)
def test_volume_list_detail_with_admin_metadata(self): volume = stubs.stub_volume("1") del volume['name'] del volume['volume_type'] del volume['volume_type_id'] volume['metadata'] = {'key': 'value'} db.volume_create(context.get_admin_context(), volume) db.volume_admin_metadata_update(context.get_admin_context(), "1", {"readonly": "True", "invisible_key": "invisible_value"}, False) values = {'volume_id': '1', } attachment = db.volume_attach(context.get_admin_context(), values) db.volume_attached(context.get_admin_context(), attachment['id'], stubs.FAKE_UUID, None, '/') req = fakes.HTTPRequest.blank('/v1/volumes/detail') admin_ctx = context.RequestContext('admin', 'fakeproject', True) req.environ['cinder.context'] = admin_ctx res_dict = self.controller.index(req) expected = {'volumes': [{'status': 'in-use', 'display_description': 'displaydesc', 'availability_zone': 'fakeaz', 'display_name': 'displayname', 'encrypted': False, 'attachments': [ {'attachment_id': attachment['id'], 'device': '/', 'server_id': stubs.FAKE_UUID, 'host_name': None, 'id': '1', 'volume_id': '1'}], 'multiattach': 'false', 'bootable': 'false', 'volume_type': None, 'snapshot_id': None, 'source_volid': None, 'metadata': {'key': 'value', 'readonly': 'True'}, 'id': '1', 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': 1}]} self.assertEqual(expected, res_dict)
def test_force_delete_snapshot(self, volume_get, snapshot_get, get_by_id, delete_snapshot): ctx = context.RequestContext('admin', 'fake', True) volume = stubs.stub_volume(1) snapshot = stubs.stub_snapshot(1) snapshot_obj = fake_snapshot.fake_snapshot_obj(ctx, **snapshot) volume_get.return_value = volume snapshot_get.return_value = snapshot get_by_id.return_value = snapshot_obj path = '/v2/fake/snapshots/%s/action' % snapshot['id'] req = webob.Request.blank(path) req.method = 'POST' req.headers['content-type'] = 'application/json' req.body = jsonutils.dumps({'os-force_delete': {}}) # attach admin context to request req.environ['cinder.context'] = ctx resp = req.get_response(app()) self.assertEqual(202, resp.status_int)
def stub_volume_get(self, context, volume_id, **kwargs): return (stubs.stub_volume(volume_id, volume_glance_metadata=dict(foo='bar')))
def stub_volume_get(self, context, volume_id, **kwargs): return stubs.stub_volume(volume_id, attach_status='detached')
def test_volume_show_with_admin_metadata(self): volume = stubs.stub_volume("1") del volume['name'] del volume['volume_type'] del volume['volume_type_id'] volume['metadata'] = {'key': 'value'} db.volume_create(context.get_admin_context(), volume) db.volume_admin_metadata_update(context.get_admin_context(), "1", { "readonly": "True", "invisible_key": "invisible_value" }, False) values = { 'volume_id': '1', } attachment = db.volume_attach(context.get_admin_context(), values) db.volume_attached(context.get_admin_context(), attachment['id'], stubs.FAKE_UUID, None, '/') req = fakes.HTTPRequest.blank('/v1/volumes/1') admin_ctx = context.RequestContext('admin', 'fakeproject', True) req.environ['cinder.context'] = admin_ctx res_dict = self.controller.show(req, '1') expected = { 'volume': { 'status': 'in-use', 'display_description': 'displaydesc', 'availability_zone': 'fakeaz', 'display_name': 'displayname', 'encrypted': False, 'attachments': [{ 'attachment_id': attachment['id'], 'device': '/', 'server_id': stubs.FAKE_UUID, 'host_name': None, 'id': '1', 'volume_id': '1' }], 'multiattach': 'false', 'bootable': 'false', 'volume_type': None, 'snapshot_id': None, 'source_volid': None, 'metadata': { 'key': 'value', 'readonly': 'True' }, 'id': '1', 'created_at': datetime.datetime(1900, 1, 1, 1, 1, 1), 'size': 1 } } self.assertEqual(expected, res_dict)
def stub_volume_get(self, context, volume_id, **kwargs): return stubs.stub_volume(volume_id, encryption_key_id=None)