Пример #1
0
    def test_volume_types_index_with_extra_specs(self):
        req = fakes.HTTPRequest.blank(
            '/v3/%s/types?extra_specs={"key1":"value1"}' % fake.PROJECT_ID,
            use_admin_context=False)
        req.api_version_request = mv.get_api_version(mv.get_prior_version(
            mv.SUPPORT_VOLUME_TYPE_FILTER))
        res_dict = self.controller.index(req)

        self.assertEqual(3, len(res_dict['volume_types']))

        # Test filter volume type with extra specs
        req = fakes.HTTPRequest.blank(
            '/v3/%s/types?extra_specs={"key1":"value1"}' % fake.PROJECT_ID,
            use_admin_context=True)
        req.api_version_request = mv.get_api_version(
            mv.SUPPORT_VOLUME_TYPE_FILTER)
        res_dict = self.controller.index(req)
        self.assertEqual(1, len(res_dict['volume_types']))
        self.assertDictEqual({'key1': 'value1',
                              'RESKEY:availability_zones': 'az1,az2'},
                             res_dict['volume_types'][0]['extra_specs'])

        # Test filter volume type with 'availability_zones'
        req = fakes.HTTPRequest.blank(
            '/v3/%s/types?extra_specs={"RESKEY:availability_zones":"az1"}'
            % fake.PROJECT_ID, use_admin_context=True)
        req.api_version_request = mv.get_api_version(
            mv.SUPPORT_VOLUME_TYPE_FILTER)
        res_dict = self.controller.index(req)
        self.assertEqual(2, len(res_dict['volume_types']))
        self.assertEqual(
            ['volume_type1', 'volume_type2'],
            sorted([az['name'] for az in res_dict['volume_types']]))
Пример #2
0
    def test_volume_types_index_with_extra_specs(self):
        req = fakes.HTTPRequest.blank(
            '/v3/%s/types?extra_specs={"key1":"value1"}' % fake.PROJECT_ID,
            use_admin_context=False)
        req.api_version_request = mv.get_api_version(mv.get_prior_version(
            mv.SUPPORT_VOLUME_TYPE_FILTER))
        res_dict = self.controller.index(req)

        # since __DEFAULT__ type always exists, total number of volume types
        # is total_types_created + 1. In this case it's 4
        self.assertEqual(4, len(res_dict['volume_types']))

        # Test filter volume type with extra specs
        req = fakes.HTTPRequest.blank(
            '/v3/%s/types?extra_specs={"key1":"value1"}' % fake.PROJECT_ID,
            use_admin_context=True)
        req.api_version_request = mv.get_api_version(
            mv.SUPPORT_VOLUME_TYPE_FILTER)
        res_dict = self.controller.index(req)
        self.assertEqual(1, len(res_dict['volume_types']))
        self.assertDictEqual({'key1': 'value1',
                              'RESKEY:availability_zones': 'az1,az2'},
                             res_dict['volume_types'][0]['extra_specs'])

        # Test filter volume type with 'availability_zones'
        req = fakes.HTTPRequest.blank(
            '/v3/%s/types?extra_specs={"RESKEY:availability_zones":"az1"}'
            % fake.PROJECT_ID, use_admin_context=True)
        req.api_version_request = mv.get_api_version(
            mv.SUPPORT_VOLUME_TYPE_FILTER)
        res_dict = self.controller.index(req)
        self.assertEqual(2, len(res_dict['volume_types']))
        self.assertEqual(
            ['volume_type1', 'volume_type2'],
            sorted([az['name'] for az in res_dict['volume_types']]))
Пример #3
0
    def test_list_volume_with_count_param(self, method, display_param):
        self._create_multiple_volumes_with_different_project()

        self.mock_object(ViewBuilder, '_get_volume_type',
                         v2_fakes.fake_volume_type_name_get)
        is_detail = True if 'detail' in method else False
        show_count = strutils.bool_from_string(display_param, strict=True)
        # Request with 'with_count' and 'limit'
        req = fakes.HTTPRequest.blank(
            "/v3/%s?with_count=%s&limit=1" % (method, display_param))
        req.headers = mv.get_mv_header(mv.SUPPORT_COUNT_INFO)
        req.api_version_request = mv.get_api_version(mv.SUPPORT_COUNT_INFO)
        ctxt = context.RequestContext(fake.USER_ID, fake.PROJECT_ID, False)
        req.environ['cinder.context'] = ctxt
        res_dict = self.controller._get_volumes(req, is_detail=is_detail)
        self.assertEqual(1, len(res_dict['volumes']))
        if show_count:
            self.assertEqual(2, res_dict['count'])
        else:
            self.assertNotIn('count', res_dict)

        # Request with 'with_count'
        req = fakes.HTTPRequest.blank(
            "/v3/%s?with_count=%s" % (method, display_param))
        req.headers = mv.get_mv_header(mv.SUPPORT_COUNT_INFO)
        req.api_version_request = mv.get_api_version(mv.SUPPORT_COUNT_INFO)
        ctxt = context.RequestContext(fake.USER_ID, fake.PROJECT_ID, False)
        req.environ['cinder.context'] = ctxt
        res_dict = self.controller._get_volumes(req, is_detail=is_detail)
        self.assertEqual(2, len(res_dict['volumes']))
        if show_count:
            self.assertEqual(2, res_dict['count'])
        else:
            self.assertNotIn('count', res_dict)

        # Request with admin context and 'all_tenants'
        req = fakes.HTTPRequest.blank(
            "/v3/%s?with_count=%s&all_tenants=1" % (method, display_param))
        req.headers = mv.get_mv_header(mv.SUPPORT_COUNT_INFO)
        req.api_version_request = mv.get_api_version(mv.SUPPORT_COUNT_INFO)
        ctxt = context.RequestContext(fake.USER_ID, fake.PROJECT_ID, True)
        req.environ['cinder.context'] = ctxt
        res_dict = self.controller._get_volumes(req, is_detail=is_detail)
        self.assertEqual(3, len(res_dict['volumes']))
        if show_count:
            self.assertEqual(3, res_dict['count'])
        else:
            self.assertNotIn('count', res_dict)
Пример #4
0
 def test_update_snapshot_invalid_progress(self, body, exception_class):
     req = webob.Request.blank('/v3/%s/snapshots/%s/action' % (
         fake.PROJECT_ID, fake.SNAPSHOT_ID))
     req.api_version_request = mv.get_api_version(mv.BASE_VERSION)
     self.assertRaises(exception_class,
                       self.controller._update_snapshot_status,
                       req, body=body)
Пример #5
0
    def test_snapshot_show(self, max_ver, snapshot_get_by_id, volume_get_by_id,
                           snapshot_metadata_get):
        snapshot = {
            'id': UUID,
            'volume_id': fake.VOLUME_ID,
            'status': fields.SnapshotStatus.AVAILABLE,
            'volume_size': 100,
            'display_name': 'Default name',
            'display_description': 'Default description',
            'expected_attrs': ['metadata'],
            'group_snapshot_id': None,
        }
        ctx = context.RequestContext(fake.PROJECT_ID, fake.USER_ID, True)
        snapshot_obj = fake_snapshot.fake_snapshot_obj(ctx, **snapshot)
        fake_volume_obj = fake_volume.fake_volume_obj(ctx)
        snapshot_get_by_id.return_value = snapshot_obj
        volume_get_by_id.return_value = fake_volume_obj
        req = fakes.HTTPRequest.blank('/v3/snapshots/%s' % UUID)
        req.api_version_request = mv.get_api_version(max_ver)
        resp_dict = self.controller.show(req, UUID)

        self.assertIn('snapshot', resp_dict)
        self.assertEqual(UUID, resp_dict['snapshot']['id'])
        self.assertIn('updated_at', resp_dict['snapshot'])
        if max_ver == mv.SNAPSHOT_LIST_USER_ID:
            self.assertIn('user_id', resp_dict['snapshot'])
        elif max_ver == mv.GROUP_SNAPSHOTS:
            self.assertIn('group_snapshot_id', resp_dict['snapshot'])
            self.assertNotIn('user_id', resp_dict['snapshot'])
        else:
            self.assertNotIn('group_snapshot_id', resp_dict['snapshot'])
            self.assertNotIn('user_id', resp_dict['snapshot'])
