cinder.tests.unit.fake.PROJECT_ID

Here are the examples of the python api cinder.tests.unit.fake.PROJECT_ID taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

199 Examples 7

Example 1

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.get_associations',
                side_effect=return_get_qos_associations)
    def test_get_associations_not_found(self, mock_get_assciations):
        req = fakes.HTTPRequest.blank(
            '/v2/%s/qos-specs/%s/associations' %
            (fake.PROJECT_ID, fake.WILL_NOT_BE_FOUND_ID))
        self.assertRaises(exception.QoSSpecsNotFound,
                          self.controller.associations,
                          req, fake.WILL_NOT_BE_FOUND_ID)

Example 2

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.get_qos_specs',
                side_effect=return_qos_specs_get_qos_specs)
    @mock.patch('cinder.volume.qos_specs.disassociate_qos_specs',
                side_effect=return_associate_qos_specs)
    def test_disassociate_not_found(self, mock_disassociate, mock_get_qos):
        req = fakes.HTTPRequest.blank(
            '/v2/%s/qos-specs/%s/disassociate?vol_type_id=%s' % (
                fake.PROJECT_ID, fake.WILL_NOT_BE_FOUND_ID,
                fake.VOLUME_TYPE_ID))
        self.assertRaises(exception.QoSSpecsNotFound,
                          self.controller.disassociate, req,
                          fake.WILL_NOT_BE_FOUND_ID)

        req = fakes.HTTPRequest.blank(
            '/v2/%s/qos-specs/%s/disassociate?vol_type_id=%s' %
            (fake.PROJECT_ID, fake.VOLUME_TYPE_ID, fake.WILL_NOT_BE_FOUND_ID))
        self.assertRaises(exception.VolumeTypeNotFound,
                          self.controller.disassociate, req,
                          fake.VOLUME_TYPE_ID)

Example 3

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.get_qos_specs',
                side_effect=return_qos_specs_get_qos_specs)
    @mock.patch('cinder.volume.qos_specs.delete',
                side_effect=return_qos_specs_delete)
    def test_qos_specs_delete_inuse(self, mock_qos_delete,
                                    mock_qos_get_specs):
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s' % (
            fake.PROJECT_ID, fake.IN_USE_ID))

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.assertRaises(webob.exc.HTTPBadRequest, self.controller.delete,
                              req, fake.IN_USE_ID)
            self.assertEqual(1, notifier.get_notification_count())

Example 4

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.update',
                side_effect=return_qos_specs_update)
    def test_update_invalid_input(self, mock_qos_update):
        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s' %
                                          (fake.PROJECT_ID, fake.INVALID_ID))
            body = {'qos_specs': {'key1': 'value1',
                                  'key2': 'value2'}}
            self.assertRaises(exception.InvalidQoSSpecs,
                              self.controller.update,
                              req, fake.INVALID_ID, body)
            self.assertEqual(1, notifier.get_notification_count())

Example 5

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.delete_keys',
                side_effect=return_qos_specs_delete_keys)
    def test_qos_specs_delete_keys_qos_notfound(self, mock_qos_specs_delete):
        body = {"keys": ['bar', 'zoo']}
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s/delete_keys' %
                                      (fake.PROJECT_ID,
                                       fake.WILL_NOT_BE_FOUND_ID))

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.assertRaises(exception.QoSSpecsNotFound,
                              self.controller.delete_keys,
                              req, fake.WILL_NOT_BE_FOUND_ID, body)
            self.assertEqual(1, notifier.get_notification_count())

Example 6

Project: cinder Source File: test_qos_specs_manage.py
    def test_index_with_sort_keys(self):
        url = '/v2/%s/qos-specs?sort=id' % fake.PROJECT_ID
        req = fakes.HTTPRequest.blank(url, use_admin_context=True)
        res = self.controller.index(req)
        self.assertEqual(4, len(res['qos_specs']))
        expect_result = [self.qos_id1, self.qos_id2,
                         self.qos_id3, self.qos_id4]
        expect_result.sort(reverse=True)

        self.assertEqual(expect_result[0], res['qos_specs'][0]['id'])
        self.assertEqual(expect_result[1], res['qos_specs'][1]['id'])
        self.assertEqual(expect_result[2], res['qos_specs'][2]['id'])
        self.assertEqual(expect_result[3], res['qos_specs'][3]['id'])

Example 7

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.get_qos_specs',
                side_effect=return_qos_specs_get_qos_specs)
    @mock.patch('cinder.volume.qos_specs.associate_qos_with_type',
                side_effect=return_associate_qos_specs)
    def test_associate_not_found(self, mock_associate, mock_get_qos):
        req = fakes.HTTPRequest.blank(
            '/v2/%s/qos-specs/%s/associate?vol_type_id=%s' % (
                fake.PROJECT_ID, fake.WILL_NOT_BE_FOUND_ID,
                fake.VOLUME_TYPE_ID))
        self.assertRaises(exception.QoSSpecsNotFound,
                          self.controller.associate, req,
                          fake.WILL_NOT_BE_FOUND_ID)

        req = fakes.HTTPRequest.blank(
            '/v2/%s/qos-specs/%s/associate?vol_type_id=%s' %
            (fake.PROJECT_ID, fake.QOS_SPEC_ID, fake.WILL_NOT_BE_FOUND_ID))

        self.assertRaises(exception.VolumeTypeNotFound,
                          self.controller.associate, req, fake.QOS_SPEC_ID)

Example 8

Project: cinder Source File: test_cgsnapshots.py
    def test_delete_cgsnapshot_with_cgsnapshot_NotFound(self):
        req = webob.Request.blank('/v2/%s/cgsnapshots/%s' %
                                  (fake.PROJECT_ID, fake.WILL_NOT_BE_FOUND_ID))
        req.method = 'DELETE'
        req.headers['Content-Type'] = 'application/json'
        res = req.get_response(fakes.wsgi_app(
            fake_auth_context=self.user_ctxt))
        res_dict = jsonutils.loads(res.body)

        self.assertEqual(404, res.status_int)
        self.assertEqual(404, res_dict['itemNotFound']['code'])
        self.assertEqual('CgSnapshot %s could not be found.' %
                         fake.WILL_NOT_BE_FOUND_ID,
                         res_dict['itemNotFound']['message'])

Example 9

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.get_qos_specs',
                side_effect=return_qos_specs_get_qos_specs)
    @mock.patch('cinder.volume.qos_specs.disassociate_all',
                side_effect=return_disassociate_all)
    def test_disassociate_all_not_found(self, mock_disassociate, mock_get):
        req = fakes.HTTPRequest.blank(
            '/v2/%s/qos-specs/%s/disassociate_all' % (
                fake.PROJECT_ID, fake.WILL_NOT_BE_FOUND_ID))
        self.assertRaises(exception.QoSSpecsNotFound,
                          self.controller.disassociate_all, req,
                          fake.WILL_NOT_BE_FOUND_ID)

Example 10

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.get_all_specs',
                side_effect=return_qos_specs_get_all)
    def test_index(self, mock_get_all_specs):
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs' % fake.PROJECT_ID)
        res = self.controller.index(req)

        self.assertEqual(3, len(res['qos_specs']))

        names = set()
        for item in res['qos_specs']:
            self.assertEqual('value1', item['specs']['key1'])
            names.add(item['name'])
        expected_names = ['qos_specs_%s' % fake.QOS_SPEC_ID,
                          'qos_specs_%s' % fake.QOS_SPEC2_ID,
                          'qos_specs_%s' % fake.QOS_SPEC3_ID]
        self.assertEqual(set(expected_names), names)

