Merge lp:~martin-hilton/charm-haproxy/alias-all_services-services into lp:charm-haproxy

Proposed by Martin Hilton
Status: Merged
Approved by: Stuart Bishop
Approved revision: 118
Merged at revision: 130
Proposed branch: lp:~martin-hilton/charm-haproxy/alias-all_services-services
Merge into: lp:charm-haproxy
Diff against target: 157 lines (+67/-14)
4 files modified
Makefile (+1/-1)
hooks/hooks.py (+17/-10)
hooks/tests/test_install.py (+1/-2)
hooks/tests/test_reverseproxy_hooks.py (+48/-1)
To merge this branch: bzr merge lp:~martin-hilton/charm-haproxy/alias-all_services-services
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Canonical IS Reviewers Pending
Review via email: mp+367560@code.launchpad.net

Commit message

Description of the change

This is the change originally proposed in https://code.launchpad.net/~evarlast/charm-haproxy/alias-all_services-services/+merge/317254 just updated to be based on the latest version and have test/lint pass.

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
Stuart Bishop (stub) wrote :

Looks fine, apart from formatting. One pep8 issue that flake8 likely ignores, and some triple quoted string indentation that can be made easier to read. Best if these get fixed before landing.

review: Approve
Revision history for this message
Stuart Bishop (stub) :
review: Needs Fixing
118. By Martin Hilton

review updates

Revision history for this message
Stuart Bishop (stub) wrote :

Yup, ta muchly

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