Пример #6
0
    def test_update_consistencygroups_no_empty_parameters(self):
        consistencygroup = self._create_consistencygroup(
            ctxt=self.ctxt,
            status=fields.ConsistencyGroupStatus.AVAILABLE)
        req = fakes.HTTPRequest.blank('/v3/%s/consistencygroups/%s/update' %
                                      (fake.PROJECT_ID, consistencygroup.id))
        req.environ['cinder.context'].is_admin = True

        non_supported_version = mv.get_prior_version(
            mv.CG_UPDATE_BLANK_PROPERTIES)
        req.headers = mv.get_mv_header(non_supported_version)
        req.headers['Content-Type'] = 'application/json'

        req.api_version_request = mv.get_api_version(non_supported_version)
        body = {"consistencygroup": {"name": "my_fake_cg",
                                     "description": "fake consistency group",
                                     "add_volumes": "volume-uuid-1",
                                     "remove_volumes":
                                     "volume-uuid-2, volume uuid-3", }}
        allow_empty = self.controller._check_update_parameters_v3(
            req, body['consistencygroup']['name'],
            body['consistencygroup']['description'],
            body['consistencygroup']['add_volumes'],
            body['consistencygroup']['remove_volumes'])
        self.assertEqual(False, allow_empty)
        consistencygroup.destroy()
Пример #7
0
 def test_update_consistencygroup_empty_parameters(self):
     consistencygroup = self._create_consistencygroup(
         ctxt=self.ctxt, status=fields.ConsistencyGroupStatus.AVAILABLE)
     req = fakes.HTTPRequest.blank('/v3/%s/consistencygroups/%s/update' %
                                   (fake.PROJECT_ID, consistencygroup.id))
     req.environ['cinder.context'].is_admin = True
     req.headers = mv.get_mv_header(mv.CG_UPDATE_BLANK_PROPERTIES)
     req.headers['Content-Type'] = 'application/json'
     req.api_version_request = mv.get_api_version(
         mv.CG_UPDATE_BLANK_PROPERTIES)
     body = {
         "consistencygroup": {
             "name": "",
             "description": "",
             "add_volumes": None,
             "remove_volumes": None,
         }
     }
     res_dict = self.controller.update(req, consistencygroup.id, body)
     consistencygroup = objects.Group.get_by_id(self.ctxt,
                                                consistencygroup.id)
     self.assertEqual(http_client.ACCEPTED, res_dict.status_int)
     self.assertEqual("", consistencygroup.name)
     self.assertEqual("", consistencygroup.description)
     consistencygroup.destroy()
Пример #8
0
    def test_volume_revert_update_status_failed(self, mock_volume, mock_update,
                                                mock_latest):
        fake_volume = self._fake_create_volume()
        fake_snapshot = self._fake_create_snapshot(fake_volume['id'])
        mock_volume.return_value = fake_volume
        mock_latest.return_value = fake_snapshot
        req = fakes.HTTPRequest.blank('/v3/volumes/%s/revert' %
                                      fake_volume['id'])
        req.headers = mv.get_mv_header(mv.VOLUME_REVERT)
        req.api_version_request = mv.get_api_version(mv.VOLUME_REVERT)
        # update volume's status failed
        mock_update.side_effect = [False, True]

        self.assertRaises(webob.exc.HTTPConflict, self.controller.revert, req,
                          fake_volume['id'],
                          {'revert': {
                              'snapshot_id': fake_snapshot['id']
                          }})

        # update snapshot's status failed
        mock_update.side_effect = [True, False]

        self.assertRaises(webob.exc.HTTPConflict, self.controller.revert, req,
                          fake_volume['id'],
                          {'revert': {
                              'snapshot_id': fake_snapshot['id']
                          }})
Пример #9
0
    def test_snapshot_show(self, max_ver, snapshot_get_by_id, volume_get_by_id,
                           snapshot_metadata_get):
        snapshot = {
            'id': UUID,
            'volume_id': fake.VOLUME_ID,
            'status': fields.SnapshotStatus.AVAILABLE,
            'volume_size': 100,
            'display_name': 'Default name',
            'display_description': 'Default description',
            'expected_attrs': ['metadata'],
            'group_snapshot_id': None,
        }
        ctx = context.RequestContext(fake.PROJECT_ID, fake.USER_ID, True)
        snapshot_obj = fake_snapshot.fake_snapshot_obj(ctx, **snapshot)
        fake_volume_obj = fake_volume.fake_volume_obj(ctx)
        snapshot_get_by_id.return_value = snapshot_obj
        volume_get_by_id.return_value = fake_volume_obj
        req = fakes.HTTPRequest.blank('/v3/snapshots/%s' % UUID)
        req.api_version_request = mv.get_api_version(max_ver)
        resp_dict = self.controller.show(req, UUID)

        self.assertIn('snapshot', resp_dict)
        self.assertEqual(UUID, resp_dict['snapshot']['id'])
        self.assertIn('updated_at', resp_dict['snapshot'])
        if max_ver == mv.SNAPSHOT_LIST_USER_ID:
            self.assertIn('user_id', resp_dict['snapshot'])
        elif max_ver == mv.GROUP_SNAPSHOTS:
            self.assertIn('group_snapshot_id', resp_dict['snapshot'])
            self.assertNotIn('user_id', resp_dict['snapshot'])
        else:
            self.assertNotIn('group_snapshot_id', resp_dict['snapshot'])
            self.assertNotIn('user_id', resp_dict['snapshot'])
Пример #10
0
    def test_get_all_messages_with_sort(self):
        self.create_message_for_tests()

        url = '/v3/messages?sort=event_id:asc'
        req = fakes.HTTPRequest.blank(url)
        req.method = 'GET'
        req.content_type = 'application/json'
        req.headers = mv.get_mv_header(mv.MESSAGES_PAGINATION)
        req.api_version_request = mv.get_api_version(mv.MESSAGES_PAGINATION)
        req.environ['cinder.context'].is_admin = True

        res = self.controller.index(req)

        expect_result = [
            "VOLUME_VOLUME_001_002",
            "VOLUME_VOLUME_002_002",
            "VOLUME_VOLUME_003_002",
            "VOLUME_VOLUME_003_002",
        ]
        expect_result.sort()

        self.assertEqual(4, len(res['messages']))
        self.assertEqual(expect_result[0], res['messages'][0]['event_id'])
        self.assertEqual(expect_result[1], res['messages'][1]['event_id'])
        self.assertEqual(expect_result[2], res['messages'][2]['event_id'])
        self.assertEqual(expect_result[3], res['messages'][3]['event_id'])
Пример #11
0
    def test_volume_creation_from_snapshot(self, max_ver, create, get_snapshot,
                                           volume_type_get, group_get):
        create.side_effect = v2_fakes.fake_volume_api_create
        get_snapshot.side_effect = v2_fakes.fake_snapshot_get
        volume_type_get.side_effect = v2_fakes.fake_volume_type_get
        fake_group = {
            'id': fake.GROUP_ID,
            'group_type_id': fake.GROUP_TYPE_ID,
            'name': 'fake_group'
        }
        group_get.return_value = fake_group

        snapshot_id = fake.SNAPSHOT_ID
        vol = self._vol_in_request_body(snapshot_id=snapshot_id,
                                        group_id=fake.GROUP_ID)
        body = {"volume": vol}
        req = fakes.HTTPRequest.blank('/v3/volumes')
        req.api_version_request = mv.get_api_version(max_ver)
        res_dict = self.controller.create(req, body)
        ex = self._expected_vol_from_controller(
            snapshot_id=snapshot_id, req_version=req.api_version_request)
        self.assertEqual(ex, res_dict)

        context = req.environ['cinder.context']
        get_snapshot.assert_called_once_with(self.controller.volume_api,
                                             context, snapshot_id)

        kwargs = self._expected_volume_api_create_kwargs(
            v2_fakes.fake_snapshot(snapshot_id),
            test_group=fake_group,
            req_version=req.api_version_request)
        create.assert_called_once_with(self.controller.volume_api, context,
                                       vol['size'], v2_fakes.DEFAULT_VOL_NAME,
                                       v2_fakes.DEFAULT_VOL_DESCRIPTION,
                                       **kwargs)
Пример #12
0
    def test_volume_create_with_snapshot_image(self, mock_validate, create,
                                               get_snapshot, volume_type_get):
        create.side_effect = v2_fakes.fake_volume_api_create
        get_snapshot.side_effect = v2_fakes.fake_snapshot_get
        volume_type_get.side_effect = v2_fakes.fake_volume_type_get

        vol = self._vol_in_request_body(
            image_id="b0a599e0-41d7-3582-b260-769f443c862a")

        snapshot_id = fake.SNAPSHOT_ID
        ex = self._expected_vol_from_controller(snapshot_id=snapshot_id)
        body = {"volume": vol}
        req = fakes.HTTPRequest.blank('/v3/volumes')
        req.headers = mv.get_mv_header(mv.SUPPORT_NOVA_IMAGE)
        req.api_version_request = mv.get_api_version(mv.SUPPORT_NOVA_IMAGE)
        res_dict = self.controller.create(req, body=body)
        self.assertEqual(ex, res_dict)
        context = req.environ['cinder.context']
        get_snapshot.assert_called_once_with(self.controller.volume_api,
                                             context, snapshot_id)
        kwargs = self._expected_volume_api_create_kwargs(
            v2_fakes.fake_snapshot(snapshot_id))
        create.assert_called_once_with(
            self.controller.volume_api, context,
            vol['size'], v2_fakes.DEFAULT_VOL_NAME,
            v2_fakes.DEFAULT_VOL_DESCRIPTION, **kwargs)
Пример #13
0
    def test_volume_creation_from_backup(self, max_ver, create, get_backup,
                                         volume_type_get):
        create.side_effect = v2_fakes.fake_volume_api_create
        get_backup.side_effect = v2_fakes.fake_backup_get
        volume_type_get.side_effect = v2_fakes.fake_volume_type_get

        backup_id = fake.BACKUP_ID
        req = fakes.HTTPRequest.blank('/v3/volumes')
        req.api_version_request = mv.get_api_version(max_ver)
        if max_ver == mv.VOLUME_CREATE_FROM_BACKUP:
            vol = self._vol_in_request_body(backup_id=backup_id)
        else:
            vol = self._vol_in_request_body()
        body = {"volume": vol}
        res_dict = self.controller.create(req, body=body)
        ex = self._expected_vol_from_controller(
            req_version=req.api_version_request)
        self.assertEqual(ex, res_dict)

        context = req.environ['cinder.context']
        kwargs = self._expected_volume_api_create_kwargs(
            req_version=req.api_version_request)
        if max_ver >= mv.VOLUME_CREATE_FROM_BACKUP:
            get_backup.assert_called_once_with(self.controller.backup_api,
                                               context, backup_id)
            kwargs.update({'backup': v2_fakes.fake_backup_get(None, context,
                                                              backup_id)})
        create.assert_called_once_with(self.controller.volume_api, context,
                                       vol['size'],
                                       v2_fakes.DEFAULT_VOL_NAME,
                                       v2_fakes.DEFAULT_VOL_DESCRIPTION,
                                       **kwargs)
Пример #14
0
    def test_update_consistencygroup_all_empty_parameters_not_version_ok(self):
        consistencygroup = self._create_consistencygroup(
            ctxt=self.ctxt, status=fields.ConsistencyGroupStatus.AVAILABLE)
        req = fakes.HTTPRequest.blank('/v3/%s/consistencygroups/%s/update' %
                                      (fake.PROJECT_ID, consistencygroup.id))
        req.environ['cinder.context'].is_admin = True

        non_supported_version = mv.get_prior_version(
            mv.CG_UPDATE_BLANK_PROPERTIES)
        req.headers = mv.get_mv_header(non_supported_version)
        req.api_version_request = mv.get_api_version(non_supported_version)
        req.headers['Content-Type'] = 'application/json'

        body = {
            "consistencygroup": {
                "name": None,
                "description": None,
                "add_volumes": None,
                "remove_volumes": None,
            }
        }
        self.assertRaisesRegex(
            webob.exc.HTTPBadRequest, "Name, description, "
            "add_volumes, and remove_volumes can not be "
            "all empty in the request body.", self.controller.update, req,
            consistencygroup.id, body)
        consistencygroup.destroy()
Пример #15
0
    def test_volume_revert_update_status_failed(self,
                                                mock_volume,
                                                mock_update,
                                                mock_latest):
        fake_volume = self._fake_create_volume()
        fake_snapshot = self._fake_create_snapshot(fake_volume['id'])
        mock_volume.return_value = fake_volume
        mock_latest.return_value = fake_snapshot
        req = fakes.HTTPRequest.blank('/v3/volumes/%s/revert'
                                      % fake_volume['id'])
        req.headers = mv.get_mv_header(mv.VOLUME_REVERT)
        req.api_version_request = mv.get_api_version(
            mv.VOLUME_REVERT)
        # update volume's status failed
        mock_update.side_effect = [False, True]

        self.assertRaises(webob.exc.HTTPConflict, self.controller.revert,
                          req, fake_volume['id'], {'revert': {'snapshot_id':
                                                   fake_snapshot['id']}})

        # update snapshot's status failed
        mock_update.side_effect = [True, False]

        self.assertRaises(webob.exc.HTTPConflict, self.controller.revert,
                          req, fake_volume['id'], {'revert': {'snapshot_id':
                                                   fake_snapshot['id']}})
Пример #16
0
    def _volume_upload_image(self, req, id, body):
        """Uploads the specified volume to image service."""
        context = req.environ['cinder.context']
        params = body['os-volume_upload_image']
        req_version = req.api_version_request

        force = params.get('force', 'False')
        force = strutils.bool_from_string(force, strict=True)

        # Not found exception will be handled at the wsgi level
        volume = self.volume_api.get(context, id)

        context.authorize(policy.UPLOAD_IMAGE_POLICY)
        # check for valid disk-format
        disk_format = params.get("disk_format", "raw")

        image_metadata = {"container_format": params.get(
            "container_format", "bare"),
            "disk_format": disk_format,
            "name": params["image_name"]}

        if volume.encryption_key_id:
            # Clone volume encryption key: the current key cannot
            # be reused because it will be deleted when the volume is
            # deleted.
            # TODO(eharney): Currently, there is no mechanism to remove
            # these keys, because Glance will not delete the key from
            # Barbican when the image is deleted.
            encryption_key_id = self._key_manager.store(
                context,
                self._key_manager.get(context, volume.encryption_key_id))

            image_metadata['cinder_encryption_key_id'] = encryption_key_id

        if req_version >= mv.get_api_version(
                mv.UPLOAD_IMAGE_PARAMS):

            image_metadata['visibility'] = params.get('visibility', 'private')
            image_metadata['protected'] = strutils.bool_from_string(
                params.get('protected', 'False'), strict=True)

            if image_metadata['visibility'] == 'public':
                context.authorize(policy.UPLOAD_PUBLIC_POLICY)

        try:
            response = self.volume_api.copy_volume_to_image(context,
                                                            volume,
                                                            image_metadata,
                                                            force)
        except exception.InvalidVolume as error:
            raise webob.exc.HTTPBadRequest(explanation=error.msg)
        except ValueError as error:
            raise webob.exc.HTTPBadRequest(explanation=six.text_type(error))
        except messaging.RemoteError as error:
            msg = "%(err_type)s: %(err_msg)s" % {'err_type': error.exc_type,
                                                 'err_msg': error.value}
            raise webob.exc.HTTPBadRequest(explanation=msg)
        except Exception as error:
            raise webob.exc.HTTPBadRequest(explanation=six.text_type(error))
        return {'os-volume_upload_image': response}
Пример #17
0
    def _volume_upload_image(self, req, id, body):
        """Uploads the specified volume to image service."""
        context = req.environ['cinder.context']
        params = body['os-volume_upload_image']
        req_version = req.api_version_request

        force = params.get('force', 'False')
        force = strutils.bool_from_string(force, strict=True)

        # Not found exception will be handled at the wsgi level
        volume = self.volume_api.get(context, id)

        context.authorize(policy.UPLOAD_IMAGE_POLICY)
        # check for valid disk-format
        disk_format = params.get("disk_format", "raw")

        image_metadata = {
            "container_format": params.get("container_format", "bare"),
            "disk_format": disk_format,
            "name": params["image_name"]
        }

        if volume.encryption_key_id:
            # Clone volume encryption key: the current key cannot
            # be reused because it will be deleted when the volume is
            # deleted.
            # TODO(eharney): Currently, there is no mechanism to remove
            # these keys, because Glance will not delete the key from
            # Barbican when the image is deleted.
            encryption_key_id = self._key_manager.store(
                context,
                self._key_manager.get(context, volume.encryption_key_id))

            image_metadata['cinder_encryption_key_id'] = encryption_key_id

        if req_version >= mv.get_api_version(mv.UPLOAD_IMAGE_PARAMS):

            image_metadata['visibility'] = params.get('visibility', 'private')
            image_metadata['protected'] = strutils.bool_from_string(
                params.get('protected', 'False'), strict=True)

            if image_metadata['visibility'] == 'public':
                context.authorize(policy.UPLOAD_PUBLIC_POLICY)

        try:
            response = self.volume_api.copy_volume_to_image(
                context, volume, image_metadata, force)
        except exception.InvalidVolume as error:
            raise webob.exc.HTTPBadRequest(explanation=error.msg)
        except ValueError as error:
            raise webob.exc.HTTPBadRequest(explanation=six.text_type(error))
        except messaging.RemoteError as error:
            msg = "%(err_type)s: %(err_msg)s" % {
                'err_type': error.exc_type,
                'err_msg': error.value
            }
            raise webob.exc.HTTPBadRequest(explanation=msg)
        except Exception as error:
            raise webob.exc.HTTPBadRequest(explanation=six.text_type(error))
        return {'os-volume_upload_image': response}
Пример #18
0
    def test_get_all_messages_with_sort(self):
        self.create_message_for_tests()

        url = '/v3/messages?sort=event_id:asc'
        req = fakes.HTTPRequest.blank(url)
        req.method = 'GET'
        req.content_type = 'application/json'
        req.headers = mv.get_mv_header(mv.MESSAGES_PAGINATION)
        req.api_version_request = mv.get_api_version(mv.MESSAGES_PAGINATION)
        req.environ['cinder.context'].is_admin = True

        res = self.controller.index(req)

        expect_result = [
            "VOLUME_VOLUME_001_002",
            "VOLUME_VOLUME_002_002",
            "VOLUME_VOLUME_003_002",
            "VOLUME_VOLUME_003_002",
        ]
        expect_result.sort()

        self.assertEqual(4, len(res['messages']))
        self.assertEqual(expect_result[0],
                         res['messages'][0]['event_id'])
        self.assertEqual(expect_result[1],
                         res['messages'][1]['event_id'])
        self.assertEqual(expect_result[2],
                         res['messages'][2]['event_id'])
        self.assertEqual(expect_result[3],
                         res['messages'][3]['event_id'])
Пример #19
0
 def test_update_snapshot_invalid_progress(self, body, exception_class):
     req = webob.Request.blank('/v3/%s/snapshots/%s/action' % (
         fake.PROJECT_ID, fake.SNAPSHOT_ID))
     req.api_version_request = mv.get_api_version(mv.BASE_VERSION)
     self.assertRaises(exception_class,
                       self.controller._update_snapshot_status,
                       req, body=body)
Пример #20
0
    def test_volume_creation_from_backup(self, max_ver, create, get_backup,
                                         volume_type_get):
        create.side_effect = v2_fakes.fake_volume_api_create
        get_backup.side_effect = v2_fakes.fake_backup_get
        volume_type_get.side_effect = v2_fakes.fake_volume_type_get

        backup_id = fake.BACKUP_ID
        req = fakes.HTTPRequest.blank('/v3/volumes')
        req.api_version_request = mv.get_api_version(max_ver)
        if max_ver == mv.VOLUME_CREATE_FROM_BACKUP:
            vol = self._vol_in_request_body(backup_id=backup_id)
        else:
            vol = self._vol_in_request_body()
        body = {"volume": vol}
        res_dict = self.controller.create(req, body=body)
        ex = self._expected_vol_from_controller(
            req_version=req.api_version_request)
        self.assertEqual(ex, res_dict)

        context = req.environ['cinder.context']
        kwargs = self._expected_volume_api_create_kwargs(
            req_version=req.api_version_request)
        if max_ver >= mv.VOLUME_CREATE_FROM_BACKUP:
            get_backup.assert_called_once_with(self.controller.backup_api,
                                               context, backup_id)
            kwargs.update({'backup': v2_fakes.fake_backup_get(None, context,
                                                              backup_id)})
        create.assert_called_once_with(self.controller.volume_api, context,
                                       vol['size'],
                                       v2_fakes.DEFAULT_VOL_NAME,
                                       v2_fakes.DEFAULT_VOL_DESCRIPTION,
                                       **kwargs)
Пример #21
0
    def test_volume_create_with_snapshot_image(self, mock_validate, create,
                                               get_snapshot, volume_type_get):
        create.side_effect = v2_fakes.fake_volume_api_create
        get_snapshot.side_effect = v2_fakes.fake_snapshot_get
        volume_type_get.side_effect = v2_fakes.fake_volume_type_get

        self.ext_mgr.extensions = {'os-image-create': 'fake'}
        vol = self._vol_in_request_body(
            image_id="b0a599e0-41d7-3582-b260-769f443c862a")

        snapshot_id = fake.SNAPSHOT_ID
        ex = self._expected_vol_from_controller(snapshot_id=snapshot_id)
        body = {"volume": vol}
        req = fakes.HTTPRequest.blank('/v3/volumes')
        req.headers = mv.get_mv_header(mv.SUPPORT_NOVA_IMAGE)
        req.api_version_request = mv.get_api_version(mv.SUPPORT_NOVA_IMAGE)
        res_dict = self.controller.create(req, body=body)
        self.assertEqual(ex, res_dict)
        context = req.environ['cinder.context']
        get_snapshot.assert_called_once_with(self.controller.volume_api,
                                             context, snapshot_id)
        kwargs = self._expected_volume_api_create_kwargs(
            v2_fakes.fake_snapshot(snapshot_id))
        create.assert_called_once_with(
            self.controller.volume_api, context,
            vol['size'], v2_fakes.DEFAULT_VOL_NAME,
            v2_fakes.DEFAULT_VOL_DESCRIPTION, **kwargs)
Пример #22
0
 def test_volume_update_without_vol_data(self):
     body = {"volume": {}}
     req = fakes.HTTPRequest.blank('/v3/volumes/%s' % fake.VOLUME_ID)
     req.api_version_request = mv.get_api_version(
         mv.SUPPORT_VOLUME_SCHEMA_CHANGES)
     self.assertRaises(exception.ValidationError, self.controller.update,
                       req, fake.VOLUME_ID, body=body)
Пример #23
0
    def test_volume_create_extra_params(self):
        self.mock_object(volume_api.API, 'get', v2_fakes.fake_volume_get)
        self.mock_object(volume_api.API, "create",
                         v2_fakes.fake_volume_api_create)
        self.mock_object(db.sqlalchemy.api, '_volume_type_get_full',
                         v2_fakes.fake_volume_type_get)

        req = fakes.HTTPRequest.blank('/v3/volumes')
        req.api_version_request = mv.get_api_version(
            mv.SUPPORT_VOLUME_SCHEMA_CHANGES)

        body = {
            'volume': {
                'name': 'test name',
                'description': 'test desc',
                'size': 1,
                'user_id': 'teapot',
                'project_id': 'kettle',
                'status': 'confused'
            }
        }
        self.assertRaises(exception.ValidationError,
                          self.controller.create,
                          req,
                          body=body)
Пример #24
0
    def test_check_volume_filters_strict_called(self):
        # Clear the filters collection to make sure the filters collection
        # cache can be reloaded using tmp filter file.
        common._FILTERS_COLLECTION = None
        with mock.patch.object(vol_get.API,
                               'check_volume_filters') as volume_get:
            req = fakes.HTTPRequest.blank('/v3/volumes?bootable=True')
            req.method = 'GET'
            req.content_type = 'application/json'
            req.headers = mv.get_mv_header(mv.VOLUME_LIST_BOOTABLE)
            req.environ['cinder.context'].is_admin = True
            req.api_version_request = mv.get_api_version(
                mv.VOLUME_LIST_BOOTABLE)

            tmp_filter_file = self.tmp_path + '/resource_filters_tests.json'
            self.override_config('resource_query_filters_file',
                                 tmp_filter_file)
            with open(tmp_filter_file, 'w') as f:
                f.write(json.dumps({"volume": ['bootable']}))
            self.controller.index(req)
            filters = req.params.copy()

            volume_get.assert_called_with(filters, True)
        # Reset the CONF.resource_query_filters_file and clear the filters
        # collection to avoid leaking other cases, and it will be re-loaded
        # from CONF.resource_query_filters_file in next call.
        self._reset_filter_file()
Пример #25
0
    def test_update_consistencygroups_no_empty_parameters(self):
        consistencygroup = self._create_consistencygroup(
            ctxt=self.ctxt, status=fields.ConsistencyGroupStatus.AVAILABLE)
        req = fakes.HTTPRequest.blank('/v3/%s/consistencygroups/%s/update' %
                                      (fake.PROJECT_ID, consistencygroup.id))
        req.environ['cinder.context'].is_admin = True

        non_supported_version = mv.get_prior_version(
            mv.CG_UPDATE_BLANK_PROPERTIES)
        req.headers = mv.get_mv_header(non_supported_version)
        req.headers['Content-Type'] = 'application/json'

        req.api_version_request = mv.get_api_version(non_supported_version)
        body = {
            "consistencygroup": {
                "name": "my_fake_cg",
                "description": "fake consistency group",
                "add_volumes": "volume-uuid-1",
                "remove_volumes": "volume-uuid-2, volume uuid-3",
            }
        }
        allow_empty = self.controller._check_update_parameters_v3(
            req, body['consistencygroup']['name'],
            body['consistencygroup']['description'],
            body['consistencygroup']['add_volumes'],
            body['consistencygroup']['remove_volumes'])
        self.assertEqual(False, allow_empty)
        consistencygroup.destroy()
Пример #26
0
    def test_check_volume_filters_strict_called(self):
        # Clear the filters collection to make sure the filters collection
        # cache can be reloaded using tmp filter file.
        common._FILTERS_COLLECTION = None
        with mock.patch.object(vol_get.API,
                               'check_volume_filters') as volume_get:
            req = fakes.HTTPRequest.blank('/v3/volumes?bootable=True')
            req.method = 'GET'
            req.content_type = 'application/json'
            req.headers = mv.get_mv_header(mv.VOLUME_LIST_BOOTABLE)
            req.environ['cinder.context'].is_admin = True
            req.api_version_request = mv.get_api_version(
                mv.VOLUME_LIST_BOOTABLE)

            tmp_filter_file = self.tmp_path + '/resource_filters_tests.json'
            self.override_config('resource_query_filters_file',
                                 tmp_filter_file)
            with open(tmp_filter_file, 'w') as f:
                f.write(json.dumps({"volume": ['bootable']}))
            self.controller.index(req)
            filters = req.params.copy()

            volume_get.assert_called_with(filters, True)
        # Reset the CONF.resource_query_filters_file and clear the filters
        # collection to avoid leaking other cases, and it will be re-loaded
        # from CONF.resource_query_filters_file in next call.
        self._reset_filter_file()
Пример #27
0
 def test_update_consistencygroup_all_empty_parameters_version_36(self):
     consistencygroup = self._create_consistencygroup(
         ctxt=self.ctxt, status=fields.ConsistencyGroupStatus.AVAILABLE)
     req = fakes.HTTPRequest.blank('/v3/%s/consistencygroups/%s/update' %
                                   (fake.PROJECT_ID, consistencygroup.id))
     req.environ['cinder.context'].is_admin = True
     req.headers = mv.get_mv_header(mv.CG_UPDATE_BLANK_PROPERTIES)
     req.headers['Content-Type'] = 'application/json'
     req.api_version_request = mv.get_api_version(
         mv.CG_UPDATE_BLANK_PROPERTIES)
     body = {
         "consistencygroup": {
             "name": None,
             "description": None,
             "add_volumes": None,
             "remove_volumes": None,
         }
     }
     self.assertRaisesRegex(
         webob.exc.HTTPBadRequest, "Must specify "
         "one or more of the following keys to "
         "update: name, description, add_volumes, "
         "remove_volumes.", self.controller.update, req,
         consistencygroup.id, body)
     consistencygroup.destroy()
Пример #28
0
 def test_volume_update_without_vol_data(self):
     body = {"volume": {}}
     req = fakes.HTTPRequest.blank('/v3/volumes/%s' % fake.VOLUME_ID)
     req.api_version_request = mv.get_api_version(
         mv.SUPPORT_VOLUME_SCHEMA_CHANGES)
     self.assertRaises(exception.ValidationError, self.controller.update,
                       req, fake.VOLUME_ID, body=body)
Пример #29
0
    def test_list_volume_with_count_param(self, method, display_param):
        self._create_multiple_volumes_with_different_project()

        is_detail = True if 'detail' in method else False
        show_count = strutils.bool_from_string(display_param, strict=True)
        # Request with 'with_count' and 'limit'
        req = fakes.HTTPRequest.blank(
            "/v3/%s?with_count=%s&limit=1" % (method, display_param))
        req.headers = mv.get_mv_header(mv.SUPPORT_COUNT_INFO)
        req.api_version_request = mv.get_api_version(mv.SUPPORT_COUNT_INFO)
        ctxt = context.RequestContext(fake.USER_ID, fake.PROJECT_ID, False)
        req.environ['cinder.context'] = ctxt
        res_dict = self.controller._get_volumes(req, is_detail=is_detail)
        self.assertEqual(1, len(res_dict['volumes']))
        if show_count:
            self.assertEqual(2, res_dict['count'])
        else:
            self.assertNotIn('count', res_dict)

        # Request with 'with_count'
        req = fakes.HTTPRequest.blank(
            "/v3/%s?with_count=%s" % (method, display_param))
        req.headers = mv.get_mv_header(mv.SUPPORT_COUNT_INFO)
        req.api_version_request = mv.get_api_version(mv.SUPPORT_COUNT_INFO)
        ctxt = context.RequestContext(fake.USER_ID, fake.PROJECT_ID, False)
        req.environ['cinder.context'] = ctxt
        res_dict = self.controller._get_volumes(req, is_detail=is_detail)
        self.assertEqual(2, len(res_dict['volumes']))
        if show_count:
            self.assertEqual(2, res_dict['count'])
        else:
            self.assertNotIn('count', res_dict)

        # Request with admin context and 'all_tenants'
        req = fakes.HTTPRequest.blank(
            "/v3/%s?with_count=%s&all_tenants=1" % (method, display_param))
        req.headers = mv.get_mv_header(mv.SUPPORT_COUNT_INFO)
        req.api_version_request = mv.get_api_version(mv.SUPPORT_COUNT_INFO)
        ctxt = context.RequestContext(fake.USER_ID, fake.PROJECT_ID, True)
        req.environ['cinder.context'] = ctxt
        res_dict = self.controller._get_volumes(req, is_detail=is_detail)
        self.assertEqual(3, len(res_dict['volumes']))
        if show_count:
            self.assertEqual(3, res_dict['count'])
        else:
            self.assertNotIn('count', res_dict)
Пример #30
0
 def test_volume_creation_fails_with_additional_properties(self):
     body = {"volume": {"size": 1, "user_id": fake.USER_ID,
                        "project_id": fake.PROJECT_ID}}
     req = fakes.HTTPRequest.blank('/v3/volumes')
     req.api_version_request = mv.get_api_version(
         mv.SUPPORT_VOLUME_SCHEMA_CHANGES)
     self.assertRaises(exception.ValidationError, self.controller.create,
                       req, body=body)
Пример #31
0
 def test_volume_creation_fails_with_additional_properties(self):
     body = {"volume": {"size": 1, "user_id": fake.USER_ID,
                        "project_id": fake.PROJECT_ID}}
     req = fakes.HTTPRequest.blank('/v3/volumes')
     req.api_version_request = mv.get_api_version(
         mv.SUPPORT_VOLUME_SCHEMA_CHANGES)
     self.assertRaises(exception.ValidationError, self.controller.create,
                       req, body=body)
Пример #32
0
 def _get_volume_types(extra_specs,
                       use_admin_context=True,
                       microversion=mv.SUPPORT_VOLUME_TYPE_FILTER):
     req = fakes.HTTPRequest.blank('/v3/%s/types?extra_specs=%s' %
                                   (fake.PROJECT_ID, extra_specs),
                                   use_admin_context=use_admin_context)
     req.api_version_request = mv.get_api_version(microversion)
     res_dict = self.controller.index(req)
     return res_dict['volume_types']
Пример #33
0
def create_snapshot_query_with_metadata(metadata_query_string,
                                        api_microversion):
    """Helper to create metadata querystring with microversion"""
    req = fakes.HTTPRequest.blank('/v3/snapshots?metadata=' +
                                  metadata_query_string)
    req.headers = mv.get_mv_header(api_microversion)
    req.api_version_request = mv.get_api_version(api_microversion)

    return req
Пример #34
0
def create_snapshot_query_with_metadata(metadata_query_string,
                                        api_microversion):
    """Helper to create metadata querystring with microversion"""
    req = fakes.HTTPRequest.blank('/v3/snapshots?metadata=' +
                                  metadata_query_string)
    req.headers = mv.get_mv_header(api_microversion)
    req.api_version_request = mv.get_api_version(api_microversion)

    return req
Пример #35
0
 def test_volume_index_filter_by_glance_metadata_in_unsupport_version(self):
     self._create_volume_with_glance_metadata()
     req = fakes.HTTPRequest.blank("/v3/volumes?glance_metadata="
                                   "{'image_name': 'imageTestOne'}")
     req.headers = mv.get_mv_header(mv.BASE_VERSION)
     req.api_version_request = mv.get_api_version(mv.BASE_VERSION)
     req.environ['cinder.context'] = self.ctxt
     res_dict = self.controller.index(req)
     volumes = res_dict['volumes']
     self.assertEqual(2, len(volumes))
Пример #36
0
 def test_volume_index_filter_by_group_id_in_unsupport_version(self):
     self._create_volume_with_group()
     req = fakes.HTTPRequest.blank(("/v3/volumes?group_id=%s") %
                                   fake.GROUP_ID)
     req.headers = mv.get_mv_header(mv.BACKUP_UPDATE)
     req.api_version_request = mv.get_api_version(mv.BACKUP_UPDATE)
     req.environ['cinder.context'] = self.ctxt
     res_dict = self.controller.index(req)
     volumes = res_dict['volumes']
     self.assertEqual(2, len(volumes))
Пример #37
0
 def test_volume_index_filter_by_group_id_in_unsupport_version(self):
     self._create_volume_with_group()
     req = fakes.HTTPRequest.blank(
         ("/v3/volumes?group_id=%s") % fake.GROUP_ID)
     req.headers = mv.get_mv_header(mv.BACKUP_UPDATE)
     req.api_version_request = mv.get_api_version(mv.BACKUP_UPDATE)
     req.environ['cinder.context'] = self.ctxt
     res_dict = self.controller.index(req)
     volumes = res_dict['volumes']
     self.assertEqual(2, len(volumes))
Пример #38
0
 def test_volume_index_filter_by_glance_metadata_in_unsupport_version(self):
     self._create_volume_with_glance_metadata()
     req = fakes.HTTPRequest.blank("/v3/volumes?glance_metadata="
                                   "{'image_name': 'imageTestOne'}")
     req.headers = mv.get_mv_header(mv.BASE_VERSION)
     req.api_version_request = mv.get_api_version(mv.BASE_VERSION)
     req.environ['cinder.context'] = self.ctxt
     res_dict = self.controller.index(req)
     volumes = res_dict['volumes']
     self.assertEqual(2, len(volumes))
