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

vultr: fix for API returned unexpected empty list #48036

Merged
merged 2 commits into from
Nov 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/48036-vultr-fix-empty-list-handling.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- vultr - fixed the handling of an inconsistency in the response from
Vultr API when it returns an unexpected empty list instead a empty dict.
2 changes: 1 addition & 1 deletion lib/ansible/module_utils/vultr.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def api_query(self, path="/", method="GET", data=None):
return {}

try:
return self.module.from_json(to_text(res))
return self.module.from_json(to_native(res)) or {}
except ValueError as e:
self.module.fail_json(msg="Could not process response into json: %s" % e)

Expand Down
15 changes: 15 additions & 0 deletions test/legacy/roles/vultr_server_facts/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
# Copyright (c) 2018, Yanis Guenane <yanis+ansible@guenane.org>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
---
- name: setup ensure VM is absent
vultr_server:
name: "{{ vultr_server_name }}"
state: absent
register: result

# Servers can only be destroyed 5 min after creation
- name: wait for 5 min until VM is absent
local_action: wait_for
when: result is changed

- name: test gather vultr server facts - empty resources
vultr_server_facts:
- name: verify test gather vultr server facts - empty resources
assert:
that:
- ansible_facts.vultr_server_facts | count == 0

- name: Create the server
vultr_server:
Expand Down