From d7ad32c4d592ebbfcccc7e8d4d0f2da8d651898c Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Tue, 28 Aug 2012 13:34:39 -0700 Subject: [PATCH] Remove wait sleep time and use the runtime status to see if its up --- anvil/components/__init__.py | 26 ++++++++++++++++++++++++++ anvil/components/glance.py | 4 +--- anvil/components/keystone.py | 4 +--- conf/templates/nova/nova-clean.sh | 2 +- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/anvil/components/__init__.py b/anvil/components/__init__.py index 9c35f761..1e17f805 100644 --- a/anvil/components/__init__.py +++ b/anvil/components/__init__.py @@ -531,6 +531,32 @@ class ProgramRuntime(component.Component): def stop(self): return 0 + def wait_active(self, between_wait=1, max_attempts=5): + rt_name = self.name + num_started = len(self.apps_to_start) + if not num_started: + raise excp.StartException("No %r programs started, can not wait for them to become active..." % (rt_name)) + + def waiter(try_num): + LOG.info("Waiting %s seconds for component %s programs to start.", between_wait, colorizer.quote(rt_name)) + LOG.info("Please wait...") + sh.sleep(between_wait) + + for i in range(0, max_attempts): + statii = self.status() + if len(statii) == num_started: + not_worked = [] + for p_status in statii: + if p_status.status != STATUS_STARTED: + not_worked.append(p_status) + if len(not_worked) == 0: + return + waiter(i + 1) + + tot_time = max(0, between_wait * max_attempts) + raise excp.StartException("Failed waiting %s seconds for component %r programs to become active..." + % (tot_time, rt_name)) + class EmptyRuntime(ProgramRuntime): pass diff --git a/anvil/components/glance.py b/anvil/components/glance.py index c7e9ddc4..298aaf9f 100644 --- a/anvil/components/glance.py +++ b/anvil/components/glance.py @@ -198,7 +198,6 @@ class GlanceRuntime(comp.PythonRuntime): def __init__(self, *args, **kargs): comp.PythonRuntime.__init__(self, *args, **kargs) self.bin_dir = sh.joinpths(self.get_option('app_dir'), 'bin') - self.wait_time = self.get_int_option('service_wait_seconds') @property def apps_to_start(self): @@ -224,8 +223,7 @@ class GlanceRuntime(comp.PythonRuntime): comp.PythonRuntime.post_start(self) if self.get_bool_option('load-images'): # Install any images that need activating... - LOG.info("Waiting %s seconds so that glance can start up before image install." % (self.wait_time)) - sh.sleep(self.wait_time) + self.wait_active() params = {} params['glance'] = ghelper.get_shared_params(**self.options) params['keystone'] = khelper.get_shared_params(ip=self.get_option('ip'), diff --git a/anvil/components/keystone.py b/anvil/components/keystone.py index b842e577..e9458315 100644 --- a/anvil/components/keystone.py +++ b/anvil/components/keystone.py @@ -196,7 +196,6 @@ class KeystoneRuntime(comp.PythonRuntime): def __init__(self, *args, **kargs): comp.PythonRuntime.__init__(self, *args, **kargs) self.bin_dir = sh.joinpths(self.get_option('app_dir'), 'bin') - self.wait_time = self.get_int_option('service_wait_seconds') self.init_fn = sh.joinpths(self.get_option('trace_dir'), INIT_WHAT_HAPPENED) @@ -214,8 +213,7 @@ class KeystoneRuntime(comp.PythonRuntime): def post_start(self): if not sh.isfile(self.init_fn) and self.get_bool_option('do-init'): - LOG.info("Waiting %s seconds so that keystone can start up before running first time init." % (self.wait_time)) - sh.sleep(self.wait_time) + self.wait_active() LOG.info("Running commands to initialize keystone.") (fn, contents) = utils.load_template(self.name, INIT_WHAT_FN) LOG.debug("Initializing with contents of %s", fn) diff --git a/conf/templates/nova/nova-clean.sh b/conf/templates/nova/nova-clean.sh index 82a22911..d5c61679 100644 --- a/conf/templates/nova/nova-clean.sh +++ b/conf/templates/nova/nova-clean.sh @@ -1,6 +1,6 @@ #!/bin/bash -# This script cleans up the system as part of a nova uninstall +# This script cleans up the system iptables/services as part of a nova uninstall # # It is best effort! #