Drop redundant get_string_type

The method always returns str type, since Python 2 support was removed.

Change-Id: Id200b60d4615eef573e6c86be4661f61e25fb0de
Signed-off-by: Takashi Kajinami <kajinamit@oss.nttdata.com>
This commit is contained in:
Takashi Kajinami
2026-01-06 23:26:16 +09:00
parent 11ccbe8488
commit 76e7970f5b
7 changed files with 29 additions and 60 deletions

View File

@@ -23,7 +23,6 @@ from cloudkitty.api.v2 import base
from cloudkitty.api.v2 import utils as api_utils
from cloudkitty.common import policy
from cloudkitty import utils as ck_utils
from cloudkitty.utils import validation as vutils
PROCESSORS_NAMESPACE = 'cloudkitty.rating.processors'
@@ -32,11 +31,11 @@ MODULE_SCHEMA = {
voluptuous.Required(
'description',
default=None,
): vutils.get_string_type(),
): str,
voluptuous.Required(
'module_id',
default=None,
): vutils.get_string_type(),
): str,
voluptuous.Required(
'enabled',
default=None,

View File

@@ -22,7 +22,6 @@ from cloudkitty.common import policy
from cloudkitty import messaging
from cloudkitty import storage_state
from cloudkitty.utils import tz as tzutils
from cloudkitty.utils import validation as vutils
from oslo_log import log
@@ -51,15 +50,13 @@ class ScopeState(base.BaseResource):
api_utils.MultiQueryParam(int),
})
@api_utils.add_output_schema({'results': [{
voluptuous.Required('scope_id'): vutils.get_string_type(),
voluptuous.Required('scope_key'): vutils.get_string_type(),
voluptuous.Required('fetcher'): vutils.get_string_type(),
voluptuous.Required('collector'): vutils.get_string_type(),
voluptuous.Optional(
'last_processed_timestamp'): vutils.get_string_type(),
voluptuous.Required('scope_id'): str,
voluptuous.Required('scope_key'): str,
voluptuous.Required('fetcher'): str,
voluptuous.Required('collector'): str,
voluptuous.Optional('last_processed_timestamp'): str,
voluptuous.Required('active'): bool,
voluptuous.Optional('scope_activation_toggle_date'):
vutils.get_string_type(),
voluptuous.Optional('scope_activation_toggle_date'): str,
}]})
def get(self, offset=0, limit=100, scope_id=None, scope_key=None,
fetcher=None, collector=None, active=None):
@@ -165,15 +162,14 @@ class ScopeState(base.BaseResource):
api_utils.SingleQueryParam(bool),
})
@api_utils.add_output_schema({
voluptuous.Required('scope_id'): vutils.get_string_type(),
voluptuous.Required('scope_key'): vutils.get_string_type(),
voluptuous.Required('fetcher'): vutils.get_string_type(),
voluptuous.Required('collector'): vutils.get_string_type(),
voluptuous.Required('scope_id'): str,
voluptuous.Required('scope_key'): str,
voluptuous.Required('fetcher'): str,
voluptuous.Required('collector'): str,
voluptuous.Optional('last_processed_timestamp'):
voluptuous.Coerce(tzutils.dt_from_iso),
voluptuous.Required('active'): bool,
voluptuous.Required('scope_activation_toggle_date'):
vutils.get_string_type()
voluptuous.Required('scope_activation_toggle_date'): str,
})
def patch(self, scope_id, scope_key=None, fetcher=None,
collector=None, active=None):
@@ -234,15 +230,13 @@ class ScopeState(base.BaseResource):
voluptuous.Coerce(tzutils.dt_from_iso),
})
@api_utils.add_output_schema({
voluptuous.Required('scope_id'): vutils.get_string_type(),
voluptuous.Required('scope_key'): vutils.get_string_type(),
voluptuous.Required('fetcher'): vutils.get_string_type(),
voluptuous.Required('collector'): vutils.get_string_type(),
voluptuous.Required('last_processed_timestamp'):
vutils.get_string_type(),
voluptuous.Required('scope_id'): str,
voluptuous.Required('scope_key'): str,
voluptuous.Required('fetcher'): str,
voluptuous.Required('collector'): str,
voluptuous.Required('last_processed_timestamp'): str,
voluptuous.Required('active'): bool,
voluptuous.Required('scope_activation_toggle_date'):
vutils.get_string_type()
voluptuous.Required('scope_activation_toggle_date'): str,
})
def post(self, scope_id, scope_key=None, fetcher=None, collector=None,
active=None, last_processed_timestamp=None):

View File

@@ -24,7 +24,6 @@ from cloudkitty.common import policy
from cloudkitty import storage_state
from cloudkitty.storage_state.models import ReprocessingScheduler
from cloudkitty.utils import tz as tzutils
from cloudkitty.utils import validation as validation_utils
from oslo_config import cfg
@@ -257,14 +256,11 @@ class ReprocessSchedulerGetApi(base.BaseResource):
api_utils.SingleQueryParam(str)
})
@api_utils.add_output_schema({'results': [{
voluptuous.Required('reason'): validation_utils.get_string_type(),
voluptuous.Required('scope_id'): validation_utils.get_string_type(),
voluptuous.Required('start_reprocess_time'):
validation_utils.get_string_type(),
voluptuous.Required('end_reprocess_time'):
validation_utils.get_string_type(),
voluptuous.Required('current_reprocess_time'):
validation_utils.get_string_type(),
voluptuous.Required('reason'): str,
voluptuous.Required('scope_id'): str,
voluptuous.Required('start_reprocess_time'): str,
voluptuous.Required('end_reprocess_time'): str,
voluptuous.Required('current_reprocess_time'): str,
}]})
def get(self, scope_ids=[], path_scope_id=None, offset=0, limit=100,
order="desc"):

View File

@@ -31,10 +31,6 @@ class SingleQueryParam(object):
verifies its type and returns it directly, instead of returning a list
containing a single element.
Note that this validator uses ``voluptuous.Coerce`` internally and thus
should not be used together with
``cloudkitty.utils.validation.get_string_type`` in python2.
:param param_type: Type of the query parameter
"""
def __init__(self, param_type):
@@ -56,10 +52,6 @@ class MultiQueryParam(object):
verifies their type and returns it directly, instead of returning a list
containing a single element.
Note that this validator uses ``voluptuous.Coerce`` internally and thus
should not be used together with
``cloudkitty.utils.validation.get_string_type`` in python2.
:param param_type: Type of the query parameter
"""
def __init__(self, param_type):
@@ -225,7 +217,7 @@ def paginated(func):
voluptuous.Required(
'message',
default='This is an example endpoint',
): validation_utils.get_string_type(),
): str,
})
def get(self, offset=0, limit=100):
# [...]
@@ -249,7 +241,7 @@ def add_output_schema(schema):
voluptuous.Required(
'message',
default='This is an example endpoint',
): validation_utils.get_string_type(),
): str,
})
def get(self):
return {}

View File

@@ -30,7 +30,7 @@ from cloudkitty.utils import validation as vutils
# Decimal(str(0.121)) == Decimal('0.121')
DATAPOINT_SCHEMA = voluptuous.Schema({
voluptuous.Required('vol'): {
voluptuous.Required('unit'): vutils.get_string_type(),
voluptuous.Required('unit'): str,
voluptuous.Required('qty'): voluptuous.Coerce(str),
},
voluptuous.Required('rating', default={}): {

View File

@@ -85,8 +85,3 @@ class IterableValuesDict(DictTypeValidator):
except (TypeError, ValueError) as e:
raise voluptuous.Invalid(
"{} can't be converted to a dict: {}".format(item, e))
def get_string_type():
"""Returns ``basestring`` in python2 and ``str`` in python3."""
return str

View File

@@ -90,15 +90,12 @@ Let's update our ``get`` method in order to use this decorator:
voluptuous.Required(
'message',
default='This is an example endpoint',
): validation_utils.get_string_type(),
): str,
})
def get(self):
return {}
.. note:: In this snippet, ``get_string_type`` returns ``basestring`` in
python2 and ``str`` in python3.
.. code-block:: console
$ curl 'http://cloudkitty-api:8889/v2/example'
@@ -118,7 +115,7 @@ exceptions for HTTP return codes.
.. code-block:: python
@api_utils.add_input_schema('body', {
voluptuous.Required('fruit'): validation_utils.get_string_type(),
voluptuous.Required('fruit'): str,
})
def post(self, fruit=None):
policy.authorize(flask.request.context, 'example:submit_fruit', {})
@@ -161,10 +158,6 @@ parameter is provided only once, and returns it.
.. autoclass:: cloudkitty.api.v2.utils.SingleQueryParam
:noindex:
.. warning:: ``SingleQueryParam`` uses ``voluptuous.Coerce`` internally for
type checking. Thus, ``validation_utils.get_string_type`` cannot
be used as ``basestring`` can't be instantiated.
Authorising methods
-------------------