From 992dd6a70679eb82cb47b734db2528fc747cb99d Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Tue, 20 Apr 2021 18:32:57 +0200 Subject: [PATCH] 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 oslo_config.cfg.NotInitializedError. This patch makes sure that the policy upgrade check uses an initialized config object instead. Story: 2008831 Task: 42313 Change-Id: I7ef81df6ffa2eac96067b6c0370bd9792014e9cd --- placement/cmd/status.py | 10 ++++++++-- placement/tests/functional/cmd/test_status.py | 5 +---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/placement/cmd/status.py b/placement/cmd/status.py index 721d17dcb..7ac2ad9e5 100644 --- a/placement/cmd/status.py +++ b/placement/cmd/status.py @@ -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) @db_api.placement_context_manager.reader @@ -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), ) diff --git a/placement/tests/functional/cmd/test_status.py b/placement/tests/functional/cmd/test_status.py index a763b6862..a276f08f3 100644 --- a/placement/tests/functional/cmd/test_status.py +++ b/placement/tests/functional/cmd/test_status.py @@ -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())