galaxy-iuc / parsec

Access Galaxy at the speed of light with automatically generated BioBlend wrappers
Apache License 2.0
9 stars 9 forks source link

non-zero exit codes in case of error #28

Closed bernt-matthias closed 5 years ago

bernt-matthias commented 5 years ago

Would it be possible to return a non-zero exit code in case of an error like:

GET: error 400: b'<html>\n <head>\n  <title>400 Bad Request</title>\n </head>\n <body>\n  <h1>400 Bad Request</h1>\n  The server could not comply with the request since it is either malformed or otherwise incorrect.<br /><br />\nMalformed id ( cc28930a2554f1e ) specified, unable to decode\n\n\n </body>\n</html>', 0 attempts left: <html>
 <head>
  <title>400 Bad Request</title>
 </head>
 <body>
  <h1>400 Bad Request</h1>
  The server could not comply with the request since it is either malformed or otherwise incorrect.<br /><br />
Malformed id ( cc28930a2554f1e ) specified, unable to decode

 </body>
</html>
hexylena commented 5 years ago

Sure, easy enough.

bernt-matthias commented 5 years ago

Cool. Would simplify usage in ansible.

hexylena commented 5 years ago

It looks like there's a subset of the error states we're not catching properly.

https://github.com/galaxy-iuc/parsec/commit/4bfef53b23dfe4f2f04aa80723c5c4b3f3ed11c7

$ parsec histories show_history asdf
Malformed id ( asdf ) specified, unable to decode
$ echo $?
1

looks better now on the unreleased branch.

you're using this in ansible? Cool! Can you share about your use case?

bernt-matthias commented 5 years ago

Just starting to manage quotas (currently only the default quota) with ansible.

Something like:

- name: query default quota id
  shell: |
    . {{ galaxy_server_dir }}/.venv/bin/activate &&
    parsec  --galaxy_instance {{ inventory_hostname }} quotas get_quotas | jq --raw-output '.[] | select(.name=="default").id'
  register: command_output

- set_fact:
    default_quota_id={{ command_output.stdout }}

- name: "Ansible | Print a message if a variable is undefined"
  debug:
    msg: "{{ default_quota_id }}"

# currently only on bioinf2-dev
- name: setup galaxy default quota
  shell: |
    . {{ galaxy_server_dir }}/.venv/bin/activate &&
    parsec  --galaxy_instance {{ inventory_hostname }} quotas create_quota --default registered default "Default quota" "{{ galaxy_default_quota }}" =
  when: inventory_hostname == "bioinf2-dev" and default_quota_id == ""

- name: query default quota size
  shell: |
    . {{ galaxy_server_dir }}/.venv/bin/activate &&
    parsec  --galaxy_instance {{ inventory_hostname }} quotas show_quota {{ default_quota_id }} | jq  --raw-output '.display_amount'
  register: command_output

- set_fact: default_quota_size={{ command_output.stdout | regex_replace(' ([MGT])B', '\\1')}}

- name: "Ansible | Print a message if a variable is undefined"
  debug:
    msg: "{{ default_quota_size }}"

- name: update galaxy default quota
  shell: |
    . {{ galaxy_server_dir }}/.venv/bin/activate &&
    parsec  --galaxy_instance {{ inventory_hostname }} quotas update_quota --default registered --amount "{{ galaxy_default_quota }}" --operation = {{ default_quota_id }}i
  when: inventory_hostname == "bioinf2-dev" and default_quota_id != "" and default_quota_size != galaxy_default_quota
  register: command_output
  failed_when: "'Bad Request' in command_output.stderr"

But not finished yet

hexylena commented 5 years ago

Wow, super cool. Thanks for sharing!

bernt-matthias commented 5 years ago

Thanks for the super fast response.

hexylena commented 5 years ago

I'll try and get a release out soon, but I'm guessing you're pulling from the branch already. Sorry it's a bit slow.