Пример #39
0
 def test_volume_filter_by_time_with_invaild_time(self, change):
     self._create_volume_with_glance_metadata()
     change_time = '123'
     req = fakes.HTTPRequest.blank(("/v3/volumes?%s=%s") %
                                   (change, change_time))
     req.environ['cinder.context'] = self.ctxt
     req.headers = mv.get_mv_header(mv.VOLUME_TIME_COMPARISON_FILTER)
     req.api_version_request = mv.get_api_version(
         mv.VOLUME_TIME_COMPARISON_FILTER)
     self.assertRaises(webob.exc.HTTPBadRequest, self.controller.index, req)
Пример #40
0
 def _fake_volumes_summary_request(self,
                                   version=mv.VOLUME_SUMMARY,
                                   all_tenant=False,
                                   is_admin=False):
     req_url = '/v3/volumes/summary'
     if all_tenant:
         req_url += '?all_tenants=True'
     req = fakes.HTTPRequest.blank(req_url, use_admin_context=is_admin)
     req.headers = mv.get_mv_header(version)
     req.api_version_request = mv.get_api_version(version)
     return req
Пример #41
0
 def _fake_volumes_summary_request(self,
                                   version=mv.VOLUME_SUMMARY,
                                   all_tenant=False,
                                   is_admin=False):
     req_url = '/v3/volumes/summary'
     if all_tenant:
         req_url += '?all_tenants=True'
     req = fakes.HTTPRequest.blank(req_url, use_admin_context=is_admin)
     req.headers = mv.get_mv_header(version)
     req.api_version_request = mv.get_api_version(version)
     return req
Пример #42
0
 def test_volume_index_filter_by_group_id(self):
     vols = self._create_volume_with_group()
     req = fakes.HTTPRequest.blank(
         ("/v3/volumes?group_id=%s") % fake.GROUP_ID)
     req.headers = mv.get_mv_header(mv.VOLUME_LIST_GROUP)
     req.api_version_request = mv.get_api_version(mv.VOLUME_LIST_GROUP)
     req.environ['cinder.context'] = self.ctxt
     res_dict = self.controller.index(req)
     volumes = res_dict['volumes']
     self.assertEqual(1, len(volumes))
     self.assertEqual(vols[0].id, volumes[0]['id'])
Пример #43
0
 def _get_resp_create(self, body, version=mv.BASE_VERSION):
     url = '/v3/%s/os-volume-manage' % fake.PROJECT_ID
     req = webob.Request.blank(url, base_url='http://localhost.com' + url)
     req.method = 'POST'
     req.headers = mv.get_mv_header(version)
     req.headers['Content-Type'] = 'application/json'
     req.environ['cinder.context'] = self._admin_ctxt
     req.body = jsonutils.dump_as_bytes(body)
     req.api_version_request = mv.get_api_version(version)
     res = self.controller.create(req, body=body)
     return res
Пример #44
0
 def test_volume_index_filter_by_group_id(self):
     vols = self._create_volume_with_group()
     req = fakes.HTTPRequest.blank(("/v3/volumes?group_id=%s") %
                                   fake.GROUP_ID)
     req.headers = mv.get_mv_header(mv.VOLUME_LIST_GROUP)
     req.api_version_request = mv.get_api_version(mv.VOLUME_LIST_GROUP)
     req.environ['cinder.context'] = self.ctxt
     res_dict = self.controller.index(req)
     volumes = res_dict['volumes']
     self.assertEqual(1, len(volumes))
     self.assertEqual(vols[0].id, volumes[0]['id'])
Пример #45
0
 def _get_resp_create(self, body, version=mv.BASE_VERSION):
     url = '/v3/%s/os-volume-manage' % fake.PROJECT_ID
     req = webob.Request.blank(url, base_url='http://localhost.com' + url)
     req.method = 'POST'
     req.headers = mv.get_mv_header(version)
     req.headers['Content-Type'] = 'application/json'
     req.environ['cinder.context'] = self._admin_ctxt
     req.body = jsonutils.dump_as_bytes(body)
     req.api_version_request = mv.get_api_version(version)
     res = self.controller.create(req, body)
     return res
Пример #46
0
 def test_volume_index_filter_by_glance_metadata(self):
     vols = self._create_volume_with_glance_metadata()
     req = fakes.HTTPRequest.blank("/v3/volumes?glance_metadata="
                                   "{'image_name': 'imageTestOne'}")
     req.headers = mv.get_mv_header(mv.VOLUME_LIST_GLANCE_METADATA)
     req.api_version_request = mv.get_api_version(
         mv.VOLUME_LIST_GLANCE_METADATA)
     req.environ['cinder.context'] = self.ctxt
     res_dict = self.controller.index(req)
     volumes = res_dict['volumes']
     self.assertEqual(1, len(volumes))
     self.assertEqual(vols[0].id, volumes[0]['id'])
Пример #47
0
 def test_vol_filter_by_updated_at_with_gt_and_lt(self, change, result):
     vols = self._create_volume_with_glance_metadata()
     change_time = vols[1].updated_at
     req = fakes.HTTPRequest.blank(("/v3/volumes?%s%s") %
                                   (change, change_time))
     req.environ['cinder.context'] = self.ctxt
     req.headers = mv.get_mv_header(mv.VOLUME_TIME_COMPARISON_FILTER)
     req.api_version_request = mv.get_api_version(
         mv.VOLUME_TIME_COMPARISON_FILTER)
     res_dict = self.controller.index(req)
     volumes = res_dict['volumes']
     self.assertEqual(result, len(volumes))
Пример #48
0
 def test_volume_index_filter_by_glance_metadata(self):
     vols = self._create_volume_with_glance_metadata()
     req = fakes.HTTPRequest.blank("/v3/volumes?glance_metadata="
                                   "{'image_name': 'imageTestOne'}")
     req.headers = mv.get_mv_header(mv.VOLUME_LIST_GLANCE_METADATA)
     req.api_version_request = mv.get_api_version(
         mv.VOLUME_LIST_GLANCE_METADATA)
     req.environ['cinder.context'] = self.ctxt
     res_dict = self.controller.index(req)
     volumes = res_dict['volumes']
     self.assertEqual(1, len(volumes))
     self.assertEqual(vols[0].id, volumes[0]['id'])
Пример #49
0
    def test_list_volume_with_count_param_version_not_matched(self, action):
        self._create_multiple_volumes_with_different_project()

        is_detail = True if 'detail' in action else False
        req = fakes.HTTPRequest.blank("/v3/%s?with_count=True" % action)
        req.headers = mv.get_mv_header(
            mv.get_prior_version(mv.SUPPORT_COUNT_INFO))
        req.api_version_request = mv.get_api_version(
            mv.get_prior_version(mv.SUPPORT_COUNT_INFO))
        ctxt = context.RequestContext(fake.USER_ID, fake.PROJECT_ID, True)
        req.environ['cinder.context'] = ctxt
        res_dict = self.controller._get_volumes(req, is_detail=is_detail)
        self.assertNotIn('count', res_dict)
Пример #50
0
    def test_list_volume_with_count_param_version_not_matched(self, action):
        self._create_multiple_volumes_with_different_project()

        is_detail = True if 'detail' in action else False
        req = fakes.HTTPRequest.blank("/v3/%s?with_count=True" % action)
        req.headers = mv.get_mv_header(
            mv.get_prior_version(mv.SUPPORT_COUNT_INFO))
        req.api_version_request = mv.get_api_version(
            mv.get_prior_version(mv.SUPPORT_COUNT_INFO))
        ctxt = context.RequestContext(fake.USER_ID, fake.PROJECT_ID, True)
        req.environ['cinder.context'] = ctxt
        res_dict = self.controller._get_volumes(req, is_detail=is_detail)
        self.assertNotIn('count', res_dict)
