Merge ~hloeung/ubuntu-syncproxy-charm:master into ubuntu-syncproxy-charm:master

Proposed by Haw Loeung
Status: Merged
Approved by: Haw Loeung
Approved revision: 20c7896e8734a4149c3b7479cb6df9e3cfd504eb
Merged at revision: 057cd698dd3e4fec33e4ef53c151bd24a19cc995
Proposed branch: ~hloeung/ubuntu-syncproxy-charm:master
Merge into: ubuntu-syncproxy-charm:master
Diff against target: 126 lines (+55/-11)
2 files modified
reactive/ubuntu_syncproxy.py (+7/-1)
tests/unit/test_ubuntu_syncproxy.py (+48/-10)
Reviewer Review Type Date Requested Status
Paul Collins lgtm Approve
Canonical IS Reviewers Pending
Review via email: mp+422257@code.launchpad.net

Commit message

Allow syncing from upstream without user/password

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
Paul Collins (pjdc) :
review: Approve (lgtm)
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 057cd698dd3e4fec33e4ef53c151bd24a19cc995

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/reactive/ubuntu_syncproxy.py b/reactive/ubuntu_syncproxy.py
2index 8da73e8..c2b92f5 100644
3--- a/reactive/ubuntu_syncproxy.py
4+++ b/reactive/ubuntu_syncproxy.py
5@@ -97,6 +97,8 @@ def configure_ubuntu_syncproxy(home_path=''):
6 'password': config['upstream-rsync-password'],
7 }
8 for k in sorted(rsync_conf.keys()):
9+ if k in ['user', 'password']:
10+ continue
11 if not rsync_conf[k]:
12 status.blocked('Required sync rsync configs missing ({})'.format(k))
13 reactive.set_flag('ubuntu-syncproxy.configured')
14@@ -136,17 +138,21 @@ CONF_TMPL = """
15 TO={target}
16 RSYNC_HOST={host}
17 RSYNC_USER={user}
18-FROM=$RSYNC_USER@$RSYNC_HOST::{module}
19+FROM={user_host}::{module}
20 RSYNC_PASSWORD={password}
21 """
22
23
24 def _setup_archive_sync_conf(conf, user, home_path):
25+ user_host = '$RSYNC_USER@$RSYNC_HOST'
26+ if not conf['user']:
27+ user_host = '$RSYNC_HOST'
28 content = CONF_TMPL.format(
29 header=JUJU_HEADER,
30 host=conf['host'],
31 module=conf['module'],
32 target=conf['target'],
33+ user_host=user_host,
34 user=conf['user'],
35 password=conf['password'],
36 )
37diff --git a/tests/unit/test_ubuntu_syncproxy.py b/tests/unit/test_ubuntu_syncproxy.py
38index 033e457..be44443 100644
39--- a/tests/unit/test_ubuntu_syncproxy.py
40+++ b/tests/unit/test_ubuntu_syncproxy.py
41@@ -237,23 +237,14 @@ class TestCharm(unittest.TestCase):
42 status.blocked.reset_mock()
43 self.mock_config.return_value['upstream-rsync-module'] = 'ftp'
44 ubuntu_syncproxy.configure_ubuntu_syncproxy(self.tmpdir)
45- status.blocked.assert_called_with('Required sync rsync configs missing (password)')
46-
47- status.blocked.reset_mock()
48- self.mock_config.return_value['upstream-rsync-password'] = 'my-secure-rsync-password'
49- ubuntu_syncproxy.configure_ubuntu_syncproxy(self.tmpdir)
50 status.blocked.assert_called_with('Required sync rsync configs missing (target)')
51
52- status.blocked.reset_mock()
53- self.mock_config.return_value['upstream-rsync-target'] = '/srv/ftp.root/ubuntu'
54- ubuntu_syncproxy.configure_ubuntu_syncproxy(self.tmpdir)
55- status.blocked.assert_called_with('Required sync rsync configs missing (user)')
56-
57 setup.assert_not_called()
58 want = [mock.call('ubuntu-syncproxy.configured')]
59 set_flag.assert_has_calls(want, any_order=True)
60
61 status.blocked.reset_mock()
62+ self.mock_config.return_value['upstream-rsync-target'] = '/srv/ftp.root/ubuntu'
63 self.mock_config.return_value['upstream-rsync-user'] = 'syncproxy'
64 ubuntu_syncproxy.configure_ubuntu_syncproxy(self.tmpdir)
65 status.blocked.assert_not_called()
66@@ -262,6 +253,28 @@ class TestCharm(unittest.TestCase):
67
68 @mock.patch('charms.reactive.clear_flag')
69 @mock.patch('charms.reactive.set_flag')
70+ @mock.patch('reactive.ubuntu_syncproxy._setup_archive_sync_conf')
71+ @mock.patch('reactive.ubuntu_syncproxy._setup_archive_sync_target')
72+ @mock.patch('reactive.ubuntu_syncproxy._setup_rsyncd')
73+ def test_configure_ubuntu_rsync_missing_user_or_password(
74+ self, setup_rsyncd, setup_target, setup, set_flag, clear_flag
75+ ):
76+ self.mock_config.return_value['upstream-rsync-password'] = 'my-special-pass'
77+ self.mock_config.return_value['upstream-rsync-user'] = ''
78+ ubuntu_syncproxy.configure_ubuntu_syncproxy(self.tmpdir)
79+ setup.assert_called_once()
80+ status.blocked.assert_not_called()
81+
82+ setup.reset_mock()
83+ status.blocked.reset_mock()
84+ self.mock_config.return_value['upstream-rsync-password'] = ''
85+ self.mock_config.return_value['upstream-rsync-user'] = 'myuser'
86+ ubuntu_syncproxy.configure_ubuntu_syncproxy(self.tmpdir)
87+ setup.assert_called_once()
88+ status.blocked.assert_not_called()
89+
90+ @mock.patch('charms.reactive.clear_flag')
91+ @mock.patch('charms.reactive.set_flag')
92 @mock.patch('reactive.ubuntu_syncproxy._setup_rsyncd')
93 def test_configure_ubuntu_syncproxy_script(self, setup_rsyncd, set_flag, clear_flag):
94 self.mock_config.return_value['sync-script'] = '#!/bin/sh\necho "here test_configure_ubuntu_syncproxy_script"\n'
95@@ -396,6 +409,31 @@ RSYNC_PASSWORD=my-secure-rsync-password
96 got = f.read()
97 self.assertEqual(got, want)
98
99+ def test__setup_archive_sync_conf_no_user(self):
100+ rsync_conf = {
101+ 'host': 'ftpmaster.internal',
102+ 'module': 'ftp',
103+ 'user': '',
104+ 'password': 'my-secure-rsync-password',
105+ 'target': '/srv/ftp.root/ubuntu',
106+ }
107+ ubuntu_syncproxy._setup_archive_sync_conf(rsync_conf, user=self.user, home_path=self.tmpdir)
108+ want = """
109+# This file is Juju managed - do not edit by hand #
110+
111+
112+
113+TO=/srv/ftp.root/ubuntu
114+RSYNC_HOST=ftpmaster.internal
115+RSYNC_USER=
116+FROM=$RSYNC_HOST::ftp
117+RSYNC_PASSWORD=my-secure-rsync-password
118+"""
119+ conf_path = os.path.join(self.tmpdir, 'archive-sync.conf')
120+ with open(conf_path, 'r') as f:
121+ got = f.read()
122+ self.assertEqual(got, want)
123+
124 @mock.patch('os.chown')
125 def test__setup_archive_sync_target(self, chown):
126 current_usr = pwd.getpwuid(os.getuid()).pw_name

Subscribers

People subscribed via source and target branches