From 8dcb532c587ef7dd0d79bea5ace835d6d5b16f09 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Thu, 29 Mar 2012 18:59:51 -0700 Subject: [PATCH] More tiny cleanups --- conf/distros/fedora-16.yaml | 22 +++++++++++++--------- conf/distros/rhel-6.yaml | 20 ++++++++++++-------- conf/distros/ubuntu-oneiric.yaml | 15 +++++++++++---- devstack/components/db.py | 16 +++++++--------- devstack/components/horizon.py | 21 ++++++++------------- devstack/components/keystone.py | 2 +- devstack/components/melange.py | 2 +- 7 files changed, 53 insertions(+), 45 deletions(-) diff --git a/conf/distros/fedora-16.yaml b/conf/distros/fedora-16.yaml index 5025e91d..6e0a4ba1 100644 --- a/conf/distros/fedora-16.yaml +++ b/conf/distros/fedora-16.yaml @@ -2,6 +2,7 @@ # Fedora 16 configuration for DevstackPy name: fedora-16 distro_pattern: fedora-16 +packager_name: devstack.packaging.yum:YumPackager commands: apache: restart: service httpd restart @@ -19,15 +20,19 @@ commands: # This is just used to check that libvirt will work with a given protocol verify: virsh -c %VIRT_PROTOCOL% uri mysql: - 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;" + # NOTE: we aren't stopping any sql injection... + create_db: mysql --user=%USER% --password=%PASSWORD% -e + "CREATE DATABASE %DB% CHARACTER SET utf8;" + 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;" + 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 @@ -647,6 +652,5 @@ components: - name: xfsprogs removable: true version: 3.1* -packager_name: devstack.packaging.yum:YumPackager ... diff --git a/conf/distros/rhel-6.yaml b/conf/distros/rhel-6.yaml index 9c6390ee..03cf9ad0 100644 --- a/conf/distros/rhel-6.yaml +++ b/conf/distros/rhel-6.yaml @@ -20,15 +20,19 @@ commands: # This is just used to check that libvirt will work with a given protocol verify: virsh -c %VIRT_PROTOCOL% uri mysql: - 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;" + # NOTE: we aren't stopping any sql injection... + create_db: mysql --user=%USER% --password=%PASSWORD% -e + "CREATE DATABASE %DB% CHARACTER SET utf8;" + 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;" + 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 diff --git a/conf/distros/ubuntu-oneiric.yaml b/conf/distros/ubuntu-oneiric.yaml index ee2b9f85..13f87b42 100644 --- a/conf/distros/ubuntu-oneiric.yaml +++ b/conf/distros/ubuntu-oneiric.yaml @@ -26,11 +26,18 @@ commands: verify: virsh -c %VIRT_PROTOCOL% uri 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;" + create_db: mysql --user=%USER% --password=%PASSWORD% -e + "CREATE DATABASE %DB% CHARACTER SET utf8;" + 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;" + 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 diff --git a/devstack/components/db.py b/devstack/components/db.py index 42cf7807..0cd74e16 100644 --- a/devstack/components/db.py +++ b/devstack/components/db.py @@ -35,7 +35,7 @@ SQL_RESET_PW_LINKS = [ ] # Used as a generic error message -BASE_ERROR = 'Currently we do not know how to [%s] for database type [%s]' +BASE_ERROR = 'Currently we do not know how to %r for database type %r' # PW keys we warm up so u won't be prompted later PASSWORD_PROMPT = 'the database user' @@ -56,7 +56,7 @@ class DBUninstaller(comp.PkgUninstallComponent): dbactions = self.distro.get_command_config(dbtype, quiet=True) try: if dbactions: - LOG.info(("Attempting to reset your db password to \"%s\" so" + LOG.info(("Attempting to reset your db password to %r so" " that we can set it the next time you install.") % (RESET_BASE_PW)) pwd_cmd = self.distro.get_command(dbtype, 'set_pwd') if pwd_cmd: @@ -71,8 +71,9 @@ class DBUninstaller(comp.PkgUninstallComponent): 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)) - LOG.info("To aid in this check out: [%s]", " or ".join(SQL_RESET_PW_LINKS)) + "reset the password to %r before the next install") % (RESET_BASE_PW)) + utils.log_iterable(SQL_RESET_PW_LINKS, logger=LOG, + header="To aid in this check out:") class DBInstaller(comp.PkgInstallComponent): @@ -138,7 +139,7 @@ class DBInstaller(comp.PkgInstallComponent): 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)) + LOG.info("Updating the DB to give user %r full control of all databases." % (user)) LOG.info("Ensuring your database is started before we operate on it.") self.runtime.restart() params = { @@ -146,8 +147,6 @@ class DBInstaller(comp.PkgInstallComponent): 'USER': user, } cmds = [{'cmd': grant_cmd}] - # Shell seems to be needed here - # since python escapes this to much... utils.execute_template(*cmds, params=params) @@ -204,8 +203,7 @@ class DBRuntime(comp.EmptyRuntime): if not run_result: return comp.STATUS_UNKNOWN (sysout, stderr) = run_result - combined = str(sysout) + str(stderr) - combined = combined.lower() + combined = (str(sysout) + str(stderr)).lower() if combined.find("running") != -1: return comp.STATUS_STARTED elif combined.find("stop") != -1 or \ diff --git a/devstack/components/horizon.py b/devstack/components/horizon.py index 6e386319..9a6d5e18 100644 --- a/devstack/components/horizon.py +++ b/devstack/components/horizon.py @@ -91,10 +91,10 @@ class HorizonInstaller(comp.PythonInstallComponent): def _check_ug(self): (user, group) = self._get_apache_user_group() if not sh.user_exists(user): - msg = "No user named %s exists on this system!" % (user) + msg = "No user named %r exists on this system!" % (user) raise excp.ConfigException(msg) if not sh.group_exists(group): - msg = "No group named %s exists on this system!" % (group) + msg = "No group named %r exists on this system!" % (group) raise excp.ConfigException(msg) if user in BAD_APACHE_USERS: msg = ("You may want to adjust your configuration, " @@ -129,11 +129,9 @@ class HorizonInstaller(comp.PythonInstallComponent): path = sh.joinpths(self.dash_dir, 'local') if sh.isdir(path): (user, group) = self._get_apache_user_group() - LOG.debug("Changing ownership (recursively) of %s so that it can be used by %s - %s", - path, user, group) - uid = sh.getuid(user) - gid = sh.getgid(group) - sh.chown_r(path, uid, gid) + LOG.debug("Changing ownership (recursively) of %r so that it can be used by %r/%r", + path, group, user) + sh.chown_r(path, sh.getuid(user), sh.getgid(group)) def pre_install(self): comp.PythonInstallComponent.pre_install(self) @@ -208,8 +206,7 @@ class HorizonRuntime(comp.EmptyRuntime): 'run_as_root': True, }] utils.execute_template(*cmds, - check_exit_code=True, - params={}) + check_exit_code=True) return 1 return 0 @@ -219,13 +216,11 @@ class HorizonRuntime(comp.EmptyRuntime): 'run_as_root': True, }] run_result = utils.execute_template(*cmds, - check_exit_code=False, - params={}) + check_exit_code=False) if not run_result or not run_result[0]: return comp.STATUS_UNKNOWN (sysout, stderr) = run_result[0] - combined = str(sysout) + str(stderr) - combined = combined.lower() + combined = (str(sysout) + str(stderr)).lower() if combined.find("is running") != -1: return comp.STATUS_STARTED elif combined.find("not running") != -1 or \ diff --git a/devstack/components/keystone.py b/devstack/components/keystone.py index 02fbcd2f..79d71975 100644 --- a/devstack/components/keystone.py +++ b/devstack/components/keystone.py @@ -140,7 +140,7 @@ class KeystoneInstaller(comp.PythonInstallComponent): if name == ROOT_CONF: # Use config parser and # then extract known configs that - # ill need locations/directories/files made (or touched)... + # will need locations/directories/files made (or touched)... with io.BytesIO(contents) as stream: config = cfg.IgnoreMissingConfigParser(cs=False) config.readfp(stream) diff --git a/devstack/components/melange.py b/devstack/components/melange.py index 181aab76..e6578bba 100644 --- a/devstack/components/melange.py +++ b/devstack/components/melange.py @@ -47,7 +47,7 @@ DB_SYNC_CMD = [ # TODO: ??? CIDR_CREATE_CMD = [ - {'cmd': ['melange', 'mac_address_range', 'create', 'cidr', '%CIDR_RANGE%']}, + {'cmd': ['melange', '--config-file=%CFG_FILE%', 'mac_address_range', 'create', 'cidr', '%CIDR_RANGE%']}, ] # What to start