conf: Remove deprecated 'project_id_regex' opt

The 'project_id_regex' opt is used as a workaround for the test
like 'fake' 'openstack' etc, it's deprecated since 13.0.0
so time to remove it.

Co-Authored-By: jichenjc <jichenjc@cn.ibm.com>
Change-Id: I3eac9ac0a2a698a3c72b4e646cdcaf293ec4b057
This commit is contained in:
Takashi NATSUME 2019-09-27 15:40:49 +09:00
parent 2ec3b73f35
commit 088f237e59
28 changed files with 597 additions and 520 deletions

View File

@ -166,11 +166,7 @@ class ProjectMapper(APIMapper):
# NOTE(sdague): project_id parameter is only valid if its hex # NOTE(sdague): project_id parameter is only valid if its hex
# or hex + dashes (note, integers are a subset of this). This # or hex + dashes (note, integers are a subset of this). This
# is required to hand our overlaping routes issues. # is required to hand our overlaping routes issues.
project_id_regex = '[0-9a-f-]+' return '{project_id:[0-9a-f-]+}'
if CONF.osapi_v21.project_id_regex:
project_id_regex = CONF.osapi_v21.project_id_regex
return '{project_id:%s}' % project_id_regex
def resource(self, member_name, collection_name, **kwargs): def resource(self, member_name, collection_name, **kwargs):
project_id_token = self._get_project_id_token() project_id_token = self._get_project_id_token()

View File

@ -45,7 +45,6 @@ from nova.conf import network
from nova.conf import neutron from nova.conf import neutron
from nova.conf import notifications from nova.conf import notifications
from nova.conf import novnc from nova.conf import novnc
from nova.conf import osapi_v21
from nova.conf import paths from nova.conf import paths
from nova.conf import pci from nova.conf import pci
from nova.conf import placement from nova.conf import placement
@ -98,7 +97,6 @@ network.register_opts(CONF)
neutron.register_opts(CONF) neutron.register_opts(CONF)
notifications.register_opts(CONF) notifications.register_opts(CONF)
novnc.register_opts(CONF) novnc.register_opts(CONF)
osapi_v21.register_opts(CONF)
paths.register_opts(CONF) paths.register_opts(CONF)
pci.register_opts(CONF) pci.register_opts(CONF)
placement.register_opts(CONF) placement.register_opts(CONF)

View File

@ -1,47 +0,0 @@
# Copyright 2015 OpenStack Foundation
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_config import cfg
api_opts_group = cfg.OptGroup(name="osapi_v21", title="API v2.1 Options")
api_opts = [
cfg.StrOpt("project_id_regex",
deprecated_for_removal=True,
deprecated_since="13.0.0",
deprecated_reason="""
Recent versions of nova constrain project IDs to hexadecimal characters and
dashes. If your installation uses IDs outside of this range, you should use
this option to provide your own regex and give you time to migrate offending
projects to valid IDs before the next release.""",
help="""
This option is a string representing a regular expression (regex) that matches
the project_id as contained in URLs. If not set, it will match normal UUIDs
created by keystone.
Possible values:
* A string representing any legal regular expression
"""),
]
def register_opts(conf):
conf.register_group(api_opts_group)
conf.register_opts(api_opts, api_opts_group)
def list_opts():
return {api_opts_group: api_opts}

View File

@ -40,7 +40,7 @@ class AccessIPsAPIValidationTestV21(test.TestCase):
fake.stub_out_image_service(self) fake.stub_out_image_service(self)
self.stub_out('nova.compute.api.API.get', self.stub_out('nova.compute.api.API.get',
# This project_id matches fakes.HTTPRequest.blank. # This project_id matches fakes.HTTPRequest.blank.
fakes.fake_compute_get(project_id='fake')) fakes.fake_compute_get(project_id=fakes.FAKE_PROJECT_ID))
self.stub_out('nova.objects.instance.Instance.save', fake_save) self.stub_out('nova.objects.instance.Instance.save', fake_save)
self.stub_out('nova.compute.api.API.rebuild', fake_rebuild) self.stub_out('nova.compute.api.API.rebuild', fake_rebuild)

View File

