예제 #1
0
    def test_list_group_snapshots_json(self):
        group = utils.create_group(
            self.context, group_type_id=fake.GROUP_TYPE_ID, volume_type_ids=[fake.VOLUME_TYPE_ID]
        )
        volume_id = utils.create_volume(self.context, group_id=group.id, volume_type_id=fake.VOLUME_TYPE_ID)["id"]
        group_snapshot1 = utils.create_group_snapshot(
            self.context, group_id=group.id, group_type_id=group.group_type_id
        )
        group_snapshot2 = utils.create_group_snapshot(
            self.context, group_id=group.id, group_type_id=group.group_type_id
        )
        group_snapshot3 = utils.create_group_snapshot(
            self.context, group_id=group.id, group_type_id=group.group_type_id
        )

        req = fakes.HTTPRequest.blank("/v3/%s/group_snapshots" % fake.PROJECT_ID, version=GROUP_MICRO_VERSION)
        res_dict = self.controller.index(req)

        self.assertEqual(1, len(res_dict))
        self.assertEqual(group_snapshot1.id, res_dict["group_snapshots"][0]["id"])
        self.assertEqual("test_group_snapshot", res_dict["group_snapshots"][0]["name"])
        self.assertEqual(group_snapshot2.id, res_dict["group_snapshots"][1]["id"])
        self.assertEqual("test_group_snapshot", res_dict["group_snapshots"][1]["name"])
        self.assertEqual(group_snapshot3.id, res_dict["group_snapshots"][2]["id"])
        self.assertEqual("test_group_snapshot", res_dict["group_snapshots"][2]["name"])

        group_snapshot3.destroy()
        group_snapshot2.destroy()
        group_snapshot1.destroy()
        db.volume_destroy(context.get_admin_context(), volume_id)
        group.destroy()
예제 #2
0
    def test_list_group_snapshots_detail_json(self):
        group = utils.create_group(
            self.context,
            group_type_id=fake.GROUP_TYPE_ID,
            volume_type_ids=[fake.VOLUME_TYPE_ID],
        )
        volume_id = utils.create_volume(
            self.context,
            group_id=group.id,
            volume_type_id=fake.VOLUME_TYPE_ID)['id']
        group_snapshot1 = utils.create_group_snapshot(self.context,
                                                      group_id=group.id)
        group_snapshot2 = utils.create_group_snapshot(self.context,
                                                      group_id=group.id)
        group_snapshot3 = utils.create_group_snapshot(self.context,
                                                      group_id=group.id)

        req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/detail' %
                                      fake.PROJECT_ID,
                                      version=GROUP_MICRO_VERSION)
        res_dict = self.controller.detail(req)

        self.assertEqual(1, len(res_dict))
        self.assertEqual(3, len(res_dict['group_snapshots']))
        self.assertEqual('this is a test group snapshot',
                         res_dict['group_snapshots'][0]['description'])
        self.assertEqual('test_group_snapshot',
                         res_dict['group_snapshots'][0]['name'])
        self.assertEqual(group_snapshot1.id,
                         res_dict['group_snapshots'][0]['id'])
        self.assertEqual('creating', res_dict['group_snapshots'][0]['status'])

        self.assertEqual('this is a test group snapshot',
                         res_dict['group_snapshots'][1]['description'])
        self.assertEqual('test_group_snapshot',
                         res_dict['group_snapshots'][1]['name'])
        self.assertEqual(group_snapshot2.id,
                         res_dict['group_snapshots'][1]['id'])
        self.assertEqual('creating', res_dict['group_snapshots'][1]['status'])

        self.assertEqual('this is a test group snapshot',
                         res_dict['group_snapshots'][2]['description'])
        self.assertEqual('test_group_snapshot',
                         res_dict['group_snapshots'][2]['name'])
        self.assertEqual(group_snapshot3.id,
                         res_dict['group_snapshots'][2]['id'])
        self.assertEqual('creating', res_dict['group_snapshots'][2]['status'])

        group_snapshot3.destroy()
        group_snapshot2.destroy()
        group_snapshot1.destroy()
        db.volume_destroy(context.get_admin_context(), volume_id)
        group.destroy()
예제 #3
0
    def test_list_cgsnapshots_json(self):
        vol_type = utils.create_volume_type(context.get_admin_context(),
                                            self,
                                            name='my_vol_type')
        consistencygroup = utils.create_group(self.context,
                                              group_type_id=fake.GROUP_TYPE_ID,
                                              volume_type_ids=[vol_type['id']])
        volume_id = utils.create_volume(self.context,
                                        volume_type_id=vol_type['id'],
                                        group_id=consistencygroup.id)['id']
        cgsnapshot1 = utils.create_group_snapshot(
            self.context,
            group_id=consistencygroup.id,
            group_type_id=fake.GROUP_TYPE_ID,
        )
        cgsnapshot2 = utils.create_group_snapshot(
            self.context,
            group_id=consistencygroup.id,
            group_type_id=fake.GROUP_TYPE_ID,
        )
        cgsnapshot3 = utils.create_group_snapshot(
            self.context,
            group_id=consistencygroup.id,
            group_type_id=fake.GROUP_TYPE_ID,
        )

        req = webob.Request.blank('/v2/%s/cgsnapshots' % fake.PROJECT_ID)
        req.method = 'GET'
        req.headers['Content-Type'] = 'application/json'
        res = req.get_response(
            fakes.wsgi_app(fake_auth_context=self.user_ctxt))
        res_dict = jsonutils.loads(res.body)

        self.assertEqual(http_client.OK, res.status_int)
        self.assertEqual(cgsnapshot3.id, res_dict['cgsnapshots'][0]['id'])
        self.assertEqual('test_group_snapshot',
                         res_dict['cgsnapshots'][0]['name'])
        self.assertEqual(cgsnapshot2.id, res_dict['cgsnapshots'][1]['id'])
        self.assertEqual('test_group_snapshot',
                         res_dict['cgsnapshots'][1]['name'])
        self.assertEqual(cgsnapshot1.id, res_dict['cgsnapshots'][2]['id'])
        self.assertEqual('test_group_snapshot',
                         res_dict['cgsnapshots'][2]['name'])

        cgsnapshot3.destroy()
        cgsnapshot2.destroy()
        cgsnapshot1.destroy()
        db.volume_destroy(context.get_admin_context(), volume_id)
        consistencygroup.destroy()
예제 #4
0
    def test_delete_group_snapshot_available(self):
        group = utils.create_group(
            self.context,
            group_type_id=fake.GROUP_TYPE_ID,
            volume_type_ids=[fake.VOLUME_TYPE_ID],
        )
        volume_id = utils.create_volume(
            self.context,
            group_id=group.id,
            volume_type_id=fake.VOLUME_TYPE_ID)['id']
        group_snapshot = utils.create_group_snapshot(self.context,
                                                     group_id=group.id,
                                                     status='available')
        req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s' %
                                      (fake.PROJECT_ID, group_snapshot.id),
                                      version=GROUP_MICRO_VERSION)
        res_dict = self.controller.delete(req, group_snapshot.id)

        group_snapshot = objects.GroupSnapshot.get_by_id(
            self.context, group_snapshot.id)
        self.assertEqual(202, res_dict.status_int)
        self.assertEqual('deleting', group_snapshot.status)

        group_snapshot.destroy()
        db.volume_destroy(context.get_admin_context(), volume_id)
        group.destroy()
    def test_list_group_snapshot_with_limit_and_offset(self, is_detail):
        group_snapshot = utils.create_group_snapshot(
            self.context,
            group_id=self.group.id,
            group_type_id=self.group.group_type_id)
        url = '/v3/%s/group_snapshots?limit=2&offset=1' % fake.PROJECT_ID
        if is_detail:
            url = ('/v3/%s/group_snapshots/detail?limit=2&offset=1' %
                   fake.PROJECT_ID)
        req = fakes.HTTPRequest.blank(url, version=SUPPORT_FILTER_VERSION)
        if is_detail:
            res_dict = self.controller.detail(req)
        else:
            res_dict = self.controller.index(req)

        self.assertEqual(2, len(res_dict))
        self.assertEqual(2, len(res_dict['group_snapshots']))
        self.assertEqual(self.g_snapshots_array[2].id,
                         res_dict['group_snapshots'][0]['id'])
        self.assertEqual(self.g_snapshots_array[1].id,
                         res_dict['group_snapshots'][1]['id'])
        self.assertIsNotNone(res_dict['group_snapshot_links'][0]['href'])
        if is_detail:
            self.assertIn('description', res_dict['group_snapshots'][0].keys())
        else:
            self.assertNotIn('description',
                             res_dict['group_snapshots'][0].keys())
        group_snapshot.destroy()
