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:
parent
86c8e041b6
commit
692d7cd9f4
@ -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
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
@ -68,4 +69,3 @@ class QuantumRuntime(comp.RuntimeComponent):
|
||||
|
||||
def restart(self):
|
||||
pass
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
||||
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
|
||||
|
1
pylintrc
1
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
|
||||
|
@ -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"
|
||||
|
4
stack
4
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
|
||||
|
Loading…
Reference in New Issue
Block a user