Merge lp:~ltrager/maas/peer_proxy into lp:~maas-committers/maas/trunk

Proposed by Lee Trager
Status: Rejected
Rejected by: MAAS Lander
Proposed branch: lp:~ltrager/maas/peer_proxy
Merge into: lp:~maas-committers/maas/trunk
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
=== modified file 'src/maasserver/models/config.py'
--- src/maasserver/models/config.py 2017-04-07 21:52:35 +0000
+++ src/maasserver/models/config.py 2017-05-06 00:25:16 +0000
@@ -96,11 +96,12 @@
96 'enable_analytics': True,96 'enable_analytics': True,
97 # First admin journey.97 # First admin journey.
98 'completed_intro': False,98 'completed_intro': False,
99 # Script results.
99 'max_node_commissioning_results': 10,100 'max_node_commissioning_results': 10,
100 'max_node_testing_results': 10,101 'max_node_testing_results': 10,
101 'max_node_installation_results': 1,102 'max_node_installation_results': 1,
102 # Notifications.103 # Notifications.
103 'subnet_ip_exhaustion_threshold_count': 16104 'subnet_ip_exhaustion_threshold_count': 16,
104 }105 }
105106
106107
107108
=== modified file 'src/maasserver/proxyconfig.py'
--- src/maasserver/proxyconfig.py 2017-05-02 19:00:58 +0000
+++ src/maasserver/proxyconfig.py 2017-05-06 00:25:16 +0000
@@ -10,6 +10,7 @@
10 ]10 ]
1111
12import datetime12import datetime
13from glob import glob
13import os14import os
14import socket15import socket
15import sys16import sys
@@ -63,6 +64,21 @@
63def proxy_update_config(reload_proxy=True):64def proxy_update_config(reload_proxy=True):
64 """Regenerate the proxy configuration file."""65 """Regenerate the proxy configuration file."""
6566
67 def check_user_proxy_conf(filename):
68 # Squid fails to start if instructed to source a path which does not
69 # exist. Check if the path exists, if it doesn't return None which
70 # tells the template to not source anything.
71 if snappy.running_in_snap():
72 path = os.path.join(snappy.get_snap_common_path(), 'proxy')
73 else:
74 path = os.path.join('/etc', 'maas', 'proxy')
75 if not os.path.exists(path):
76 return None
77 full_path = os.path.join(path, filename)
78 if glob(full_path) == []:
79 return None
80 return full_path
81
66 @transactional82 @transactional
67 def write_config():83 def write_config():
68 allowed_subnets = Subnet.objects.filter(allow_proxy=True)84 allowed_subnets = Subnet.objects.filter(allow_proxy=True)
@@ -76,6 +92,8 @@
76 'snap_path': snappy.get_snap_path(),92 'snap_path': snappy.get_snap_path(),
77 'snap_data_path': snappy.get_snap_data_path(),93 'snap_data_path': snappy.get_snap_data_path(),
78 'snap_common_path': snappy.get_snap_common_path(),94 'snap_common_path': snappy.get_snap_common_path(),
95 'user_acls': check_user_proxy_conf('*.acl'),
96 'user_conf': check_user_proxy_conf('*.conf'),
79 }97 }
80 template_path = locate_template('proxy', MAAS_PROXY_CONF_TEMPLATE)98 template_path = locate_template('proxy', MAAS_PROXY_CONF_TEMPLATE)
81 template = tempita.Template.from_filename(99 template = tempita.Template.from_filename(
82100
=== modified file 'src/maasserver/tests/test_proxyconfig.py'
--- src/maasserver/tests/test_proxyconfig.py 2017-05-02 18:42:35 +0000
+++ src/maasserver/tests/test_proxyconfig.py 2017-05-06 00:25:16 +0000
@@ -86,6 +86,38 @@
8686
87 @wait_for_reactor87 @wait_for_reactor
88 @inlineCallbacks88 @inlineCallbacks
89 def test__doesnt_include_user_config_when_not_found(self):
90 self.patch(settings, "PROXY_CONNECT", True)
91 yield proxyconfig.proxy_update_config(reload_proxy=False)
92 matcher = Not(Contains("include "))
93 self.assertThat(
94 "%s/%s" % (self.tmpdir, proxyconfig.MAAS_PROXY_CONF_NAME),
95 FileContains(matcher=matcher))
96
97 @wait_for_reactor
98 @inlineCallbacks
99 def test__includes_user_config_when_found(self):
100 self.patch(settings, "PROXY_CONNECT", True)
101 self.patch(snappy, 'running_in_snap').return_value = True
102 self.patch(snappy, 'get_snap_common_path').return_value = self.tmpdir
103 proxy_path = os.path.join(self.tmpdir, 'proxy')
104 os.makedirs(proxy_path)
105 open(os.path.join(
106 proxy_path, '%s.acl' % factory.make_name('acl')), 'w').close()
107 open(os.path.join(
108 proxy_path, '%s.conf' % factory.make_name('conf')), 'w').close()
109 yield proxyconfig.proxy_update_config(reload_proxy=False)
110 matcher = Contains("include %s/proxy/*.acl" % self.tmpdir)
111 self.assertThat(
112 "%s/%s" % (self.tmpdir, proxyconfig.MAAS_PROXY_CONF_NAME),
113 FileContains(matcher=matcher))
114 matcher = Contains("include %s/proxy/*.conf" % self.tmpdir)
115 self.assertThat(
116 "%s/%s" % (self.tmpdir, proxyconfig.MAAS_PROXY_CONF_NAME),
117 FileContains(matcher=matcher))
118
119 @wait_for_reactor
120 @inlineCallbacks
89 def test__calls_reloadService(self):121 def test__calls_reloadService(self):
90 self.patch(settings, "PROXY_CONNECT", True)122 self.patch(settings, "PROXY_CONNECT", True)
91 yield deferToDatabase(self.make_subnet)123 yield deferToDatabase(self.make_subnet)
@@ -99,6 +131,7 @@
99 def test__calls_restartService(self):131 def test__calls_restartService(self):
100 self.patch(settings, "PROXY_CONNECT", True)132 self.patch(settings, "PROXY_CONNECT", True)
101 self.patch(snappy, 'running_in_snap').return_value = True133 self.patch(snappy, 'running_in_snap').return_value = True
134 self.patch(snappy, 'get_snap_common_path').return_value = '/'
102 yield deferToDatabase(self.make_subnet)135 yield deferToDatabase(self.make_subnet)
103 yield proxyconfig.proxy_update_config()136 yield proxyconfig.proxy_update_config()
104 self.assertThat(137 self.assertThat(
105138
=== modified file 'src/provisioningserver/templates/proxy/maas-proxy.conf.template'
--- src/provisioningserver/templates/proxy/maas-proxy.conf.template 2017-04-05 14:58:22 +0000
+++ src/provisioningserver/templates/proxy/maas-proxy.conf.template 2017-05-06 00:25:16 +0000
@@ -1,4 +1,6 @@
1# DO NOT EDIT. This file is automatically created by MAAS.1# DO NOT EDIT. This file is automatically created by MAAS.
2# User defined ACLs can be defined in {{if running_in_snap}}{{snap_common_path}}{{else}}/etc/maas{{endif}}/proxy/*.acl
3# Additional user defined config can be defined in {{if running_in_snap}}{{snap_common_path}}{{else}}/etc/maas{{endif}}/proxy/*.conf
2# Last updated at {{modified}}.4# Last updated at {{modified}}.
35
4# Inspired by UDS's conference proxy6# Inspired by UDS's conference proxy
@@ -15,6 +17,9 @@
15acl Safe_ports port 443 # https17acl Safe_ports port 443 # https
16acl Safe_ports port 1025-65535 # unregistered ports18acl Safe_ports port 1025-65535 # unregistered ports
17acl CONNECT method CONNECT19acl CONNECT method CONNECT
20{{if user_acls is not None}}
21include {{user_acls}}
22{{endif}}
18http_access allow maas_proxy_manager localhost23http_access allow maas_proxy_manager localhost
19http_access deny maas_proxy_manager24http_access deny maas_proxy_manager
20http_access deny !Safe_ports25http_access deny !Safe_ports
@@ -56,3 +61,6 @@
56cache_log /var/log/maas/proxy/cache.log61cache_log /var/log/maas/proxy/cache.log
57cache_store_log /var/log/maas/proxy/store.log62cache_store_log /var/log/maas/proxy/store.log
58{{endif}}63{{endif}}
64{{if user_conf is not None}}
65include {{user_conf}}
66{{endif}}