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
=== modified file 'config.yaml'
--- config.yaml 2016-04-26 17:00:59 +0000
+++ config.yaml 2016-10-24 14:10:45 +0000
@@ -31,4 +31,10 @@
31 type: string31 type: string
32 default: "/var/log/dpkg.log /var/log/apt/history.log"32 default: "/var/log/dpkg.log /var/log/apt/history.log"
33 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."33 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."
3434 forward_hosts:
35 type: string
36 default: ""
37 description: >
38 A comma-separated list of key=value representing hostname and
39 ip address of servers to forward all logs to as in
40 hostname1=host_ip1, hostname2=host_ip2, hostname3=host_ip3
3541
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2016-08-25 16:06:35 +0000
+++ hooks/hooks.py 2016-10-24 14:10:45 +0000
@@ -52,10 +52,10 @@
52]52]
5353
5454
55IMFILE_FILE = '/etc/rsyslog.d/40-rsyslog-imfile.conf'55IMFILE_FILE = '/etc/rsyslog.d/75-rsyslog-imfile.conf'
56LOGS_TEMPLATE = 'keep_local.template'56LOGS_TEMPLATE = 'keep_local.template'
57LOGS_SYSTEM_FILE = '/etc/rsyslog.d/50-default.conf'57LOGS_SYSTEM_FILE = '/etc/rsyslog.d/50-default.conf'
58REPLICATION_FILE = '/etc/rsyslog.d/45-rsyslog-replication.conf'58REPLICATION_FILE = '/etc/rsyslog.d/80-rsyslog-replication.conf'
5959
6060
61hooks = Hooks()61hooks = Hooks()
@@ -123,7 +123,14 @@
123123
124124
125def update_replication():125def update_replication():
126 server_list = config_get('forward_hosts')
126 servers = session.query(Server).all()127 servers = session.query(Server).all()
128 if server_list:
129 for server_pair in server_list.split(','):
130 server = Server()
131 [server.remote_unit,
132 server.private_address] = server_pair.split('=')
133 servers.append(server)
127134
128 if not len(servers):135 if not len(servers):
129 juju_log("Ready for add rsyslog relations to this forwarder")136 juju_log("Ready for add rsyslog relations to this forwarder")
130137
=== modified file 'tests/unit/test_basic.py'
--- tests/unit/test_basic.py 2016-05-19 16:36:12 +0000
+++ tests/unit/test_basic.py 2016-10-24 14:10:45 +0000
@@ -160,7 +160,7 @@
160 return [{}, {}]160 return [{}, {}]
161161
162 self.session.query.return_value = DummyServer()162 self.session.query.return_value = DummyServer()
163 self.config_get.return_value = 'failover'163 self.config_get.side_effect = ['', 'failover']
164164
165 hooks.update_replication()165 hooks.update_replication()
166 failover.assert_called_once()166 failover.assert_called_once()
@@ -178,7 +178,86 @@
178 return [{}, {}]178 return [{}, {}]
179179
180 self.session.query.return_value = DummyServer()180 self.session.query.return_value = DummyServer()
181 self.config_get.return_value = 'fanout'181 self.config_get.side_effect = ['', 'fanout']
182
183 hooks.update_replication()
184 fanout.assert_called_once()
185
186 self.service_restart.assert_called_once_with("rsyslog")
187
188 @mock.patch("hooks.hooks.update_failover_replication")
189 @mock.patch("hooks.hooks.update_fanout_replication")
190 def test_update_replication_fwd_hosts_failover(self, fanout, failover):
191 """check if update_replication works with provided forward_hosts
192 in failover mode"""
193
194 self.config_get.side_effect = ['svr1=ip1, srv2=ip2', 'failover']
195
196 hooks.update_replication()
197 failover.assert_called_once()
198
199 self.service_restart.assert_called_once_with("rsyslog")
200
201 @mock.patch("hooks.hooks.update_failover_replication")
202 @mock.patch("hooks.hooks.update_fanout_replication")
203 def test_update_replication_fwd_one_host_fanout(self, fanout, failover):
204 """check if update_replication switch to fanout if only one provided
205 forward_hosts in failover mode"""
206
207 self.config_get.side_effect = ['svr1=ip1', 'fanout']
208
209 hooks.update_replication()
210
211 self.juju_log.assert_called_once()
212 failover.assert_called_once()
213 self.sys.exit.assert_called_once()
214 self.service_restart.assert_called_once_with("rsyslog")
215
216 @mock.patch("hooks.hooks.update_failover_replication")
217 @mock.patch("hooks.hooks.update_fanout_replication")
218 def test_update_replication_fwd(self, fanout, failover):
219 """check if update_replication works with provided forward_hosts
220 in fanout mode"""
221
222 self.config_get.side_effect = ['svr1=ip1, srv2=ip2', 'fanout']
223
224 hooks.update_replication()
225 fanout.assert_called_once()
226
227 self.service_restart.assert_called_once_with("rsyslog")
228
229 @mock.patch("hooks.hooks.update_failover_replication")
230 @mock.patch("hooks.hooks.update_fanout_replication")
231 def test_update_replication_fwd_rel_failover(self, fanout, failover):
232 """check if update_replication works with provided forward_hosts
233 and a relation in failover mode"""
234
235 class DummyServer(object):
236 @classmethod
237 def all(self, *args, **kwargs):
238 return [{}]
239
240 self.config_get.side_effect = ['svr1=ip1, srv2=ip2', 'failover']
241 self.session.query.return_value = DummyServer()
242
243 hooks.update_replication()
244 failover.assert_called_once()
245
246 self.service_restart.assert_called_once_with("rsyslog")
247
248 @mock.patch("hooks.hooks.update_failover_replication")
249 @mock.patch("hooks.hooks.update_fanout_replication")
250 def test_update_replication_fwd_rel_fanout(self, fanout, failover):
251 """check if update_replication works with provided forward_hosts
252 and a relation in fanout mode"""
253
254 class DummyServer(object):
255 @classmethod
256 def all(self, *args, **kwargs):
257 return [{}, {}]
258
259 self.config_get.side_effect = ['svr1=ip1, srv2=ip2', 'fanout']
260 self.session.query.return_value = DummyServer()
182261
183 hooks.update_replication()262 hooks.update_replication()
184 fanout.assert_called_once()263 fanout.assert_called_once()

Subscribers

People subscribed via source and target branches