Example 11

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.update',
                side_effect=return_qos_specs_update)
    def test_update(self, mock_qos_update):
        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s' %
                                          (fake.PROJECT_ID, fake.QOS_SPEC_ID))
            body = {'qos_specs': {'key1': 'value1',
                                  'key2': 'value2'}}
            res = self.controller.update(req, fake.QOS_SPEC_ID, body)
            self.assertDictMatch(body, res)
            self.assertEqual(1, notifier.get_notification_count())

Example 12

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.delete_keys',
                side_effect=return_qos_specs_delete_keys)
    def test_qos_specs_delete_keys_get_notifier(self, mock_qos_delete_keys):
        body = {"keys": ['bar', 'zoo']}
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s/delete_keys' %
                                      (fake.PROJECT_ID, fake.IN_USE_ID))

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier,
                        autospec=True) as mock_get_notifier:
            self.controller.delete_keys(req, fake.IN_USE_ID, body)
            mock_get_notifier.assert_called_once_with('QoSSpecs')

Example 13

Project: cinder Source File: test_qos_specs_manage.py
    def test_index_with_marker(self):
        url = '/v2/%s/qos-specs?marker=%s' % (fake.PROJECT_ID, self.qos_id4)
        req = fakes.HTTPRequest.blank(url, use_admin_context=True)
        res = self.controller.index(req)

        self.assertEqual(3, len(res['qos_specs']))

Example 14

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.get_qos_specs',
                side_effect=return_qos_specs_get_qos_specs)
    def test_show(self, mock_get_qos_specs):
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s' % (
            fake.PROJECT_ID, fake.QOS_SPEC_ID))
        res_dict = self.controller.show(req, fake.QOS_SPEC_ID)

        self.assertEqual(fake.QOS_SPEC_ID, res_dict['qos_specs']['id'])
        self.assertEqual('qos_specs_%s' % fake.QOS_SPEC_ID,
                         res_dict['qos_specs']['name'])

Example 15

Project: cinder Source File: test_cgsnapshots.py
    def test_show_cgsnapshot_with_cgsnapshot_NotFound(self):
        req = webob.Request.blank('/v2/%s/cgsnapshots/%s' % (
            fake.PROJECT_ID, fake.WILL_NOT_BE_FOUND_ID))
        req.method = 'GET'
        req.headers['Content-Type'] = 'application/json'
        res = req.get_response(fakes.wsgi_app(
            fake_auth_context=self.user_ctxt))
        res_dict = jsonutils.loads(res.body)

        self.assertEqual(404, res.status_int)
        self.assertEqual(404, res_dict['itemNotFound']['code'])
        self.assertEqual('CgSnapshot %s could not be found.' %
                         fake.WILL_NOT_BE_FOUND_ID,
                         res_dict['itemNotFound']['message'])

Example 16

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.get_qos_specs',
                side_effect=return_qos_specs_get_qos_specs)
    @mock.patch('cinder.volume.qos_specs.associate_qos_with_type',
                side_effect=return_associate_qos_specs)
    def test_associate(self, mock_associate, mock_get_qos):
        req = fakes.HTTPRequest.blank(
            '/v2/%s/qos-specs/%s/associate?vol_type_id=%s' %
            (fake.PROJECT_ID, fake.QOS_SPEC_ID, fake.VOLUME_TYPE_ID))
        res = self.controller.associate(req, fake.QOS_SPEC_ID)

        self.assertEqual(202, res.status_int)

Example 17

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.get_qos_specs',
                side_effect=return_qos_specs_get_qos_specs)
    @mock.patch('cinder.volume.qos_specs.delete',
                side_effect=return_qos_specs_delete)
    def test_qos_specs_delete(self, mock_qos_delete, mock_qos_get_specs):
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s' % (
            fake.PROJECT_ID, fake.QOS_SPEC_ID))
        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.controller.delete(req, fake.QOS_SPEC_ID)
            self.assertEqual(1, notifier.get_notification_count())

