def test_create_consistencygroup_from_src_cgsnapshot_notfound(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']

        test_cg_name = 'test cg'
        body = {"consistencygroup-from-src": {"name": test_cg_name,
                                              "description":
                                              "Consistency Group 1",
                                              "cgsnapshot_id": "fake_cgsnap"}}
        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(404, res.status_int)
        self.assertEqual(404, res_dict['itemNotFound']['code'])
        self.assertIsNotNone(res_dict['itemNotFound']['message'])

        db.volume_destroy(ctxt.elevated(), volume_id)
        db.consistencygroup_destroy(ctxt.elevated(), consistencygroup_id)
    def test_create_consistencygroup_from_src_cg(self):
        self.mock_object(volume_api.API, "create", stubs.stub_volume_create)

        ctxt = context.RequestContext('fake', 'fake', auth_token=True)
        source_cgid = utils.create_consistencygroup(ctxt)['id']
        volume_id = utils.create_volume(
            ctxt,
            consistencygroup_id=source_cgid)['id']

        test_cg_name = 'test cg'
        body = {"consistencygroup-from-src": {"name": test_cg_name,
                                              "description":
                                              "Consistency Group 1",
                                              "source_cgid": source_cgid}}
        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.volume_destroy(ctxt.elevated(), volume_id)
        db.consistencygroup_destroy(ctxt.elevated(), source_cgid)
    def test_update_consistencygroup_remove_volume_not_found(self):
        ctxt = context.RequestContext("fake", "fake")
        consistencygroup_id = self._create_consistencygroup(status="available")
        req = webob.Request.blank("/v2/fake/consistencygroups/%s/update" % consistencygroup_id)
        req.method = "PUT"
        req.headers["Content-Type"] = "application/json"
        body = {
            "consistencygroup": {
                "name": None,
                "description": "new description",
                "add_volumes": None,
                "remove_volumes": "fake-volume-uuid",
            }
        }
        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 volume: Cannot remove volume fake-volume-uuid "
            "from consistency group %(group_id)s because it is not "
            "in the group."
        ) % {"group_id": consistencygroup_id}
        self.assertEqual(msg, res_dict["badRequest"]["message"])

        db.consistencygroup_destroy(ctxt.elevated(), consistencygroup_id)
    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)
Exemple #5
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)
    def test_update_consistencygroup_add_volume_invalid_state(self):
        volume_type_id = "123456"
        ctxt = context.RequestContext("fake", "fake")
        consistencygroup_id = self._create_consistencygroup(status="available")
        add_volume_id = utils.create_volume(ctxt, volume_type_id=volume_type_id, status="wrong_status")["id"]
        req = webob.Request.blank("/v2/fake/consistencygroups/%s/update" % consistencygroup_id)
        req.method = "PUT"
        req.headers["Content-Type"] = "application/json"
        add_volumes = add_volume_id
        body = {"consistencygroup": {"name": "", "description": "", "add_volumes": add_volumes, "remove_volumes": None}}
        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 volume: Cannot add volume %(volume_id)s "
            "to consistency group %(group_id)s because volume is in an "
            "invalid state: %(status)s. Valid states are: ('available', "
            "'in-use')."
        ) % {"volume_id": add_volume_id, "group_id": consistencygroup_id, "status": "wrong_status"}
        self.assertEqual(msg, res_dict["badRequest"]["message"])

        db.consistencygroup_destroy(ctxt.elevated(), consistencygroup_id)
    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)
