Some cleanups.

This commit is contained in:
Joshua Harlow 2012-01-31 22:05:38 -08:00
parent 2bc9005d99
commit 1561e636fa
14 changed files with 114 additions and 200 deletions

View File

@ -70,32 +70,41 @@ class PkgInstallComponent(ComponentBase):
def download(self):
locations = self._get_download_locations()
base_dir = self.appdir
am_downloaded = 0
for location_info in locations:
uri = location_info.get("uri")
if not uri:
continue
branch = location_info.get("branch")
uri_tuple = location_info.get("uri")
branch_tuple = location_info.get("branch")
subdir = location_info.get("subdir")
target_loc = None
if subdir and len(subdir):
target_loc = sh.joinpths(base_dir, subdir)
else:
target_loc = base_dir
dirsmade = down.download(target_loc, uri, branch)
branch = None
if branch_tuple:
branch = self.cfg.get(branch_tuple[0], branch_tuple[1])
uri = self.cfg.get(uri_tuple[0], uri_tuple[1])
self.tracewriter.dir_made(*down.download(target_loc, uri, branch))
self.tracewriter.downloaded(target_loc, uri)
self.tracewriter.dir_made(*dirsmade)
am_downloaded += 1
return am_downloaded
return len(locations)
def _get_param_map(self, config_fn):
return None
def _get_pkgs(self):
return dict()
def _get_pkgs(self):
return list()
def _get_pkgs_expanded(self):
short = self._get_pkgs()
if not short:
return dict()
pkgs = dict()
for fn in short:
full_name = sh.joinpths(settings.STACK_PKG_DIR, fn)
pkgs = utils.extract_pkg_list([full_name], self.distro, pkgs)
return pkgs
def install(self):
pkgs = self._get_pkgs()
pkgs = self._get_pkgs_expanded()
if pkgs:
pkgnames = sorted(pkgs.keys())
LOG.info("Installing packages (%s)." % (", ".join(pkgnames)))
@ -106,14 +115,14 @@ class PkgInstallComponent(ComponentBase):
return self.tracedir
def pre_install(self):
pkgs = self._get_pkgs()
pkgs = self._get_pkgs_expanded()
if pkgs:
mp = self._get_param_map(None)
self.packager.pre_install(pkgs, mp)
return self.tracedir
def post_install(self):
pkgs = self._get_pkgs()
pkgs = self._get_pkgs_expanded()
if pkgs:
mp = self._get_param_map(None)
self.packager.post_install(pkgs, mp)
@ -166,19 +175,25 @@ class PythonInstallComponent(PkgInstallComponent):
PkgInstallComponent.__init__(self, component_name, *args, **kargs)
def _get_python_directories(self):
py_dirs = list()
py_dirs.append({
'name': self.component_name,
'work_dir': self.appdir,
})
py_dirs = dict()
py_dirs[self.component_name] = self.appdir
return py_dirs
def _get_pips(self):
return dict()
return list()
def _get_pips_expanded(self):
shorts = self._get_pips()
if not shorts:
return dict()
pips = dict()
for fn in shorts:
full_name = sh.joinpths(settings.STACK_PIP_DIR, fn)
pips = utils.extract_pip_list([full_name], self.distro, pips)
return pips
def _install_pips(self):
#install any need pip items
pips = self._get_pips()
pips = self._get_pips_expanded()
if pips:
LOG.info("Setting up %s pips (%s)" % (len(pips), ", ".join(pips.keys())))
pip.install(pips, self.distro)
@ -197,21 +212,12 @@ class PythonInstallComponent(PkgInstallComponent):
return "%s-%s" % (tr.PY_TRACE, name)
def _install_python_setups(self):
#setup any python directories
pydirs = self._get_python_directories()
if pydirs:
actual_dirs = list()
for pydir_info in pydirs:
working_dir = pydir_info.get('work_dir', self.appdir)
actual_dirs.append(working_dir)
LOG.info("Setting up %s python directories (%s)" % (len(pydirs), ", ".join(actual_dirs)))
self.tracewriter.make_dir(self.tracedir)
for pydir_info in pydirs:
name = pydir_info.get("name")
if not name:
#TODO should we raise an exception here?
continue
working_dir = pydir_info.get('work_dir', self.appdir)
LOG.info("Setting up %s python directories (%s)" % (len(pydirs), pydirs))
for (name, wkdir) in pydirs.items():
working_dir = wkdir or self.appdir
self.tracewriter.make_dir(working_dir)
record_fn = tr.touch_trace(self.tracedir, self._format_trace_name(name))
self.tracewriter.file_touched(record_fn)
(stdout, stderr) = sh.execute(*PY_INSTALL, cwd=working_dir, run_as_root=True)

View File

@ -143,11 +143,7 @@ class DBInstaller(comp.PkgInstallComponent):
sh.execute(*UBUNTU_HOST_ADJUST, run_as_root=True)
def _get_pkgs(self):
pkgs = comp.PkgInstallComponent._get_pkgs(self)
for fn in REQ_PKGS:
full_name = sh.joinpths(settings.STACK_PKG_DIR, fn)
pkgs = utils.extract_pkg_list([full_name], self.distro, pkgs)
return pkgs
return list(REQ_PKGS)
def post_install(self):
parent_result = comp.PkgInstallComponent.post_install(self)

View File

@ -85,35 +85,24 @@ class GlanceUninstaller(comp.PythonUninstallComponent):
class GlanceInstaller(comp.PythonInstallComponent):
def __init__(self, *args, **kargs):
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_DIR)
def _get_download_locations(self):
places = comp.PythonInstallComponent._get_download_locations(self)
places = list()
places.append({
'uri': self.git_loc,
'branch': self.git_branch,
'uri': ("git", "glance_repo"),
'branch': ("git", "glance_branch"),
})
return places
def _get_config_files(self):
#these are the config files we will be adjusting
return list(CONFIGS)
def _get_pips(self):
pips = comp.PythonInstallComponent._get_pips(self)
for fn in REQ_PIPS:
full_name = sh.joinpths(settings.STACK_PIP_DIR, fn)
pips = utils.extract_pip_list([full_name], self.distro, pips)
return pips
return list(REQ_PIPS)
def _get_pkgs(self):
pkgs = comp.PythonInstallComponent._get_pkgs(self)
for fn in REQ_PKGS:
full_name = sh.joinpths(settings.STACK_PKG_DIR, fn)
pkgs = utils.extract_pkg_list([full_name], self.distro, pkgs)
return pkgs
return list(REQ_PKGS)
def post_install(self):
parent_result = comp.PythonInstallComponent.post_install(self)

View File

@ -70,32 +70,22 @@ class HorizonUninstaller(comp.PythonUninstallComponent):
class HorizonInstaller(comp.PythonInstallComponent):
def __init__(self, *args, **kargs):
comp.PythonInstallComponent.__init__(self, TYPE, *args, **kargs)
self.git_loc = self.cfg.get("git", "horizon_repo")
self.git_branch = self.cfg.get("git", "horizon_branch")
self.horizon_dir = sh.joinpths(self.appdir, ROOT_HORIZON)
self.dash_dir = sh.joinpths(self.appdir, ROOT_DASH)
def _get_download_locations(self):
places = comp.PythonInstallComponent._get_download_locations(self)
places = list()
places.append({
'uri': self.git_loc,
'branch': self.git_branch,
'uri': ("git", "horizon_repo"),
'branch': ("git", "horizon_branch"),
})
return places
def _get_pkgs(self):
pkgs = comp.PythonInstallComponent._get_pkgs(self)
for fn in REQ_PKGS:
full_name = sh.joinpths(settings.STACK_PKG_DIR, fn)
pkgs = utils.extract_pkg_list([full_name], self.distro, pkgs)
return pkgs
return list(REQ_PKGS)
def _get_pips(self):
pips = comp.PythonInstallComponent._get_pips(self)
for fn in REQ_PIPS:
full_name = sh.joinpths(settings.STACK_PIP_DIR, fn)
pips = utils.extract_pip_list([full_name], self.distro, pips)
return pips
return list(REQ_PIPS)
def _get_target_config_name(self, config_name):
if config_name == HORIZON_PY_CONF:
@ -107,19 +97,12 @@ class HorizonInstaller(comp.PythonInstallComponent):
return comp.PythonInstallComponent._get_target_config_name(self, config_name)
def _get_python_directories(self):
py_dirs = list()
py_dirs.append({
'name': HORIZON_NAME,
'work_dir': self.horizon_dir,
})
py_dirs.append({
'name': DASH_NAME,
'work_dir': self.dash_dir,
})
py_dirs = dict()
py_dirs[HORIZON_NAME] = self.horizon_dir
py_dirs[DASH_NAME] = self.dash_dir
return py_dirs
def _get_config_files(self):
#these are the config files we will be adjusting
return list(CONFIGS)
def _setup_blackhole(self):
@ -131,6 +114,7 @@ class HorizonInstaller(comp.PythonInstallComponent):
def _sync_db(self):
#Initialize the horizon database (it stores sessions and notices shown to users).
#The user system is external (keystone).
LOG.info("Initializing the horizon database")
sh.execute(*DB_SYNC_CMD, cwd=self.dash_dir)
def _fake_quantum(self):

View File

@ -73,32 +73,22 @@ class KeystoneUninstaller(comp.PythonUninstallComponent):
class KeystoneInstaller(comp.PythonInstallComponent):
def __init__(self, *args, **kargs):
comp.PythonInstallComponent.__init__(self, TYPE, *args, **kargs)
self.git_loc = self.cfg.get("git", "keystone_repo")
self.git_branch = self.cfg.get("git", "keystone_branch")
self.cfgdir = sh.joinpths(self.appdir, CONFIG_DIR)
self.bindir = sh.joinpths(self.appdir, BIN_DIR)
def _get_download_locations(self):
places = comp.PythonInstallComponent._get_download_locations(self)
places = list()
places.append({
'uri': self.git_loc,
'branch': self.git_branch,
'uri': ("git", "keystone_repo"),
'branch': ("git", "keystone_branch"),
})
return places
def _get_pips(self):
pips = comp.PythonInstallComponent._get_pips(self)
for fn in REQ_PIPS:
full_name = sh.joinpths(settings.STACK_PIP_DIR, fn)
pips = utils.extract_pip_list([full_name], self.distro, pips)
return pips
return list(REQ_PIPS)
def _get_pkgs(self):
pkgs = comp.PythonInstallComponent._get_pkgs(self)
for fn in REQ_PKGS:
full_name = sh.joinpths(settings.STACK_PKG_DIR, fn)
pkgs = utils.extract_pkg_list([full_name], self.distro, pkgs)
return pkgs
return list(REQ_PKGS)
def post_install(self):
parent_result = comp.PythonInstallComponent.post_install(self)
@ -120,7 +110,7 @@ class KeystoneInstaller(comp.PythonInstallComponent):
return list(CONFIGS)
def _setup_db(self):
LOG.info("Fixing up database named %s", DB_NAME)
LOG.info("Fixing up database named %s.", DB_NAME)
db.drop_db(self.cfg, DB_NAME)
db.create_db(self.cfg, DB_NAME)

View File

@ -37,23 +37,17 @@ class KeyStoneClientUninstaller(comp.PythonUninstallComponent):
class KeyStoneClientInstaller(comp.PythonInstallComponent):
def __init__(self, *args, **kargs):
comp.PythonInstallComponent.__init__(self, TYPE, *args, **kargs)
self.git_loc = self.cfg.get("git", "keystoneclient_repo")
self.git_branch = self.cfg.get("git", "keystoneclient_branch")
def _get_download_locations(self):
places = comp.PythonInstallComponent._get_download_locations(self)
places = list()
places.append({
'uri': self.git_loc,
'branch': self.git_branch,
'uri': ("git", "keystoneclient_repo"),
'branch': ("git", "keystoneclient_branch"),
})
return places
def _get_pkgs(self):
pkgs = comp.PythonInstallComponent._get_pkgs(self)
for fn in REQ_PKGS:
full_name = sh.joinpths(settings.STACK_PKG_DIR, fn)
pkgs = utils.extract_pkg_list([full_name], self.distro, pkgs)
return pkgs
return list(REQ_PKGS)
class KeyStoneClientRuntime(comp.EmptyRuntime):