Example 18

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.get_qos_specs',
                side_effect=return_qos_specs_get_qos_specs)
    @mock.patch('cinder.volume.qos_specs.disassociate_qos_specs',
                side_effect=return_associate_qos_specs)
    def test_disassociate(self, mock_disassociate, mock_get_qos):
        req = fakes.HTTPRequest.blank(
            '/v2/%s/qos-specs/%s/disassociate?vol_type_id=%s' % (
                fake.PROJECT_ID, fake.QOS_SPEC_ID, fake.VOLUME_TYPE_ID))
        res = self.controller.disassociate(req, fake.QOS_SPEC_ID)
        self.assertEqual(202, res.status_int)

Example 19

Project: cinder Source File: test_admin_actions.py
    def _migrate_volume_exec(self, ctx, volume, host, expected_status,
                             force_host_copy=False):
        # build request to migrate to host
        req = webob.Request.blank('/v2/%s/volumes/%s/action' % (
            fake.PROJECT_ID, volume['id']))
        req.method = 'POST'
        req.headers['content-type'] = 'application/json'
        body = {'os-migrate_volume': {'host': host,
                                      'force_host_copy': force_host_copy}}
        req.body = jsonutils.dump_as_bytes(body)
        req.environ['cinder.context'] = ctx
        resp = req.get_response(app())
        # verify status
        self.assertEqual(expected_status, resp.status_int)
        volume = db.volume_get(self.ctx, volume['id'])
        return volume

Example 20

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.get_qos_specs',
                side_effect=return_qos_specs_get_qos_specs)
    @mock.patch('cinder.volume.qos_specs.disassociate_all',
                side_effect=return_disassociate_all)
    def test_disassociate_all(self, mock_disassociate, mock_get_qos):
        req = fakes.HTTPRequest.blank(
            '/v2/%s/qos-specs/%s/disassociate_all' % (
                fake.PROJECT_ID, fake.QOS_SPEC_ID))
        res = self.controller.disassociate_all(req, fake.QOS_SPEC_ID)
        self.assertEqual(202, res.status_int)

Example 21

Project: cinder Source File: test_qos_specs_manage.py
    def test_qos_specs_delete_with_invalid_force(self):
        invalid_force = "invalid_bool"
        req = fakes.HTTPRequest.blank(
            '/v2/%s/qos-specs/%s/delete_keys?force=%s' %
            (fake.PROJECT_ID, fake.QOS_SPEC_ID, invalid_force))

        self.assertRaises(exception.InvalidParameterValue,
                          self.controller.delete,
                          req, fake.QOS_SPEC_ID)

Example 22

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.delete_keys',
                side_effect=return_qos_specs_delete_keys)
    def test_qos_specs_delete_keys(self, mock_qos_delete_keys):
        body = {"keys": ['bar', 'zoo']}
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s/delete_keys' %
                                      (fake.PROJECT_ID, fake.IN_USE_ID))

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.controller.delete_keys(req, fake.IN_USE_ID, body)
            self.assertEqual(1, notifier.get_notification_count())

Example 23

Project: cinder Source File: test_admin_actions.py
    def test_migrate_volume_without_host_parameter(self):
        expected_status = 400
        host = 'test3'
        volume = self._migrate_volume_prep()
        # build request to migrate without host
        req = webob.Request.blank('/v2/%s/volumes/%s/action' % (
            fake.PROJECT_ID, volume['id']))
        req.method = 'POST'
        req.headers['content-type'] = 'application/json'
        body = {'os-migrate_volume': {'host': host,
                                      'force_host_copy': False}}
        req.body = jsonutils.dump_as_bytes(body)
        req.environ['cinder.context'] = self.ctx
        resp = req.get_response(app())
        # verify status
        self.assertEqual(expected_status, resp.status_int)

Example 24

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.delete_keys',
                side_effect=return_qos_specs_delete_keys)
    def test_qos_specs_delete_keys_badkey(self, mock_qos_specs_delete):
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s/delete_keys' %
                                      (fake.PROJECT_ID, fake.IN_USE_ID))
        body = {"keys": ['foo', 'zoo']}

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.assertRaises(exception.QoSSpecsKeyNotFound,
                              self.controller.delete_keys,
                              req, fake.IN_USE_ID, body)
            self.assertEqual(1, notifier.get_notification_count())

