From 77f31ed489c8ac430a472f47727f1905e238e5c7 Mon Sep 17 00:00:00 2001 From: Guillermo Gonzalez Date: Wed, 19 Apr 2023 15:32:34 -0300 Subject: [PATCH 1/2] Add `-S` option when calling add-apt-repository for a line starting with `deb` --- charmhelpers/fetch/ubuntu.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/charmhelpers/fetch/ubuntu.py b/charmhelpers/fetch/ubuntu.py index effc884ad..d100508cf 100644 --- a/charmhelpers/fetch/ubuntu.py +++ b/charmhelpers/fetch/ubuntu.py @@ -20,7 +20,12 @@ import time from charmhelpers import deprecate -from charmhelpers.core.host import get_distrib_codename, get_system_env +from charmhelpers.core.host import ( + CompareHostReleases, + get_distrib_codename, + get_system_env, +) + from charmhelpers.core.hookenv import ( log, @@ -760,9 +765,16 @@ def _add_apt_repository(spec): :param spec: the parameter to pass to add_apt_repository :type spec: str """ + series = get_distrib_codename() if '{series}' in spec: - series = get_distrib_codename() spec = spec.replace('{series}', series) + cmd = ['add-apt-repository', '--yes'] + if (spec.strip().startswith('deb') + and CompareHostReleases(series) >= 'jammy'): + # if starts with deb, just add the source.list as per lp:2017014, only + # in jammy or newer + cmd.append('-S') + cmd.append(spec) _run_with_retries(['add-apt-repository', '--yes', spec], cmd_env=env_proxy_settings(['https', 'http', 'no_proxy']) ) From 1d88de2099588ef10b33177840406cf7aa40c93a Mon Sep 17 00:00:00 2001 From: Guillermo Gonzalez Date: Thu, 20 Apr 2023 17:20:45 -0300 Subject: [PATCH 2/2] use the built cmd in the _run_with_retries call --- charmhelpers/fetch/ubuntu.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/charmhelpers/fetch/ubuntu.py b/charmhelpers/fetch/ubuntu.py index d100508cf..a65a16baf 100644 --- a/charmhelpers/fetch/ubuntu.py +++ b/charmhelpers/fetch/ubuntu.py @@ -769,13 +769,13 @@ def _add_apt_repository(spec): if '{series}' in spec: spec = spec.replace('{series}', series) cmd = ['add-apt-repository', '--yes'] - if (spec.strip().startswith('deb') - and CompareHostReleases(series) >= 'jammy'): + if (spec.strip().startswith('deb') and + CompareHostReleases(series) >= 'jammy'): # if starts with deb, just add the source.list as per lp:2017014, only # in jammy or newer cmd.append('-S') cmd.append(spec) - _run_with_retries(['add-apt-repository', '--yes', spec], + _run_with_retries(cmd, cmd_env=env_proxy_settings(['https', 'http', 'no_proxy']) )