@ -37,6 +37,7 @@ API_DISK_CONFIG = 'OS-DCF:diskConfig'
class DiskConfigTestCaseV21(test.TestCase): class DiskConfigTestCaseV21(test.TestCase):
project_id = fakes.FAKE_PROJECT_ID
def setUp(self): def setUp(self):
super(DiskConfigTestCaseV21, self).setUp() super(DiskConfigTestCaseV21, self).setUp()
@ -46,7 +47,7 @@ class DiskConfigTestCaseV21(test.TestCase):
self._setup_fake_image_service() self._setup_fake_image_service()
ctxt = nova_context.RequestContext( ctxt = nova_context.RequestContext(
# These values match what is used in fakes.HTTPRequest.blank. # These values match what is used in fakes.HTTPRequest.blank.
user_id='fake_user', project_id='fake') user_id='fake_user', project_id=self.project_id)
FAKE_INSTANCES = [ FAKE_INSTANCES = [
fakes.stub_instance_obj(ctxt, fakes.stub_instance_obj(ctxt,
uuid=MANUAL_INSTANCE_UUID, uuid=MANUAL_INSTANCE_UUID,
@ -132,19 +133,19 @@ class DiskConfigTestCaseV21(test.TestCase):
def test_show_server(self): def test_show_server(self):
req = fakes.HTTPRequest.blank( req = fakes.HTTPRequest.blank(
'/fake/servers/%s' % MANUAL_INSTANCE_UUID) '/%s/servers/%s' % (self.project_id, MANUAL_INSTANCE_UUID))
res = req.get_response(self.app) res = req.get_response(self.app)
server_dict = jsonutils.loads(res.body)['server'] server_dict = jsonutils.loads(res.body)['server']
self.assertDiskConfig(server_dict, 'MANUAL') self.assertDiskConfig(server_dict, 'MANUAL')
req = fakes.HTTPRequest.blank( req = fakes.HTTPRequest.blank(
'/fake/servers/%s' % AUTO_INSTANCE_UUID) '/%s/servers/%s' % (self.project_id, AUTO_INSTANCE_UUID))
res = req.get_response(self.app) res = req.get_response(self.app)
server_dict = jsonutils.loads(res.body)['server'] server_dict = jsonutils.loads(res.body)['server']
self.assertDiskConfig(server_dict, 'AUTO') self.assertDiskConfig(server_dict, 'AUTO')
def test_detail_servers(self): def test_detail_servers(self):
req = fakes.HTTPRequest.blank('/fake/servers/detail') req = fakes.HTTPRequest.blank('/%s/servers/detail' % self.project_id)
res = req.get_response(self.app) res = req.get_response(self.app)
server_dicts = jsonutils.loads(res.body)['servers'] server_dicts = jsonutils.loads(res.body)['servers']
@ -156,19 +157,21 @@ class DiskConfigTestCaseV21(test.TestCase):
self.flags(group='glance', api_servers=['http://localhost:9292']) self.flags(group='glance', api_servers=['http://localhost:9292'])
req = fakes.HTTPRequest.blank( req = fakes.HTTPRequest.blank(
'/fake/images/a440c04b-79fa-479c-bed1-0b816eaec379') '/%s/images/a440c04b-79fa-479c-bed1-0b816eaec379' %
self.project_id)
res = req.get_response(self.app) res = req.get_response(self.app)
image_dict = jsonutils.loads(res.body)['image'] image_dict = jsonutils.loads(res.body)['image']
self.assertDiskConfig(image_dict, 'MANUAL') self.assertDiskConfig(image_dict, 'MANUAL')
req = fakes.HTTPRequest.blank( req = fakes.HTTPRequest.blank(
'/fake/images/70a599e0-31e7-49b7-b260-868f441e862b') '/%s/images/70a599e0-31e7-49b7-b260-868f441e862b' %
self.project_id)
res = req.get_response(self.app) res = req.get_response(self.app)
image_dict = jsonutils.loads(res.body)['image'] image_dict = jsonutils.loads(res.body)['image']
self.assertDiskConfig(image_dict, 'AUTO') self.assertDiskConfig(image_dict, 'AUTO')
def test_detail_image(self): def test_detail_image(self):
req = fakes.HTTPRequest.blank('/fake/images/detail') req = fakes.HTTPRequest.blank('/%s/images/detail' % self.project_id)
res = req.get_response(self.app) res = req.get_response(self.app)
image_dicts = jsonutils.loads(res.body)['images'] image_dicts = jsonutils.loads(res.body)['images']
@ -180,7 +183,7 @@ class DiskConfigTestCaseV21(test.TestCase):
self.assertDiskConfig(image_dict, expected) self.assertDiskConfig(image_dict, expected)
def test_create_server_override_auto(self): def test_create_server_override_auto(self):
req = fakes.HTTPRequest.blank('/fake/servers') req = fakes.HTTPRequest.blank('/%s/servers' % self.project_id)
req.method = 'POST' req.method = 'POST'
req.content_type = 'application/json' req.content_type = 'application/json'
body = {'server': { body = {'server': {
@ -196,7 +199,7 @@ class DiskConfigTestCaseV21(test.TestCase):
self.assertDiskConfig(server_dict, 'AUTO') self.assertDiskConfig(server_dict, 'AUTO')
def test_create_server_override_manual(self): def test_create_server_override_manual(self):
req = fakes.HTTPRequest.blank('/fake/servers') req = fakes.HTTPRequest.blank('/%s/servers' % self.project_id)
req.method = 'POST' req.method = 'POST'
req.content_type = 'application/json' req.content_type = 'application/json'
body = {'server': { body = {'server': {
@ -215,7 +218,7 @@ class DiskConfigTestCaseV21(test.TestCase):
"""If user doesn't pass in diskConfig for server, use image metadata """If user doesn't pass in diskConfig for server, use image metadata
to specify AUTO or MANUAL. to specify AUTO or MANUAL.
""" """
req = fakes.HTTPRequest.blank('/fake/servers') req = fakes.HTTPRequest.blank('/%s/servers' % self.project_id)
req.method = 'POST' req.method = 'POST'
req.content_type = 'application/json' req.content_type = 'application/json'
body = {'server': { body = {'server': {
@ -229,7 +232,7 @@ class DiskConfigTestCaseV21(test.TestCase):
server_dict = jsonutils.loads(res.body)['server'] server_dict = jsonutils.loads(res.body)['server']
self.assertDiskConfig(server_dict, 'MANUAL') self.assertDiskConfig(server_dict, 'MANUAL')
req = fakes.HTTPRequest.blank('/fake/servers') req = fakes.HTTPRequest.blank('/%s/servers' % self.project_id)
req.method = 'POST' req.method = 'POST'
req.content_type = 'application/json' req.content_type = 'application/json'
body = {'server': { body = {'server': {
@ -244,7 +247,7 @@ class DiskConfigTestCaseV21(test.TestCase):
self.assertDiskConfig(server_dict, 'AUTO') self.assertDiskConfig(server_dict, 'AUTO')
def test_create_server_detect_from_image_disabled_goes_to_manual(self): def test_create_server_detect_from_image_disabled_goes_to_manual(self):
req = fakes.HTTPRequest.blank('/fake/servers') req = fakes.HTTPRequest.blank('/%s/servers' % self.project_id)
req.method = 'POST' req.method = 'POST'
req.content_type = 'application/json' req.content_type = 'application/json'
body = {'server': { body = {'server': {
@ -259,7 +262,7 @@ class DiskConfigTestCaseV21(test.TestCase):
self.assertDiskConfig(server_dict, 'MANUAL') self.assertDiskConfig(server_dict, 'MANUAL')
def test_create_server_errors_when_disabled_and_auto(self): def test_create_server_errors_when_disabled_and_auto(self):
req = fakes.HTTPRequest.blank('/fake/servers') req = fakes.HTTPRequest.blank('/%s/servers' % self.project_id)
req.method = 'POST' req.method = 'POST'
req.content_type = 'application/json' req.content_type = 'application/json'
body = {'server': { body = {'server': {
@ -274,7 +277,7 @@ class DiskConfigTestCaseV21(test.TestCase):
self.assertEqual(res.status_int, 400) self.assertEqual(res.status_int, 400)
def test_create_server_when_disabled_and_manual(self): def test_create_server_when_disabled_and_manual(self):
req = fakes.HTTPRequest.blank('/fake/servers') req = fakes.HTTPRequest.blank('/%s/servers' % self.project_id)
req.method = 'POST' req.method = 'POST'
req.content_type = 'application/json' req.content_type = 'application/json'
body = {'server': { body = {'server': {
@ -293,7 +296,7 @@ class DiskConfigTestCaseV21(test.TestCase):
def _test_update_server_disk_config(self, uuid, disk_config, def _test_update_server_disk_config(self, uuid, disk_config,
get_instance_mock): get_instance_mock):
req = fakes.HTTPRequest.blank( req = fakes.HTTPRequest.blank(
'/fake/servers/%s' % uuid) '/%s/servers/%s' % (self.project_id, uuid))
req.method = 'PUT' req.method = 'PUT'
req.content_type = 'application/json' req.content_type = 'application/json'
body = {'server': {API_DISK_CONFIG: disk_config}} body = {'server': {API_DISK_CONFIG: disk_config}}
@ -318,7 +321,7 @@ class DiskConfigTestCaseV21(test.TestCase):
def test_update_server_invalid_disk_config(self): def test_update_server_invalid_disk_config(self):
# Return BadRequest if user passes an invalid diskConfig value. # Return BadRequest if user passes an invalid diskConfig value.
req = fakes.HTTPRequest.blank( req = fakes.HTTPRequest.blank(
'/fake/servers/%s' % MANUAL_INSTANCE_UUID) '/%s/servers/%s' % (self.project_id, MANUAL_INSTANCE_UUID))
req.method = 'PUT' req.method = 'PUT'
req.content_type = 'application/json' req.content_type = 'application/json'
body = {'server': {API_DISK_CONFIG: 'server_test'}} body = {'server': {API_DISK_CONFIG: 'server_test'}}
@ -335,7 +338,7 @@ class DiskConfigTestCaseV21(test.TestCase):
def _test_rebuild_server_disk_config(self, uuid, disk_config, def _test_rebuild_server_disk_config(self, uuid, disk_config,
get_instance_mock): get_instance_mock):
req = fakes.HTTPRequest.blank( req = fakes.HTTPRequest.blank(
'/fake/servers/%s/action' % uuid) '/%s/servers/%s/action' % (self.project_id, uuid))
req.method = 'POST' req.method = 'POST'
req.content_type = 'application/json' req.content_type = 'application/json'
auto_disk_config = (disk_config == 'AUTO') auto_disk_config = (disk_config == 'AUTO')
@ -361,7 +364,7 @@ class DiskConfigTestCaseV21(test.TestCase):
self._test_rebuild_server_disk_config(MANUAL_INSTANCE_UUID, 'MANUAL') self._test_rebuild_server_disk_config(MANUAL_INSTANCE_UUID, 'MANUAL')
def test_create_server_with_auto_disk_config(self): def test_create_server_with_auto_disk_config(self):
req = fakes.HTTPRequest.blank('/fake/servers') req = fakes.HTTPRequest.blank('/%s/servers' % self.project_id)
req.method = 'POST' req.method = 'POST'
req.content_type = 'application/json' req.content_type = 'application/json'
body = {'server': { body = {'server': {
@ -387,7 +390,7 @@ class DiskConfigTestCaseV21(test.TestCase):
@mock.patch('nova.api.openstack.common.get_instance') @mock.patch('nova.api.openstack.common.get_instance')
def test_rebuild_server_with_auto_disk_config(self, get_instance_mock): def test_rebuild_server_with_auto_disk_config(self, get_instance_mock):
req = fakes.HTTPRequest.blank( req = fakes.HTTPRequest.blank(
'/fake/servers/%s/action' % AUTO_INSTANCE_UUID) '/%s/servers/%s/action' % (self.project_id, AUTO_INSTANCE_UUID))
req.method = 'POST' req.method = 'POST'
req.content_type = 'application/json' req.content_type = 'application/json'
instance = fakes.stub_instance_obj( instance = fakes.stub_instance_obj(
@ -414,7 +417,7 @@ class DiskConfigTestCaseV21(test.TestCase):
def test_resize_server_with_auto_disk_config(self): def test_resize_server_with_auto_disk_config(self):
req = fakes.HTTPRequest.blank( req = fakes.HTTPRequest.blank(
'/fake/servers/%s/action' % AUTO_INSTANCE_UUID) '/%s/servers/%s/action' % (self.project_id, AUTO_INSTANCE_UUID))
req.method = 'POST' req.method = 'POST'
req.content_type = 'application/json' req.content_type = 'application/json'
body = {"resize": { body = {"resize": {

View File

@ -133,14 +133,14 @@ class ExtendedIpsTestV21(test.TestCase):
self.assertJsonEqual(ALL_IPS, results) self.assertJsonEqual(ALL_IPS, results)
def test_show(self): def test_show(self):
url = '/v2/fake/servers/%s' % UUID3 url = '/v2/%s/servers/%s' % (fakes.FAKE_PROJECT_ID, UUID3)
res = self._make_request(url) res = self._make_request(url)
self.assertEqual(res.status_int, 200) self.assertEqual(res.status_int, 200)
self.assertServerStates(self._get_server(res.body)) self.assertServerStates(self._get_server(res.body))
def test_detail(self): def test_detail(self):
url = '/v2/fake/servers/detail' url = '/v2/%s/servers/detail' % fakes.FAKE_PROJECT_ID
res = self._make_request(url) res = self._make_request(url)
self.assertEqual(res.status_int, 200) self.assertEqual(res.status_int, 200)

View File

@ -138,14 +138,14 @@ class ExtendedIpsMacTestV21(test.TestCase):
self.assertJsonEqual(ALL_IPS, results) self.assertJsonEqual(ALL_IPS, results)
def test_show(self): def test_show(self):
url = '/v2/fake/servers/%s' % UUID3 url = '/v2/%s/servers/%s' % (fakes.FAKE_PROJECT_ID, UUID3)
res = self._make_request(url) res = self._make_request(url)
self.assertEqual(200, res.status_int) self.assertEqual(200, res.status_int)
self.assertServerStates(self._get_server(res.body)) self.assertServerStates(self._get_server(res.body))
def test_detail(self): def test_detail(self):
url = '/v2/fake/servers/detail' url = '/v2/%s/servers/detail' % fakes.FAKE_PROJECT_ID
res = self._make_request(url) res = self._make_request(url)
self.assertEqual(200, res.status_int) self.assertEqual(200, res.status_int)

View File

@ -19,7 +19,7 @@ from nova.tests.unit.api.openstack import fakes
class FlavorDisabledTestV21(test.NoDBTestCase): class FlavorDisabledTestV21(test.NoDBTestCase):
base_url = '/v2/fake/flavors' base_url = '/v2/%s/flavors' % fakes.FAKE_PROJECT_ID
content_type = 'application/json' content_type = 'application/json'
prefix = "OS-FLV-DISABLED:" prefix = "OS-FLV-DISABLED:"

View File

@ -61,7 +61,7 @@ def fake_create_without_swap(newflavor):
class FlavorManageTestV21(test.NoDBTestCase): class FlavorManageTestV21(test.NoDBTestCase):
controller = flavormanage_v21.FlavorManageController() controller = flavormanage_v21.FlavorManageController()
validation_error = exception.ValidationError validation_error = exception.ValidationError
base_url = '/v2/fake/flavors' base_url = '/v2/%s/flavors' % fakes.FAKE_PROJECT_ID
microversion = '2.1' microversion = '2.1'
def setUp(self): def setUp(self):
@ -507,9 +507,8 @@ class FlavorManageTestV2_75(FlavorManageTestV2_61):
flavor = self._create_flavor_success_case(self.request_body, flavor = self._create_flavor_success_case(self.request_body,
version='2.74')['flavor'] version='2.74')['flavor']
mock_get.return_value = self.FLAVOR_WITH_NO_SWAP mock_get.return_value = self.FLAVOR_WITH_NO_SWAP
req = fakes.HTTPRequest.blank( req = fakes.HTTPRequest.blank('/%s/flavors' % fakes.FAKE_PROJECT_ID,
'/fake/flavors', version='2.74')
version='2.74')
req.method = 'PUT' req.method = 'PUT'
response = self.controller._update( response = self.controller._update(
req, flavor['id'], req, flavor['id'],
@ -530,9 +529,8 @@ class FlavorManageTestV2_75(FlavorManageTestV2_61):
del self.request_body['flavor']['swap'] del self.request_body['flavor']['swap']
mock_get.return_value = self.FLAVOR_WITH_NO_SWAP mock_get.return_value = self.FLAVOR_WITH_NO_SWAP
flavor = self._create_flavor_success_case(self.request_body)['flavor'] flavor = self._create_flavor_success_case(self.request_body)['flavor']
req = fakes.HTTPRequest.blank( req = fakes.HTTPRequest.blank('/%s/flavors' % fakes.FAKE_PROJECT_ID,
'/fake/flavors', version=self.microversion)
version=self.microversion)
response = self.controller._update( response = self.controller._update(
req, flavor['id'], req, flavor['id'],
body={'flavor': {'description': None}})['flavor'] body={'flavor': {'description': None}})['flavor']
@ -541,7 +539,7 @@ class FlavorManageTestV2_75(FlavorManageTestV2_61):
class PrivateFlavorManageTestV21(test.TestCase): class PrivateFlavorManageTestV21(test.TestCase):
controller = flavormanage_v21.FlavorManageController() controller = flavormanage_v21.FlavorManageController()
base_url = '/v2/fake/flavors' base_url = '/v2/%s/flavors' % fakes.FAKE_PROJECT_ID
def setUp(self): def setUp(self):
super(PrivateFlavorManageTestV21, self).setUp() super(PrivateFlavorManageTestV21, self).setUp()

View File

@ -20,7 +20,7 @@ from nova.tests.unit.api.openstack import fakes
class FlavorExtraDataTestV21(test.NoDBTestCase): class FlavorExtraDataTestV21(test.NoDBTestCase):
base_url = '/v2/fake/flavors' base_url = '/v2/%s/flavors' % fakes.FAKE_PROJECT_ID
def setUp(self): def setUp(self):
super(FlavorExtraDataTestV21, self).setUp() super(FlavorExtraDataTestV21, self).setUp()

View File

@ -44,11 +44,11 @@ def return_flavor_not_found(context, flavor_id, read_deleted=None):
class FlavorsTestV21(test.TestCase): class FlavorsTestV21(test.TestCase):
_prefix = "/v2/fake" _prefix = "/v2/%s" % fakes.FAKE_PROJECT_ID
Controller = flavors_v21.FlavorsController Controller = flavors_v21.FlavorsController
fake_request = fakes.HTTPRequestV21 fake_request = fakes.HTTPRequestV21
_rspv = "v2/fake" _rspv = "v2/%s" % fakes.FAKE_PROJECT_ID
_fake = "/fake" _fake = "/%s" % fakes.FAKE_PROJECT_ID
microversion = '2.1' microversion = '2.1'
# Flag to tell the test if a description should be expected in a response. # Flag to tell the test if a description should be expected in a response.
expect_description = False expect_description = False
@ -338,11 +338,13 @@ class FlavorsTestV21(test.TestCase):
"links": [ "links": [
{ {
"rel": "self", "rel": "self",
"href": "http://localhost/v2/fake/flavors/1", "href": ("http://localhost/v2/%s/flavors/1" %
fakes.FAKE_PROJECT_ID),
}, },
{ {
"rel": "bookmark", "rel": "bookmark",
"href": "http://localhost/fake/flavors/1", "href": ("http://localhost/%s/flavors/1" %
fakes.FAKE_PROJECT_ID),
} }
] ]
} }
@ -354,7 +356,8 @@ class FlavorsTestV21(test.TestCase):
self.assertEqual(response_list, expected_flavors) self.assertEqual(response_list, expected_flavors)
self.assertEqual(response_links[0]['rel'], 'next') self.assertEqual(response_links[0]['rel'], 'next')
href_parts = urlparse.urlparse(response_links[0]['href']) href_parts = urlparse.urlparse(response_links[0]['href'])
self.assertEqual('/v2/fake/flavors', href_parts.path) self.assertEqual('/v2/%s/flavors' % fakes.FAKE_PROJECT_ID,
href_parts.path)
params = urlparse.parse_qs(href_parts.query) params = urlparse.parse_qs(href_parts.query)
self.assertThat({'limit': ['2'], 'marker': ['1']}, self.assertThat({'limit': ['2'], 'marker': ['1']},
matchers.DictMatches(params)) matchers.DictMatches(params))
@ -813,10 +816,11 @@ class FlavorsTestV2_75(FlavorsTestV2_61):
def test_list_flavors_with_additional_filter_old_version(self): def test_list_flavors_with_additional_filter_old_version(self):
req = self.fake_request.blank( req = self.fake_request.blank(
'/fake/flavors?limit=1&marker=1&additional=something', '/%s/flavors?limit=1&marker=1&additional=something' %
version='2.74') fakes.FAKE_PROJECT_ID, version='2.74')
self._test_list_flavors_with_allowed_filter( self._test_list_flavors_with_allowed_filter(
'/fake/flavors?limit=1&marker=1&additional=something', req=req) '/%s/flavors?limit=1&marker=1&additional=something' %
fakes.FAKE_PROJECT_ID, req=req)
def test_list_detail_flavors_with_additional_filter_old_version(self): def test_list_detail_flavors_with_additional_filter_old_version(self):
expected = { expected = {
@ -830,11 +834,11 @@ class FlavorsTestV2_75(FlavorsTestV2_61):
"swap": fakes.FLAVORS['2'].swap "swap": fakes.FLAVORS['2'].swap
} }
req = self.fake_request.blank( req = self.fake_request.blank(
'/fake/flavors?limit=1&marker=1&additional=something', '/%s/flavors?limit=1&marker=1&additional=something' %
version='2.74') fakes.FAKE_PROJECT_ID, version='2.74')
self._test_list_flavors_with_allowed_filter( self._test_list_flavors_with_allowed_filter(
'/fake/flavors/detail?limit=1&marker=1&additional=something', '/%s/flavors/detail?limit=1&marker=1&additional=something' %
expected, req=req) fakes.FAKE_PROJECT_ID, expected, req=req)
def _test_list_flavors_with_additional_filter(self, url): def _test_list_flavors_with_additional_filter(self, url):
controller_list = self.controller.index controller_list = self.controller.index
@ -857,7 +861,7 @@ class FlavorsTestV2_75(FlavorsTestV2_61):
mock_get.return_value = objects.FlavorList( mock_get.return_value = objects.FlavorList(
objects=[self.FLAVOR_WITH_NO_SWAP]) objects=[self.FLAVOR_WITH_NO_SWAP])
req = self.fake_request.blank( req = self.fake_request.blank(
'/fake/flavors/detail?limit=1', '/%s/flavors/detail?limit=1' % fakes.FAKE_PROJECT_ID,
version='2.74') version='2.74')
response = self.controller.detail(req) response = self.controller.detail(req)
response_list = response["flavors"] response_list = response["flavors"]
@ -867,7 +871,7 @@ class FlavorsTestV2_75(FlavorsTestV2_61):
def test_show_flavor_default_swap_value_old_version(self, mock_get): def test_show_flavor_default_swap_value_old_version(self, mock_get):
mock_get.return_value = self.FLAVOR_WITH_NO_SWAP mock_get.return_value = self.FLAVOR_WITH_NO_SWAP
req = self.fake_request.blank( req = self.fake_request.blank(
'/fake/flavors/detail?limit=1', '/%s/flavors/detail?limit=1' % fakes.FAKE_PROJECT_ID,
version='2.74') version='2.74')
response = self.controller.show(req, 1) response = self.controller.show(req, 1)
response_list = response["flavor"] response_list = response["flavor"]
@ -878,7 +882,7 @@ class FlavorsTestV2_75(FlavorsTestV2_61):
mock_get.return_value = objects.FlavorList( mock_get.return_value = objects.FlavorList(
objects=[self.FLAVOR_WITH_NO_SWAP]) objects=[self.FLAVOR_WITH_NO_SWAP])
req = self.fake_request.blank( req = self.fake_request.blank(
'/fake/flavors/detail?limit=1', '/%s/flavors/detail?limit=1' % fakes.FAKE_PROJECT_ID,
version=self.microversion) version=self.microversion)
response = self.controller.detail(req) response = self.controller.detail(req)
response_list = response["flavors"] response_list = response["flavors"]
@ -888,7 +892,7 @@ class FlavorsTestV2_75(FlavorsTestV2_61):
def test_show_flavor_default_swap_value(self, mock_get): def test_show_flavor_default_swap_value(self, mock_get):
mock_get.return_value = self.FLAVOR_WITH_NO_SWAP mock_get.return_value = self.FLAVOR_WITH_NO_SWAP
req = self.fake_request.blank( req = self.fake_request.blank(
'/fake/flavors/detail?limit=1', '/%s/flavors/detail?limit=1' % fakes.FAKE_PROJECT_ID,
version=self.microversion) version=self.microversion)
response = self.controller.show(req, 1) response = self.controller.show(req, 1)
response_list = response["flavor"] response_list = response["flavor"]

View File

@ -43,8 +43,8 @@ class ImagesControllerTestV21(test.NoDBTestCase):
"""Test of the OpenStack API /images application controller w/Glance. """Test of the OpenStack API /images application controller w/Glance.
""" """
image_controller_class = images_v21.ImagesController image_controller_class = images_v21.ImagesController
url_base = '/v2/fake' url_base = '/v2/%s' % fakes.FAKE_PROJECT_ID
bookmark_base = '/fake' bookmark_base = '/%s' % fakes.FAKE_PROJECT_ID
http_request = fakes.HTTPRequestV21 http_request = fakes.HTTPRequestV21
def setUp(self): def setUp(self):

View File

@ -64,7 +64,7 @@ def db_key_pair_create_duplicate(context):
class KeypairsTestV21(test.TestCase): class KeypairsTestV21(test.TestCase):
base_url = '/v2/fake' base_url = '/v2/%s' % fakes.FAKE_PROJECT_ID
validation_error = exception.ValidationError validation_error = exception.ValidationError
wsgi_api_version = os_wsgi.DEFAULT_API_VERSION wsgi_api_version = os_wsgi.DEFAULT_API_VERSION
@ -545,7 +545,7 @@ class KeypairsTestV210(KeypairsTestV22):
class KeypairsTestV235(test.TestCase): class KeypairsTestV235(test.TestCase):
base_url = '/v2/fake' base_url = '/v2/%s' % fakes.FAKE_PROJECT_ID
wsgi_api_version = '2.35' wsgi_api_version = '2.35'
def _setup_app_and_controller(self): def _setup_app_and_controller(self):

View File

@ -49,14 +49,17 @@ class LegacyMicroversionsTest(test.NoDBTestCase):
return headers return headers
def test_microversions_no_header(self): def test_microversions_no_header(self):
req = fakes.HTTPRequest.blank('/v2/fake/microversions', method='GET') req = fakes.HTTPRequest.blank(
'/v2/%s/microversions' % fakes.FAKE_PROJECT_ID,
method='GET')
res = req.get_response(self.app) res = req.get_response(self.app)
self.assertEqual(200, res.status_int) self.assertEqual(200, res.status_int)
resp_json = jsonutils.loads(res.body) resp_json = jsonutils.loads(res.body)
self.assertEqual('val', resp_json['param']) self.assertEqual('val', resp_json['param'])
def test_microversions_return_header(self): def test_microversions_return_header(self):
req = fakes.HTTPRequest.blank('/v2/fake/microversions') req = fakes.HTTPRequest.blank(
'/v2/%s/microversions' % fakes.FAKE_PROJECT_ID)
res = req.get_response(self.app) res = req.get_response(self.app)
self.assertEqual(200, res.status_int) self.assertEqual(200, res.status_int)
resp_json = jsonutils.loads(res.body) resp_json = jsonutils.loads(res.body)
@ -72,7 +75,8 @@ class LegacyMicroversionsTest(test.NoDBTestCase):
mock_maxver): mock_maxver):
mock_maxver.return_value = api_version.APIVersionRequest("2.3") mock_maxver.return_value = api_version.APIVersionRequest("2.3")
req = fakes.HTTPRequest.blank('/v2/fake/microversions') req = fakes.HTTPRequest.blank(
'/v2/%s/microversions' % fakes.FAKE_PROJECT_ID)
req.headers = self._make_header('2.3') req.headers = self._make_header('2.3')
res = req.get_response(self.app) res = req.get_response(self.app)
self.assertEqual(200, res.status_int) self.assertEqual(200, res.status_int)
@ -88,7 +92,8 @@ class LegacyMicroversionsTest(test.NoDBTestCase):
def test_microversions_return_header_fault(self, mock_maxver): def test_microversions_return_header_fault(self, mock_maxver):
mock_maxver.return_value = api_version.APIVersionRequest("3.0") mock_maxver.return_value = api_version.APIVersionRequest("3.0")
req = fakes.HTTPRequest.blank('/v2/fake/microversions') req = fakes.HTTPRequest.blank(
'/v2/%s/microversions' % fakes.FAKE_PROJECT_ID)
req.headers = self._make_header('3.0') req.headers = self._make_header('3.0')
res = req.get_response(self.app) res = req.get_response(self.app)
self.assertEqual(400, res.status_int) self.assertEqual(400, res.status_int)
@ -111,22 +116,26 @@ class LegacyMicroversionsTest(test.NoDBTestCase):
self.assertEqual(resp_param, resp_json['param']) self.assertEqual(resp_param, resp_json['param'])
def test_microversions_with_header(self): def test_microversions_with_header(self):
self._check_microversion_response('/v2/fake/microversions', self._check_microversion_response(
'2.3', 'val2') '/v2/%s/microversions' % fakes.FAKE_PROJECT_ID,
'2.3', 'val2')
def test_microversions_with_header_exact_match(self): def test_microversions_with_header_exact_match(self):
self._check_microversion_response('/v2/fake/microversions', self._check_microversion_response(
'2.2', 'val2') '/v2/%s/microversions' % fakes.FAKE_PROJECT_ID,
'2.2', 'val2')
def test_microversions2_no_2_1_version(self): def test_microversions2_no_2_1_version(self):
self._check_microversion_response('/v2/fake/microversions2', self._check_microversion_response(
'2.3', 'controller2_val1') '/v2/%s/microversions2' % fakes.FAKE_PROJECT_ID,
'2.3', 'controller2_val1')
@mock.patch("nova.api.openstack.api_version_request.max_api_version") @mock.patch("nova.api.openstack.api_version_request.max_api_version")
def test_microversions2_later_version(self, mock_maxver): def test_microversions2_later_version(self, mock_maxver):
mock_maxver.return_value = api_version.APIVersionRequest("3.1") mock_maxver.return_value = api_version.APIVersionRequest("3.1")
req = fakes.HTTPRequest.blank('/v2/fake/microversions2') req = fakes.HTTPRequest.blank(
'/v2/%s/microversions2' % fakes.FAKE_PROJECT_ID)
req.headers = self._make_header('3.0') req.headers = self._make_header('3.0')
res = req.get_response(self.app) res = req.get_response(self.app)
self.assertEqual(202, res.status_int) self.assertEqual(202, res.status_int)
@ -137,13 +146,15 @@ class LegacyMicroversionsTest(test.NoDBTestCase):
def test_microversions2_version_too_high(self, mock_maxver): def test_microversions2_version_too_high(self, mock_maxver):
mock_maxver.return_value = api_version.APIVersionRequest("3.5") mock_maxver.return_value = api_version.APIVersionRequest("3.5")
req = fakes.HTTPRequest.blank('/v2/fake/microversions2') req = fakes.HTTPRequest.blank(
'/v2/%s/microversions2' % fakes.FAKE_PROJECT_ID)
req.headers = {self.header_name: '3.2'} req.headers = {self.header_name: '3.2'}
res = req.get_response(self.app) res = req.get_response(self.app)
self.assertEqual(404, res.status_int) self.assertEqual(404, res.status_int)
def test_microversions2_version_too_low(self): def test_microversions2_version_too_low(self):
req = fakes.HTTPRequest.blank('/v2/fake/microversions2') req = fakes.HTTPRequest.blank(
'/v2/%s/microversions2' % fakes.FAKE_PROJECT_ID)
req.headers = {self.header_name: '2.1'} req.headers = {self.header_name: '2.1'}
res = req.get_response(self.app) res = req.get_response(self.app)
self.assertEqual(404, res.status_int) self.assertEqual(404, res.status_int)
@ -153,7 +164,8 @@ class LegacyMicroversionsTest(test.NoDBTestCase):
mock_maxver): mock_maxver):
mock_maxver.return_value = api_version.APIVersionRequest("3.5") mock_maxver.return_value = api_version.APIVersionRequest("3.5")
req = fakes.HTTPRequest.blank('/v2/fake/microversions2') req = fakes.HTTPRequest.blank(
'/v2/%s/microversions2' % fakes.FAKE_PROJECT_ID)
req.headers = self._make_header('3.7') req.headers = self._make_header('3.7')
res = req.get_response(self.app) res = req.get_response(self.app)
self.assertEqual(406, res.status_int) self.assertEqual(406, res.status_int)
@ -166,7 +178,8 @@ class LegacyMicroversionsTest(test.NoDBTestCase):
def test_microversions_schema(self, mock_maxver): def test_microversions_schema(self, mock_maxver):
mock_maxver.return_value = api_version.APIVersionRequest("3.3") mock_maxver.return_value = api_version.APIVersionRequest("3.3")
req = fakes.HTTPRequest.blank('/v2/fake/microversions3') req = fakes.HTTPRequest.blank(
'/v2/%s/microversions3' % fakes.FAKE_PROJECT_ID)
req.method = 'POST' req.method = 'POST'
req.headers = self._make_header('2.2') req.headers = self._make_header('2.2')
req.environ['CONTENT_TYPE'] = "application/json" req.environ['CONTENT_TYPE'] = "application/json"
@ -186,7 +199,8 @@ class LegacyMicroversionsTest(test.NoDBTestCase):
def test_microversions_schema_fail(self, mock_maxver): def test_microversions_schema_fail(self, mock_maxver):
mock_maxver.return_value = api_version.APIVersionRequest("3.3") mock_maxver.return_value = api_version.APIVersionRequest("3.3")
req = fakes.HTTPRequest.blank('/v2/fake/microversions3') req = fakes.HTTPRequest.blank(
'/v2/%s/microversions3' % fakes.FAKE_PROJECT_ID)
req.method = 'POST' req.method = 'POST'
req.headers = {self.header_name: '2.2'} req.headers = {self.header_name: '2.2'}
req.environ['CONTENT_TYPE'] = "application/json" req.environ['CONTENT_TYPE'] = "application/json"
@ -203,7 +217,8 @@ class LegacyMicroversionsTest(test.NoDBTestCase):
mock_maxver): mock_maxver):
mock_maxver.return_value = api_version.APIVersionRequest("3.3") mock_maxver.return_value = api_version.APIVersionRequest("3.3")
req = fakes.HTTPRequest.blank('/v2/fake/microversions3/1') req = fakes.HTTPRequest.blank(
'/v2/%s/microversions3/1' % fakes.FAKE_PROJECT_ID)
req.method = 'PUT' req.method = 'PUT'
req.headers = self._make_header('2.2') req.headers = self._make_header('2.2')
req.body = jsonutils.dump_as_bytes({'dummy': {'inv_val': 'foo'}}) req.body = jsonutils.dump_as_bytes({'dummy': {'inv_val': 'foo'}})
@ -223,7 +238,8 @@ class LegacyMicroversionsTest(test.NoDBTestCase):
mock_maxver): mock_maxver):
mock_maxver.return_value = api_version.APIVersionRequest("3.3") mock_maxver.return_value = api_version.APIVersionRequest("3.3")
req = fakes.HTTPRequest.blank('/v2/fake/microversions3/1') req = fakes.HTTPRequest.blank(
'/v2/%s/microversions3/1' % fakes.FAKE_PROJECT_ID)
req.headers = self._make_header('2.10') req.headers = self._make_header('2.10')
req.environ['CONTENT_TYPE'] = "application/json" req.environ['CONTENT_TYPE'] = "application/json"
req.method = 'PUT' req.method = 'PUT'
@ -242,7 +258,8 @@ class LegacyMicroversionsTest(test.NoDBTestCase):
def _test_microversions_inner_function(self, version, expected_resp, def _test_microversions_inner_function(self, version, expected_resp,
mock_maxver): mock_maxver):
mock_maxver.return_value = api_version.APIVersionRequest("2.2") mock_maxver.return_value = api_version.APIVersionRequest("2.2")
req = fakes.HTTPRequest.blank('/v2/fake/microversions4') req = fakes.HTTPRequest.blank(
'/v2/%s/microversions4' % fakes.FAKE_PROJECT_ID)
req.headers = self._make_header(version) req.headers = self._make_header(version)
req.environ['CONTENT_TYPE'] = "application/json" req.environ['CONTENT_TYPE'] = "application/json"
req.method = 'POST' req.method = 'POST'
@ -267,7 +284,8 @@ class LegacyMicroversionsTest(test.NoDBTestCase):
mock_maxver): mock_maxver):
mock_maxver.return_value = api_version.APIVersionRequest("2.3") mock_maxver.return_value = api_version.APIVersionRequest("2.3")
req = fakes.HTTPRequest.blank('/v2/fake/microversions3/1/action') req = fakes.HTTPRequest.blank(
'/v2/%s/microversions3/1/action' % fakes.FAKE_PROJECT_ID)
if req_header: if req_header:
req.headers = self._make_header(req_header) req.headers = self._make_header(req_header)
req.method = 'POST' req.method = 'POST'

View File

@ -143,12 +143,14 @@ class TestNeutronSecurityGroupsV21(
def test_get_security_group_list(self): def test_get_security_group_list(self):
self._create_sg_template().get('security_group') self._create_sg_template().get('security_group')
req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups') req = fakes.HTTPRequest.blank(
'/v2/%s/os-security-groups' % fakes.FAKE_PROJECT_ID)
list_dict = self.controller.index(req) list_dict = self.controller.index(req)
self.assertEqual(len(list_dict['security_groups']), 2) self.assertEqual(len(list_dict['security_groups']), 2)
def test_get_security_group_list_offset_and_limit(self): def test_get_security_group_list_offset_and_limit(self):
path = '/v2/fake/os-security-groups?offset=1&limit=1' path = ('/v2/%s/os-security-groups?offset=1&limit=1' %
fakes.FAKE_PROJECT_ID)
self._create_sg_template().get('security_group') self._create_sg_template().get('security_group')
req = fakes.HTTPRequest.blank(path) req = fakes.HTTPRequest.blank(path)
list_dict = self.controller.index(req) list_dict = self.controller.index(req)
@ -165,30 +167,34 @@ class TestNeutronSecurityGroupsV21(
device_id=test_security_groups.UUID_SERVER) device_id=test_security_groups.UUID_SERVER)
expected = [{'rules': [], 'tenant_id': 'fake', 'id': sg['id'], expected = [{'rules': [], 'tenant_id': 'fake', 'id': sg['id'],
'name': 'test', 'description': 'test-description'}] 'name': 'test', 'description': 'test-description'}]
req = fakes.HTTPRequest.blank('/v2/fake/servers/%s/os-security-groups' req = fakes.HTTPRequest.blank(
% test_security_groups.UUID_SERVER) '/v2/%s/servers/%s/os-security-groups'
% (fakes.FAKE_PROJECT_ID, test_security_groups.UUID_SERVER))
res_dict = self.server_controller.index( res_dict = self.server_controller.index(
req, test_security_groups.UUID_SERVER)['security_groups'] req, test_security_groups.UUID_SERVER)['security_groups']
self.assertEqual(expected, res_dict) self.assertEqual(expected, res_dict)
def test_get_security_group_by_id(self): def test_get_security_group_by_id(self):
sg = self._create_sg_template().get('security_group') sg = self._create_sg_template().get('security_group')
req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups/%s' req = fakes.HTTPRequest.blank(
% sg['id']) '/v2/%s/os-security-groups/%s'
% (fakes.FAKE_PROJECT_ID, sg['id']))
res_dict = self.controller.show(req, sg['id']) res_dict = self.controller.show(req, sg['id'])
expected = {'security_group': sg} expected = {'security_group': sg}
self.assertEqual(res_dict, expected) self.assertEqual(res_dict, expected)
def test_delete_security_group_by_id(self): def test_delete_security_group_by_id(self):
sg = self._create_sg_template().get('security_group') sg = self._create_sg_template().get('security_group')
req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups/%s' % req = fakes.HTTPRequest.blank(
sg['id']) '/v2/%s/os-security-groups/%s' %
(fakes.FAKE_PROJECT_ID, sg['id']))
self.controller.delete(req, sg['id']) self.controller.delete(req, sg['id'])
def test_delete_security_group_by_admin(self): def test_delete_security_group_by_admin(self):
sg = self._create_sg_template().get('security_group') sg = self._create_sg_template().get('security_group')
req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups/%s' % req = fakes.HTTPRequest.blank(
sg['id'], use_admin_context=True) '/v2/%s/os-security-groups/%s' %
(fakes.FAKE_PROJECT_ID, sg['id']), use_admin_context=True)
self.controller.delete(req, sg['id']) self.controller.delete(req, sg['id'])
@mock.patch('nova.compute.utils.refresh_info_cache_for_instance') @mock.patch('nova.compute.utils.refresh_info_cache_for_instance')
@ -206,8 +212,9 @@ class TestNeutronSecurityGroupsV21(
neutron.allocate_for_instance(_context, instance, False, None, neutron.allocate_for_instance(_context, instance, False, None,
security_groups=[sg['id']]) security_groups=[sg['id']])
req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups/%s' req = fakes.HTTPRequest.blank(
% sg['id']) '/v2/%s/os-security-groups/%s'
% (fakes.FAKE_PROJECT_ID, sg['id']))
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.delete, self.assertRaises(webob.exc.HTTPBadRequest, self.controller.delete,
req, sg['id']) req, sg['id'])
@ -232,8 +239,9 @@ class TestNeutronSecurityGroupsV21(
body = dict(addSecurityGroup=dict(name="test")) body = dict(addSecurityGroup=dict(name="test"))
req = fakes.HTTPRequest.blank('/v2/fake/servers/%s/action' % req = fakes.HTTPRequest.blank(
UUID_SERVER) '/v2/%s/servers/%s/action' %
(fakes.FAKE_PROJECT_ID, UUID_SERVER))
self.manager._addSecurityGroup(req, UUID_SERVER, body) self.manager._addSecurityGroup(req, UUID_SERVER, body)
def test_associate_duplicate_names(self): def test_associate_duplicate_names(self):
@ -248,8 +256,9 @@ class TestNeutronSecurityGroupsV21(
body = dict(addSecurityGroup=dict(name="sg1")) body = dict(addSecurityGroup=dict(name="sg1"))
req = fakes.HTTPRequest.blank('/v2/fake/servers/%s/action' % req = fakes.HTTPRequest.blank(
UUID_SERVER) '/v2/%s/servers/%s/action' %
(fakes.FAKE_PROJECT_ID, UUID_SERVER))
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
self.manager._addSecurityGroup, self.manager._addSecurityGroup,
req, UUID_SERVER, body) req, UUID_SERVER, body)
@ -264,8 +273,9 @@ class TestNeutronSecurityGroupsV21(
body = dict(addSecurityGroup=dict(name="test")) body = dict(addSecurityGroup=dict(name="test"))
req = fakes.HTTPRequest.blank('/v2/fake/servers/%s/action' % req = fakes.HTTPRequest.blank(
UUID_SERVER) '/v2/%s/servers/%s/action' %
(fakes.FAKE_PROJECT_ID, UUID_SERVER))
self.manager._addSecurityGroup(req, UUID_SERVER, body) self.manager._addSecurityGroup(req, UUID_SERVER, body)
def test_associate_port_security_enabled_false(self): def test_associate_port_security_enabled_false(self):
@ -277,8 +287,9 @@ class TestNeutronSecurityGroupsV21(
body = dict(addSecurityGroup=dict(name="test")) body = dict(addSecurityGroup=dict(name="test"))
req = fakes.HTTPRequest.blank('/v2/fake/servers/%s/action' % req = fakes.HTTPRequest.blank(
UUID_SERVER) '/v2/%s/servers/%s/action' %
(fakes.FAKE_PROJECT_ID, UUID_SERVER))
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.manager._addSecurityGroup, self.manager._addSecurityGroup,
req, UUID_SERVER, body) req, UUID_SERVER, body)
@ -293,15 +304,17 @@ class TestNeutronSecurityGroupsV21(
body = dict(addSecurityGroup=dict(name="test")) body = dict(addSecurityGroup=dict(name="test"))
req = fakes.HTTPRequest.blank('/v2/fake/servers/%s/action' % req = fakes.HTTPRequest.blank(
UUID_SERVER) '/v2/%s/servers/%s/action' %
(fakes.FAKE_PROJECT_ID, UUID_SERVER))
self.manager._addSecurityGroup(req, UUID_SERVER, body) self.manager._addSecurityGroup(req, UUID_SERVER, body)
def test_disassociate_by_non_existing_security_group_name(self): def test_disassociate_by_non_existing_security_group_name(self):
body = dict(removeSecurityGroup=dict(name='non-existing')) body = dict(removeSecurityGroup=dict(name='non-existing'))
req = fakes.HTTPRequest.blank('/v2/fake/servers/%s/action' % req = fakes.HTTPRequest.blank(
UUID_SERVER) '/v2/%s/servers/%s/action' %
(fakes.FAKE_PROJECT_ID, UUID_SERVER))
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.manager._removeSecurityGroup, self.manager._removeSecurityGroup,
req, UUID_SERVER, body) req, UUID_SERVER, body)
@ -327,8 +340,9 @@ class TestNeutronSecurityGroupsV21(
body = dict(removeSecurityGroup=dict(name="test")) body = dict(removeSecurityGroup=dict(name="test"))
req = fakes.HTTPRequest.blank('/v2/fake/servers/%s/action' % req = fakes.HTTPRequest.blank(
UUID_SERVER) '/v2/%s/servers/%s/action' %
(fakes.FAKE_PROJECT_ID, UUID_SERVER))
self.manager._removeSecurityGroup(req, UUID_SERVER, body) self.manager._removeSecurityGroup(req, UUID_SERVER, body)
def test_get_instances_security_groups_bindings(self): def test_get_instances_security_groups_bindings(self):
@ -439,22 +453,26 @@ class _TestNeutronSecurityGroupRulesBase(object):
def test_create_add_existing_rules_by_cidr(self): def test_create_add_existing_rules_by_cidr(self):
sg = test_security_groups.security_group_template() sg = test_security_groups.security_group_template()
req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups') req = fakes.HTTPRequest.blank(
'/v2/%s/os-security-groups' % fakes.FAKE_PROJECT_ID)
self.controller_sg.create(req, {'security_group': sg}) self.controller_sg.create(req, {'security_group': sg})
rule = test_security_groups.security_group_rule_template( rule = test_security_groups.security_group_rule_template(
cidr='15.0.0.0/8', parent_group_id=self.sg2['id']) cidr='15.0.0.0/8', parent_group_id=self.sg2['id'])
req = fakes.HTTPRequest.blank('/v2/fake/os-security-group-rules') req = fakes.HTTPRequest.blank(
'/v2/%s/os-security-group-rules' % fakes.FAKE_PROJECT_ID)
self.controller.create(req, {'security_group_rule': rule}) self.controller.create(req, {'security_group_rule': rule})
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create, self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create,
req, {'security_group_rule': rule}) req, {'security_group_rule': rule})
def test_create_add_existing_rules_by_group_id(self): def test_create_add_existing_rules_by_group_id(self):
sg = test_security_groups.security_group_template() sg = test_security_groups.security_group_template()
req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups') req = fakes.HTTPRequest.blank(
'/v2/%s/os-security-groups' % fakes.FAKE_PROJECT_ID)
self.controller_sg.create(req, {'security_group': sg}) self.controller_sg.create(req, {'security_group': sg})
rule = test_security_groups.security_group_rule_template( rule = test_security_groups.security_group_rule_template(
group=self.sg1['id'], parent_group_id=self.sg2['id']) group=self.sg1['id'], parent_group_id=self.sg2['id'])
req = fakes.HTTPRequest.blank('/v2/fake/os-security-group-rules') req = fakes.HTTPRequest.blank(
'/v2/%s/os-security-group-rules' % fakes.FAKE_PROJECT_ID)
self.controller.create(req, {'security_group_rule': rule}) self.controller.create(req, {'security_group_rule': rule})
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create, self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create,
req, {'security_group_rule': rule}) req, {'security_group_rule': rule})
@ -463,11 +481,12 @@ class _TestNeutronSecurityGroupRulesBase(object):
rule = test_security_groups.security_group_rule_template( rule = test_security_groups.security_group_rule_template(
parent_group_id=self.sg2['id']) parent_group_id=self.sg2['id'])
req = fakes.HTTPRequest.blank('/v2/fake/os-security-group-rules') req = fakes.HTTPRequest.blank(
'/v2/%s/os-security-group-rules' % fakes.FAKE_PROJECT_ID)
res_dict = self.controller.create(req, {'security_group_rule': rule}) res_dict = self.controller.create(req, {'security_group_rule': rule})
security_group_rule = res_dict['security_group_rule'] security_group_rule = res_dict['security_group_rule']
req = fakes.HTTPRequest.blank('/v2/fake/os-security-group-rules/%s' req = fakes.HTTPRequest.blank('/v2/%s/os-security-group-rules/%s' % (
% security_group_rule['id']) fakes.FAKE_PROJECT_ID, security_group_rule['id']))
self.controller.delete(req, security_group_rule['id']) self.controller.delete(req, security_group_rule['id'])
def test_create_rule_quota_limit(self): def test_create_rule_quota_limit(self):
@ -549,9 +568,10 @@ class TestNeutronSecurityGroupsOutputTest(TestNeutronSecurityGroupsTestCase):
return server.get('security_groups') return server.get('security_groups')
def test_create(self): def test_create(self):
url = '/v2/fake/servers' url = '/v2/%s/servers' % fakes.FAKE_PROJECT_ID
image_uuid = 'c905cedb-7281-47e4-8a62-f26bc5fc4c77' image_uuid = 'c905cedb-7281-47e4-8a62-f26bc5fc4c77'
req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups') req = fakes.HTTPRequest.blank(
'/v2/%s/os-security-groups' % fakes.FAKE_PROJECT_ID)
security_groups = [{'name': 'fake-2-0'}, {'name': 'fake-2-1'}] security_groups = [{'name': 'fake-2-0'}, {'name': 'fake-2-1'}]
for security_group in security_groups: for security_group in security_groups:
sg = test_security_groups.security_group_template( sg = test_security_groups.security_group_template(
@ -568,7 +588,7 @@ class TestNeutronSecurityGroupsOutputTest(TestNeutronSecurityGroupsTestCase):
self.assertEqual(group.get('name'), name) self.assertEqual(group.get('name'), name)
def test_create_server_get_default_security_group(self): def test_create_server_get_default_security_group(self):
url = '/v2/fake/servers' url = '/v2/%s/servers' % fakes.FAKE_PROJECT_ID
image_uuid = 'c905cedb-7281-47e4-8a62-f26bc5fc4c77' image_uuid = 'c905cedb-7281-47e4-8a62-f26bc5fc4c77'
server = dict(name='server_test', imageRef=image_uuid, flavorRef=2) server = dict(name='server_test', imageRef=image_uuid, flavorRef=2)
res = self._make_request(url, {'server': server}) res = self._make_request(url, {'server': server})
@ -583,9 +603,10 @@ class TestNeutronSecurityGroupsOutputTest(TestNeutronSecurityGroupsTestCase):
lambda self, inst, context, id: lambda self, inst, context, id:
[{'name': 'fake-2-0'}, {'name': 'fake-2-1'}]) [{'name': 'fake-2-0'}, {'name': 'fake-2-1'}])
url = '/v2/fake/servers' url = '/v2/%s/servers' % fakes.FAKE_PROJECT_ID
image_uuid = 'c905cedb-7281-47e4-8a62-f26bc5fc4c77' image_uuid = 'c905cedb-7281-47e4-8a62-f26bc5fc4c77'
req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups') req = fakes.HTTPRequest.blank(
'/v2/%s/os-security-groups' % fakes.FAKE_PROJECT_ID)
security_groups = [{'name': 'fake-2-0'}, {'name': 'fake-2-1'}] security_groups = [{'name': 'fake-2-0'}, {'name': 'fake-2-1'}]
for security_group in security_groups: for security_group in security_groups:
sg = test_security_groups.security_group_template( sg = test_security_groups.security_group_template(
@ -602,7 +623,8 @@ class TestNeutronSecurityGroupsOutputTest(TestNeutronSecurityGroupsTestCase):
self.assertEqual(group.get('name'), name) self.assertEqual(group.get('name'), name)
# Test that show (GET) returns the same information as create (POST) # Test that show (GET) returns the same information as create (POST)
url = '/v2/fake/servers/' + test_security_groups.UUID3 url = ('/v2/%s/servers/%s' % (fakes.FAKE_PROJECT_ID,
test_security_groups.UUID3))
res = self._make_request(url) res = self._make_request(url)
self.assertEqual(res.status_int, 200) self.assertEqual(res.status_int, 200)
server = self._get_server(res.body) server = self._get_server(res.body)
@ -612,7 +634,7 @@ class TestNeutronSecurityGroupsOutputTest(TestNeutronSecurityGroupsTestCase):
self.assertEqual(group.get('name'), name) self.assertEqual(group.get('name'), name)
def test_detail(self): def test_detail(self):
url = '/v2/fake/servers/detail' url = '/v2/%s/servers/detail' % fakes.FAKE_PROJECT_ID
res = self._make_request(url) res = self._make_request(url)
self.assertEqual(res.status_int, 200) self.assertEqual(res.status_int, 200)
@ -624,7 +646,8 @@ class TestNeutronSecurityGroupsOutputTest(TestNeutronSecurityGroupsTestCase):
@mock.patch('nova.compute.api.API.get', @mock.patch('nova.compute.api.API.get',
side_effect=exception.InstanceNotFound(instance_id='fake')) side_effect=exception.InstanceNotFound(instance_id='fake'))
def test_no_instance_passthrough_404(self, mock_get): def test_no_instance_passthrough_404(self, mock_get):
url = '/v2/fake/servers/70f6db34-de8d-4fbd-aafb-4065bdfa6115' url = ('/v2/%s/servers/70f6db34-de8d-4fbd-aafb-4065bdfa6115' %
fakes.FAKE_PROJECT_ID)
res = self._make_request(url) res = self._make_request(url)
self.assertEqual(res.status_int, 404) self.assertEqual(res.status_int, 404)

View File

@ -311,7 +311,7 @@ class TestSecurityGroupsV21(test.TestCase):
self.stub_out('nova.db.api.security_group_get_by_project', self.stub_out('nova.db.api.security_group_get_by_project',
return_security_groups) return_security_groups)
path = '/v2/fake/os-security-groups' path = '/v2/%s/os-security-groups' % fakes.FAKE_PROJECT_ID
if limited: if limited:
path += '?offset=1&limit=1' path += '?offset=1&limit=1'
req = fakes.HTTPRequest.blank(path, use_admin_context=True) req = fakes.HTTPRequest.blank(path, use_admin_context=True)
@ -359,7 +359,8 @@ class TestSecurityGroupsV21(test.TestCase):
self.assertEqual(res_dict, expected) self.assertEqual(res_dict, expected)
mock_list.assert_called_once_with(self.req.environ['nova.context'], mock_list.assert_called_once_with(self.req.environ['nova.context'],
project='fake', search_opts={}) project=fakes.FAKE_PROJECT_ID,
search_opts={})
def test_get_security_group_list_all_tenants(self): def test_get_security_group_list_all_tenants(self):
all_groups = [] all_groups = []
@ -389,7 +390,7 @@ class TestSecurityGroupsV21(test.TestCase):
self.stub_out('nova.db.api.security_group_get_by_project', self.stub_out('nova.db.api.security_group_get_by_project',
return_tenant_security_groups) return_tenant_security_groups)
path = '/v2/fake/os-security-groups' path = '/v2/%s/os-security-groups' % fakes.FAKE_PROJECT_ID
req = fakes.HTTPRequest.blank(path, use_admin_context=True) req = fakes.HTTPRequest.blank(path, use_admin_context=True)
res_dict = self.controller.index(req) res_dict = self.controller.index(req)
@ -1350,7 +1351,7 @@ def fake_compute_create(*args, **kwargs):
class SecurityGroupsOutputTestV21(test.TestCase): class SecurityGroupsOutputTestV21(test.TestCase):
base_url = '/v2/fake/servers' base_url = '/v2/%s/servers' % fakes.FAKE_PROJECT_ID
content_type = 'application/json' content_type = 'application/json'
def setUp(self): def setUp(self):

View File

@ -45,7 +45,7 @@ class ServerDiagnosticsTestV21(test.NoDBTestCase):
def _get_request(self): def _get_request(self):
return fakes.HTTPRequest.blank( return fakes.HTTPRequest.blank(
'/v2/fake/servers/%s/diagnostics' % UUID, '/v2/%s/servers/%s/diagnostics' % (fakes.FAKE_PROJECT_ID, UUID),
version=self.api_version, version=self.api_version,
headers = {os_wsgi.API_VERSION_REQUEST_HEADER: headers = {os_wsgi.API_VERSION_REQUEST_HEADER:
'compute %s' % self.api_version}) 'compute %s' % self.api_version})

View File

@ -191,7 +191,8 @@ class ServerGroupTestV21(test.NoDBTestCase):
instance = objects.Instance(context=cctx, instance = objects.Instance(context=cctx,
image_ref=uuidsentinel.fake_image_ref, image_ref=uuidsentinel.fake_image_ref,
node='node1', reservation_id='a', node='node1', reservation_id='a',
host='host1', project_id='fake', host='host1',
project_id=fakes.FAKE_PROJECT_ID,
vm_state='fake', vm_state='fake',
system_metadata={'key': 'value'}) system_metadata={'key': 'value'})
instance.create() instance.create()
@ -205,7 +206,7 @@ class ServerGroupTestV21(test.NoDBTestCase):
def _create_instance_group(self, context, members): def _create_instance_group(self, context, members):
ig = objects.InstanceGroup(context=context, name='fake_name', ig = objects.InstanceGroup(context=context, name='fake_name',
user_id='fake_user', project_id='fake', user_id='fake_user', project_id=fakes.FAKE_PROJECT_ID,
members=members) members=members)
ig.create() ig.create()
return ig.uuid return ig.uuid
@ -373,7 +374,7 @@ class ServerGroupTestV21(test.NoDBTestCase):
self.assertEqual(expected, res_dict) self.assertEqual(expected, res_dict)
def test_display_members(self): def test_display_members(self):
ctx = context.RequestContext('fake_user', 'fake') ctx = context.RequestContext('fake_user', fakes.FAKE_PROJECT_ID)
(ig_uuid, instances, members) = self._create_groups_and_instances(ctx) (ig_uuid, instances, members) = self._create_groups_and_instances(ctx)
res_dict = self.controller.show(self.req, ig_uuid) res_dict = self.controller.show(self.req, ig_uuid)
result_members = res_dict['server_group']['members'] result_members = res_dict['server_group']['members']
@ -386,7 +387,7 @@ class ServerGroupTestV21(test.NoDBTestCase):
self.controller.show, self.req, uuidsentinel.group) self.controller.show, self.req, uuidsentinel.group)
def test_display_active_members_only(self): def test_display_active_members_only(self):
ctx = context.RequestContext('fake_user', 'fake') ctx = context.RequestContext('fake_user', fakes.FAKE_PROJECT_ID)
(ig_uuid, instances, members) = self._create_groups_and_instances(ctx) (ig_uuid, instances, members) = self._create_groups_and_instances(ctx)
# delete an instance # delete an instance
@ -407,7 +408,7 @@ class ServerGroupTestV21(test.NoDBTestCase):
self.assertIn(instances[0].uuid, result_members) self.assertIn(instances[0].uuid, result_members)
def test_display_members_rbac_default(self): def test_display_members_rbac_default(self):
ctx = context.RequestContext('fake_user', 'fake') ctx = context.RequestContext('fake_user', fakes.FAKE_PROJECT_ID)
ig_uuid = self._create_groups_and_instances(ctx)[0] ig_uuid = self._create_groups_and_instances(ctx)[0]
# test as admin # test as admin
@ -421,7 +422,7 @@ class ServerGroupTestV21(test.NoDBTestCase):
self.controller.show, self.foo_req, ig_uuid) self.controller.show, self.foo_req, ig_uuid)
def test_display_members_rbac_admin_only(self): def test_display_members_rbac_admin_only(self):
ctx = context.RequestContext('fake_user', 'fake') ctx = context.RequestContext('fake_user', fakes.FAKE_PROJECT_ID)
ig_uuid = self._create_groups_and_instances(ctx)[0] ig_uuid = self._create_groups_and_instances(ctx)[0]
# override policy to restrict to admin # override policy to restrict to admin
@ -670,7 +671,7 @@ class ServerGroupTestV21(test.NoDBTestCase):
self.req, 'invalid') self.req, 'invalid')
def test_delete_server_group_rbac_default(self): def test_delete_server_group_rbac_default(self):
ctx = context.RequestContext('fake_user', 'fake') ctx = context.RequestContext('fake_user', fakes.FAKE_PROJECT_ID)
# test as admin # test as admin
ig_uuid = self._create_groups_and_instances(ctx)[0] ig_uuid = self._create_groups_and_instances(ctx)[0]

View File

@ -37,7 +37,8 @@ class ServerStartStopTestV21(test.TestCase):
self.req = fakes.HTTPRequest.blank('') self.req = fakes.HTTPRequest.blank('')
self.useFixture(nova_fixtures.SingleCellSimple()) self.useFixture(nova_fixtures.SingleCellSimple())
self.stub_out('nova.db.api.instance_get_by_uuid', self.stub_out('nova.db.api.instance_get_by_uuid',
fakes.fake_instance_get()) fakes.fake_instance_get(
project_id=fakes.FAKE_PROJECT_ID))
def _setup_controller(self): def _setup_controller(self):
self.controller = server_v21.ServersController() self.controller = server_v21.ServersController()

View File

@ -71,7 +71,8 @@ class ServerTagsTest(test.TestCase):
def test_show(self, mock_exists): def test_show(self, mock_exists):
mock_exists.return_value = True mock_exists.return_value = True
req = self._get_request( req = self._get_request(
'/v2/fake/servers/%s/tags/%s' % (UUID, TAG1), 'GET') '/v2/%s/servers/%s/tags/%s' % (
fakes.FAKE_PROJECT_ID, UUID, TAG1), 'GET')
self.controller.show(req, UUID, TAG1) self.controller.show(req, UUID, TAG1)
mock_exists.assert_called_once_with(mock.ANY, UUID, TAG1) mock_exists.assert_called_once_with(mock.ANY, UUID, TAG1)
@ -81,7 +82,8 @@ class ServerTagsTest(test.TestCase):
fake_tags = [self._get_tag(tag) for tag in TAGS] fake_tags = [self._get_tag(tag) for tag in TAGS]
mock_db_get_inst_tags.return_value = fake_tags mock_db_get_inst_tags.return_value = fake_tags
req = self._get_request('/v2/fake/servers/%s/tags' % UUID, 'GET') req = self._get_request('/v2/%s/servers/%s/tags' % (
fakes.FAKE_PROJECT_ID, UUID), 'GET')
res = self.controller.index(req, UUID) res = self.controller.index(req, UUID)
self.assertEqual(TAGS, res.get('tags')) self.assertEqual(TAGS, res.get('tags'))
@ -94,7 +96,7 @@ class ServerTagsTest(test.TestCase):
fake_tags = [self._get_tag(tag) for tag in TAGS] fake_tags = [self._get_tag(tag) for tag in TAGS]
mock_db_set_inst_tags.return_value = fake_tags mock_db_set_inst_tags.return_value = fake_tags
req = self._get_request( req = self._get_request(
'/v2/fake/servers/%s/tags' % UUID, 'PUT') '/v2/%s/servers/%s/tags' % (fakes.FAKE_PROJECT_ID, UUID), 'PUT')
res = self.controller.update_all(req, UUID, body={'tags': TAGS}) res = self.controller.update_all(req, UUID, body={'tags': TAGS})
self.assertEqual(TAGS, res['tags']) self.assertEqual(TAGS, res['tags'])
@ -107,41 +109,46 @@ class ServerTagsTest(test.TestCase):
instance.MAX_TAG_COUNT + 1)]} instance.MAX_TAG_COUNT + 1)]}
req = self._get_request( req = self._get_request(
'/v2/fake/servers/%s/tags' % UUID, 'PUT') '/v2/%s/servers/%s/tags' % (fakes.FAKE_PROJECT_ID, UUID), 'PUT')
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller.update_all, self.controller.update_all,
req, UUID, body=fake_tags) req, UUID, body=fake_tags)
def test_update_all_forbidden_characters(self): def test_update_all_forbidden_characters(self):
self.stub_out('nova.api.openstack.common.get_instance', return_server) self.stub_out('nova.api.openstack.common.get_instance', return_server)
req = self._get_request('/v2/fake/servers/%s/tags' % UUID, 'PUT') req = self._get_request('/v2/%s/servers/%s/tags' % (
fakes.FAKE_PROJECT_ID, UUID), 'PUT')
for tag in ['tag,1', 'tag/1']: for tag in ['tag,1', 'tag/1']:
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller.update_all, self.controller.update_all,
req, UUID, body={'tags': [tag, 'tag2']}) req, UUID, body={'tags': [tag, 'tag2']})
def test_update_all_invalid_tag_type(self): def test_update_all_invalid_tag_type(self):
req = self._get_request('/v2/fake/servers/%s/tags' % UUID, 'PUT') req = self._get_request('/v2/%s/servers/%s/tags' % (
fakes.FAKE_PROJECT_ID, UUID), 'PUT')
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller.update_all, self.controller.update_all,
req, UUID, body={'tags': [1]}) req, UUID, body={'tags': [1]})
def test_update_all_tags_with_one_tag_empty_string(self): def test_update_all_tags_with_one_tag_empty_string(self):
req = self._get_request('/v2/fake/servers/%s/tags' % UUID, 'PUT') req = self._get_request('/v2/%s/servers/%s/tags' % (
fakes.FAKE_PROJECT_ID, UUID), 'PUT')
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller.update_all, self.controller.update_all,
req, UUID, body={'tags': ['tag1', '']}) req, UUID, body={'tags': ['tag1', '']})
def test_update_all_too_long_tag(self): def test_update_all_too_long_tag(self):
self.stub_out('nova.api.openstack.common.get_instance', return_server) self.stub_out('nova.api.openstack.common.get_instance', return_server)
req = self._get_request('/v2/fake/servers/%s/tags' % UUID, 'PUT') req = self._get_request('/v2/%s/servers/%s/tags' % (
fakes.FAKE_PROJECT_ID, UUID), 'PUT')
tag = "a" * (tag_obj.MAX_TAG_LENGTH + 1) tag = "a" * (tag_obj.MAX_TAG_LENGTH + 1)
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller.update_all, self.controller.update_all,
req, UUID, body={'tags': [tag]}) req, UUID, body={'tags': [tag]})
def test_update_all_invalid_tag_list_type(self): def test_update_all_invalid_tag_list_type(self):
req = self._get_request('/v2/ake/servers/%s/tags' % UUID, 'PUT') req = self._get_request('/v2/%s/servers/%s/tags' % (
fakes.FAKE_PROJECT_ID, UUID), 'PUT')
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller.update_all, self.controller.update_all,
req, UUID, body={'tags': {'tag': 'tag'}}) req, UUID, body={'tags': {'tag': 'tag'}})
@ -149,7 +156,8 @@ class ServerTagsTest(test.TestCase):
def test_update_all_invalid_instance_state(self): def test_update_all_invalid_instance_state(self):
self.stub_out('nova.api.openstack.common.get_instance', self.stub_out('nova.api.openstack.common.get_instance',
return_invalid_server) return_invalid_server)
req = self._get_request('/v2/fake/servers/%s/tags' % UUID, 'PUT') req = self._get_request('/v2/%s/servers/%s/tags' % (
fakes.FAKE_PROJECT_ID, UUID), 'PUT')
self.assertRaises(exc.HTTPConflict, self.controller.update_all, self.assertRaises(exc.HTTPConflict, self.controller.update_all,
req, UUID, body={'tags': TAGS}) req, UUID, body={'tags': TAGS})
@ -157,7 +165,8 @@ class ServerTagsTest(test.TestCase):
def test_show_non_existing_tag(self, mock_exists): def test_show_non_existing_tag(self, mock_exists):
mock_exists.return_value = False mock_exists.return_value = False
req = self._get_request( req = self._get_request(
'/v2/fake/servers/%s/tags/%s' % (UUID, TAG1), 'GET') '/v2/%s/servers/%s/tags/%s' % (
fakes.FAKE_PROJECT_ID, UUID, TAG1), 'GET')
self.assertRaises(exc.HTTPNotFound, self.controller.show, self.assertRaises(exc.HTTPNotFound, self.controller.show,
req, UUID, TAG1) req, UUID, TAG1)
@ -170,7 +179,7 @@ class ServerTagsTest(test.TestCase):
mock_db_get_inst_tags.return_value = [self._get_tag(TAG1)] mock_db_get_inst_tags.return_value = [self._get_tag(TAG1)]
mock_db_add_inst_tags.return_value = self._get_tag(TAG2) mock_db_add_inst_tags.return_value = self._get_tag(TAG2)
url = '/v2/fake/servers/%s/tags/%s' % (UUID, TAG2) url = '/v2/%s/servers/%s/tags/%s' % (fakes.FAKE_PROJECT_ID, UUID, TAG2)
location = 'http://localhost' + url location = 'http://localhost' + url
req = self._get_request(url, 'PUT') req = self._get_request(url, 'PUT')
res = self.controller.update(req, UUID, TAG2, body=None) res = self.controller.update(req, UUID, TAG2, body=None)
@ -188,7 +197,8 @@ class ServerTagsTest(test.TestCase):
mock_db_get_inst_tags.return_value = [self._get_tag(TAG1)] mock_db_get_inst_tags.return_value = [self._get_tag(TAG1)]
req = self._get_request( req = self._get_request(
'/v2/fake/servers/%s/tags/%s' % (UUID, TAG1), 'PUT') '/v2/%s/servers/%s/tags/%s' % (
fakes.FAKE_PROJECT_ID, UUID, TAG1), 'PUT')
res = self.controller.update(req, UUID, TAG1, body=None) res = self.controller.update(req, UUID, TAG1, body=None)
self.assertEqual(204, res.status_int) self.assertEqual(204, res.status_int)
@ -203,7 +213,8 @@ class ServerTagsTest(test.TestCase):
mock_db_get_inst_tags.return_value = fake_tags mock_db_get_inst_tags.return_value = fake_tags
req = self._get_request( req = self._get_request(
'/v2/fake/servers/%s/tags/%s' % (UUID, TAG2), 'PUT') '/v2/%s/servers/%s/tags/%s' % (
fakes.FAKE_PROJECT_ID, UUID, TAG2), 'PUT')
self.assertRaises(exc.HTTPBadRequest, self.controller.update, self.assertRaises(exc.HTTPBadRequest, self.controller.update,
req, UUID, TAG2, body=None) req, UUID, TAG2, body=None)
@ -214,7 +225,8 @@ class ServerTagsTest(test.TestCase):
tag = "a" * (tag_obj.MAX_TAG_LENGTH + 1) tag = "a" * (tag_obj.MAX_TAG_LENGTH + 1)
req = self._get_request( req = self._get_request(
'/v2/fake/servers/%s/tags/%s' % (UUID, tag), 'PUT') '/v2/%s/servers/%s/tags/%s' % (
fakes.FAKE_PROJECT_ID, UUID, tag), 'PUT')
self.assertRaises(exc.HTTPBadRequest, self.controller.update, self.assertRaises(exc.HTTPBadRequest, self.controller.update,
req, UUID, tag, body=None) req, UUID, tag, body=None)
@ -224,7 +236,8 @@ class ServerTagsTest(test.TestCase):
mock_db_get_inst_tags.return_value = [] mock_db_get_inst_tags.return_value = []
for tag in ['tag,1', 'tag/1']: for tag in ['tag,1', 'tag/1']:
req = self._get_request( req = self._get_request(
'/v2/fake/servers/%s/tags/%s' % (UUID, tag), 'PUT') '/v2/%s/servers/%s/tags/%s' % (
fakes.FAKE_PROJECT_ID, UUID, tag), 'PUT')
self.assertRaises(exc.HTTPBadRequest, self.controller.update, self.assertRaises(exc.HTTPBadRequest, self.controller.update,
req, UUID, tag, body=None) req, UUID, tag, body=None)
@ -232,7 +245,8 @@ class ServerTagsTest(test.TestCase):
self.stub_out('nova.api.openstack.common.get_instance', self.stub_out('nova.api.openstack.common.get_instance',
return_invalid_server) return_invalid_server)
req = self._get_request( req = self._get_request(
'/v2/fake/servers/%s/tags/%s' % (UUID, TAG1), 'PUT') '/v2/%s/servers/%s/tags/%s' % (
fakes.FAKE_PROJECT_ID, UUID, TAG1), 'PUT')
self.assertRaises(exc.HTTPConflict, self.controller.update, req, UUID, self.assertRaises(exc.HTTPConflict, self.controller.update, req, UUID,
TAG1, body=None) TAG1, body=None)
@ -243,7 +257,8 @@ class ServerTagsTest(test.TestCase):
mock_db_get_inst_tags): mock_db_get_inst_tags):
self.stub_out('nova.api.openstack.common.get_instance', return_server) self.stub_out('nova.api.openstack.common.get_instance', return_server)
req = self._get_request( req = self._get_request(
'/v2/fake/servers/%s/tags/%s' % (UUID, TAG2), 'DELETE') '/v2/%s/servers/%s/tags/%s' % (
fakes.FAKE_PROJECT_ID, UUID, TAG2), 'DELETE')
self.controller.delete(req, UUID, TAG2) self.controller.delete(req, UUID, TAG2)
mock_db_delete_inst_tags.assert_called_once_with(mock.ANY, UUID, TAG2) mock_db_delete_inst_tags.assert_called_once_with(mock.ANY, UUID, TAG2)
mock_db_get_inst_tags.assert_called_once_with(mock.ANY, UUID) mock_db_get_inst_tags.assert_called_once_with(mock.ANY, UUID)
@ -260,7 +275,8 @@ class ServerTagsTest(test.TestCase):
tag=tag) tag=tag)
mock_db_delete_inst_tags.side_effect = fake_db_delete_tag mock_db_delete_inst_tags.side_effect = fake_db_delete_tag
req = self._get_request( req = self._get_request(
'/v2/fake/servers/%s/tags/%s' % (UUID, TAG1), 'DELETE') '/v2/%s/servers/%s/tags/%s' % (
fakes.FAKE_PROJECT_ID, UUID, TAG1), 'DELETE')
self.assertRaises(exc.HTTPNotFound, self.controller.delete, self.assertRaises(exc.HTTPNotFound, self.controller.delete,
req, UUID, TAG1) req, UUID, TAG1)
@ -268,7 +284,8 @@ class ServerTagsTest(test.TestCase):
self.stub_out('nova.api.openstack.common.get_instance', self.stub_out('nova.api.openstack.common.get_instance',
return_invalid_server) return_invalid_server)
req = self._get_request( req = self._get_request(
'/v2/fake/servers/%s/tags/%s' % (UUID, TAG2), 'DELETE') '/v2/%s/servers/%s/tags/%s' % (
fakes.FAKE_PROJECT_ID, UUID, TAG2), 'DELETE')
self.assertRaises(exc.HTTPConflict, self.controller.delete, req, UUID, self.assertRaises(exc.HTTPConflict, self.controller.delete, req, UUID,
TAG1) TAG1)
@ -276,7 +293,8 @@ class ServerTagsTest(test.TestCase):
@mock.patch('nova.db.api.instance_tag_delete_all') @mock.patch('nova.db.api.instance_tag_delete_all')
def test_delete_all(self, mock_db_delete_inst_tags, mock_notify): def test_delete_all(self, mock_db_delete_inst_tags, mock_notify):
self.stub_out('nova.api.openstack.common.get_instance', return_server) self.stub_out('nova.api.openstack.common.get_instance', return_server)
req = self._get_request('/v2/fake/servers/%s/tags' % UUID, 'DELETE') req = self._get_request('/v2/%s/servers/%s/tags' % (
fakes.FAKE_PROJECT_ID, UUID), 'DELETE')
self.controller.delete_all(req, UUID) self.controller.delete_all(req, UUID)
mock_db_delete_inst_tags.assert_called_once_with(mock.ANY, UUID) mock_db_delete_inst_tags.assert_called_once_with(mock.ANY, UUID)
self.assertEqual(1, mock_notify.call_count) self.assertEqual(1, mock_notify.call_count)
@ -284,50 +302,57 @@ class ServerTagsTest(test.TestCase):
def test_delete_all_invalid_instance_state(self): def test_delete_all_invalid_instance_state(self):
self.stub_out('nova.api.openstack.common.get_instance', self.stub_out('nova.api.openstack.common.get_instance',
return_invalid_server) return_invalid_server)
req = self._get_request('/v2/fake/servers/%s/tags' % UUID, 'DELETE') req = self._get_request('/v2/%s/servers/%s/tags' % (
fakes.FAKE_PROJECT_ID, UUID), 'DELETE')
self.assertRaises(exc.HTTPConflict, self.controller.delete_all, req, self.assertRaises(exc.HTTPConflict, self.controller.delete_all, req,
UUID) UUID)
def test_show_non_existing_instance(self): def test_show_non_existing_instance(self):
req = self._get_request( req = self._get_request(
'/v2/fake/servers/%s/tags/%s' % (NON_EXISTING_UUID, TAG1), 'GET') '/v2/%s/servers/%s/tags/%s' % (
fakes.FAKE_PROJECT_ID, NON_EXISTING_UUID, TAG1), 'GET')
self.assertRaises(exc.HTTPNotFound, self.controller.show, req, self.assertRaises(exc.HTTPNotFound, self.controller.show, req,
NON_EXISTING_UUID, TAG1) NON_EXISTING_UUID, TAG1)
def test_show_with_details_information_non_existing_instance(self): def test_show_with_details_information_non_existing_instance(self):
req = self._get_request( req = self._get_request(
'/v2/fake/servers/%s' % NON_EXISTING_UUID, 'GET') '/v2/%s/servers/%s' % (
fakes.FAKE_PROJECT_ID, NON_EXISTING_UUID), 'GET')
servers_controller = servers.ServersController() servers_controller = servers.ServersController()
self.assertRaises(exc.HTTPNotFound, servers_controller.show, req, self.assertRaises(exc.HTTPNotFound, servers_controller.show, req,
NON_EXISTING_UUID) NON_EXISTING_UUID)
def test_index_non_existing_instance(self): def test_index_non_existing_instance(self):
req = self._get_request( req = self._get_request(
'v2/fake/servers/%s/tags' % NON_EXISTING_UUID, 'GET') 'v2/%s/servers/%s/tags' % (
fakes.FAKE_PROJECT_ID, NON_EXISTING_UUID), 'GET')
self.assertRaises(exc.HTTPNotFound, self.controller.index, req, self.assertRaises(exc.HTTPNotFound, self.controller.index, req,
NON_EXISTING_UUID) NON_EXISTING_UUID)
def test_update_non_existing_instance(self): def test_update_non_existing_instance(self):
req = self._get_request( req = self._get_request(
'/v2/fake/servers/%s/tags/%s' % (NON_EXISTING_UUID, TAG1), 'PUT') '/v2/%s/servers/%s/tags/%s' % (
fakes.FAKE_PROJECT_ID, NON_EXISTING_UUID, TAG1), 'PUT')
self.assertRaises(exc.HTTPNotFound, self.controller.update, req, self.assertRaises(exc.HTTPNotFound, self.controller.update, req,
NON_EXISTING_UUID, TAG1, body=None) NON_EXISTING_UUID, TAG1, body=None)
def test_update_all_non_existing_instance(self): def test_update_all_non_existing_instance(self):
req = self._get_request( req = self._get_request(
'/v2/fake/servers/%s/tags' % NON_EXISTING_UUID, 'PUT') '/v2/%s/servers/%s/tags' % (
fakes.FAKE_PROJECT_ID, NON_EXISTING_UUID), 'PUT')
self.assertRaises(exc.HTTPNotFound, self.controller.update_all, req, self.assertRaises(exc.HTTPNotFound, self.controller.update_all, req,
NON_EXISTING_UUID, body={'tags': TAGS}) NON_EXISTING_UUID, body={'tags': TAGS})
def test_delete_non_existing_instance(self): def test_delete_non_existing_instance(self):
req = self._get_request( req = self._get_request(
'/v2/fake/servers/%s/tags/%s' % (NON_EXISTING_UUID, TAG1), '/v2/%s/servers/%s/tags/%s' % (
'DELETE') fakes.FAKE_PROJECT_ID, NON_EXISTING_UUID, TAG1), 'DELETE')
self.assertRaises(exc.HTTPNotFound, self.controller.delete, req, self.assertRaises(exc.HTTPNotFound, self.controller.delete, req,
NON_EXISTING_UUID, TAG1) NON_EXISTING_UUID, TAG1)
def test_delete_all_non_existing_instance(self): def test_delete_all_non_existing_instance(self):
req = self._get_request( req = self._get_request(
'/v2/fake/servers/%s/tags' % NON_EXISTING_UUID, 'DELETE') '/v2/%s/servers/%s/tags' % (
fakes.FAKE_PROJECT_ID, NON_EXISTING_UUID), 'DELETE')
self.assertRaises(exc.HTTPNotFound, self.controller.delete_all, self.assertRaises(exc.HTTPNotFound, self.controller.delete_all,
req, NON_EXISTING_UUID) req, NON_EXISTING_UUID)