예제 #6
0
 def test_delete_cgsnapshot_delete_policy_not_auth(self, mock_delete):
     vol_type = utils.create_volume_type(context.get_admin_context(),
                                         self,
                                         name='my_vol_type')
     consistencygroup = utils.create_group(self.context,
                                           group_type_id=fake.GROUP_TYPE_ID,
                                           volume_type_ids=[vol_type['id']])
     volume_id = utils.create_volume(self.context,
                                     volume_type_id=vol_type['id'],
                                     group_id=consistencygroup.id)['id']
     cgsnapshot = utils.create_group_snapshot(
         self.context,
         group_id=consistencygroup.id,
         group_type_id=fake.GROUP_TYPE_ID,
         status='available')
     mock_delete.side_effect = exception.PolicyNotAuthorized(
         message='PolicyNotAuthorized')
     req = webob.Request.blank('/v2/%s/cgsnapshots/%s' %
                               (fake.PROJECT_ID, cgsnapshot.id))
     req.method = 'DELETE'
     req.headers['Content-Type'] = 'application/json'
     res = req.get_response(
         fakes.wsgi_app(fake_auth_context=self.user_ctxt))
     res_dict = jsonutils.loads(res.body)
     self.assertEqual('PolicyNotAuthorized',
                      res_dict['forbidden']['message'])
     cgsnapshot.destroy()
     db.volume_destroy(context.get_admin_context(), volume_id)
     consistencygroup.destroy()
    def test_delete_cgsnapshot_available(self):
        vol_type = utils.create_volume_type(context.get_admin_context(),
                                            self, name='my_vol_type')
        consistencygroup = utils.create_group(
            self.context,
            group_type_id=fake.GROUP_TYPE_ID,
            volume_type_ids=[vol_type['id']])
        volume_id = utils.create_volume(self.context,
                                        volume_type_id=vol_type['id'],
                                        group_id=
                                        consistencygroup.id)['id']
        cgsnapshot = utils.create_group_snapshot(
            self.context, group_id=consistencygroup.id,
            group_type_id=fake.GROUP_TYPE_ID,
            status='available')
        req = webob.Request.blank('/v2/%s/cgsnapshots/%s' %
                                  (fake.PROJECT_ID, cgsnapshot.id))
        req.method = 'DELETE'
        req.headers['Content-Type'] = 'application/json'
        res = req.get_response(fakes.wsgi_app(
            fake_auth_context=self.user_ctxt))

        cgsnapshot = objects.GroupSnapshot.get_by_id(self.context,
                                                     cgsnapshot.id)
        self.assertEqual(http_client.ACCEPTED, res.status_int)
        self.assertEqual('deleting', cgsnapshot.status)

        cgsnapshot.destroy()
        db.volume_destroy(context.get_admin_context(), volume_id)
        consistencygroup.destroy()
    def test_delete_cgsnapshot_available_used_as_source(self):
        vol_type = utils.create_volume_type(context.get_admin_context(),
                                            self, name='my_vol_type')
        consistencygroup = utils.create_group(
            self.context,
            group_type_id=fake.GROUP_TYPE_ID,
            volume_type_ids=[vol_type['id']])
        volume_id = utils.create_volume(self.context,
                                        volume_type_id=vol_type['id'],
                                        group_id=
                                        consistencygroup.id)['id']
        cgsnapshot = utils.create_group_snapshot(
            self.context, group_id=consistencygroup.id,
            group_type_id=fake.GROUP_TYPE_ID,
            status='available')

        cg2 = utils.create_consistencygroup(
            self.context, status='creating',
            group_snapshot_id=cgsnapshot.id,
            group_type_id=fake.GROUP_TYPE_ID)
        req = webob.Request.blank('/v2/fake/cgsnapshots/%s' %
                                  cgsnapshot.id)
        req.method = 'DELETE'
        req.headers['Content-Type'] = 'application/json'
        res = req.get_response(fakes.wsgi_app())

        cgsnapshot = objects.GroupSnapshot.get_by_id(self.context,
                                                     cgsnapshot.id)
        self.assertEqual(http_client.BAD_REQUEST, res.status_int)
        self.assertEqual('available', cgsnapshot.status)

        cgsnapshot.destroy()
        db.volume_destroy(context.get_admin_context(), volume_id)
        consistencygroup.destroy()
        cg2.destroy()
    def test_delete_cgsnapshot_with_invalid_cgsnapshot(self):
        vol_type = utils.create_volume_type(context.get_admin_context(),
                                            self, name='my_vol_type')
        consistencygroup = utils.create_group(
            self.context,
            group_type_id=fake.GROUP_TYPE_ID,
            volume_type_ids=[vol_type['id']])
        volume_id = utils.create_volume(self.context,
                                        volume_type_id=vol_type['id'],
                                        group_id=
                                        consistencygroup.id)['id']
        cgsnapshot = utils.create_group_snapshot(
            self.context, group_id=consistencygroup.id,
            group_type_id=fake.GROUP_TYPE_ID,
            status='invalid')

        req = webob.Request.blank('/v2/%s/cgsnapshots/%s' % (
            fake.PROJECT_ID, cgsnapshot.id))
        req.method = 'DELETE'
        req.headers['Content-Type'] = 'application/json'
        res = req.get_response(fakes.wsgi_app(
            fake_auth_context=self.user_ctxt))
        res_dict = jsonutils.loads(res.body)

        self.assertEqual(http_client.BAD_REQUEST, res.status_int)
        self.assertEqual(http_client.BAD_REQUEST,
                         res_dict['badRequest']['code'])
        self.assertIsNotNone(res_dict['badRequest']['message'])

        cgsnapshot.destroy()
        db.volume_destroy(context.get_admin_context(), volume_id)
        consistencygroup.destroy()
예제 #10
0
    def test_list_group_snapshot_with_limit_and_offset(self, is_detail):
        group_snapshot = utils.create_group_snapshot(
            self.context,
            group_id=self.group.id,
            group_type_id=self.group.group_type_id)
        url = '/v3/%s/group_snapshots?limit=2&offset=1' % fake.PROJECT_ID
        if is_detail:
            url = ('/v3/%s/group_snapshots/detail?limit=2&offset=1' %
                   fake.PROJECT_ID)
        req = fakes.HTTPRequest.blank(url,
                                      version=mv.GROUP_SNAPSHOT_PAGINATION)
        if is_detail:
            res_dict = self.controller.detail(req)
        else:
            res_dict = self.controller.index(req)

        self.assertEqual(2, len(res_dict))
        self.assertEqual(2, len(res_dict['group_snapshots']))
        self.assertEqual(self.g_snapshots_array[2].id,
                         res_dict['group_snapshots'][0]['id'])
        self.assertEqual(self.g_snapshots_array[1].id,
                         res_dict['group_snapshots'][1]['id'])
        self.assertIsNotNone(res_dict['group_snapshot_links'][0]['href'])
        if is_detail:
            self.assertIn('description', res_dict['group_snapshots'][0].keys())
        else:
            self.assertNotIn('description',
                             res_dict['group_snapshots'][0].keys())
        group_snapshot.destroy()
