Move existing kingbird to V1 directory.
Currently kingbird api version is V1 and if the api version is upgraded or changed to V2 it creates ambiguity because of the loose files present in "api/controllers".So made changes to move entire current code to V1 and made changes to existing tests to provide support to new changes. Change-Id: I07c19cac7eca111391a22b186949b26729d93414
This commit is contained in:
parent
923c9c140d
commit
7f89f08407
|
@ -16,9 +16,7 @@
|
|||
|
||||
import pecan
|
||||
|
||||
from kingbird.api.controllers import quota_manager
|
||||
from kingbird.api.controllers import sync_manager
|
||||
from kingbird.api.controllers.v1 import quota_class
|
||||
from kingbird.api.controllers.v1 import root as v1_root
|
||||
|
||||
|
||||
class RootController(object):
|
||||
|
@ -26,7 +24,7 @@ class RootController(object):
|
|||
@pecan.expose('json')
|
||||
def _lookup(self, version, *remainder):
|
||||
if version == 'v1.0':
|
||||
return V1Controller(), remainder
|
||||
return v1_root.Controller(), remainder
|
||||
|
||||
@pecan.expose(generic=True, template='json')
|
||||
def index(self):
|
||||
|
@ -53,56 +51,3 @@ class RootController(object):
|
|||
@index.when(method='PATCH')
|
||||
def not_supported(self):
|
||||
pecan.abort(405)
|
||||
|
||||
|
||||
class V1Controller(object):
|
||||
|
||||
def __init__(self):
|
||||
self.sub_controllers = {
|
||||
"os-quota-sets": quota_manager.QuotaManagerController,
|
||||
"os-quota-class-sets": quota_class.QuotaClassSetController,
|
||||
"os-sync": sync_manager.ResourceSyncController
|
||||
}
|
||||
for name, ctrl in self.sub_controllers.items():
|
||||
setattr(self, name, ctrl)
|
||||
|
||||
def _get_resource_controller(self, tenant_id, remainder):
|
||||
if not remainder:
|
||||
pecan.abort(404)
|
||||
return
|
||||
|
||||
resource = remainder[0]
|
||||
if resource not in self.sub_controllers:
|
||||
pecan.abort(404)
|
||||
return
|
||||
|
||||
# Pass the tenant_id for verification
|
||||
remainder = (tenant_id,) + remainder[1:]
|
||||
return self.sub_controllers[resource](), remainder
|
||||
|
||||
@pecan.expose()
|
||||
def _lookup(self, tenant_id, *remainder):
|
||||
return self._get_resource_controller(tenant_id, remainder)
|
||||
|
||||
@pecan.expose(generic=True, template='json')
|
||||
def index(self):
|
||||
return {
|
||||
"version": "1.0",
|
||||
"links": [
|
||||
{"rel": "self",
|
||||
"href": pecan.request.application_url + "/v1.0"}
|
||||
] + [
|
||||
{"rel": name,
|
||||
"href": pecan.request.application_url +
|
||||
"/v1.0/{tenant_id}/" + name}
|
||||
for name in sorted(self.sub_controllers)
|
||||
]
|
||||
}
|
||||
|
||||
@index.when(method='POST')
|
||||
@index.when(method='PUT')
|
||||
@index.when(method='DELETE')
|
||||
@index.when(method='HEAD')
|
||||
@index.when(method='PATCH')
|
||||
def not_supported(self):
|
||||
pecan.abort(405)
|
||||
|
|
|
@ -22,8 +22,7 @@ import pecan
|
|||
from pecan import expose
|
||||
from pecan import request
|
||||
|
||||
import restcomm
|
||||
|
||||
from kingbird.api.controllers import restcomm
|
||||
from kingbird.common import exceptions
|
||||
from kingbird.common.i18n import _
|
||||
from kingbird.common import utils
|
|
@ -0,0 +1,74 @@
|
|||
# Copyright (c) 2017 Ericsson AB.
|
||||
# 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.
|
||||
|
||||
|
||||
import pecan
|
||||
|
||||
from kingbird.api.controllers.v1 import quota_class
|
||||
from kingbird.api.controllers.v1 import quota_manager
|
||||
from kingbird.api.controllers.v1 import sync_manager
|
||||
|
||||
|
||||
class Controller(object):
|
||||
|
||||
def __init__(self):
|
||||
self.sub_controllers = {
|
||||
"os-quota-sets": quota_manager.QuotaManagerController,
|
||||
"os-quota-class-sets": quota_class.QuotaClassSetController,
|
||||
"os-sync": sync_manager.ResourceSyncController
|
||||
}
|
||||
for name, ctrl in self.sub_controllers.items():
|
||||
setattr(self, name, ctrl)
|
||||
|
||||
def _get_resource_controller(self, tenant_id, remainder):
|
||||
if not remainder:
|
||||
pecan.abort(404)
|
||||
return
|
||||
|
||||
resource = remainder[0]
|
||||
if resource not in self.sub_controllers:
|
||||
pecan.abort(404)
|
||||
return
|
||||
|
||||
# Pass the tenant_id for verification
|
||||
remainder = (tenant_id,) + remainder[1:]
|
||||
return self.sub_controllers[resource](), remainder
|
||||
|
||||
@pecan.expose()
|
||||
def _lookup(self, tenant_id, *remainder):
|
||||
return self._get_resource_controller(tenant_id, remainder)
|
||||
|
||||
@pecan.expose(generic=True, template='json')
|
||||
def index(self):
|
||||
return {
|
||||
"version": "1.0",
|
||||
"links": [
|
||||
{"rel": "self",
|
||||
"href": pecan.request.application_url + "/v1.0"}
|
||||
] + [
|
||||
{"rel": name,
|
||||
"href": pecan.request.application_url +
|
||||
"/v1.0/{tenant_id}/" + name}
|
||||
for name in sorted(self.sub_controllers)
|
||||
]
|
||||
}
|
||||
|
||||
@index.when(method='POST')
|
||||
@index.when(method='PUT')
|
||||
@index.when(method='DELETE')
|
||||
@index.when(method='HEAD')
|
||||
@index.when(method='PATCH')
|
||||
def not_supported(self):
|
||||
pecan.abort(405)
|
|
@ -13,8 +13,6 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import restcomm
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import uuidutils
|
||||
|
@ -24,6 +22,7 @@ import pecan
|
|||
from pecan import expose
|
||||
from pecan import request
|
||||
|
||||
from kingbird.api.controllers import restcomm
|
||||
from kingbird.common import consts
|
||||
from kingbird.common import exceptions
|
||||
from kingbird.common.i18n import _
|
|
@ -52,7 +52,7 @@ class KingbirdQMTestJSON(base.BaseKingbirdTest):
|
|||
expected_value = {
|
||||
self.resource_ids["target_project_id"]: new_quota["quota_set"]
|
||||
}
|
||||
self.assertEqual(expected_value, eval(actual_value))
|
||||
self.assertEqual(expected_value, actual_value)
|
||||
|
||||
def test_kingbird_get_another_tenant_quota(self):
|
||||
new_quota = {"quota_set": {"instances": 15, "cores": 10}}
|
||||
|
|
|
@ -19,7 +19,7 @@ from oslo_config import cfg
|
|||
|
||||
from kingbird.api.controllers.v1 import quota_class
|
||||
from kingbird.common import config
|
||||
from kingbird.tests.unit.api import testroot
|
||||
from kingbird.tests.unit.api import test_root_controller as testroot
|
||||
from kingbird.tests import utils
|
||||
|
||||
config.register_options()
|
|
@ -18,10 +18,10 @@ import webtest
|
|||
|
||||
from oslo_config import cfg
|
||||
|
||||
from kingbird.api.controllers import quota_manager
|
||||
from kingbird.api.controllers.v1 import quota_manager
|
||||
from kingbird.common import config
|
||||
from kingbird.rpc import client as rpc_client
|
||||
from kingbird.tests.unit.api import testroot
|
||||
from kingbird.tests.unit.api import test_root_controller as testroot
|
||||
from kingbird.tests import utils
|
||||
|
||||
config.register_options()
|
|
@ -18,10 +18,10 @@ import webtest
|
|||
|
||||
from oslo_utils import timeutils
|
||||
|
||||
from kingbird.api.controllers import sync_manager
|
||||
from kingbird.api.controllers.v1 import sync_manager
|
||||
from kingbird.common import consts
|
||||
from kingbird.rpc import client as rpc_client
|
||||
from kingbird.tests.unit.api import testroot
|
||||
from kingbird.tests.unit.api import test_root_controller as testroot
|
||||
from kingbird.tests import utils
|
||||
|
||||
DEFAULT_FORCE = False
|
|
@ -36,8 +36,7 @@ class DBAPIQuotaTest(base.KingbirdTestCase):
|
|||
def setup_dummy_db(self):
|
||||
options.cfg.set_defaults(options.database_opts,
|
||||
sqlite_synchronous=False)
|
||||
options.set_defaults(cfg.CONF, connection="sqlite://",
|
||||
sqlite_db='kingbird.db')
|
||||
options.set_defaults(cfg.CONF, connection="sqlite://")
|
||||
engine = get_engine()
|
||||
db_api.db_sync(engine)
|
||||
engine.connect()
|
||||
|
|
|
@ -37,8 +37,7 @@ class DBAPIResourceSyncTest(base.KingbirdTestCase):
|
|||
def setup_dummy_db(self):
|
||||
options.cfg.set_defaults(options.database_opts,
|
||||
sqlite_synchronous=False)
|
||||
options.set_defaults(cfg.CONF, connection="sqlite://",
|
||||
sqlite_db='kingbird.db')
|
||||
options.set_defaults(cfg.CONF, connection="sqlite://")
|
||||
engine = get_engine()
|
||||
db_api.db_sync(engine)
|
||||
engine.connect()
|
||||
|
|
|
@ -33,8 +33,7 @@ class ServiceRegistryTest(base.KingbirdTestCase):
|
|||
def setup_dummy_db(self):
|
||||
options.cfg.set_defaults(options.database_opts,
|
||||
sqlite_synchronous=False)
|
||||
options.set_defaults(cfg.CONF, connection="sqlite://",
|
||||
sqlite_db='kingbird.db')
|
||||
options.set_defaults(cfg.CONF, connection="sqlite://")
|
||||
engine = get_engine()
|
||||
db_api.db_sync(engine)
|
||||
engine.connect()
|
||||
|
|
|
@ -36,8 +36,7 @@ class DBAPISyncLockTest(base.KingbirdTestCase):
|
|||
def setup_dummy_db(self):
|
||||
options.cfg.set_defaults(options.database_opts,
|
||||
sqlite_synchronous=False)
|
||||
options.set_defaults(cfg.CONF, connection="sqlite://",
|
||||
sqlite_db='kingbird.db')
|
||||
options.set_defaults(cfg.CONF, connection="sqlite://")
|
||||
engine = get_engine()
|
||||
db_api.db_sync(engine)
|
||||
engine.connect()
|
||||
|
|
|
@ -53,8 +53,7 @@ def random_name():
|
|||
|
||||
def setup_dummy_db():
|
||||
options.cfg.set_defaults(options.database_opts, sqlite_synchronous=False)
|
||||
options.set_defaults(cfg.CONF, connection="sqlite://",
|
||||
sqlite_db='kingbird.db')
|
||||
options.set_defaults(cfg.CONF, connection="sqlite://")
|
||||
engine = get_engine()
|
||||
db_api.db_sync(engine)
|
||||
engine.connect()
|
||||
|
|
Loading…
Reference in New Issue