Пример #1
0
    def test_create_cgsnapshot_json(self):
        cgsnapshot_id = "1"

        consistencygroup_id = utils.create_consistencygroup(self.context)['id']
        utils.create_volume(self.context,
                            consistencygroup_id=consistencygroup_id)['id']

        body = {
            "cgsnapshot": {
                "name": "cg1",
                "description": "CG Snapshot 1",
                "consistencygroup_id": consistencygroup_id
            }
        }
        req = webob.Request.blank('/v2/fake/cgsnapshots')
        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)
        LOG.info(res_dict)

        self.assertEqual(res.status_int, 202)
        self.assertIn('id', res_dict['cgsnapshot'])

        db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id)
Пример #2
0
    def test_create_consistencygroup_from_src_cgsnapshot_empty(self):
        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']

        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: Cgsnahost is empty. No "
                "consistency group will be created.")
        self.assertIn(msg, res_dict['badRequest']['message'])

        db.cgsnapshot_destroy(ctxt.elevated(), cgsnapshot_id)
        db.volume_destroy(ctxt.elevated(), volume_id)
        db.consistencygroup_destroy(ctxt.elevated(), consistencygroup_id)
Пример #3
0
    def test_list_cgsnapshots_json(self):
        consistencygroup_id = utils.create_consistencygroup(self.context)['id']
        volume_id = utils.create_volume(
            self.context, consistencygroup_id=consistencygroup_id)['id']
        cgsnapshot_id1 = self._create_cgsnapshot(
            consistencygroup_id=consistencygroup_id)
        cgsnapshot_id2 = self._create_cgsnapshot(
            consistencygroup_id=consistencygroup_id)
        cgsnapshot_id3 = self._create_cgsnapshot(
            consistencygroup_id=consistencygroup_id)

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

        self.assertEqual(res.status_int, 200)
        self.assertEqual(res_dict['cgsnapshots'][0]['id'], cgsnapshot_id1)
        self.assertEqual(res_dict['cgsnapshots'][0]['name'], 'test_cgsnapshot')
        self.assertEqual(res_dict['cgsnapshots'][1]['id'], cgsnapshot_id2)
        self.assertEqual(res_dict['cgsnapshots'][1]['name'], 'test_cgsnapshot')
        self.assertEqual(res_dict['cgsnapshots'][2]['id'], cgsnapshot_id3)
        self.assertEqual(res_dict['cgsnapshots'][2]['name'], 'test_cgsnapshot')

        db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id3)
        db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id2)
        db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id1)
        db.volume_destroy(context.get_admin_context(), volume_id)
        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id)
Пример #4
0
    def test_list_cgsnapshots_xml(self):
        consistencygroup_id = utils.create_consistencygroup(self.context)['id']
        volume_id = utils.create_volume(
            self.context, consistencygroup_id=consistencygroup_id)['id']
        cgsnapshot_id1 = self._create_cgsnapshot(
            consistencygroup_id=consistencygroup_id)
        cgsnapshot_id2 = self._create_cgsnapshot(
            consistencygroup_id=consistencygroup_id)
        cgsnapshot_id3 = self._create_cgsnapshot(
            consistencygroup_id=consistencygroup_id)

        req = webob.Request.blank('/v2/fake/cgsnapshots')
        req.method = 'GET'
        req.headers['Content-Type'] = 'application/xml'
        req.headers['Accept'] = 'application/xml'
        res = req.get_response(fakes.wsgi_app())

        self.assertEqual(res.status_int, 200)
        dom = minidom.parseString(res.body)
        cgsnapshot_list = dom.getElementsByTagName('cgsnapshot')

        self.assertEqual(
            cgsnapshot_list.item(0).getAttribute('id'), cgsnapshot_id1)
        self.assertEqual(
            cgsnapshot_list.item(1).getAttribute('id'), cgsnapshot_id2)
        self.assertEqual(
            cgsnapshot_list.item(2).getAttribute('id'), cgsnapshot_id3)

        db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id3)
        db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id2)
        db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id1)
        db.volume_destroy(context.get_admin_context(), volume_id)
        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id)
