Shotgun PostgreSQL dump generation fixed

Multiply writing dump_config into settings fixed.
Path to .pgpass file fixed. Information from pwd used instead
value of environment variable HOME

Change-Id: Ib701a57fb6386d02cc93eb3d9f588f7abb1aac9f
Closes-Bug: #1317018
This commit is contained in:
Alexander Kislitsky 2014-05-07 18:18:54 +04:00
parent 6b5e2797da
commit 2f7cf160ac
2 changed files with 8 additions and 4 deletions

View File

@ -14,6 +14,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from copy import deepcopy
import netaddr
from sqlalchemy import func
@ -645,7 +647,7 @@ class DumpTask(object):
Node.status.in_(['ready', 'provisioned', 'deploying', 'error'])
).all()
dump_conf = settings.DUMP
dump_conf = deepcopy(settings.DUMP)
dump_conf['dump']['slave']['hosts'] = [
{
'address': n.fqdn,

View File

@ -16,6 +16,7 @@ import fnmatch
import logging
import os
import pprint
import pwd
import re
import stat
import tempfile
@ -226,7 +227,9 @@ class Postgres(Driver):
authline = "{host}:{port}:{dbname}:{username}:{password}".format(
host=self.dbhost, port="5432", dbname=self.dbname,
username=self.username, password=self.password)
with open(os.path.expanduser("~/.pgpass"), "a+") as fo:
home_dir = pwd.getpwuid(os.getuid()).pw_dir
pgpass = os.path.join(home_dir, ".pgpass")
with open(pgpass, "a+") as fo:
fo.seek(0)
auth = False
for line in fo:
@ -236,8 +239,7 @@ class Postgres(Driver):
if not auth:
fo.seek(0, 2)
fo.write("{0}\n".format(authline))
os.chmod(os.path.expanduser("~/.pgpass"),
stat.S_IRUSR + stat.S_IWUSR)
os.chmod(pgpass, stat.S_IRUSR + stat.S_IWUSR)
temp = self.command("mktemp").stdout.strip()
self.command("pg_dump -h {dbhost} -U {username} -w "
"-f {file} {dbname}".format(