Example 25

Project: cinder Source File: test_qos_specs_manage.py
    def test_index_with_limit(self):
        url = '/v2/%s/qos-specs?limit=2' % fake.PROJECT_ID
        req = fakes.HTTPRequest.blank(url, use_admin_context=True)
        res = self.controller.index(req)

        self.assertEqual(2, len(res['qos_specs']))
        self.assertEqual(self.qos_id4, res['qos_specs'][0]['id'])
        self.assertEqual(self.qos_id3, res['qos_specs'][1]['id'])

        expect_next_link = ('http://localhost/v2/%s/qos-specs?limit'
                            '=2&marker=%s') % (
                                fake.PROJECT_ID, res['qos_specs'][1]['id'])
        self.assertEqual(expect_next_link, res['qos_specs_links'][0]['href'])

Example 26

Project: cinder Source File: test_qos_specs_manage.py
    @ddt.data({'name': None},
              {'name': 'n' * 256},
              {'name': ''},
              {'name': '  '})
    def test_create_qos_with_invalid_spec_name(self, value):
        body = {'qos_specs': value}
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs' % fake.PROJECT_ID,
                                      use_admin_context=True)
        req.method = 'POST'
        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.create, req, body)

Example 27

Project: cinder Source File: test_qos_specs_manage.py
    @ddt.data({'foo': {'a': 'b'}},
              {'qos_specs': {'a': 'b'}},
              {'qos_specs': 'string'},
              None)
    def test_create_invalid_body_bad_request(self, body):
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs' % fake.PROJECT_ID,
                                      use_admin_context=True)
        req.method = 'POST'
        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.create, req, body)

Example 28

Project: cinder Source File: test_qos_specs_manage.py
    def test_index_with_limit_and_offset(self):
        url = '/v2/%s/qos-specs?limit=2&offset=1' % fake.PROJECT_ID
        req = fakes.HTTPRequest.blank(url, use_admin_context=True)
        res = self.controller.index(req)

        self.assertEqual(2, len(res['qos_specs']))
        self.assertEqual(self.qos_id3, res['qos_specs'][0]['id'])
        self.assertEqual(self.qos_id2, res['qos_specs'][1]['id'])

Example 29

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.update',
                side_effect=return_qos_specs_update)
    def test_update_not_found(self, mock_qos_update):
        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s' %
                                          (fake.PROJECT_ID,
                                           fake.WILL_NOT_BE_FOUND_ID))
            body = {'qos_specs': {'key1': 'value1',
                                  'key2': 'value2'}}
            self.assertRaises(exception.QoSSpecsNotFound,
                              self.controller.update,
                              req, fake.WILL_NOT_BE_FOUND_ID, body)
            self.assertEqual(1, notifier.get_notification_count())

Example 30

Project: cinder Source File: test_cgsnapshots.py
    def setUp(self):
        super(CgsnapshotsAPITestCase, self).setUp()
        self.volume_api = cinder.volume.API()
        self.context = context.get_admin_context()
        self.context.project_id = fake.PROJECT_ID
        self.context.user_id = fake.USER_ID
        self.user_ctxt = context.RequestContext(
            fake.USER_ID, fake.PROJECT_ID, auth_token=True)

Example 31

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.update',
                side_effect=return_qos_specs_update)
    def test_update_failed(self, mock_qos_update):
        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s' %
                                          (fake.PROJECT_ID,
                                           fake.UPDATE_FAILED_ID))
            body = {'qos_specs': {'key1': 'value1',
                                  'key2': 'value2'}}
            self.assertRaises(webob.exc.HTTPInternalServerError,
                              self.controller.update,
                              req, fake.UPDATE_FAILED_ID, body)
            self.assertEqual(1, notifier.get_notification_count())

Example 32