Exemple #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)
Exemple #9
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)
    def test_update_consistencygroup_invalid_state(self):
        ctxt = context.RequestContext('fake', 'fake')
        wrong_status = 'wrong_status'
        consistencygroup_id = self._create_consistencygroup(
            status=wrong_status)
        req = webob.Request.blank('/v2/fake/consistencygroups/%s/update' %
                                  consistencygroup_id)
        req.method = 'PUT'
        req.headers['Content-Type'] = 'application/json'
        body = {
            "consistencygroup": {
                "name": "new name",
                "description": None,
                "add_volumes": None,
                "remove_volumes": None,
            }
        }
        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: Consistency group status must be "
                "available, but current status is: %s.") % wrong_status
        self.assertEqual(msg, res_dict['badRequest']['message'])

        db.consistencygroup_destroy(ctxt.elevated(), consistencygroup_id)
    def test_update_consistencygroup_add_volume_invalid_volume_type(self):
        ctxt = context.RequestContext('fake', 'fake')
        consistencygroup_id = self._create_consistencygroup(status='available')
        wrong_type = 'wrong-volume-type-id'
        add_volume_id = utils.create_volume(ctxt,
                                            volume_type_id=wrong_type)['id']
        req = webob.Request.blank('/v2/fake/consistencygroups/%s/update' %
                                  consistencygroup_id)
        req.method = 'PUT'
        req.headers['Content-Type'] = 'application/json'
        add_volumes = add_volume_id
        body = {
            "consistencygroup": {
                "name": "",
                "description": "",
                "add_volumes": add_volumes,
                "remove_volumes": None,
            }
        }
        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 volume: Cannot add volume %(volume_id)s "
                 "to consistency group %(group_id)s because volume type "
                 "%(volume_type)s is not supported by the group.") % {
                     'volume_id': add_volume_id,
                     'group_id': consistencygroup_id,
                     'volume_type': wrong_type
                 })
        self.assertEqual(msg, res_dict['badRequest']['message'])

        db.consistencygroup_destroy(ctxt.elevated(), consistencygroup_id)
    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)
Exemple #13
0
    def test_create_consistencygroup_from_src_cgsnapshot_notfound(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']

        test_cg_name = 'test cg'
        body = {
            "consistencygroup-from-src": {
                "name": test_cg_name,
                "description": "Consistency Group 1",
                "cgsnapshot_id": "fake_cgsnap"
            }
        }
        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(404, res.status_int)
        self.assertEqual(404, res_dict['itemNotFound']['code'])
        self.assertIsNotNone(res_dict['itemNotFound']['message'])

        db.volume_destroy(ctxt.elevated(), volume_id)
        db.consistencygroup_destroy(ctxt.elevated(), consistencygroup_id)
    def test_update_consistencygroup_add_volume_invalid_volume_type(self):
        ctxt = context.RequestContext('fake', 'fake')
        consistencygroup_id = self._create_consistencygroup(status='available')
        wrong_type = 'wrong-volume-type-id'
        add_volume_id = utils.create_volume(
            ctxt,
            volume_type_id=wrong_type)['id']
        req = webob.Request.blank('/v2/fake/consistencygroups/%s/update' %
                                  consistencygroup_id)
        req.method = 'PUT'
        req.headers['Content-Type'] = 'application/json'
        add_volumes = add_volume_id
        body = {"consistencygroup": {"name": "",
                                     "description": "",
                                     "add_volumes": add_volumes,
                                     "remove_volumes": None, }}
        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 volume: Cannot add volume %(volume_id)s "
                 "to consistency group %(group_id)s because volume type "
                 "%(volume_type)s is not supported by the group.") %
               {'volume_id': add_volume_id,
                'group_id': consistencygroup_id,
                'volume_type': wrong_type})
        self.assertEqual(msg, res_dict['badRequest']['message'])

        db.consistencygroup_destroy(ctxt.elevated(), consistencygroup_id)
    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)
Exemple #16
0
    def test_create_consistencygroup_from_src_cg(self):
        self.mock_object(volume_api.API, "create", stubs.stub_volume_create)

        ctxt = context.RequestContext('fake', 'fake', auth_token=True)
        source_cgid = utils.create_consistencygroup(ctxt)['id']
        volume_id = utils.create_volume(ctxt,
                                        consistencygroup_id=source_cgid)['id']

        test_cg_name = 'test cg'
        body = {
            "consistencygroup-from-src": {
                "name": test_cg_name,
                "description": "Consistency Group 1",
                "source_cgid": source_cgid
            }
        }
        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.volume_destroy(ctxt.elevated(), volume_id)
        db.consistencygroup_destroy(ctxt.elevated(), source_cgid)
    def test_create_consistencygroup_json(self):
        group_id = "1"

        # Create volume type
        vol_type = 'test'
        db.volume_type_create(context.get_admin_context(), {
            'name': vol_type,
            'extra_specs': {}
        })

        body = {
            "consistencygroup": {
                "name": "cg1",
                "volume_types": vol_type,
                "description": "Consistency Group 1",
            }
        }
        req = webob.Request.blank('/v2/fake/consistencygroups')
        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'])

        db.consistencygroup_destroy(context.get_admin_context(), group_id)
    def test_create_consistencygroup_from_src_create_volume_failed(self, mock_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(400, res.status_int)
        self.assertEqual(400, res_dict["badRequest"]["code"])
        msg = _("Create volume failed.")
        self.assertEqual(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)
Exemple #19
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)
    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)
    def test_update_consistencygroup_remove_volume_not_found(self):
        ctxt = context.RequestContext('fake', 'fake')
        consistencygroup_id = self._create_consistencygroup(status='available')
        req = webob.Request.blank('/v2/fake/consistencygroups/%s/update' %
                                  consistencygroup_id)
        req.method = 'PUT'
        req.headers['Content-Type'] = 'application/json'
        body = {
            "consistencygroup": {
                "name": None,
                "description": "new description",
                "add_volumes": None,
                "remove_volumes": "fake-volume-uuid",
            }
        }
        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 volume: Cannot remove volume fake-volume-uuid "
                 "from consistency group %(group_id)s because it is not "
                 "in the group.") % {
                     'group_id': consistencygroup_id
                 })
        self.assertEqual(msg, res_dict['badRequest']['message'])

        db.consistencygroup_destroy(ctxt.elevated(), consistencygroup_id)
    def test_update_consistencygroup_empty_parameters(self):
        ctxt = context.RequestContext('fake', 'fake')
        consistencygroup_id = self._create_consistencygroup(status='available')
        req = webob.Request.blank('/v2/fake/consistencygroups/%s/update' %
                                  consistencygroup_id)
        req.method = 'PUT'
        req.headers['Content-Type'] = 'application/json'
        body = {
            "consistencygroup": {
                "name": "",
                "description": "",
                "add_volumes": None,
                "remove_volumes": None,
            }
        }
        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'])
        self.assertEqual(
            'Name, description, add_volumes, and remove_volumes '
            'can not be all empty in the request body.',
            res_dict['badRequest']['message'])

        db.consistencygroup_destroy(ctxt.elevated(), consistencygroup_id)
