Extensions handler for Nailgun
Added new API handler /extensions/ which returns a list of available extensions. Co-Authored-By: Sylwester Brzeczkowski <sbrzeczkowski@mirantis.com> Change-Id: I072f3e4d9cd8f71498a20312af7c2016e951456d Implements: blueprint extensions-management Partial-Bug: #1614526
This commit is contained in:
parent
eb5a939f15
commit
28dd1ff3a1
30
nailgun/nailgun/api/v1/handlers/extension.py
Normal file
30
nailgun/nailgun/api/v1/handlers/extension.py
Normal file
@ -0,0 +1,30 @@
|
||||
# Copyright 2016 Mirantis, Inc.
|
||||
#
|
||||
# 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 nailgun.api.v1.handlers.base import BaseHandler
|
||||
from nailgun.api.v1.handlers.base import serialize
|
||||
|
||||
from nailgun.extensions import get_all_extensions
|
||||
|
||||
|
||||
class ExtensionHandler(BaseHandler):
|
||||
"""Exception Handler"""
|
||||
|
||||
@serialize
|
||||
def GET(self):
|
||||
""":returns: JSONized list of available extensions.
|
||||
|
||||
:http: * 200 (OK)
|
||||
"""
|
||||
return [ext.to_dict() for ext in get_all_extensions()]
|
@ -55,6 +55,8 @@ from nailgun.api.v1.handlers.cluster_plugin_link \
|
||||
from nailgun.api.v1.handlers.deployment_history \
|
||||
import DeploymentHistoryCollectionHandler
|
||||
|
||||
from nailgun.api.v1.handlers.extension import ExtensionHandler
|
||||
|
||||
from nailgun.api.v1.handlers.logs import LogEntryCollectionHandler
|
||||
from nailgun.api.v1.handlers.logs import LogPackageDefaultConfig
|
||||
from nailgun.api.v1.handlers.logs import LogPackageHandler
|
||||
@ -252,6 +254,8 @@ urls = (
|
||||
r'/clusters/(?P<cluster_id>\d+)/plugin_links/(?P<obj_id>\d+)/?$',
|
||||
ClusterPluginLinkHandler,
|
||||
|
||||
r'/extensions/?$',
|
||||
ExtensionHandler,
|
||||
r'/clusters/(?P<cluster_id>\d+)/extensions/?$',
|
||||
ClusterExtensionsHandler,
|
||||
|
||||
|
@ -248,3 +248,11 @@ class BaseExtension(object):
|
||||
def on_before_provisioning_serialization(cls, cluster, nodes,
|
||||
ignore_customized):
|
||||
"""Callback which gets executed before provisioning serialization"""
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
"name": self.name,
|
||||
"version": self.version,
|
||||
"description": self.description,
|
||||
"provides": self.provides,
|
||||
}
|
||||
|
69
nailgun/nailgun/test/integration/test_extension_handler.py
Normal file
69
nailgun/nailgun/test/integration/test_extension_handler.py
Normal file
@ -0,0 +1,69 @@
|
||||
# Copyright 2016 Mirantis, Inc.
|
||||
#
|
||||
# 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.
|
||||
|
||||
import mock
|
||||
|
||||
from nailgun import extensions
|
||||
from nailgun.test.base import BaseTestCase
|
||||
from nailgun.utils import reverse
|
||||
|
||||
|
||||
class TestExtensionHandler(BaseTestCase):
|
||||
|
||||
def test_get_extensions_list(self):
|
||||
class FakeExtension(extensions.BaseExtension):
|
||||
@property
|
||||
def name(self):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def version(self):
|
||||
return self._version
|
||||
|
||||
@property
|
||||
def description(self):
|
||||
return self._description
|
||||
|
||||
def __init__(self, name, version, description, provides):
|
||||
self._name = name
|
||||
self._version = version
|
||||
self._description = description
|
||||
self.provides = provides
|
||||
|
||||
exts = [FakeExtension('ex1', '1.0.1', 'descr #1', ['method_call_1']),
|
||||
FakeExtension('ex2', '1.2.3', 'descr #2', ['method_call_2'])]
|
||||
|
||||
with mock.patch('nailgun.api.v1.handlers.extension.get_all_extensions',
|
||||
return_value=exts):
|
||||
|
||||
resp = self.app.get(
|
||||
reverse('ExtensionHandler'),
|
||||
headers=self.default_headers,
|
||||
)
|
||||
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
expected_body = [
|
||||
{'name': 'ex1',
|
||||
'version': '1.0.1',
|
||||
'description': 'descr #1',
|
||||
'provides': ['method_call_1'],
|
||||
},
|
||||
{'name': 'ex2',
|
||||
'version': '1.2.3',
|
||||
'description': 'descr #2',
|
||||
'provides': ['method_call_2'],
|
||||
},
|
||||
]
|
||||
self.assertEqual(len(resp.json_body), 2)
|
||||
self.assertEqual(expected_body, resp.json_body)
|
@ -53,6 +53,13 @@ class BaseExtensionCase(BaseTestCase):
|
||||
|
||||
class TestBaseExtension(BaseExtensionCase):
|
||||
|
||||
def test_extension_to_dict(self):
|
||||
serialized = self.extension.to_dict()
|
||||
self.assertEqual('ext_name', serialized['name'])
|
||||
self.assertEqual('1.0.0', serialized['version'])
|
||||
self.assertEqual('ext description', serialized['description'])
|
||||
self.assertEqual([], serialized['provides'])
|
||||
|
||||
def test_alembic_table_version(self):
|
||||
self.assertEqual(
|
||||
self.extension.alembic_table_version(),
|
||||
|
Loading…
Reference in New Issue
Block a user