From 412bd3b20b3953d630b2ec8cf51a6b69bcda30a6 Mon Sep 17 00:00:00 2001 From: Adam King Date: Fri, 1 Apr 2022 08:20:28 -0400 Subject: [PATCH] mgr/cephadm: make UpgradeState from_json a bit safer This way, for downgrades to whatever versions this lands in onward, having added new parameters to UpgradeState shouldn't break anything. Can't do much about downgrades to older versions from this one but this should help in the future. Signed-off-by: Adam King (cherry picked from commit aeaa0b5fd87068a31bfa61dd088c49affce42419) --- src/pybind/mgr/cephadm/upgrade.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/cephadm/upgrade.py b/src/pybind/mgr/cephadm/upgrade.py index cd2aa6cc6d6aa..70b09be1b9cb9 100644 --- a/src/pybind/mgr/cephadm/upgrade.py +++ b/src/pybind/mgr/cephadm/upgrade.py @@ -86,8 +86,9 @@ class UpgradeState: @classmethod def from_json(cls, data: dict) -> Optional['UpgradeState']: + valid_params = UpgradeState.__init__.__code__.co_varnames if data: - c = {k: v for k, v in data.items()} + c = {k: v for k, v in data.items() if k in valid_params} if 'repo_digest' in c: c['target_digests'] = [c.pop('repo_digest')] return cls(**c) -- 2.39.5