Fix problem with pq dump restore
Copy data to psql stdin using shutil.copyfileobj
Change-Id: Ia77d45d01ee9c3d11049c003e7640c086a8da20f
Closes-bug: 1570371
(cherry picked from commit 95db28139c
)
This commit is contained in:
parent
432fb878c4
commit
2a8516d8c7
|
@ -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([
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue