Merge ~nick-moffitt/ubuntu-mirror-charm:master into ubuntu-mirror-charm:master

Proposed by Nick Moffitt
Status: Merged
Approved by: Nick Moffitt
Approved revision: 8d9ec9c55c8d6a45f1f22432ec4dc4428438d3b4
Merged at revision: 4c4b53e8143262c2419d7fd48233425dc388bdef
Proposed branch: ~nick-moffitt/ubuntu-mirror-charm:master
Merge into: ubuntu-mirror-charm:master
Diff against target: 77 lines (+13/-3)
2 files modified
hooks/hooks.py (+9/-0)
tests/unit/test_charm.py (+4/-3)
Reviewer Review Type Date Requested Status
Joel Sing (community) +1 Approve
Canonical IS Reviewers Pending
Review via email: mp+394889@code.launchpad.net

Commit message

switching bewteen xinetd and systemd RT#128036

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
Joel Sing (jsing) wrote :

LGTM, but see comments.

review: Approve (+1)
Revision history for this message
Nick Moffitt (nick-moffitt) :
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 4c4b53e8143262c2419d7fd48233425dc388bdef

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/hooks/hooks.py b/hooks/hooks.py
2index f5f9339..62aa81d 100755
3--- a/hooks/hooks.py
4+++ b/hooks/hooks.py
5@@ -437,11 +437,19 @@ def configure_rsync_server(conf, hostname):
6 if conf.rsync_use_xinetd():
7 file_from_template("rsync-default.tmpl", "/etc/default/rsync", tmpl_data)
8 file_from_template("rsync-xinetd.tmpl", "/etc/xinetd.d/rsync", tmpl_data)
9+ check_call('systemctl disable rsyncd.socket'.split())
10+ check_call('systemctl stop rsyncd.socket'.split())
11 # Need to tell systemd to enable rsync and then start it
12 # but only in 15.04 or greater per https://wiki.ubuntu.com/SystemdForUpstartUsers
13 elif float(platform.linux_distribution()[1]) >= 15.04:
14 # We disable rsync and run rsync over systemd sockets to allow limiting
15 # connections per source/IP
16+ # We clean up any xinetd files as well.
17+ try:
18+ os.unlink("/etc/default/rsync")
19+ os.unlink("/etc/xinetd.d/rsync")
20+ except OSError:
21+ pass # If the files are already gone, we're happy.
22 check_call('systemctl disable rsync'.split())
23 check_call('systemctl stop rsync'.split())
24
25@@ -455,6 +463,7 @@ def configure_rsync_server(conf, hostname):
26 check_call('systemctl start rsyncd.socket'.split())
27 # pre-15.04 installations will need to explicitly turn on xinetd,
28 # or continue with previous upstart behaviours.
29+ check_call('systemctl restart xinetd.service'.split())
30
31 log("CHARM: Finished configuring rsync server")
32
33diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py
34index b92bd34..086a5aa 100644
35--- a/tests/unit/test_charm.py
36+++ b/tests/unit/test_charm.py
37@@ -279,13 +279,14 @@ class TestUbuntuMirrorCharm(unittest.TestCase):
38 @patch('hooks.check_call')
39 @patch('hooks.mkdir')
40 @patch('hooks.write_file')
41+ @patch('hooks.os.unlink')
42 @patch('hooks.os.path.isfile')
43 @patch('hooks.os.chmod')
44 @patch('shutil.copyfile')
45 @patch('platform.linux_distribution')
46 @patch('Config.config')
47 def test_configure_rsync_server(self, _config, _distro, _copyfile, _chmod,
48- _isfile, _write_file, _mkdir, _check_call, _charm_dir):
49+ _isfile, _unlink, _write_file, _mkdir, _check_call, _charm_dir):
50 _distro.return_value = ('Ubuntu', '20.04', 'focal')
51 _mkdir.return_value = None
52 _isfile.return_value = False
53@@ -317,7 +318,7 @@ WantedBy=sockets.target
54 """, perms=0o444)
55
56 _copyfile.assert_called_with("./files/rsyncd-systemd.service", "/etc/systemd/system/rsyncd@.service")
57- _check_call.assert_called_with(['systemctl', 'start', 'rsyncd.socket'])
58+ _check_call.assert_any_call(['systemctl', 'start', 'rsyncd.socket'])
59
60 # Cheetah warns about using the Python version of NameMapper, so
61 # we ignore it here. Matching more closely by the message doesn't
62@@ -344,7 +345,6 @@ WantedBy=sockets.target
63 hooks.configure_rsync_server(conf, 'localhost')
64 _write_file.assert_any_call("/etc/rsyncd/motd", "This is an Ubuntu mirror - treat it kindly\n", perms=0o444)
65 self.assertEqual(_write_file.call_count, 5) # We render the two
66- _check_call.assert_not_called() # No systemctl commands are run
67 _write_file.assert_any_call("/etc/xinetd.d/rsync",
68 JUJU_HEADER + """service rsync
69 {
70@@ -359,6 +359,7 @@ WantedBy=sockets.target
71 per_source = 5
72 }
73 """, perms=0o444)
74+ _check_call.any_call(['systemctl', 'stop', 'rsyncd.socket'])
75
76 def test_ensure_symlink(self):
77 try:

Subscribers

People subscribed via source and target branches