-
Notifications
You must be signed in to change notification settings - Fork 83
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
fix(grafana_datasource): orgId by name if defined to compare diff #345
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #345 +/- ##
==========================================
+ Coverage 69.25% 70.82% +1.56%
==========================================
Files 9 18 +9
Lines 1184 1878 +694
Branches 263 326 +63
==========================================
+ Hits 820 1330 +510
- Misses 212 404 +192
+ Partials 152 144 -8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
I actually liked your first try (41596d3) better, because there you didn't redefine And now that I think of it: Now we check twice, if Aside, for another issue: We obviously need tests for idempotency. |
This is what I had in mind: diff --git a/plugins/modules/grafana_datasource.py b/plugins/modules/grafana_datasource.py
index 910e16b..3784999 100644
--- a/plugins/modules/grafana_datasource.py
+++ b/plugins/modules/grafana_datasource.py
@@ -688,6 +688,7 @@ class GrafanaInterface(object):
def __init__(self, module):
self._module = module
self.grafana_url = base.clean_url(module.params.get("url"))
+ self.org_id = None
# {{{ Authentication header
self.headers = {"Content-Type": "application/json"}
if module.params.get("grafana_api_key", None):
@@ -698,12 +699,12 @@ class GrafanaInterface(object):
self.headers["Authorization"] = basic_auth_header(
module.params["url_username"], module.params["url_password"]
)
- org_id = (
+ self.org_id = (
self.organization_by_name(module.params["org_name"])
if module.params["org_name"]
else module.params["org_id"]
)
- self.switch_organization(org_id)
+ self.switch_organization(self.org_id)
# }}}
def _send_request(self, url, data=None, headers=None, method="GET"):
@@ -923,12 +924,7 @@ def main():
ds = grafana_iface.datasource_by_name(name)
if state == "present":
- org_id = (
- grafana_iface.organization_by_name(module.params["org_name"])
- if module.params["org_name"]
- else module.params["org_id"]
- )
- payload = get_datasource_payload(module.params, org_id)
+ payload = get_datasource_payload(module.params, grafana_iface.org_id)
if ds is None:
grafana_iface.create_datasource(payload)
ds = grafana_iface.datasource_by_name(name) This way I think, this should work. My local tests are failing with another error, so can you please test this? |
@rndmh3ro Yes it works :) Great suggestion to define the variable for org_id this way. Thank you. |
SUMMARY
If
org_name
is set instead oforg_id
, comparing the diff (after/before) to determine whether something has changed or not does not work.ISSUE TYPE
COMPONENT NAME
grafana_datasource
ADDITIONAL INFORMATION