예제 #11
0
    def test_show_group_snapshot(self):
        group = utils.create_group(
            self.context,
            group_type_id=fake.GROUP_TYPE_ID,
            volume_type_ids=[fake.VOLUME_TYPE_ID],
        )
        volume_id = utils.create_volume(
            self.context,
            group_id=group.id,
            volume_type_id=fake.VOLUME_TYPE_ID)['id']
        group_snapshot = utils.create_group_snapshot(self.context,
                                                     group_id=group.id)
        req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s' %
                                      (fake.PROJECT_ID, group_snapshot.id),
                                      version=GROUP_MICRO_VERSION)
        res_dict = self.controller.show(req, group_snapshot.id)

        self.assertEqual(1, len(res_dict))
        self.assertEqual('this is a test group snapshot',
                         res_dict['group_snapshot']['description'])
        self.assertEqual('test_group_snapshot',
                         res_dict['group_snapshot']['name'])
        self.assertEqual('creating', res_dict['group_snapshot']['status'])

        group_snapshot.destroy()
        db.volume_destroy(context.get_admin_context(), volume_id)
        group.destroy()
예제 #12
0
    def test_delete_group_snapshot_available_used_as_source(self):
        group = utils.create_group(
            self.context,
            group_type_id=fake.GROUP_TYPE_ID,
            volume_type_ids=[fake.VOLUME_TYPE_ID],
        )
        volume_id = utils.create_volume(
            self.context,
            group_id=group.id,
            volume_type_id=fake.VOLUME_TYPE_ID)['id']
        group_snapshot = utils.create_group_snapshot(self.context,
                                                     group_id=group.id,
                                                     status='available')

        group2 = utils.create_group(
            self.context,
            status='creating',
            group_snapshot_id=group_snapshot.id,
            group_type_id=fake.GROUP_TYPE_ID,
            volume_type_ids=[fake.VOLUME_TYPE_ID],
        )
        req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s' %
                                      (fake.PROJECT_ID, group_snapshot.id),
                                      version=GROUP_MICRO_VERSION)
        self.assertRaises(webob.exc.HTTPBadRequest, self.controller.delete,
                          req, group_snapshot.id)

        group_snapshot.destroy()
        db.volume_destroy(context.get_admin_context(), volume_id)
        group.destroy()
        group2.destroy()
예제 #13
0
 def test_delete_cgsnapshot_delete_policy_not_auth(self, mock_delete):
     vol_type = utils.create_volume_type(context.get_admin_context(),
                                         self, name='my_vol_type')
     consistencygroup = utils.create_group(
         self.context,
         group_type_id=fake.GROUP_TYPE_ID,
         volume_type_ids=[vol_type['id']])
     volume_id = utils.create_volume(self.context,
                                     volume_type_id=vol_type['id'],
                                     group_id=
                                     consistencygroup.id)['id']
     cgsnapshot = utils.create_group_snapshot(
         self.context, group_id=consistencygroup.id,
         group_type_id=fake.GROUP_TYPE_ID,
         status='available')
     mock_delete.side_effect = exception.PolicyNotAuthorized(
         message='PolicyNotAuthorized')
     req = webob.Request.blank('/v2/%s/cgsnapshots/%s' %
                               (fake.PROJECT_ID, cgsnapshot.id))
     req.method = 'DELETE'
     req.headers['Content-Type'] = 'application/json'
     res = req.get_response(fakes.wsgi_app(
         fake_auth_context=self.user_ctxt))
     res_dict = jsonutils.loads(res.body)
     self.assertEqual('PolicyNotAuthorized',
                      res_dict['forbidden']['message'])
     cgsnapshot.destroy()
     db.volume_destroy(context.get_admin_context(), volume_id)
     consistencygroup.destroy()
예제 #14
0
    def test_list_cgsnapshots_json(self):
        vol_type = utils.create_volume_type(context.get_admin_context(),
                                            self, name='my_vol_type')
        consistencygroup = utils.create_group(
            self.context,
            group_type_id=fake.GROUP_TYPE_ID,
            volume_type_ids=[vol_type['id']])
        volume_id = utils.create_volume(self.context,
                                        volume_type_id=vol_type['id'],
                                        group_id=
                                        consistencygroup.id)['id']
        cgsnapshot1 = utils.create_group_snapshot(
            self.context, group_id=consistencygroup.id,
            group_type_id=fake.GROUP_TYPE_ID,)
        cgsnapshot2 = utils.create_group_snapshot(
            self.context, group_id=consistencygroup.id,
            group_type_id=fake.GROUP_TYPE_ID,)
        cgsnapshot3 = utils.create_group_snapshot(
            self.context, group_id=consistencygroup.id,
            group_type_id=fake.GROUP_TYPE_ID,)

        req = webob.Request.blank('/v2/%s/cgsnapshots' % fake.PROJECT_ID)
        req.method = 'GET'
        req.headers['Content-Type'] = 'application/json'
        res = req.get_response(fakes.wsgi_app(
            fake_auth_context=self.user_ctxt))
        res_dict = jsonutils.loads(res.body)

        self.assertEqual(http_client.OK, res.status_int)
        self.assertEqual(cgsnapshot3.id,
                         res_dict['cgsnapshots'][0]['id'])
        self.assertEqual('test_group_snapshot',
                         res_dict['cgsnapshots'][0]['name'])
        self.assertEqual(cgsnapshot2.id,
                         res_dict['cgsnapshots'][1]['id'])
        self.assertEqual('test_group_snapshot',
                         res_dict['cgsnapshots'][1]['name'])
        self.assertEqual(cgsnapshot1.id,
                         res_dict['cgsnapshots'][2]['id'])
        self.assertEqual('test_group_snapshot',
                         res_dict['cgsnapshots'][2]['name'])

        cgsnapshot3.destroy()
        cgsnapshot2.destroy()
        cgsnapshot1.destroy()
        db.volume_destroy(context.get_admin_context(), volume_id)
        consistencygroup.destroy()
예제 #15
0
 def test_delete_group_snapshot_frozen(self):
     service = utils.create_service(self.ctxt, {'frozen': True})
     group = utils.create_group(self.ctxt, host=service.host,
                                group_type_id='gt')
     gsnap = utils.create_group_snapshot(self.ctxt, group.id)
     group_api = cinder.group.api.API()
     self.assertRaises(exception.InvalidInput,
                       group_api.delete_group_snapshot,
                       self.ctxt, gsnap)
예제 #16
0
 def test_delete_group_snapshot_frozen(self):
     service = utils.create_service(self.ctxt, {'frozen': True})
     group = utils.create_group(self.ctxt,
                                host=service.host,
                                group_type_id='gt')
     gsnap = utils.create_group_snapshot(self.ctxt, group.id)
     group_api = cinder.group.api.API()
     self.assertRaises(exception.InvalidInput,
                       group_api.delete_group_snapshot, self.ctxt, gsnap)
