Merge ~hloeung/smtp-relay-charm:mx into smtp-relay-charm:master

Proposed by Haw Loeung
Status: Merged
Approved by: Haw Loeung
Approved revision: 41e11c93a389927d157cddc053a8fd527ceb454e
Merged at revision: f45de6b42d00e78a442ff5bc2b6737231176702f
Proposed branch: ~hloeung/smtp-relay-charm:mx
Merge into: smtp-relay-charm:master
Diff against target: 137 lines (+45/-11)
3 files modified
config.yaml (+4/-7)
reactive/smtp_relay.py (+3/-2)
tests/unit/test_smtp_relay.py (+38/-2)
Reviewer Review Type Date Requested Status
James Simpson Approve
Canonical IS Reviewers Pending
Review via email: mp+416915@code.launchpad.net

Commit message

Overload relay_recipient_maps config

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
James Simpson (jsimpso) wrote :

LGTM

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision f45de6b42d00e78a442ff5bc2b6737231176702f

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 cc05bde..494ec54 100644
3--- a/config.yaml
4+++ b/config.yaml
5@@ -82,16 +82,13 @@ options:
6 domains to other local or remote addresses (use 'MANUAL' to
7 indicate it is managed outside of juju configs).
8
9- http://www.postfix.org/postconf.5.html#relay_recipient_maps
10- relay_recipient_maps_combined:
11- type: boolean
12- default: false
13- description: |
14- Use virtual_alias_maps and transport_maps as value for
15- relay_recipient_maps.
16+ Use 'COMBINED' to use both virtual_alias_maps and transport_maps
17+ as value for relay_recipient_maps.
18
19 Allows for all configured aliases and transports to be valid
20 recipients for relay_domains.
21+
22+ http://www.postfix.org/postconf.5.html#relay_recipient_maps
23 restrict_recipients:
24 type: string
25 default: ''
26diff --git a/reactive/smtp_relay.py b/reactive/smtp_relay.py
27index 5e8354b..1f715c3 100644
28--- a/reactive/smtp_relay.py
29+++ b/reactive/smtp_relay.py
30@@ -115,7 +115,6 @@ def configure_smtp_auth(dovecot_config='/etc/dovecot/dovecot.conf', dovecot_user
31 'config.changed.relay_domains',
32 'config.changed.relay_host',
33 'config.changed.relay_recipient_maps',
34- 'config.changed.relay_recipient_maps_combined',
35 'config.changed.restrict_recipients',
36 'config.changed.restrict_senders',
37 'config.changed.restrict_sender_access',
38@@ -160,6 +159,8 @@ def _create_update_map(content, postmap):
39
40 if content.startswith('MANUAL'):
41 hookenv.log('Map {} manually managed'.format(pmfname))
42+ elif content.startswith('COMBINED'):
43+ hookenv.log('Map {} using combined maps'.format(pmfname))
44 else:
45 contents = JUJU_HEADER + content + '\n'
46 changed = _write_file(contents, pmfname) or changed
47@@ -219,7 +220,7 @@ def configure_smtp_relay(postfix_conf_dir='/etc/postfix', tls_dh_params='/etc/ss
48 'relayhost': config['relay_host'],
49 'relay_domains': config['relay_domains'],
50 'relay_recipient_maps': bool(config['relay_recipient_maps']),
51- 'relay_recipient_maps_combined': bool(config['relay_recipient_maps_combined']),
52+ 'relay_recipient_maps_combined': config['relay_recipient_maps'] == 'COMBINED',
53 'restrict_recipients': bool(config['restrict_recipients']),
54 'restrict_senders': bool(config['restrict_senders']),
55 'restrict_sender_access': bool(config['restrict_sender_access']),
56diff --git a/tests/unit/test_smtp_relay.py b/tests/unit/test_smtp_relay.py
57index 58ab466..ddc851c 100644
58--- a/tests/unit/test_smtp_relay.py
59+++ b/tests/unit/test_smtp_relay.py
60@@ -69,7 +69,6 @@ class TestCharm(unittest.TestCase):
61 'relay_domains': '',
62 'relay_host': '',
63 'relay_recipient_maps': '',
64- 'relay_recipient_maps_combined': False,
65 'restrict_recipients': '',
66 'restrict_senders': '',
67 'restrict_sender_access': '',
68@@ -933,6 +932,34 @@ someplace.local encrypt
69 self, call, get_milters, get_cn, set_flag, clear_flag
70 ):
71 postfix_main_cf = os.path.join(self.tmpdir, 'main.cf')
72+ postfix_relay_recipient_maps = os.path.join(self.tmpdir, 'relay_recipient')
73+ get_cn.return_value = ''
74+ get_milters.return_value = ''
75+ self.mock_config.return_value['relay_domains'] = 'mydomain.local mydomain2.local'
76+ self.mock_config.return_value['relay_recipient_maps'] = 'noreply@mydomain.local noreply@mydomain.local'
77+ smtp_relay.configure_smtp_relay(self.tmpdir)
78+ with open(
79+ 'tests/unit/files/postfix_main_relay_domains_with_relay_recipient_maps.cf', 'r', encoding='utf-8'
80+ ) as f:
81+ want = f.read()
82+ with open(postfix_main_cf, 'r', encoding='utf-8') as f:
83+ got = f.read()
84+ self.assertEqual(want, got)
85+ want = smtp_relay.JUJU_HEADER + 'noreply@mydomain.local noreply@mydomain.local' + "\n"
86+ with open(postfix_relay_recipient_maps, 'r', encoding='utf-8') as f:
87+ got = f.read()
88+ self.assertEqual(want, got)
89+
90+ @mock.patch('charms.reactive.clear_flag')
91+ @mock.patch('charms.reactive.set_flag')
92+ @mock.patch('reactive.smtp_relay._get_autocert_cn')
93+ @mock.patch('reactive.smtp_relay._get_milters')
94+ @mock.patch('subprocess.call')
95+ def test_configure_smtp_relay_config_relay_domains_with_relay_recipient_maps_manual(
96+ self, call, get_milters, get_cn, set_flag, clear_flag
97+ ):
98+ postfix_main_cf = os.path.join(self.tmpdir, 'main.cf')
99+ postfix_relay_recipient_maps = os.path.join(self.tmpdir, 'relay_recipient')
100 get_cn.return_value = ''
101 get_milters.return_value = ''
102 self.mock_config.return_value['relay_domains'] = 'mydomain.local mydomain2.local'
103@@ -945,6 +972,10 @@ someplace.local encrypt
104 with open(postfix_main_cf, 'r', encoding='utf-8') as f:
105 got = f.read()
106 self.assertEqual(want, got)
107+ want = ''
108+ with open(postfix_relay_recipient_maps, 'r', encoding='utf-8') as f:
109+ got = f.read()
110+ self.assertEqual(want, got)
111
112 @mock.patch('charms.reactive.clear_flag')
113 @mock.patch('charms.reactive.set_flag')
114@@ -955,10 +986,11 @@ someplace.local encrypt
115 self, call, get_milters, get_cn, set_flag, clear_flag
116 ):
117 postfix_main_cf = os.path.join(self.tmpdir, 'main.cf')
118+ postfix_relay_recipient_maps = os.path.join(self.tmpdir, 'relay_recipient')
119 get_cn.return_value = ''
120 get_milters.return_value = ''
121 self.mock_config.return_value['relay_domains'] = 'mydomain.local mydomain2.local'
122- self.mock_config.return_value['relay_recipient_maps_combined'] = True
123+ self.mock_config.return_value['relay_recipient_maps'] = 'COMBINED'
124 self.mock_config.return_value['transport_maps'] = '.mydomain.local smtp:[smtp.mydomain.local]'
125 self.mock_config.return_value['virtual_alias_maps'] = 'abuse@mydomain.local sysadmin@mydomain.local'
126 smtp_relay.configure_smtp_relay(self.tmpdir)
127@@ -969,6 +1001,10 @@ someplace.local encrypt
128 with open(postfix_main_cf, 'r', encoding='utf-8') as f:
129 got = f.read()
130 self.assertEqual(want, got)
131+ want = ''
132+ with open(postfix_relay_recipient_maps, 'r', encoding='utf-8') as f:
133+ got = f.read()
134+ self.assertEqual(want, got)
135
136 @mock.patch('charms.reactive.clear_flag')
137 @mock.patch('charms.reactive.set_flag')

Subscribers

People subscribed via source and target branches