Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uri: Add redirect tests for none, safe, urllib2 and all #37068

Merged
merged 1 commit into from
Mar 29, 2018

Conversation

dagwieers
Copy link
Contributor

@dagwieers dagwieers commented Mar 6, 2018

SUMMARY

This is required if we want to ensure that #36809 doesn't cause any important behavioral changes.

This PR includes:

  • All possible tests for testing HTTP forwarding behaviour in fetch_url and open_url
  • Exposes 'urllib2' method to users (for testing) but undocumented
  • Adds support for BadStatusLine exceptions to provide a more detailed error message (instead of An unknown error occured)

This requires httpbin v0.6.0+ we are using v0.5.0.
Latest httpbin is v0.6.2.

See #37076 #37222

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

uri

ANSIBLE VERSION

v2.5

@dagwieers dagwieers added test_pull_requests meraki Cisco Meraki community labels Mar 6, 2018
@dagwieers dagwieers requested a review from sivel March 6, 2018 11:58
@ansibot
Copy link
Contributor

ansibot commented Mar 6, 2018

@ansibot ansibot added feature This issue/PR relates to a feature request. net_tools Net-tools category support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Mar 6, 2018
@dagwieers dagwieers force-pushed the uri-redirect-tests branch 4 times, most recently from 0296362 to b3c20a0 Compare March 6, 2018 13:36
@ansibot ansibot added the module This issue/PR relates to a module. label Mar 6, 2018
@dagwieers dagwieers force-pushed the uri-redirect-tests branch 5 times, most recently from 0b13250 to da14ec9 Compare March 6, 2018 14:41
dagwieers added a commit to dagwieers/ansible that referenced this pull request Mar 6, 2018
This is required to test against /anything, which is important to test
whether redirected links do a GET or POST request (without making
assumptions and avoiding HTTP 405 METHOD NOT ALLOWED issues)

For more information, see ansible#37068
@dagwieers dagwieers changed the title uri: Add redirect tests for none, safe and all uri: Add redirect tests for none, safe, urllib2 and all Mar 6, 2018
@mattclay mattclay added the ci_verified Changes made in this PR are causing tests to fail. label Mar 7, 2018
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Mar 17, 2018
@kbreit
Copy link
Contributor

kbreit commented Mar 20, 2018

Checking in. Is there something in this PR we're waiting on?

@sivel
Copy link
Member

sivel commented Mar 20, 2018

We are waiting on updated testing environment to support these tests. The PRs are referenced above.

@ansibot ansibot removed ci_verified Changes made in this PR are causing tests to fail. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Mar 21, 2018
@dagwieers
Copy link
Contributor Author

dagwieers commented Mar 21, 2018

Now that we have an updated httpbin, the integration tests are failing, but surprisingly it's not any tests of this PR that are failing...

The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_O84sPO/ansible_modlib.zip/ansible/module_utils/urls.py", line 1017, in fetch_url
    client_key=client_key, cookies=cookies)
  File "/tmp/ansible_O84sPO/ansible_modlib.zip/ansible/module_utils/urls.py", line 920, in open_url
    r = urllib_request.urlopen(*urlopen_args)
  File "/usr/lib64/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib64/python2.7/urllib2.py", line 431, in open
    response = self._open(req, data)
  File "/usr/lib64/python2.7/urllib2.py", line 449, in _open
    '_open', req)
  File "/usr/lib64/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "/usr/lib64/python2.7/urllib2.py", line 1244, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/usr/lib64/python2.7/urllib2.py", line 1217, in do_open
    r = h.getresponse(buffering=True)
  File "/usr/lib64/python2.7/httplib.py", line 1089, in getresponse
    response.begin()
  File "/usr/lib64/python2.7/httplib.py", line 444, in begin
    version, status, reason = self._read_status()
  File "/usr/lib64/python2.7/httplib.py", line 408, in _read_status
    raise BadStatusLine(line)
BadStatusLine: ''

PS And it is not failing locally. Let's restart Shippable.

@sivel
Copy link
Member

sivel commented Mar 21, 2018

The httptester sha update hasn't been merged yet: #37746

@dagwieers
Copy link
Contributor Author

@sivel In any case we need to catch BadStatusLine better in order to debug this... Thanks for the heads up.

@sivel
Copy link
Member

sivel commented Mar 21, 2018

Those failures are generally due to the simple http server we start during the tests having trouble, or terminating before the tests are complete.

@dagwieers
Copy link
Contributor Author

dagwieers commented Mar 21, 2018

@sivel I'd like to return a proper error to the user, how about:

except BadStatusLine as e:
    info.update(dict(msg="Connection failure: connection was closed before a valid response was received: %s" % to_native(e.line), status=-1))

This is required if we want to ensure that ansible#36809 doesn't cause any
important behavioral changes.

This PR changes the uri module to support follow_redirects=urllib2

It also adds a better error message when the connection closes before
any data was returned.
@dagwieers
Copy link
Contributor Author

@sivel This PR is ready for re-evaluation. It only adds tests to pinpoint the existing forwarding behavior of the different methods, before we add #36809

@dagwieers
Copy link
Contributor Author

This is ready to be re-evaluated.

@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Mar 23, 2018
@sivel
Copy link
Member

sivel commented Mar 28, 2018

Is the intention to get this PR merged and then rebase #36809 to resolve the FIXME issues?

I don't necessarily have a preference, I just want to make sure I understand. The other option would be to remove the failing tests and add them in #36809

@dagwieers
Copy link
Contributor Author

dagwieers commented Mar 28, 2018

Yes, first we need this one merged, so we have a baseline for the original behavior.
I will then resolve the HTTP 307/308 fixes, so you can easily tell from the integration tests diff if those changes are to be expected. If this gets merged now, I will do the other PR asap.

@sivel
Copy link
Member

sivel commented Mar 29, 2018

rebuild_merge

@ansibot ansibot merged commit 800dad5 into ansible:devel Mar 29, 2018
ryancurrah pushed a commit to ryancurrah/ansible that referenced this pull request Apr 4, 2018
This is required if we want to ensure that ansible#36809 doesn't cause any
important behavioral changes.

This PR changes the uri module to support follow_redirects=urllib2

It also adds a better error message when the connection closes before
any data was returned.
ilicmilan pushed a commit to ilicmilan/ansible that referenced this pull request Nov 7, 2018
This is required if we want to ensure that ansible#36809 doesn't cause any
important behavioral changes.

This PR changes the uri module to support follow_redirects=urllib2

It also adds a better error message when the connection closes before
any data was returned.
@dagwieers dagwieers added the cisco Cisco technologies label Feb 22, 2019
@ansible ansible locked and limited conversation to collaborators Apr 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cisco Cisco technologies core_review In order to be merged, this PR must follow the core review workflow. feature This issue/PR relates to a feature request. meraki Cisco Meraki community module This issue/PR relates to a module. net_tools Net-tools category support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants