def test_volume_create_with_snapshot_image(self, mock_validate, create, get_snapshot, volume_type_get): create.side_effect = v2_fakes.fake_volume_api_create get_snapshot.side_effect = v2_fakes.fake_snapshot_get volume_type_get.side_effect = v2_fakes.fake_volume_type_get self.ext_mgr.extensions = {'os-image-create': 'fake'} vol = self._vol_in_request_body( image_id="b0a599e0-41d7-3582-b260-769f443c862a") snapshot_id = fake.SNAPSHOT_ID ex = self._expected_vol_from_controller(snapshot_id=snapshot_id) body = {"volume": vol} req = fakes.HTTPRequest.blank('/v3/volumes') req.headers = mv.get_mv_header(mv.SUPPORT_NOVA_IMAGE) req.api_version_request = mv.get_api_version(mv.SUPPORT_NOVA_IMAGE) res_dict = self.controller.create(req, body=body) self.assertEqual(ex, res_dict) context = req.environ['cinder.context'] get_snapshot.assert_called_once_with(self.controller.volume_api, context, snapshot_id) kwargs = self._expected_volume_api_create_kwargs( v2_fakes.fake_snapshot(snapshot_id)) create.assert_called_once_with( self.controller.volume_api, context, vol['size'], v2_fakes.DEFAULT_VOL_NAME, v2_fakes.DEFAULT_VOL_DESCRIPTION, **kwargs)
def test_volume_creation_from_snapshot(self, max_ver, create, get_snapshot, volume_type_get, group_get): create.side_effect = v2_fakes.fake_volume_api_create get_snapshot.side_effect = v2_fakes.fake_snapshot_get volume_type_get.side_effect = v2_fakes.fake_volume_type_get fake_group = { 'id': fake.GROUP_ID, 'group_type_id': fake.GROUP_TYPE_ID, 'name': 'fake_group' } group_get.return_value = fake_group snapshot_id = fake.SNAPSHOT_ID vol = self._vol_in_request_body(snapshot_id=snapshot_id, group_id=fake.GROUP_ID) body = {"volume": vol} req = fakes.HTTPRequest.blank('/v3/volumes') req.api_version_request = mv.get_api_version(max_ver) res_dict = self.controller.create(req, body) ex = self._expected_vol_from_controller( snapshot_id=snapshot_id, req_version=req.api_version_request) self.assertEqual(ex, res_dict) context = req.environ['cinder.context'] get_snapshot.assert_called_once_with(self.controller.volume_api, context, snapshot_id) kwargs = self._expected_volume_api_create_kwargs( v2_fakes.fake_snapshot(snapshot_id), test_group=fake_group, req_version=req.api_version_request) create.assert_called_once_with(self.controller.volume_api, context, vol['size'], v2_fakes.DEFAULT_VOL_NAME, v2_fakes.DEFAULT_VOL_DESCRIPTION, **kwargs)
def test_volume_create_with_snapshot_image(self, mock_validate, create, get_snapshot, volume_type_get): create.side_effect = v2_fakes.fake_volume_api_create get_snapshot.side_effect = v2_fakes.fake_snapshot_get volume_type_get.side_effect = v2_fakes.fake_volume_type_get vol = self._vol_in_request_body( image_id="b0a599e0-41d7-3582-b260-769f443c862a") snapshot_id = fake.SNAPSHOT_ID ex = self._expected_vol_from_controller(snapshot_id=snapshot_id) body = {"volume": vol} req = fakes.HTTPRequest.blank('/v3/volumes') req.headers = mv.get_mv_header(mv.SUPPORT_NOVA_IMAGE) req.api_version_request = mv.get_api_version(mv.SUPPORT_NOVA_IMAGE) res_dict = self.controller.create(req, body=body) self.assertEqual(ex, res_dict) context = req.environ['cinder.context'] get_snapshot.assert_called_once_with(self.controller.volume_api, context, snapshot_id) kwargs = self._expected_volume_api_create_kwargs( v2_fakes.fake_snapshot(snapshot_id)) create.assert_called_once_with( self.controller.volume_api, context, vol['size'], v2_fakes.DEFAULT_VOL_NAME, v2_fakes.DEFAULT_VOL_DESCRIPTION, **kwargs)
def get_all(context, filters=None, marker=None, limit=None, sort_keys=None, sort_dirs=None, offset=None): if 'project_id' in filters and 'tenant1' in filters['project_id']: return [v2_fakes.fake_snapshot(fake.VOLUME_ID, tenant_id='tenant1')] else: return []
def fake_snapshot_get(context, snapshot_id): snapshot = v2_fakes.fake_snapshot(snapshot_id) if snapshot_id == fake.SNAPSHOT_ID: snapshot['status'] = fields.SnapshotStatus.CREATING else: snapshot['status'] = fields.SnapshotStatus.ERROR return snapshot
def test_force_delete_snapshot(self, volume_get, snapshot_get, get_by_id, delete_snapshot): volume = v2_fakes.create_fake_volume(fake.VOLUME_ID) snapshot = v2_fakes.fake_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_creation_from_snapshot(self, max_ver, create, get_snapshot, volume_type_get, group_get): create.side_effect = v2_fakes.fake_volume_api_create get_snapshot.side_effect = v2_fakes.fake_snapshot_get volume_type_get.side_effect = v2_fakes.fake_volume_type_get fake_group = { 'id': fake.GROUP_ID, 'group_type_id': fake.GROUP_TYPE_ID, 'name': 'fake_group' } group_get.return_value = fake_group snapshot_id = fake.SNAPSHOT_ID vol = self._vol_in_request_body(snapshot_id=snapshot_id, group_id=fake.GROUP_ID) body = {"volume": vol} req = fakes.HTTPRequest.blank('/v3/volumes') req.api_version_request = mv.get_api_version(max_ver) res_dict = self.controller.create(req, body=body) ex = self._expected_vol_from_controller( snapshot_id=snapshot_id, req_version=req.api_version_request) self.assertEqual(ex, res_dict) context = req.environ['cinder.context'] get_snapshot.assert_called_once_with(self.controller.volume_api, context, snapshot_id) kwargs = self._expected_volume_api_create_kwargs( v2_fakes.fake_snapshot(snapshot_id), test_group=fake_group, req_version=req.api_version_request) create.assert_called_once_with(self.controller.volume_api, context, vol['size'], v2_fakes.DEFAULT_VOL_NAME, v2_fakes.DEFAULT_VOL_DESCRIPTION, **kwargs)