Switch all of the commands in YAML files to simple strings and

parse them into lists in the code that fetches commands from
the config.
This commit is contained in:
Doug Hellmann 2012-03-21 11:23:09 -04:00
parent 462eee3a99
commit cefd378401
9 changed files with 583 additions and 724 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,101 +1,42 @@
---
# RedHat Enterprise Linux 6
distro_pattern: redhat-6(.*)
name: rhel-6
packager_name: devstack.distros.rhel6:YumPackager
distro_pattern: redhat-6(.*)
commands:
apache:
restart:
- service
- httpd
- restart
restart: service httpd restart
settings:
# Ensure runs after wsgi.conf (file naming wise)
conf-link-target: /etc/httpd/conf.d/wsgi-horizon-000-default.conf
start:
- service
- httpd
- start
status:
- service
- httpd
- status
stop:
- service
- httpd
- stop
start: service httpd start
status: service httpd status
stop: service httpd stop
git:
checkout:
- git
- checkout
clone:
- git
- clone
pull:
- git
- pull
checkout: git checkout
clone: git clone
pull: git pull
libvirt:
restart:
- service
- libvirtd
- restart
status:
- service
- libvirtd
- status
restart: service libvirtd restart
status: service libvirtd status
mysql:
# NOTE: we aren't stopping any sql injection...
create_db:
- mysql
- --user=%USER%
- --password=%PASSWORD%
- -e
- CREATE DATABASE %DB%;
drop_db:
- mysql
- --user=%USER%
- --password=%PASSWORD%
- -e
- DROP DATABASE IF EXISTS %DB%;
grant_all:
- mysql
- --user=%USER%
- --password=%PASSWORD%
- -e
- '"GRANT ALL PRIVILEGES ON *.* TO ''%USER%''@''%'' IDENTIFIED BY ''%PASSWORD%'';
FLUSH PRIVILEGES;"'
restart:
- service
- mysqld
- restart
set_pwd:
- mysql
- --user=%USER%
- --password=%OLD_PASSWORD%
- -e
- '"USE mysql; UPDATE user SET password=PASSWORD(''%NEW_PASSWORD%'') WHERE
User=''%USER%''; FLUSH PRIVILEGES;"'
start:
- service
- mysqld
- start
status:
- service
- mysqld
- status
stop:
- service
- mysqld
- stop
create_db: mysql --user=%USER% --password=%PASSWORD% -e "CREATE DATABASE %DB%;"
drop_db: mysql --user=%USER% --password=%PASSWORD% -e "DROP DATABASE IF EXISTS
%DB%;"
grant_all: mysql --user=%USER% --password=%PASSWORD% -e "GRANT ALL PRIVILEGES
ON *.* TO '%USER%'@'%' IDENTIFIED BY '%PASSWORD%'; FLUSH PRIVILEGES;"
restart: service mysqld restart
set_pwd: mysql --user=%USER% --password=%OLD_PASSWORD% -e "USE mysql; UPDATE
user SET password=PASSWORD('%NEW_PASSWORD%') WHERE User='%USER%'; FLUSH
PRIVILEGES;"
start: service mysqld start
status: service mysqld status
stop: service mysqld stop
pip: pip-python
rabbit-mq:
start: ['service', "rabbitmq-server", "start"]
stop: ['service', "rabbitmq-server", "stop"]
status: ['service', "rabbitmq-server", "status"]
restart: ['service', "rabbitmq-server", "restart"]
change_password: ['rabbitmqctl', 'change_password', 'guest']
change_password: rabbitmqctl change_password guest
restart: service rabbitmq-server restart
start: service rabbitmq-server start
status: service rabbitmq-server status
stop: service rabbitmq-server stop
components:
db:
install: devstack.distros.rhel6:DBInstaller
@ -702,5 +643,6 @@ components:
start: devstack.components.swift:SwiftRuntime
stop: devstack.components.swift:SwiftRuntime
uninstall: devstack.components.swift:SwiftUninstaller
packager_name: devstack.distros.rhel6:YumPackager
...

View File

@ -5,111 +5,41 @@ name: ubuntu-oneiric
packager_name: devstack.distros.oneiric:AptPackager
commands:
apache:
restart:
- service
- apache2
- restart
restart: service apache2 restart
settings:
conf-link-target: /etc/apache2/sites-enabled/000-default
start:
- service
- apache2
- start
status:
- service
- apache2
- status
stop:
- service
- apache2
- stop
start: service apache2 start
status: service apache2 status
stop: service apache2 stop
git:
checkout:
- git
- checkout
clone:
- git
- clone
pull:
- git
- pull
checkout: git checkout
clone: git clone
pull: git pull
iscsi:
restart:
- service
- tgt
- restart
start:
- service
- tgt
- start
status:
- service
- tgt
- status
stop:
- service
- tgt
- stop
restart: service tgt restart
start: service tgt start
status: service tgt status
stop: service tgt stop
libvirt:
restart:
- service
- libvirt-bin
- restart
status:
- service
- libvirt-bin
- status
restart: service libvirt-bin restart
status: service libvirt-bin status
mysql:
# NOTE: we aren't stopping any sql injection...
create_db:
- mysql
- --user=%USER%
- --password=%PASSWORD%
- -e
- CREATE DATABASE %DB%;
drop_db:
- mysql
- --user=%USER%
- --password=%PASSWORD%
- -e
- DROP DATABASE IF EXISTS %DB%;
grant_all:
- mysql
- --user=%USER%
- --password=%PASSWORD%
- -e
- '"GRANT ALL PRIVILEGES ON *.* TO ''%USER%''@''%'' IDENTIFIED BY ''%PASSWORD%'';
FLUSH PRIVILEGES;"'
restart:
- service
- mysql
- restart
set_pwd:
- mysql
- --user=%USER%
- --password=%OLD_PASSWORD%
- -e
- '"USE mysql; UPDATE user SET password=PASSWORD(''%NEW_PASSWORD%'') WHERE
User=''%USER%''; FLUSH PRIVILEGES;"'
start:
- service
- mysql
- start
status:
- service
- mysql
- status
stop:
- service
- mysql
- stop
create_db: mysql --user=%USER% --password=%PASSWORD% -e "CREATE DATABASE %DB%;"
drop_db: mysql --user=%USER% --password=%PASSWORD% -e "DROP DATABASE IF EXISTS %DB%;"
grant_all: mysql --user=%USER% --password=%PASSWORD% -e "GRANT ALL PRIVILEGES ON *.* TO '%USER%'@'%' IDENTIFIED BY '%PASSWORD%'; FLUSH PRIVILEGES;"
restart: service mysql restart
set_pwd: mysql --user=%USER% --password=%OLD_PASSWORD% -e "USE mysql; UPDATE user SET password=PASSWORD('%NEW_PASSWORD%') WHERE User='%USER%'; FLUSH PRIVILEGES;"
start: service mysql start
status: service mysql status
stop: service mysql stop
pip: pip
rabbit-mq:
start: ['service', "rabbitmq-server", "start"]
stop: ['service', "rabbitmq-server", "stop"]
status: ['service', "rabbitmq-server", "status"]
restart: ['service', "rabbitmq-server", "restart"]
change_password: ['rabbitmqctl', 'change_password', 'guest']
start: service rabbitmq-server start
stop: service rabbitmq-server stop
status: service rabbitmq-server status
restart: service rabbitmq-server restart
change_password: rabbitmqctl change_password guest
components:
db:

View File

