Ejemplo n.º 1
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()
Ejemplo n.º 2
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()
Ejemplo n.º 3
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)
Ejemplo n.º 4
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'])
Ejemplo n.º 5
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']}})
Ejemplo n.º 6
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)
Ejemplo n.º 7
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
Ejemplo n.º 8
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))
Ejemplo n.º 9
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))
Ejemplo n.º 10
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'])
Ejemplo n.º 11
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
Ejemplo n.º 12
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
Ejemplo n.º 13
0
 def _get_resp_post(self, body, version=mv.MANAGE_EXISTING_LIST):
     """Helper to execute a POST manageable_volumes API call."""
     req = webob.Request.blank('/v3/%s/manageable_volumes' %
                               fake.PROJECT_ID)
     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)
     res = req.get_response(app())
     return res
Ejemplo n.º 14
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'])
Ejemplo n.º 15
0
 def _get_request_response(self, context, path, method, body=None,
                           microversion=mv.BASE_VERSION):
     request = webob.Request.blank(path)
     request.content_type = 'application/json'
     request.headers = mv.get_mv_header(microversion)
     request.method = method
     if body:
         request.headers["content-type"] = "application/json"
         request.body = jsonutils.dump_as_bytes(body)
     return request.get_response(
         fakes.wsgi_app(fake_auth_context=context)
     )
Ejemplo n.º 16
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']))
Ejemplo n.º 17
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)
Ejemplo n.º 18
0
    def test_get_all_messages_paging(self):
        self.create_message_for_tests()

        # first request of this test
        url = '/v3/fake/messages?limit=2'
        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.RESOURCE_FILTER)
        req.environ['cinder.context'].is_admin = True

        res = self.controller.index(req)
        self.assertEqual(2, len(res['messages']))

        next_link = ('http://localhost/v3/%s/messages?limit='
                     '2&marker=%s') % (fake_constants.PROJECT_ID,
                                       res['messages'][1]['id'])
        self.assertEqual(next_link,
                         res['messages_links'][0]['href'])

        # Second request in this test
        # Test for second page using marker (res['messages][0]['id'])
        # values fetched in first request with limit 2 in this test
        url = '/v3/fake/messages?limit=1&marker=%s' % (
            res['messages'][0]['id'])
        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 = api_version.max_api_version()
        req.environ['cinder.context'].is_admin = True

        result = self.controller.index(req)
        self.assertEqual(1, len(result['messages']))

        # checking second message of first request in this test with first
        # message of second request. (to test paging mechanism)
        self.assertEqual(res['messages'][1], result['messages'][0])
Ejemplo n.º 19
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']))
Ejemplo n.º 20
0
 def test_vol_filter_by_updated_at_with_eq_and_neq(self, change, result,
                                                   expected_volume_id):
     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))
     self.assertEqual(expected_volume_id, volumes[0]['id'])
Ejemplo n.º 21
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']))
Ejemplo n.º 22
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'}})
Ejemplo n.º 23
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'}})
Ejemplo n.º 24
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'}})
Ejemplo n.º 25
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'}})
Ejemplo n.º 26
0
    def test_check_volume_filters_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.BASE_VERSION)
            req.environ['cinder.context'].is_admin = True

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

            volume_get.assert_called_with(filters, False)
Ejemplo n.º 27
0
    def test_check_volume_filters_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.BASE_VERSION)
            req.environ['cinder.context'].is_admin = True

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

            volume_get.assert_called_with(filters, False)
Ejemplo n.º 28
0
 def test_show_transfer(self):
     volume_id = self._create_volume(size=5)
     transfer = self._create_transfer(volume_id)
     req = webob.Request.blank('/v3/%s/volume-transfers/%s' %
                               (fake.PROJECT_ID, transfer['id']))
     req.method = 'GET'
     req.headers = mv.get_mv_header(self.microversion)
     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(http_client.OK, res.status_int)
     self.assertEqual('test_transfer', res_dict['transfer']['name'])
     self.assertEqual(transfer['id'], res_dict['transfer']['id'])
     self.assertEqual(volume_id, res_dict['transfer']['volume_id'])