Пример #51
0
    def test_get_all_messages_with_limit_and_offset(self):
        self.create_message_for_tests()

        url = '/v3/messages?limit=2&offset=1'
        req = fakes.HTTPRequest.blank(url)
        req.method = 'GET'
        req.content_type = 'application/json'
        req.headers = mv.get_mv_header(mv.MESSAGES_PAGINATION)
        req.api_version_request = mv.get_api_version(mv.MESSAGES_PAGINATION)
        req.environ['cinder.context'].is_admin = True

        res = self.controller.index(req)
        self.assertEqual(2, len(res['messages']))
Пример #52
0
    def test_get_all_messages_with_limit_and_offset(self):
        self.create_message_for_tests()

        url = '/v3/messages?limit=2&offset=1'
        req = fakes.HTTPRequest.blank(url)
        req.method = 'GET'
        req.content_type = 'application/json'
        req.headers = mv.get_mv_header(mv.MESSAGES_PAGINATION)
        req.api_version_request = mv.get_api_version(mv.MESSAGES_PAGINATION)
        req.environ['cinder.context'].is_admin = True

        res = self.controller.index(req)
        self.assertEqual(2, len(res['messages']))
Пример #53
0
    def test_volume_revert_with_snapshot_not_found(self, mock_volume,
                                                   mock_latest):
        fake_volume = self._fake_create_volume()
        mock_volume.return_value = fake_volume
        mock_latest.side_effect = exception.VolumeSnapshotNotFound(volume_id=
                                                                   'fake_id')
        req = fakes.HTTPRequest.blank('/v3/volumes/fake_id/revert')
        req.headers = mv.get_mv_header(mv.VOLUME_REVERT)
        req.api_version_request = mv.get_api_version(
            mv.VOLUME_REVERT)

        self.assertRaises(webob.exc.HTTPBadRequest, self.controller.revert,
                          req, 'fake_id', {'revert': {'snapshot_id':
                                                      'fake_snapshot_id'}})
Пример #54
0
    def test_volume_revert_with_snapshot_not_match(self, mock_volume,
                                                   mock_latest):
        fake_volume = self._fake_create_volume()
        mock_volume.return_value = fake_volume
        fake_snapshot = self._fake_create_snapshot(fake.UUID1)
        mock_latest.return_value = fake_snapshot
        req = fakes.HTTPRequest.blank('/v3/volumes/fake_id/revert')
        req.headers = mv.get_mv_header(mv.VOLUME_REVERT)
        req.api_version_request = mv.get_api_version(
            mv.VOLUME_REVERT)

        self.assertRaises(webob.exc.HTTPBadRequest, self.controller.revert,
                          req, 'fake_id', {'revert': {'snapshot_id':
                                                      'fake_snapshot_id'}})
Пример #55
0
    def test_get_all_messages_with_filter(self):
        self.create_message_for_tests()

        url = '/v3/messages?action_id=%s' % (
            message_field.Action.ATTACH_VOLUME[0])
        req = fakes.HTTPRequest.blank(url)
        req.method = 'GET'
        req.content_type = 'application/json'
        req.headers = mv.get_mv_header(mv.MESSAGES_PAGINATION)
        req.api_version_request = mv.get_api_version(mv.MESSAGES_PAGINATION)
        req.environ['cinder.context'].is_admin = True

        res = self.controller.index(req)
        self.assertEqual(1, len(res['messages']))
Пример #56
0
 def test_volume_revert_with_not_equal_size(self, mock_volume,
                                            mock_latest):
     fake_volume = self._fake_create_volume(size=2)
     fake_snapshot = self._fake_create_snapshot(fake_volume['id'],
                                                volume_size=1)
     mock_volume.return_value = fake_volume
     mock_latest.return_value = fake_snapshot
     req = fakes.HTTPRequest.blank('/v3/volumes/%s/revert'
                                   % fake_volume['id'])
     req.headers = mv.get_mv_header(mv.VOLUME_REVERT)
     req.api_version_request = mv.get_api_version(
         mv.VOLUME_REVERT)
     self.assertRaises(webob.exc.HTTPBadRequest, self.controller.revert,
                       req, fake_volume['id'],
                       {'revert': {'snapshot_id': fake_snapshot['id']}})
Пример #57
0
    def test_volume_create(self, max_ver, mock_validate):
        self.mock_object(volume_api.API, 'get', v2_fakes.fake_volume_get)
        self.mock_object(volume_api.API, "create",
                         v2_fakes.fake_volume_api_create)
        self.mock_object(db.sqlalchemy.api, '_volume_type_get_full',
                         v2_fakes.fake_volume_type_get)

        vol = self._vol_in_request_body()
        body = {"volume": vol}
        req = fakes.HTTPRequest.blank('/v3/volumes')
        req.api_version_request = mv.get_api_version(max_ver)
        res_dict = self.controller.create(req, body)
        ex = self._expected_vol_from_controller(
            req_version=req.api_version_request)
        self.assertEqual(ex, res_dict)
        self.assertTrue(mock_validate.called)
Пример #58
0
    def test_check_volume_filters_strict_called(self):

        with mock.patch.object(vol_get.API,
                               'check_volume_filters') as volume_get:
            req = fakes.HTTPRequest.blank('/v3/volumes?bootable=True')
            req.method = 'GET'
            req.content_type = 'application/json'
            req.headers = mv.get_mv_header(mv.VOLUME_LIST_BOOTABLE)
            req.environ['cinder.context'].is_admin = True
            req.api_version_request = mv.get_api_version(
                mv.VOLUME_LIST_BOOTABLE)

            self.override_config('query_volume_filters', 'bootable')
            self.controller.index(req)
            filters = req.params.copy()

            volume_get.assert_called_with(filters, True)
Пример #59
0
    def _send_backup_request(self, ctx, detail=False,
                             version=mv.BACKUP_PROJECT):
        req = None
        if detail:
            req = webob.Request.blank(('/v3/%s/backups/detail'
                                       % fake.PROJECT_ID))
        else:
            req = webob.Request.blank('/v3/%s/backups/%s' % (fake.PROJECT_ID,
                                                             fake.BACKUP_ID))
        req.method = 'GET'
        req.environ['cinder.context'] = ctx
        req.headers = mv.get_mv_header(version)
        req.api_version_request = mv.get_api_version(version)
        res = req.get_response(app())

        if detail:
            return jsonutils.loads(res.body)['backups']
        return jsonutils.loads(res.body)['backup']
Пример #60
0
    def test_volume_create(self, max_ver, volume_body):
        self.mock_object(volume_api.API, 'get', v2_fakes.fake_volume_get)
        self.mock_object(volume_api.API, "create",
                         v2_fakes.fake_volume_api_create)
        self.mock_object(db.sqlalchemy.api, '_volume_type_get_full',
                         v2_fakes.fake_volume_type_get)

        req = fakes.HTTPRequest.blank('/v3/volumes')
        req.api_version_request = mv.get_api_version(max_ver)

        body = {'volume': volume_body}
        res_dict = self.controller.create(req, body=body)
        ex = self._expected_vol_from_controller(
            req_version=req.api_version_request, name='test name',
            description='test desc')
        self.assertEqual(ex['volume']['name'],
                         res_dict['volume']['name'])
        self.assertEqual(ex['volume']['description'],
                         res_dict['volume']['description'])