@ -53,12 +53,12 @@ class DBUninstaller(comp.PkgUninstallComponent):
def pre_uninstall(self):
dbtype = self.cfg.get("db", "type")
dbactions = self.distro.get_command(dbtype, quiet=True)
dbactions = self.distro.get_command_config(dbtype, quiet=True)
try:
if dbactions:
LOG.info(("Attempting to reset your db password to \"%s\" so"
" that we can set it the next time you install.") % (RESET_BASE_PW))
pwd_cmd = dbactions.get('set_pwd')
pwd_cmd = self.distro.get_command(dbtype, 'set_pwd')
if pwd_cmd:
LOG.info("Ensuring your database is started before we operate on it.")
self.runtime.restart()
@ -68,7 +68,7 @@ class DBUninstaller(comp.PkgUninstallComponent):
'USER': self.cfg.getdefaulted("db", "sql_user", 'root'),
}
cmds = [{'cmd': pwd_cmd}]
utils.execute_template(*cmds, params=params, shell=True)
utils.execute_template(*cmds, params=params)
except IOError:
LOG.warn(("Could not reset the database password. You might have to manually "
"reset the password to \"%s\" before the next install") % (RESET_BASE_PW))
@ -111,12 +111,12 @@ class DBInstaller(comp.PkgInstallComponent):
# Extra actions to ensure we are granted access
dbtype = self.cfg.get("db", "type")
dbactions = self.distro.get_command(dbtype, quiet=True)
dbactions = self.distro.get_command_config(dbtype, quiet=True)
# Set your password
try:
if dbactions:
pwd_cmd = dbactions.get('set_pwd')
pwd_cmd = self.distro.get_command(dbtype, 'set_pwd')
if pwd_cmd:
LOG.info(("Attempting to set your db password"
" just incase it wasn't set previously."))
@ -128,14 +128,14 @@ class DBInstaller(comp.PkgInstallComponent):
'OLD_PASSWORD': RESET_BASE_PW,
}
cmds = [{'cmd': pwd_cmd}]
utils.execute_template(*cmds, params=params, shell=True)
utils.execute_template(*cmds, params=params)
except IOError:
LOG.warn(("Couldn't set your db password. It might have already been "
"set by a previous process."))
# Ensure access granted
if dbactions:
grant_cmd = dbactions.get('grant_all')
grant_cmd = self.distro.get_command(dbtype, 'grant_all')
if grant_cmd:
user = self.cfg.getdefaulted("db", "sql_user", 'root')
LOG.info("Updating the DB to give user '%s' full control of all databases." % (user))
@ -148,7 +148,7 @@ class DBInstaller(comp.PkgInstallComponent):
cmds = [{'cmd': grant_cmd}]
# Shell seems to be needed here
# since python escapes this to much...
utils.execute_template(*cmds, params=params, shell=True)
utils.execute_template(*cmds, params=params)
class DBRuntime(comp.EmptyRuntime):
@ -158,11 +158,11 @@ class DBRuntime(comp.EmptyRuntime):
def _get_run_actions(self, act, exception_cls):
dbtype = self.cfg.get("db", "type")
distro_options = self.distro.get_command(dbtype)
distro_options = self.distro.get_command_config(dbtype)
if distro_options is None:
msg = BASE_ERROR % (act, dbtype)
raise NotImplementedError(msg)
return distro_options.get(act)
return self.distro.get_command(dbtype, act)
def start(self):
if self.status() != comp.STATUS_STARTED:
@ -190,8 +190,8 @@ class DBRuntime(comp.EmptyRuntime):
LOG.info("Restarting your database.")
restartcmd = self._get_run_actions('restart', excp.RestartException)
sh.execute(*restartcmd,
run_as_root=True,
check_exit_code=True)
run_as_root=True,
check_exit_code=True)
LOG.info("Please wait %s seconds while it restarts." % self.wait_time)
sh.sleep(self.wait_time)
return 1
@ -217,9 +217,8 @@ class DBRuntime(comp.EmptyRuntime):
def drop_db(cfg, pw_gen, distro, dbname):
dbtype = cfg.get("db", "type")
dbactions = distro.get_command(dbtype)
if dbactions and dbactions.get('drop_db'):
dropcmd = dbactions.get('drop_db')
dropcmd = distro.get_command(dbtype, 'drop_db', silent=True)
if dropcmd:
params = dict()
params['PASSWORD'] = pw_gen.get_password("sql", PASSWORD_PROMPT)
params['USER'] = cfg.getdefaulted("db", "sql_user", 'root')
@ -237,9 +236,8 @@ def drop_db(cfg, pw_gen, distro, dbname):
def create_db(cfg, pw_gen, distro, dbname):
dbtype = cfg.get("db", "type")
dbactions = distro.get_command(dbtype)
if dbactions and dbactions.get('create_db'):
createcmd = dbactions.get('create_db')
createcmd = distro.get_command(dbtype, 'create_db', silent=True)
if createcmd:
params = dict()
params['PASSWORD'] = pw_gen.get_password("sql", PASSWORD_PROMPT)
params['USER'] = cfg.getdefaulted("db", "sql_user", 'root')

View File

@ -80,8 +80,9 @@ class HorizonInstaller(comp.PythonInstallComponent):
def _get_symlinks(self):
links = comp.PythonInstallComponent._get_symlinks(self)
link_tgt = self.distro.get_command('apache', 'settings',
'conf-link-target', quiet=True)
link_tgt = self.distro.get_command_config(
'apache', 'settings', 'conf-link-target',
quiet=True)
if link_tgt:
src = self._get_target_config_name(HORIZON_APACHE_CONF)
links[src] = link_tgt

View File

@ -49,6 +49,8 @@ RSYNC_SERVICE_RESTART = ['service', 'rsync', 'restart']
RSYSLOG_SERVICE_RESTART = ['service', 'rsyslog', 'restart']
RSYNC_ON_OFF_RE = re.compile(r'^\s*RSYNC_ENABLE\s*=\s*(.*)$', re.I)
# FIXME: This should come from the persona, if we really expect
# people to change it.
# Defines our auth service type
AUTH_SERVICE = 'keystone'

View File

@ -18,6 +18,7 @@
import glob
import platform
import re
import shlex
import yaml
@ -84,7 +85,7 @@ class Distro(object):
self._commands = commands
self._components = components
def get_command(self, key, *more_keys, **kargs):
def get_command_config(self, key, *more_keys, **kargs):
""" Gets a end object for a given set of keys """
root = self._commands
acutal_keys = [key] + list(more_keys)
@ -105,9 +106,18 @@ class Distro(object):
end_value = root[end_key]
else:
end_value = root.get(end_key)
LOG.debug("Retrieved end command: %s", end_value)
LOG.debug("Retrieved end command config: %s", end_value)
return end_value
def get_command(self, key, *more_keys, **kargs):
"""Retrieves a string for running a command from the setup
and splits it to return a list.
"""
val = self.get_command_config(key, *more_keys, **kargs)
ret_val = shlex.split(val) if val else []
LOG.debug("Parsed configured command: %s", ret_val)
return ret_val
def known_component(self, name):
return name in self._components

View File

@ -32,7 +32,7 @@ def _make_pip_name(name, version):
def install(pip, distro):
name = pip['name']
root_cmd = distro.get_command('pip')
root_cmd = distro.get_command_config('pip')
LOG.audit("Installing python package (%s) using pip command (%s)" % (name, root_cmd))
name_full = _make_pip_name(name, pip.get('version'))
real_cmd = [root_cmd, 'install'] + PIP_INSTALL_CMD_OPTS

View File

@ -101,9 +101,9 @@ def execute(*cmd, **kwargs):
execute_cmd = str_cmd.strip()
if not shell:
LOG.audit('Running cmd: %s' % (execute_cmd))
LOG.audit('Running cmd: %r' % (execute_cmd))
else:
LOG.audit('Running shell cmd: %s' % (execute_cmd))
LOG.audit('Running shell cmd: %r' % (execute_cmd))
if process_input is not None:
LOG.audit('With stdin: %s' % (process_input))