예제 #17
0
    def test_create_from_src(self, mock_validate_host, mock_snap_get_all,
                             mock_group_snap_get, mock_update_quota,
                             mock_create_from_group,
                             mock_create_from_snap):
        name = "test_group"
        description = "this is a test group"
        grp = utils.create_group(self.ctxt, group_type_id=fake.GROUP_TYPE_ID,
                                 volume_type_ids=[fake.VOLUME_TYPE_ID],
                                 availability_zone='nova',
                                 name=name, description=description,
                                 status=fields.GroupStatus.AVAILABLE,)

        vol1 = utils.create_volume(
            self.ctxt,
            availability_zone='nova',
            volume_type_id=fake.VOLUME_TYPE_ID,
            group_id=grp.id)

        snap = utils.create_snapshot(self.ctxt, vol1.id,
                                     volume_type_id=fake.VOLUME_TYPE_ID,
                                     status=fields.SnapshotStatus.AVAILABLE)
        mock_snap_get_all.return_value = [snap]
        mock_validate_host.return_host = True

        grp_snap = utils.create_group_snapshot(
            self.ctxt, grp.id,
            group_type_id=fake.GROUP_TYPE_ID,
            status=fields.GroupStatus.AVAILABLE)
        mock_group_snap_get.return_value = grp_snap

        grp2 = utils.create_group(self.ctxt,
                                  group_type_id=fake.GROUP_TYPE_ID,
                                  volume_type_ids=[fake.VOLUME_TYPE_ID],
                                  availability_zone='nova',
                                  name=name, description=description,
                                  status=fields.GroupStatus.CREATING,
                                  group_snapshot_id=grp_snap.id)

        with mock.patch('cinder.objects.Group') as mock_group:
            mock_group.return_value = grp2
            with mock.patch('cinder.objects.group.Group.create'):
                ret_group = self.group_api.create_from_src(
                    self.ctxt, name, description,
                    group_snapshot_id=grp_snap.id,
                    source_group_id=None)
                self.assertEqual(grp2.obj_to_primitive(),
                                 ret_group.obj_to_primitive())
                mock_create_from_snap.assert_called_once_with(
                    self.ctxt, grp2, grp_snap.id)

        snap.destroy()
        grp_snap.destroy()
        vol1.destroy()
        grp.destroy()
        grp2.destroy()
예제 #18
0
    def test_create_from_src(self, mock_validate_host, mock_snap_get_all,
                             mock_group_snap_get, mock_update_quota,
                             mock_create_from_group,
                             mock_create_from_snap):
        name = "test_group"
        description = "this is a test group"
        grp = utils.create_group(self.ctxt, group_type_id=fake.GROUP_TYPE_ID,
                                 volume_type_ids=[fake.VOLUME_TYPE_ID],
                                 availability_zone='nova',
                                 name=name, description=description,
                                 status=fields.GroupStatus.AVAILABLE,)

        vol1 = utils.create_volume(
            self.ctxt,
            availability_zone='nova',
            volume_type_id=fake.VOLUME_TYPE_ID,
            group_id=grp.id)

        snap = utils.create_snapshot(self.ctxt, vol1.id,
                                     volume_type_id=fake.VOLUME_TYPE_ID,
                                     status=fields.SnapshotStatus.AVAILABLE)
        mock_snap_get_all.return_value = [snap]
        mock_validate_host.return_host = True

        grp_snap = utils.create_group_snapshot(
            self.ctxt, grp.id,
            group_type_id=fake.GROUP_TYPE_ID,
            status=fields.GroupStatus.AVAILABLE)
        mock_group_snap_get.return_value = grp_snap

        grp2 = utils.create_group(self.ctxt,
                                  group_type_id=fake.GROUP_TYPE_ID,
                                  volume_type_ids=[fake.VOLUME_TYPE_ID],
                                  availability_zone='nova',
                                  name=name, description=description,
                                  status=fields.GroupStatus.CREATING,
                                  group_snapshot_id=grp_snap.id)

        with mock.patch('cinder.objects.Group') as mock_group:
            mock_group.return_value = grp2
            with mock.patch('cinder.objects.group.Group.create'):
                ret_group = self.group_api.create_from_src(
                    self.ctxt, name, description,
                    group_snapshot_id=grp_snap.id,
                    source_group_id=None)
                self.assertEqual(grp2.obj_to_primitive(),
                                 ret_group.obj_to_primitive())
                mock_create_from_snap.assert_called_once_with(
                    self.ctxt, grp2, grp_snap.id)

        snap.destroy()
        grp_snap.destroy()
        vol1.destroy()
        grp.destroy()
        grp2.destroy()
예제 #19
0
    def test_delete_group_snapshot_with_invalid_group_snapshot(self):
        group_snapshot = utils.create_group_snapshot(self.context,
                                                     group_id=self.group.id,
                                                     status='invalid')
        req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s' %
                                      (fake.PROJECT_ID, group_snapshot.id),
                                      version=mv.GROUP_SNAPSHOTS)
        self.assertRaises(webob.exc.HTTPBadRequest, self.controller.delete,
                          req, group_snapshot.id)

        group_snapshot.destroy()
예제 #20
0
 def test_reset_group_snapshot_status_invalid_status(self):
     group = utils.create_group(
         self.context, group_type_id=fake.GROUP_TYPE_ID, volume_type_ids=[fake.VOLUME_TYPE_ID]
     )
     group_snapshot = utils.create_group_snapshot(
         self.context, group_id=group.id, status=fields.GroupSnapshotStatus.CREATING
     )
     req = fakes.HTTPRequest.blank(
         "/v3/%s/group_snapshots/%s/action" % (fake.PROJECT_ID, group_snapshot.id), version="3.19"
     )
     body = {"reset_status": {"status": "invalid_test_status"}}
     self.assertRaises(webob.exc.HTTPBadRequest, self.controller.reset_status, req, group_snapshot.id, body)
    def test_delete_group_snapshot_with_invalid_group_snapshot(self):
        group_snapshot = utils.create_group_snapshot(
            self.context,
            group_id=self.group.id,
            status='invalid')
        req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s' %
                                      (fake.PROJECT_ID, group_snapshot.id),
                                      version=GROUP_MICRO_VERSION)
        self.assertRaises(webob.exc.HTTPBadRequest, self.controller.delete,
                          req, group_snapshot.id)

        group_snapshot.destroy()
예제 #22
0
 def test_reset_group_snapshot_status_invalid_status(self):
     group_snapshot = utils.create_group_snapshot(
         self.context,
         group_id=self.group.id,
         status=fields.GroupSnapshotStatus.CREATING)
     req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s/action' %
                                   (fake.PROJECT_ID, group_snapshot.id),
                                   version='3.19')
     body = {"reset_status": {"status": "invalid_test_status"}}
     self.assertRaises(webob.exc.HTTPBadRequest,
                       self.controller.reset_status, req, group_snapshot.id,
                       body)
     group_snapshot.destroy()
예제 #23
0
    def test_delete_group_snapshot_with_invalid_group_snapshot(self):
        group = utils.create_group(
            self.context, group_type_id=fake.GROUP_TYPE_ID, volume_type_ids=[fake.VOLUME_TYPE_ID]
        )
        volume_id = utils.create_volume(self.context, group_id=group.id, volume_type_id=fake.VOLUME_TYPE_ID)["id"]
        group_snapshot = utils.create_group_snapshot(self.context, group_id=group.id, status="invalid")
        req = fakes.HTTPRequest.blank(
            "/v3/%s/group_snapshots/%s" % (fake.PROJECT_ID, group_snapshot.id), version=GROUP_MICRO_VERSION
        )
        self.assertRaises(webob.exc.HTTPBadRequest, self.controller.delete, req, group_snapshot.id)

        group_snapshot.destroy()
        db.volume_destroy(context.get_admin_context(), volume_id)
        group.destroy()
예제 #24
0
    def test_delete_group_snapshot_available(self):
        group_snapshot = utils.create_group_snapshot(self.context,
                                                     group_id=self.group.id,
                                                     status='available')
        req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s' %
                                      (fake.PROJECT_ID, group_snapshot.id),
                                      version=GROUP_MICRO_VERSION)
        res_dict = self.controller.delete(req, group_snapshot.id)

        group_snapshot = objects.GroupSnapshot.get_by_id(
            self.context, group_snapshot.id)
        self.assertEqual(http_client.ACCEPTED, res_dict.status_int)
        self.assertEqual('deleting', group_snapshot.status)

        group_snapshot.destroy()
