Merge branch 'fix-docker_kill_error_not_found' into 'main'

Fix docker kill error not found and pre-migration files (fix #15 #16)

Closes #16 and #15

See merge request odoo-openupgrade-wizard/odoo-openupgrade-wizard!28
This commit is contained in:
LE GAL SYLVAIN 2023-02-28 10:54:42 +00:00
commit a55b921457
2 changed files with 20 additions and 5 deletions

View File

@ -12,6 +12,9 @@ from odoo_openupgrade_wizard.tools.tools_odoo import (
kill_odoo, kill_odoo,
run_odoo, run_odoo,
) )
from odoo_openupgrade_wizard.tools.tools_postgres import (
execute_sql_files_pre_migration,
)
@click.command() @click.command()
@ -25,6 +28,7 @@ def upgrade(ctx, first_step, last_step, database):
ctx, first_step, last_step ctx, first_step, last_step
) )
for migration_step in migration_steps: for migration_step in migration_steps:
execute_sql_files_pre_migration(ctx, database, migration_step)
try: try:
run_odoo( run_odoo(
ctx, ctx,

View File

@ -114,17 +114,28 @@ def exec_container(container, command):
def kill_container(container_name): def kill_container(container_name):
client = get_docker_client() client = get_docker_client()
try:
containers = client.containers.list( containers = client.containers.list(
all=True, all=True,
filters={"name": container_name}, filters={"name": container_name},
) )
except docker.errors.NotFound as err:
logger.debug(f"Cannot kill container {container_name}: " + str(err))
containers = []
for container in containers: for container in containers:
if container.status != "exited": if container.status != "exited":
logger.debug( logger.debug(
"Stop container %s, based on image '%s'." "Stop container %s, based on image '%s'."
% (container.name, ",".join(container.image.tags)) % (container.name, ",".join(container.image.tags))
) )
try:
container.stop() container.stop()
except docker.errors.NotFound as err:
logger.debug(
f"Cannot kill container {container.name}: " + str(err)
)
# TODO, we should here filter by name # TODO, we should here filter by name
# but filters={"name": container_name} # but filters={"name": container_name}