Romeo Theriault wrote an EXCELLENT module for interacting with web
services, and I've pushed it, and the docs on it are now up on the
docsite.
It's called "uri".
Unfortunately the examples kind of ate it when using our docsite
module formatter (produced some weird markup), so there aren't a lot
of examples online yet.
You should try it out anyway.
It can be used in combination with "fail" and "register" and "when"
and the like to do really basic tests for web services, and it can
even log into forms, use register to save a cookie, and then submit
other requests.
You can even use it submit JIRA tickets.
(Actually what I am thinking is eventually we start including more
examples in the examples directory, and the docsite can just link to
them).
Until we get the examples formatting straightened out I figured I’d post the examples they will show here so people can get a taste of how it works:
# Check that you can connect to a page and it returns a status 200"
action: uri url=[http://www.awesome.com](http://www.awesome.com) method=GET"
# Check that a page returns a status 200 and fail if the word AWESOME is not in the page contents.
action: uri url=[http://www.awesome.com](http://www.awesome.com) method=GET return_content=yes
register: webpage
action: fail
when_string: '"AWESOME" not in "${webpage.content}"'
# "Create a JIRA issue."
action: uri url=[https://your.jira.server.com/rest/api/2/issue/](https://your.jira.server.com/rest/api/2/issue/) method=POST user=your_username password=your_pass body='$FILE(issue.json)' force_basic_auth=yes status_code=201 HEADER_Content-Type="application/json"
# Login to a form based webpage, then use the cookie that got returned to access the app in later tasks.
action: uri url=[https://your.form.based.auth.app.com/index.php](https://your.form.based.auth.app.com/index.php) method=POST body="name=your_username&password=your_password&enter=Sign%20in" status_code=302 HEADER_Content-Type="application/x-www-form-urlencoded"
register: login
action: uri url=[https://your.form.based.auth.app.com/dashboard.php](https://your.form.based.auth.app.com/dashboard.php) method=GET return_content=yes HEADER_Cookie="${login.set_cookie}"
Until we get the examples formatting straightened out I figured I'd post the
examples they will show here so people can get a taste of how it works:
Thanks, I think "make docs" were fine but it was evident issues came
up with "make webdocs" when they produced weirdness in the rst files
that Sphinx did not like.
If you want to try to fix those, that would be great, and I'll take them.
Is it possible to define two status_codes? For instance I have webpage which can return status code 200 or status code 301 and both are ok. How can i tell uri module to accept both?
thanks
Edgars
svētdiena, 2013. gada 17. februāris 00:50:27 UTC+1, Michael DeHaan rakstīja:
stdout_lines is an array, so it’s printing them as an array.
I would be more inclined to save the result to a file locally if you really wanted to do that, but I’d like to ask what the root use case actually is, as there are better ways to model this sort of thing in almost all cases than going through intermediate files.
Help me understand a bit what the real world scenario is?
Well, usecase was rather simple - I needed to install Openstack`s Cinder with Ceph backend, and that required issuing commands that respond with hasg keys on STDOUT. Idea was to capture this output as variable and use it in consequent libvirt commands.
But I managed to route it to file and read from it.
and possibly try resubmitting it the suggested fixes. This would allow
you to specify more than one status_code. If you can't get to it I may
be able to this weekend.