Пример #5
0
    def test_create_cgsnapshot_json(self):
        cgsnapshot_id = "1"

        consistencygroup_id = utils.create_consistencygroup(self.context)['id']
        utils.create_volume(
            self.context,
            consistencygroup_id=consistencygroup_id)['id']

        body = {"cgsnapshot": {"name": "cg1",
                               "description":
                               "CG Snapshot 1",
                               "consistencygroup_id": consistencygroup_id}}
        req = webob.Request.blank('/v2/fake/cgsnapshots')
        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)
        LOG.info(res_dict)

        self.assertEqual(res.status_int, 202)
        self.assertIn('id', res_dict['cgsnapshot'])

        db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id)
Пример #6
0
    def test_list_cgsnapshots_detail_json(self):
        consistencygroup_id = utils.create_consistencygroup(self.context)["id"]
        volume_id = utils.create_volume(self.context, consistencygroup_id=consistencygroup_id)["id"]
        cgsnapshot_id1 = self._create_cgsnapshot(consistencygroup_id=consistencygroup_id)
        cgsnapshot_id2 = self._create_cgsnapshot(consistencygroup_id=consistencygroup_id)
        cgsnapshot_id3 = self._create_cgsnapshot(consistencygroup_id=consistencygroup_id)

        req = webob.Request.blank("/v2/fake/cgsnapshots/detail")
        req.method = "GET"
        req.headers["Content-Type"] = "application/json"
        req.headers["Accept"] = "application/json"
        res = req.get_response(fakes.wsgi_app())
        res_dict = json.loads(res.body)

        self.assertEqual(res.status_int, 200)
        self.assertEqual(res_dict["cgsnapshots"][0]["description"], "this is a test cgsnapshot")
        self.assertEqual(res_dict["cgsnapshots"][0]["name"], "test_cgsnapshot")
        self.assertEqual(res_dict["cgsnapshots"][0]["id"], cgsnapshot_id1)
        self.assertEqual(res_dict["cgsnapshots"][0]["status"], "creating")

        self.assertEqual(res_dict["cgsnapshots"][1]["description"], "this is a test cgsnapshot")
        self.assertEqual(res_dict["cgsnapshots"][1]["name"], "test_cgsnapshot")
        self.assertEqual(res_dict["cgsnapshots"][1]["id"], cgsnapshot_id2)
        self.assertEqual(res_dict["cgsnapshots"][1]["status"], "creating")

        self.assertEqual(res_dict["cgsnapshots"][2]["description"], "this is a test cgsnapshot")
        self.assertEqual(res_dict["cgsnapshots"][2]["name"], "test_cgsnapshot")
        self.assertEqual(res_dict["cgsnapshots"][2]["id"], cgsnapshot_id3)
        self.assertEqual(res_dict["cgsnapshots"][2]["status"], "creating")

        db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id3)
        db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id2)
        db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id1)
        db.volume_destroy(context.get_admin_context(), volume_id)
        db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id)
Пример #7
0
    def test_create_consistencygroup_from_src_cgsnapshot_empty(self):
        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']

        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: Cgsnahost is empty. No "
                "consistency group will be created.")
        self.assertIn(msg, res_dict['badRequest']['message'])

        db.cgsnapshot_destroy(ctxt.elevated(), cgsnapshot_id)
        db.volume_destroy(ctxt.elevated(), volume_id)
        db.consistencygroup_destroy(ctxt.elevated(), consistencygroup_id)
Пример #8
0
    def test_list_cgsnapshots_xml(self):
        consistencygroup_id = utils.create_consistencygroup(self.context)["id"]
        volume_id = utils.create_volume(self.context, consistencygroup_id=consistencygroup_id)["id"]
        cgsnapshot_id1 = self._create_cgsnapshot(consistencygroup_id=consistencygroup_id)
        cgsnapshot_id2 = self._create_cgsnapshot(consistencygroup_id=consistencygroup_id)
        cgsnapshot_id3 = self._create_cgsnapshot(consistencygroup_id=consistencygroup_id)

        req = webob.Request.blank("/v2/fake/cgsnapshots")
        req.method = "GET"
        req.headers["Content-Type"] = "application/xml"
        req.headers["Accept"] = "application/xml"
        res = req.get_response(fakes.wsgi_app())

        self.assertEqual(res.status_int, 200)
        dom = minidom.parseString(res.body)
        cgsnapshot_list = dom.getElementsByTagName("cgsnapshot")

        self.assertEqual(cgsnapshot_list.item(0).getAttribute("id"), cgsnapshot_id1)
        self.assertEqual(cgsnapshot_list.item(1).getAttribute("id"), cgsnapshot_id2)
        self.assertEqual(cgsnapshot_list.item(2).getAttribute("id"), cgsnapshot_id3)

        db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id3)
        db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id2)
        db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id1)
        db.volume_destroy(context.get_admin_context(), volume_id)
        db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id)
Пример #9
0
    def test_delete_cgsnapshot_available(self):
        consistencygroup_id = utils.create_consistencygroup(self.context)['id']
        volume_id = utils.create_volume(
            self.context,
            consistencygroup_id=consistencygroup_id)['id']
        cgsnapshot_id = self._create_cgsnapshot(
            consistencygroup_id=consistencygroup_id,
            status='available')
        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())

        self.assertEqual(res.status_int, 202)
        self.assertEqual(self._get_cgsnapshot_attrib(cgsnapshot_id,
                         'status'),
                         'deleting')

        db.cgsnapshot_destroy(context.get_admin_context(),
                              cgsnapshot_id)
        db.volume_destroy(context.get_admin_context(),
                          volume_id)
        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id)
Пример #10
0
    def test_delete_cgsnapshot_with_Invalidcgsnapshot(self):
        consistencygroup_id = utils.create_consistencygroup(self.context)['id']
        volume_id = utils.create_volume(
            self.context,
            consistencygroup_id=consistencygroup_id)['id']
        cgsnapshot_id = self._create_cgsnapshot(
            consistencygroup_id=consistencygroup_id,
            status='invalid')
        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())
        res_dict = json.loads(res.body)

        self.assertEqual(res.status_int, 400)
        self.assertEqual(res_dict['badRequest']['code'], 400)
        self.assertEqual(res_dict['badRequest']['message'],
                         'Invalid cgsnapshot')

        db.cgsnapshot_destroy(context.get_admin_context(),
                              cgsnapshot_id)
        db.volume_destroy(context.get_admin_context(),
                          volume_id)
        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id)
Пример #11
0
    def test_show_cgsnapshot(self):
        consistencygroup_id = utils.create_consistencygroup(self.context)['id']
        volume_id = utils.create_volume(self.context,
                                        consistencygroup_id=
                                        consistencygroup_id)['id']
        cgsnapshot_id = self._create_cgsnapshot(
            consistencygroup_id=consistencygroup_id)
        LOG.debug('Created cgsnapshot with id %s' % cgsnapshot_id)
        req = webob.Request.blank('/v2/fake/cgsnapshots/%s' %
                                  cgsnapshot_id)
        req.method = 'GET'
        req.headers['Content-Type'] = 'application/json'
        res = req.get_response(fakes.wsgi_app())
        res_dict = json.loads(res.body)

        self.assertEqual(res.status_int, 200)
        self.assertEqual(res_dict['cgsnapshot']['description'],
                         'this is a test cgsnapshot')
        self.assertEqual(res_dict['cgsnapshot']['name'],
                         'test_cgsnapshot')
        self.assertEqual(res_dict['cgsnapshot']['status'], 'creating')

        db.cgsnapshot_destroy(context.get_admin_context(),
                              cgsnapshot_id)
        db.volume_destroy(context.get_admin_context(),
                          volume_id)
        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id)
Пример #12
0
    def test_list_cgsnapshots_detail_json(self):
        consistencygroup_id = utils.create_consistencygroup(self.context)['id']
        volume_id = utils.create_volume(self.context,
                                        consistencygroup_id=
                                        consistencygroup_id)['id']
        cgsnapshot_id1 = self._create_cgsnapshot(consistencygroup_id=
                                                 consistencygroup_id)
        cgsnapshot_id2 = self._create_cgsnapshot(consistencygroup_id=
                                                 consistencygroup_id)
        cgsnapshot_id3 = self._create_cgsnapshot(consistencygroup_id=
                                                 consistencygroup_id)

        req = webob.Request.blank('/v2/fake/cgsnapshots/detail')
        req.method = 'GET'
        req.headers['Content-Type'] = 'application/json'
        req.headers['Accept'] = 'application/json'
        res = req.get_response(fakes.wsgi_app())
        res_dict = json.loads(res.body)

        self.assertEqual(res.status_int, 200)
        self.assertEqual(res_dict['cgsnapshots'][0]['description'],
                         'this is a test cgsnapshot')
        self.assertEqual(res_dict['cgsnapshots'][0]['name'],
                         'test_cgsnapshot')
        self.assertEqual(res_dict['cgsnapshots'][0]['id'],
                         cgsnapshot_id1)
        self.assertEqual(res_dict['cgsnapshots'][0]['status'],
                         'creating')

        self.assertEqual(res_dict['cgsnapshots'][1]['description'],
                         'this is a test cgsnapshot')
        self.assertEqual(res_dict['cgsnapshots'][1]['name'],
                         'test_cgsnapshot')
        self.assertEqual(res_dict['cgsnapshots'][1]['id'],
                         cgsnapshot_id2)
        self.assertEqual(res_dict['cgsnapshots'][1]['status'],
                         'creating')

        self.assertEqual(res_dict['cgsnapshots'][2]['description'],
                         'this is a test cgsnapshot')
        self.assertEqual(res_dict['cgsnapshots'][2]['name'],
                         'test_cgsnapshot')
        self.assertEqual(res_dict['cgsnapshots'][2]['id'],
                         cgsnapshot_id3)
        self.assertEqual(res_dict['cgsnapshots'][2]['status'],
                         'creating')

        db.cgsnapshot_destroy(context.get_admin_context(),
                              cgsnapshot_id3)
        db.cgsnapshot_destroy(context.get_admin_context(),
                              cgsnapshot_id2)
        db.cgsnapshot_destroy(context.get_admin_context(),
                              cgsnapshot_id1)
        db.volume_destroy(context.get_admin_context(),
                          volume_id)
        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id)
Пример #13
0
    def test_delete_cgsnapshot_available(self):
        consistencygroup_id = utils.create_consistencygroup(self.context)["id"]
        volume_id = utils.create_volume(self.context, consistencygroup_id=consistencygroup_id)["id"]
        cgsnapshot_id = self._create_cgsnapshot(consistencygroup_id=consistencygroup_id, status="available")
        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())

        self.assertEqual(res.status_int, 202)
        self.assertEqual(self._get_cgsnapshot_attrib(cgsnapshot_id, "status"), "deleting")

        db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id)
        db.volume_destroy(context.get_admin_context(), volume_id)
        db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id)
Пример #14
0
    def test_delete_cgsnapshot_with_Invalidcgsnapshot(self):
        consistencygroup_id = utils.create_consistencygroup(self.context)["id"]
        volume_id = utils.create_volume(self.context, consistencygroup_id=consistencygroup_id)["id"]
        cgsnapshot_id = self._create_cgsnapshot(consistencygroup_id=consistencygroup_id, status="invalid")
        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())
        res_dict = json.loads(res.body)

        self.assertEqual(res.status_int, 400)
        self.assertEqual(res_dict["badRequest"]["code"], 400)
        self.assertEqual(res_dict["badRequest"]["message"], "Invalid cgsnapshot")

        db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id)
        db.volume_destroy(context.get_admin_context(), volume_id)
        db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id)
Пример #15
0
    def test_create_with_invalid_cgsnapshot(self, mock_create_cgsnapshot):
        consistencygroup_id = utils.create_consistencygroup(self.context)["id"]
        utils.create_volume(self.context, consistencygroup_id=consistencygroup_id)["id"]

        body = {
            "cgsnapshot": {"name": "cg1", "description": "CG Snapshot 1", "consistencygroup_id": consistencygroup_id}
        }
        req = webob.Request.blank("/v2/fake/cgsnapshots")
        req.body = json.dumps(body)
        req.method = "POST"
        req.headers["Content-Type"] = "application/json"
        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"])
        self.assertEqual("Invalid CgSnapshot: invalid cgsnapshot", res_dict["badRequest"]["message"])
Пример #16
0
    def test_delete_cgsnapshot_available(self):
        consistencygroup_id = utils.create_consistencygroup(self.context)['id']
        volume_id = utils.create_volume(
            self.context, consistencygroup_id=consistencygroup_id)['id']
        cgsnapshot_id = self._create_cgsnapshot(
            consistencygroup_id=consistencygroup_id, status='available')
        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())

        self.assertEqual(res.status_int, 202)
        self.assertEqual(self._get_cgsnapshot_attrib(cgsnapshot_id, 'status'),
                         'deleting')

        db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id)
        db.volume_destroy(context.get_admin_context(), volume_id)
        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id)
