Browse Source

Make sure the policy upgrade check get a valid config

Placement does not use global CONF object. However when the policy
upgrade check was added in Ia7365cc3ae09e2ff916ab9f9ff0ba4fef0dc446b it
was referred to the global CONF object. However in placement it is not
initialized. Therefore the $ placement-status upgrade check fails with

This patch makes sure that the policy upgrade check uses an initialized
config object instead.

Story: 2008831
Task: 42313

Change-Id: I7ef81df6ffa2eac96067b6c0370bd9792014e9cd
(cherry picked from commit 992dd6a70679eb82cb47b734db2528fc747cb99d)
Balazs Gibizer 4 weeks ago
2 changed files with 9 additions and 6 deletions
  1. +8
  2. +1

+ 8
- 2
placement/cmd/ View File

@ -30,6 +30,7 @@ class Checks(upgradecheck.UpgradeCommands):
and added to _upgrade_checks tuple.
def __init__(self, config):
self.config = config
self.ctxt = context.RequestContext(config=config)
@ -96,6 +97,12 @@ class Checks(upgradecheck.UpgradeCommands):
# No missing consumers (or no allocations [fresh install?]) so it's OK.
return upgradecheck.Result(upgradecheck.Code.SUCCESS)
def _check_policy_json(self):
"""A wrapper passing a proper config object when calling the generic
policy json check.
return common_checks.check_policy_json(self, self.config)
# The format of the check functions is to return an
# oslo_upgradecheck.upgradecheck.Result
# object with the appropriate
@ -106,8 +113,7 @@ class Checks(upgradecheck.UpgradeCommands):
_upgrade_checks = (
('Missing Root Provider IDs', _check_root_provider_ids),
('Incomplete Consumers', _check_incomplete_consumers),
("Policy File JSON to YAML Migration",
(common_checks.check_policy_json, {'conf': cfg.CONF})),
("Policy File JSON to YAML Migration", _check_policy_json),

+ 1
- 4
placement/tests/functional/cmd/ View File

@ -81,7 +81,4 @@ class UpgradeCheckIncompleteConsumersTestCase(
self.assertEqual(upgradecheck.Code.SUCCESS, result.code)
def test_all_registered_check_is_runnable(self):
# this is bug story/2008831
self.assertRaises(cfg.NotInitializedError, self.checks.check)
# after it is fixed we expect that all the checks succeeds
# self.assertEquals(upgradecheck.Code.SUCCESS, self.checks.check())
self.assertEqual(upgradecheck.Code.SUCCESS, self.checks.check())