diff options
author | Toshio Kuratomi <a.badger@gmail.com> | 2016-12-13 15:55:06 -0800 |
---|---|---|
committer | Toshio Kuratomi <a.badger@gmail.com> | 2016-12-13 15:55:06 -0800 |
commit | cbf1f23e7ec23af80cac67eacd7f0a6ce5ab3b58 (patch) | |
tree | 837c980c475a08ffffd9bfed04506b428f808156 | |
parent | 0db1c770416f4060374dbdc99753935857f6d770 (diff) | |
download | ansible-cbf1f23e7ec23af80cac67eacd7f0a6ce5ab3b58.tar.gz |
Fixes for uri under python3 and local (non-httptester) testing
(cherry picked from c6b42028c40e42662491bbd7a97c41f27e89ccd5)
-rw-r--r-- | lib/ansible/module_utils/urls.py | 9 | ||||
-rw-r--r-- | test/integration/roles/test_uri/tasks/main.yml | 8 |
2 files changed, 10 insertions, 7 deletions
diff --git a/lib/ansible/module_utils/urls.py b/lib/ansible/module_utils/urls.py index c4a13bf3c8..1fd67bd564 100644 --- a/lib/ansible/module_utils/urls.py +++ b/lib/ansible/module_utils/urls.py @@ -512,9 +512,15 @@ def RedirectHandlerFactory(follow_redirects=None, validate_certs=True): newheaders = dict((k,v) for k,v in req.headers.items() if k.lower() not in ("content-length", "content-type") ) + try: + # Python 2-3.3 + origin_req_host = req.get_origin_req_host() + except AttributeError: + # Python 3.4+ + origin_req_host = req.origin_req_host return urllib_request.Request(newurl, headers=newheaders, - origin_req_host=req.get_origin_req_host(), + origin_req_host=origin_req_host, unverifiable=True) else: raise urllib_error.HTTPError(req.get_full_url(), code, msg, hdrs, fp) @@ -862,6 +868,7 @@ def open_url(url, data=None, headers=None, method=None, use_proxy=True, opener = urllib_request.build_opener(*handlers) urllib_request.install_opener(opener) + data = to_bytes(data, nonstring='passthru') if method: if method.upper() not in ('OPTIONS','GET','HEAD','POST','PUT','DELETE','TRACE','CONNECT','PATCH'): raise ConnectionError('invalid HTTP request method; %s' % method.upper()) diff --git a/test/integration/roles/test_uri/tasks/main.yml b/test/integration/roles/test_uri/tasks/main.yml index bfb193a26b..4e7ce0c90d 100644 --- a/test/integration/roles/test_uri/tasks/main.yml +++ b/test/integration/roles/test_uri/tasks/main.yml @@ -198,10 +198,6 @@ set_fact: is_ubuntu_precise: "{{ ansible_distribution == 'Ubuntu' and ansible_distribution_release == 'precise' }}" -# These tests are just side effects of how the site is hosted. It's not -# specifically a test site. So the tests may break due to the hosting -# changing. Eventually we need to standup a webserver with SNI as part of the -# test run. - name: Test that SNI succeeds on python versions that have SNI uri: url: 'https://{{ sni_host }}/' @@ -213,7 +209,7 @@ assert: that: - result|success - - 'sni_host == result.content' + - 'sni_host in result.content' when: ansible_python.has_sslcontext - name: Verify SNI verification fails on old python without urllib3 contrib @@ -253,7 +249,7 @@ assert: that: - result|success - - 'sni_host == result.content' + - 'sni_host in result.content' when: not ansible_python.has_sslcontext and not is_ubuntu_precise|bool - name: Uninstall ndg-httpsclient and urllib3 |