diff options
author | lucasmoura <lucas.moura@canonical.com> | 2021-04-12 13:22:22 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-12 12:22:22 -0400 |
commit | 83f6bbfbe5b924be61a3c098f4202377d69c8947 (patch) | |
tree | 0a6f8f9c0ec95b554774e94784977689b2629f2f /cloudinit | |
parent | fb38aa591bca82b7aa89187695a2bff676d687cb (diff) | |
download | vyos-cloud-init-83f6bbfbe5b924be61a3c098f4202377d69c8947.tar.gz vyos-cloud-init-83f6bbfbe5b924be61a3c098f4202377d69c8947.zip |
Fix unpickle for source paths missing run_dir (#863)
On the datasource class, we require the use of paths.run_dir to
perform some operations. On older cloud-init version, the
Paths class does not have the run_dir attribute. To fix that,
we are now manually adding that attribute in the Paths
object if doesn't exist in the unpickle operation.
LP: #1899299
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/helpers.py | 17 | ||||
-rw-r--r-- | cloudinit/tests/test_upgrade.py | 3 |
2 files changed, 19 insertions, 1 deletions
diff --git a/cloudinit/helpers.py b/cloudinit/helpers.py index fc5011ec..b8f9d2c3 100644 --- a/cloudinit/helpers.py +++ b/cloudinit/helpers.py @@ -20,6 +20,7 @@ from cloudinit.settings import (PER_INSTANCE, PER_ALWAYS, PER_ONCE, from cloudinit import log as logging from cloudinit import type_utils +from cloudinit import persistence from cloudinit import util LOG = logging.getLogger(__name__) @@ -317,7 +318,9 @@ class ContentHandlers(object): return list(self.registered.items()) -class Paths(object): +class Paths(persistence.CloudInitPickleMixin): + _ci_pkl_version = 1 + def __init__(self, path_cfgs, ds=None): self.cfgs = path_cfgs # Populate all the initial paths @@ -354,6 +357,18 @@ class Paths(object): # Set when a datasource becomes active self.datasource = ds + def _unpickle(self, ci_pkl_version: int) -> None: + """Perform deserialization fixes for Paths.""" + if not hasattr(self, "run_dir"): + # On older versions of cloud-init the Paths class do not + # have the run_dir attribute. This is problematic because + # when loading the pickle object on newer versions of cloud-init + # we will rely on this attribute. To fix that, we are now + # manually adding that attribute here. + self.run_dir = Paths( + path_cfgs=self.cfgs, + ds=self.datasource).run_dir + # get_ipath_cur: get the current instance path for an item def get_ipath_cur(self, name=None): return self._get_path(self.instance_link, name) diff --git a/cloudinit/tests/test_upgrade.py b/cloudinit/tests/test_upgrade.py index f79a2536..05eefd2a 100644 --- a/cloudinit/tests/test_upgrade.py +++ b/cloudinit/tests/test_upgrade.py @@ -43,3 +43,6 @@ class TestUpgrade: def test_blacklist_drivers_set_on_networking(self, previous_obj_pkl): """We always expect Networking.blacklist_drivers to be initialised.""" assert previous_obj_pkl.distro.networking.blacklist_drivers is None + + def test_paths_has_run_dir_attribute(self, previous_obj_pkl): + assert previous_obj_pkl.paths.run_dir is not None |