Exemple #23
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(200, res.status_int)
        dom = minidom.parseString(res.body)
        cgsnapshot_detail = dom.getElementsByTagName('cgsnapshot')

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

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

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

        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)
    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)
    def test_update_consistencygroup_success(self):
        volume_type_id = '123456'
        ctxt = context.RequestContext('fake', 'fake')
        consistencygroup_id = self._create_consistencygroup(status='available',
                                                            host='test_host')
        remove_volume_id = utils.create_volume(
            ctxt,
            volume_type_id=volume_type_id,
            consistencygroup_id=consistencygroup_id)['id']
        remove_volume_id2 = utils.create_volume(
            ctxt,
            volume_type_id=volume_type_id,
            consistencygroup_id=consistencygroup_id)['id']

        self.assertEqual(
            'available',
            self._get_consistencygroup_attrib(consistencygroup_id, 'status'))

        cg_volumes = db.volume_get_all_by_group(ctxt.elevated(),
                                                consistencygroup_id)
        cg_vol_ids = [cg_vol['id'] for cg_vol in cg_volumes]
        self.assertIn(remove_volume_id, cg_vol_ids)
        self.assertIn(remove_volume_id2, cg_vol_ids)

        add_volume_id = utils.create_volume(
            ctxt, volume_type_id=volume_type_id)['id']
        add_volume_id2 = utils.create_volume(
            ctxt, volume_type_id=volume_type_id)['id']
        req = webob.Request.blank('/v2/fake/consistencygroups/%s/update' %
                                  consistencygroup_id)
        req.method = 'PUT'
        req.headers['Content-Type'] = 'application/json'
        name = 'newcg'
        description = 'New Consistency Group Description'
        add_volumes = add_volume_id + "," + add_volume_id2
        remove_volumes = remove_volume_id + "," + remove_volume_id2
        body = {
            "consistencygroup": {
                "name": name,
                "description": description,
                "add_volumes": add_volumes,
                "remove_volumes": remove_volumes,
            }
        }
        req.body = json.dumps(body)
        res = req.get_response(fakes.wsgi_app())

        self.assertEqual(202, res.status_int)
        self.assertEqual(
            'updating',
            self._get_consistencygroup_attrib(consistencygroup_id, 'status'))

        db.consistencygroup_destroy(ctxt.elevated(), consistencygroup_id)
 def test_show_consistencygroup_xml_content_type(self):
     consistencygroup_id = self._create_consistencygroup()
     req = webob.Request.blank("/v2/fake/consistencygroups/%s" % consistencygroup_id)
     req.method = "GET"
     req.headers["Content-Type"] = "application/xml"
     req.headers["Accept"] = "application/xml"
     res = req.get_response(fakes.wsgi_app())
     self.assertEqual(200, res.status_int)
     dom = minidom.parseString(res.body)
     consistencygroup = dom.getElementsByTagName("consistencygroup")
     name = consistencygroup.item(0).getAttribute("name")
     self.assertEqual("test_consistencygroup", name.strip())
     db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id)
    def test_delete_consistencygroup_available(self):
        consistencygroup_id = self._create_consistencygroup(status="available")
        req = webob.Request.blank("/v2/fake/consistencygroups/%s/delete" % consistencygroup_id)
        req.method = "POST"
        req.headers["Content-Type"] = "application/json"
        body = {"consistencygroup": {"force": True}}
        req.body = json.dumps(body)
        res = req.get_response(fakes.wsgi_app())

        self.assertEqual(202, res.status_int)
        self.assertEqual("deleting", self._get_consistencygroup_attrib(consistencygroup_id, "status"))

        db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id)
    def test_update_consistencygroup_success(self):
        volume_type_id = '123456'
        ctxt = context.RequestContext('fake', 'fake')
        consistencygroup_id = self._create_consistencygroup(status='available',
                                                            host='test_host')
        remove_volume_id = utils.create_volume(
            ctxt,
            volume_type_id=volume_type_id,
            consistencygroup_id=consistencygroup_id)['id']
        remove_volume_id2 = utils.create_volume(
            ctxt,
            volume_type_id=volume_type_id,
            consistencygroup_id=consistencygroup_id)['id']

        self.assertEqual('available',
                         self._get_consistencygroup_attrib(consistencygroup_id,
                                                           'status'))

        cg_volumes = db.volume_get_all_by_group(ctxt.elevated(),
                                                consistencygroup_id)
        cg_vol_ids = [cg_vol['id'] for cg_vol in cg_volumes]
        self.assertIn(remove_volume_id, cg_vol_ids)
        self.assertIn(remove_volume_id2, cg_vol_ids)

        add_volume_id = utils.create_volume(
            ctxt,
            volume_type_id=volume_type_id)['id']
        add_volume_id2 = utils.create_volume(
            ctxt,
            volume_type_id=volume_type_id)['id']
        req = webob.Request.blank('/v2/fake/consistencygroups/%s/update' %
                                  consistencygroup_id)
        req.method = 'PUT'
        req.headers['Content-Type'] = 'application/json'
        name = 'newcg'
        description = 'New Consistency Group Description'
        add_volumes = add_volume_id + "," + add_volume_id2
        remove_volumes = remove_volume_id + "," + remove_volume_id2
        body = {"consistencygroup": {"name": name,
                                     "description": description,
                                     "add_volumes": add_volumes,
                                     "remove_volumes": remove_volumes, }}
        req.body = json.dumps(body)
        res = req.get_response(fakes.wsgi_app())

        self.assertEqual(202, res.status_int)
        self.assertEqual('updating',
                         self._get_consistencygroup_attrib(consistencygroup_id,
                                                           'status'))

        db.consistencygroup_destroy(ctxt.elevated(), consistencygroup_id)