File diff suppressed because it is too large Load Diff

View File

@ -62,7 +62,8 @@ class UrlmapTest(test.NoDBTestCase):
def test_accept_content_type(self): def test_accept_content_type(self):
# Test Accept header specifying JSON returns JSON content. # Test Accept header specifying JSON returns JSON content.
url = '/v2/fake/images/cedef40a-ed67-4d10-800e-17455edce175' url = ('/v2/%s/images/cedef40a-ed67-4d10-800e-17455edce175' %
fakes.FAKE_PROJECT_ID)
req = fakes.HTTPRequest.blank(url) req = fakes.HTTPRequest.blank(url)
req.accept = "application/xml;q=0.8, application/json" req.accept = "application/xml;q=0.8, application/json"
res = req.get_response(fakes.wsgi_app_v21()) res = req.get_response(fakes.wsgi_app_v21())

View File

@ -467,7 +467,9 @@ class VersionsTestV21(test.NoDBTestCase):
self.assertEqual(expected, version) self.assertEqual(expected, version)
def test_get_version_21_versions_v21_detail(self): def test_get_version_21_versions_v21_detail(self):
req = fakes.HTTPRequest.blank('/v2.1/fake/versions/v2.1', base_url='') req = fakes.HTTPRequest.blank(
'/v2.1/%s/versions/v2.1' % fakes.FAKE_PROJECT_ID,
base_url='')
req.accept = "application/json" req.accept = "application/json"
res = req.get_response(self.wsgi_app) res = req.get_response(self.wsgi_app)
self.assertEqual(200, res.status_int) self.assertEqual(200, res.status_int)
@ -477,7 +479,9 @@ class VersionsTestV21(test.NoDBTestCase):
self.assertEqual(expected, version) self.assertEqual(expected, version)
def test_get_version_21_versions_v20_detail(self): def test_get_version_21_versions_v20_detail(self):
req = fakes.HTTPRequest.blank('/v2.1/fake/versions/v2.0', base_url='') req = fakes.HTTPRequest.blank(
'/v2.1/%s/versions/v2.0' % fakes.FAKE_PROJECT_ID,
base_url='')
req.accept = "application/json" req.accept = "application/json"
res = req.get_response(self.wsgi_app) res = req.get_response(self.wsgi_app)
self.assertEqual(200, res.status_int) self.assertEqual(200, res.status_int)

