From 62e449c2b2a98c727ac3a2755db97843d746b30c Mon Sep 17 00:00:00 2001 From: Alberto Donato Date: Wed, 26 Aug 2015 16:16:31 +0300 Subject: [PATCH] Fix service list. --- actions/actions.py | 6 +++--- hooks/glance_utils.py | 8 +++----- tests/basic_deployment.py | 13 ++++++++----- unit_tests/__init__.py | 1 - unit_tests/test_actions.py | 12 ++++++++---- unit_tests/test_actions_openstack_upgrade.py | 2 +- 6 files changed, 23 insertions(+), 19 deletions(-) diff --git a/actions/actions.py b/actions/actions.py index 70fd82ea..1b2d9a41 100755 --- a/actions/actions.py +++ b/actions/actions.py @@ -6,7 +6,7 @@ import os from charmhelpers.core.host import service_pause, service_resume from charmhelpers.core.hookenv import action_fail, status_set -from hooks.glance_utils import SERVICES +from hooks.glance_utils import services def pause(args): @@ -14,7 +14,7 @@ def pause(args): @raises Exception if any services fail to stop """ - for service in SERVICES: + for service in services(): stopped = service_pause(service) if not stopped: raise Exception("{} didn't stop cleanly.".format(service)) @@ -27,7 +27,7 @@ def resume(args): @raises Exception if any services fail to start """ - for service in SERVICES: + for service in services(): started = service_resume(service) if not started: raise Exception("{} didn't start cleanly.".format(service)) diff --git a/hooks/glance_utils.py b/hooks/glance_utils.py index bb6f0729..aae4a1d9 100755 --- a/hooks/glance_utils.py +++ b/hooks/glance_utils.py @@ -3,6 +3,7 @@ import os import shutil import subprocess +from itertools import chain from hooks import glance_contexts @@ -294,11 +295,8 @@ def restart_map(): def services(): - ''' Returns a list of services associate with this charm ''' - _services = [] - for v in restart_map().values(): - _services = _services + v - return list(set(_services)) + ''' Returns a list of (unique) services associate with this charm ''' + return list(set(chain(*restart_map().values()))) def setup_ipv6(): diff --git a/tests/basic_deployment.py b/tests/basic_deployment.py index 4693fce6..5afdc061 100644 --- a/tests/basic_deployment.py +++ b/tests/basic_deployment.py @@ -28,8 +28,6 @@ class GlanceBasicDeployment(OpenStackAmuletDeployment): relations, service status, endpoint service catalog, create and delete new image.""" - SERVICES = ('glance-api', 'glance-registry') - def __init__(self, series=None, openstack=None, source=None, git=False, stable=False): """Deploy the entire test environment.""" @@ -44,7 +42,9 @@ class GlanceBasicDeployment(OpenStackAmuletDeployment): def _assert_services(self, should_run): u.get_unit_process_ids( - {self.glance_sentry: self.services}, expect_success=should_run) + {self.glance_sentry: ( + 'apache2', 'haproxy', 'glance-api', 'glance-registry')}, + expect_success=should_run) def get_service_overrides(self, unit): """ @@ -54,7 +54,7 @@ class GlanceBasicDeployment(OpenStackAmuletDeployment): init_contents = unit.directory_contents("/etc/init/") return { service: "{}.override".format(service) in init_contents["files"] - for service in self.SERVICES} + for service in ('glance-api', 'glance-registry')} def _add_services(self): """Add services @@ -542,12 +542,15 @@ class GlanceBasicDeployment(OpenStackAmuletDeployment): # Config file affected by juju set config change conf_file = '/etc/glance/glance-api.conf' + # Services which are expected to restart upon config change + services = ['glance-api', 'glance-registry'] + # Make config change, check for service restarts u.log.debug('Making config change on {}...'.format(juju_service)) self.d.configure(juju_service, set_alternate) sleep_time = 30 - for s in self.SERVICES: + for s in services: u.log.debug("Checking that service restarted: {}".format(s)) if not u.service_restarted(sentry, s, conf_file, sleep_time=sleep_time): diff --git a/unit_tests/__init__.py b/unit_tests/__init__.py index 8b137891..e69de29b 100644 --- a/unit_tests/__init__.py +++ b/unit_tests/__init__.py @@ -1 +0,0 @@ - diff --git a/unit_tests/test_actions.py b/unit_tests/test_actions.py index 9d6eaf8d..f34e353e 100644 --- a/unit_tests/test_actions.py +++ b/unit_tests/test_actions.py @@ -25,7 +25,9 @@ class PauseTestCase(CharmTestCase): self.service_pause.side_effect = fake_service_pause actions.actions.pause([]) - self.assertEqual(pause_calls, ['glance-api', 'glance-registry']) + self.assertItemsEqual( + pause_calls, + ['glance-api', 'glance-registry', 'haproxy', 'apache2']) def test_bails_out_early_on_error(self): """Pause action fails early if there are errors stopping a service.""" @@ -42,7 +44,7 @@ class PauseTestCase(CharmTestCase): self.assertRaisesRegexp( Exception, "glance-registry didn't stop cleanly.", actions.actions.pause, []) - self.assertEqual(pause_calls, ['glance-api']) + self.assertEqual(pause_calls, ['haproxy', 'glance-api']) def test_status_mode(self): """Pause action sets the status to maintenance.""" @@ -81,7 +83,9 @@ class ResumeTestCase(CharmTestCase): self.service_resume.side_effect = fake_service_resume actions.actions.resume([]) - self.assertEqual(resume_calls, ['glance-api', 'glance-registry']) + self.assertItemsEqual( + resume_calls, + ['glance-api', 'glance-registry', 'haproxy', 'apache2']) def test_bails_out_early_on_error(self): """Resume action fails early if there are errors starting a service.""" @@ -98,7 +102,7 @@ class ResumeTestCase(CharmTestCase): self.assertRaisesRegexp( Exception, "glance-registry didn't start cleanly.", actions.actions.resume, []) - self.assertEqual(resume_calls, ['glance-api']) + self.assertEqual(resume_calls, ['haproxy', 'glance-api']) def test_status_mode(self): """Resume action sets the status to maintenance.""" diff --git a/unit_tests/test_actions_openstack_upgrade.py b/unit_tests/test_actions_openstack_upgrade.py index 760452ca..40a2ca09 100644 --- a/unit_tests/test_actions_openstack_upgrade.py +++ b/unit_tests/test_actions_openstack_upgrade.py @@ -3,7 +3,7 @@ import os os.environ['JUJU_UNIT_NAME'] = 'glance' -with patch('hooks.glance_utils.register_configs') as register_configs: +with patch('hooks.glance_utils.register_configs'): from actions import openstack_upgrade from test_utils import (