Add config option to enable/disable services for each sp
Modified proxy.py and config.py to support the option. Change-Id: Ibd7d701f4efb1fc952cd4750cd39d98c9eb98a79
This commit is contained in:
parent
3081c8b37e
commit
755da47df3
|
@ -27,6 +27,7 @@ messagebus="rabbit://stackrabbit:stackqueue@localhost"
|
|||
auth_url="http://127.0.0.1:5000/v3"
|
||||
image_endpoint="http://localhost:9292"
|
||||
volume_endpoint="http://localhost:8776"
|
||||
enabled_services=image, volume
|
||||
|
||||
[sp_cornmeal-sp]
|
||||
sp_name=cornmeal-sp
|
||||
|
@ -34,6 +35,7 @@ messagebus="rabbit://stackrabbit:stackqueue@192.168.0.141"
|
|||
auth_url="http://192.168.0.141:5000/v3"
|
||||
image_endpoint="http://192.168.0.141:9292"
|
||||
volume_endpoint="http://192.168.0.141:8776"
|
||||
enabled_services=image, volume
|
||||
|
||||
# Logging
|
||||
[loggers]
|
||||
|
|
|
@ -151,7 +151,11 @@ def more_config():
|
|||
|
||||
cfg.StrOpt('volume_endpoint',
|
||||
default=None,
|
||||
help="Volume Endpoint for Service Provider")
|
||||
help="Volume Endpoint for Service Provider"),
|
||||
|
||||
cfg.ListOpt('enabled_services',
|
||||
default=['image', 'volume'],
|
||||
help="Services to enable for Service Provider")
|
||||
]
|
||||
|
||||
CONF.register_group(sp_group)
|
||||
|
|
|
@ -55,6 +55,11 @@ class RequestHandler(object):
|
|||
self.request_path.insert(0, 'image')
|
||||
|
||||
self.service_type = self.request_path[0]
|
||||
self.enabled_sps = filter(
|
||||
lambda sp: (self.service_type in
|
||||
config.get_conf_for_sp(sp).enabled_services),
|
||||
CONF.service_providers
|
||||
)
|
||||
|
||||
if len(self.request_path) == 1:
|
||||
# unversioned calls with no action
|
||||
|
@ -185,7 +190,7 @@ class RequestHandler(object):
|
|||
if not CONF.search_by_broadcast:
|
||||
return self._local_forward()
|
||||
|
||||
for sp in CONF.service_providers:
|
||||
for sp in self.enabled_sps:
|
||||
if sp == 'default':
|
||||
response = self._do_request_on('default')
|
||||
if 200 <= response.status_code < 300:
|
||||
|
@ -207,7 +212,7 @@ class RequestHandler(object):
|
|||
|
||||
responses = {}
|
||||
|
||||
for sp in CONF.service_providers:
|
||||
for sp in self.enabled_sps:
|
||||
if sp == 'default':
|
||||
responses['default'] = self._do_request_on('default')
|
||||
else:
|
||||
|
@ -222,7 +227,7 @@ class RequestHandler(object):
|
|||
path=request.base_url,
|
||||
detailed=self.detailed),
|
||||
200,
|
||||
content_type=responses['default'].headers['content-type']
|
||||
content_type='application/json'
|
||||
)
|
||||
|
||||
def _list_api_versions(self):
|
||||
|
|
|
@ -13,15 +13,19 @@
|
|||
# under the License.
|
||||
|
||||
import uuid
|
||||
import json
|
||||
|
||||
from testtools import testcase
|
||||
from oslo_config import fixture as config_fixture
|
||||
|
||||
from mixmatch import proxy
|
||||
from mixmatch.config import CONF
|
||||
from mixmatch.tests.unit.base import BaseTest
|
||||
|
||||
|
||||
class TestRequestHandler(testcase.TestCase):
|
||||
class TestRequestHandler(BaseTest):
|
||||
def setUp(self):
|
||||
super(TestRequestHandler, self).setUp()
|
||||
self.config_fixture = self.useFixture(config_fixture.Config(conf=CONF))
|
||||
|
||||
def test_prepare_headers(self):
|
||||
user_headers = {
|
||||
|
@ -37,3 +41,59 @@ class TestRequestHandler(testcase.TestCase):
|
|||
}
|
||||
args = proxy.RequestHandler._prepare_args(user_args)
|
||||
self.assertEqual({}, args)
|
||||
|
||||
def test_toggle_services(self):
|
||||
self.config_fixture.load_raw_values(
|
||||
group='sp_remote1',
|
||||
enabled_services='volume'
|
||||
)
|
||||
REMOTE_PROJECT_ID = "319d8162b38342609f5fafe1404216b9"
|
||||
self.session_fixture.add_local_auth('local-tok', 'my_project_id')
|
||||
self.session_fixture.add_sp_auth('remote1', 'local-tok',
|
||||
REMOTE_PROJECT_ID, 'remote-tok')
|
||||
self.session_fixture.add_project_at_sp('remote1', REMOTE_PROJECT_ID)
|
||||
|
||||
LOCAL_IMAGES = {
|
||||
"images": [
|
||||
{"id": "1bea47ed-f6a9-463b-b423-14b9cca9ad27",
|
||||
"size": 4096},
|
||||
{"id": "781b3762-9469-4cec-b58d-3349e5de4e9c",
|
||||
"size": 476704768}
|
||||
],
|
||||
}
|
||||
|
||||
self.requests_fixture.get(
|
||||
'http://images.local/v2/images',
|
||||
text=json.dumps(LOCAL_IMAGES),
|
||||
status_code=200,
|
||||
request_headers={'X-AUTH-TOKEN': 'local-tok'},
|
||||
headers={'CONTENT-TYPE': 'application/json'})
|
||||
|
||||
response = self.app.get(
|
||||
'/image/v2/images',
|
||||
headers={'X-AUTH-TOKEN': 'local-tok',
|
||||
'CONTENT-TYPE': 'application/json'})
|
||||
actual = json.loads(response.data.decode("ascii"))
|
||||
self.assertEqual(actual, LOCAL_IMAGES)
|
||||
|
||||
def test_toggle_services_no_sps(self):
|
||||
self.config_fixture.load_raw_values(
|
||||
group='sp_remote1',
|
||||
enabled_services='volume'
|
||||
)
|
||||
self.config_fixture.load_raw_values(
|
||||
group='sp_default',
|
||||
enabled_services='volume'
|
||||
)
|
||||
REMOTE_PROJECT_ID = "319d8162b38342609f5fafe1404216b9"
|
||||
self.session_fixture.add_local_auth('local-tok', 'my_project_id')
|
||||
self.session_fixture.add_sp_auth('remote1', 'local-tok',
|
||||
REMOTE_PROJECT_ID, 'remote-tok')
|
||||
self.session_fixture.add_project_at_sp('remote1', REMOTE_PROJECT_ID)
|
||||
|
||||
response = self.app.get(
|
||||
'/image/v2/images',
|
||||
headers={'X-AUTH-TOKEN': 'local-tok',
|
||||
'CONTENT-TYPE': 'application/json'})
|
||||
actual = json.loads(response.data.decode("ascii"))
|
||||
self.assertEqual(actual, {'images': []})
|
||||
|
|
|
@ -14,12 +14,12 @@
|
|||
|
||||
import json
|
||||
from six.moves.urllib import parse
|
||||
from oslo_config import fixture as config_fixture
|
||||
from mixmatch.config import CONF
|
||||
|
||||
from testtools import testcase
|
||||
|
||||
from oslo_config import fixture as config_fixture
|
||||
|
||||
from mixmatch import services
|
||||
from mixmatch.config import CONF
|
||||
from mixmatch.tests.unit import samples
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue