From: Adam King Date: Fri, 1 Apr 2022 12:20:28 +0000 (-0400) Subject: mgr/cephadm: make UpgradeState from_json a bit safer X-Git-Tag: v18.0.0~842^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=aeaa0b5fd87068a31bfa61dd088c49affce42419;p=ceph.git 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 --- diff --git a/src/pybind/mgr/cephadm/upgrade.py b/src/pybind/mgr/cephadm/upgrade.py index c4e4f74b278d..b3c9d3d15410 100644 --- a/src/pybind/mgr/cephadm/upgrade.py +++ b/src/pybind/mgr/cephadm/upgrade.py @@ -87,8 +87,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)