summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-11-30 16:46:50 +0000
committerGerrit Code Review <review@openstack.org>2012-11-30 16:46:50 +0000
commit925ba0b6d5c48d5ea80f06a384311eb2605b63db (patch)
treea24a47a84d713938c8c1621eb7944bdd532d9368 /nova
parentf19fc49b220632a3d4005ed416121c1dfd0c4f8b (diff)
parentce79e4ce66eac284ce29941744fb09e316b899db (diff)
Merge "Fix test_migrations for postgres"
Diffstat (limited to 'nova')
-rw-r--r--nova/tests/test_migrations.py36
1 files changed, 15 insertions, 21 deletions
diff --git a/nova/tests/test_migrations.py b/nova/tests/test_migrations.py
index d82ae7585..138bb3477 100644
--- a/nova/tests/test_migrations.py
+++ b/nova/tests/test_migrations.py
@@ -177,29 +177,23 @@ class TestMigrations(test.TestCase):
user = auth_pieces[0]
password = ""
if len(auth_pieces) > 1:
- if auth_pieces[1].strip():
- password = auth_pieces[1]
- cmd = ("touch ~/.pgpass;"
- "chmod 0600 ~/.pgpass;"
- "sed -i -e"
- "'1{s/^.*$/\*:\*:\*:%(user)s:%(password)s/};"
- "1!d' ~/.pgpass") % locals()
- execute_cmd(cmd)
- sql = ("UPDATE pg_catalog.pg_database SET datallowconn=false "
- "WHERE datname='%(database)s';") % locals()
- cmd = ("psql -U%(user)s -h%(host)s -c\"%(sql)s\"") % locals()
- execute_cmd(cmd)
- sql = ("SELECT pg_catalog.pg_terminate_backend(procpid) "
- "FROM pg_catalog.pg_stat_activity "
- "WHERE datname='%(database)s';") % locals()
- cmd = ("psql -U%(user)s -h%(host)s -c\"%(sql)s\"") % locals()
- execute_cmd(cmd)
+ password = auth_pieces[1].strip()
+ # note(boris-42): This file is used for authentication
+ # without password prompt.
+ createpgpass = ("echo '*:*:*:%(user)s:%(password)s' > "
+ "~/.pgpass && chmod 0600 ~/.pgpass" % locals())
+ execute_cmd(createpgpass)
+ # note(boris-42): We must create and drop database, we can't
+ # drop database wich we have connected to, so for such
+ # operations there is a special database template1.
+ sqlcmd = ("psql -w -U %(user)s -h %(host)s -c"
+ " '%(sql)s' -d template1")
sql = ("drop database if exists %(database)s;") % locals()
- cmd = ("psql -U%(user)s -h%(host)s -c\"%(sql)s\"") % locals()
- execute_cmd(cmd)
+ droptable = sqlcmd % locals()
+ execute_cmd(droptable)
sql = ("create database %(database)s;") % locals()
- cmd = ("psql -U%(user)s -h%(host)s -c\"%(sql)s\"") % locals()
- execute_cmd(cmd)
+ createtable = sqlcmd % locals()
+ execute_cmd(createtable)
def test_walk_versions(self):
"""