Add upgrade status check for missing root ids

Starting in Queens with the 1.28 microversion, resource_providers
table has the root_provider_id column. Older resource_providers with
no root provider id records will be online migrated when accessed
via the REST API or when the
"placement-manage db online_data_migrations" command is run during
an upgrade. This status check emits a warning if there are missing
root provider ids to remind operators to perform the data migration.

Note that normally we would not add an upgrade status check to simply
mirror an online data migration since online data migrations should
be part of deploying/upgrading placement automation. However, with
placement being freshly extracted from nova, this check serves as a
friendly reminder.

Change-Id: I503c7d4e829407175992a90002646110aa9a323f
This commit is contained in:
Tetsuro Nakamura
2019-01-22 07:04:22 +00:00
parent 82fd23d8c2
commit 09c1318294
2 changed files with 65 additions and 0 deletions

View File

@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import sqlalchemy as sa
import sys
from oslo_config import cfg
@ -31,6 +32,37 @@ class Checks(upgradecheck.UpgradeCommands):
def __init__(self, config):
self.ctxt = context.RequestContext(config=config)
@db_api.placement_context_manager.reader
def _check_missing_root_ids(self, ctxt):
exists = sa.exists().where(
models.ResourceProvider.root_provider_id == sa.null())
ret = ctxt.session.query(exists).scalar()
return ret
def _check_root_provider_ids(self):
"""Starting in Queens with the 1.28 microversion, resource_providers
table has the root_provider_id column. Older resource_providers with
no root provider id records will be online migrated when accessed
via the REST API or when the
"placement-manage db online_data_migrations" command is run during
an upgrade. This status check emits a warning if there are missing
root provider ids to remind operators to perform the data migration.
Note that normally we would not add an upgrade status check to simply
mirror an online data migration since online data migrations should
be part of deploying/upgrading placement automation. However, with
placement being freshly extracted from nova, this check serves as a
friendly reminder.
"""
if self._check_missing_root_ids(self.ctxt):
return upgradecheck.Result(
upgradecheck.Code.WARNING,
details=_('There is at least one resource provider table '
'record which misses its root provider id. '
'Run the "placement-manage db '
'online_data_migrations" command.'))
return upgradecheck.Result(upgradecheck.Code.SUCCESS)
@db_api.placement_context_manager.reader
def _count_missing_consumers(self, ctxt):
# Count the total number of consumers.
@ -79,6 +111,7 @@ class Checks(upgradecheck.UpgradeCommands):
# in the returned Result's "details" attribute. The
# summary will be rolled up at the end of the check() method.
_upgrade_checks = (
(_('Missing Root Provider IDs'), _check_root_provider_ids),
(_('Incomplete Consumers'), _check_incomplete_consumers),
)

View File

@ -12,10 +12,13 @@
from oslo_config import cfg
from oslo_upgradecheck import upgradecheck
from oslo_utils.fixture import uuidsentinel
from placement.cmd import status
from placement import conf
from placement import db_api
from placement.objects import consumer
from placement.objects import resource_provider
from placement.tests.functional import base
from placement.tests.functional.db import test_consumer
@ -46,3 +49,32 @@ class UpgradeCheckIncompleteConsumersTestCase(
# Run the check again and it should be successful.
result = self.checks._check_incomplete_consumers()
self.assertEqual(upgradecheck.Code.SUCCESS, result.code)
def test_check_root_provider_ids(self):
@db_api.placement_context_manager.writer
def _create_old_rp(ctx):
rp_tbl = resource_provider._RP_TBL
ins_stmt1 = rp_tbl.insert().values(
id=1,
uuid=uuidsentinel.rp1,
name='rp-1',
root_provider_id=None,
parent_provider_id=None,
generation=42,
)
ctx.session.execute(ins_stmt1)
# Create a resource provider with no root provider id.
_create_old_rp(self.context)
result = self.checks._check_root_provider_ids()
# Since there is a missing root id, there should be a warning.
self.assertEqual(upgradecheck.Code.WARNING, result.code)
# Check the details for the consumer count.
self.assertIn('There is at least one resource provider table record '
'which misses its root provider id. ', result.details)
# Run the online data migration as recommended from the check output.
resource_provider.set_root_provider_ids(self.context, batch_size=50)
# Run the check again and it should be successful.
result = self.checks._check_root_provider_ids()
self.assertEqual(upgradecheck.Code.SUCCESS, result.code)