Merge "Remove deprecated APIs and method in cloudkitty"

This commit is contained in:
Zuul 2017-12-12 21:56:35 +00:00 committed by Gerrit Code Review
commit e3ea773448
28 changed files with 56 additions and 582 deletions

View File

@ -1,41 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Objectif Libre
#
# 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.
#
# @author: Stéphane Albert
#
import warnings
from cloudkitty.api.v1.controllers import rating as rating_api
from cloudkitty.api.v1.controllers.rating import ModulesController # noqa
from cloudkitty.api.v1.controllers.rating import ModulesExposer # noqa
from cloudkitty.api.v1.controllers.rating import UnconfigurableController # noqa
def deprecated():
warnings.warn(
('The billing controllers are deprecated. '
'Please use rating\'s one instead.'),
DeprecationWarning,
stacklevel=3)
deprecated()
class BillingController(rating_api.RatingController):
"""The BillingController is exposed by the API.
Deprecated, replaced by the RatingController.
"""

View File

@ -1,31 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Objectif Libre
#
# 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.
#
# @author: Stéphane Albert
#
import warnings
from cloudkitty.api.v1.datamodels.rating import * # noqa
def deprecated():
warnings.warn(
('The billing datamodels are deprecated. '
'Please use rating\'s one instead.'),
DeprecationWarning,
stacklevel=3)
deprecated()

View File

@ -1,38 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Objectif Libre
#
# 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.
#
# @author: Stéphane Albert
#
import warnings
from cloudkitty import rating
def deprecated():
warnings.warn(
('The billing processors are deprecated. '
'Please use rating\'s one instead.'),
DeprecationWarning,
stacklevel=3)
deprecated()
class BillingProcessorBase(rating.RatingProcessorBase):
"""Provides the Cloudkitty integration code to the billing processors.
Deprecated, please use RatingProcessorBase.
"""

View File

@ -1,31 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Objectif Libre
#
# 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.
#
# @author: Stéphane Albert
#
import warnings
from cloudkitty.api.v1.datamodels.rating import * # noqa
def deprecated():
warnings.warn(
('The hashmap billing processors are deprecated. '
'Please use rating\'s one instead.'),
DeprecationWarning,
stacklevel=3)
deprecated()

View File

@ -1,31 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Objectif Libre
#
# 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.
#
# @author: Stéphane Albert
#
import warnings
from cloudkitty.rating.hash.controllers import * # noqa
def deprecated():
warnings.warn(
('The hashmap billing controllers are deprecated. '
'Please use rating\'s one instead.'),
DeprecationWarning,
stacklevel=3)
deprecated()

View File

@ -1,18 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Objectif Libre
#
# 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.
#
# @author: Stéphane Albert
#
from cloudkitty.rating.hash.controllers.field import * # noqa

View File

@ -1,18 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Objectif Libre
#
# 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.
#
# @author: Stéphane Albert
#
from cloudkitty.rating.hash.controllers.group import * # noqa

View File

@ -1,18 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Objectif Libre
#
# 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.
#
# @author: Stéphane Albert
#
from cloudkitty.rating.hash.controllers.mapping import * # noqa

View File

@ -1,18 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Objectif Libre
#
# 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.
#
# @author: Stéphane Albert
#
from cloudkitty.rating.hash.controllers.root import * # noqa

View File

@ -1,18 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Objectif Libre
#
# 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.
#
# @author: Stéphane Albert
#
from cloudkitty.rating.hash.controllers.service import * # noqa

View File

@ -1,31 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Objectif Libre
#
# 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.
#
# @author: Stéphane Albert
#
import warnings
from cloudkitty.rating.hash.datamodels import * # noqa
def deprecated():
warnings.warn(
('The hashmap billing datamodels are deprecated. '
'Please use rating\'s one instead.'),
DeprecationWarning,
stacklevel=3)
deprecated()

View File

@ -1,18 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Objectif Libre
#
# 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.
#
# @author: Stéphane Albert
#
from cloudkitty.rating.hash.datamodels.field import * # noqa

View File

@ -1,18 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Objectif Libre
#
# 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.
#
# @author: Stéphane Albert
#
from cloudkitty.rating.hash.datamodels.group import * # noqa

View File

@ -1,18 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Objectif Libre
#
# 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.
#
# @author: Stéphane Albert
#
from cloudkitty.rating.hash.datamodels.mapping import * # noqa

View File

@ -1,18 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Objectif Libre
#
# 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.
#
# @author: Stéphane Albert
#
from cloudkitty.rating.hash.datamodels.service import * # noqa

View File

@ -1,31 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Objectif Libre
#
# 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.
#
# @author: Stéphane Albert
#
import warnings
from cloudkitty.rating.hash.db import * # noqa
def deprecated():
warnings.warn(
('The hashmap db API is deprecated. '
'Please use rating\'s one instead.'),
DeprecationWarning,
stacklevel=3)
deprecated()

View File

@ -1,18 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Objectif Libre
#
# 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.
#
# @author: Stéphane Albert
#
from cloudkitty.rating.hash.db.api import * # noqa

View File

@ -1,31 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Objectif Libre
#
# 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.
#
# @author: Stéphane Albert
#
import warnings
from cloudkitty.rating.hash.db.sqlalchemy import * # noqa
def deprecated():
warnings.warn(
('The hashmap db API is deprecated. '
'Please use rating\'s one instead.'),
DeprecationWarning,
stacklevel=3)
deprecated()

View File

@ -1,18 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Objectif Libre
#
# 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.
#
# @author: Stéphane Albert
#
from cloudkitty.rating.hash.db.api.sqlalchemy.api import * # noqa

View File

