diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-06-19 17:58:41 -0700 |
---|---|---|
committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-06-19 17:58:41 -0700 |
commit | 43eb6d5aace53bef2116dde0796807befef1d8ff (patch) | |
tree | 4e19b985cb97fd1293f9617c2b800e5377fc8494 /cloudinit/transforms/apt_update_upgrade.py | |
parent | b492cedaa5a4e66f4f4c589fc73f53afade7b904 (diff) | |
download | vyos-cloud-init-43eb6d5aace53bef2116dde0796807befef1d8ff.tar.gz vyos-cloud-init-43eb6d5aace53bef2116dde0796807befef1d8ff.zip |
Make most of all the places use the paths join() function so that testing with non-real read/write paths is easier.
Diffstat (limited to 'cloudinit/transforms/apt_update_upgrade.py')
-rw-r--r-- | cloudinit/transforms/apt_update_upgrade.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/cloudinit/transforms/apt_update_upgrade.py b/cloudinit/transforms/apt_update_upgrade.py index d49d8bd2..29bbc1ae 100644 --- a/cloudinit/transforms/apt_update_upgrade.py +++ b/cloudinit/transforms/apt_update_upgrade.py @@ -26,6 +26,8 @@ from cloudinit import util distros = ['ubuntu', 'debian'] +PROXY_TPL = "Acquire::HTTP::Proxy \"%s\";\n" + def handle(_name, cfg, cloud, log, _args): update = util.get_cfg_option_bool(cfg, 'apt_update', False) @@ -44,22 +46,23 @@ def handle(_name, cfg, cloud, log, _args): "archive.ubuntu.com/ubuntu") rename_apt_lists(old_mir, mirror) - # set up proxy + # Set up any apt proxy proxy = cfg.get("apt_proxy", None) proxy_filename = "/etc/apt/apt.conf.d/95cloud-init-proxy" if proxy: try: - # See http://linux.die.net/man/5/apt.conf - contents = "Acquire::HTTP::Proxy \"%s\";\n" - util.write_file(proxy_filename, contents % (proxy)) + # See man 'apt.conf' + contents = PROXY_TPL % (proxy) + util.write_file(cloud.paths.join(False, proxy_filename), + contents) except Exception as e: util.logexc(log, "Failed to write proxy to %s", proxy_filename) elif os.path.isfile(proxy_filename): util.del_file(proxy_filename) - # process 'apt_sources' + # Process 'apt_sources' if 'apt_sources' in cfg: - errors = add_sources(cfg['apt_sources'], + errors = add_sources(cloud, cfg['apt_sources'], {'MIRROR': mirror, 'RELEASE': release}) for e in errors: log.warn("Source Error: %s", ':'.join(e)) @@ -138,7 +141,7 @@ def generate_sources_list(codename, mirror, cloud, log): log.warn("No template found, not rendering /etc/apt/sources.list") -def add_sources(srclist, template_params=None): +def add_sources(cloud, srclist, template_params=None): """ add entries in /etc/apt/sources.list.d for each abbreviated sources.list entry in 'srclist'. When rendering template, also @@ -187,7 +190,9 @@ def add_sources(srclist, template_params=None): errorlist.append([source, "failed add key"]) try: - util.write_file(ent['filename'], "%s\n" % (source), omode="ab") + contents = "%s\n" % (source) + util.write_file(cloud.paths.join(False, ent['filename']), + contents, omode="ab") except: errorlist.append([source, "failed write to file %s" % ent['filename']]) |