]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
heat-db-setup read engine config file for DB connection details
authorSteven Hardy <shardy@redhat.com>
Fri, 7 Dec 2012 17:16:04 +0000 (17:16 +0000)
committerSteven Hardy <shardy@redhat.com>
Fri, 7 Dec 2012 17:16:04 +0000 (17:16 +0000)
Currently heat-db-setup, or rather the underlying python -m heat.db.sqlalchemy.manage
has a hard-coded database connection URL, so DB setup will fail if a non-default
configuration exists in /etc/heat/heat-engine.conf.

This attempts to read the sql_connection from the DEFAULT section of heat-engine.conf
falling back to the old default string on failure.

bug/1087741

Change-Id: Ieb41503a58ee0804d79a32a8286268803c9f456c
Signed-off-by: Steven Hardy <shardy@redhat.com>
heat/db/sqlalchemy/manage.py

index a0dd923aaeb0ce627a5cc0dbf88b8a31c7498519..dabb204cbd9becea374c6aaabb455e0b760b64d4 100755 (executable)
@@ -1,14 +1,25 @@
 #!/usr/bin/env python
 from migrate.versioning.shell import main
 import migrate.exceptions
+import ConfigParser
 
 if __name__ == '__main__':
     import os.path
     migrate_repo_path = os.path.join(os.path.dirname(__file__),
                                      'migrate_repo')
 
+    # Try to get the config-file value for sql_connection
+    # Note we can't use openstack.common.cfg because this also insists
+    # on parsing the CLI, which we don't want here
+    config = ConfigParser.SafeConfigParser()
     try:
-        main(url='mysql://heat:heat@localhost/heat', debug='False',
-             repository=migrate_repo_path)
+        config = ConfigParser.SafeConfigParser()
+        config.readfp(open('/etc/heat/heat-engine.conf'))
+        sql_connection = config.get('DEFAULT', 'sql_connection')
+    except Exception:
+        sql_connection = 'mysql://heat:heat@localhost/heat'
+
+    try:
+        main(url=sql_connection, debug='False', repository=migrate_repo_path)
     except migrate.exceptions.DatabaseAlreadyControlledError:
         print 'Database already version controlled.'