Merge ~andreserl/maas:minor_performace_proxy_config into maas:master

Proposed by Andres Rodriguez
Status: Merged
Approved by: Andres Rodriguez
Approved revision: 048c74aa43758f64e226615fb48367687d1aff92
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~andreserl/maas:minor_performace_proxy_config
Merge into: maas:master
Diff against target: 66 lines (+15/-13)
2 files modified
src/maasserver/compose_preseed.py (+7/-5)
src/maasserver/proxyconfig.py (+8/-8)
Reviewer Review Type Date Requested Status
Lee Trager (community) Approve
MAAS Lander Approve
Newell Jensen (community) Approve
Review via email: mp+349438@code.launchpad.net

Commit message

Minor performance improvement when accessing proxy settings.

To post a comment you must log in.
Revision history for this message
Newell Jensen (newell-jensen) wrote :

LGTM. No need to update the unit tests I take it?

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

UNIT TESTS
-b minor_performace_proxy_config lp:~andreserl/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 048c74aa43758f64e226615fb48367687d1aff92

review: Approve
Revision history for this message
Lee Trager (ltrager) wrote :

LGTM!

Newell, the only test we could do for this is a query count. While I wouldn't be against these functions are simple enough I don't think a query count test should block this from landing.

review: Approve
Revision history for this message
Newell Jensen (newell-jensen) wrote :

> LGTM!
>
> Newell, the only test we could do for this is a query count. While I wouldn't
> be against these functions are simple enough I don't think a query count test
> should block this from landing.

Agreed, additionally the reason I approved is because even if there were associated unit tests, the code change itself was to improve the performance while the functionality of the code has stayed the same so I knew it was unlikely that a change to the unit tests would have been needed.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/compose_preseed.py b/src/maasserver/compose_preseed.py
2index ca7f16d..2bfdcf7 100644
3--- a/src/maasserver/compose_preseed.py
4+++ b/src/maasserver/compose_preseed.py
5@@ -36,17 +36,19 @@ RSYSLOG_PORT = 514
6
7 def get_apt_proxy(request, rack_controller=None):
8 """Return the APT proxy for the `rack_controller`."""
9- if Config.objects.get_config("enable_http_proxy"):
10- http_proxy = Config.objects.get_config("http_proxy")
11+ config = Config.objects.get_configs([
12+ 'enable_http_proxy', 'http_proxy', 'use_peer_proxy',
13+ 'maas_proxy_port'])
14+ if config["enable_http_proxy"]:
15+ http_proxy = config["http_proxy"]
16 if http_proxy is not None:
17 http_proxy = http_proxy.strip()
18- use_peer_proxy = Config.objects.get_config("use_peer_proxy")
19+ use_peer_proxy = config["use_peer_proxy"]
20 if http_proxy and not use_peer_proxy:
21 return http_proxy
22 else:
23 region_ip = get_default_region_ip(request)
24- maas_proxy_port = Config.objects.get_config("maas_proxy_port")
25- url = "http://:%d/" % maas_proxy_port
26+ url = "http://:%d/" % config["maas_proxy_port"]
27 return compose_URL(
28 url, get_maas_facing_server_host(
29 rack_controller, default_region_ip=region_ip))
30diff --git a/src/maasserver/proxyconfig.py b/src/maasserver/proxyconfig.py
31index ae36244..95bc4d0 100644
32--- a/src/maasserver/proxyconfig.py
33+++ b/src/maasserver/proxyconfig.py
34@@ -69,12 +69,12 @@ def proxy_update_config(reload_proxy=True):
35 def write_config():
36 allowed_subnets = Subnet.objects.filter(allow_proxy=True)
37 cidrs = [subnet.cidr for subnet in allowed_subnets]
38+ config = Config.objects.get_configs([
39+ 'http_proxy', 'maas_proxy_port', 'use_peer_proxy',
40+ 'prefer_v4_proxy', 'enable_http_proxy'])
41
42- http_proxy = Config.objects.get_config("http_proxy")
43- maas_proxy_port = Config.objects.get_config("maas_proxy_port")
44- upstream_proxy_enabled = (
45- Config.objects.get_config("use_peer_proxy") and http_proxy)
46- dns_v4_first = Config.objects.get_config("prefer_v4_proxy")
47+ http_proxy = config["http_proxy"]
48+ upstream_proxy_enabled = (config["use_peer_proxy"] and http_proxy)
49 context = {
50 'allowed': allowed_subnets,
51 'modified': str(datetime.date.today()),
52@@ -85,11 +85,11 @@ def proxy_update_config(reload_proxy=True):
53 'snap_data_path': snappy.get_snap_data_path(),
54 'snap_common_path': snappy.get_snap_common_path(),
55 'upstream_peer_proxy': upstream_proxy_enabled,
56- 'dns_v4_first': dns_v4_first,
57- 'maas_proxy_port': maas_proxy_port,
58+ 'dns_v4_first': config['prefer_v4_proxy'],
59+ 'maas_proxy_port': config['maas_proxy_port'],
60 }
61
62- proxy_enabled = Config.objects.get_config("enable_http_proxy")
63+ proxy_enabled = config["enable_http_proxy"]
64 if proxy_enabled and upstream_proxy_enabled:
65 http_proxy_hostname = urlparse(http_proxy).hostname
66 http_proxy_port = urlparse(http_proxy).port

Subscribers

People subscribed via source and target branches