View File

@ -184,45 +184,25 @@ class NovaUninstaller(comp.PythonUninstallComponent):
class NovaInstaller(comp.PythonInstallComponent):
def __init__(self, *args, **kargs):
comp.PythonInstallComponent.__init__(self, TYPE, *args, **kargs)
self.git_repo = self.cfg.get("git", "nova_repo")
self.git_branch = self.cfg.get("git", "nova_branch")
self.bindir = sh.joinpths(self.appdir, BIN_DIR)
self.paste_conf_fn = self._get_target_config_name(PASTE_CONF)
def _get_pkgs(self):
pkgs = comp.PythonInstallComponent._get_pkgs(self)
# Get the core pkgs
for fn in REQ_PKGS:
full_name = sh.joinpths(settings.STACK_PKG_DIR, fn)
pkgs = utils.extract_pkg_list([full_name], self.distro, pkgs)
# Walk through the subcomponents (like 'vol' and 'cpu') and add those
# those packages as well.
sub_components = []
if self.component_opts:
sub_components = self.component_opts
else:
sub_components = SUBCOMPONENTS
# Add the extra dependencies
pkgs = list(REQ_PKGS)
sub_components = self.component_opts or SUBCOMPONENTS
for c in sub_components:
fns = ADD_PKGS.get(c)
if fns:
for fn in fns:
full_name = sh.joinpths(settings.STACK_PKG_DIR, fn)
pkgs = utils.extract_pkg_list([full_name], self.distro, pkgs)
fns = ADD_PKGS.get(c) or []
pkgs.extend(fns)
return pkgs
def _get_pips(self):
pips = comp.PythonInstallComponent._get_pips(self)
for fn in REQ_PIPS:
full_name = sh.joinpths(settings.STACK_PIP_DIR, fn)
pips = utils.extract_pip_list([full_name], self.distro, pips)
return pips
return list(REQ_PIPS)
def _get_download_locations(self):
places = comp.PythonInstallComponent._get_download_locations(self)
places = list()
places.append({
'uri': self.git_repo,
'branch': self.git_branch,
'uri': ("git", "nova_repo"),
'branch': ("git", "nova_branch"),
})
return places
@ -263,12 +243,12 @@ class NovaInstaller(comp.PythonInstallComponent):
return parent_result
def _setup_db(self):
LOG.info("Fixing up database named %s", DB_NAME)
LOG.info("Fixing up database named %s.", DB_NAME)
db.drop_db(self.cfg, DB_NAME)
db.create_db(self.cfg, DB_NAME)
def _setup_vol_groups(self):
LOG.info("Attempting to setup volume groups for nova volume management")
LOG.info("Attempting to setup volume groups for nova volume management.")
mp = dict()
backing_file = self.cfg.get('nova', 'volume_backing_file')
# check if we need to have a default backing file
@ -301,7 +281,7 @@ class NovaInstaller(comp.PythonInstallComponent):
utils.execute_template(*RESTART_TGT_CMD, check_exit_code=False, tracewriter=self.tracewriter)
def _process_lvs(self, mp):
LOG.info("Attempting to setup logical volumes for nova volume management")
LOG.info("Attempting to setup logical volumes for nova volume management.")
lvs_result = utils.execute_template(*VG_LVS_CMD, params=mp, tracewriter=self.tracewriter)
LOG.debug("lvs result: %s" % (lvs_result))
vol_name_prefix = self.cfg.get('nova', 'volume_name_prefix')

View File