Ejemplo n.º 29
0
    def test_get_all_messages_with_limit_wrong_version(self):
        self.create_message_for_tests()

        PRE_MESSAGES_PAGINATION = mv.get_prior_version(mv.MESSAGES_PAGINATION)

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

        res = self.controller.index(req)
        self.assertEqual(4, len(res['messages']))
Ejemplo n.º 30
0
 def test_volume_index_filter_by_time_with_lte_and_gte(self):
     vols = self._create_volume_with_glance_metadata()
     change_since = vols[1].updated_at
     change_before = timeutils.utcnow() + datetime.timedelta(minutes=1)
     req = fakes.HTTPRequest.blank(("/v3/volumes?updated_at=lte:%s&"
                                    "updated_at=gte:%s") %
                                   (change_before, change_since))
     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(1, len(volumes))
     self.assertEqual(vols[1].id, volumes[0]['id'])
Ejemplo n.º 31
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']}})
Ejemplo n.º 32
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']}})
Ejemplo n.º 33
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('resource_query_filters_file',
                                 {'volume': ['bootable']})
            self.controller.index(req)
            filters = req.params.copy()

            volume_get.assert_called_with(filters, True)
Ejemplo n.º 34
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']
Ejemplo n.º 35
0
    def test_update_consistencygroup_no_body(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 = None
        self.assertRaisesRegex(webob.exc.HTTPBadRequest,
                               "Missing request body", self.controller.update,
                               req, consistencygroup.id, body)
        consistencygroup.destroy()
Ejemplo n.º 36
0
    def test_update_consistencygroup_no_body(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 = None
        self.assertRaisesRegexp(webob.exc.HTTPBadRequest,
                                "Missing request body",
                                self.controller.update,
                                req, consistencygroup.id, body)
        consistencygroup.destroy()
Ejemplo n.º 37
0
 def _get_resp_get(self, host, detailed, paging,
                   version=mv.MANAGE_EXISTING_LIST, **kwargs):
     """Helper to execute a GET os-snapshot-manage API call."""
     params = {'host': host} if host else {}
     params.update(kwargs)
     if paging:
         params.update({'marker': '1234', 'limit': 10,
                        'offset': 4, 'sort': 'reference:asc'})
     query_string = "?%s" % urlencode(params)
     detail = ""
     if detailed:
         detail = "/detail"
     req = webob.Request.blank('/v3/%s/manageable_snapshots%s%s' %
                               (fake.PROJECT_ID, detail, query_string))
     req.method = 'GET'
     req.headers = mv.get_mv_header(version)
     req.headers['Content-Type'] = 'application/json'
     req.environ['cinder.context'] = self._admin_ctxt
     res = req.get_response(app())
     return res
Ejemplo n.º 38
0
    def test_create_transfer(self):
        volume_id = self._create_volume(status='available', size=5)
        body = {"transfer": {"name": "transfer1", "volume_id": volume_id}}

        req = webob.Request.blank('/v3/%s/volume-transfers' % fake.PROJECT_ID)
        req.method = 'POST'
        req.headers = mv.get_mv_header(mv.TRANSFER_WITH_SNAPSHOTS)
        req.headers['Content-Type'] = 'application/json'
        req.body = jsonutils.dump_as_bytes(body)
        res = req.get_response(
            fakes.wsgi_app(fake_auth_context=self.user_ctxt))

        res_dict = jsonutils.loads(res.body)

        self.assertEqual(http_client.ACCEPTED, res.status_int)
        self.assertIn('id', res_dict['transfer'])
        self.assertIn('auth_key', res_dict['transfer'])
        self.assertIn('created_at', res_dict['transfer'])
        self.assertIn('name', res_dict['transfer'])
        self.assertIn('volume_id', res_dict['transfer'])
Ejemplo n.º 39
0
 def _get_resp_get(self, host, detailed, paging,
                   version=mv.MANAGE_EXISTING_LIST, **kwargs):
     """Helper to execute a GET os-snapshot-manage API call."""
     params = {'host': host} if host else {}
     params.update(kwargs)
     if paging:
         params.update({'marker': '1234', 'limit': 10,
                        'offset': 4, 'sort': 'reference:asc'})
     query_string = "?%s" % urlencode(params)
     detail = ""
     if detailed:
         detail = "/detail"
     req = webob.Request.blank('/v3/%s/manageable_snapshots%s%s' %
                               (fake.PROJECT_ID, detail, query_string))
     req.method = 'GET'
     req.headers = mv.get_mv_header(version)
     req.headers['Content-Type'] = 'application/json'
     req.environ['cinder.context'] = self._admin_ctxt
     res = req.get_response(app())
     return res
    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']
Ejemplo n.º 41
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()
Ejemplo n.º 42
0
    def test_owner_can_show_volumes(self, mock_volume):
        # Make sure owners are authorized to list their volumes
        fake_project_id = uuid.uuid4().hex
        user_context = cinder_context.RequestContext(
            user_id=uuid.uuid4().hex, project_id=fake_project_id
        )

        volume = self._create_fake_volume(user_context)
        mock_volume.return_value = volume
        path = '/v3/%(project_id)s/volumes/%(volume_id)s' % {
            'project_id': fake_project_id, 'volume_id': volume.id
        }
        request = webob.Request.blank(path)
        request.content_type = 'application/json'
        request.headers = mv.get_mv_header(mv.BASE_VERSION)
        request.method = 'GET'
        response = request.get_response(
            fakes.wsgi_app(fake_auth_context=user_context)
        )
        self.assertEqual(http_client.OK, response.status_int)
        self.assertEqual(response.json_body['volume']['id'], volume.id)
Ejemplo n.º 43
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.assertRaisesRegexp(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()
Ejemplo n.º 44
0
    def test_list_transfers(self):
        volume_id_1 = self._create_volume(size=5)
        volume_id_2 = self._create_volume(size=5)
        transfer1 = self._create_transfer(volume_id_1)
        transfer2 = self._create_transfer(volume_id_2)

        req = webob.Request.blank('/v3/%s/volume-transfers' % fake.PROJECT_ID)
        req.method = 'GET'
        req.headers = mv.get_mv_header(self.microversion)
        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(http_client.OK, res.status_int)
        self.assertEqual(self.SUMMARY_LEN, len(res_dict['transfers'][0]))
        self.assertEqual(transfer1['id'], res_dict['transfers'][0]['id'])
        self.assertEqual('test_transfer', res_dict['transfers'][0]['name'])
        self.assertEqual(self.SUMMARY_LEN, len(res_dict['transfers'][1]))
        self.assertEqual(transfer2['id'], res_dict['transfers'][1]['id'])
        self.assertEqual('test_transfer', res_dict['transfers'][1]['name'])
Ejemplo n.º 45
0
    def test_accept_transfer_volume_id_specified(self, type_get):
        volume_id = self._create_volume()
        transfer = self.volume_transfer_api.create(context.get_admin_context(),
                                                   volume_id, 'test_transfer')

        svc = self.start_service('volume', host='fake_host')
        body = {"accept": {"auth_key": transfer['auth_key']}}
        req = webob.Request.blank('/v3/%s/volume-transfers/%s/accept' %
                                  (fake.PROJECT_ID, transfer['id']))
        req.method = 'POST'
        req.headers = mv.get_mv_header(self.microversion)
        req.headers['Content-Type'] = 'application/json'
        req.body = jsonutils.dump_as_bytes(body)
        res = req.get_response(
            fakes.wsgi_app(fake_auth_context=self.user_ctxt))
        res_dict = jsonutils.loads(res.body)

        self.assertEqual(http_client.ACCEPTED, res.status_int)
        self.assertEqual(transfer['id'], res_dict['transfer']['id'])
        self.assertEqual(volume_id, res_dict['transfer']['volume_id'])
        # cleanup
        svc.stop()
Ejemplo n.º 46
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()
Ejemplo n.º 47
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()
Ejemplo n.º 48
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.assertRaisesRegexp(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()
Ejemplo n.º 49
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()
Ejemplo n.º 50
0
 def __init__(self, version=mv.BASE_VERSION, **kwargs):
     self.GET = kwargs
     self.headers = mv.get_mv_header(version)
     self.api_version_request = mv.get_api_version(version)
Ejemplo n.º 51
0
 def __init__(self, version=mv.BASE_VERSION, **kwargs):
     self.GET = kwargs
     self.headers = mv.get_mv_header(version)
     self.api_version_request = mv.get_api_version(version)