Updated null runtime to be renamed empty runtime (which is more appropriate)

Adjusted the changes from that and added in runtime constants for runtimes to use to know if stopped/started/??
This commit is contained in:
Joshua Harlow
2012-01-24 20:20:24 -08:00
parent 8db88809b4
commit f0ea9c3b2d
11 changed files with 87 additions and 58 deletions

View File

@@ -27,9 +27,16 @@ from devstack.runners import screen
LOG = logging.getLogger("devstack.component")
#how we actually setup and unsetup python
PY_INSTALL = ['python', 'setup.py', 'develop']
PY_UNINSTALL = ['python', 'setup.py', 'develop', '--uninstall']
#runtime status constants (return by runtime status)
STATUS_UNKNOWN = "unknown"
STATUS_STARTED = "started"
STATUS_STOPPED = "stopped"
class ComponentBase(object):
def __init__(self, component_name, **kargs):
@@ -428,7 +435,7 @@ class ProgramRuntime(ComponentBase):
return killedam
def status(self):
return None
return STATUS_UNKNOWN
def restart(self):
return 0
@@ -439,7 +446,7 @@ class PythonRuntime(ProgramRuntime):
ProgramRuntime.__init__(self, component_name, *args, **kargs)
def status(self):
return None
return STATUS_UNKNOWN
def restart(self):
return 0
@@ -455,7 +462,7 @@ class PythonRuntime(ProgramRuntime):
return True
class NullRuntime(ComponentBase):
class EmptyRuntime(ComponentBase):
def __init__(self, component_name, *args, **kargs):
ComponentBase.__init__(self, component_name, *args, **kargs)
@@ -472,7 +479,7 @@ class NullRuntime(ComponentBase):
return 0
def status(self):
return None
return STATUS_UNKNOWN
def restart(self):
return 0

View File

@@ -103,9 +103,9 @@ class DBInstaller(comp.PkgInstallComponent):
return parent_result
class DBRuntime(comp.NullRuntime):
class DBRuntime(comp.EmptyRuntime):
def __init__(self, *args, **kargs):
comp.NullRuntime.__init__(self, TYPE, *args, **kargs)
comp.EmptyRuntime.__init__(self, TYPE, *args, **kargs)
self.tracereader = tr.TraceReader(self.tracedir, tr.IN_TRACE)
def _gettypeactions(self, act, exception_cls):
@@ -122,16 +122,19 @@ class DBRuntime(comp.NullRuntime):
return typeactions.get(act)
def start(self):
if(self.status().find('start') == -1):
if(self.status() == comp.STATUS_STOPPED):
startcmd = self._gettypeactions('start', excp.StartException)
sh.execute(*startcmd, run_as_root=True)
return None
return 1
else:
return 0
def stop(self):
if(self.status().find('stop') == -1):
if(self.status() == comp.STATUS_STARTED):
stopcmd = self._gettypeactions('stop', excp.StopException)
sh.execute(*stopcmd, run_as_root=True)
return 1
else:
return 0
def restart(self):
@@ -141,8 +144,13 @@ class DBRuntime(comp.NullRuntime):
def status(self):
statuscmd = self._gettypeactions('status', excp.StatusException)
(sysout, _) = sh.execute(*statuscmd, run_as_root=True)
return sysout.strip()
(sysout, _) = sh.execute(*statuscmd)
if(sysout.find("start/running") != -1):
return comp.STATUS_STARTED
elif(sysout.find("stop/waiting") != -1):
return comp.STATUS_STOPPED
else:
return comp.STATUS_UNKNOWN
def drop_db(cfg, dbname):

View File