Change successfully merged at revision 130

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Makefile'
--- Makefile 2019-03-21 11:33:58 +0000
+++ Makefile 2019-05-17 12:11:53 +0000
@@ -24,7 +24,7 @@
2424
25lint: .venv25lint: .venv
26 @echo Checking for Python syntax...26 @echo Checking for Python syntax...
27 @python -m flake8 $(HOOKS_DIR) --extend-ignore=E123 --exclude=$(HOOKS_DIR)/charmhelpers27 @python -m flake8 $(HOOKS_DIR) --ignore=E123 --max-line-length=120 --exclude=$(HOOKS_DIR)/charmhelpers
2828
29sourcedeps:29sourcedeps:
30 @echo Updating source dependencies...30 @echo Updating source dependencies...
3131
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2019-03-21 15:39:53 +0000
+++ hooks/hooks.py 2019-05-17 12:11:53 +0000
@@ -253,9 +253,8 @@
253 # bind 1.2.3.5:234253 # bind 1.2.3.5:234
254 # bind 2001:db8::1:80254 # bind 2001:db8::1:80
255 # bind 1.2.3.4:123 ssl crt /foo/bar255 # bind 1.2.3.4:123 ssl crt /foo/bar
256 bind_stanzas = re.findall(256 bind_stanzas = re.findall(r"\s+bind\s+([a-fA-F0-9\.:\*]+):(\d+).*\n\s+default_backend\s+([^\s]+)",
257 r"\s+bind\s+([a-fA-F0-9\.:\*]+):(\d+).*\n\s+default_backend\s+([^\s]+)",257 haproxy_config, re.M)
258 haproxy_config, re.M)
259 return (tuple(((service, addr, int(port))258 return (tuple(((service, addr, int(port))
260 for service, addr, port in listen_stanzas)) +259 for service, addr, port in listen_stanzas)) +
261 tuple(((service, addr, int(port))260 tuple(((service, addr, int(port))
@@ -614,8 +613,19 @@
614 # Handle relations which specify their own services clauses613 # Handle relations which specify their own services clauses
615 for relation_info in relation_data:614 for relation_info in relation_data:
616 if "services" in relation_info:615 if "services" in relation_info:
616 services_dict = parse_services_yaml(services_dict, relation_info['services'])
617 # apache2 charm uses "all_services" key instead of "services".
618 if "all_services" in relation_info and "services" not in relation_info:
617 services_dict = parse_services_yaml(services_dict,619 services_dict = parse_services_yaml(services_dict,
618 relation_info['services'])620 relation_info['all_services'])
621 # Replace the backend server(2hops away) with the private-address.
622 for service_name in services_dict.keys():
623 if service_name == 'service' or 'servers' not in services_dict[service_name]:
624 continue
625 servers = services_dict[service_name]['servers']
626 for i in range(len(servers)):
627 servers[i][1] = relation_info['private-address']
628 servers[i][2] = str(services_dict[service_name]['service_port'])
619629
620 if len(services_dict) == 0:630 if len(services_dict) == 0:
621 log("No services configured, exiting.")631 log("No services configured, exiting.")
@@ -636,8 +646,7 @@
636 relation_ok = True646 relation_ok = True
637 for required in ("port", "private-address"):647 for required in ("port", "private-address"):
638 if required not in relation_info:648 if required not in relation_info:
639 log("No %s in relation data for '%s', skipping." %649 log("No %s in relation data for '%s', skipping." % (required, unit))
640 (required, unit))
641 relation_ok = False650 relation_ok = False
642 break651 break
643652
@@ -655,8 +664,7 @@
655 if relation_info['service_name'] in services_dict:664 if relation_info['service_name'] in services_dict:
656 service_names.add(relation_info['service_name'])665 service_names.add(relation_info['service_name'])
657 else:666 else:
658 log("Service '%s' does not exist." %667 log("Service '%s' does not exist." % relation_info['service_name'])
659 relation_info['service_name'])
660 continue668 continue
661669
662 if 'sitenames' in relation_info:670 if 'sitenames' in relation_info:
@@ -927,8 +935,7 @@
927 if release == 'trusty':935 if release == 'trusty':
928 pkgs.append('python-ipaddr')936 pkgs.append('python-ipaddr')
929 apt_install(filter_installed_packages(pkgs), fatal=False)937 apt_install(filter_installed_packages(pkgs), fatal=False)
930 ensure_package_status(service_affecting_packages,938 ensure_package_status(service_affecting_packages, config_data['package_status'])
931 config_data['package_status'])
932 enable_haproxy()939 enable_haproxy()
933940
934941
935942
=== modified file 'hooks/tests/test_install.py'
--- hooks/tests/test_install.py 2019-03-21 10:47:31 +0000
+++ hooks/tests/test_install.py 2019-05-17 12:11:53 +0000
@@ -50,8 +50,7 @@
50 for package in calls[1][0][0]:50 for package in calls[1][0][0]:
51 self.assertIn(51 self.assertIn(
52 package,52 package,
53 (['python-pyasn1', 'python-pyasn1-modules', 'python-apt',53 ['python-pyasn1', 'python-pyasn1-modules', 'python-apt', 'python-openssl'])
54 'python-openssl'],))
55 self.assertEqual({'fatal': False}, calls[1][1])54 self.assertEqual({'fatal': False}, calls[1][1])
5655
57 def test_add_source(self):56 def test_add_source(self):
5857
=== modified file 'hooks/tests/test_reverseproxy_hooks.py'
--- hooks/tests/test_reverseproxy_hooks.py 2015-09-01 13:41:44 +0000
+++ hooks/tests/test_reverseproxy_hooks.py 2019-05-17 12:11:53 +0000
@@ -503,7 +503,8 @@
503 'service': {503 'service': {
504 'service_name': 'service',504 'service_name': 'service',
505 'service_host': '0.0.0.0',505 'service_host': '0.0.0.0',
506 'service_port': 10002,506 'service_options': ['balance leastconn'],
507 'service_port': 4242,
507 'servers': [508 'servers': [
508 ['foo-0', '1.2.3.4', 4242, ["maxconn 4"]],509 ['foo-0', '1.2.3.4', 4242, ["maxconn 4"]],
509 ]510 ]
@@ -648,3 +649,49 @@
648 relation_settings={649 relation_settings={
649 "public-address": "1.2.3.4",650 "public-address": "1.2.3.4",
650 "ssl_cert": ssl_cert})651 "ssl_cert": ssl_cert})
652
653 def test_relation_all_services(self):
654 self.get_config_services.return_value = {
655 None: {
656 "service_name": "service",
657 },
658 "service": {
659 "service_name": "service",
660 },
661 }
662 self.relations_of_type.return_value = [
663 {"port": 80,
664 "hostname": "blah.internal",
665 "private-address": "1.2.3.4",
666 "__unit__": "foo/0",
667 "all_services": '''
668 - server_options: &id001 [check inter 2000 rise 2 fall 5 maxconn 500]
669 servers:
670 - - my-service-2-8082
671 - 10.142.0.16
672 - '8082'
673 - *id001
674 service_host: 0.0.0.0
675 service_name: my-service
676 service_options: [mode http, balance url_param waitid]
677 service_port: 83
678 '''
679 },
680 ]
681
682 expected = {
683 'my-service': {
684 'server_options': ['check inter 2000 rise 2 fall 5 maxconn 500'],
685 'servers': [['my-service-2-8082', '1.2.3.4', '83', ['check inter 2000 rise 2 fall 5 maxconn 500']]],
686 'service_host': '0.0.0.0',
687 'service_name': 'my-service',
688 'service_options': ['mode http', 'balance url_param waitid'],
689 'service_port': 83},
690 'service': {
691 'servers': [('foo-0-80', '1.2.3.4', 80, [])],
692 'service_host': '0.0.0.0',
693 'service_name': 'service',
694 'service_port': 85}}
695
696 self.assertEqual(expected, hooks.create_services())
697 self.write_service_config.assert_called_with(expected)

Subscribers

People subscribed via source and target branches

to all changes: