def test_snapshot_update(self, snapshot_get_by_id, volume_get_by_id, snapshot_metadata_get, update_snapshot):
        snapshot = {
            "id": UUID,
            "volume_id": 1,
            "status": "available",
            "volume_size": 100,
            "display_name": "Default name",
            "display_description": "Default description",
            "expected_attrs": ["metadata"],
        }
        ctx = context.RequestContext("admin", "fake", True)
        snapshot_obj = fake_snapshot.fake_snapshot_obj(ctx, **snapshot)
        fake_volume_obj = fake_volume.fake_volume_obj(ctx)
        snapshot_get_by_id.return_value = snapshot_obj
        volume_get_by_id.return_value = fake_volume_obj

        updates = {"display_name": "Updated Test Name"}
        body = {"snapshot": updates}
        req = fakes.HTTPRequest.blank("/v1/snapshots/%s" % UUID)
        res_dict = self.controller.update(req, UUID, body)
        expected = {
            "snapshot": {
                "id": UUID,
                "volume_id": "1",
                "status": u"available",
                "size": 100,
                "created_at": None,
                "display_name": u"Updated Test Name",
                "display_description": u"Default description",
                "metadata": {},
            }
        }
        self.assertEqual(expected, res_dict)
    def test_create(self, snapshot_get_by_id, volume_get_by_id,
                    snapshot_update):
        snapshot = {
            'id': self.req_id,
            'expected_attrs': ['metadata']
        }
        ctx = context.RequestContext('admin', 'fake', True)
        snapshot_obj = fake_snapshot.fake_snapshot_obj(ctx, **snapshot)
        fake_volume_obj = fake_volume.fake_volume_obj(ctx)
        snapshot_get_by_id.return_value = snapshot_obj
        volume_get_by_id.return_value = fake_volume_obj

        self.stubs.Set(cinder.db, 'snapshot_metadata_get',
                       return_empty_snapshot_metadata)
        self.stubs.Set(cinder.db, 'snapshot_metadata_update',
                       return_create_snapshot_metadata)

        req = fakes.HTTPRequest.blank('/v2/snapshot_metadata')
        req.method = 'POST'
        req.content_type = "application/json"
        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)
Exemple #3
0
    def test_snapshot_update(self, snapshot_get_by_id, volume_get_by_id,
                             snapshot_metadata_get, update_snapshot):
        snapshot = {
            'id': UUID,
            'volume_id': 1,
            'status': 'available',
            'volume_size': 100,
            'display_name': 'Default name',
            'display_description': 'Default description',
            'expected_attrs': ['metadata'],
        }
        ctx = context.RequestContext('admin', 'fake', True)
        snapshot_obj = fake_snapshot.fake_snapshot_obj(ctx, **snapshot)
        fake_volume_obj = fake_volume.fake_volume_obj(ctx)
        snapshot_get_by_id.return_value = snapshot_obj
        volume_get_by_id.return_value = fake_volume_obj

        updates = {"display_name": "Updated Test Name", }
        body = {"snapshot": updates}
        req = fakes.HTTPRequest.blank('/v1/snapshots/%s' % UUID)
        res_dict = self.controller.update(req, UUID, body)
        expected = {'snapshot': {
            'id': UUID,
            'volume_id': '1',
            'status': u'available',
            'size': 100,
            'created_at': None,
            'display_name': u'Updated Test Name',
            'display_description': u'Default description',
            'metadata': {},
        }}
        self.assertEqual(expected, res_dict)
    def test_get_all(self, snapshot_get_all, volume_get_by_id,
                     snapshot_metadata_get):
        fake_volume_obj = fake_volume.fake_volume_obj(self.context)
        volume_get_by_id.return_value = fake_volume_obj

        snapshots = snapshot_obj.SnapshotList.get_all(self.context)
        self.assertEqual(1, len(snapshots))
        TestSnapshot._compare(self, fake_snapshot, snapshots[0])
Exemple #5
0
    def test_get_all(self, snapshot_get_all, volume_get_by_id,
                     snapshot_metadata_get):
        fake_volume_obj = fake_volume.fake_volume_obj(self.context)
        volume_get_by_id.return_value = fake_volume_obj

        snapshots = snapshot_obj.SnapshotList.get_all(self.context)
        self.assertEqual(1, len(snapshots))
        TestSnapshot._compare(self, fake_snapshot, snapshots[0])
