Destroy contaniner on postgres restore step

Stopped container hasn't openrc file so it's never started successfully
after restore

Closes-bug: 1599143
Change-Id: I385c603e7d82b4146cde83c4461c0a6a4e550433
This commit is contained in:
Sergey Abramov 2016-07-05 16:34:02 +03:00
parent b5aaa8d6a7
commit 046f272ffc
2 changed files with 15 additions and 19 deletions

View File

@ -54,17 +54,15 @@ class PostgresArchivator(base.CmdArchivator):
subprocess.call([
"systemctl", "stop", "docker-{0}.service".format(self.db)
])
docker.stop_container(self.db)
docker.run_in_container(
"postgres",
["sudo", "-u", "postgres", "dropdb", "--if-exists", self.db],
)
with docker.in_container("postgres",
["sudo", "-u", "postgres", "psql"],
stdin=subprocess.PIPE) as process:
shutil.copyfileobj(dump, process.stdin)
docker.start_container(self.db)
docker.wait_for_container(self.db)
with docker.destroyed_container(self.db):
docker.run_in_container(
"postgres",
["sudo", "-u", "postgres", "dropdb", "--if-exists", self.db],
)
with docker.in_container("postgres",
["sudo", "-u", "postgres", "psql"],
stdin=subprocess.PIPE) as process:
shutil.copyfileobj(dump, process.stdin)
subprocess.call([
"systemctl", "start", "docker-{0}.service".format(self.db)
])

View File

@ -259,16 +259,14 @@ def test_postgres_restore(mocker, cls, db, sync_db_cmd, mocked_action_names):
run_in_container = mocker.patch(
"octane.util.docker.run_in_container",
side_effect=foo("run_in_container"))
mocker.patch("octane.util.docker.stop_container",
side_effect=foo("stop_container"))
mocker.patch("octane.util.docker.start_container",
side_effect=foo("start_container"))
mocker.patch("octane.util.docker.wait_for_container",
side_effect=foo("wait_for_container"))
mock_destroier = mocker.patch("octane.util.docker.destroyed_container")
mock_destroier.return_value.__enter__.side_effect = foo(
"destroy_container")
mock_destroier.return_value.__exit__.side_effect = foo("start_container")
cls(archive).restore()
member.assert_extract()
args = ["call", "stop_container", "run_in_container", "in_container",
"start_container", "wait_for_container", "call"]
args = ["call", "destroy_container", "run_in_container",
"in_container", "start_container", "call"]
assert args == actions
if cls is postgres.NailgunArchivator:
assert [