Fix problem with pq dump restore

Copy data to psql stdin using shutil.copyfileobj

Change-Id: Ia77d45d01ee9c3d11049c003e7640c086a8da20f
Closes-bug: 1570371
This commit is contained in:
Sergey Abramov 2016-04-15 15:40:48 +03:00
parent 3c710fc182
commit 95db28139c
2 changed files with 10 additions and 3 deletions

View File

@ -14,6 +14,7 @@ import json
import logging
import os
import requests
import shutil
import six
import urlparse
import yaml
@ -60,7 +61,7 @@ class PostgresArchivator(base.CmdArchivator):
with docker.in_container("postgres",
["sudo", "-u", "postgres", "psql"],
stdin=subprocess.PIPE) as process:
process.stdin.write(dump.read())
shutil.copyfileobj(dump, process.stdin)
docker.start_container(self.db)
docker.wait_for_container(self.db)
subprocess.call([

View File

@ -39,6 +39,7 @@ class TestMember(object):
self.path = ''
self.is_extracted = False
self.dump = ""
self.read_idx = 0
def isfile(self):
return self.is_file
@ -48,8 +49,13 @@ class TestMember(object):
if self.is_extracted and path:
assert os.path.join(path, "/") == os.path.join(self.path, "/")
def read(self):
return self.dump
def read(self, chunk_size=None):
current_idx = self.read_idx
if chunk_size:
self.read_idx += chunk_size
else:
self.read_idx = len(self.dump)
return self.dump[current_idx: self.read_idx]
class TestArchive(object):