Exemple #29
0
 def test_volume_type_delete_with_consistencygroups_in_use(self):
     volume_type = db.volume_type_create(self.ctxt,
                                         {'name': 'fake volume type'})
     consistency_group1 = db.consistencygroup_create(
         self.ctxt, {'volume_type_id': volume_type['id']})
     consistency_group2 = db.consistencygroup_create(
         self.ctxt, {'volume_type_id': volume_type['id']})
     self.assertRaises(exception.VolumeTypeInUse, volume_types.destroy,
                       self.ctxt, volume_type['id'])
     db.consistencygroup_destroy(self.ctxt, consistency_group1['id'])
     self.assertRaises(exception.VolumeTypeInUse, volume_types.destroy,
                       self.ctxt, volume_type['id'])
     db.consistencygroup_destroy(self.ctxt, consistency_group2['id'])
     volume_types.destroy(self.ctxt, volume_type['id'])
    def test_show_consistencygroup(self):
        consistencygroup_id = self._create_consistencygroup()
        req = webob.Request.blank("/v2/fake/consistencygroups/%s" % consistencygroup_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(200, res.status_int)
        self.assertEqual("az1", res_dict["consistencygroup"]["availability_zone"])
        self.assertEqual("this is a test consistency group", res_dict["consistencygroup"]["description"])
        self.assertEqual("test_consistencygroup", res_dict["consistencygroup"]["name"])
        self.assertEqual("creating", res_dict["consistencygroup"]["status"])

        db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id)
 def test_show_consistencygroup_xml_content_type(self):
     consistencygroup_id = self._create_consistencygroup()
     req = webob.Request.blank('/v2/fake/consistencygroups/%s' %
                               consistencygroup_id)
     req.method = 'GET'
     req.headers['Content-Type'] = 'application/xml'
     req.headers['Accept'] = 'application/xml'
     res = req.get_response(fakes.wsgi_app())
     self.assertEqual(200, res.status_int)
     dom = minidom.parseString(res.body)
     consistencygroup = dom.getElementsByTagName('consistencygroup')
     name = consistencygroup.item(0).getAttribute('name')
     self.assertEqual("test_consistencygroup", name.strip())
     db.consistencygroup_destroy(context.get_admin_context(),
                                 consistencygroup_id)
Exemple #32
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)
 def test_volume_type_delete_with_consistencygroups_in_use(self):
     volume_type = db.volume_type_create(self.ctxt, {'name':
                                                     'fake volume type'})
     consistency_group1 = db.consistencygroup_create(self.ctxt,
                                                     {'volume_type_id':
                                                      volume_type['id']})
     consistency_group2 = db.consistencygroup_create(self.ctxt,
                                                     {'volume_type_id':
                                                      volume_type['id']})
     self.assertRaises(exception.VolumeTypeInUse, volume_types.destroy,
                       self.ctxt, volume_type['id'])
     db.consistencygroup_destroy(self.ctxt, consistency_group1['id'])
     self.assertRaises(exception.VolumeTypeInUse, volume_types.destroy,
                       self.ctxt, volume_type['id'])
     db.consistencygroup_destroy(self.ctxt, consistency_group2['id'])
     volume_types.destroy(self.ctxt, volume_type['id'])
    def test_create_consistencygroup_json(self):
        group_id = "1"
        body = {"consistencygroup": {"name": "cg1",
                                     "description":
                                     "Consistency Group 1", }}
        req = webob.Request.blank('/v2/fake/consistencygroups')
        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(res.status_int, 202)
        self.assertIn('id', res_dict['consistencygroup'])

        db.consistencygroup_destroy(context.get_admin_context(), group_id)
 def test_show_consistencygroup_xml_content_type(self):
     consistencygroup_id = self._create_consistencygroup()
     req = webob.Request.blank('/v2/fake/consistencygroups/%s' %
                               consistencygroup_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)
     consistencygroup = dom.getElementsByTagName('consistencygroup')
     name = consistencygroup.item(0).getAttribute('name')
     self.assertEqual(name.strip(), "test_consistencygroup")
     db.consistencygroup_destroy(
         context.get_admin_context(),
         consistencygroup_id)
Exemple #36
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)
    def test_delete_consistencygroup_available(self):
        consistencygroup_id = self._create_consistencygroup(status='available')
        req = webob.Request.blank('/v2/fake/consistencygroups/%s/delete' %
                                  consistencygroup_id)
        req.method = 'POST'
        req.headers['Content-Type'] = 'application/json'
        body = {"consistencygroup": {"force": True}}
        req.body = json.dumps(body)
        res = req.get_response(fakes.wsgi_app())

        self.assertEqual(202, res.status_int)
        self.assertEqual(
            'deleting',
            self._get_consistencygroup_attrib(consistencygroup_id, 'status'))

        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id)
    def test_delete_consistencygroup_available(self):
        consistencygroup_id = self._create_consistencygroup(status='available')
        req = webob.Request.blank('/v2/fake/consistencygroups/%s/delete' %
                                  consistencygroup_id)
        req.method = 'POST'
        req.headers['Content-Type'] = 'application/json'
        body = {"consistencygroup": {"force": True}}
        req.body = json.dumps(body)
        res = req.get_response(fakes.wsgi_app())

        self.assertEqual(202, res.status_int)
        self.assertEqual('deleting',
                         self._get_consistencygroup_attrib(consistencygroup_id,
                                                           'status'))

        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id)
