summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBoris Pavlovic <boris@pavlovic.me>2012-11-30 15:15:30 +0400
committerBoris Pavlovic <boris@pavlovic.me>2012-11-30 16:47:52 +0400
commitce79e4ce66eac284ce29941744fb09e316b899db (patch)
treecb59832965437178dd8ceee57b7490dae02a753f
parent37df2052d7b9666c72478de79b46a60b15c9f4fd (diff)
downloadnova-ce79e4ce66eac284ce29941744fb09e316b899db.tar.gz
nova-ce79e4ce66eac284ce29941744fb09e316b899db.tar.xz
nova-ce79e4ce66eac284ce29941744fb09e316b899db.zip
Fix test_migrations for postgres
Fix creating .pgpass file that is used to connect to postgress database without password prompt. Fix command that execute SQL in postgres DB: a) there were no spaces between command options and values b) we can't drop database while we are connected to it. There is a special database `template1` in postgres for dropping databases. c) using `'` instead of `"` in bash to quote SQL expressions because bash interprets only text in single quotes as plain string. Remove SQL requests which lock database Fix stripping password, so it works not only when password contains only spaces. Change-Id: I753a044aba8579b0f4225b4e67163d046ec1a32e
-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):
"""