@@ -49,21 +49,21 @@ APP_OPTIONS = {
'glance-registry': ['--config-file', sh.joinpths('%ROOT%', "etc", REG_CONF)]
}
#subdirs of the checkout
CONFIG_ACTUAL_DIR = 'etc'
#subdirs of the downloaded
CONFIG_DIR = 'etc'
BIN_DIR = 'bin'
class GlanceUninstaller(comp.PythonUninstallComponent):
def __init__(self, *args, **kargs):
comp.PythonUninstallComponent.__init__(self, TYPE, *args, **kargs)
self.cfgdir = sh.joinpths(self.appdir, CONFIG_ACTUAL_DIR)
self.cfgdir = sh.joinpths(self.appdir, CONFIG_DIR)
class GlanceRuntime(comp.PythonRuntime):
def __init__(self, *args, **kargs):
comp.PythonRuntime.__init__(self, TYPE, *args, **kargs)
self.cfgdir = sh.joinpths(self.appdir, CONFIG_ACTUAL_DIR)
self.cfgdir = sh.joinpths(self.appdir, CONFIG_DIR)
def _get_apps_to_start(self):
apps = list()
@@ -89,7 +89,7 @@ class GlanceInstaller(comp.PythonInstallComponent):
comp.PythonInstallComponent.__init__(self, TYPE, *args, **kargs)
self.git_loc = self.cfg.get("git", "glance_repo")
self.git_branch = self.cfg.get("git", "glance_branch")
self.cfgdir = sh.joinpths(self.appdir, CONFIG_ACTUAL_DIR)
self.cfgdir = sh.joinpths(self.appdir, CONFIG_DIR)
def _get_download_locations(self):
places = comp.PythonInstallComponent._get_download_locations(self)

View File

@@ -35,6 +35,8 @@ HORIZON_APACHE_TGT = ['/', 'etc', 'apache2', 'sites-enabled', '000-default']
CONFIGS = [HORIZON_PY_CONF, HORIZON_APACHE_CONF]
DB_SYNC_CMD = ['python', 'manage.py', 'syncdb']
BLACKHOLE_DIR = '.blackhole'
#hopefully this will be distro independent ??
APACHE_RESTART_CMD = ['service', 'apache2', 'restart']
LOG = logging.getLogger("devstack.components.horizon")
@@ -111,11 +113,11 @@ class HorizonInstaller(comp.PythonInstallComponent):
self.tracewriter.touch_file(sh.joinpths(quantum_dir, 'client.py'))
def post_install(self):
parent_res = comp.PythonInstallComponent.post_install(self)
parent_result = comp.PythonInstallComponent.post_install(self)
self._fake_quantum()
self._sync_db()
self._setup_blackhole()
return parent_res
return parent_result
def _get_apache_user(self):
#TODO will this be the right user?
@@ -138,6 +140,6 @@ class HorizonInstaller(comp.PythonInstallComponent):
return mp
class HorizonRuntime(comp.NullRuntime):
class HorizonRuntime(comp.EmptyRuntime):
def __init__(self, *args, **kargs):
comp.NullRuntime.__init__(self, TYPE, *args, **kargs)
comp.EmptyRuntime.__init__(self, TYPE, *args, **kargs)

View File

@@ -44,6 +44,6 @@ class KeyStoneClientInstaller(comp.PythonInstallComponent):
return places
class KeyStoneClientRuntime(comp.NullRuntime):
class KeyStoneClientRuntime(comp.EmptyRuntime):
def __init__(self, *args, **kargs):
comp.NullRuntime.__init__(self, TYPE, *args, **kargs)
comp.EmptyRuntime.__init__(self, TYPE, *args, **kargs)

View File

@@ -51,6 +51,6 @@ class NovaClientInstaller(comp.PythonInstallComponent):
return mp
class NovaClientRuntime(comp.NullRuntime):
class NovaClientRuntime(comp.EmptyRuntime):
def __init__(self, *args, **kargs):
comp.NullRuntime.__init__(self, TYPE, *args, **kargs)
comp.EmptyRuntime.__init__(self, TYPE, *args, **kargs)

View File

@@ -43,6 +43,6 @@ class OpenstackXInstaller(comp.PythonInstallComponent):
return places
class OpenstackXRuntime(comp.NullRuntime):
class OpenstackXRuntime(comp.EmptyRuntime):
def __init__(self, *args, **kargs):
comp.NullRuntime.__init__(self, TYPE, *args, **kargs)
comp.EmptyRuntime.__init__(self, TYPE, *args, **kargs)

View File