Exemple #39
0
    def test_delete_consistencygroup_with_Invalidconsistencygroup(self):
        consistencygroup_id = self._create_consistencygroup(status='invalid')
        req = webob.Request.blank('/v2/fake/consistencygroups/%s/delete' %
                                  consistencygroup_id)
        req.method = 'POST'
        req.headers['Content-Type'] = 'application/json'
        body = {"consistencygroup": {"force": False}}
        req.body = json.dumps(body)
        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 consistency group')

        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id)
    def test_delete_consistencygroup_with_Invalidconsistencygroup(self):
        consistencygroup_id = self._create_consistencygroup(status='invalid')
        req = webob.Request.blank('/v2/fake/consistencygroups/%s/delete' %
                                  consistencygroup_id)
        req.method = 'POST'
        req.headers['Content-Type'] = 'application/json'
        body = {"consistencygroup": {"force": False}}
        req.body = json.dumps(body)
        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 consistency group')

        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id)
    def test_delete_consistencygroup_with_Invalidconsistencygroup(self):
        consistencygroup_id = self._create_consistencygroup(status="invalid")
        req = webob.Request.blank("/v2/fake/consistencygroups/%s/delete" % consistencygroup_id)
        req.method = "POST"
        req.headers["Content-Type"] = "application/json"
        body = {"consistencygroup": {"force": False}}
        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: Consistency group status must be "
            "available or error, but current status is: invalid"
        )
        self.assertEqual(msg, res_dict["badRequest"]["message"])

        db.consistencygroup_destroy(context.get_admin_context(), consistencygroup_id)
    def test_create_consistencygroup_json(self):
        group_id = "1"

        # Create volume type
        vol_type = "test"
        db.volume_type_create(context.get_admin_context(), {"name": vol_type, "extra_specs": {}})

        body = {"consistencygroup": {"name": "cg1", "volume_types": vol_type, "description": "Consistency Group 1"}}
        req = webob.Request.blank("/v2/fake/consistencygroups")
        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"])

        db.consistencygroup_destroy(context.get_admin_context(), group_id)
Exemple #43
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)
Exemple #44
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)
    def test_update_consistencygroup_empty_parameters(self):
        ctxt = context.RequestContext("fake", "fake")
        consistencygroup_id = self._create_consistencygroup(status="available")
        req = webob.Request.blank("/v2/fake/consistencygroups/%s/update" % consistencygroup_id)
        req.method = "PUT"
        req.headers["Content-Type"] = "application/json"
        body = {"consistencygroup": {"name": "", "description": "", "add_volumes": None, "remove_volumes": None}}
        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"])
        self.assertEqual(
            "Name, description, add_volumes, and remove_volumes " "can not be all empty in the request body.",
            res_dict["badRequest"]["message"],
        )

        db.consistencygroup_destroy(ctxt.elevated(), consistencygroup_id)
    def test_update_consistencygroup_success(self):
        volume_type_id = "123456"
        ctxt = context.RequestContext("fake", "fake")
        consistencygroup_id = self._create_consistencygroup(status="available", host="test_host")
        remove_volume_id = utils.create_volume(
            ctxt, volume_type_id=volume_type_id, consistencygroup_id=consistencygroup_id
        )["id"]
        remove_volume_id2 = utils.create_volume(
            ctxt, volume_type_id=volume_type_id, consistencygroup_id=consistencygroup_id
        )["id"]

        self.assertEqual("available", self._get_consistencygroup_attrib(consistencygroup_id, "status"))

        cg_volumes = db.volume_get_all_by_group(ctxt.elevated(), consistencygroup_id)
        cg_vol_ids = [cg_vol["id"] for cg_vol in cg_volumes]
        self.assertIn(remove_volume_id, cg_vol_ids)
        self.assertIn(remove_volume_id2, cg_vol_ids)

        add_volume_id = utils.create_volume(ctxt, volume_type_id=volume_type_id)["id"]
        add_volume_id2 = utils.create_volume(ctxt, volume_type_id=volume_type_id)["id"]
        req = webob.Request.blank("/v2/fake/consistencygroups/%s/update" % consistencygroup_id)
        req.method = "PUT"
        req.headers["Content-Type"] = "application/json"
        name = "newcg"
        description = "New Consistency Group Description"
        add_volumes = add_volume_id + "," + add_volume_id2
        remove_volumes = remove_volume_id + "," + remove_volume_id2
        body = {
            "consistencygroup": {
                "name": name,
                "description": description,
                "add_volumes": add_volumes,
                "remove_volumes": remove_volumes,
            }
        }
        req.body = json.dumps(body)
        res = req.get_response(fakes.wsgi_app())

        self.assertEqual(202, res.status_int)
        self.assertEqual("updating", self._get_consistencygroup_attrib(consistencygroup_id, "status"))

        db.consistencygroup_destroy(ctxt.elevated(), consistencygroup_id)