@ -37,23 +37,17 @@ class NovaClientUninstaller(comp.PythonUninstallComponent):
class NovaClientInstaller(comp.PythonInstallComponent):
def __init__(self, *args, **kargs):
comp.PythonInstallComponent.__init__(self, TYPE, *args, **kargs)
self.git_loc = self.cfg.get("git", "novaclient_repo")
self.git_branch = self.cfg.get("git", "novaclient_branch")
def _get_download_locations(self):
places = comp.PythonInstallComponent._get_download_locations(self)
places = list()
places.append({
'uri': self.git_loc,
'branch': self.git_branch,
'uri': ("git", "novaclient_repo"),
'branch': ("git", "novaclient_branch"),
})
return places
def _get_pkgs(self):
pkgs = comp.PythonInstallComponent._get_pkgs(self)
for fn in REQ_PKGS:
full_name = sh.joinpths(settings.STACK_PKG_DIR, fn)
pkgs = utils.extract_pkg_list([full_name], self.distro, pkgs)
return pkgs
return list(REQ_PKGS)
class NovaClientRuntime(comp.EmptyRuntime):

View File

@ -49,23 +49,17 @@ class NoVNCUninstaller(comp.PkgUninstallComponent):
class NoVNCInstaller(comp.PkgInstallComponent):
def __init__(self, *args, **kargs):
comp.PkgInstallComponent.__init__(self, TYPE, *args, **kargs)
self.git_loc = self.cfg.get("git", "novnc_repo")
self.git_branch = self.cfg.get("git", "novnc_branch")
def _get_download_locations(self):
places = comp.PkgInstallComponent._get_download_locations(self)
places = list()
places.append({
'uri': self.git_loc,
'branch': self.git_branch,
'uri': ("git", "novnc_repo"),
'branch': ("git", "novnc_branch"),
})
return places
def _get_pkgs(self):
pkgs = comp.PkgInstallComponent._get_pkgs(self)
for fn in REQ_PKGS:
full_name = sh.joinpths(settings.STACK_PKG_DIR, fn)
pkgs = utils.extract_pkg_list([full_name], self.distro, pkgs)
return pkgs
return list(REQ_PKGS)
class NoVNCRuntime(comp.ProgramRuntime):

View File

@ -37,23 +37,17 @@ class OpenstackXUninstaller(comp.PythonUninstallComponent):
class OpenstackXInstaller(comp.PythonInstallComponent):
def __init__(self, *args, **kargs):
comp.PythonInstallComponent.__init__(self, TYPE, *args, **kargs)
self.git_loc = self.cfg.get("git", "openstackx_repo")
self.git_branch = self.cfg.get("git", "openstackx_branch")
def _get_download_locations(self):
places = comp.PythonInstallComponent._get_download_locations(self)
places = list()
places.append({
'uri': self.git_loc,
'branch': self.git_branch,
'uri': ("git", "openstackx_repo"),
'branch': ("git", "openstackx_branch"),
})
return places
def _get_pkgs(self):
pkgs = comp.PythonInstallComponent._get_pkgs(self)
for fn in REQ_PKGS:
full_name = sh.joinpths(settings.STACK_PKG_DIR, fn)
pkgs = utils.extract_pkg_list([full_name], self.distro, pkgs)
return pkgs
return list(REQ_PKGS)
class OpenstackXRuntime(comp.EmptyRuntime):

View File

