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:
parent
6b5e2797da
commit
2f7cf160ac
|
@ -14,6 +14,8 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from copy import deepcopy
|
||||||
|
|
||||||
import netaddr
|
import netaddr
|
||||||
|
|
||||||
from sqlalchemy import func
|
from sqlalchemy import func
|
||||||
|
@ -645,7 +647,7 @@ class DumpTask(object):
|
||||||
Node.status.in_(['ready', 'provisioned', 'deploying', 'error'])
|
Node.status.in_(['ready', 'provisioned', 'deploying', 'error'])
|
||||||
).all()
|
).all()
|
||||||
|
|
||||||
dump_conf = settings.DUMP
|
dump_conf = deepcopy(settings.DUMP)
|
||||||
dump_conf['dump']['slave']['hosts'] = [
|
dump_conf['dump']['slave']['hosts'] = [
|
||||||
{
|
{
|
||||||
'address': n.fqdn,
|
'address': n.fqdn,
|
||||||
|
|
|
@ -16,6 +16,7 @@ import fnmatch
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import pprint
|
import pprint
|
||||||
|
import pwd
|
||||||
import re
|
import re
|
||||||
import stat
|
import stat
|
||||||
import tempfile
|
import tempfile
|
||||||
|
@ -226,7 +227,9 @@ class Postgres(Driver):
|
||||||
authline = "{host}:{port}:{dbname}:{username}:{password}".format(
|
authline = "{host}:{port}:{dbname}:{username}:{password}".format(
|
||||||
host=self.dbhost, port="5432", dbname=self.dbname,
|
host=self.dbhost, port="5432", dbname=self.dbname,
|
||||||
username=self.username, password=self.password)
|
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)
|
fo.seek(0)
|
||||||
auth = False
|
auth = False
|
||||||
for line in fo:
|
for line in fo:
|
||||||
|
@ -236,8 +239,7 @@ class Postgres(Driver):
|
||||||
if not auth:
|
if not auth:
|
||||||
fo.seek(0, 2)
|
fo.seek(0, 2)
|
||||||
fo.write("{0}\n".format(authline))
|
fo.write("{0}\n".format(authline))
|
||||||
os.chmod(os.path.expanduser("~/.pgpass"),
|
os.chmod(pgpass, stat.S_IRUSR + stat.S_IWUSR)
|
||||||
stat.S_IRUSR + stat.S_IWUSR)
|
|
||||||
temp = self.command("mktemp").stdout.strip()
|
temp = self.command("mktemp").stdout.strip()
|
||||||
self.command("pg_dump -h {dbhost} -U {username} -w "
|
self.command("pg_dump -h {dbhost} -U {username} -w "
|
||||||
"-f {file} {dbname}".format(
|
"-f {file} {dbname}".format(
|
||||||
|
|
Loading…
Reference in New Issue