Add disk_allocation_ratio to ComputeNode
We forgot to provide the disk allocation ratio when moving RAM and CPU ratios. This change is persisting now the disk ratio to the DB and adds the object compat layer. Note: Since we need to provide a compatibility path for upgrades and as we don't want to ask the operators to change their config files before upgrading, we then verify the allocation ratio value to match if defaulted and then return an hardcoded value identitical to the behaviour we want. In order to know if the compute related opt values were updated, we plan to change the ratios defaults with 0.0 in a later change Change-Id: I6d8b75dd085003d36728880f93cf6db86e6cf1a5 Partially-Implements: blueprint disk-allocation-ratio-to-rt
This commit is contained in:
parent
03e34a10d8
commit
5d97e62d19
@ -0,0 +1,27 @@
|
||||
# Copyright (c) 2016 Red Hat, Inc.
|
||||
# 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.
|
||||
|
||||
|
||||
from sqlalchemy import Float, Column, MetaData, Table
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
meta = MetaData()
|
||||
meta.bind = migrate_engine
|
||||
|
||||
cn = Table('compute_nodes', meta, autoload=True)
|
||||
shadow_cn = Table('shadow_compute_nodes', meta, autoload=True)
|
||||
cn.create_column(Column('disk_allocation_ratio', Float, nullable=True))
|
||||
shadow_cn.create_column(Column('disk_allocation_ratio', Float))
|
@ -176,6 +176,7 @@ class ComputeNode(BASE, NovaBase, models.SoftDeleteMixin):
|
||||
# allocation ratios provided by the RT
|
||||
ram_allocation_ratio = Column(Float, nullable=True)
|
||||
cpu_allocation_ratio = Column(Float, nullable=True)
|
||||
disk_allocation_ratio = Column(Float, nullable=True)
|
||||
|
||||
|
||||
class Certificate(BASE, NovaBase, models.SoftDeleteMixin):
|
||||
|
@ -28,6 +28,7 @@ from nova.objects import pci_device_pool
|
||||
CONF = cfg.CONF
|
||||
CONF.import_opt('cpu_allocation_ratio', 'nova.compute.resource_tracker')
|
||||
CONF.import_opt('ram_allocation_ratio', 'nova.compute.resource_tracker')
|
||||
CONF.import_opt('disk_allocation_ratio', 'nova.compute.resource_tracker')
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -51,7 +52,8 @@ class ComputeNode(base.NovaPersistentObject, base.NovaObject,
|
||||
# Version 1.13: Changed service_id field to be nullable
|
||||
# Version 1.14: Added cpu_allocation_ratio and ram_allocation_ratio
|
||||
# Version 1.15: Added uuid
|
||||
VERSION = '1.15'
|
||||
# Version 1.16: Added disk_allocation_ratio
|
||||
VERSION = '1.16'
|
||||
|
||||
fields = {
|
||||
'id': fields.IntegerField(read_only=True),
|
||||
@ -91,11 +93,15 @@ class ComputeNode(base.NovaPersistentObject, base.NovaObject,
|
||||
nullable=True),
|
||||
'cpu_allocation_ratio': fields.FloatField(),
|
||||
'ram_allocation_ratio': fields.FloatField(),
|
||||
'disk_allocation_ratio': fields.FloatField(),
|
||||
}
|
||||
|
||||
def obj_make_compatible(self, primitive, target_version):
|
||||
super(ComputeNode, self).obj_make_compatible(primitive, target_version)
|
||||
target_version = versionutils.convert_version_to_tuple(target_version)
|
||||
if target_version < (1, 16):
|
||||
if 'disk_allocation_ratio' in primitive:
|
||||
del primitive['disk_allocation_ratio']
|
||||
if target_version < (1, 15):
|
||||
if 'uuid' in primitive:
|
||||
del primitive['uuid']
|
||||
@ -174,11 +180,13 @@ class ComputeNode(base.NovaPersistentObject, base.NovaObject,
|
||||
# As we want to care about our operators and since we don't want to
|
||||
# ask them to change their configuration files before upgrading, we
|
||||
# prefer to hardcode the default values for the ratios here until
|
||||
# the next release (Mitaka) where the opt default values will be
|
||||
# restored for both cpu (16.0) and ram (1.5) allocation ratios.
|
||||
# the next release (Newton) where the opt default values will be
|
||||
# restored for both cpu (16.0), ram (1.5) and disk (1.0)
|
||||
# allocation ratios.
|
||||
# TODO(sbauza): Remove that in the next major version bump where
|
||||
# we break compatibilility with old Kilo computes
|
||||
if key == 'cpu_allocation_ratio' or key == 'ram_allocation_ratio':
|
||||
# we break compatibilility with old Liberty computes
|
||||
if (key == 'cpu_allocation_ratio' or key == 'ram_allocation_ratio'
|
||||
or key == 'disk_allocation_ratio'):
|
||||
if value == 0.0:
|
||||
# Operator has not yet provided a new value for that ratio
|
||||
# on the compute node
|
||||
@ -194,6 +202,9 @@ class ComputeNode(base.NovaPersistentObject, base.NovaObject,
|
||||
if value == 0.0 and key == 'ram_allocation_ratio':
|
||||
# It's not specified either on the controller
|
||||
value = 1.5
|
||||
if value == 0.0 and key == 'disk_allocation_ratio':
|
||||
# It's not specified either on the controller
|
||||
value = 1.0
|
||||
compute[key] = value
|
||||
|
||||
stats = db_compute['stats']
|
||||
|
@ -198,6 +198,7 @@ class BaseTestCase(test.TestCase):
|
||||
'host': 'fake_phyp1',
|
||||
'cpu_allocation_ratio': 16.0,
|
||||
'ram_allocation_ratio': 1.5,
|
||||
'disk_allocation_ratio': 1.0,
|
||||
'host_ip': '127.0.0.1'}]
|
||||
return [objects.ComputeNode._from_db_object(
|
||||
context, objects.ComputeNode(), cn)
|
||||
|
@ -100,6 +100,7 @@ class MultiNodeComputeTestCase(BaseTestCase):
|
||||
'host': 'fake_phyp1',
|
||||
'cpu_allocation_ratio': None,
|
||||
'ram_allocation_ratio': None,
|
||||
'disk_allocation_ratio': None,
|
||||
'host_ip': '127.0.0.1'}]
|
||||
return [objects.ComputeNode._from_db_object(
|
||||
context, objects.ComputeNode(), cn)
|
||||
|
@ -280,6 +280,7 @@ class BaseTestCase(test.TestCase):
|
||||
'deleted': False,
|
||||
'cpu_allocation_ratio': None,
|
||||
'ram_allocation_ratio': None,
|
||||
'disk_allocation_ratio': None,
|
||||
}
|
||||
if values:
|
||||
compute.update(values)
|
||||
|
@ -74,6 +74,7 @@ _COMPUTE_NODE_FIXTURES = [
|
||||
numa_topology=None,
|
||||
cpu_allocation_ratio=16.0,
|
||||
ram_allocation_ratio=1.5,
|
||||
disk_allocation_ratio=1.0,
|
||||
),
|
||||
]
|
||||
|
||||
|
@ -7332,6 +7332,7 @@ class ComputeNodeTestCase(test.TestCase, ModelsObjectComparatorMixin):
|
||||
extra_resources='',
|
||||
cpu_allocation_ratio=16.0,
|
||||
ram_allocation_ratio=1.5,
|
||||
disk_allocation_ratio=1.0,
|
||||
stats='', numa_topology='')
|
||||
# add some random stats
|
||||
self.stats = dict(num_instances=3, num_proj_12345=2,
|
||||
|
@ -847,6 +847,10 @@ class NovaMigrationsCheckers(test_migrations.ModelsMigrationsSync,
|
||||
self.assertColumnExists(engine, 'migrations',
|
||||
'disk_remaining')
|
||||
|
||||
def _check_316(self, engine, data):
|
||||
self.assertColumnExists(engine, 'compute_nodes',
|
||||
'disk_allocation_ratio')
|
||||
|
||||
|
||||
class TestNovaMigrationsSQLite(NovaMigrationsCheckers,
|
||||
test_base.DbTestCase,
|
||||
|
@ -88,6 +88,7 @@ fake_compute_node = {
|
||||
'pci_stats': fake_pci,
|
||||
'cpu_allocation_ratio': 16.0,
|
||||
'ram_allocation_ratio': 1.5,
|
||||
'disk_allocation_ratio': 1.0,
|
||||
}
|
||||
# FIXME(sbauza) : For compatibility checking, to be removed once we are sure
|
||||
# that all computes are running latest DB version with host field in it.
|
||||
@ -456,39 +457,51 @@ class _TestComputeNodeObject(object):
|
||||
self.assertNotIn('cpu_allocation_ratio', primitive)
|
||||
self.assertNotIn('ram_allocation_ratio', primitive)
|
||||
|
||||
def test_compat_disk_allocation_ratio(self):
|
||||
compute = compute_node.ComputeNode()
|
||||
primitive = compute.obj_to_primitive(target_version='1.15')
|
||||
self.assertNotIn('disk_allocation_ratio', primitive)
|
||||
|
||||
def test_compat_allocation_ratios_old_compute(self):
|
||||
self.flags(cpu_allocation_ratio=2.0, ram_allocation_ratio=3.0)
|
||||
self.flags(cpu_allocation_ratio=2.0, ram_allocation_ratio=3.0,
|
||||
disk_allocation_ratio=0.9)
|
||||
compute_dict = fake_compute_node.copy()
|
||||
# old computes don't provide allocation ratios to the table
|
||||
compute_dict['cpu_allocation_ratio'] = None
|
||||
compute_dict['ram_allocation_ratio'] = None
|
||||
compute_dict['disk_allocation_ratio'] = None
|
||||
cls = objects.ComputeNode
|
||||
compute = cls._from_db_object(self.context, cls(), compute_dict)
|
||||
|
||||
self.assertEqual(2.0, compute.cpu_allocation_ratio)
|
||||
self.assertEqual(3.0, compute.ram_allocation_ratio)
|
||||
self.assertEqual(0.9, compute.disk_allocation_ratio)
|
||||
|
||||
def test_compat_allocation_ratios_default_values(self):
|
||||
compute_dict = fake_compute_node.copy()
|
||||
# new computes provide allocation ratios defaulted to 0.0
|
||||
compute_dict['cpu_allocation_ratio'] = 0.0
|
||||
compute_dict['ram_allocation_ratio'] = 0.0
|
||||
compute_dict['disk_allocation_ratio'] = 0.0
|
||||
cls = objects.ComputeNode
|
||||
compute = cls._from_db_object(self.context, cls(), compute_dict)
|
||||
|
||||
self.assertEqual(16.0, compute.cpu_allocation_ratio)
|
||||
self.assertEqual(1.5, compute.ram_allocation_ratio)
|
||||
self.assertEqual(1.0, compute.disk_allocation_ratio)
|
||||
|
||||
def test_compat_allocation_ratios_old_compute_default_values(self):
|
||||
compute_dict = fake_compute_node.copy()
|
||||
# old computes don't provide allocation ratios to the table
|
||||
compute_dict['cpu_allocation_ratio'] = None
|
||||
compute_dict['ram_allocation_ratio'] = None
|
||||
compute_dict['disk_allocation_ratio'] = None
|
||||
cls = objects.ComputeNode
|
||||
compute = cls._from_db_object(self.context, cls(), compute_dict)
|
||||
|
||||
self.assertEqual(16.0, compute.cpu_allocation_ratio)
|
||||
self.assertEqual(1.5, compute.ram_allocation_ratio)
|
||||
self.assertEqual(1.0, compute.disk_allocation_ratio)
|
||||
|
||||
|
||||
class TestComputeNodeObject(test_objects._LocalTest,
|
||||
|
@ -1106,7 +1106,7 @@ object_data = {
|
||||
'BlockDeviceMapping': '1.16-12319f6f47f740a67a88a23f7c7ee6ef',
|
||||
'BlockDeviceMappingList': '1.17-1e568eecb91d06d4112db9fd656de235',
|
||||
'CellMapping': '1.0-7f1a7e85a22bbb7559fc730ab658b9bd',
|
||||
'ComputeNode': '1.15-71bd34f7ababb634e9b4e8b51aa9ddef',
|
||||
'ComputeNode': '1.16-2436e5b836fa0306a3c4e6d9e5ddacec',
|
||||
'ComputeNodeList': '1.14-3b6f4f5ade621c40e70cb116db237844',
|
||||
'DNSDomain': '1.0-7b0b2dab778454b6a7b6c66afe163a1a',
|
||||
'DNSDomainList': '1.0-4ee0d9efdfd681fed822da88376e04d2',
|
||||
|
Loading…
Reference in New Issue
Block a user