Merge lp:~louis/charms/trusty/rsyslog-forwarder-ha/add_forward_hosts into lp:charms/trusty/rsyslog-forwarder-ha

Proposed by Louis Bouchard
Status: Merged
Merged at revision: 18
Proposed branch: lp:~louis/charms/trusty/rsyslog-forwarder-ha/add_forward_hosts
Merge into: lp:charms/trusty/rsyslog-forwarder-ha
Diff against target: 148 lines (+97/-5)
3 files modified
config.yaml (+7/-1)
hooks/hooks.py (+9/-2)
tests/unit/test_basic.py (+81/-2)
To merge this branch: bzr merge lp:~louis/charms/trusty/rsyslog-forwarder-ha/add_forward_hosts
Reviewer Review Type Date Requested Status
Jorge Niedbalski (community) Approve
Jorge Niedbalski Pending
Review via email: mp+309120@code.launchpad.net

Description of the change

Add 'forward_hosts' parameter to provide a list of rsyslog listeners that are not juju-deployed.
Test coverage also included.

To post a comment you must log in.
Revision history for this message
Jorge Niedbalski (niedbalski) wrote :

Hello Louis,

Thank you for submitting this fix.

I deployed this charm on the following environment:

[Environment]
UPGRADE-AVAILABLE
1.25.6

[Services]
NAME STATUS EXPOSED CHARM
external active false cs:xenial/ubuntu-8
rsyslog-forwarder-ha false local:trusty/rsyslog-forwarder-ha-0
ubuntu active false cs:trusty/ubuntu-8

[Units]
ID WORKLOAD-STATE AGENT-STATE VERSION MACHINE PORTS PUBLIC-ADDRESS MESSAGE
external/0 active idle 1.25.5.1 4 10.5.0.41 ready
ubuntu/3 active idle 1.25.5.1 5 10.5.0.42 ready
  rsyslog-forwarder-ha/0 unknown idle 1.25.5.1 10.5.0.42

[Machines]
ID STATE VERSION DNS INS-ID SERIES HARDWARE
0 started 1.25.5.1 10.5.0.37 d459cd19-5ea2-4d96-b187-13fc8e4117af xenial arch=amd64 cpu-cores=1 mem=1536M root-disk=10240M availability-zone=nova
4 started 1.25.5.1 10.5.0.41 82aac885-f27b-450f-a221-a6c65c68104a xenial arch=amd64 cpu-cores=1 mem=1536M root-disk=10240M availability-zone=nova
5 started 1.25.5.1 10.5.0.42 813f9b99-bdeb-4a6f-8838-546720998853 trusty arch=amd64 cpu-cores=1 mem=1536M root-disk=10240M availability-zone=nova

Then I related ubuntu with rsyslog-forwarder-ha, and then I did set the forward_hosts option:

ubuntu@niedbalski-bastion:~$ juju set rsyslog-forwarder-ha forward_hosts=external=10.5.0.41

The resulting configuration looks like:

$ActionQueueType LinkedList # use asynchronous processing
$ActionQueueFileName external # set file name, also enables disk mode
$ActionResumeRetryCount -1 # infinite retries on insert failure
$ActionQueueSaveOnShutdown on # save in-memory data if rsyslog shuts down

# Forward everything

*.* @10.5.0.41:514

The logs are being forwarder to the remote rsyslog server, I did run the lint/tests
also. All seems good.

LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'config.yaml'
2--- config.yaml 2016-04-26 17:00:59 +0000
3+++ config.yaml 2016-10-24 14:10:45 +0000
4@@ -31,4 +31,10 @@
5 type: string
6 default: "/var/log/dpkg.log /var/log/apt/history.log"
7 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."
8-
9+ forward_hosts:
10+ type: string
11+ default: ""
12+ description: >
13+ A comma-separated list of key=value representing hostname and
14+ ip address of servers to forward all logs to as in
15+ hostname1=host_ip1, hostname2=host_ip2, hostname3=host_ip3
16
17=== modified file 'hooks/hooks.py'
18--- hooks/hooks.py 2016-08-25 16:06:35 +0000
19+++ hooks/hooks.py 2016-10-24 14:10:45 +0000
20@@ -52,10 +52,10 @@
21 ]
22
23
24-IMFILE_FILE = '/etc/rsyslog.d/40-rsyslog-imfile.conf'
25+IMFILE_FILE = '/etc/rsyslog.d/75-rsyslog-imfile.conf'
26 LOGS_TEMPLATE = 'keep_local.template'
27 LOGS_SYSTEM_FILE = '/etc/rsyslog.d/50-default.conf'
28-REPLICATION_FILE = '/etc/rsyslog.d/45-rsyslog-replication.conf'
29+REPLICATION_FILE = '/etc/rsyslog.d/80-rsyslog-replication.conf'
30
31
32 hooks = Hooks()
33@@ -123,7 +123,14 @@
34
35
36 def update_replication():
37+ server_list = config_get('forward_hosts')
38 servers = session.query(Server).all()
39+ if server_list:
40+ for server_pair in server_list.split(','):
41+ server = Server()
42+ [server.remote_unit,
43+ server.private_address] = server_pair.split('=')
44+ servers.append(server)
45
46 if not len(servers):
47 juju_log("Ready for add rsyslog relations to this forwarder")
48
49=== modified file 'tests/unit/test_basic.py'
50--- tests/unit/test_basic.py 2016-05-19 16:36:12 +0000
51+++ tests/unit/test_basic.py 2016-10-24 14:10:45 +0000
52@@ -160,7 +160,7 @@
53 return [{}, {}]
54
55 self.session.query.return_value = DummyServer()
56- self.config_get.return_value = 'failover'
57+ self.config_get.side_effect = ['', 'failover']
58
59 hooks.update_replication()
60 failover.assert_called_once()
61@@ -178,7 +178,86 @@
62 return [{}, {}]
63
64 self.session.query.return_value = DummyServer()
65- self.config_get.return_value = 'fanout'
66+ self.config_get.side_effect = ['', 'fanout']
67+
68+ hooks.update_replication()
69+ fanout.assert_called_once()
70+
71+ self.service_restart.assert_called_once_with("rsyslog")
72+
73+ @mock.patch("hooks.hooks.update_failover_replication")
74+ @mock.patch("hooks.hooks.update_fanout_replication")
75+ def test_update_replication_fwd_hosts_failover(self, fanout, failover):
76+ """check if update_replication works with provided forward_hosts
77+ in failover mode"""
78+
79+ self.config_get.side_effect = ['svr1=ip1, srv2=ip2', 'failover']
80+
81+ hooks.update_replication()
82+ failover.assert_called_once()
83+
84+ self.service_restart.assert_called_once_with("rsyslog")
85+
86+ @mock.patch("hooks.hooks.update_failover_replication")
87+ @mock.patch("hooks.hooks.update_fanout_replication")
88+ def test_update_replication_fwd_one_host_fanout(self, fanout, failover):
89+ """check if update_replication switch to fanout if only one provided
90+ forward_hosts in failover mode"""
91+
92+ self.config_get.side_effect = ['svr1=ip1', 'fanout']
93+
94+ hooks.update_replication()
95+
96+ self.juju_log.assert_called_once()
97+ failover.assert_called_once()
98+ self.sys.exit.assert_called_once()
99+ self.service_restart.assert_called_once_with("rsyslog")
100+
101+ @mock.patch("hooks.hooks.update_failover_replication")
102+ @mock.patch("hooks.hooks.update_fanout_replication")
103+ def test_update_replication_fwd(self, fanout, failover):
104+ """check if update_replication works with provided forward_hosts
105+ in fanout mode"""
106+
107+ self.config_get.side_effect = ['svr1=ip1, srv2=ip2', 'fanout']
108+
109+ hooks.update_replication()
110+ fanout.assert_called_once()
111+
112+ self.service_restart.assert_called_once_with("rsyslog")
113+
114+ @mock.patch("hooks.hooks.update_failover_replication")
115+ @mock.patch("hooks.hooks.update_fanout_replication")
116+ def test_update_replication_fwd_rel_failover(self, fanout, failover):
117+ """check if update_replication works with provided forward_hosts
118+ and a relation in failover mode"""
119+
120+ class DummyServer(object):
121+ @classmethod
122+ def all(self, *args, **kwargs):
123+ return [{}]
124+
125+ self.config_get.side_effect = ['svr1=ip1, srv2=ip2', 'failover']
126+ self.session.query.return_value = DummyServer()
127+
128+ hooks.update_replication()
129+ failover.assert_called_once()
130+
131+ self.service_restart.assert_called_once_with("rsyslog")
132+
133+ @mock.patch("hooks.hooks.update_failover_replication")
134+ @mock.patch("hooks.hooks.update_fanout_replication")
135+ def test_update_replication_fwd_rel_fanout(self, fanout, failover):
136+ """check if update_replication works with provided forward_hosts
137+ and a relation in fanout mode"""
138+
139+ class DummyServer(object):
140+ @classmethod
141+ def all(self, *args, **kwargs):
142+ return [{}, {}]
143+
144+ self.config_get.side_effect = ['svr1=ip1, srv2=ip2', 'fanout']
145+ self.session.query.return_value = DummyServer()
146
147 hooks.update_replication()
148 fanout.assert_called_once()

Subscribers

People subscribed via source and target branches