Merge ~pguimaraes/charm-rsyslog-forwarder-ha/+git/rsyslog-forwarder-ha-charm:master into ~rsyslog-charmers/charm-rsyslog-forwarder-ha:master

Proposed by Pedro Guimarães
Status: Merged
Approved by: Tom Haddon
Approved revision: eb3039b79e4890561314b1630b17eca9068475cf
Merged at revision: a6557a9e7f05a5b7377464029ed49b6c5b0b2dbb
Proposed branch: ~pguimaraes/charm-rsyslog-forwarder-ha/+git/rsyslog-forwarder-ha-charm:master
Merge into: ~rsyslog-charmers/charm-rsyslog-forwarder-ha:master
Diff against target: 84 lines (+55/-1)
3 files modified
config.yaml (+7/-1)
hooks/hooks.py (+11/-0)
tests/unit/test_basic.py (+37/-0)
Reviewer Review Type Date Requested Status
Tom Haddon Approve
Canonical IS Reviewers Pending
Review via email: mp+362725@code.launchpad.net

Commit message

* Allows to add rsyslog servers to log forward to via config options
* Added unit tests

LP: #1812004

Description of the change

* Allows to add rsyslog servers to log forward to via config options
* Added unit tests

LP: #1812004

To post a comment you must log in.
Revision history for this message
Tom Haddon (mthaddon) wrote :

One comment inline

review: Needs Fixing
Revision history for this message
Chris Sanders (chris.sanders) wrote :

One inline comment

Revision history for this message
Tom Haddon (mthaddon) wrote :

LGTM, thanks

review: Approve
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
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision a6557a9e7f05a5b7377464029ed49b6c5b0b2dbb

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/config.yaml b/config.yaml
2index 6fd48cb..1993475 100644
3--- a/config.yaml
4+++ b/config.yaml
5@@ -35,4 +35,10 @@ options:
6 type: string
7 default: "/var/log/dpkg.log /var/log/apt/history.log"
8 description: "A space separated list of files to follow with rsyslog imfile and forward to the aggregator. If set to empty string no files will be watched with imfile."
9-
10+ forward_hosts:
11+ type: string
12+ default:
13+ description: >
14+ A comma-separated list of key=value representing hostname and
15+ ip address of servers to forward all logs to as in
16+ hostname1=host_ip1,hostname2=host_ip2,hostname3=host_ip3
17diff --git a/hooks/hooks.py b/hooks/hooks.py
18index 16aa879..7728a8c 100755
19--- a/hooks/hooks.py
20+++ b/hooks/hooks.py
21@@ -149,7 +149,18 @@ def update_fanout_replication(servers):
22
23
24 def update_replication():
25+ server_list = config_get('forward_hosts')
26 servers = session.query(Server).all()
27+ if server_list:
28+ for server_pair in server_list.split(','):
29+ if len(server_pair.split('=')) != 2:
30+ juju_log("Wrong forward_hosts option, missing "
31+ "hostname=address format, found: {}".format(server_pair))
32+ continue
33+ server = Server()
34+ [server.remote_unit,
35+ server.private_address] = server_pair.split('=')
36+ servers.append(server)
37
38 if not len(servers):
39 juju_log("Ready for add rsyslog relations to this forwarder")
40diff --git a/tests/unit/test_basic.py b/tests/unit/test_basic.py
41index 85991f8..a1a6bd1 100644
42--- a/tests/unit/test_basic.py
43+++ b/tests/unit/test_basic.py
44@@ -185,3 +185,40 @@ class HooksTestCase(unittest.TestCase):
45 fanout.assert_called_once()
46
47 self.service_restart.assert_called_once_with("rsyslog")
48+
49+ @mock.patch("hooks.hooks.update_failover_replication")
50+ @mock.patch("hooks.hooks.update_fanout_replication")
51+ def test_update_replication_bad_charm_config(self, fanout, failover):
52+ """rsyslog forwarding (malformed config check)"""
53+
54+ class DummyServer(object):
55+ @classmethod
56+ def all(self, *args, **kwargs):
57+ return [{}, {}]
58+
59+ self.session.query.return_value = DummyServer()
60+ self.config_get.return_value = 'wrong format'
61+
62+ hooks.update_replication()
63+ args, kwargs = self.juju_log.call_args
64+ assert "found: wrong format" in args[0]
65+
66+ @mock.patch("hooks.hooks.Server")
67+ @mock.patch("hooks.hooks.update_failover_replication")
68+ @mock.patch("hooks.hooks.update_fanout_replication")
69+ def test_update_replication_good_charm_config(self, fanout, failover, Server):
70+ """rsyslog forwarding (valid config options)"""
71+
72+ class DummyServer(object):
73+ @classmethod
74+ def all(self, *args, **kwargs):
75+ return [{}, {}]
76+
77+ self.session.query.return_value = DummyServer()
78+ self.config_get.return_value = \
79+ 'hostname1=host_ip1,hostname2=host_ip2,hostname3=host_ip3'
80+
81+ hooks.update_replication()
82+ self.assertEqual(Server.mock_calls, [
83+ mock.call(), mock.call(), mock.call()
84+ ])

Subscribers

People subscribed via source and target branches