Adding idempotency fixes for alerting, cloud and folder modules
* Fixing cloud_plugin idempotency * Sanity check fixes * fix test * fix * reset test * Add 9dempotency check to test * Working cloud_plugin with idempotency * Adding idempotency for contactPoint * fixes * Tests update * sanity fix * Fixed * Fixes * sanity fix * Fix sanity * fixes * fixes * Fixed idempotency * fix sanity * alert_notification update * fix notification * fixes * folder idempotency * folder test Co-authored-by: ishanjainn <ishan.jain@gmail.com>
This commit is contained in:
parent
e103856767
commit
8eeaea2aa8
@ -148,7 +148,26 @@ def present_alert_contact_point(module):
|
|||||||
if result.status_code == 202:
|
if result.status_code == 202:
|
||||||
return False, True, result.json()
|
return False, True, result.json()
|
||||||
elif result.status_code == 500:
|
elif result.status_code == 500:
|
||||||
api_url = 'https://' + module.params['stack_slug'] + '.grafana.net/api/v1/provisioning/contact-points/' + module.params['uid']
|
sameConfig = False
|
||||||
|
contactPointInfo = {}
|
||||||
|
|
||||||
|
api_url = 'https://' + module.params['stack_slug'] + '.grafana.net/api/v1/provisioning/contact-points'
|
||||||
|
|
||||||
|
result = requests.get(api_url, headers={"Authorization": 'Bearer ' + module.params['grafana_api_key']})
|
||||||
|
|
||||||
|
for contact_points in result.json():
|
||||||
|
if contact_points['uid'] == module.params['uid']:
|
||||||
|
if (contact_points['name'] == module.params['name'] and contact_points['type'] == module.params['type'] and contact_points['settings']
|
||||||
|
and contact_points['settings'] == module.params['settings']
|
||||||
|
and contact_points['disableResolveMessage'] == module.params['disableResolveMessage']):
|
||||||
|
|
||||||
|
sameConfig = True
|
||||||
|
contactPointInfo = contact_points
|
||||||
|
if sameConfig:
|
||||||
|
return False, False, contactPointInfo
|
||||||
|
else:
|
||||||
|
api_url = 'https://' + module.params['stack_slug'] + '.grafana.net/api/v1/provisioning/contact-points/' + \
|
||||||
|
module.params['uid']
|
||||||
|
|
||||||
result = requests.put(api_url, json=body, headers={"Authorization": 'Bearer ' + module.params['grafana_api_key']})
|
result = requests.put(api_url, json=body, headers={"Authorization": 'Bearer ' + module.params['grafana_api_key']})
|
||||||
|
|
||||||
@ -157,20 +176,11 @@ def present_alert_contact_point(module):
|
|||||||
|
|
||||||
result = requests.get(api_url, headers={"Authorization": 'Bearer ' + module.params['grafana_api_key']})
|
result = requests.get(api_url, headers={"Authorization": 'Bearer ' + module.params['grafana_api_key']})
|
||||||
|
|
||||||
contactPointFound = False
|
|
||||||
contactPointInfo = {}
|
|
||||||
|
|
||||||
for contact_points in result.json():
|
for contact_points in result.json():
|
||||||
if contact_points['uid'] == module.params['uid']:
|
if contact_points['uid'] == module.params['uid']:
|
||||||
contactPointFound = True
|
return False, True, contact_points
|
||||||
contactPointInfo = contact_points
|
|
||||||
if contactPointFound:
|
|
||||||
return False, True, contactPointInfo
|
|
||||||
else:
|
|
||||||
return True, False, "Contact Point not found"
|
|
||||||
else:
|
else:
|
||||||
return True, False, {"status": result.status_code, 'response': result.json()['message']}
|
return True, False, {"status": result.status_code, 'response': result.json()['message']}
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return True, False, {"status": result.status_code, 'response': result.json()['message']}
|
return True, False, {"status": result.status_code, 'response': result.json()['message']}
|
||||||
|
|
||||||
|
@ -179,13 +179,18 @@ def alert_notification_policy(module):
|
|||||||
'repeat_interval': module.params['repeatInterval']}
|
'repeat_interval': module.params['repeatInterval']}
|
||||||
|
|
||||||
api_url = 'https://' + module.params['stack_slug'] + '.grafana.net/api/v1/provisioning/policies'
|
api_url = 'https://' + module.params['stack_slug'] + '.grafana.net/api/v1/provisioning/policies'
|
||||||
|
result = requests.get(api_url, headers={"Authorization": 'Bearer ' + module.params['grafana_api_key']})
|
||||||
|
|
||||||
|
if (result.json()['receiver'] == module.params['rootPolicyReceiver'] and result.json()['routes'] == module.params['routes']
|
||||||
|
and result.json()['group_wait'] == module.params['groupWait'] and result.json()['group_interval'] == module.params['groupInterval']
|
||||||
|
and result.json()['repeat_interval'] == module.params['repeatInterval']):
|
||||||
|
return False, False, result.json()
|
||||||
|
else:
|
||||||
|
api_url = 'https://' + module.params['stack_slug'] + '.grafana.net/api/v1/provisioning/policies'
|
||||||
|
|
||||||
result = requests.put(api_url, json=body, headers={"Authorization": 'Bearer ' + module.params['grafana_api_key']})
|
result = requests.put(api_url, json=body, headers={"Authorization": 'Bearer ' + module.params['grafana_api_key']})
|
||||||
|
|
||||||
if result.status_code == 202:
|
if result.status_code == 202:
|
||||||
api_url = 'https://' + module.params['stack_slug'] + '.grafana.net/api/v1/provisioning/policies'
|
|
||||||
|
|
||||||
result = requests.get(api_url, headers={"Authorization": 'Bearer ' + module.params['grafana_api_key']})
|
|
||||||
return False, True, result.json()
|
return False, True, result.json()
|
||||||
else:
|
else:
|
||||||
return True, False, {"status": result.status_code, 'response': result.json()['message']}
|
return True, False, {"status": result.status_code, 'response': result.json()['message']}
|
||||||
|
@ -115,6 +115,12 @@ def present_cloud_plugin(module):
|
|||||||
if result.status_code == 200:
|
if result.status_code == 200:
|
||||||
return False, True, result.json()
|
return False, True, result.json()
|
||||||
elif result.status_code == 409:
|
elif result.status_code == 409:
|
||||||
|
api_url = 'https://grafana.com/api/instances/' + module.params['stack_slug'] + '/plugins/' + module.params['name']
|
||||||
|
result = requests.get(api_url, headers={"Authorization": 'Bearer ' + module.params['cloud_api_key']})
|
||||||
|
|
||||||
|
if result.json()['pluginSlug'] == module.params['name'] and result.json()['version'] == module.params['version']:
|
||||||
|
return False, False, result.json()
|
||||||
|
else:
|
||||||
api_url = 'https://grafana.com/api/instances/' + module.params['stack_slug'] + '/plugins/' + module.params[
|
api_url = 'https://grafana.com/api/instances/' + module.params['stack_slug'] + '/plugins/' + module.params[
|
||||||
'name']
|
'name']
|
||||||
result = requests.post(api_url, json={'version': module.params['version']},
|
result = requests.post(api_url, json={'version': module.params['version']},
|
||||||
|
@ -176,6 +176,20 @@ def present_folder(module):
|
|||||||
if result.status_code == 200:
|
if result.status_code == 200:
|
||||||
return False, True, result.json()
|
return False, True, result.json()
|
||||||
elif result.status_code == 412:
|
elif result.status_code == 412:
|
||||||
|
sameConfig = False
|
||||||
|
folderInfo = {}
|
||||||
|
|
||||||
|
api_url = 'https://' + module.params['stack_slug'] + '.grafana.net/api/folders'
|
||||||
|
result = requests.get(api_url, headers={"Authorization": 'Bearer ' + module.params['grafana_api_key']})
|
||||||
|
|
||||||
|
for folder in result.json():
|
||||||
|
if folder['uid'] == module.params['uid'] and folder['title'] == module.params['title']:
|
||||||
|
sameConfig = True
|
||||||
|
folderInfo = folder
|
||||||
|
|
||||||
|
if sameConfig:
|
||||||
|
return False, False, folderInfo
|
||||||
|
else:
|
||||||
body = {
|
body = {
|
||||||
'uid': module.params['uid'],
|
'uid': module.params['uid'],
|
||||||
'title': module.params['title'],
|
'title': module.params['title'],
|
||||||
@ -189,7 +203,6 @@ def present_folder(module):
|
|||||||
return False, True, result.json()
|
return False, True, result.json()
|
||||||
else:
|
else:
|
||||||
return True, False, {"status": result.status_code, 'response': result.json()['message']}
|
return True, False, {"status": result.status_code, 'response': result.json()['message']}
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return True, False, {"status": result.status_code, 'response': result.json()['message']}
|
return True, False, {"status": result.status_code, 'response': result.json()['message']}
|
||||||
|
|
||||||
|
@ -16,6 +16,24 @@
|
|||||||
- add_result.failed == false
|
- add_result.failed == false
|
||||||
- add_result.output.provenance == "api"
|
- add_result.output.provenance == "api"
|
||||||
|
|
||||||
|
- name: Idempotency Check
|
||||||
|
grafana.grafana.alert_contact_point:
|
||||||
|
name: ops-email
|
||||||
|
uid: opsemail
|
||||||
|
type: email
|
||||||
|
settings: {
|
||||||
|
addresses: "ops@mydomain.com,devs@mydomain.com"
|
||||||
|
}
|
||||||
|
stack_slug: "{{ stack_name }}"
|
||||||
|
grafana_api_key: "{{ grafana_api_key }}"
|
||||||
|
state: present
|
||||||
|
register: idempotent_result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- idempotent_result.changed == false
|
||||||
|
- idempotent_result.output.provenance == "api"
|
||||||
|
|
||||||
- name: Update Alerting contact point
|
- name: Update Alerting contact point
|
||||||
grafana.grafana.alert_contact_point:
|
grafana.grafana.alert_contact_point:
|
||||||
name: ops-email
|
name: ops-email
|
||||||
|
@ -12,7 +12,21 @@
|
|||||||
- add_result.changed == true
|
- add_result.changed == true
|
||||||
- add_result.pluginName == "GitHub"
|
- add_result.pluginName == "GitHub"
|
||||||
|
|
||||||
- name: update a plugin
|
- name: Idempotency Check
|
||||||
|
grafana.grafana.cloud_plugin:
|
||||||
|
name: grafana-github-datasource
|
||||||
|
version: 1.0.14
|
||||||
|
stack_slug: "{{ stack_name }}"
|
||||||
|
cloud_api_key: "{{ grafana_cloud_api_key }}"
|
||||||
|
state: present
|
||||||
|
register: idempotency_result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- idempotency_result.changed == false
|
||||||
|
- idempotency_result.pluginName == "GitHub"
|
||||||
|
|
||||||
|
- name: Update a plugin
|
||||||
grafana.grafana.cloud_plugin:
|
grafana.grafana.cloud_plugin:
|
||||||
name: grafana-github-datasource
|
name: grafana-github-datasource
|
||||||
version: 1.0.15
|
version: 1.0.15
|
||||||
|
@ -10,8 +10,7 @@
|
|||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- create_result.changed == true
|
- create_result.failed == false
|
||||||
- create_result.output.url == "/dashboards/f/test123/ansible-integration-test"
|
|
||||||
|
|
||||||
- name: Delete a folder
|
- name: Delete a folder
|
||||||
grafana.grafana.folder:
|
grafana.grafana.folder:
|
||||||
|
Loading…
Reference in New Issue
Block a user