Merge ~sajoupa/charm-telegraf:snap_daemon_user into charm-telegraf:master

Proposed by Laurent Sesquès
Status: Merged
Approved by: Benjamin Allot
Approved revision: d5f8eb421a8e45124bc31e00ee3f6086e0a605c9
Merged at revision: 6ef444a43da988a0b48fc24d3acde8ad1c348bb5
Proposed branch: ~sajoupa/charm-telegraf:snap_daemon_user
Merge into: charm-telegraf:master
Diff against target: 114 lines (+43/-5)
4 files modified
src/reactive/telegraf.py (+25/-1)
src/tests/functional/tests/base.py (+4/-2)
src/tests/functional/tests/test_compute.py (+1/-1)
src/tests/unit/test_telegraf.py (+13/-1)
Reviewer Review Type Date Requested Status
Benjamin Allot Approve
BootStack Reviewers Pending
Review via email: mp+397492@code.launchpad.net

Commit message

when using the snap, set config files ownership to snap_daemon https://snapcraft.io/docs/services-and-daemons

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

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

Revision history for this message
Laurent Sesquès (sajoupa) wrote :

passes make test (without bionic-compute and focal-compute, which kill my machine)

Revision history for this message
Laurent Sesquès (sajoupa) wrote :

(also, a couple of fixes for black / make lint)

Revision history for this message
Benjamin Allot (ballot) wrote :

LGTM

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 6ef444a43da988a0b48fc24d3acde8ad1c348bb5

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/reactive/telegraf.py b/src/reactive/telegraf.py
2index 017ad67..d8fd268 100644
3--- a/src/reactive/telegraf.py
4+++ b/src/reactive/telegraf.py
5@@ -72,6 +72,11 @@ GRAFANA_DASHBOARD_NAME = "telegraf"
6 SNAP_SERVICE = "snap.telegraf.telegraf"
7 DEB_SERVICE = "telegraf"
8
9+SNAP_USER = "snap_daemon"
10+SNAP_GROUP = "snap_daemon"
11+DEB_USER = "root"
12+DEB_GROUP = "telegraf"
13+
14 # Utilities #
15
16
17@@ -83,7 +88,8 @@ def write_telegraf_file(path, content):
18 return host.write_file(
19 path,
20 content.encode("UTF-8"),
21- group="telegraf",
22+ owner=get_telegraf_user(),
23+ group=get_telegraf_group(),
24 perms=0o640,
25 )
26
27@@ -101,6 +107,24 @@ def get_install_method():
28 raise InvalidInstallMethod()
29
30
31+def get_telegraf_user():
32+ install_method = get_install_method()
33+
34+ # get_install_method() already checked that we got a valid value
35+ if install_method == "snap":
36+ return SNAP_USER
37+ return DEB_USER
38+
39+
40+def get_telegraf_group():
41+ install_method = get_install_method()
42+
43+ # get_install_method() already checked that we got a valid value
44+ if install_method == "snap":
45+ return SNAP_GROUP
46+ return DEB_GROUP
47+
48+
49 def get_base_dir():
50 config = hookenv.config()
51
52diff --git a/src/tests/functional/tests/base.py b/src/tests/functional/tests/base.py
53index 3433c5d..23dedab 100644
54--- a/src/tests/functional/tests/base.py
55+++ b/src/tests/functional/tests/base.py
56@@ -32,8 +32,10 @@ class BaseTelegrafTest(unittest.TestCase):
57 def check_re_pattern(self, re_pattern, text):
58 logging.info("checking metrics %s", re_pattern)
59 # findall returns a list, [] when no match
60- self.assertTrue(re.findall(re_pattern, text, flags=re.M),
61- msg="Failed to find {}".format(re_pattern))
62+ self.assertTrue(
63+ re.findall(re_pattern, text, flags=re.M),
64+ msg="Failed to find {}".format(re_pattern),
65+ )
66
67 def check_metrics(self, patterns):
68 principal_units = (
69diff --git a/src/tests/functional/tests/test_compute.py b/src/tests/functional/tests/test_compute.py
70index db4f3b9..450205f 100644
71--- a/src/tests/functional/tests/test_compute.py
72+++ b/src/tests/functional/tests/test_compute.py
73@@ -43,7 +43,7 @@ class TestTelegrafCompute(BaseTelegrafTest):
74 # Sometimes, the logs show errors on Telegraf first start because br-int isn't
75 # yet started. To overcome this, just check the most recent start of Telegraf.
76 up_to_word = "I! Starting Telegraf"
77- rx_to_last = r'^.*{}'.format(re.escape(up_to_word))
78+ rx_to_last = r"^.*{}".format(re.escape(up_to_word))
79 last_logs = re.sub(rx_to_last, "", content, flags=re.DOTALL).strip()
80 error_pattern = "E!"
81 self.assertFalse(re.findall(error_pattern, last_logs, flags=re.M))
82diff --git a/src/tests/unit/test_telegraf.py b/src/tests/unit/test_telegraf.py
83index 7179db6..62a5595 100644
84--- a/src/tests/unit/test_telegraf.py
85+++ b/src/tests/unit/test_telegraf.py
86@@ -190,15 +190,27 @@ def check_sysstat_config(original, expected):
87 assert actual == expected
88
89
90-def test_write_telegraf_file(mocker):
91+def test_write_telegraf_file(mocker, config):
92+ config["install_method"] = "deb"
93 write_file = mocker.patch("charmhelpers.core.host.write_file")
94 telegraf.write_telegraf_file("the-path", "the-content áéíóú")
95 write_file.assert_called_once_with(
96 "the-path",
97 "the-content áéíóú".encode("utf-8"),
98+ owner="root",
99 group="telegraf",
100 perms=0o640,
101 )
102+ config["install_method"] = "snap"
103+ write_file = mocker.patch("charmhelpers.core.host.write_file")
104+ telegraf.write_telegraf_file("the-path", "the-content áéíóú")
105+ write_file.assert_called_once_with(
106+ "the-path",
107+ "the-content áéíóú".encode("utf-8"),
108+ owner="snap_daemon",
109+ group="snap_daemon",
110+ perms=0o640,
111+ )
112
113
114 def test_sadc_options_correct(monkeypatch):

Subscribers

People subscribed via source and target branches

to all changes: