Skip to content

Commit

Permalink
change configure option name
Browse files Browse the repository at this point in the history
  • Loading branch information
itdependsnetworks committed Sep 16, 2021
1 parent 8b98158 commit 6553a0c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
19 changes: 9 additions & 10 deletions plugins/action/query_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ def nautobot_action_graphql(args):
if not isinstance(ssl_verify, bool):
raise AnsibleError("validate_certs must be a boolean")

populate_root = args.get("populate_root", False)
Display().vv("Populate root is set to: %s" % populate_root)
update_hostvars = args.get("update_hostvars", False)
Display().vv("Populate root is set to: %s" % update_hostvars)

# Verify SSL Verify is of boolean
if not isinstance(populate_root, bool):
raise AnsibleError("populate_root must be a boolean")
if not isinstance(update_hostvars, bool):
raise AnsibleError("update_hostvars must be a boolean")

nautobot_api = NautobotApiBase(token=token, url=url, ssl_verify=ssl_verify)
query = args.get("query")
Expand Down Expand Up @@ -97,14 +97,13 @@ def nautobot_action_graphql(args):

# Good result, return it
if isinstance(nautobot_response, pynautobot.core.graphql.GraphQLRecord):
# If populate_root is set, add to ansible_facts which will set to the root of
# If update_hostvars is set, add to ansible_facts which will set to the root of
# the data structure, e.g. hostvars[inventory_hostname]
if args.get("populate_root"):
if args.get("update_hostvars"):
results["ansible_facts"] = nautobot_response.json.get("data")
else:
# Assign the data of a good result to the response to the data key
# otherwise, e.g. hostvars[inventory_hostname]['data']
results["data"] = nautobot_response.json.get("data")
# Assign to data regardless a good result to the response to the data key
# e.g. hostvars[inventory_hostname]['data']
results["data"] = nautobot_response.json.get("data")

return results

Expand Down
6 changes: 3 additions & 3 deletions plugins/modules/query_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
required: False
default: True
type: bool
populate_root:
update_hostvars:
description:
- Whether or not to populate data in the in the root (e.g. hostvars[inventory_hostname]) or within the
'data' key (e.g. hostvars[inventory_hostname]['data']). Beware, that the root keys provided by the query
Expand Down Expand Up @@ -106,7 +106,7 @@
token: thisIsMyToken
query: "{{ query_string }}"
variables: "{{ variables }}"
populate_root: "yes"
update_hostvars: "yes"
"""

RETURN = """
Expand Down Expand Up @@ -154,7 +154,7 @@ def main():
token=dict(required=False, type="str", no_log=True, default=None),
url=dict(required=False, type="str", default=None),
validate_certs=dict(required=False, type="bool", default=True),
populate_root=dict(required=False, type="bool", default=False),
update_hostvars=dict(required=False, type="bool", default=False),
),
# Set to true as this is a read only API, this may need to change or have significant changes when Mutations are
# added to the GraphQL endpoint of Nautobot
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/action/test_graphql_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ def test_setup_api_error_incorrect_validate_certs(nautobot_valid_args):
assert str(exc.value) == "validate_certs must be a boolean"


def test_setup_api_error_incorrect_populate_root(nautobot_valid_args):
nautobot_valid_args["populate_root"] = "Hi"
def test_setup_api_error_incorrect_update_hostvars(nautobot_valid_args):
nautobot_valid_args["update_hostvars"] = "Hi"
with pytest.raises(AnsibleError) as exc:
test_class = nautobot_action_graphql(args=nautobot_valid_args)

assert str(exc.value) == "populate_root must be a boolean"
assert str(exc.value) == "update_hostvars must be a boolean"


def test_query_api_query_error_none(nautobot_valid_args):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ def nautobot_valid_args(graphql_test_query):
"validate_certs": False,
"query": graphql_test_query,
"graph_variables": {},
"populate_root": False,
"update_hostvars": False,
}

0 comments on commit 6553a0c

Please sign in to comment.