From c2a409a9e0325f9e46c6bba2294a33b392f44f98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=8A=E3=81=99=E3=81=97?= <47208255+1kaw@users.noreply.github.com> Date: Thu, 14 Feb 2019 04:10:47 +0900 Subject: [PATCH] Fix: Yum module does not use proxy when username is not set #51548 (#51994) * add test of yum with proxy * Properly handle unauthenticated yum proxy config Fixes #51548 * shell executable is bash --- lib/ansible/modules/packaging/os/yum.py | 6 +---- test/integration/targets/yum/tasks/proxy.yml | 27 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/lib/ansible/modules/packaging/os/yum.py b/lib/ansible/modules/packaging/os/yum.py index 7a180f9a979..31e8b3c63dc 100644 --- a/lib/ansible/modules/packaging/os/yum.py +++ b/lib/ansible/modules/packaging/os/yum.py @@ -703,7 +703,6 @@ class YumModule(YumDnf): # setting system proxy environment and saving old, if exists my = self.yum_base() namepass = "" - proxy_url = "" scheme = ["http", "https"] old_proxy_env = [os.getenv("http_proxy"), os.getenv("https_proxy")] try: @@ -726,10 +725,7 @@ class YumModule(YumDnf): ) else: for item in scheme: - os.environ[item + "_proxy"] = re.sub( - r"(http://)", - r"\g<1>", proxy_url - ) + os.environ[item + "_proxy"] = my.conf.proxy yield except yum.Errors.YumBaseError: raise diff --git a/test/integration/targets/yum/tasks/proxy.yml b/test/integration/targets/yum/tasks/proxy.yml index 969ad1fbdb5..aa1cac7a03e 100644 --- a/test/integration/targets/yum/tasks/proxy.yml +++ b/test/integration/targets/yum/tasks/proxy.yml @@ -17,6 +17,12 @@ line: "proxy=http://127.0.0.1:8888" state: present + - name: clear proxy logs + shell: ': > /var/log/tinyproxy/tinyproxy.log' + changed_when: false + args: + executable: /usr/bin/bash + - name: install ninvaders with unauthenticated proxy yum: name: 'https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/yum/ninvaders-0.1.1-18.el7.x86_64.rpm' @@ -29,6 +35,9 @@ - "'msg' in yum_proxy_result" - "'rc' in yum_proxy_result" + - name: check that it install via unauthenticated proxy + command: grep -q Request /var/log/tinyproxy/tinyproxy.log + - name: uninstall ninvaders with unauthenticated proxy yum: name: ninvaders @@ -67,6 +76,12 @@ line: "proxy=http://1testuser:1testpassword@127.0.0.1:8888" state: present + - name: clear proxy logs + shell: ': > /var/log/tinyproxy/tinyproxy.log' + changed_when: false + args: + executable: /usr/bin/bash + - name: install ninvaders with authenticated proxy yum: name: 'https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/yum/ninvaders-0.1.1-18.el7.x86_64.rpm' @@ -79,6 +94,9 @@ - "'msg' in yum_proxy_result" - "'rc' in yum_proxy_result" + - name: check that it install via authenticated proxy + command: grep -q Request /var/log/tinyproxy/tinyproxy.log + - name: uninstall ninvaders with authenticated proxy yum: name: ninvaders @@ -108,6 +126,12 @@ line: "proxy_password=1testpassword" state: present + - name: clear proxy logs + shell: ': > /var/log/tinyproxy/tinyproxy.log' + changed_when: false + args: + executable: /usr/bin/bash + - name: install ninvaders with proxy, proxy_username, and proxy_password config in yum.conf yum: name: 'https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/yum/ninvaders-0.1.1-18.el7.x86_64.rpm' @@ -120,6 +144,9 @@ - "'msg' in yum_proxy_result" - "'rc' in yum_proxy_result" + - name: check that it install via proxy with proxy_username, proxy_password config in yum.conf + command: grep -q Request /var/log/tinyproxy/tinyproxy.log + always: #cleanup - name: uninstall tinyproxy