From 692d7cd9f44759e51b139e0762cdf435382f687d Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Sat, 21 Jan 2012 10:58:09 -0800 Subject: [PATCH] Added offical pre and post install and having glance use that + the main runner. Some cleanups to the creator of image classes. --- devstack/component.py | 24 +++++++++++++++++++----- devstack/components/db.py | 4 ++-- devstack/components/glance.py | 8 ++++---- devstack/components/horizon.py | 8 ++++---- devstack/components/keystone.py | 4 +--- devstack/components/quantum.py | 4 ++-- devstack/components/rabbit.py | 4 ++-- devstack/image/creator.py | 22 ++++++++++++---------- pylintrc | 1 - run_checks.sh | 2 +- stack | 4 ++++ 11 files changed, 51 insertions(+), 34 deletions(-) diff --git a/devstack/component.py b/devstack/component.py index 7b373e74..e1e7c3da 100644 --- a/devstack/component.py +++ b/devstack/component.py @@ -72,9 +72,6 @@ class RuntimeComponent(): def __init__(self): pass - def start(self): - raise NotImplementedError() - def stop(self): raise NotImplementedError() @@ -84,6 +81,15 @@ class RuntimeComponent(): def restart(self): raise NotImplementedError() + def pre_start(self): + raise NotImplementedError() + + def start(self): + raise NotImplementedError() + + def post_start(self): + raise NotImplementedError() + # useful impls @@ -385,7 +391,10 @@ class ProgramRuntime(ComponentBase, RuntimeComponent): 'ROOT': self.appdir, } - def _post_apps_start(self): + def pre_start(self): + pass + + def post_start(self): pass def start(self): @@ -424,7 +433,6 @@ class ProgramRuntime(ComponentBase, RuntimeComponent): self.tracewriter.started_info(app_name, fn) else: LOG.info("Started %s" % (app_name)) - self._post_apps_start() return fns def stop(self): @@ -497,6 +505,12 @@ class NullRuntime(ComponentBase, RuntimeComponent): ComponentBase.__init__(self, component_name, *args, **kargs) RuntimeComponent.__init__(self) + def pre_start(self): + pass + + def post_start(self): + pass + def start(self): return 0 diff --git a/devstack/components/db.py b/devstack/components/db.py index 0c4cf6c4..239f3714 100644 --- a/devstack/components/db.py +++ b/devstack/components/db.py @@ -99,9 +99,9 @@ class DBInstaller(comp.PkgInstallComponent): return parent_result -class DBRuntime(comp.ComponentBase, comp.RuntimeComponent): +class DBRuntime(comp.NullRuntime): def __init__(self, *args, **kargs): - comp.ComponentBase.__init__(self, TYPE, *args, **kargs) + comp.NullRuntime.__init__(self, TYPE, *args, **kargs) self.tracereader = tr.TraceReader(self.tracedir, tr.IN_TRACE) def _gettypeactions(self, act, exception_cls): diff --git a/devstack/components/glance.py b/devstack/components/glance.py index d38bbf1e..8b48cde9 100644 --- a/devstack/components/glance.py +++ b/devstack/components/glance.py @@ -14,8 +14,6 @@ # under the License. import io -import json -import os.path from devstack import cfg from devstack import component as comp @@ -69,7 +67,9 @@ class GlanceRuntime(comp.PythonRuntime): def _get_app_options(self, app): return APP_OPTIONS.get(app) - def _post_apps_start(self): + def post_start(self): + comp.PythonRuntime.post_start(self) + #install any images that need activating... creator.ImageCreationService(self.cfg).install() @@ -128,7 +128,7 @@ class GlanceInstaller(comp.PythonInstallComponent): log_filename = config.get('log_file', CFG_SECTION) if(log_filename): LOG.info("Ensuring log file %s exists and is empty" % (log_filename)) - log_dir = os.path.dirname(log_filename) + log_dir = sh.dirname(log_filename) if(log_dir): LOG.info("Ensuring log directory %s exists" % (log_dir)) self.tracewriter.make_dir(log_dir) diff --git a/devstack/components/horizon.py b/devstack/components/horizon.py index 9fef12cd..eaf1d52e 100644 --- a/devstack/components/horizon.py +++ b/devstack/components/horizon.py @@ -96,10 +96,10 @@ class HorizonInstaller(comp.PythonInstallComponent): #The user system is external (keystone). cmd = DB_SYNC_CMD sh.execute(*cmd, cwd=self.dash_dir) - + def _fake_quantum(self): - #Horizon currently imports quantum even if you aren't using it. - #Instead of installing quantum we can create a simple module + #Horizon currently imports quantum even if you aren't using it. + #Instead of installing quantum we can create a simple module #that will pass the initial imports. if(constants.QUANTUM in self.all_components): return @@ -116,7 +116,7 @@ class HorizonInstaller(comp.PythonInstallComponent): self._sync_db() self._setup_blackhole() return parent_res - + def _get_apache_user(self): #TODO will this be the right user? user = self.cfg.get('horizon', 'apache_user') diff --git a/devstack/components/keystone.py b/devstack/components/keystone.py index c132ea3e..4dab76a5 100644 --- a/devstack/components/keystone.py +++ b/devstack/components/keystone.py @@ -14,8 +14,6 @@ # under the License. import io -import os -import os.path from devstack import cfg from devstack import component as comp @@ -94,7 +92,7 @@ class KeystoneInstaller(comp.PythonInstallComponent): log_filename = config.get('log_file', CFG_SECTION) if(log_filename): LOG.info("Ensuring log file %s exists and is empty" % (log_filename)) - log_dir = os.path.dirname(log_filename) + log_dir = sh.dirname(log_filename) if(log_dir): LOG.info("Ensuring log directory %s exists" % (log_dir)) self.tracewriter.make_dir(log_dir) diff --git a/devstack/components/quantum.py b/devstack/components/quantum.py index a5aabdb9..587daf9d 100644 --- a/devstack/components/quantum.py +++ b/devstack/components/quantum.py @@ -22,6 +22,7 @@ from devstack import utils LOG = logging.getLogger("devstack.components.quantum") TYPE = constants.QUANTUM + class QuantumUninstaller(comp.UninstallComponent): def __init__(self, *args, **kargs): comp.UninstallComponent.__init__(self) @@ -48,7 +49,7 @@ class QuantumInstaller(comp.InstallComponent): def install(self): pass - + def post_install(self): pass @@ -68,4 +69,3 @@ class QuantumRuntime(comp.RuntimeComponent): def restart(self): pass - diff --git a/devstack/components/rabbit.py b/devstack/components/rabbit.py index 516e46d0..e543a148 100644 --- a/devstack/components/rabbit.py +++ b/devstack/components/rabbit.py @@ -57,9 +57,9 @@ class RabbitInstaller(comp.PkgInstallComponent): return parent_result -class RabbitRuntime(comp.ComponentBase, comp.RuntimeComponent): +class RabbitRuntime(comp.NullRuntime): def __init__(self, *args, **kargs): - comp.ComponentBase.__init__(self, TYPE, *args, **kargs) + comp.NullRuntime.__init__(self, TYPE, *args, **kargs) self.tracereader = tr.TraceReader(self.tracedir, tr.IN_TRACE) def start(self): diff --git a/devstack/image/creator.py b/devstack/image/creator.py index a5b66068..21e525ba 100644 --- a/devstack/image/creator.py +++ b/devstack/image/creator.py @@ -98,11 +98,11 @@ class Image: self.image = self.download_file_name else: - raise IOError('Unknown image format') + raise IOError('Unknown image format for download %s' % (self.download_name)) def _register(self): if self.kernel: - LOG.info('adding kernel %s to glance', self.kernel) + LOG.info('Adding kernel %s to glance', self.kernel) params = {'TOKEN': self.token, 'IMAGE_NAME': self.image_name} cmd = {'cmd': KERNEL_FORMAT} with open(self.kernel) as file_: @@ -110,14 +110,14 @@ class Image: self.kernel_id = res[0].split(':')[1].strip() if self.initrd: - LOG.info('adding ramdisk %s to glance', self.initrd) + LOG.info('Adding ramdisk %s to glance', self.initrd) params = {'TOKEN': self.token, 'IMAGE_NAME': self.image_name} cmd = {'cmd': INITRD_FORMAT} with open(self.initrd) as file_: res = utils.execute_template(cmd, params=params, stdin_fh=file_) self.initrd_id = res[0].split(':')[1].strip() - LOG.info('adding image %s to glance', self.image_name) + LOG.info('Adding image %s to glance', self.image_name) params = {'TOKEN': self.token, 'IMAGE_NAME': self.image_name, \ 'KERNEL_ID': self.kernel_id, 'INITRD_ID': self.initrd_id} cmd = {'cmd': IMAGE_FORMAT} @@ -139,25 +139,27 @@ class Image: class ImageCreationService: - def __init__(self, cfg=None, flat_urls=None, token=None): + flat_urls = None + token = None if cfg: - self.token = cfg.getpw("passwords", "service_token") + token = cfg.getpw("passwords", "service_token") flat_urls = cfg.get('img', 'image_urls') if flat_urls: self.urls = [x.strip() for x in flat_urls.split(',')] + else: + self.urls = [] - if token: - self.token = token + self.token = token def install(self): for url in self.urls: try: Image(url, self.token).install() - except: - LOG.exception('Installing "%s" failed', url) + except Exception, e: + LOG.exception('Installing "%s" failed due to "%s"', url, e.message) if __name__ == "__main__": import logging diff --git a/pylintrc b/pylintrc index 94d37c36..64c8c0dd 100644 --- a/pylintrc +++ b/pylintrc @@ -1,7 +1,6 @@ # The format of this file isn't really documented; just use --generate-rcfile [Master] -init-hook='import sys; sys.path.append("devstack")' [Messages Control] # NOTE(justinsb): We might want to have a 2nd strict pylintrc in future diff --git a/run_checks.sh b/run_checks.sh index 532021ad..d84b1f59 100755 --- a/run_checks.sh +++ b/run_checks.sh @@ -53,7 +53,7 @@ function run_pep8 { function run_pylint { echo "Running pylint ..." - srcfiles=`find devstack -type f | grep "py\$" | sed 's/devstack\/\(.*\)\.py/\1/' | tr '/' '.'` + srcfiles=`find devstack -type f | grep "py\$"` srcfiles+=" stack" tee_fn="pylint.log" pylint_opts="--rcfile=$pylintrc_fn" diff --git a/stack b/stack index be540c24..b5d66b5e 100755 --- a/stack +++ b/stack @@ -142,8 +142,12 @@ def run_components(action_name, component_order, components_info, distro, root_d else: raise elif(action_name == constants.START): + LOG.info("Pre-starting %s." % (c)) + instance.pre_start() LOG.info("Starting %s." % (c)) start_info = instance.start() + LOG.info("Post-starting %s." % (c)) + instance.post_start() if(type(start_info) == list): LOG.info("Check [%s] for traces of what happened." % (", ".join(start_info))) results = results + start_info