summaryrefslogtreecommitdiff
path: root/cloudinit/helpers.py
diff options
context:
space:
mode:
authorlucasmoura <lucas.moura@canonical.com>2021-04-12 13:22:22 -0300
committerGitHub <noreply@github.com>2021-04-12 12:22:22 -0400
commit83f6bbfbe5b924be61a3c098f4202377d69c8947 (patch)
tree0a6f8f9c0ec95b554774e94784977689b2629f2f /cloudinit/helpers.py
parentfb38aa591bca82b7aa89187695a2bff676d687cb (diff)
downloadvyos-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/helpers.py')
-rw-r--r--cloudinit/helpers.py17
1 files changed, 16 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)