예제 #25
0
 def test_reset_group_snapshot_status_invalid_status(self):
     group_snapshot = utils.create_group_snapshot(
         self.context,
         group_id=self.group.id,
         status=fields.GroupSnapshotStatus.CREATING)
     req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s/action' %
                                   (fake.PROJECT_ID, group_snapshot.id),
                                   version=mv.GROUP_SNAPSHOT_RESET_STATUS)
     body = {"reset_status": {"status": "invalid_test_status"}}
     self.assertRaises(exception.InvalidGroupSnapshotStatus,
                       self.controller.reset_status,
                       req,
                       group_snapshot.id,
                       body=body)
     group_snapshot.destroy()
 def test_reset_group_snapshot_status_invalid_status(self):
     group_snapshot = utils.create_group_snapshot(
         self.context,
         group_id=self.group.id,
         status=fields.GroupSnapshotStatus.CREATING)
     req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s/action' %
                                   (fake.PROJECT_ID, group_snapshot.id),
                                   version='3.19')
     body = {"reset_status": {
         "status": "invalid_test_status"
     }}
     self.assertRaises(webob.exc.HTTPBadRequest,
                       self.controller.reset_status,
                       req, group_snapshot.id, body)
     group_snapshot.destroy()
예제 #27
0
    def test_reset_group_snapshot_status(self):
        group = utils.create_group(
            self.context, group_type_id=fake.GROUP_TYPE_ID, volume_type_ids=[fake.VOLUME_TYPE_ID]
        )
        group_snapshot = utils.create_group_snapshot(
            self.context, group_id=group.id, status=fields.GroupSnapshotStatus.CREATING
        )
        req = fakes.HTTPRequest.blank(
            "/v3/%s/group_snapshots/%s/action" % (fake.PROJECT_ID, group_snapshot.id), version="3.19"
        )
        body = {"reset_status": {"status": fields.GroupSnapshotStatus.AVAILABLE}}
        response = self.controller.reset_status(req, group_snapshot.id, body)

        g_snapshot = objects.GroupSnapshot.get_by_id(self.context, group_snapshot.id)
        self.assertEqual(202, response.status_int)
        self.assertEqual(fields.GroupSnapshotStatus.AVAILABLE, g_snapshot.status)
예제 #28
0
    def test_show_group_snapshot(self):
        group_snapshot = utils.create_group_snapshot(self.context,
                                                     group_id=self.group.id)
        req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s' %
                                      (fake.PROJECT_ID, group_snapshot.id),
                                      version=GROUP_MICRO_VERSION)
        res_dict = self.controller.show(req, group_snapshot.id)

        self.assertEqual(1, len(res_dict))
        self.assertEqual('this is a test group snapshot',
                         res_dict['group_snapshot']['description'])
        self.assertEqual('test_group_snapshot',
                         res_dict['group_snapshot']['name'])
        self.assertEqual('creating', res_dict['group_snapshot']['status'])

        group_snapshot.destroy()
예제 #29
0
    def test_show_group_snapshot_with_project_id(self):
        group_snapshot = utils.create_group_snapshot(self.context,
                                                     group_id=self.group.id)
        req = fakes.HTTPRequest.blank(
            '/v3/%s/group_snapshots/%s' % (fake.PROJECT_ID, group_snapshot.id),
            version=mv.GROUP_GROUPSNAPSHOT_PROJECT_ID,
            use_admin_context=True)
        res_dict = self.controller.show(req, group_snapshot.id)

        self.assertEqual(1, len(res_dict))
        self.assertEqual('test_group_snapshot',
                         res_dict['group_snapshot']['name'])
        self.assertEqual(fake.PROJECT_ID,
                         res_dict['group_snapshot']['project_id'])

        group_snapshot.destroy()
예제 #30
0
    def test_delete_group_snapshot_available(self):
        group_snapshot = utils.create_group_snapshot(
            self.context,
            group_id=self.group.id,
            status=fields.GroupSnapshotStatus.AVAILABLE)
        req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s' %
                                      (fake.PROJECT_ID, group_snapshot.id),
                                      version=mv.GROUP_SNAPSHOTS)
        res_dict = self.controller.delete(req, group_snapshot.id)

        group_snapshot = objects.GroupSnapshot.get_by_id(
            self.context, group_snapshot.id)
        self.assertEqual(http_client.ACCEPTED, res_dict.status_int)
        self.assertEqual(fields.GroupSnapshotStatus.DELETING,
                         group_snapshot.status)

        group_snapshot.destroy()
    def test_delete_group_snapshot_available(self):
        group_snapshot = utils.create_group_snapshot(
            self.context,
            group_id=self.group.id,
            status=fields.GroupSnapshotStatus.AVAILABLE)
        req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s' %
                                      (fake.PROJECT_ID, group_snapshot.id),
                                      version=GROUP_MICRO_VERSION)
        res_dict = self.controller.delete(req, group_snapshot.id)

        group_snapshot = objects.GroupSnapshot.get_by_id(self.context,
                                                         group_snapshot.id)
        self.assertEqual(http_client.ACCEPTED, res_dict.status_int)
        self.assertEqual(fields.GroupSnapshotStatus.DELETING,
                         group_snapshot.status)

        group_snapshot.destroy()
    def test_show_group_snapshot(self):
        group_snapshot = utils.create_group_snapshot(
            self.context, group_id=self.group.id)
        req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s' %
                                      (fake.PROJECT_ID, group_snapshot.id),
                                      version=GROUP_MICRO_VERSION)
        res_dict = self.controller.show(req, group_snapshot.id)

        self.assertEqual(1, len(res_dict))
        self.assertEqual('this is a test group snapshot',
                         res_dict['group_snapshot']['description'])
        self.assertEqual('test_group_snapshot',
                         res_dict['group_snapshot']['name'])
        self.assertEqual(fields.GroupSnapshotStatus.CREATING,
                         res_dict['group_snapshot']['status'])

        group_snapshot.destroy()
예제 #33
0
    def test_show_group_snapshot_without_project_id(self):
        group_snapshot = utils.create_group_snapshot(self.context,
                                                     group_id=self.group.id)
        # using mv.TRANSFER_WITH_HISTORY (3.57) to test the
        # project_id field is not in response before mv 3.58
        req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s' %
                                      (fake.PROJECT_ID, group_snapshot.id),
                                      version=mv.TRANSFER_WITH_HISTORY,
                                      use_admin_context=True)
        res_dict = self.controller.show(req, group_snapshot.id)

        self.assertEqual(1, len(res_dict))
        self.assertEqual('test_group_snapshot',
                         res_dict['group_snapshot']['name'])
        self.assertNotIn('project_id', res_dict['group_snapshot'])

        group_snapshot.destroy()
예제 #34
0
    def _create_group_snap_array(self):
        group = test_utils.create_group(self.project_admin_context,
                                        status=fields.GroupStatus.AVAILABLE,
                                        group_type_id=fake.GROUP_TYPE_ID,
                                        volume_type_ids=[fake.VOLUME_TYPE_ID])

        test_utils.create_volume(self.project_member_context,
                                 group_id=group.id,
                                 volume_type_id=fake.VOLUME_TYPE_ID)
        g_snapshots_array = [
            test_utils.create_group_snapshot(self.project_admin_context,
                                             group_id=group.id,
                                             group_type_id=group.group_type_id)
            for _ in range(3)
        ]

        return g_snapshots_array
예제 #35
0
    def test_show_group_snapshot(self):
        group_snapshot = utils.create_group_snapshot(self.context,
                                                     group_id=self.group.id)
        req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s' %
                                      (fake.PROJECT_ID, group_snapshot.id),
                                      version=mv.GROUP_SNAPSHOTS)
        res_dict = self.controller.show(req, group_snapshot.id)

        self.assertEqual(1, len(res_dict))
        self.assertEqual('this is a test group snapshot',
                         res_dict['group_snapshot']['description'])
        self.assertEqual('test_group_snapshot',
                         res_dict['group_snapshot']['name'])
        self.assertEqual(fields.GroupSnapshotStatus.CREATING,
                         res_dict['group_snapshot']['status'])

        group_snapshot.destroy()
