aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRonan Amicel <ronan.amicel@gmail.com>2012-09-25 12:32:27 +0200
committerRonan Amicel <ronan.amicel@gmail.com>2012-09-25 12:32:27 +0200
commit00e10ce3c9088451f48490b42785e15e84e32e27 (patch)
treea0c63946e2a5121b309760ec31b607041eb09fcf
parentDocumentation fixes (diff)
downloadfabtools-00e10ce3c9088451f48490b42785e15e84e32e27.tar.xz
Fix #4 (for real this time?)
-rw-r--r--fabtools/postgres.py3
-rw-r--r--fabtools/tests/fabfiles/postgres.py11
2 files changed, 13 insertions, 1 deletions
diff --git a/fabtools/postgres.py b/fabtools/postgres.py
index 05f3a75..a13e64a 100644
--- a/fabtools/postgres.py
+++ b/fabtools/postgres.py
@@ -14,7 +14,8 @@ def _run_as_pg(command):
"""
Run command as 'postgres' user
"""
- return sudo(command, user='postgres', shell=False)
+ with cd('/var/lib/postgresql'):
+ return sudo('sudo -u postgres %s' % command)
def user_exists(name):
diff --git a/fabtools/tests/fabfiles/postgres.py b/fabtools/tests/fabfiles/postgres.py
index 4eaa3d0..8c834e5 100644
--- a/fabtools/tests/fabfiles/postgres.py
+++ b/fabtools/tests/fabfiles/postgres.py
@@ -12,6 +12,17 @@ def postgresql():
"""
require.postgres.server()
+ # Test low-level operations
+ assert not fabtools.postgres.user_exists('alice')
+ assert not fabtools.postgres.user_exists('bob')
+ fabtools.postgres.create_user('alice', password='1234')
+ assert fabtools.postgres.user_exists('alice')
+ assert not fabtools.postgres.user_exists('bob')
+ fabtools.postgres.create_user('bob', password='5678')
+ assert fabtools.postgres.user_exists('alice')
+ assert fabtools.postgres.user_exists('bob')
+
+ # Test high-level operations
require.postgres.user('pguser', 'foo')
assert fabtools.postgres.user_exists('pguser')