Exemple #47
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(200, res.status_int)
     dom = minidom.parseString(res.body)
     cgsnapshot = dom.getElementsByTagName('cgsnapshot')
     name = cgsnapshot.item(0).getAttribute('name')
     self.assertEqual('test_cgsnapshot', name.strip())
     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)
    def test_show_consistencygroup(self):
        consistencygroup_id = self._create_consistencygroup()
        req = webob.Request.blank('/v2/fake/consistencygroups/%s' %
                                  consistencygroup_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(200, res.status_int)
        self.assertEqual('az1',
                         res_dict['consistencygroup']['availability_zone'])
        self.assertEqual('this is a test consistency group',
                         res_dict['consistencygroup']['description'])
        self.assertEqual('test_consistencygroup',
                         res_dict['consistencygroup']['name'])
        self.assertEqual('creating', res_dict['consistencygroup']['status'])

        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id)
Exemple #49
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)
    def test_list_consistencygroups_json(self):
        consistencygroup_id1 = self._create_consistencygroup()
        consistencygroup_id2 = self._create_consistencygroup()
        consistencygroup_id3 = self._create_consistencygroup()

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

        self.assertEqual(200, res.status_int)
        self.assertEqual(consistencygroup_id1,
                         res_dict['consistencygroups'][0]['id'])
        self.assertEqual('test_consistencygroup',
                         res_dict['consistencygroups'][0]['name'])
        self.assertEqual(consistencygroup_id2,
                         res_dict['consistencygroups'][1]['id'])
        self.assertEqual('test_consistencygroup',
                         res_dict['consistencygroups'][1]['name'])
        self.assertEqual(consistencygroup_id3,
                         res_dict['consistencygroups'][2]['id'])
        self.assertEqual('test_consistencygroup',
                         res_dict['consistencygroups'][2]['name'])

        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id3)
        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id2)
        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id1)
    def test_list_consistencygroups_xml(self):
        consistencygroup_id1 = self._create_consistencygroup()
        consistencygroup_id2 = self._create_consistencygroup()
        consistencygroup_id3 = self._create_consistencygroup()

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

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

        self.assertEqual(consistencygroup_id1,
                         consistencygroup_list.item(0).getAttribute('id'))
        self.assertEqual(consistencygroup_id2,
                         consistencygroup_list.item(1).getAttribute('id'))
        self.assertEqual(consistencygroup_id3,
                         consistencygroup_list.item(2).getAttribute('id'))

        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id3)
        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id2)
        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id1)
Exemple #52
0
    def test_create_consistencygroup_from_src_both_snap_cg(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,
                "source_cgid": consistencygroup_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'])
        self.assertIsNotNone(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)
Exemple #53
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)
Exemple #54
0
    def test_create_consistencygroup_from_src_source_cg_empty(self):
        ctxt = context.RequestContext('fake', 'fake', auth_token=True)
        source_cgid = utils.create_consistencygroup(ctxt)['id']

        test_cg_name = 'test cg'
        body = {
            "consistencygroup-from-src": {
                "name": test_cg_name,
                "description": "Consistency Group 1",
                "source_cgid": source_cgid
            }
        }
        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'])
        self.assertIsNotNone(res_dict['badRequest']['message'])

        db.consistencygroup_destroy(ctxt.elevated(), source_cgid)
