Exemple #1
0
 def test_name_id_snapshot_volume_name(self):
     """Make sure snapshot['volume_name'] is updated."""
     vol_ref = testutils.create_volume(self.ctxt, size=1)
     db.volume_update(self.ctxt, vol_ref['id'], {'name_id': 'fake'})
     snap_ref = testutils.create_snapshot(self.ctxt, vol_ref['id'])
     expected_name = CONF.volume_name_template % 'fake'
     self.assertEquals(snap_ref['volume_name'], expected_name)
Exemple #2
0
 def test_name_id_snapshot_volume_name(self):
     """Make sure snapshot['volume_name'] is updated."""
     vol_ref = testutils.create_volume(self.ctxt, size=1)
     db.volume_update(self.ctxt, vol_ref['id'], {'name_id': 'fake'})
     snap_ref = testutils.create_snapshot(self.ctxt, vol_ref['id'])
     expected_name = CONF.volume_name_template % 'fake'
     self.assertEqual(snap_ref['volume_name'], expected_name)
Exemple #3
0
 def test_name_id_snapshot_volume_name(self):
     """Make sure snapshot['volume_name'] is updated."""
     vol_ref = testutils.create_volume(self.ctxt, size=1)
     db.volume_update(self.ctxt, vol_ref["id"], {"name_id": "fake"})
     snap_ref = testutils.create_snapshot(self.ctxt, vol_ref["id"])
     expected_name = CONF.volume_name_template % "fake"
     self.assertEqual(snap_ref["volume_name"], expected_name)
    def test_create_consistencygroup_from_src(self):
        self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)

        ctxt = context.RequestContext('fake', 'fake', auth_token=True)
        consistencygroup_id = utils.create_consistencygroup(ctxt)['id']
        volume_id = utils.create_volume(
            ctxt, consistencygroup_id=consistencygroup_id)['id']
        cgsnapshot_id = utils.create_cgsnapshot(
            ctxt, consistencygroup_id=consistencygroup_id)['id']
        snapshot_id = utils.create_snapshot(ctxt,
                                            volume_id,
                                            cgsnapshot_id=cgsnapshot_id,
                                            status='available')['id']

        test_cg_name = 'test cg'
        body = {
            "consistencygroup-from-src": {
                "name": test_cg_name,
                "description": "Consistency Group 1",
                "cgsnapshot_id": cgsnapshot_id
            }
        }
        req = webob.Request.blank('/v2/fake/consistencygroups/create_from_src')
        req.method = 'POST'
        req.headers['Content-Type'] = 'application/json'
        req.body = json.dumps(body)
        res = req.get_response(fakes.wsgi_app())
        res_dict = json.loads(res.body)

        self.assertEqual(202, res.status_int)
        self.assertIn('id', res_dict['consistencygroup'])
        self.assertEqual(test_cg_name, res_dict['consistencygroup']['name'])

        db.consistencygroup_destroy(ctxt.elevated(),
                                    res_dict['consistencygroup']['id'])
        db.snapshot_destroy(ctxt.elevated(), snapshot_id)
        db.cgsnapshot_destroy(ctxt.elevated(), cgsnapshot_id)
        db.volume_destroy(ctxt.elevated(), volume_id)
        db.consistencygroup_destroy(ctxt.elevated(), consistencygroup_id)
    def test_create_consistencygroup_from_src_no_host(self):
        ctxt = context.RequestContext('fake', 'fake', auth_token=True)
        consistencygroup_id = utils.create_consistencygroup(
            ctxt,
            host=None)['id']
        volume_id = utils.create_volume(
            ctxt,
            consistencygroup_id=consistencygroup_id)['id']
        cgsnapshot_id = utils.create_cgsnapshot(
            ctxt,
            consistencygroup_id=consistencygroup_id)['id']
        snapshot_id = utils.create_snapshot(
            ctxt,
            volume_id,
            cgsnapshot_id=cgsnapshot_id,
            status='available')['id']

        test_cg_name = 'test cg'
        body = {"consistencygroup-from-src": {"name": test_cg_name,
                                              "description":
                                              "Consistency Group 1",
                                              "cgsnapshot_id": cgsnapshot_id}}
        req = webob.Request.blank('/v2/fake/consistencygroups/create_from_src')
        req.method = 'POST'
        req.headers['Content-Type'] = 'application/json'
        req.body = json.dumps(body)
        res = req.get_response(fakes.wsgi_app())
        res_dict = json.loads(res.body)

        self.assertEqual(400, res.status_int)
        self.assertEqual(400, res_dict['badRequest']['code'])
        msg = _('Invalid ConsistencyGroup: No host to create consistency '
                'group')
        self.assertIn(msg, res_dict['badRequest']['message'])

        db.snapshot_destroy(ctxt.elevated(), snapshot_id)
        db.cgsnapshot_destroy(ctxt.elevated(), cgsnapshot_id)
        db.volume_destroy(ctxt.elevated(), volume_id)
        db.consistencygroup_destroy(ctxt.elevated(), consistencygroup_id)
    def test_create_consistencygroup_from_src(self):
        self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)

        ctxt = context.RequestContext('fake', 'fake', auth_token=True)
        consistencygroup_id = utils.create_consistencygroup(ctxt)['id']
        volume_id = utils.create_volume(
            ctxt,
            consistencygroup_id=consistencygroup_id)['id']
        cgsnapshot_id = utils.create_cgsnapshot(
            ctxt,
            consistencygroup_id=consistencygroup_id)['id']
        snapshot_id = utils.create_snapshot(
            ctxt,
            volume_id,
            cgsnapshot_id=cgsnapshot_id,
            status='available')['id']

        test_cg_name = 'test cg'
        body = {"consistencygroup-from-src": {"name": test_cg_name,
                                              "description":
                                              "Consistency Group 1",
                                              "cgsnapshot_id": cgsnapshot_id}}
        req = webob.Request.blank('/v2/fake/consistencygroups/create_from_src')
        req.method = 'POST'
        req.headers['Content-Type'] = 'application/json'
        req.body = json.dumps(body)
        res = req.get_response(fakes.wsgi_app())
        res_dict = json.loads(res.body)

        self.assertEqual(202, res.status_int)
        self.assertIn('id', res_dict['consistencygroup'])
        self.assertEqual(test_cg_name, res_dict['consistencygroup']['name'])

        db.consistencygroup_destroy(ctxt.elevated(),
                                    res_dict['consistencygroup']['id'])
        db.snapshot_destroy(ctxt.elevated(), snapshot_id)
        db.cgsnapshot_destroy(ctxt.elevated(), cgsnapshot_id)
        db.volume_destroy(ctxt.elevated(), volume_id)
        db.consistencygroup_destroy(ctxt.elevated(), consistencygroup_id)
    def test_create_consistencygroup_from_src_no_host(self):
        ctxt = context.RequestContext('fake', 'fake', auth_token=True)
        consistencygroup_id = utils.create_consistencygroup(ctxt,
                                                            host=None)['id']
        volume_id = utils.create_volume(
            ctxt, consistencygroup_id=consistencygroup_id)['id']
        cgsnapshot_id = utils.create_cgsnapshot(
            ctxt, consistencygroup_id=consistencygroup_id)['id']
        snapshot_id = utils.create_snapshot(ctxt,
                                            volume_id,
                                            cgsnapshot_id=cgsnapshot_id,
                                            status='available')['id']

        test_cg_name = 'test cg'
        body = {
            "consistencygroup-from-src": {
                "name": test_cg_name,
                "description": "Consistency Group 1",
                "cgsnapshot_id": cgsnapshot_id
            }
        }
        req = webob.Request.blank('/v2/fake/consistencygroups/create_from_src')
        req.method = 'POST'
        req.headers['Content-Type'] = 'application/json'
        req.body = json.dumps(body)
        res = req.get_response(fakes.wsgi_app())
        res_dict = json.loads(res.body)

        self.assertEqual(400, res.status_int)
        self.assertEqual(400, res_dict['badRequest']['code'])
        msg = _('Invalid ConsistencyGroup: No host to create consistency '
                'group')
        self.assertIn(msg, res_dict['badRequest']['message'])

        db.snapshot_destroy(ctxt.elevated(), snapshot_id)
        db.cgsnapshot_destroy(ctxt.elevated(), cgsnapshot_id)
        db.volume_destroy(ctxt.elevated(), volume_id)
        db.consistencygroup_destroy(ctxt.elevated(), consistencygroup_id)