Merge ~jamesbeedy/charm-grafana:relation_base_to_endpoint into charm-grafana:master

Proposed by james beedy on 2020-11-03
Status: Needs review
Proposed branch: ~jamesbeedy/charm-grafana:relation_base_to_endpoint
Merge into: charm-grafana:master
Diff against target: 52 lines (+24/-18)
1 file modified
src/reactive/grafana.py (+24/-18)
Reviewer Review Type Date Requested Status
BootStack Reviewers 2020-11-03 Pending
Review via email: mp+393218@code.launchpad.net

Description of the change

Accompanying changes to interface-grafana-source changes (https://code.launchpad.net/~jamesbeedy/interface-grafana-source/+git/interface-grafana-source/+ref/relation_base_to_endpoint) in respect to replacing RelationBase with Endpoint in the grafana-source requires.

To post a comment you must log in.

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Unmerged commits

4491ac8... by james beedy on 2020-11-03

refactor sources_gone to accommodate for Endpoint relation

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/reactive/grafana.py b/src/reactive/grafana.py
2index d6718eb..a95b271 100644
3--- a/src/reactive/grafana.py
4+++ b/src/reactive/grafana.py
5@@ -616,25 +616,31 @@ def sources_gone(relation):
6 hookenv.log(relation)
7 # Update the datasources now with the new information that something is
8 # not available.
9- conv = relation.conversation()
10- ds = {
11- "service_name": conv.scope.split("/")[0],
12- "type": conv.get_remote("type"),
13- "url": conv.get_remote("url"),
14- "description": conv.get_remote("description"),
15- }
16- hookenv.log("Removing datasource:")
17- hookenv.log(ds)
18+ units = relation.all_joined_units
19+ if len(units) > 0:
20+
21+ unit = units[0]
22+
23+ ds = {
24+ "service_name": relation.application_name,
25+ "type": unit.received.get('type'),
26+ "url": unit.received.get('url'),
27+ "description": unit.received.get('description'),
28+ }
29+
30+ hookenv.log("Removing datasource:")
31+ hookenv.log(ds)
32+
33+ if ds:
34+ conn = sqlite3.connect("{}/grafana.db".format(data_dir), timeout=30)
35+ cur = conn.cursor()
36+ cur.execute(
37+ "DELETE FROM DATA_SOURCE WHERE type=? AND url=?",
38+ (ds["type"], ds["url"]),
39+ )
40+ conn.commit()
41+ cur.close()
42
43- if ds:
44- conn = sqlite3.connect("{}/grafana.db".format(data_dir), timeout=30)
45- cur = conn.cursor()
46- cur.execute(
47- "DELETE FROM DATA_SOURCE WHERE type=? AND url=?",
48- (ds["type"], ds["url"]),
49- )
50- conn.commit()
51- cur.close()
52 relation.set_local = None
53
54

Subscribers

People subscribed via source and target branches