Added offical pre and post install and having glance use that + the main runner. Some cleanups to the creator of image classes.

This commit is contained in:
Joshua Harlow 2012-01-21 10:58:09 -08:00
parent 86c8e041b6
commit 692d7cd9f4
11 changed files with 51 additions and 34 deletions

View File

@ -72,9 +72,6 @@ class RuntimeComponent():
def __init__(self): def __init__(self):
pass pass
def start(self):
raise NotImplementedError()
def stop(self): def stop(self):
raise NotImplementedError() raise NotImplementedError()
@ -84,6 +81,15 @@ class RuntimeComponent():
def restart(self): def restart(self):
raise NotImplementedError() raise NotImplementedError()
def pre_start(self):
raise NotImplementedError()
def start(self):
raise NotImplementedError()
def post_start(self):
raise NotImplementedError()
# useful impls # useful impls
@ -385,7 +391,10 @@ class ProgramRuntime(ComponentBase, RuntimeComponent):
'ROOT': self.appdir, 'ROOT': self.appdir,
} }
def _post_apps_start(self): def pre_start(self):
pass
def post_start(self):
pass pass
def start(self): def start(self):
@ -424,7 +433,6 @@ class ProgramRuntime(ComponentBase, RuntimeComponent):
self.tracewriter.started_info(app_name, fn) self.tracewriter.started_info(app_name, fn)
else: else:
LOG.info("Started %s" % (app_name)) LOG.info("Started %s" % (app_name))
self._post_apps_start()
return fns return fns
def stop(self): def stop(self):
@ -497,6 +505,12 @@ class NullRuntime(ComponentBase, RuntimeComponent):
ComponentBase.__init__(self, component_name, *args, **kargs) ComponentBase.__init__(self, component_name, *args, **kargs)
RuntimeComponent.__init__(self) RuntimeComponent.__init__(self)
def pre_start(self):
pass
def post_start(self):
pass
def start(self): def start(self):
return 0 return 0

View File

@ -99,9 +99,9 @@ class DBInstaller(comp.PkgInstallComponent):
return parent_result return parent_result
class DBRuntime(comp.ComponentBase, comp.RuntimeComponent): class DBRuntime(comp.NullRuntime):
def __init__(self, *args, **kargs): 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) self.tracereader = tr.TraceReader(self.tracedir, tr.IN_TRACE)
def _gettypeactions(self, act, exception_cls): def _gettypeactions(self, act, exception_cls):

View File