Пример #17
0
    def test_show_cgsnapshot(self):
        consistencygroup_id = utils.create_consistencygroup(self.context)["id"]
        volume_id = utils.create_volume(self.context, consistencygroup_id=consistencygroup_id)["id"]
        cgsnapshot_id = self._create_cgsnapshot(consistencygroup_id=consistencygroup_id)
        LOG.debug("Created cgsnapshot with id %s" % cgsnapshot_id)
        req = webob.Request.blank("/v2/fake/cgsnapshots/%s" % cgsnapshot_id)
        req.method = "GET"
        req.headers["Content-Type"] = "application/json"
        res = req.get_response(fakes.wsgi_app())
        res_dict = json.loads(res.body)

        self.assertEqual(res.status_int, 200)
        self.assertEqual(res_dict["cgsnapshot"]["description"], "this is a test cgsnapshot")
        self.assertEqual(res_dict["cgsnapshot"]["name"], "test_cgsnapshot")
        self.assertEqual(res_dict["cgsnapshot"]["status"], "creating")

        db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id)
        db.volume_destroy(context.get_admin_context(), volume_id)
        db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id)
Пример #18
0
    def test_delete_cgsnapshot_with_Invalidcgsnapshot(self):
        consistencygroup_id = utils.create_consistencygroup(self.context)['id']
        volume_id = utils.create_volume(
            self.context, consistencygroup_id=consistencygroup_id)['id']
        cgsnapshot_id = self._create_cgsnapshot(
            consistencygroup_id=consistencygroup_id, status='invalid')
        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())
        res_dict = json.loads(res.body)

        self.assertEqual(res.status_int, 400)
        self.assertEqual(res_dict['badRequest']['code'], 400)
        self.assertEqual(res_dict['badRequest']['message'],
                         'Invalid cgsnapshot')

        db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id)
        db.volume_destroy(context.get_admin_context(), volume_id)
        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id)
Пример #19
0
    def test_create_with_invalid_cgsnapshot(self, mock_create_cgsnapshot):
        consistencygroup_id = utils.create_consistencygroup(self.context)['id']
        utils.create_volume(
            self.context,
            consistencygroup_id=consistencygroup_id)['id']

        body = {"cgsnapshot": {"name": "cg1",
                               "description":
                               "CG Snapshot 1",
                               "consistencygroup_id": consistencygroup_id}}
        req = webob.Request.blank('/v2/fake/cgsnapshots')
        req.body = json.dumps(body)
        req.method = 'POST'
        req.headers['Content-Type'] = 'application/json'
        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'])
        self.assertEqual('Invalid CgSnapshot: invalid cgsnapshot',
                         res_dict['badRequest']['message'])
Пример #20
0
    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)
Пример #21
0
    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)
Пример #22
0
    def test_create_with_invalid_cgsnapshot(self, mock_create_cgsnapshot):
        consistencygroup_id = utils.create_consistencygroup(self.context)['id']
        utils.create_volume(self.context,
                            consistencygroup_id=consistencygroup_id)['id']

        body = {
            "cgsnapshot": {
                "name": "cg1",
                "description": "CG Snapshot 1",
                "consistencygroup_id": consistencygroup_id
            }
        }
        req = webob.Request.blank('/v2/fake/cgsnapshots')
        req.body = json.dumps(body)
        req.method = 'POST'
        req.headers['Content-Type'] = 'application/json'
        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'])
        self.assertEqual('Invalid CgSnapshot: invalid cgsnapshot',
                         res_dict['badRequest']['message'])
Пример #23
0
    def test_show_cgsnapshot(self):
        consistencygroup_id = utils.create_consistencygroup(self.context)['id']
        volume_id = utils.create_volume(
            self.context, consistencygroup_id=consistencygroup_id)['id']
        cgsnapshot_id = self._create_cgsnapshot(
            consistencygroup_id=consistencygroup_id)
        LOG.debug('Created cgsnapshot with id %s' % cgsnapshot_id)
        req = webob.Request.blank('/v2/fake/cgsnapshots/%s' % cgsnapshot_id)
        req.method = 'GET'
        req.headers['Content-Type'] = 'application/json'
        res = req.get_response(fakes.wsgi_app())
        res_dict = json.loads(res.body)

        self.assertEqual(res.status_int, 200)
        self.assertEqual(res_dict['cgsnapshot']['description'],
                         'this is a test cgsnapshot')
        self.assertEqual(res_dict['cgsnapshot']['name'], 'test_cgsnapshot')
        self.assertEqual(res_dict['cgsnapshot']['status'], 'creating')

        db.cgsnapshot_destroy(context.get_admin_context(), cgsnapshot_id)
        db.volume_destroy(context.get_admin_context(), volume_id)
        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id)