예제 #36
0
    def test_delete_group_snapshot_available(self):
        group = utils.create_group(
            self.context, group_type_id=fake.GROUP_TYPE_ID, volume_type_ids=[fake.VOLUME_TYPE_ID]
        )
        volume_id = utils.create_volume(self.context, group_id=group.id, volume_type_id=fake.VOLUME_TYPE_ID)["id"]
        group_snapshot = utils.create_group_snapshot(self.context, group_id=group.id, status="available")
        req = fakes.HTTPRequest.blank(
            "/v3/%s/group_snapshots/%s" % (fake.PROJECT_ID, group_snapshot.id), version=GROUP_MICRO_VERSION
        )
        res_dict = self.controller.delete(req, group_snapshot.id)

        group_snapshot = objects.GroupSnapshot.get_by_id(self.context, group_snapshot.id)
        self.assertEqual(202, res_dict.status_int)
        self.assertEqual("deleting", group_snapshot.status)

        group_snapshot.destroy()
        db.volume_destroy(context.get_admin_context(), volume_id)
        group.destroy()
예제 #37
0
    def setUp(self):
        super(VolumeRPCAPITestCase, self).setUp()
        self.rpcapi = volume_rpcapi.VolumeAPI
        self.base_version = '3.0'
        vol = {}
        vol['host'] = 'fake_host'
        vol['availability_zone'] = CONF.storage_availability_zone
        vol['status'] = "available"
        vol['attach_status'] = "detached"
        vol['metadata'] = {"test_key": "test_val"}
        vol['size'] = 1
        vol['volume_type_id'] = fake.VOLUME_TYPE_ID
        volume = db.volume_create(self.context, vol)

        kwargs = {
            'status': fields.SnapshotStatus.CREATING,
            'progress': '0%',
            'display_name': 'fake_name',
            'display_description': 'fake_description'
        }
        snapshot = tests_utils.create_snapshot(self.context, vol['id'],
                                               **kwargs)

        generic_group = tests_utils.create_group(
            self.context,
            availability_zone=CONF.storage_availability_zone,
            group_type_id='group_type1',
            host='fakehost@fakedrv#fakepool')

        group_snapshot = tests_utils.create_group_snapshot(
            self.context,
            group_id=generic_group.id,
            group_type_id=fake.GROUP_TYPE_ID)

        self.fake_volume = jsonutils.to_primitive(volume)
        self.fake_volume_obj = fake_volume.fake_volume_obj(self.context, **vol)
        self.fake_snapshot = snapshot
        self.fake_reservations = ["RESERVATION"]
        self.fake_backup_obj = fake_backup.fake_backup_obj(self.context)
        self.fake_group = generic_group
        self.fake_group_snapshot = group_snapshot

        self.can_send_version_mock = self.patch(
            'oslo_messaging.RPCClient.can_send_version', return_value=True)
예제 #38
0
    def test_delete_group_snapshot_policy_not_authorized(self):
        group_snapshot = utils.create_group_snapshot(
            self.context,
            group_id=self.group.id,
            status=fields.GroupSnapshotStatus.AVAILABLE)

        req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s/' %
                                      (fake.PROJECT_ID, group_snapshot.id),
                                      version=mv.GROUP_SNAPSHOTS,
                                      use_admin_context=False)

        rules = {
            group_snapshots_policy.DELETE_POLICY: base_policy.RULE_ADMIN_API
        }
        policy.set_rules(oslo_policy.Rules.from_dict(rules))
        self.addCleanup(policy.reset)

        self.assertRaises(exception.PolicyNotAuthorized,
                          self.controller.delete, req, group_snapshot.id)
예제 #39
0
    def test_show_group_snapshot(self):
        group = utils.create_group(
            self.context, group_type_id=fake.GROUP_TYPE_ID, volume_type_ids=[fake.VOLUME_TYPE_ID]
        )
        volume_id = utils.create_volume(self.context, group_id=group.id, volume_type_id=fake.VOLUME_TYPE_ID)["id"]
        group_snapshot = utils.create_group_snapshot(self.context, group_id=group.id)
        req = fakes.HTTPRequest.blank(
            "/v3/%s/group_snapshots/%s" % (fake.PROJECT_ID, group_snapshot.id), version=GROUP_MICRO_VERSION
        )
        res_dict = self.controller.show(req, group_snapshot.id)

        self.assertEqual(1, len(res_dict))
        self.assertEqual("this is a test group snapshot", res_dict["group_snapshot"]["description"])
        self.assertEqual("test_group_snapshot", res_dict["group_snapshot"]["name"])
        self.assertEqual("creating", res_dict["group_snapshot"]["status"])

        group_snapshot.destroy()
        db.volume_destroy(context.get_admin_context(), volume_id)
        group.destroy()
    def test_delete_group_snapshot_available_used_as_source(self):
        group_snapshot = utils.create_group_snapshot(
            self.context,
            group_id=self.group.id,
            status=fields.GroupSnapshotStatus.AVAILABLE)

        group2 = utils.create_group(
            self.context, status='creating',
            group_snapshot_id=group_snapshot.id,
            group_type_id=fake.GROUP_TYPE_ID,
            volume_type_ids=[fake.VOLUME_TYPE_ID],)
        req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s' %
                                      (fake.PROJECT_ID, group_snapshot.id),
                                      version=GROUP_MICRO_VERSION)
        self.assertRaises(webob.exc.HTTPBadRequest, self.controller.delete,
                          req, group_snapshot.id)

        group_snapshot.destroy()
        group2.destroy()
예제 #41
0
    def test_delete_group_snapshot_available_used_as_source(self):
        group_snapshot = utils.create_group_snapshot(
            self.context,
            group_id=self.group.id,
            status=fields.GroupSnapshotStatus.AVAILABLE)

        group2 = utils.create_group(
            self.context, status='creating',
            group_snapshot_id=group_snapshot.id,
            group_type_id=fake.GROUP_TYPE_ID,
            volume_type_ids=[fake.VOLUME_TYPE_ID],)
        req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s' %
                                      (fake.PROJECT_ID, group_snapshot.id),
                                      version=mv.GROUP_SNAPSHOTS)
        self.assertRaises(webob.exc.HTTPBadRequest, self.controller.delete,
                          req, group_snapshot.id)

        group_snapshot.destroy()
        group2.destroy()
예제 #42
0
파일: test_rpcapi.py 프로젝트: mahak/cinder
    def setUp(self):
        super(VolumeRPCAPITestCase, self).setUp()
        self.rpcapi = volume_rpcapi.VolumeAPI
        self.base_version = '3.0'
        vol = {}
        vol['host'] = 'fake_host'
        vol['availability_zone'] = CONF.storage_availability_zone
        vol['status'] = "available"
        vol['attach_status'] = "detached"
        vol['metadata'] = {"test_key": "test_val"}
        vol['size'] = 1
        volume = db.volume_create(self.context, vol)

        kwargs = {
            'status': fields.SnapshotStatus.CREATING,
            'progress': '0%',
            'display_name': 'fake_name',
            'display_description': 'fake_description'}
        snapshot = tests_utils.create_snapshot(self.context, vol['id'],
                                               **kwargs)

        generic_group = tests_utils.create_group(
            self.context,
            availability_zone=CONF.storage_availability_zone,
            group_type_id='group_type1',
            host='fakehost@fakedrv#fakepool')

        group_snapshot = tests_utils.create_group_snapshot(
            self.context,
            group_id=generic_group.id,
            group_type_id=fake.GROUP_TYPE_ID)

        self.fake_volume = jsonutils.to_primitive(volume)
        self.fake_volume_obj = fake_volume.fake_volume_obj(self.context, **vol)
        self.fake_snapshot = snapshot
        self.fake_reservations = ["RESERVATION"]
        self.fake_backup_obj = fake_backup.fake_backup_obj(self.context)
        self.fake_group = generic_group
        self.fake_group_snapshot = group_snapshot

        self.can_send_version_mock = self.patch(
            'oslo_messaging.RPCClient.can_send_version', return_value=True)
