Add Enable/Disable options for freezer-api
Allow users to enable whatever freezer-api version they like. * Added enable_v1_api to control v1 api * Added enable_v2_api to control v2 api Implements blueprint api-v2-multi-tenancy Change-Id: I62a31476d416f9fe89e6e90c2206a55a8c1b7d14 Signed-off-by: Saad Zaher <eng.szaher@gmail.com>
This commit is contained in:
@@ -12,6 +12,37 @@
|
|||||||
# Maximum value: 65535
|
# Maximum value: 65535
|
||||||
#bind_port = 9090
|
#bind_port = 9090
|
||||||
|
|
||||||
|
# Deploy the v1 OpenStack Freezer API.
|
||||||
|
# When this option is set to ``True``, Freezer-api service will respond to
|
||||||
|
# requests on registered endpoints conforming to the v1 OpenStack Freezer API.
|
||||||
|
# NOTES:
|
||||||
|
# * Multi-tenancy is not supported under this api version.
|
||||||
|
# * Everything is user based.
|
||||||
|
# * Freezer api v1 doesn't support Oslo.db.
|
||||||
|
# * Use elasticsearch db with v1 api version
|
||||||
|
# Possible values:
|
||||||
|
# * True
|
||||||
|
# * False
|
||||||
|
# Related options:
|
||||||
|
# * enable_v2_api
|
||||||
|
# (boolean value)
|
||||||
|
#enable_v1_api = true
|
||||||
|
|
||||||
|
# Deploy the v2 OpenStack Freezer API.
|
||||||
|
# When this option is set to ``True``, Freezer-api service will respond to
|
||||||
|
# requests on registered endpoints conforming to the v2 OpenStack Freezer api.
|
||||||
|
# NOTES:
|
||||||
|
# * Multi-tenancy is supported under this api version.
|
||||||
|
# * Freezer api v2 supports Oslo.db.
|
||||||
|
# * Recommended to use oslo.db with api v2
|
||||||
|
# Possible values:
|
||||||
|
# * True
|
||||||
|
# * False
|
||||||
|
# Related options:
|
||||||
|
# * enable_v1_api
|
||||||
|
# (boolean value)
|
||||||
|
#enable_v2_api = true
|
||||||
|
|
||||||
#
|
#
|
||||||
# From oslo.log
|
# From oslo.log
|
||||||
#
|
#
|
||||||
@@ -21,12 +52,6 @@
|
|||||||
# Note: This option can be changed without restarting.
|
# Note: This option can be changed without restarting.
|
||||||
#debug = false
|
#debug = false
|
||||||
|
|
||||||
# DEPRECATED: If set to false, the logging level will be set to WARNING instead
|
|
||||||
# of the default INFO level. (boolean value)
|
|
||||||
# This option is deprecated for removal.
|
|
||||||
# Its value may be silently ignored in the future.
|
|
||||||
#verbose = true
|
|
||||||
|
|
||||||
# The name of a logging configuration file. This file is appended to any
|
# The name of a logging configuration file. This file is appended to any
|
||||||
# existing logging configuration files. For details about logging configuration
|
# existing logging configuration files. For details about logging configuration
|
||||||
# files, see the Python logging module documentation. Note that when logging
|
# files, see the Python logging module documentation. Note that when logging
|
||||||
@@ -65,6 +90,12 @@
|
|||||||
# is set. (boolean value)
|
# is set. (boolean value)
|
||||||
#use_syslog = false
|
#use_syslog = false
|
||||||
|
|
||||||
|
# Enable journald for logging. If running in a systemd environment you may wish
|
||||||
|
# to enable journal support. Doing so will use the journal native protocol
|
||||||
|
# which includes structured metadata in addition to log messages.This option is
|
||||||
|
# ignored if log_config_append is set. (boolean value)
|
||||||
|
#use_journal = false
|
||||||
|
|
||||||
# Syslog facility to receive log lines. This option is ignored if
|
# Syslog facility to receive log lines. This option is ignored if
|
||||||
# log_config_append is set. (string value)
|
# log_config_append is set. (string value)
|
||||||
#syslog_log_facility = LOG_USER
|
#syslog_log_facility = LOG_USER
|
||||||
@@ -186,9 +217,8 @@
|
|||||||
# From freezer-api
|
# From freezer-api
|
||||||
#
|
#
|
||||||
|
|
||||||
# specify the storage hosts (string value)
|
# specify the storage hosts (list value)
|
||||||
# Deprecated group/name - [elasticsearch]/endpoint
|
#hosts = http://127.0.0.1:9200
|
||||||
#hosts = http://localhost:9200
|
|
||||||
|
|
||||||
# specify the name of the elasticsearch index (string value)
|
# specify the name of the elasticsearch index (string value)
|
||||||
#index = freezer
|
#index = freezer
|
||||||
|
@@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
|
|
||||||
import falcon
|
import falcon
|
||||||
import json
|
import json
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
|
||||||
|
|
||||||
@@ -24,13 +25,13 @@ from freezer_api.api.common import middleware
|
|||||||
from freezer_api.api import v1
|
from freezer_api.api import v1
|
||||||
from freezer_api.api import v2
|
from freezer_api.api import v2
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
VERSIONS = {
|
VERSIONS = {
|
||||||
'versions': [
|
'versions': [
|
||||||
v1.VERSION,
|
v2.VERSION,
|
||||||
v2.VERSION
|
v1.VERSION
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,11 +51,13 @@ def api_versions(conf=None):
|
|||||||
class Resource(object):
|
class Resource(object):
|
||||||
|
|
||||||
def _build_versions(self, host_url):
|
def _build_versions(self, host_url):
|
||||||
|
allowed_versions = {'v1': CONF.enable_v1_api, 'v2': CONF.enable_v2_api}
|
||||||
|
|
||||||
updated_versions = {'versions': []}
|
updated_versions = {'versions': []}
|
||||||
for version in VERSIONS['versions']:
|
for version in VERSIONS['versions']:
|
||||||
version['links'][0]['href'] = version['links'][0]['href'].format(
|
if allowed_versions[version['id']]:
|
||||||
host_url
|
version['links'][0]['href'] = \
|
||||||
)
|
version['links'][0]['href'].format(host_url)
|
||||||
updated_versions['versions'].append(version)
|
updated_versions['versions'].append(version)
|
||||||
return json.dumps(updated_versions, ensure_ascii=False)
|
return json.dumps(updated_versions, ensure_ascii=False)
|
||||||
|
|
||||||
|
@@ -46,7 +46,38 @@ def api_common_opts():
|
|||||||
default=9090,
|
default=9090,
|
||||||
dest='bind_port',
|
dest='bind_port',
|
||||||
help='Port number to listen on. Default is 9090'
|
help='Port number to listen on. Default is 9090'
|
||||||
)
|
),
|
||||||
|
cfg.BoolOpt('enable_v1_api',
|
||||||
|
default=True,
|
||||||
|
help="""Deploy the v1 OpenStack Freezer API.
|
||||||
|
When this option is set to ``True``, Freezer-api service will respond to
|
||||||
|
requests on registered endpoints conforming to the v1 OpenStack Freezer API.
|
||||||
|
NOTES:
|
||||||
|
* Multi-tenancy is not supported under this api version.
|
||||||
|
* Everything is user based.
|
||||||
|
* Freezer api v1 doesn't support Oslo.db.
|
||||||
|
* Use elasticsearch db with v1 api version
|
||||||
|
Possible values:
|
||||||
|
* True
|
||||||
|
* False
|
||||||
|
Related options:
|
||||||
|
* enable_v2_api
|
||||||
|
"""),
|
||||||
|
cfg.BoolOpt('enable_v2_api',
|
||||||
|
default=True,
|
||||||
|
help="""Deploy the v2 OpenStack Freezer API.
|
||||||
|
When this option is set to ``True``, Freezer-api service will respond to
|
||||||
|
requests on registered endpoints conforming to the v2 OpenStack Freezer api.
|
||||||
|
NOTES:
|
||||||
|
* Multi-tenancy is supported under this api version.
|
||||||
|
* Freezer api v2 supports Oslo.db.
|
||||||
|
* Recommended to use oslo.db with api v2
|
||||||
|
Possible values:
|
||||||
|
* True
|
||||||
|
* False
|
||||||
|
Related options:
|
||||||
|
* enable_v1_api
|
||||||
|
""")
|
||||||
]
|
]
|
||||||
|
|
||||||
return _COMMON
|
return _COMMON
|
||||||
|
@@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
import falcon
|
import falcon
|
||||||
|
from oslo_config import cfg
|
||||||
from paste import deploy
|
from paste import deploy
|
||||||
from paste import urlmap
|
from paste import urlmap
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
@@ -24,6 +25,7 @@ import pkg_resources
|
|||||||
from freezer_api.cmd import api
|
from freezer_api.cmd import api
|
||||||
from freezer_api.common import config
|
from freezer_api.common import config
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
# Define the minimum version of falcon at which we can use the "new" invocation
|
# Define the minimum version of falcon at which we can use the "new" invocation
|
||||||
# style for middleware (aka v1), i.e. the "middleware" named argument for
|
# style for middleware (aka v1), i.e. the "middleware" named argument for
|
||||||
# falcon.API.
|
# falcon.API.
|
||||||
@@ -34,6 +36,10 @@ def root_app_factory(loader, global_conf, **local_conf):
|
|||||||
"""Allows freezer to launch multiple applications at a time.
|
"""Allows freezer to launch multiple applications at a time.
|
||||||
It will allow freezer to manage multiple versions.
|
It will allow freezer to manage multiple versions.
|
||||||
"""
|
"""
|
||||||
|
if not CONF.enable_v1_api and '/v1' in local_conf:
|
||||||
|
del local_conf['/v1']
|
||||||
|
if not CONF.enable_v2_api and '/v2' in local_conf:
|
||||||
|
del local_conf['/v2']
|
||||||
return urlmap.urlmap_factory(loader, global_conf, **local_conf)
|
return urlmap.urlmap_factory(loader, global_conf, **local_conf)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -35,7 +35,7 @@ class TestFreezerApiVersion(base.BaseFreezerApiTest):
|
|||||||
|
|
||||||
resp_body_json = json.loads(response_body)
|
resp_body_json = json.loads(response_body)
|
||||||
self.assertIn('versions', resp_body_json)
|
self.assertIn('versions', resp_body_json)
|
||||||
current_version = resp_body_json['versions'][0]
|
current_version = resp_body_json['versions'][1]
|
||||||
self.assertEqual(len(current_version), 4)
|
self.assertEqual(len(current_version), 4)
|
||||||
self.assertIn('id', current_version)
|
self.assertIn('id', current_version)
|
||||||
self.assertEqual(current_version['id'], 'v1')
|
self.assertEqual(current_version['id'], 'v1')
|
||||||
|
@@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import unittest
|
|
||||||
|
|
||||||
import falcon
|
import falcon
|
||||||
import mock
|
import mock
|
||||||
@@ -25,16 +24,19 @@ import mock
|
|||||||
from freezer_api.api import v1
|
from freezer_api.api import v1
|
||||||
from freezer_api.api import v2
|
from freezer_api.api import v2
|
||||||
from freezer_api.api import versions
|
from freezer_api.api import versions
|
||||||
|
from freezer_api.tests.unit import common
|
||||||
|
|
||||||
|
|
||||||
class TestVersionResource(unittest.TestCase):
|
class TestVersionResource(common.FreezerBaseTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
super(TestVersionResource, self).setUp()
|
||||||
self.resource = versions.Resource()
|
self.resource = versions.Resource()
|
||||||
self.req = mock.Mock()
|
self.req = mock.Mock()
|
||||||
|
self.req.url = "{0}"
|
||||||
|
|
||||||
def test_on_get_return_versions(self):
|
def test_on_get_return_versions(self):
|
||||||
self.resource.on_get(self.req, self.req)
|
self.resource.on_get(self.req, self.req)
|
||||||
self.assertEqual(self.req.status, falcon.HTTP_300)
|
self.assertEqual(self.req.status, falcon.HTTP_300)
|
||||||
expected_result = json.dumps({'versions': [v1.VERSION, v2.VERSION]})
|
expected_result = json.dumps({'versions': [v2.VERSION, v1.VERSION]})
|
||||||
self.assertEqual(self.req.data, expected_result)
|
self.assertEqual(self.req.data, expected_result)
|
||||||
|
Reference in New Issue
Block a user