@ -1,18 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Objectif Libre
#
# 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.
#
# @author: Stéphane Albert
#
from cloudkitty.rating.hash.db.api.sqlalchemy.migration import * # noqa

View File

@ -1,18 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Objectif Libre
#
# 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.
#
# @author: Stéphane Albert
#
from cloudkitty.rating.hash.db.api.sqlalchemy.models import * # noqa

View File

@ -1,18 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Objectif Libre
#
# 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.
#
# @author: Stéphane Albert
#
from cloudkitty.rating.noop import * # noqa

View File

@ -42,7 +42,7 @@ class MetaCollector(collector.BaseCollector):
self._mappings[db_mapping.service] = db_mapping.collector
def _check_enabled(self, name):
enable_state = db_api.get_instance().get_module_enable_state()
enable_state = db_api.get_instance().get_module_info()
return enable_state.get_state('collector_{}'.format(name))
def _load_collectors(self):

View File

@ -71,28 +71,7 @@ class State(object):
@six.add_metaclass(abc.ABCMeta)
class ModuleEnableState(object):
"""Base class for module state management."""
@abc.abstractmethod
def get_state(self, name):
"""Retrieve the module state.
:param name: Name of the module
:return bool: State of the module
"""
@abc.abstractmethod
def set_state(self, name, state):
"""Set the module state.
:param name: Name of the module
:param value: State of the module
"""
@six.add_metaclass(abc.ABCMeta)
class ModuleInfo(ModuleEnableState):
class ModuleInfo(object):
"""Base class for module info management."""
@abc.abstractmethod
@ -111,6 +90,22 @@ class ModuleInfo(ModuleEnableState):
:param priority: New priority of the module
"""
@abc.abstractmethod
def get_state(self, name):
"""Retrieve the module state.
:param name: Name of the module
:return bool: State of the module
"""
@abc.abstractmethod
def set_state(self, name, state):
"""Set the module state.
:param name: Name of the module
:param value: State of the module
"""
class NoSuchMapping(Exception):
"""Raised when the mapping doesn't exist."""

View File

@ -81,40 +81,7 @@ class State(api.State):
session.add(db_state)
class ModuleEnableState(api.ModuleEnableState):
"""Deprecated, use ModuleInfo instead.
"""
def get_state(self, name):
session = db.get_session()
try:
q = utils.model_query(
models.ModuleStateInfo,
session)
q = q.filter(models.ModuleStateInfo.name == name)
res = q.value(models.ModuleStateInfo.state)
return bool(res)
except sqlalchemy.orm.exc.NoResultFound:
return None
def set_state(self, name, state):
session = db.get_session()
with session.begin():
try:
q = utils.model_query(
models.ModuleStateInfo,
session)
q = q.filter(models.ModuleStateInfo.name == name)
q = q.with_lockmode('update')
db_state = q.one()
db_state.state = state
except sqlalchemy.orm.exc.NoResultFound:
db_state = models.ModuleStateInfo(name=name, state=state)
session.add(db_state)
return bool(db_state.state)
class ModuleInfo(ModuleEnableState):
class ModuleInfo(api.ModuleInfo):
"""Base class for module info management."""
def get_priority(self, name):
@ -147,6 +114,34 @@ class ModuleInfo(ModuleEnableState):
session.add(db_state)
return int(db_state.priority)
def get_state(self, name):
session = db.get_session()
try:
q = utils.model_query(
models.ModuleStateInfo,
session)
q = q.filter(models.ModuleStateInfo.name == name)
res = q.value(models.ModuleStateInfo.state)
return bool(res)
except sqlalchemy.orm.exc.NoResultFound:
return None
def set_state(self, name, state):
session = db.get_session()
with session.begin():
try:
q = utils.model_query(
models.ModuleStateInfo,
session)
q = q.filter(models.ModuleStateInfo.name == name)
q = q.with_lockmode('update')
db_state = q.one()
db_state.state = state
except sqlalchemy.orm.exc.NoResultFound:
db_state = models.ModuleStateInfo(name=name, state=state)
session.add(db_state)
return bool(db_state.state)
class ServiceToCollectorMapping(object):
"""Base class for service to collector mapping."""
@ -222,10 +217,6 @@ class DBAPIManager(object):
def get_state():
return State()
@staticmethod
def get_module_enable_state():
return ModuleEnableState()
@staticmethod
def get_module_info():
return ModuleInfo()

View File

@ -60,7 +60,7 @@ class RatingProcessorBase(object):
:returns: bool if module is enabled
"""
api = db_api.get_instance()
module_db = api.get_module_enable_state()
module_db = api.get_module_info()
return module_db.get_state(self.module_name) or False
@property

View File

@ -78,7 +78,7 @@ class RatingTest(tests.TestCase):
rpcmock.return_value = self._fake_rpc
self._module.set_state(True)
db_api = ck_db_api.get_instance()
module_db = db_api.get_module_enable_state()
module_db = db_api.get_module_info()
self.assertTrue(module_db.get_state('fake'))
def test_disable_module(self):
@ -86,12 +86,12 @@ class RatingTest(tests.TestCase):
rpcmock.return_value = self._fake_rpc
self._module.set_state(False)
db_api = ck_db_api.get_instance()
module_db = db_api.get_module_enable_state()
module_db = db_api.get_module_info()
self.assertFalse(module_db.get_state('fake'))
def test_enabled_property(self):
db_api = ck_db_api.get_instance()
module_db = db_api.get_module_enable_state()
module_db = db_api.get_module_info()
module_db.set_state('fake', True)
self.assertTrue(self._module.enabled)
module_db.set_state('fake', False)

View File

@ -0,0 +1,5 @@
---
other:
- |
The deprecated 'Billing' API endpoint has been removed, and its code has
been deleted from the CloudKitty repository.