Add Versions API to Drydock
This ps adds a VersionsResource that returns a list of API versions available and includes unit tests for get_versions and get_health Change-Id: Ibcbc2af79cf5e441b59d64da9a1c7f951eff0563
This commit is contained in:
parent
1becc37311
commit
3b4e702518
|
@ -24,7 +24,7 @@ from .bootdata import BootdataResource
|
|||
from .nodes import NodesResource
|
||||
from .health import HealthResource
|
||||
|
||||
from .base import DrydockRequest
|
||||
from .base import DrydockRequest, BaseResource
|
||||
from .middleware import AuthMiddleware, ContextMiddleware, LoggingMiddleware
|
||||
|
||||
|
||||
|
@ -46,6 +46,8 @@ def start_api(state_manager=None, ingester=None, orchestrator=None):
|
|||
LoggingMiddleware()
|
||||
])
|
||||
|
||||
control_api.add_route('/versions', VersionsResource())
|
||||
|
||||
# v1.0 of Drydock API
|
||||
v1_0_routes = [
|
||||
# API for managing orchestrator tasks
|
||||
|
@ -77,3 +79,17 @@ def start_api(state_manager=None, ingester=None, orchestrator=None):
|
|||
control_api.add_route('/api/v1.0' + path, res)
|
||||
|
||||
return control_api
|
||||
|
||||
|
||||
class VersionsResource(BaseResource):
|
||||
"""
|
||||
Lists the versions supported by this API
|
||||
"""
|
||||
|
||||
def on_get(self, req, resp):
|
||||
resp.body = self.to_json({
|
||||
'v1.0': {
|
||||
'path': '/api/v1.0',
|
||||
'status': 'stable'
|
||||
}})
|
||||
resp.status = falcon.HTTP_200
|
||||
|
|
|
@ -82,6 +82,12 @@ class BaseResource(object):
|
|||
|
||||
self.logger.log(level, msg, extra=extra)
|
||||
|
||||
def to_json(self, body_dict):
|
||||
"""
|
||||
Thin wrapper around json.dumps, providing the default=str config
|
||||
"""
|
||||
return json.dumps(body_dict, default=str)
|
||||
|
||||
def debug(self, ctx, msg):
|
||||
self.log_error(ctx, logging.DEBUG, msg)
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
# Copyright 2017 AT&T Intellectual Property. All other 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.
|
||||
"""Test Health API"""
|
||||
|
||||
from drydock_provisioner.control.health import HealthResource
|
||||
|
||||
import falcon
|
||||
|
||||
|
||||
def test_get_health(mocker):
|
||||
api = HealthResource()
|
||||
|
||||
# Configure mocked request and response
|
||||
req = mocker.MagicMock(spec=falcon.Request)
|
||||
resp = mocker.MagicMock(spec=falcon.Response)
|
||||
|
||||
api.on_get(req, resp)
|
||||
|
||||
assert resp.status == falcon.HTTP_204
|
|
@ -0,0 +1,33 @@
|
|||
# Copyright 2017 AT&T Intellectual Property. All other 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.
|
||||
"""Test Versions API"""
|
||||
|
||||
from drydock_provisioner.control.api import VersionsResource
|
||||
|
||||
import falcon
|
||||
|
||||
|
||||
def test_get_versions(mocker):
|
||||
api = VersionsResource()
|
||||
|
||||
# Configure mocked request and response
|
||||
req = mocker.MagicMock(spec=falcon.Request)
|
||||
resp = mocker.MagicMock(spec=falcon.Response)
|
||||
|
||||
api.on_get(req, resp)
|
||||
|
||||
expected = api.to_json({'v1.0': {'path': '/api/v1.0', 'status': 'stable'}})
|
||||
|
||||
assert resp.body == expected
|
||||
assert resp.status == falcon.HTTP_200
|
Loading…
Reference in New Issue