SHA256
1
0
forked from pool/cloud-init
cloud-init/cloud-init-purge-cache-py-ver-change.patch
Robert Schweikert b8c37f9e0f - Add cloud-init-log-file-mode.patch (bsc#1183939)
+ Change log file creation mode to 640
- Add cloud-init-no-pwd-in-log.patch (bsc#1184758)
  + Do not write the generated password to the log file
- Add cloud-init-purge-cahce-py-ver-change.patch

OBS-URL: https://build.opensuse.org/package/show/Cloud:Tools/cloud-init?expand=0&rev=184
2021-06-02 21:15:40 +00:00

36 lines
1.4 KiB
Diff

--- cloudinit/cmd/main.py.orig
+++ cloudinit/cmd/main.py
@@ -210,6 +210,24 @@ def attempt_cmdline_url(path, network=Tr
"wrote cloud-config data from %s='%s' to %s" %
(cmdline_name, url, path))
+def cache_pyver_maybe_purge_cache(init):
+ """Check if the Python version changed on us"""
+ pyver = '%d.%d' % (sys.version_info.major, sys.version_info.minor)
+ pyrefver = os.path.join(init.paths.get_cpath('data'), 'python-version')
+ if os.path.exists(pyrefver):
+ cached_pyver = open(pyrefver).read()
+ # The Python version has changed out from under us, anything that was
+ # pickled previously is likely useless due to API changes.
+ if cached_pyver != pyver:
+ LOG.debug('Python version change detected purging cache')
+ init.purge_cache(True)
+ else:
+ LOG.debug(
+ 'Could not determine Python version used to write cache, purging'
+ )
+ init.purge_cache(True)
+ util.write_file(pyrefver, pyver)
+
def main_init(name, args):
deps = [sources.DEP_FILESYSTEM, sources.DEP_NETWORK]
@@ -277,6 +295,7 @@ def main_init(name, args):
util.logexc(LOG, "Failed to initialize, likely bad things to come!")
# Stage 4
path_helper = init.paths
+ cache_pyver_maybe_purge_cache(init)
mode = sources.DSMODE_LOCAL if args.local else sources.DSMODE_NETWORK
if mode == sources.DSMODE_NETWORK: