From 39fbe50eac36cd748a6e3a5c805712fe6e89caef Mon Sep 17 00:00:00 2001 From: charlie4284 Date: Tue, 4 Jul 2023 19:43:40 +0800 Subject: [PATCH 1/6] fix: use proxy for wget --- src/runner.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/runner.py b/src/runner.py index 90bd6a0e1..e3081f1ac 100644 --- a/src/runner.py +++ b/src/runner.py @@ -635,5 +635,12 @@ def _wget_install(self, executables: Iterable[WgetExecutable]) -> None: for executable in executables: executable_path = f"/usr/bin/{executable.cmd}" logger.info("Downloading %s via wget to %s...", executable.url, executable_path) - self.instance.execute(["/usr/bin/wget", executable.url, "-O", executable_path]) + wget_cmd = ["/usr/bin/wget", executable.url, "-O", executable_path] + if self.config.proxies["http"] or self.config.proxies["https"]: + wget_cmd += ["-e", "use_proxy=on"] + if self.config.proxies["http"]: + wget_cmd += ["-e", f"http_proxy={self.config.proxies['http']}"] + if self.config.proxies["https"]: + wget_cmd += ["-e", f"https_proxy={self.config.proxies['https']}"] + self.instance.execute(wget_cmd) self.instance.execute(["/usr/bin/chmod", "+x", executable_path]) From 4fb5b043e15d5bbdb031a815f4fb0b0826948e21 Mon Sep 17 00:00:00 2001 From: charlie4284 Date: Tue, 4 Jul 2023 20:37:35 +0800 Subject: [PATCH 2/6] fix: filter by no_proxy --- src/runner.py | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/runner.py b/src/runner.py index e3081f1ac..fff62ad39 100644 --- a/src/runner.py +++ b/src/runner.py @@ -620,6 +620,24 @@ def _apt_install(self, packages: Iterable[str]) -> None: logger.info("Installing %s via APT...", pkg) self.instance.execute(["/usr/bin/apt-get", "install", "-yq", pkg]) + def _get_filtered_proxies(self) -> tuple[str, str]: + """Filter http and https proxy with no proxy. + + Returns: + Filtered http and https proxy values. + """ + http_proxy = self.config.proxies["http"] + https_proxy = self.config.proxies["https"] + if not self.config.proxies["no_proxy"]: + return (http_proxy, https_proxy) + + no_proxy_hosts = set(self.config.proxies["no_proxy"].split(",")) + if http_proxy in no_proxy_hosts: + http_proxy = "" + if https_proxy in no_proxy_hosts: + https_proxy = "" + return (http_proxy, https_proxy) + def _wget_install(self, executables: Iterable[WgetExecutable]) -> None: """Installs the given binaries. @@ -636,11 +654,12 @@ def _wget_install(self, executables: Iterable[WgetExecutable]) -> None: executable_path = f"/usr/bin/{executable.cmd}" logger.info("Downloading %s via wget to %s...", executable.url, executable_path) wget_cmd = ["/usr/bin/wget", executable.url, "-O", executable_path] - if self.config.proxies["http"] or self.config.proxies["https"]: + http_proxy, https_proxy = self._get_filtered_proxies() + if http_proxy or https_proxy: wget_cmd += ["-e", "use_proxy=on"] - if self.config.proxies["http"]: - wget_cmd += ["-e", f"http_proxy={self.config.proxies['http']}"] - if self.config.proxies["https"]: - wget_cmd += ["-e", f"https_proxy={self.config.proxies['https']}"] + if http_proxy: + wget_cmd += ["-e", f"http_proxy={http_proxy}"] + if https_proxy: + wget_cmd += ["-e", f"https_proxy={https_proxy}"] self.instance.execute(wget_cmd) self.instance.execute(["/usr/bin/chmod", "+x", executable_path]) From f897f97e765c6b28cc97ebdfb8e163be67b45f28 Mon Sep 17 00:00:00 2001 From: charlie4284 Date: Tue, 4 Jul 2023 21:34:03 +0800 Subject: [PATCH 3/6] fix: no proxy option --- src/runner.py | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/src/runner.py b/src/runner.py index fff62ad39..30cb0c189 100644 --- a/src/runner.py +++ b/src/runner.py @@ -620,24 +620,6 @@ def _apt_install(self, packages: Iterable[str]) -> None: logger.info("Installing %s via APT...", pkg) self.instance.execute(["/usr/bin/apt-get", "install", "-yq", pkg]) - def _get_filtered_proxies(self) -> tuple[str, str]: - """Filter http and https proxy with no proxy. - - Returns: - Filtered http and https proxy values. - """ - http_proxy = self.config.proxies["http"] - https_proxy = self.config.proxies["https"] - if not self.config.proxies["no_proxy"]: - return (http_proxy, https_proxy) - - no_proxy_hosts = set(self.config.proxies["no_proxy"].split(",")) - if http_proxy in no_proxy_hosts: - http_proxy = "" - if https_proxy in no_proxy_hosts: - https_proxy = "" - return (http_proxy, https_proxy) - def _wget_install(self, executables: Iterable[WgetExecutable]) -> None: """Installs the given binaries. @@ -654,12 +636,13 @@ def _wget_install(self, executables: Iterable[WgetExecutable]) -> None: executable_path = f"/usr/bin/{executable.cmd}" logger.info("Downloading %s via wget to %s...", executable.url, executable_path) wget_cmd = ["/usr/bin/wget", executable.url, "-O", executable_path] - http_proxy, https_proxy = self._get_filtered_proxies() - if http_proxy or https_proxy: + if self.config.proxies["http"] or self.config.proxies["https"]: wget_cmd += ["-e", "use_proxy=on"] - if http_proxy: - wget_cmd += ["-e", f"http_proxy={http_proxy}"] - if https_proxy: - wget_cmd += ["-e", f"https_proxy={https_proxy}"] + if self.config.proxies["http"]: + wget_cmd += ["-e", f"http_proxy={self.config.proxies['http']}"] + if self.config.proxies["https"]: + wget_cmd += ["-e", f"https_proxy={self.config.proxies['https']}"] + if self.config.proxies["no_proxy"]: + wget_cmd += ["-e", f"https_proxy={self.config.proxies['no_proxy']}"] self.instance.execute(wget_cmd) self.instance.execute(["/usr/bin/chmod", "+x", executable_path]) From 17985b8f6a77c30db295932dc6d44539fb20e2fc Mon Sep 17 00:00:00 2001 From: charlie4284 Date: Tue, 4 Jul 2023 21:35:31 +0800 Subject: [PATCH 4/6] fix: no proxy option --- src/runner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runner.py b/src/runner.py index 30cb0c189..24bfe6663 100644 --- a/src/runner.py +++ b/src/runner.py @@ -643,6 +643,6 @@ def _wget_install(self, executables: Iterable[WgetExecutable]) -> None: if self.config.proxies["https"]: wget_cmd += ["-e", f"https_proxy={self.config.proxies['https']}"] if self.config.proxies["no_proxy"]: - wget_cmd += ["-e", f"https_proxy={self.config.proxies['no_proxy']}"] + wget_cmd += ["-e", f"no_proxy={self.config.proxies['no_proxy']}"] self.instance.execute(wget_cmd) self.instance.execute(["/usr/bin/chmod", "+x", executable_path]) From b82e003d6fa293d6862e5e8eb98d0df0ae579548 Mon Sep 17 00:00:00 2001 From: charlie4284 Date: Tue, 4 Jul 2023 22:24:30 +0800 Subject: [PATCH 5/6] fix: key error --- src/runner.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/runner.py b/src/runner.py index 24bfe6663..2815b1188 100644 --- a/src/runner.py +++ b/src/runner.py @@ -636,13 +636,13 @@ def _wget_install(self, executables: Iterable[WgetExecutable]) -> None: executable_path = f"/usr/bin/{executable.cmd}" logger.info("Downloading %s via wget to %s...", executable.url, executable_path) wget_cmd = ["/usr/bin/wget", executable.url, "-O", executable_path] - if self.config.proxies["http"] or self.config.proxies["https"]: + if self.config.proxies.get("http", None) or self.config.proxies.get("https", None): wget_cmd += ["-e", "use_proxy=on"] - if self.config.proxies["http"]: + if self.config.proxies.get("http", None): wget_cmd += ["-e", f"http_proxy={self.config.proxies['http']}"] - if self.config.proxies["https"]: + if self.config.proxies.get("https", None): wget_cmd += ["-e", f"https_proxy={self.config.proxies['https']}"] - if self.config.proxies["no_proxy"]: + if self.config.proxies.get("no_proxy", None): wget_cmd += ["-e", f"no_proxy={self.config.proxies['no_proxy']}"] self.instance.execute(wget_cmd) self.instance.execute(["/usr/bin/chmod", "+x", executable_path]) From 08e6eaef2f39082b6e1696fbfa031780750e6c5e Mon Sep 17 00:00:00 2001 From: charlie4284 Date: Wed, 5 Jul 2023 09:37:27 +0800 Subject: [PATCH 6/6] chore: disable self-hosted runner for tests --- .github/workflows/test.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index fcffaca11..43bc27369 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,9 +1,11 @@ name: Tests on: - pull_request: { } + pull_request: {} jobs: unit-tests: uses: canonical/operator-workflows/.github/workflows/test.yaml@main secrets: inherit + with: + self-hosted-runner: false