Esempio n. 1
0
 def stub_snapshot_get_all_by_project(context, project_id,
                                      search_opts):
     return [
         stubs.stub_snapshot(1, display_name='backup1'),
         stubs.stub_snapshot(2, display_name='backup2'),
         stubs.stub_snapshot(3, display_name='backup3'),
     ]
Esempio n. 2
0
 def stub_snapshot_get_all_by_project(context, project_id,
                                      search_opts):
     return [
         stubs.stub_snapshot(1, display_name='backup1'),
         stubs.stub_snapshot(2, display_name='backup2'),
         stubs.stub_snapshot(3, display_name='backup3'),
     ]
Esempio n. 3
0
 def stub_snapshot_get_all_by_project(context, project_id):
     return [
         stubs.stub_snapshot(1, display_name='backup1',
                             status='available'),
         stubs.stub_snapshot(2, display_name='backup2',
                             status='available'),
         stubs.stub_snapshot(3, display_name='backup3',
                             status='creating'),
     ]
Esempio n. 4
0
 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 [stubs.stub_snapshot(fake.volume_id,
                                     tenant_id='tenant1')]
     else:
         return []
Esempio n. 5
0
    def test_volume_creation_from_snapshot(self, max_ver, create, get_snapshot,
                                           volume_type_get, group_get):
        create.side_effect = stubs.stub_volume_api_create
        get_snapshot.side_effect = stubs.stub_snapshot_get
        volume_type_get.side_effect = stubs.stub_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 = api_version.APIVersionRequest(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(
            stubs.stub_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'], stubs.DEFAULT_VOL_NAME,
                                       stubs.DEFAULT_VOL_DESCRIPTION, **kwargs)
Esempio n. 6
0
    def test_volume_creation_from_snapshot(self, max_ver, create, get_snapshot,
                                           volume_type_get, group_get):
        create.side_effect = stubs.stub_volume_api_create
        get_snapshot.side_effect = stubs.stub_snapshot_get
        volume_type_get.side_effect = stubs.stub_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 = api_version.APIVersionRequest(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(
            stubs.stub_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'], stubs.DEFAULT_VOL_NAME,
                                       stubs.DEFAULT_VOL_DESCRIPTION, **kwargs)
Esempio n. 7
0
def stub_snapshot_get(context, snapshot_id):
    snapshot = stubs.stub_snapshot(snapshot_id)
    if snapshot_id == fake.SNAPSHOT_ID:
        snapshot['status'] = 'creating'
    else:
        snapshot['status'] = 'error'
    return snapshot
Esempio n. 8
0
def stub_snapshot_get(context, snapshot_id):
    snapshot = stubs.stub_snapshot(snapshot_id)
    if snapshot_id == fake.SNAPSHOT_ID:
        snapshot['status'] = 'creating'
    else:
        snapshot['status'] = 'error'
    return snapshot
Esempio n. 9
0
def fake_snapshot_get(context, snapshot_id):
    snapshot = stubs.stub_snapshot(snapshot_id)

    if snapshot_id == fake.SNAPSHOT_ID:
        snapshot['status'] = fields.SnapshotStatus.CREATING
    else:
        snapshot['status'] = fields.SnapshotStatus.ERROR
    return snapshot
Esempio n. 10
0
def fake_snapshot_get(context, snapshot_id):
    snapshot = stubs.stub_snapshot(snapshot_id)

    if snapshot_id == fake.SNAPSHOT_ID:
        snapshot['status'] = fields.SnapshotStatus.CREATING
    else:
        snapshot['status'] = fields.SnapshotStatus.ERROR
    return snapshot
Esempio n. 11
0
def stub_snapshot_get(context, snapshot_id):
    snapshot = stubs.stub_snapshot(snapshot_id)
    if snapshot_id == 3:
        snapshot["status"] = "error"
    elif snapshot_id == 1:
        snapshot["status"] = "creating"
    elif snapshot_id == 7:
        snapshot["status"] = "available"
    else:
        snapshot["status"] = "creating"

    return snapshot
Esempio n. 12
0
def stub_snapshot_get(context, snapshot_id):
    snapshot = stubs.stub_snapshot(snapshot_id)
    if snapshot_id == 3:
        snapshot['status'] = 'error'
    elif snapshot_id == 1:
        snapshot['status'] = 'creating'
    elif snapshot_id == 7:
        snapshot['status'] = 'available'
    else:
        snapshot['status'] = 'creating'

    return snapshot
Esempio n. 13
0
def stub_snapshot_get(context, snapshot_id):
    snapshot = stubs.stub_snapshot(snapshot_id)
    if snapshot_id == 3:
        snapshot['status'] = 'error'
    elif snapshot_id == 1:
        snapshot['status'] = 'creating'
    elif snapshot_id == 7:
        snapshot['status'] = 'available'
    else:
        snapshot['status'] = 'creating'

    return snapshot
Esempio n. 14
0
    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)
Esempio n. 15
0
    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)
Esempio n. 16
0
    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)
Esempio n. 17
0
    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)
Esempio n. 18
0
    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)
Esempio n. 19
0
 def stub_snapshot_get_all_by_project(context, project_id):
     return [
         stubs.stub_snapshot(1, volume_id='vol1', status='creating'),
         stubs.stub_snapshot(2, volume_id='vol1', status='available'),
         stubs.stub_snapshot(3, volume_id='vol2', status='available'),
     ]
Esempio n. 20
0
 def stub_snapshot_get_all_by_project(context, project_id):
     return [
         stubs.stub_snapshot(1, volume_id='vol1', status='creating'),
         stubs.stub_snapshot(2, volume_id='vol1', status='available'),
         stubs.stub_snapshot(3, volume_id='vol2', status='available'),
     ]