Merge lp:~ltrager/maas/peer_proxy into lp:maas

Proposed by Lee Trager
Status: Rejected
Rejected by: MAAS Lander
Proposed branch: lp:~ltrager/maas/peer_proxy
Merge into: lp:maas
Diff against target: 139 lines (+61/-1)
4 files modified
src/maasserver/models/config.py (+2/-1)
src/maasserver/proxyconfig.py (+18/-0)
src/maasserver/tests/test_proxyconfig.py (+33/-0)
src/provisioningserver/templates/proxy/maas-proxy.conf.template (+8/-0)
To merge this branch: bzr merge lp:~ltrager/maas/peer_proxy
Reviewer Review Type Date Requested Status
Andres Rodriguez (community) Needs Information
Review via email: mp+323706@code.launchpad.net

Commit message

Allow user Squid proxy config to be defined in /etc/maas/proxy/{*.acl, *.conf} or /var/snap/maas/common/proxy/{*.acl, *.conf}

To post a comment you must log in.
Revision history for this message
Andres Rodriguez (andreserl) wrote :

This is a nice improvement but doesn't really solve what the real issue is. That said, this could be additional so let's discuss it.

review: Needs Information
Revision history for this message
MAAS Lander (maas-lander) wrote :

Transitioned to Git.

lp:maas has now moved from Bzr to Git.
Please propose your branches with Launchpad using Git.

git clone https://git.launchpad.net/maas

Unmerged revisions

6042. By Lee Trager