예제 #43
0
    def test_create_group_from_src_snap(self, mock_validate):
        self.mock_object(volume_api.API, "create", v3_fakes.fake_volume_create)

        group = utils.create_group(self.ctxt,
                                   group_type_id=fake.GROUP_TYPE_ID,
                                   volume_type_ids=[fake.VOLUME_TYPE_ID])
        volume = utils.create_volume(self.ctxt,
                                     group_id=group.id,
                                     volume_type_id=fake.VOLUME_TYPE_ID)
        group_snapshot = utils.create_group_snapshot(
            self.ctxt, group_id=group.id, group_type_id=group.group_type_id)
        snapshot = utils.create_snapshot(
            self.ctxt,
            volume.id,
            group_snapshot_id=group_snapshot.id,
            status=fields.SnapshotStatus.AVAILABLE,
            volume_type_id=volume.volume_type_id)

        test_grp_name = 'test grp'
        body = {
            "create-from-src": {
                "name": test_grp_name,
                "description": "Group 1",
                "group_snapshot_id": group_snapshot.id
            }
        }
        req = fakes.HTTPRequest.blank('/v3/%s/groups/action' % fake.PROJECT_ID,
                                      version=GROUP_FROM_SRC_MICRO_VERSION)
        res_dict = self.controller.create_from_src(req, body)

        self.assertIn('id', res_dict['group'])
        self.assertEqual(test_grp_name, res_dict['group']['name'])
        self.assertTrue(mock_validate.called)

        grp_ref = objects.Group.get_by_id(self.ctxt.elevated(),
                                          res_dict['group']['id'])

        grp_ref.destroy()
        snapshot.destroy()
        volume.destroy()
        group.destroy()
        group_snapshot.destroy()
예제 #44
0
    def test_reset_group_snapshot_status(self):
        group_snapshot = utils.create_group_snapshot(
            self.context,
            group_id=self.group.id,
            status=fields.GroupSnapshotStatus.CREATING)
        req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s/action' %
                                      (fake.PROJECT_ID, group_snapshot.id),
                                      version=mv.GROUP_SNAPSHOT_RESET_STATUS)
        body = {"reset_status": {
            "status": fields.GroupSnapshotStatus.AVAILABLE
        }}
        response = self.controller.reset_status(req, group_snapshot.id,
                                                body=body)

        g_snapshot = objects.GroupSnapshot.get_by_id(self.context,
                                                     group_snapshot.id)
        self.assertEqual(HTTPStatus.ACCEPTED, response.status_int)
        self.assertEqual(fields.GroupSnapshotStatus.AVAILABLE,
                         g_snapshot.status)
        group_snapshot.destroy()
    def test_reset_group_snapshot_status(self):
        group_snapshot = utils.create_group_snapshot(
            self.context,
            group_id=self.group.id,
            status=fields.GroupSnapshotStatus.CREATING)
        req = fakes.HTTPRequest.blank('/v3/%s/group_snapshots/%s/action' %
                                      (fake.PROJECT_ID, group_snapshot.id),
                                      version='3.19')
        body = {"reset_status": {
            "status": fields.GroupSnapshotStatus.AVAILABLE
        }}
        response = self.controller.reset_status(req, group_snapshot.id,
                                                body)

        g_snapshot = objects.GroupSnapshot.get_by_id(self.context,
                                                     group_snapshot.id)
        self.assertEqual(http_client.ACCEPTED, response.status_int)
        self.assertEqual(fields.GroupSnapshotStatus.AVAILABLE,
                         g_snapshot.status)
        group_snapshot.destroy()
예제 #46
0
    def test_create_group_from_src_snap(self, mock_validate):
        self.mock_object(volume_api.API, "create", v3_fakes.fake_volume_create)

        group = utils.create_group(self.ctxt,
                                   group_type_id=fake.GROUP_TYPE_ID,
                                   volume_type_ids=[fake.VOLUME_TYPE_ID])
        volume = utils.create_volume(
            self.ctxt,
            group_id=group.id,
            volume_type_id=fake.VOLUME_TYPE_ID)
        group_snapshot = utils.create_group_snapshot(
            self.ctxt, group_id=group.id,
            group_type_id=group.group_type_id)
        snapshot = utils.create_snapshot(
            self.ctxt,
            volume.id,
            group_snapshot_id=group_snapshot.id,
            status=fields.SnapshotStatus.AVAILABLE,
            volume_type_id=volume.volume_type_id)

        test_grp_name = 'test grp'
        body = {"create-from-src": {"name": test_grp_name,
                                    "description": "Group 1",
                                    "group_snapshot_id": group_snapshot.id}}
        req = fakes.HTTPRequest.blank('/v3/%s/groups/action' %
                                      fake.PROJECT_ID,
                                      version=GROUP_FROM_SRC_MICRO_VERSION)
        res_dict = self.controller.create_from_src(req, body)

        self.assertIn('id', res_dict['group'])
        self.assertEqual(test_grp_name, res_dict['group']['name'])
        self.assertTrue(mock_validate.called)

        grp_ref = objects.Group.get_by_id(
            self.ctxt.elevated(), res_dict['group']['id'])

        grp_ref.destroy()
        snapshot.destroy()
        volume.destroy()
        group.destroy()
        group_snapshot.destroy()
 def setUp(self):
     super(GroupSnapshotsAPITestCase, self).setUp()
     self.controller = v3_group_snapshots.GroupSnapshotsController()
     self.volume_api = cinder.volume.API()
     self.context = context.get_admin_context()
     self.context.project_id = fake.PROJECT_ID
     self.context.user_id = fake.USER_ID
     self.user_ctxt = context.RequestContext(
         fake.USER_ID, fake.PROJECT_ID, auth_token=True)
     self.group = utils.create_group(self.context,
                                     group_type_id=fake.GROUP_TYPE_ID,
                                     volume_type_ids=[fake.VOLUME_TYPE_ID])
     self.volume = utils.create_volume(self.context,
                                       group_id=self.group.id,
                                       volume_type_id=fake.VOLUME_TYPE_ID)
     self.g_snapshots_array = [
         utils.create_group_snapshot(
             self.context,
             group_id=self.group.id,
             group_type_id=self.group.group_type_id) for _ in range(3)]
     self.addCleanup(self._cleanup)
예제 #48
0
    def _create_group_snapshot(self,
                               snap_status=fields.GroupSnapshotStatus.AVAILABLE
                               ):
        volume_type = test_utils.create_volume_type(self.project_admin_context,
                                                    name="test")

        group = test_utils.create_group(self.project_admin_context,
                                        status=fields.GroupStatus.AVAILABLE,
                                        group_type_id=fake.GROUP_TYPE_ID,
                                        volume_type_ids=[volume_type.id])

        test_utils.create_volume(self.project_member_context,
                                 group_id=group.id,
                                 testcase_instance=self,
                                 volume_type_id=volume_type.id)

        return test_utils.create_group_snapshot(
            self.project_admin_context,
            group_id=group.id,
            status=snap_status,
            group_type_id=group.group_type_id)