@@ -56,6 +56,6 @@ class QuantumInstaller(object):
raise NotImplementedError()
class QuantumRuntime(comp.NullRuntime):
class QuantumRuntime(comp.EmptyRuntime):
def __init__(self, *args, **kargs):
comp.NullRuntime.__init__(self, TYPE, *args, **kargs)
comp.EmptyRuntime.__init__(self, TYPE, *args, **kargs)

View File

@@ -58,49 +58,57 @@ class RabbitInstaller(comp.PkgInstallComponent):
return parent_result
class RabbitRuntime(comp.NullRuntime):
class RabbitRuntime(comp.EmptyRuntime):
def __init__(self, *args, **kargs):
comp.NullRuntime.__init__(self, TYPE, *args, **kargs)
comp.EmptyRuntime.__init__(self, TYPE, *args, **kargs)
self.tracereader = tr.TraceReader(self.tracedir, tr.IN_TRACE)
def start(self):
pkgsinstalled = self.tracereader.packages_installed()
if(len(pkgsinstalled) == 0):
msg = "Can not start %s since it was not installed" % (TYPE)
raise excp.StartException(msg)
if(self.status().find('start') == -1):
if(self.status() == comp.STATUS_STOPPED):
self._run_cmd(START_CMD)
return None
return 1
else:
return 0
def status(self):
pkgsinstalled = self.tracereader.packages_installed()
if(len(pkgsinstalled) == 0):
msg = "Can not check the status of %s since it was not installed" % (TYPE)
raise excp.StatusException(msg)
(sysout, _) = sh.execute(*STATUS_CMD, run_as_root=True)
return sysout.strip().lower()
#this has got to be the worst status output
#i have ever seen (its like a weird mix json)
(sysout, _) = sh.execute(*STATUS_CMD,
run_as_root=True,
check_exit_code=False)
if(sysout.find('nodedown') != -1 or sysout.find("unable to connect to node") != -1):
return comp.STATUS_STOPPED
elif(sysout.find('running_applications') != -1):
return comp.STATUS_STARTED
else:
return comp.STATUS_UNKNOWN
def _run_cmd(self, cmd):
if(self.distro == settings.UBUNTU11):
#this seems to fix one of the bugs with rabbit mq starting and stopping
#not cool, possibly connected to the following bugs:
#https://bugs.launchpad.net/ubuntu/+source/rabbitmq-server/+bug/878597
#https://bugs.launchpad.net/ubuntu/+source/rabbitmq-server/+bug/878600
with TemporaryFile() as f:
sh.execute(*cmd, run_as_root=True,
stdout_fh=f, stderr_fh=f)
else:
sh.execute(*cmd, run_as_root=True)
return sh.execute(*cmd, run_as_root=True)
def restart(self):
pkgsinstalled = self.tracereader.packages_installed()
if(len(pkgsinstalled) == 0):
msg = "Can not check the status of %s since it was not installed" % (TYPE)
raise excp.RestartException(msg)
self._run_cmd(RESTART_CMD)
return None
return 1
def stop(self):
pkgsinstalled = self.tracereader.packages_installed()
if(len(pkgsinstalled) == 0):
msg = "Can not stop %s since it was not installed" % (TYPE)
raise excp.StopException(msg)
if(self.status().find('stop') == -1):
if(self.status() == comp.STATUS_STARTED):
self._run_cmd(STOP_CMD)
return None
return 1
else:
return 0

View File

@@ -57,6 +57,6 @@ class SwiftInstaller(object):
raise NotImplementedError()
class SwiftRuntime(comp.NullRuntime):
class SwiftRuntime(comp.EmptyRuntime):
def __init__(self, *args, **kargs):
comp.NullRuntime.__init__(self, TYPE, *args, **kargs)
comp.EmptyRuntime.__init__(self, TYPE, *args, **kargs)

View File

@@ -145,6 +145,8 @@ class Image(object):
self._register()
finally:
self._cleanup()
else:
LOG.warn("You already seem to have image named %s, skipping" % (possible_name))
class ImageRegistry:
@@ -212,6 +214,8 @@ class ImageCreationService:
#install them in glance
am_installed = 0
if(urls):
LOG.info("Attempting to download & extract and upload (%s) images." % (", ".join(urls)))
for url in urls:
try:
Image(url, token).install()