diff options
author | Scott Moser <smoser@ubuntu.com> | 2015-02-11 13:45:55 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2015-02-11 13:45:55 -0500 |
commit | 9acda162465a9b580a79a0fdc2c8e003151c7ead (patch) | |
tree | a35f8216ff34b877ebbe39cca1d0c33af67a21ee | |
parent | ceb229043cec98d79aa8e72c6eb5e79f796a96d7 (diff) | |
download | vyos-cloud-init-9acda162465a9b580a79a0fdc2c8e003151c7ead.tar.gz vyos-cloud-init-9acda162465a9b580a79a0fdc2c8e003151c7ead.zip |
pickle contents: be careful loading and storing pickle to be binary
-rw-r--r-- | cloudinit/stages.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/cloudinit/stages.py b/cloudinit/stages.py index f4f4591d..c5b1ded0 100644 --- a/cloudinit/stages.py +++ b/cloudinit/stages.py @@ -180,9 +180,12 @@ class Init(object): pickled_fn = self.paths.get_ipath_cur('obj_pkl') pickle_contents = None try: - pickle_contents = util.load_file(pickled_fn) - except Exception: + pickle_contents = util.load_file(pickled_fn, decode=False) + except Exception as e: + if os.path.isfile(pickled_fn): + LOG.warn("failed loading pickle in %s: %s" % (pickled_fn, e)) pass + # This is expected so just return nothing # successfully loaded... if not pickle_contents: @@ -203,7 +206,7 @@ class Init(object): util.logexc(LOG, "Failed pickling datasource %s", self.datasource) return False try: - util.write_file(pickled_fn, pk_contents, mode=0o400) + util.write_file(pickled_fn, pk_contents, omode="wb", mode=0o400) except Exception: util.logexc(LOG, "Failed pickling datasource to %s", pickled_fn) return False |