예제 #49
0
 def setUp(self):
     super(GroupSnapshotsAPITestCase, self).setUp()
     self.controller = v3_group_snapshots.GroupSnapshotsController()
     self.volume_api = cinder.volume.API()
     self.context = context.get_admin_context()
     self.context.project_id = fake.PROJECT_ID
     self.context.user_id = fake.USER_ID
     self.user_ctxt = context.RequestContext(
         fake.USER_ID, fake.PROJECT_ID, auth_token=True)
     self.group = utils.create_group(self.context,
                                     group_type_id=fake.GROUP_TYPE_ID,
                                     volume_type_ids=[fake.VOLUME_TYPE_ID])
     self.volume = utils.create_volume(self.context,
                                       group_id=self.group.id,
                                       volume_type_id=fake.VOLUME_TYPE_ID)
     self.g_snapshots_array = [
         utils.create_group_snapshot(
             self.context,
             group_id=self.group.id,
             group_type_id=self.group.group_type_id) for _ in range(3)]
     self.addCleanup(self._cleanup)
    def test_show_cgsnapshot(self):
        vol_type = utils.create_volume_type(context.get_admin_context(),
                                            self, name='my_vol_type')
        consistencygroup = utils.create_group(
            self.context,
            group_type_id=fake.GROUP_TYPE_ID,
            volume_type_ids=[vol_type['id']])
        volume_id = utils.create_volume(self.context,
                                        volume_type_id=vol_type['id'],
                                        group_id=
                                        consistencygroup.id)['id']
        cgsnapshot = utils.create_group_snapshot(
            self.context, group_id=consistencygroup.id,
            group_type_id=fake.GROUP_TYPE_ID,)
        snapshot_id = utils.create_snapshot(
            self.context,
            volume_type_id=vol_type['id'],
            volume_id=volume_id,
            group_snapshot_id=cgsnapshot.id)['id']

        req = webob.Request.blank('/v2/%s/cgsnapshots/%s' % (
            fake.PROJECT_ID, cgsnapshot.id))
        req.method = 'GET'
        req.headers['Content-Type'] = 'application/json'
        res = req.get_response(fakes.wsgi_app(
            fake_auth_context=self.user_ctxt))
        res_dict = jsonutils.loads(res.body)

        self.assertEqual(http_client.OK, res.status_int)
        self.assertEqual('this is a test group snapshot',
                         res_dict['cgsnapshot']['description'])

        self.assertEqual('test_group_snapshot',
                         res_dict['cgsnapshot']['name'])
        self.assertEqual('creating', res_dict['cgsnapshot']['status'])

        db.snapshot_destroy(context.get_admin_context(), snapshot_id)
        cgsnapshot.destroy()
        db.volume_destroy(context.get_admin_context(), volume_id)
        consistencygroup.destroy()
예제 #51
0
    def test_create_group_from_snap(self, mock_volume_get_all,
                                    mock_rpc_create_group_from_src,
                                    mock_snap_get_all, mock_group_snap_get,
                                    mock_volume_api_create,
                                    mock_mapping_create,
                                    mock_get_volume_type):
        vol_type = utils.create_volume_type(self.ctxt,
                                            name = 'fake_volume_type')
        mock_get_volume_type.return_value = vol_type

        grp_snap = utils.create_group_snapshot(
            self.ctxt, fake.GROUP_ID,
            group_type_id = fake.GROUP_TYPE_ID,
            status = fields.GroupStatus.CREATING)
        mock_group_snap_get.return_value = grp_snap

        vol1 = utils.create_volume(
            self.ctxt,
            availability_zone = 'nova',
            volume_type_id = vol_type['id'],
            group_id = fake.GROUP_ID)

        snap = utils.create_snapshot(self.ctxt, vol1.id,
                                     volume_type_id = vol_type['id'],
                                     status = fields.GroupStatus.CREATING)
        mock_snap_get_all.return_value = [snap]

        name = "test_group"
        description = "this is a test group"
        grp = utils.create_group(self.ctxt, group_type_id = fake.GROUP_TYPE_ID,
                                 volume_type_ids = [vol_type['id']],
                                 availability_zone = 'nova',
                                 name = name, description = description,
                                 group_snapshot_id = grp_snap.id,
                                 status = fields.GroupStatus.CREATING)

        vol2 = utils.create_volume(
            self.ctxt,
            availability_zone = grp.availability_zone,
            volume_type_id = vol_type['id'],
            group_id = grp.id,
            snapshot_id = snap.id)
        mock_volume_get_all.return_value = [vol2]

        self.group_api._create_group_from_group_snapshot(self.ctxt, grp,
                                                         grp_snap.id)

        mock_volume_api_create.assert_called_once_with(
            self.ctxt, 1, None, None,
            availability_zone = grp.availability_zone,
            group_snapshot = grp_snap,
            group = grp,
            snapshot = snap,
            volume_type = vol_type)

        mock_rpc_create_group_from_src.assert_called_once_with(
            self.ctxt, grp, grp_snap)

        vol2.destroy()
        grp.destroy()
        snap.destroy()
        vol1.destroy()
        grp_snap.destroy()
        db.volume_type_destroy(self.ctxt, vol_type['id'])
예제 #52
0
    def setUp(self):
        super(VolumeRpcAPITestCase, self).setUp()
        self.context = context.get_admin_context()
        vol = {}
        vol['host'] = 'fake_host'
        vol['availability_zone'] = CONF.storage_availability_zone
        vol['status'] = "available"
        vol['attach_status'] = "detached"
        vol['metadata'] = {"test_key": "test_val"}
        vol['size'] = 1
        volume = db.volume_create(self.context, vol)

        kwargs = {
            'status': fields.SnapshotStatus.CREATING,
            'progress': '0%',
            'display_name': 'fake_name',
            'display_description': 'fake_description'}
        snapshot = tests_utils.create_snapshot(self.context, vol['id'],
                                               **kwargs)

        source_group = tests_utils.create_consistencygroup(
            self.context,
            availability_zone=CONF.storage_availability_zone,
            volume_type='type1,type2',
            host='fakehost@fakedrv#fakepool')

        cgsnapshot = tests_utils.create_cgsnapshot(
            self.context,
            consistencygroup_id=source_group.id)

        cg = tests_utils.create_consistencygroup(
            self.context,
            availability_zone=CONF.storage_availability_zone,
            volume_type='type1,type2',
            host='fakehost@fakedrv#fakepool',
            cgsnapshot_id=cgsnapshot.id)

        cg2 = tests_utils.create_consistencygroup(
            self.context,
            availability_zone=CONF.storage_availability_zone,
            volume_type='type1,type2',
            host='fakehost@fakedrv#fakepool',
            source_cgid=source_group.id)

        generic_group = tests_utils.create_group(
            self.context,
            availability_zone=CONF.storage_availability_zone,
            group_type_id='group_type1',
            host='fakehost@fakedrv#fakepool')

        group_snapshot = tests_utils.create_group_snapshot(
            self.context,
            group_id=generic_group.id,
            group_type_id='group_type1')

        cg = objects.ConsistencyGroup.get_by_id(self.context, cg.id)
        cg2 = objects.ConsistencyGroup.get_by_id(self.context, cg2.id)
        cgsnapshot = objects.CGSnapshot.get_by_id(self.context, cgsnapshot.id)
        self.fake_volume = jsonutils.to_primitive(volume)
        self.fake_volume_obj = fake_volume.fake_volume_obj(self.context, **vol)
        self.fake_volume_metadata = volume["volume_metadata"]
        self.fake_snapshot = snapshot
        self.fake_reservations = ["RESERVATION"]
        self.fake_cg = cg
        self.fake_cg2 = cg2
        self.fake_src_cg = jsonutils.to_primitive(source_group)
        self.fake_cgsnap = cgsnapshot
        self.fake_backup_obj = fake_backup.fake_backup_obj(self.context)
        self.fake_group = generic_group
        self.fake_group_snapshot = group_snapshot

        self.addCleanup(self._cleanup)