From 259d9c501472315e539701f00095743390eb89e5 Mon Sep 17 00:00:00 2001 From: Ryan Harper Date: Thu, 16 Jan 2020 11:29:59 -0600 Subject: Ensure util.get_architecture() runs only once (#172) * Ensure util.get_architecture() runs only once util.get_architecture() recently was wrapped using python3's lru_cache() which will cache the result so we only invoke 'dpkg --print-architecture' once. In practice, cloud-init.log will show multiple invocations of the command. The source of this was that the debian Distro object implements the get_primary_arch() with this command, but it was not calling it from util, but issuing a util.subp() directly. This branch also updates cc_apt_configure methods to fetch the arch value from the distro class, and then ensure that the methods apt_configure calls pass the arch value around. * utils: remove lsb_release and get_architecture wrappers The original lsb_release wrapper was used to prevent polluting the single value we cached, however lru_cache() already handles this case by using args, kwargs values to cache different calls to the method. * rename_apt_list: use all positional parameters --- cloudinit/config/cc_apt_configure.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'cloudinit/config') diff --git a/cloudinit/config/cc_apt_configure.py b/cloudinit/config/cc_apt_configure.py index f01e2aaf..4a3aed36 100644 --- a/cloudinit/config/cc_apt_configure.py +++ b/cloudinit/config/cc_apt_configure.py @@ -309,7 +309,7 @@ def apply_apt(cfg, cloud, target): if util.is_false(cfg.get('preserve_sources_list', False)): generate_sources_list(cfg, release, mirrors, cloud) - rename_apt_lists(mirrors, target) + rename_apt_lists(mirrors, target, arch) try: apply_apt_config(cfg, APT_PROXY_FN, APT_CONFIG_FN) @@ -427,9 +427,9 @@ def mirrorurl_to_apt_fileprefix(mirror): return string -def rename_apt_lists(new_mirrors, target=None): +def rename_apt_lists(new_mirrors, target, arch): """rename_apt_lists - rename apt lists to preserve old cache data""" - default_mirrors = get_default_mirrors(util.get_architecture(target)) + default_mirrors = get_default_mirrors(arch) pre = util.target_path(target, APT_LISTS) for (name, omirror) in default_mirrors.items(): -- cgit v1.2.3