View File

@ -159,7 +159,8 @@ class BootFromVolumeTest(test.TestCase):
delete_on_termination=False, delete_on_termination=False,
)] )]
)) ))
req = fakes.HTTPRequest.blank('/v2/fake/os-volumes_boot') req = fakes.HTTPRequest.blank('/v2/%s/os-volumes_boot' %
fakes.FAKE_PROJECT_ID)
req.method = 'POST' req.method = 'POST'
req.body = jsonutils.dump_as_bytes(body) req.body = jsonutils.dump_as_bytes(body)
req.headers['content-type'] = 'application/json' req.headers['content-type'] = 'application/json'
@ -187,7 +188,8 @@ class BootFromVolumeTest(test.TestCase):
delete_on_termination=False, delete_on_termination=False,
)] )]
)) ))
req = fakes.HTTPRequest.blank('/v2/fake/os-volumes_boot') req = fakes.HTTPRequest.blank('/v2/%s/os-volumes_boot' %
fakes.FAKE_PROJECT_ID)
req.method = 'POST' req.method = 'POST'
req.body = jsonutils.dump_as_bytes(body) req.body = jsonutils.dump_as_bytes(body)
req.headers['content-type'] = 'application/json' req.headers['content-type'] = 'application/json'
@ -205,7 +207,7 @@ class BootFromVolumeTest(test.TestCase):
class VolumeApiTestV21(test.NoDBTestCase): class VolumeApiTestV21(test.NoDBTestCase):
url_prefix = '/v2/fake' url_prefix = '/v2/%s' % fakes.FAKE_PROJECT_ID
def setUp(self): def setUp(self):
super(VolumeApiTestV21, self).setUp() super(VolumeApiTestV21, self).setUp()
@ -1183,7 +1185,8 @@ class CommonBadRequestTestCase(object):
self.controller = self.controller_cls() self.controller = self.controller_cls()
def _bad_request_create(self, body): def _bad_request_create(self, body):
req = fakes.HTTPRequest.blank('/v2/fake/' + self.resource) req = fakes.HTTPRequest.blank('/v2/%s/%s' % (
fakes.FAKE_PROJECT_ID, self.resource))
req.method = 'POST' req.method = 'POST'
kwargs = self.kwargs.copy() kwargs = self.kwargs.copy()
@ -1238,10 +1241,12 @@ class AssistedSnapshotCreateTestCaseV21(test.NoDBTestCase):
self.controller = \ self.controller = \
self.assisted_snaps.AssistedVolumeSnapshotsController() self.assisted_snaps.AssistedVolumeSnapshotsController()
self.url = ('/v2/%s/os-assisted-volume-snapshots' %
fakes.FAKE_PROJECT_ID)
@mock.patch.object(compute_api.API, 'volume_snapshot_create') @mock.patch.object(compute_api.API, 'volume_snapshot_create')
def test_assisted_create(self, mock_volume_snapshot_create): def test_assisted_create(self, mock_volume_snapshot_create):
req = fakes.HTTPRequest.blank('/v2/fake/os-assisted-volume-snapshots') req = fakes.HTTPRequest.blank(self.url)
expected_create_info = {'type': 'qcow2', expected_create_info = {'type': 'qcow2',
'new_file': 'new_file', 'new_file': 'new_file',
'snapshot_id': 'snapshot_id'} 'snapshot_id': 'snapshot_id'}
@ -1255,14 +1260,14 @@ class AssistedSnapshotCreateTestCaseV21(test.NoDBTestCase):
expected_create_info) expected_create_info)
def test_assisted_create_missing_create_info(self): def test_assisted_create_missing_create_info(self):
req = fakes.HTTPRequest.blank('/v2/fake/os-assisted-volume-snapshots') req = fakes.HTTPRequest.blank(self.url)
body = {'snapshot': {'volume_id': '1'}} body = {'snapshot': {'volume_id': '1'}}
req.method = 'POST' req.method = 'POST'
self.assertRaises(self.bad_request, self.controller.create, self.assertRaises(self.bad_request, self.controller.create,
req, body=body) req, body=body)
def test_assisted_create_with_unexpected_attr(self): def test_assisted_create_with_unexpected_attr(self):
req = fakes.HTTPRequest.blank('/v2/fake/os-assisted-volume-snapshots') req = fakes.HTTPRequest.blank(self.url)
body = { body = {
'snapshot': { 'snapshot': {
'volume_id': '1', 'volume_id': '1',
@ -1281,7 +1286,7 @@ class AssistedSnapshotCreateTestCaseV21(test.NoDBTestCase):
@mock.patch('nova.objects.BlockDeviceMapping.get_by_volume', @mock.patch('nova.objects.BlockDeviceMapping.get_by_volume',
side_effect=exception.VolumeBDMIsMultiAttach(volume_id='1')) side_effect=exception.VolumeBDMIsMultiAttach(volume_id='1'))
def test_assisted_create_multiattach_fails(self, bdm_get_by_volume): def test_assisted_create_multiattach_fails(self, bdm_get_by_volume):
req = fakes.HTTPRequest.blank('/v2/fake/os-assisted-volume-snapshots') req = fakes.HTTPRequest.blank(self.url)
body = {'snapshot': body = {'snapshot':
{'volume_id': '1', {'volume_id': '1',
'create_info': {'type': 'qcow2', 'create_info': {'type': 'qcow2',
@ -1292,7 +1297,7 @@ class AssistedSnapshotCreateTestCaseV21(test.NoDBTestCase):
webob.exc.HTTPBadRequest, self.controller.create, req, body=body) webob.exc.HTTPBadRequest, self.controller.create, req, body=body)
def _test_assisted_create_instance_conflict(self, api_error): def _test_assisted_create_instance_conflict(self, api_error):
req = fakes.HTTPRequest.blank('/v2/fake/os-assisted-volume-snapshots') req = fakes.HTTPRequest.blank(self.url)
body = {'snapshot': body = {'snapshot':
{'volume_id': '1', {'volume_id': '1',
'create_info': {'type': 'qcow2', 'create_info': {'type': 'qcow2',
@ -1332,13 +1337,15 @@ class AssistedSnapshotDeleteTestCaseV21(test.NoDBTestCase):
self.mock_volume_snapshot_delete = self.useFixture( self.mock_volume_snapshot_delete = self.useFixture(
fixtures.MockPatchObject(compute_api.API, fixtures.MockPatchObject(compute_api.API,
'volume_snapshot_delete')).mock 'volume_snapshot_delete')).mock
self.url = ('/v2/%s/os-assisted-volume-snapshots' %
fakes.FAKE_PROJECT_ID)
def test_assisted_delete(self): def test_assisted_delete(self):
params = { params = {
'delete_info': jsonutils.dumps({'volume_id': '1'}), 'delete_info': jsonutils.dumps({'volume_id': '1'}),
} }
req = fakes.HTTPRequest.blank( req = fakes.HTTPRequest.blank(
'/v2/fake/os-assisted-volume-snapshots?%s' % self.url + '?%s' %
urllib.parse.urlencode(params), urllib.parse.urlencode(params),
version=self.microversion) version=self.microversion)
req.method = 'DELETE' req.method = 'DELETE'
@ -1346,7 +1353,7 @@ class AssistedSnapshotDeleteTestCaseV21(test.NoDBTestCase):
self._check_status(204, result, self.controller.delete) self._check_status(204, result, self.controller.delete)
def test_assisted_delete_missing_delete_info(self): def test_assisted_delete_missing_delete_info(self):
req = fakes.HTTPRequest.blank('/v2/fake/os-assisted-volume-snapshots', req = fakes.HTTPRequest.blank(self.url,
version=self.microversion) version=self.microversion)
req.method = 'DELETE' req.method = 'DELETE'
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.delete, self.assertRaises(webob.exc.HTTPBadRequest, self.controller.delete,
@ -1359,7 +1366,7 @@ class AssistedSnapshotDeleteTestCaseV21(test.NoDBTestCase):
'delete_info': jsonutils.dumps({'volume_id': '1'}), 'delete_info': jsonutils.dumps({'volume_id': '1'}),
} }
req = fakes.HTTPRequest.blank( req = fakes.HTTPRequest.blank(
'/v2/fake/os-assisted-volume-snapshots?%s' % self.url + '?%s' %
urllib.parse.urlencode(params), urllib.parse.urlencode(params),
version=self.microversion) version=self.microversion)
req.method = 'DELETE' req.method = 'DELETE'
@ -1385,7 +1392,7 @@ class AssistedSnapshotDeleteTestCaseV21(test.NoDBTestCase):
'additional': 123 'additional': 123
} }
req = fakes.HTTPRequest.blank( req = fakes.HTTPRequest.blank(
'/v2/fake/os-assisted-volume-snapshots?%s' % self.url + '?%s' %
urllib.parse.urlencode(params), urllib.parse.urlencode(params),
version=self.microversion) version=self.microversion)
req.method = 'DELETE' req.method = 'DELETE'
@ -1397,7 +1404,7 @@ class AssistedSnapshotDeleteTestCaseV21(test.NoDBTestCase):
'delete_info': jsonutils.dumps({'volume_id': '2'}) 'delete_info': jsonutils.dumps({'volume_id': '2'})
} }
req = fakes.HTTPRequest.blank( req = fakes.HTTPRequest.blank(
'/v2/fake/os-assisted-volume-snapshots?%s' % self.url + '?%s' %
urllib.parse.urlencode(params), urllib.parse.urlencode(params),
version=self.microversion) version=self.microversion)
req.method = 'DELETE' req.method = 'DELETE'
@ -1408,7 +1415,7 @@ class AssistedSnapshotDeleteTestCaseV21(test.NoDBTestCase):
'delete_info': jsonutils.dumps({'something_else': '1'}), 'delete_info': jsonutils.dumps({'something_else': '1'}),
} }
req = fakes.HTTPRequest.blank( req = fakes.HTTPRequest.blank(
'/v2/fake/os-assisted-volume-snapshots?%s' % self.url + '?%s' %
urllib.parse.urlencode(params), urllib.parse.urlencode(params),
version=self.microversion) version=self.microversion)
@ -1430,14 +1437,14 @@ class AssistedSnapshotDeleteTestCaseV275(AssistedSnapshotDeleteTestCaseV21):
'additional': 123 'additional': 123
} }
req = fakes.HTTPRequest.blank( req = fakes.HTTPRequest.blank(
'/v2/fake/os-assisted-volume-snapshots?%s' % self.url + '?%s' %
urllib.parse.urlencode(params), urllib.parse.urlencode(params),
version='2.74') version='2.74')
self.controller.delete(req, 1) self.controller.delete(req, 1)
def test_delete_additional_query_parameters(self): def test_delete_additional_query_parameters(self):
req = fakes.HTTPRequest.blank( req = fakes.HTTPRequest.blank(
'/v2/fake/os-assisted-volume-snapshots?unknown=1', self.url + '?unknown=1',
version=self.microversion) version=self.microversion)
self.assertRaises(exception.ValidationError, self.assertRaises(exception.ValidationError,
self.controller.delete, req, 1) self.controller.delete, req, 1)

View File

@ -73,7 +73,8 @@ def wsgi_app_v21(fake_auth_context=None, v2_compatible=False,
if fake_auth_context is not None: if fake_auth_context is not None:
ctxt = fake_auth_context ctxt = fake_auth_context
else: else:
ctxt = context.RequestContext('fake', 'fake', auth_token=True) ctxt = context.RequestContext(
'fake', FAKE_PROJECT_ID, auth_token=True)
api_v21 = openstack_api.FaultWrapper( api_v21 = openstack_api.FaultWrapper(
api_auth.InjectContext(ctxt, inner_app_v21)) api_auth.InjectContext(ctxt, inner_app_v21))
mapper = urlmap.URLMap() mapper = urlmap.URLMap()
@ -269,7 +270,7 @@ class HTTPRequest(os_wsgi.Request):
def blank(cls, *args, **kwargs): def blank(cls, *args, **kwargs):
defaults = {'base_url': 'http://localhost/v2'} defaults = {'base_url': 'http://localhost/v2'}
use_admin_context = kwargs.pop('use_admin_context', False) use_admin_context = kwargs.pop('use_admin_context', False)
project_id = kwargs.pop('project_id', 'fake') project_id = kwargs.pop('project_id', FAKE_PROJECT_ID)
version = kwargs.pop('version', os_wsgi.DEFAULT_API_VERSION) version = kwargs.pop('version', os_wsgi.DEFAULT_API_VERSION)
defaults.update(kwargs) defaults.update(kwargs)
out = super(HTTPRequest, cls).blank(*args, **defaults) out = super(HTTPRequest, cls).blank(*args, **defaults)

View File

@ -578,7 +578,7 @@ class UrlJoinTest(test.NoDBTestCase):
class ViewBuilderLinkTest(test.NoDBTestCase): class ViewBuilderLinkTest(test.NoDBTestCase):
project_id = "fake" project_id = fakes.FAKE_PROJECT_ID
api_version = "2.1" api_version = "2.1"
def setUp(self): def setUp(self):

View File

@ -42,11 +42,6 @@ class ConfFixture(config_fixture.Config):
self.conf.set_default('network_size', 8) self.conf.set_default('network_size', 8)
self.conf.set_default('num_networks', 2) self.conf.set_default('num_networks', 2)
self.conf.set_default('periodic_enable', False) self.conf.set_default('periodic_enable', False)
# TODO(sdague): this makes our project_id match 'fake' as well.
# We should fix the tests to use real
# UUIDs then drop this work around.
self.conf.set_default('project_id_regex',
'[0-9a-fk-]+', 'osapi_v21')
self.conf.set_default('use_ipv6', True) self.conf.set_default('use_ipv6', True)
self.conf.set_default('vlan_interface', 'eth0') self.conf.set_default('vlan_interface', 'eth0')

View File

@ -0,0 +1,4 @@
---
upgrade:
- The ``[osapi_v21]/project_id_regex`` configuration option which has been
deprecated since the Mitaka 13.0.0 release has now been removed.