Exemple #55
0
    def test_list_consistencygroups_detail_json(self):
        consistencygroup_id1 = self._create_consistencygroup()
        consistencygroup_id2 = self._create_consistencygroup()
        consistencygroup_id3 = self._create_consistencygroup()

        req = webob.Request.blank('/v2/fake/consistencygroups/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['consistencygroups'][0]['availability_zone'],
                         'az1')
        self.assertEqual(res_dict['consistencygroups'][0]['description'],
                         'this is a test consistency group')
        self.assertEqual(res_dict['consistencygroups'][0]['name'],
                         'test_consistencygroup')
        self.assertEqual(res_dict['consistencygroups'][0]['id'],
                         consistencygroup_id1)
        self.assertEqual(res_dict['consistencygroups'][0]['status'],
                         'creating')

        self.assertEqual(res_dict['consistencygroups'][1]['availability_zone'],
                         'az1')
        self.assertEqual(res_dict['consistencygroups'][1]['description'],
                         'this is a test consistency group')
        self.assertEqual(res_dict['consistencygroups'][1]['name'],
                         'test_consistencygroup')
        self.assertEqual(res_dict['consistencygroups'][1]['id'],
                         consistencygroup_id2)
        self.assertEqual(res_dict['consistencygroups'][1]['status'],
                         'creating')

        self.assertEqual(res_dict['consistencygroups'][2]['availability_zone'],
                         'az1')
        self.assertEqual(res_dict['consistencygroups'][2]['description'],
                         'this is a test consistency group')
        self.assertEqual(res_dict['consistencygroups'][2]['name'],
                         'test_consistencygroup')
        self.assertEqual(res_dict['consistencygroups'][2]['id'],
                         consistencygroup_id3)
        self.assertEqual(res_dict['consistencygroups'][2]['status'],
                         'creating')

        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id3)
        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id2)
        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id1)
 def destroy(self):
     with self.obj_as_admin():
         db.consistencygroup_destroy(self._context, self.id)
Exemple #57
0
 def destroy(self):
     with self.obj_as_admin():
         updated_values = db.consistencygroup_destroy(
             self._context, self.id)
     self.update(updated_values)
     self.obj_reset_changes(updated_values.keys())
Exemple #58
0
    def test_list_consistencygroups_detail_xml(self):
        consistencygroup_id1 = self._create_consistencygroup()
        consistencygroup_id2 = self._create_consistencygroup()
        consistencygroup_id3 = self._create_consistencygroup()

        req = webob.Request.blank('/v2/fake/consistencygroups/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)
        consistencygroup_detail = dom.getElementsByTagName('consistencygroup')

        self.assertEqual(
            consistencygroup_detail.item(0).getAttribute('availability_zone'),
            'az1')
        self.assertEqual(
            consistencygroup_detail.item(0).getAttribute('description'),
            'this is a test consistency group')
        self.assertEqual(
            consistencygroup_detail.item(0).getAttribute('name'),
            'test_consistencygroup')
        self.assertEqual(
            consistencygroup_detail.item(0).getAttribute('id'),
            consistencygroup_id1)
        self.assertEqual(
            consistencygroup_detail.item(0).getAttribute('status'), 'creating')

        self.assertEqual(
            consistencygroup_detail.item(1).getAttribute('availability_zone'),
            'az1')
        self.assertEqual(
            consistencygroup_detail.item(1).getAttribute('description'),
            'this is a test consistency group')
        self.assertEqual(
            consistencygroup_detail.item(1).getAttribute('name'),
            'test_consistencygroup')
        self.assertEqual(
            consistencygroup_detail.item(1).getAttribute('id'),
            consistencygroup_id2)
        self.assertEqual(
            consistencygroup_detail.item(1).getAttribute('status'), 'creating')

        self.assertEqual(
            consistencygroup_detail.item(2).getAttribute('availability_zone'),
            'az1')
        self.assertEqual(
            consistencygroup_detail.item(2).getAttribute('description'),
            'this is a test consistency group')
        self.assertEqual(
            consistencygroup_detail.item(2).getAttribute('name'),
            'test_consistencygroup')
        self.assertEqual(
            consistencygroup_detail.item(2).getAttribute('id'),
            consistencygroup_id3)
        self.assertEqual(
            consistencygroup_detail.item(2).getAttribute('status'), 'creating')

        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id3)
        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id2)
        db.consistencygroup_destroy(context.get_admin_context(),
                                    consistencygroup_id1)