Move db MAX constants to own file
The "MAX" constants in the db api are useful to import without needing to import the rest of the api, so they are moved to a constants.py file in the same package. api.py then imports the symbols from that file for backwards compatibility. The handler and schema for placement inventories (which use the MAX constants) are updated to point to the constants file directly as they do not need the db api. Change-Id: Ifab10e023bcf4389f6514b477755c4cced2d1598
This commit is contained in:
parent
e4b2eb3049
commit
431eaf6edb
@ -22,7 +22,7 @@ from nova.api.openstack.placement import microversion
|
||||
from nova.api.openstack.placement.schemas import inventory as schema
|
||||
from nova.api.openstack.placement import util
|
||||
from nova.api.openstack.placement import wsgi_wrapper
|
||||
from nova import db
|
||||
from nova.db import constants as db_const
|
||||
from nova import exception
|
||||
from nova.i18n import _
|
||||
from nova.objects import resource_provider as rp_obj
|
||||
@ -42,7 +42,7 @@ OUTPUT_INVENTORY_FIELDS = [
|
||||
INVENTORY_DEFAULTS = {
|
||||
'reserved': 0,
|
||||
'min_unit': 1,
|
||||
'max_unit': db.MAX_INT,
|
||||
'max_unit': db_const.MAX_INT,
|
||||
'step_size': 1,
|
||||
'allocation_ratio': 1.0
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
import copy
|
||||
|
||||
from nova import db
|
||||
from nova.db import constants as db_const
|
||||
|
||||
|
||||
RESOURCE_CLASS_IDENTIFIER = "^[A-Z0-9_]+$"
|
||||
@ -25,32 +25,32 @@ BASE_INVENTORY_SCHEMA = {
|
||||
},
|
||||
"total": {
|
||||
"type": "integer",
|
||||
"maximum": db.MAX_INT,
|
||||
"maximum": db_const.MAX_INT,
|
||||
"minimum": 1,
|
||||
},
|
||||
"reserved": {
|
||||
"type": "integer",
|
||||
"maximum": db.MAX_INT,
|
||||
"maximum": db_const.MAX_INT,
|
||||
"minimum": 0,
|
||||
},
|
||||
"min_unit": {
|
||||
"type": "integer",
|
||||
"maximum": db.MAX_INT,
|
||||
"maximum": db_const.MAX_INT,
|
||||
"minimum": 1
|
||||
},
|
||||
"max_unit": {
|
||||
"type": "integer",
|
||||
"maximum": db.MAX_INT,
|
||||
"maximum": db_const.MAX_INT,
|
||||
"minimum": 1
|
||||
},
|
||||
"step_size": {
|
||||
"type": "integer",
|
||||
"maximum": db.MAX_INT,
|
||||
"maximum": db_const.MAX_INT,
|
||||
"minimum": 1
|
||||
},
|
||||
"allocation_ratio": {
|
||||
"type": "number",
|
||||
"maximum": db.SQL_SP_FLOAT_MAX
|
||||
"maximum": db_const.SQL_SP_FLOAT_MAX
|
||||
},
|
||||
},
|
||||
"required": [
|
||||
|
@ -32,9 +32,14 @@ from oslo_log import log as logging
|
||||
|
||||
from nova.cells import rpcapi as cells_rpcapi
|
||||
import nova.conf
|
||||
from nova.db import constants
|
||||
|
||||
|
||||
CONF = nova.conf.CONF
|
||||
# NOTE(cdent): These constants are re-defined in this module to preserve
|
||||
# existing references to them.
|
||||
MAX_INT = constants.MAX_INT
|
||||
SQL_SP_FLOAT_MAX = constants.SQL_SP_FLOAT_MAX
|
||||
|
||||
_BACKEND_MAPPING = {'sqlalchemy': 'nova.db.sqlalchemy.api'}
|
||||
|
||||
@ -43,17 +48,6 @@ IMPL = concurrency.TpoolDbapiWrapper(CONF, backend_mapping=_BACKEND_MAPPING)
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
# The maximum value a signed INT type may have
|
||||
MAX_INT = 0x7FFFFFFF
|
||||
|
||||
# NOTE(dosaboy): This is supposed to represent the maximum value that we can
|
||||
# place into a SQL single precision float so that we can check whether values
|
||||
# are oversize. Postgres and MySQL both define this as their max whereas Sqlite
|
||||
# uses dynamic typing so this would not apply. Different dbs react in different
|
||||
# ways to oversize values e.g. postgres will raise an exception while mysql
|
||||
# will round off the value. Nevertheless we may still want to know prior to
|
||||
# insert whether the value is oversize or not.
|
||||
SQL_SP_FLOAT_MAX = 3.40282e+38
|
||||
|
||||
###################
|
||||
|
||||
|
25
nova/db/constants.py
Normal file
25
nova/db/constants.py
Normal file
@ -0,0 +1,25 @@
|
||||
# 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.
|
||||
"""Useful db-related constants. In their own file so they can be imported
|
||||
cleanly."""
|
||||
|
||||
# The maximum value a signed INT type may have
|
||||
MAX_INT = 0x7FFFFFFF
|
||||
|
||||
# NOTE(dosaboy): This is supposed to represent the maximum value that we can
|
||||
# place into a SQL single precision float so that we can check whether values
|
||||
# are oversize. Postgres and MySQL both define this as their max whereas Sqlite
|
||||
# uses dynamic typing so this would not apply. Different dbs react in different
|
||||
# ways to oversize values e.g. postgres will raise an exception while mysql
|
||||
# will round off the value. Nevertheless we may still want to know prior to
|
||||
# insert whether the value is oversize or not.
|
||||
SQL_SP_FLOAT_MAX = 3.40282e+38
|
Loading…
x
Reference in New Issue
Block a user