Exemple #6
0
    def test_show(self, snapshot_get_by_id, volume_get_by_id,
                  snapshot_metadata_get):
        ctx = context.RequestContext('fake', 'fake', auth_token=True)
        snapshot = _get_default_snapshot_param()
        snapshot_obj = fake_snapshot.fake_snapshot_obj(ctx, **snapshot)
        fake_volume_obj = fake_volume.fake_volume_obj(ctx)
        snapshot_get_by_id.return_value = snapshot_obj
        volume_get_by_id.return_value = fake_volume_obj

        url = '/v2/fake/snapshots/%s' % UUID1
        res = self._make_request(url)

        self.assertEqual(res.status_int, 200)
        self.assertSnapshotAttributes(self._get_snapshot(res.body),
                                      project_id='fake',
                                      progress='0%')
    def test_show(self, snapshot_get_by_id, volume_get_by_id,
                  snapshot_metadata_get):
        ctx = context.RequestContext('fake', 'fake', auth_token=True)
        snapshot = _get_default_snapshot_param()
        snapshot_obj = fake_snapshot.fake_snapshot_obj(ctx, **snapshot)
        fake_volume_obj = fake_volume.fake_volume_obj(ctx)
        snapshot_get_by_id.return_value = snapshot_obj
        volume_get_by_id.return_value = fake_volume_obj

        url = '/v2/fake/snapshots/%s' % UUID1
        res = self._make_request(url)

        self.assertEqual(res.status_int, 200)
        self.assertSnapshotAttributes(self._get_snapshot(res.body),
                                      project_id='fake',
                                      progress='0%')
    def test_snapshot_delete(self, snapshot_get_by_id, volume_get_by_id, snapshot_metadata_get, delete_snapshot):
        snapshot = {
            "id": UUID,
            "volume_id": 1,
            "status": "available",
            "volume_size": 100,
            "display_name": "Default name",
            "display_description": "Default description",
            "expected_attrs": ["metadata"],
        }
        ctx = context.RequestContext("admin", "fake", True)
        snapshot_obj = fake_snapshot.fake_snapshot_obj(ctx, **snapshot)
        fake_volume_obj = fake_volume.fake_volume_obj(ctx)
        snapshot_get_by_id.return_value = snapshot_obj
        volume_get_by_id.return_value = fake_volume_obj

        snapshot_id = UUID
        req = fakes.HTTPRequest.blank("/v1/snapshots/%s" % snapshot_id)
        resp = self.controller.delete(req, snapshot_id)
        self.assertEqual(resp.status_int, 202)
    def test_snapshot_show(self, snapshot_get_by_id, volume_get_by_id, snapshot_metadata_get):
        snapshot = {
            "id": UUID,
            "volume_id": 1,
            "status": "available",
            "volume_size": 100,
            "display_name": "Default name",
            "display_description": "Default description",
            "expected_attrs": ["metadata"],
        }
        ctx = context.RequestContext("admin", "fake", True)
        snapshot_obj = fake_snapshot.fake_snapshot_obj(ctx, **snapshot)
        fake_volume_obj = fake_volume.fake_volume_obj(ctx)
        snapshot_get_by_id.return_value = snapshot_obj
        volume_get_by_id.return_value = fake_volume_obj

        req = fakes.HTTPRequest.blank("/v1/snapshots/%s" % UUID)
        resp_dict = self.controller.show(req, UUID)

        self.assertIn("snapshot", resp_dict)
        self.assertEqual(resp_dict["snapshot"]["id"], UUID)
Exemple #10
0
    def test_snapshot_delete(self, snapshot_get_by_id, volume_get_by_id,
                             snapshot_metadata_get, delete_snapshot):
        snapshot = {
            'id': UUID,
            'volume_id': 1,
            'status': 'available',
            'volume_size': 100,
            'display_name': 'Default name',
            'display_description': 'Default description',
            'expected_attrs': ['metadata'],
        }
        ctx = context.RequestContext('admin', 'fake', True)
        snapshot_obj = fake_snapshot.fake_snapshot_obj(ctx, **snapshot)
        fake_volume_obj = fake_volume.fake_volume_obj(ctx)
        snapshot_get_by_id.return_value = snapshot_obj
        volume_get_by_id.return_value = fake_volume_obj

        snapshot_id = UUID
        req = fakes.HTTPRequest.blank('/v2/snapshots/%s' % snapshot_id)
        resp = self.controller.delete(req, snapshot_id)
        self.assertEqual(resp.status_int, 202)
Exemple #11
0
    def test_snapshot_delete(self, snapshot_get_by_id, volume_get_by_id,
                             snapshot_metadata_get, delete_snapshot):
        snapshot = {
            'id': UUID,
            'volume_id': 1,
            'status': 'available',
            'volume_size': 100,
            'display_name': 'Default name',
            'display_description': 'Default description',
            'expected_attrs': ['metadata'],
        }
        ctx = context.RequestContext('admin', 'fake', True)
        snapshot_obj = fake_snapshot.fake_snapshot_obj(ctx, **snapshot)
        fake_volume_obj = fake_volume.fake_volume_obj(ctx)
        snapshot_get_by_id.return_value = snapshot_obj
        volume_get_by_id.return_value = fake_volume_obj

        snapshot_id = UUID
        req = fakes.HTTPRequest.blank('/v2/snapshots/%s' % snapshot_id)
        resp = self.controller.delete(req, snapshot_id)
        self.assertEqual(resp.status_int, 202)
Exemple #12
0
    def test_snapshot_show(self, snapshot_get_by_id, volume_get_by_id,
                           snapshot_metadata_get):
        snapshot = {
            'id': UUID,
            'volume_id': 1,
            'status': 'available',
            'volume_size': 100,
            'display_name': 'Default name',
            'display_description': 'Default description',
            'expected_attrs': ['metadata'],
        }
        ctx = context.RequestContext('admin', 'fake', True)
        snapshot_obj = fake_snapshot.fake_snapshot_obj(ctx, **snapshot)
        fake_volume_obj = fake_volume.fake_volume_obj(ctx)
        snapshot_get_by_id.return_value = snapshot_obj
        volume_get_by_id.return_value = fake_volume_obj

        req = fakes.HTTPRequest.blank('/v2/snapshots/%s' % UUID)
        resp_dict = self.controller.show(req, UUID)

        self.assertIn('snapshot', resp_dict)
        self.assertEqual(resp_dict['snapshot']['id'], UUID)
Exemple #13
0
    def test_snapshot_show(self, snapshot_get_by_id, volume_get_by_id,
                           snapshot_metadata_get):
        snapshot = {
            'id': UUID,
            'volume_id': 1,
            'status': 'available',
            'volume_size': 100,
            'display_name': 'Default name',
            'display_description': 'Default description',
            'expected_attrs': ['metadata'],
        }
        ctx = context.RequestContext('admin', 'fake', True)
        snapshot_obj = fake_snapshot.fake_snapshot_obj(ctx, **snapshot)
        fake_volume_obj = fake_volume.fake_volume_obj(ctx)
        snapshot_get_by_id.return_value = snapshot_obj
        volume_get_by_id.return_value = fake_volume_obj

        req = fakes.HTTPRequest.blank('/v2/snapshots/%s' % UUID)
        resp_dict = self.controller.show(req, UUID)

        self.assertIn('snapshot', resp_dict)
        self.assertEqual(resp_dict['snapshot']['id'], UUID)
Exemple #14
0
    def test_snapshot_update(self, snapshot_get_by_id, volume_get_by_id,
                             snapshot_metadata_get, update_snapshot):
        snapshot = {
            'id': UUID,
            'volume_id': 1,
            'status': 'available',
            'volume_size': 100,
            'display_name': 'Default name',
            'display_description': 'Default description',
            'expected_attrs': ['metadata'],
        }
        ctx = context.RequestContext('admin', 'fake', True)
        snapshot_obj = fake_snapshot.fake_snapshot_obj(ctx, **snapshot)
        fake_volume_obj = fake_volume.fake_volume_obj(ctx)
        snapshot_get_by_id.return_value = snapshot_obj
        volume_get_by_id.return_value = fake_volume_obj

        updates = {
            "name": "Updated Test Name",
        }
        body = {"snapshot": updates}
        req = fakes.HTTPRequest.blank('/v2/snapshots/%s' % UUID)
        res_dict = self.controller.update(req, UUID, body)
        expected = {
            'snapshot': {
                'id': UUID,
                'volume_id': '1',
                'status': u'available',
                'size': 100,
                'created_at': None,
                'name': u'Updated Test Name',
                'description': u'Default description',
                'metadata': {},
            }
        }
        self.assertEqual(expected, res_dict)