Project: cinder Source File: test_qos_specs_manage.py
    def test_index_with_filter(self):
        url = '/v2/%s/qos-specs?id=%s' % (fake.PROJECT_ID, self.qos_id4)
        req = fakes.HTTPRequest.blank(url, use_admin_context=True)
        res = self.controller.index(req)

        self.assertEqual(1, len(res['qos_specs']))
        self.assertEqual(self.qos_id4, res['qos_specs'][0]['id'])

Example 33

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.get_associations',
                side_effect=return_get_qos_associations)
    def test_get_associations(self, mock_get_assciations):
        req = fakes.HTTPRequest.blank(
            '/v2/%s/qos-specs/%s/associations' % (
                fake.PROJECT_ID, fake.QOS_SPEC_ID))
        res = self.controller.associations(req, fake.QOS_SPEC_ID)

        self.assertEqual('FakeVolTypeName',
                         res['qos_associations'][0]['name'])
        self.assertEqual(fake.VOLUME_TYPE_ID,
                         res['qos_associations'][0]['id'])

Example 34

Project: cinder Source File: test_admin_actions.py
    def test_force_delete(self):
        # current status is creating
        volume = self._create_volume(self.ctx, {'size': 1, 'host': None})
        req = webob.Request.blank('/v2/%s/volumes/%s/action' % (
            fake.PROJECT_ID, volume['id']))
        req.method = 'POST'
        req.headers['content-type'] = 'application/json'
        req.body = jsonutils.dump_as_bytes({'os-force_delete': {}})
        # attach admin context to request
        req.environ['cinder.context'] = self.ctx
        resp = req.get_response(app())
        # request is accepted
        self.assertEqual(202, resp.status_int)
        # volume is deleted
        self.assertRaises(exception.NotFound, objects.Volume.get_by_id,
                          self.ctx, volume.id)

Example 35

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.get_associations',
                side_effect=return_get_qos_associations)
    def test_get_associations_failed(self, mock_get_associations):
        req = fakes.HTTPRequest.blank(
            '/v2/%s/qos-specs/%s/associations' % (
                fake.PROJECT_ID, fake.RAISE_ID))
        self.assertRaises(webob.exc.HTTPInternalServerError,
                          self.controller.associations,
                          req, fake.RAISE_ID)

Example 36

Project: cinder Source File: test_qos_specs_manage.py
    def test_index_with_sort_keys_and_sort_dirs(self):
        url = '/v2/%s/qos-specs?sort=id:asc' % fake.PROJECT_ID
        req = fakes.HTTPRequest.blank(url, use_admin_context=True)
        res = self.controller.index(req)
        self.assertEqual(4, len(res['qos_specs']))
        expect_result = [self.qos_id1, self.qos_id2,
                         self.qos_id3, self.qos_id4]
        expect_result.sort()

        self.assertEqual(expect_result[0], res['qos_specs'][0]['id'])
        self.assertEqual(expect_result[1], res['qos_specs'][1]['id'])
        self.assertEqual(expect_result[2], res['qos_specs'][2]['id'])
        self.assertEqual(expect_result[3], res['qos_specs'][3]['id'])

Example 37

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.get_qos_specs',
                side_effect=return_qos_specs_get_qos_specs)
    @mock.patch('cinder.volume.qos_specs.associate_qos_with_type',
                side_effect=return_associate_qos_specs)
    def test_associate_no_type(self, mock_associate, mock_get_qos):
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s/associate' %
                                      (fake.PROJECT_ID, fake.QOS_SPEC_ID))
        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.associate, req, fake.QOS_SPEC_ID)

Example 38

Project: cinder Source File: test_cgsnapshots.py
    def test_create_cgsnapshot_with_no_body(self):
        # omit body from the request
        req = webob.Request.blank('/v2/%s/cgsnapshots' % fake.PROJECT_ID)
        req.body = jsonutils.dump_as_bytes(None)
        req.method = 'POST'
        req.headers['Content-Type'] = 'application/json'
        req.headers['Accept'] = 'application/json'
        res = req.get_response(fakes.wsgi_app(
            fake_auth_context=self.user_ctxt))
        res_dict = jsonutils.loads(res.body)

        self.assertEqual(400, res.status_int)
        self.assertEqual(400, res_dict['badRequest']['code'])
        self.assertEqual("Missing required element 'cgsnapshot' in "
                         "request body.",
                         res_dict['badRequest']['message'])

Example 39

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.get_qos_specs',
                side_effect=return_qos_specs_get_qos_specs)
    @mock.patch('cinder.volume.qos_specs.associate_qos_with_type',
                side_effect=return_associate_qos_specs)
    def test_associate_fail(self, mock_associate, mock_get_qos):
        req = fakes.HTTPRequest.blank(
            '/v2/%s/qos-specs/%s/associate?vol_type_id=%s' %
            (fake.PROJECT_ID, fake.ACTION_FAILED_ID, fake.VOLUME_TYPE_ID))
        self.assertRaises(webob.exc.HTTPInternalServerError,
                          self.controller.associate, req,
                          fake.ACTION_FAILED_ID)

Example 40

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.get_qos_specs',
                side_effect=return_qos_specs_get_qos_specs)
    @mock.patch('cinder.volume.qos_specs.delete',
                side_effect=return_qos_specs_delete)
    def test_qos_specs_delete_not_found(self, mock_qos_delete,
                                        mock_qos_get_specs):
        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s' %
                                          (fake.PROJECT_ID,
                                           fake.WILL_NOT_BE_FOUND_ID))
            self.assertRaises(exception.QoSSpecsNotFound,
                              self.controller.delete, req,
                              fake.WILL_NOT_BE_FOUND_ID)
            self.assertEqual(1, notifier.get_notification_count())

Example 41

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.get_qos_specs',
                side_effect=return_qos_specs_get_qos_specs)
    @mock.patch('cinder.volume.qos_specs.disassociate_qos_specs',
                side_effect=return_associate_qos_specs)
    def test_disassociate_no_type(self, mock_disassociate, mock_get_qos):
        req = fakes.HTTPRequest.blank(
            '/v2/%s/qos-specs/%s/disassociate' % (
                fake.PROJECT_ID, fake.QOS_SPEC_ID))

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.disassociate, req, fake.QOS_SPEC_ID)

Example 42

Project: cinder Source File: test_admin_actions.py
    def _issue_resource_reset(self, ctx, name, id, status):
        req = webob.Request.blank('/v2/%s/%s/%s/action' % (
            fake.PROJECT_ID, name, id))
        req.method = 'POST'
        req.headers['content-type'] = 'application/json'
        req.body = jsonutils.dump_as_bytes({'os-reset_status': status})
        req.environ['cinder.context'] = ctx
        resp = req.get_response(app())
        return resp

Example 43

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.get_qos_specs',
                side_effect=return_qos_specs_get_qos_specs)
    @mock.patch('cinder.volume.qos_specs.disassociate_qos_specs',
                side_effect=return_associate_qos_specs)
    def test_disassociate_failed(self, mock_disassociate, mock_get_qos):
        req = fakes.HTTPRequest.blank(
            '/v2/%s/qos-specs/%s/disassociate?vol_type_id=%s' % (
                fake.PROJECT_ID, fake.ACTION2_FAILED_ID, fake.VOLUME_TYPE_ID))
        self.assertRaises(webob.exc.HTTPInternalServerError,
                          self.controller.disassociate, req,
                          fake.ACTION2_FAILED_ID)

Example 44

Project: cinder Source File: test_qos_specs_manage.py
    @mock.patch('cinder.volume.qos_specs.get_qos_specs',
                side_effect=return_qos_specs_get_qos_specs)
    @mock.patch('cinder.volume.qos_specs.delete',
                side_effect=return_qos_specs_delete)
    def test_qos_specs_delete_inuse_force(self, mock_qos_delete,
                                          mock_qos_get_specs):
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs/%s?force=True' %
                                      (fake.PROJECT_ID, fake.IN_USE_ID))

        notifier = fake_notifier.get_fake_notifier()
        with mock.patch('cinder.rpc.get_notifier', return_value=notifier):
            self.assertRaises(webob.exc.HTTPInternalServerError,
                              self.controller.delete,
                              req, fake.IN_USE_ID)
            self.assertEqual(1, notifier.get_notification_count())

Example 45

Project: cinder Source File: test_extended_snapshot_attributes.py
Function: test_detail
    def test_detail(self):
        url = '/v2/%s/snapshots/detail' % fake.PROJECT_ID
        res = self._make_request(url)

        self.assertEqual(200, res.status_int)
        for snapshot in self._get_snapshots(res.body):
            self.assertSnapshotAttributes(snapshot,
                                          project_id=fake.PROJECT_ID,
                                          progress='0%')

Example 46

Project: cinder Source File: client.py
Function: init
    def __init__(self, auth_user, auth_key, auth_uri, api_version=None):
        super(TestOpenStackClient, self).__init__()
        self.auth_result = None
        self.auth_user = auth_user
        self.auth_key = auth_key
        self.auth_uri = auth_uri
        # default project_id
        self.project_id = fake.PROJECT_ID
        self.api_version = api_version

Example 47

Project: cinder Source File: test_admin_actions.py
    def test_reset_status_for_missing_volume(self):
        req = webob.Request.blank('/v2/%s/volumes/%s/action' % (
            fake.PROJECT_ID, fake.WILL_NOT_BE_FOUND_ID))
        req.method = 'POST'
        req.headers['content-type'] = 'application/json'
        body = {'os-reset_status': {'status': 'available'}}
        req.body = jsonutils.dump_as_bytes(body)
        req.environ['cinder.context'] = self.ctx
        resp = req.get_response(app())
        self.assertEqual(404, resp.status_int)
        self.assertRaises(exception.NotFound, db.volume_get, self.ctx,
                          fake.WILL_NOT_BE_FOUND_ID)

Example 48

Project: cinder Source File: test_admin_actions.py
    @mock.patch('cinder.backup.rpcapi.BackupAPI.check_support_to_force_delete',
                return_value=False)
    def test_delete_backup_force_when_not_supported(self, mock_check_support):
        # admin context
        self.override_config('backup_driver', 'cinder.backup.drivers.ceph')
        id = test_backups.BackupsAPITestCase._create_backup()
        req = webob.Request.blank('/v2/%s/backups/%s/action' % (
            fake.PROJECT_ID, id))
        req.method = 'POST'
        req.headers['Content-Type'] = 'application/json'
        req.body = jsonutils.dump_as_bytes({'os-force_delete': {}})
        req.environ['cinder.context'] = self.ctx
        res = req.get_response(app())
        self.assertEqual(405, res.status_int)

Example 49

Project: cinder Source File: test_qos_specs_manage.py
    def test_index_with_offset(self):
        url = '/v2/%s/qos-specs?offset=1' % fake.PROJECT_ID
        req = fakes.HTTPRequest.blank(url, use_admin_context=True)
        res = self.controller.index(req)

        self.assertEqual(3, len(res['qos_specs']))

Example 50

Project: cinder Source File: test_qos_specs_manage.py
    @ddt.data({'name': 'fake_name', 'a' * 256: 'a'},
              {'name': 'fake_name', 'a': 'a' * 256},
              {'name': 'fake_name', '': 'a'})
    def test_create_qos_with_invalid_specs(self, value):
        body = {'qos_specs': value}
        req = fakes.HTTPRequest.blank('/v2/%s/qos-specs' % fake.PROJECT_ID,
                                      use_admin_context=True)
        req.method = 'POST'
        self.assertRaises(exception.InvalidInput,
                          self.controller.create, req, body)
See More Examples - Go to Next Page
Page 1 Selected Page 2 Page 3 Page 4