Merge ~hloeung/content-cache-charm:haproxy-config into content-cache-charm:master

Proposed by Haw Loeung
Status: Merged
Approved by: Haw Loeung
Approved revision: 23cdcb3ee6f41c867ad4ccbe0d22b1f53af40adb
Merged at revision: 0b9452a319d89ca7f6686ea5980b1720d27b1dc3
Proposed branch: ~hloeung/content-cache-charm:haproxy-config
Merge into: content-cache-charm:master
Diff against target: 100 lines (+22/-12)
4 files modified
lib/haproxy.py (+1/-1)
tests/unit/files/content_cache_rendered_haproxy_test_output_backup.txt (+13/-6)
tests/unit/files/content_cache_rendered_haproxy_test_output_srv_template.txt (+2/-1)
tests/unit/test_content_cache.py (+6/-4)
Reviewer Review Type Date Requested Status
Joel Sing (community) +1 Approve
Canonical IS Reviewers Pending
Review via email: mp+392273@code.launchpad.net

Commit message

Fixed to support multiple server template configs

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
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Unable to determine commit message from repository - please click "Set commit message" and enter the commit message manually.

Revision history for this message
Joel Sing (jsing) wrote :

LGTM

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

Change successfully merged at revision 0b9452a319d89ca7f6686ea5980b1720d27b1dc3

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/haproxy.py b/lib/haproxy.py
2index cfbabfd..60e9660 100644
3--- a/lib/haproxy.py
4+++ b/lib/haproxy.py
5@@ -272,7 +272,7 @@ backend backend-{name}
6 for flag in flags:
7 # https://www.haproxy.com/documentation/hapee/1-8r2/traffic-management/dns-service-discovery/dns-srv-records/
8 if flag == 'srv':
9- name = 'server-template server_ {}'.format(flags[flags.index(flag) + 1])
10+ name = 'server-template server_{}_ {}'.format(count, flags[flags.index(flag) + 1])
11 elif flag == 'backup':
12 backup = ' backup'
13
14diff --git a/tests/unit/files/content_cache_rendered_haproxy_test_output_backup.txt b/tests/unit/files/content_cache_rendered_haproxy_test_output_backup.txt
15index 244fc2e..06670cd 100644
16--- a/tests/unit/files/content_cache_rendered_haproxy_test_output_backup.txt
17+++ b/tests/unit/files/content_cache_rendered_haproxy_test_output_backup.txt
18@@ -76,20 +76,19 @@ listen stats
19 stats refresh 3
20
21
22-listen redirect-site1-local
23+listen cached-site1-local
24 bind 0.0.0.0:80
25 bind :::80
26- redirect prefix https://site1.local
27-
28-listen cached-site1-local
29- bind 0.0.0.0:443 ssl crt /var/lib/haproxy/certs alpn h2,http/1.1
30- bind :::443 ssl crt /var/lib/haproxy/certs alpn h2,http/1.1
31 default_backend backend-cached-site1-local
32
33 listen site1-local
34 bind 127.0.0.1:8080
35 default_backend backend-site1-local
36
37+listen site1-local-2
38+ bind 127.0.0.1:8081
39+ default_backend backend-site1-local-2
40+
41 backend backend-cached-site1-local
42 option forwardfor
43 option httpchk HEAD / HTTP/1.0\r\nHost:\ site1.local\r\nUser-Agent:\ haproxy/httpchk\r\nCache-Control:\ no-cache
44@@ -98,8 +97,16 @@ backend backend-cached-site1-local
45 server server_1 127.0.0.1:6080 check inter 2s rise 2 fall 60 maxconn 2048
46
47 backend backend-site1-local
48+ option allbackups
49 option httpchk HEAD / HTTP/1.0\r\nHost:\ site1.local\r\nUser-Agent:\ haproxy/httpchk\r\nCache-Control:\ no-cache
50 http-request set-header Host site1.local
51 balance leastconn
52 server server_1 192.168.1.1:8080 check inter 5s rise 2 fall 5 maxconn 2048
53 server server_2 192.168.1.2:8080 backup check inter 5s rise 2 fall 5 maxconn 2048
54+
55+backend backend-site1-local-2
56+ option httpchk HEAD / HTTP/1.0\r\nHost:\ site1.local\r\nUser-Agent:\ haproxy/httpchk\r\nCache-Control:\ no-cache
57+ http-request set-header Host site1.local
58+ balance leastconn
59+ server server_1 192.168.1.1:8080 check inter 5s rise 2 fall 5 maxconn 2048
60+ server server_2 192.168.1.2:8080 check inter 5s rise 2 fall 5 maxconn 2048
61diff --git a/tests/unit/files/content_cache_rendered_haproxy_test_output_srv_template.txt b/tests/unit/files/content_cache_rendered_haproxy_test_output_srv_template.txt
62index 8c24f8d..5037a1e 100644
63--- a/tests/unit/files/content_cache_rendered_haproxy_test_output_srv_template.txt
64+++ b/tests/unit/files/content_cache_rendered_haproxy_test_output_srv_template.txt
65@@ -96,4 +96,5 @@ backend backend-site1-local
66 option httpchk HEAD / HTTP/1.0\r\nHost:\ site1.local\r\nUser-Agent:\ haproxy/httpchk\r\nCache-Control:\ no-cache
67 http-request set-header Host site1.local
68 balance leastconn
69- server-template server_ 4 _http._tcp.uk.archive.ubuntu.com:80 resolvers dns init-addr none check inter 5s rise 2 fall 5 maxconn 2048
70+ server-template server_1_ 2 _http._tcp.us.archive.ubuntu.com:80 resolvers dns init-addr none check inter 5s rise 2 fall 5 maxconn 2048
71+ server-template server_2_ 2 _http._tcp.gb.archive.ubuntu.com:80 backup resolvers dns init-addr none check inter 5s rise 2 fall 5 maxconn 2048
72diff --git a/tests/unit/test_content_cache.py b/tests/unit/test_content_cache.py
73index 073eb8b..1c11a30 100644
74--- a/tests/unit/test_content_cache.py
75+++ b/tests/unit/test_content_cache.py
76@@ -472,10 +472,10 @@ site1.local:
77 site1.local:
78 locations:
79 /:
80- backend-tls: false
81+ backend-options: ['allbackups']
82 backends: ['192.168.1.1:8080', '192.168.1.2:8080 backup']
83- redirect-http-to-https: True
84- tls-cert-bundle-path: /var/lib/haproxy/certs
85+ /some-path:
86+ backends: ['192.168.1.1:8080', '192.168.1.2:8080']
87 '''
88 self.mock_config.return_value = {'haproxy_hard_stop_after': '15m', 'max_connections': 8192, 'sites': config}
89 with mock.patch('lib.haproxy.HAProxyConf.conf_file', new_callable=mock.PropertyMock) as mock_conf_file:
90@@ -500,7 +500,9 @@ site1.local:
91 site1.local:
92 locations:
93 /:
94- backends: ['_http._tcp.uk.archive.ubuntu.com:80 srv 4']
95+ backends:
96+ - _http._tcp.us.archive.ubuntu.com:80 srv 2
97+ - _http._tcp.gb.archive.ubuntu.com:80 srv 2 backup
98 '''
99 self.mock_config.return_value = {'haproxy_hard_stop_after': '15m', 'max_connections': 8192, 'sites': config}
100 with mock.patch('lib.haproxy.HAProxyConf.conf_file', new_callable=mock.PropertyMock) as mock_conf_file:

Subscribers

People subscribed via source and target branches