From 2f6c3733527c5d3eaee750c7bd478d0f2add21b5 Mon Sep 17 00:00:00 2001 From: Edward Hope-Morley Date: Sun, 29 Mar 2015 21:09:12 +0100 Subject: [PATCH 1/2] [hopem,r=] Ensure apache2 reloaded/restarted when https configured Closes-Bug: #1410568 --- hooks/glance_relations.py | 23 +++++++++++++++++------ unit_tests/test_glance_relations.py | 20 ++++++++++++-------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/hooks/glance_relations.py b/hooks/glance_relations.py index f7c92f4e..0fd15c01 100755 --- a/hooks/glance_relations.py +++ b/hooks/glance_relations.py @@ -1,10 +1,12 @@ #!/usr/bin/python -from subprocess import ( - check_call, - call -) import sys +from subprocess import ( + call, + check_call, + CalledProcessError, +) + from glance_utils import ( do_openstack_upgrade, migrate_database, @@ -164,7 +166,8 @@ def db_changed(): status = call(['glance-manage', 'db_version']) if status != 0: juju_log('Setting version_control to 0') - check_call(["glance-manage", "version_control", "0"]) + cmd = ["glance-manage", "version_control", "0"] + check_call(cmd) juju_log('Cluster leader, performing db sync') migrate_database() @@ -189,7 +192,8 @@ def pgsql_db_changed(): status = call(['glance-manage', 'db_version']) if status != 0: juju_log('Setting version_control to 0') - check_call(["glance-manage", "version_control", "0"]) + cmd = ["glance-manage", "version_control", "0"] + check_call(cmd) juju_log('Cluster leader, performing db sync') migrate_database() @@ -462,6 +466,13 @@ def configure_https(): cmd = ['a2dissite', 'openstack_https_frontend'] check_call(cmd) + # TODO: improve this by checking if local CN certs are available + # first then checking reload status (see LP #1433114). + try: + check_call(['service', 'apache2', 'reload']) + except CalledProcessError: + call(['service', 'apache2', 'restart']) + for r_id in relation_ids('identity-service'): keystone_joined(relation_id=r_id) for r_id in relation_ids('image-service'): diff --git a/unit_tests/test_glance_relations.py b/unit_tests/test_glance_relations.py index 70050fd8..644132fd 100644 --- a/unit_tests/test_glance_relations.py +++ b/unit_tests/test_glance_relations.py @@ -604,8 +604,9 @@ class GlanceRelationTests(CharmTestCase): configs.write = MagicMock() self.relation_ids.return_value = ['identity-service:0'] relations.configure_https() - cmd = ['a2ensite', 'openstack_https_frontend'] - self.check_call.assert_called_with(cmd) + calls = [call('a2dissite', 'openstack_https_frontend'), + call('service', 'apache2', 'reload')] + self.check_call.assert_called_has_calls(calls) keystone_joined.assert_called_with(relation_id='identity-service:0') @patch.object(relations, 'keystone_joined') @@ -617,8 +618,9 @@ class GlanceRelationTests(CharmTestCase): configs.write = MagicMock() self.relation_ids.return_value = ['identity-service:0'] relations.configure_https() - cmd = ['a2dissite', 'openstack_https_frontend'] - self.check_call.assert_called_with(cmd) + calls = [call('a2dissite', 'openstack_https_frontend'), + call('service', 'apache2', 'reload')] + self.check_call.assert_called_has_calls(calls) keystone_joined.assert_called_with(relation_id='identity-service:0') @patch.object(relations, 'image_service_joined') @@ -630,8 +632,9 @@ class GlanceRelationTests(CharmTestCase): configs.write = MagicMock() self.relation_ids.return_value = ['image-service:0'] relations.configure_https() - cmd = ['a2ensite', 'openstack_https_frontend'] - self.check_call.assert_called_with(cmd) + calls = [call('a2dissite', 'openstack_https_frontend'), + call('service', 'apache2', 'reload')] + self.check_call.assert_called_has_calls(calls) image_service_joined.assert_called_with(relation_id='image-service:0') @patch.object(relations, 'image_service_joined') @@ -643,8 +646,9 @@ class GlanceRelationTests(CharmTestCase): configs.write = MagicMock() self.relation_ids.return_value = ['image-service:0'] relations.configure_https() - cmd = ['a2dissite', 'openstack_https_frontend'] - self.check_call.assert_called_with(cmd) + calls = [call('a2dissite', 'openstack_https_frontend'), + call('service', 'apache2', 'reload')] + self.check_call.assert_called_has_calls(calls) image_service_joined.assert_called_with(relation_id='image-service:0') def test_amqp_joined(self): From 32eac5ffcd1acc01a5a6c658628f99e4e898634b Mon Sep 17 00:00:00 2001 From: Edward Hope-Morley Date: Mon, 30 Mar 2015 18:26:30 +0100 Subject: [PATCH 2/2] use service_reload() --- hooks/glance_relations.py | 7 ++----- unit_tests/test_glance_relations.py | 1 + 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/hooks/glance_relations.py b/hooks/glance_relations.py index 0fd15c01..f038ddc1 100755 --- a/hooks/glance_relations.py +++ b/hooks/glance_relations.py @@ -4,7 +4,6 @@ import sys from subprocess import ( call, check_call, - CalledProcessError, ) from glance_utils import ( @@ -43,6 +42,7 @@ from charmhelpers.core.hookenv import ( ) from charmhelpers.core.host import ( restart_on_change, + service_reload, service_stop, ) from charmhelpers.fetch import ( @@ -468,10 +468,7 @@ def configure_https(): # TODO: improve this by checking if local CN certs are available # first then checking reload status (see LP #1433114). - try: - check_call(['service', 'apache2', 'reload']) - except CalledProcessError: - call(['service', 'apache2', 'restart']) + service_reload('apache2', restart_on_failure=True) for r_id in relation_ids('identity-service'): keystone_joined(relation_id=r_id) diff --git a/unit_tests/test_glance_relations.py b/unit_tests/test_glance_relations.py index 644132fd..566a0aa8 100644 --- a/unit_tests/test_glance_relations.py +++ b/unit_tests/test_glance_relations.py @@ -38,6 +38,7 @@ TO_PATCH = [ 'apt_install', 'apt_update', 'restart_on_change', + 'service_reload', 'service_stop', # charmhelpers.contrib.openstack.utils 'configure_installation_source',