Allow user Squid proxy config to be defined in /etc/maas/proxy/{*.acl, *.conf} or /var/snap/maas/common/proxy/{*.acl, *.conf}

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/models/config.py'
2--- src/maasserver/models/config.py 2017-04-07 21:52:35 +0000
3+++ src/maasserver/models/config.py 2017-05-06 00:25:16 +0000
4@@ -96,11 +96,12 @@
5 'enable_analytics': True,
6 # First admin journey.
7 'completed_intro': False,
8+ # Script results.
9 'max_node_commissioning_results': 10,
10 'max_node_testing_results': 10,
11 'max_node_installation_results': 1,
12 # Notifications.
13- 'subnet_ip_exhaustion_threshold_count': 16
14+ 'subnet_ip_exhaustion_threshold_count': 16,
15 }
16
17
18
19=== modified file 'src/maasserver/proxyconfig.py'
20--- src/maasserver/proxyconfig.py 2017-05-02 19:00:58 +0000
21+++ src/maasserver/proxyconfig.py 2017-05-06 00:25:16 +0000
22@@ -10,6 +10,7 @@
23 ]
24
25 import datetime
26+from glob import glob
27 import os
28 import socket
29 import sys
30@@ -63,6 +64,21 @@
31 def proxy_update_config(reload_proxy=True):
32 """Regenerate the proxy configuration file."""
33
34+ def check_user_proxy_conf(filename):
35+ # Squid fails to start if instructed to source a path which does not
36+ # exist. Check if the path exists, if it doesn't return None which
37+ # tells the template to not source anything.
38+ if snappy.running_in_snap():
39+ path = os.path.join(snappy.get_snap_common_path(), 'proxy')
40+ else:
41+ path = os.path.join('/etc', 'maas', 'proxy')
42+ if not os.path.exists(path):
43+ return None
44+ full_path = os.path.join(path, filename)
45+ if glob(full_path) == []:
46+ return None
47+ return full_path
48+
49 @transactional
50 def write_config():
51 allowed_subnets = Subnet.objects.filter(allow_proxy=True)
52@@ -76,6 +92,8 @@
53 'snap_path': snappy.get_snap_path(),
54 'snap_data_path': snappy.get_snap_data_path(),
55 'snap_common_path': snappy.get_snap_common_path(),
56+ 'user_acls': check_user_proxy_conf('*.acl'),
57+ 'user_conf': check_user_proxy_conf('*.conf'),
58 }
59 template_path = locate_template('proxy', MAAS_PROXY_CONF_TEMPLATE)
60 template = tempita.Template.from_filename(
61
62=== modified file 'src/maasserver/tests/test_proxyconfig.py'
63--- src/maasserver/tests/test_proxyconfig.py 2017-05-02 18:42:35 +0000
64+++ src/maasserver/tests/test_proxyconfig.py 2017-05-06 00:25:16 +0000
65@@ -86,6 +86,38 @@
66
67 @wait_for_reactor
68 @inlineCallbacks
69+ def test__doesnt_include_user_config_when_not_found(self):
70+ self.patch(settings, "PROXY_CONNECT", True)
71+ yield proxyconfig.proxy_update_config(reload_proxy=False)
72+ matcher = Not(Contains("include "))
73+ self.assertThat(
74+ "%s/%s" % (self.tmpdir, proxyconfig.MAAS_PROXY_CONF_NAME),
75+ FileContains(matcher=matcher))
76+
77+ @wait_for_reactor
78+ @inlineCallbacks
79+ def test__includes_user_config_when_found(self):
80+ self.patch(settings, "PROXY_CONNECT", True)
81+ self.patch(snappy, 'running_in_snap').return_value = True
82+ self.patch(snappy, 'get_snap_common_path').return_value = self.tmpdir
83+ proxy_path = os.path.join(self.tmpdir, 'proxy')
84+ os.makedirs(proxy_path)
85+ open(os.path.join(
86+ proxy_path, '%s.acl' % factory.make_name('acl')), 'w').close()
87+ open(os.path.join(
88+ proxy_path, '%s.conf' % factory.make_name('conf')), 'w').close()
89+ yield proxyconfig.proxy_update_config(reload_proxy=False)
90+ matcher = Contains("include %s/proxy/*.acl" % self.tmpdir)
91+ self.assertThat(
92+ "%s/%s" % (self.tmpdir, proxyconfig.MAAS_PROXY_CONF_NAME),
93+ FileContains(matcher=matcher))
94+ matcher = Contains("include %s/proxy/*.conf" % self.tmpdir)
95+ self.assertThat(
96+ "%s/%s" % (self.tmpdir, proxyconfig.MAAS_PROXY_CONF_NAME),
97+ FileContains(matcher=matcher))
98+
99+ @wait_for_reactor
100+ @inlineCallbacks
101 def test__calls_reloadService(self):
102 self.patch(settings, "PROXY_CONNECT", True)
103 yield deferToDatabase(self.make_subnet)
104@@ -99,6 +131,7 @@
105 def test__calls_restartService(self):
106 self.patch(settings, "PROXY_CONNECT", True)
107 self.patch(snappy, 'running_in_snap').return_value = True
108+ self.patch(snappy, 'get_snap_common_path').return_value = '/'
109 yield deferToDatabase(self.make_subnet)
110 yield proxyconfig.proxy_update_config()
111 self.assertThat(
112
113=== modified file 'src/provisioningserver/templates/proxy/maas-proxy.conf.template'
114--- src/provisioningserver/templates/proxy/maas-proxy.conf.template 2017-04-05 14:58:22 +0000
115+++ src/provisioningserver/templates/proxy/maas-proxy.conf.template 2017-05-06 00:25:16 +0000
116@@ -1,4 +1,6 @@
117 # DO NOT EDIT. This file is automatically created by MAAS.
118+# User defined ACLs can be defined in {{if running_in_snap}}{{snap_common_path}}{{else}}/etc/maas{{endif}}/proxy/*.acl
119+# Additional user defined config can be defined in {{if running_in_snap}}{{snap_common_path}}{{else}}/etc/maas{{endif}}/proxy/*.conf
120 # Last updated at {{modified}}.
121
122 # Inspired by UDS's conference proxy
123@@ -15,6 +17,9 @@
124 acl Safe_ports port 443 # https
125 acl Safe_ports port 1025-65535 # unregistered ports
126 acl CONNECT method CONNECT
127+{{if user_acls is not None}}
128+include {{user_acls}}
129+{{endif}}
130 http_access allow maas_proxy_manager localhost
131 http_access deny maas_proxy_manager
132 http_access deny !Safe_ports
133@@ -56,3 +61,6 @@
134 cache_log /var/log/maas/proxy/cache.log
135 cache_store_log /var/log/maas/proxy/store.log
136 {{endif}}
137+{{if user_conf is not None}}
138+include {{user_conf}}
139+{{endif}}