Пример #24
0
 def test_show_cgsnapshot_xml_content_type(self):
     consistencygroup_id = utils.create_consistencygroup(self.context)['id']
     volume_id = utils.create_volume(self.context,
                                     consistencygroup_id=
                                     consistencygroup_id)['id']
     cgsnapshot_id = self._create_cgsnapshot(
         consistencygroup_id=consistencygroup_id)
     req = webob.Request.blank('/v2/fake/cgsnapshots/%s' %
                               cgsnapshot_id)
     req.method = 'GET'
     req.headers['Content-Type'] = 'application/xml'
     req.headers['Accept'] = 'application/xml'
     res = req.get_response(fakes.wsgi_app())
     self.assertEqual(res.status_int, 200)
     dom = minidom.parseString(res.body)
     cgsnapshot = dom.getElementsByTagName('cgsnapshot')
     name = cgsnapshot.item(0).getAttribute('name')
     self.assertEqual(name.strip(), "test_cgsnapshot")
     db.cgsnapshot_destroy(context.get_admin_context(),
                           cgsnapshot_id)
     db.volume_destroy(context.get_admin_context(),
                       volume_id)
     db.consistencygroup_destroy(context.get_admin_context(),
                                 consistencygroup_id)
Пример #25
0
    def test_list_cgsnapshots_detail_xml(self):
        consistencygroup_id = utils.create_consistencygroup(self.context)['id']
        volume_id = utils.create_volume(self.context,
                                        consistencygroup_id=
                                        consistencygroup_id)['id']
        cgsnapshot_id1 = self._create_cgsnapshot(consistencygroup_id=
                                                 consistencygroup_id)
        cgsnapshot_id2 = self._create_cgsnapshot(consistencygroup_id=
                                                 consistencygroup_id)
        cgsnapshot_id3 = self._create_cgsnapshot(consistencygroup_id=
                                                 consistencygroup_id)

        req = webob.Request.blank('/v2/fake/cgsnapshots/detail')
        req.method = 'GET'
        req.headers['Content-Type'] = 'application/xml'
        req.headers['Accept'] = 'application/xml'
        res = req.get_response(fakes.wsgi_app())

        self.assertEqual(res.status_int, 200)
        dom = minidom.parseString(res.body)
        cgsnapshot_detail = dom.getElementsByTagName('cgsnapshot')

        self.assertEqual(
            cgsnapshot_detail.item(0).getAttribute('description'),
            'this is a test cgsnapshot')
        self.assertEqual(
            cgsnapshot_detail.item(0).getAttribute('name'),
            'test_cgsnapshot')
        self.assertEqual(
            cgsnapshot_detail.item(0).getAttribute('id'),
            cgsnapshot_id1)
        self.assertEqual(
            cgsnapshot_detail.item(0).getAttribute('status'), 'creating')

        self.assertEqual(
            cgsnapshot_detail.item(1).getAttribute('description'),
            'this is a test cgsnapshot')
        self.assertEqual(
            cgsnapshot_detail.item(1).getAttribute('name'),
            'test_cgsnapshot')
        self.assertEqual(
            cgsnapshot_detail.item(1).getAttribute('id'),
            cgsnapshot_id2)
        self.assertEqual(
            cgsnapshot_detail.item(1).getAttribute('status'), 'creating')

        self.assertEqual(
            cgsnapshot_detail.item(2).getAttribute('description'),
            'this is a test cgsnapshot')
        self.assertEqual(
            cgsnapshot_detail.item(2).getAttribute('name'),
            'test_cgsnapshot')
        self.assertEqual(
            cgsnapshot_detail.item(2).getAttribute('id'),
            cgsnapshot_id3)
        self.assertEqual(
            cgsnapshot_detail.item(2).getAttribute('status'), 'creating')

        db.cgsnapshot_destroy(context.get_admin_context(),
                              cgsnapshot_id3)
        db.cgsnapshot_destroy(context.get_admin_context(),
                              cgsnapshot_id2)
        db.cgsnapshot_destroy(context.get_admin_context(),
                              cgsnapshot_id1)
        db.volume_destroy(context.get_admin_context(),
                          volume_id)
        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id)