@ -80,8 +80,6 @@ class QuantumUninstaller(comp.PkgUninstallComponent):
class QuantumInstaller(comp.PkgInstallComponent):
def __init__(self, *args, **kargs):
comp.PkgInstallComponent.__init__(self, TYPE, *args, **kargs)
self.git_loc = self.cfg.get("git", "quantum_repo")
self.git_branch = self.cfg.get("git", "quantum_branch")
self.q_vswitch_agent = False
self.q_vswitch_service = False
plugin = self.cfg.get("quantum", "q_plugin")
@ -98,27 +96,21 @@ class QuantumInstaller(comp.PkgInstallComponent):
self.q_vswitch_agent = True
def _get_download_locations(self):
places = comp.PkgInstallComponent._get_download_locations(self)
places = list()
places.append({
'uri': self.git_loc,
'branch': self.git_branch,
'uri': ("git", "quantum_repo"),
'branch': ("git", "quantum_branch"),
})
return places
def _get_pkgs(self):
pkglist = comp.PkgInstallComponent._get_pkgs(self)
for fn in REQ_PKGS:
full_name = sh.joinpths(settings.STACK_PKG_DIR, fn)
pkglist = utils.extract_pkg_list([full_name], self.distro, pkglist)
pkglist = list(REQ_PKGS)
if self.q_vswitch_service:
listing_fn = sh.joinpths(settings.STACK_PKG_DIR, PKG_VSWITCH)
pkglist = utils.extract_pkg_list([listing_fn], self.distro, pkglist)
pkglist.append(PKG_VSWITCH)
return pkglist
def _get_config_files(self):
parent_list = comp.PkgInstallComponent._get_config_files(self)
parent_list.extend(CONFIG_FILES)
return parent_list
return list(CONFIG_FILES)
def _get_target_config_name(self, config_fn):
if config_fn == PLUGIN_CONF:
@ -198,7 +190,7 @@ class QuantumInstaller(comp.PkgInstallComponent):
return parent_result
def _setup_db(self):
LOG.info("Fixing up database named %s", DB_NAME)
LOG.info("Fixing up database named %s.", DB_NAME)
db.drop_db(self.cfg, DB_NAME)
db.create_db(self.cfg, DB_NAME)

View File

@ -37,23 +37,17 @@ class QuantumClientUninstaller(comp.PythonUninstallComponent):
class QuantumClientInstaller(comp.PythonInstallComponent):
def __init__(self, *args, **kargs):
comp.PythonInstallComponent.__init__(self, TYPE, *args, **kargs)
self.git_loc = self.cfg.get("git", "quantum_client_repo")
self.git_branch = self.cfg.get("git", "quantum_client_branch")
def _get_download_locations(self):
places = comp.PythonInstallComponent._get_download_locations(self)
places = list()
places.append({
'uri': self.git_loc,
'branch': self.git_branch,
'uri': ("git", "quantum_client_repo"),
'branch': ("git", "quantum_client_branch"),
})
return places
def _get_pkgs(self):
pkgs = comp.PythonInstallComponent._get_pkgs(self)
for fn in REQ_PKGS:
full_name = sh.joinpths(settings.STACK_PKG_DIR, fn)
pkgs = utils.extract_pkg_list([full_name], self.distro, pkgs)
return pkgs
return list(REQ_PKGS)
class QuantumClientRuntime(comp.EmptyRuntime):

View File

@ -55,7 +55,7 @@ class RabbitUninstaller(comp.PkgUninstallComponent):
def pre_uninstall(self):
try:
self.runtime.restart()
LOG.info("Resetting the guest password to \"%s\"", RESET_BASE_PW)
LOG.info("Resetting the rabbit-mq guest password to \"%s\"", RESET_BASE_PW)
cmd = PWD_CMD + [RESET_BASE_PW]
sh.execute(*cmd, run_as_root=True)
except IOError:
@ -83,11 +83,7 @@ class RabbitInstaller(comp.PkgInstallComponent):
return parent_result
def _get_pkgs(self):
pkgs = comp.PkgInstallComponent._get_pkgs(self)
for fn in REQ_PKGS:
full_name = sh.joinpths(settings.STACK_PKG_DIR, fn)
pkgs = utils.extract_pkg_list([full_name], self.distro, pkgs)
return pkgs
return list(REQ_PKGS)
class RabbitRuntime(comp.EmptyRuntime):

View File

@ -21,6 +21,7 @@ import os.path
import pwd
import shutil
import subprocess
import tempfile
from devstack import env
from devstack import exceptions as excp
@ -161,6 +162,16 @@ def _gen_password(pw_len):
return stdout.strip()
def write_file_su(fn, text, flush=True):
with tempfile.NamedTemporaryFile() as fh:
tmp_fn = fh.name
fh.write(text)
if flush:
fh.flush()
cmd = ['cp', tmp_fn, fn]
execute(*cmd, run_as_root=True)
def prompt_password(pw_prompt=None):
if pw_prompt:
rc = getpass.getpass(pw_prompt)