@ -14,8 +14,6 @@
# under the License. # under the License.
import io import io
import json
import os.path
from devstack import cfg from devstack import cfg
from devstack import component as comp from devstack import component as comp
@ -69,7 +67,9 @@ class GlanceRuntime(comp.PythonRuntime):
def _get_app_options(self, app): def _get_app_options(self, app):
return APP_OPTIONS.get(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() creator.ImageCreationService(self.cfg).install()
@ -128,7 +128,7 @@ class GlanceInstaller(comp.PythonInstallComponent):
log_filename = config.get('log_file', CFG_SECTION) log_filename = config.get('log_file', CFG_SECTION)
if(log_filename): if(log_filename):
LOG.info("Ensuring log file %s exists and is empty" % (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): if(log_dir):
LOG.info("Ensuring log directory %s exists" % (log_dir)) LOG.info("Ensuring log directory %s exists" % (log_dir))
self.tracewriter.make_dir(log_dir) self.tracewriter.make_dir(log_dir)

View File

@ -96,10 +96,10 @@ class HorizonInstaller(comp.PythonInstallComponent):
#The user system is external (keystone). #The user system is external (keystone).
cmd = DB_SYNC_CMD cmd = DB_SYNC_CMD
sh.execute(*cmd, cwd=self.dash_dir) sh.execute(*cmd, cwd=self.dash_dir)
def _fake_quantum(self): def _fake_quantum(self):
#Horizon currently imports quantum even if you aren't using it. #Horizon currently imports quantum even if you aren't using it.
#Instead of installing quantum we can create a simple module #Instead of installing quantum we can create a simple module
#that will pass the initial imports. #that will pass the initial imports.
if(constants.QUANTUM in self.all_components): if(constants.QUANTUM in self.all_components):
return return
@ -116,7 +116,7 @@ class HorizonInstaller(comp.PythonInstallComponent):
self._sync_db() self._sync_db()
self._setup_blackhole() self._setup_blackhole()
return parent_res return parent_res
def _get_apache_user(self): def _get_apache_user(self):
#TODO will this be the right user? #TODO will this be the right user?
user = self.cfg.get('horizon', 'apache_user') user = self.cfg.get('horizon', 'apache_user')

View File

@ -14,8 +14,6 @@
# under the License. # under the License.
import io import io
import os
import os.path
from devstack import cfg from devstack import cfg
from devstack import component as comp from devstack import component as comp
@ -94,7 +92,7 @@ class KeystoneInstaller(comp.PythonInstallComponent):
log_filename = config.get('log_file', CFG_SECTION) log_filename = config.get('log_file', CFG_SECTION)
if(log_filename): if(log_filename):
LOG.info("Ensuring log file %s exists and is empty" % (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): if(log_dir):
LOG.info("Ensuring log directory %s exists" % (log_dir)) LOG.info("Ensuring log directory %s exists" % (log_dir))
self.tracewriter.make_dir(log_dir) self.tracewriter.make_dir(log_dir)

View File

@ -22,6 +22,7 @@ from devstack import utils
LOG = logging.getLogger("devstack.components.quantum") LOG = logging.getLogger("devstack.components.quantum")
TYPE = constants.QUANTUM TYPE = constants.QUANTUM
class QuantumUninstaller(comp.UninstallComponent): class QuantumUninstaller(comp.UninstallComponent):
def __init__(self, *args, **kargs): def __init__(self, *args, **kargs):
comp.UninstallComponent.__init__(self) comp.UninstallComponent.__init__(self)
@ -48,7 +49,7 @@ class QuantumInstaller(comp.InstallComponent):
def install(self): def install(self):
pass pass
def post_install(self): def post_install(self):
pass pass
@ -68,4 +69,3 @@ class QuantumRuntime(comp.RuntimeComponent):
def restart(self): def restart(self):
pass pass

View File

@ -57,9 +57,9 @@ class RabbitInstaller(comp.PkgInstallComponent):
return parent_result return parent_result
class RabbitRuntime(comp.ComponentBase, comp.RuntimeComponent): class RabbitRuntime(comp.NullRuntime):
def __init__(self, *args, **kargs): 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) self.tracereader = tr.TraceReader(self.tracedir, tr.IN_TRACE)
def start(self): def start(self):

View File

@ -98,11 +98,11 @@ class Image:
self.image = self.download_file_name self.image = self.download_file_name
else: else:
raise IOError('Unknown image format') raise IOError('Unknown image format for download %s' % (self.download_name))
def _register(self): def _register(self):
if self.kernel: 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} params = {'TOKEN': self.token, 'IMAGE_NAME': self.image_name}
cmd = {'cmd': KERNEL_FORMAT} cmd = {'cmd': KERNEL_FORMAT}
with open(self.kernel) as file_: with open(self.kernel) as file_:
@ -110,14 +110,14 @@ class Image:
self.kernel_id = res[0].split(':')[1].strip() self.kernel_id = res[0].split(':')[1].strip()
if self.initrd: 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} params = {'TOKEN': self.token, 'IMAGE_NAME': self.image_name}
cmd = {'cmd': INITRD_FORMAT} cmd = {'cmd': INITRD_FORMAT}
with open(self.initrd) as file_: with open(self.initrd) as file_:
res = utils.execute_template(cmd, params=params, stdin_fh=file_) res = utils.execute_template(cmd, params=params, stdin_fh=file_)
self.initrd_id = res[0].split(':')[1].strip() 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, \ params = {'TOKEN': self.token, 'IMAGE_NAME': self.image_name, \
'KERNEL_ID': self.kernel_id, 'INITRD_ID': self.initrd_id} 'KERNEL_ID': self.kernel_id, 'INITRD_ID': self.initrd_id}
cmd = {'cmd': IMAGE_FORMAT} cmd = {'cmd': IMAGE_FORMAT}
@ -139,25 +139,27 @@ class Image:
class ImageCreationService: class ImageCreationService:
def __init__(self, cfg=None, flat_urls=None, token=None): def __init__(self, cfg=None, flat_urls=None, token=None):
flat_urls = None
token = None
if cfg: if cfg:
self.token = cfg.getpw("passwords", "service_token") token = cfg.getpw("passwords", "service_token")
flat_urls = cfg.get('img', 'image_urls') flat_urls = cfg.get('img', 'image_urls')
if flat_urls: if flat_urls:
self.urls = [x.strip() for x in flat_urls.split(',')] self.urls = [x.strip() for x in flat_urls.split(',')]
else:
self.urls = []
if token: self.token = token
self.token = token
def install(self): def install(self):
for url in self.urls: for url in self.urls:
try: try:
Image(url, self.token).install() Image(url, self.token).install()
except: except Exception, e:
LOG.exception('Installing "%s" failed', url) LOG.exception('Installing "%s" failed due to "%s"', url, e.message)
if __name__ == "__main__": if __name__ == "__main__":
import logging import logging

View File

@ -1,7 +1,6 @@
# The format of this file isn't really documented; just use --generate-rcfile # The format of this file isn't really documented; just use --generate-rcfile
[Master] [Master]
init-hook='import sys; sys.path.append("devstack")'
[Messages Control] [Messages Control]
# NOTE(justinsb): We might want to have a 2nd strict pylintrc in future # NOTE(justinsb): We might want to have a 2nd strict pylintrc in future

View File

@ -53,7 +53,7 @@ function run_pep8 {
function run_pylint { function run_pylint {
echo "Running 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" srcfiles+=" stack"
tee_fn="pylint.log" tee_fn="pylint.log"
pylint_opts="--rcfile=$pylintrc_fn" pylint_opts="--rcfile=$pylintrc_fn"

4
stack
View File

@ -142,8 +142,12 @@ def run_components(action_name, component_order, components_info, distro, root_d
else: else:
raise raise
elif(action_name == constants.START): elif(action_name == constants.START):
LOG.info("Pre-starting %s." % (c))
instance.pre_start()
LOG.info("Starting %s." % (c)) LOG.info("Starting %s." % (c))
start_info = instance.start() start_info = instance.start()
LOG.info("Post-starting %s." % (c))
instance.post_start()
if(type(start_info) == list): if(type(start_info) == list):
LOG.info("Check [%s] for traces of what happened." % (", ".join(start_info))) LOG.info("Check [%s] for traces of what happened." % (", ".join(start_info)))
results = results + start_info results = results + start_info