[IMP] add --database option ; [CI] try to fix ci, adding a postgresql container

This commit is contained in:
Sylvain LE GAL 2022-04-11 13:22:29 +02:00
parent 11a59249b3
commit 5776ff5893
4 changed files with 35 additions and 18 deletions

View File

@ -36,4 +36,8 @@ pytest:
- echo $PATH - echo $PATH
- echo $PYTHONPATH - echo $PYTHONPATH
- poetry run pytest --version - poetry run pytest --version
- # Create a postgresql container
- docker run -v odoo-data:/var/lib/odoo -d -p 8069:8069 --name odoo --link db:db -t odoo
- poetry run pytest --cov odoo_openupgrade_wizard -v - poetry run pytest --cov odoo_openupgrade_wizard -v

View File

@ -11,6 +11,26 @@ def releases_options(function):
return function return function
def step_option(function):
function = click.option(
"--step",
required=True,
prompt=True,
type=str,
help="Migration step for which you want to perform the operation.",
)(function)
return function
def database_option(function):
function = click.option(
"--database",
type=str,
help="Odoo Database for which you want to perform the operation.",
)(function)
return function
def get_odoo_versions_from_options(ctx, releases_arg): def get_odoo_versions_from_options(ctx, releases_arg):
if not releases_arg: if not releases_arg:
@ -24,17 +44,6 @@ def get_odoo_versions_from_options(ctx, releases_arg):
return odoo_versions return odoo_versions
def step_options(function):
function = click.option(
"--step",
required=True,
prompt=True,
type=str,
help="Migration step for which you want to perform the operation.",
)(function)
return function
def get_migration_step_from_options(ctx, step_arg): def get_migration_step_from_options(ctx, step_arg):
step = float(step_arg) step = float(step_arg)
for migration_step in ctx.obj["config"]["migration_steps"]: for migration_step in ctx.obj["config"]["migration_steps"]:

View File

@ -4,14 +4,16 @@ import click
from loguru import logger from loguru import logger
from odoo_openupgrade_wizard.cli_options import ( from odoo_openupgrade_wizard.cli_options import (
database_option,
get_migration_step_from_options, get_migration_step_from_options,
step_options, step_option,
) )
from odoo_openupgrade_wizard.tools_odoo import kill_odoo, run_odoo from odoo_openupgrade_wizard.tools_odoo import kill_odoo, run_odoo
@click.command() @click.command()
@step_options @step_option
@database_option
@click.option( @click.option(
"--duration", "--duration",
type=float, type=float,
@ -21,11 +23,11 @@ from odoo_openupgrade_wizard.tools_odoo import kill_odoo, run_odoo
" function to stop.", " function to stop.",
) )
@click.pass_context @click.pass_context
def run(ctx, step, duration): def run(ctx, step, database, duration):
migration_step = get_migration_step_from_options(ctx, step) migration_step = get_migration_step_from_options(ctx, step)
try: try:
run_odoo(ctx, migration_step) run_odoo(ctx, migration_step, database=database)
if duration: if duration:
sleep(duration) sleep(duration)
else: else:

View File

@ -36,12 +36,13 @@ def get_odoo_version_from_migration_step(ctx, migration_step: dict) -> dict:
def generate_odoo_command( def generate_odoo_command(
ctx, migration_step: dict, update_all: bool = False ctx, migration_step: dict, database: str = False, update_all: bool = False
) -> str: ) -> str:
# TODO, make it dynamic # TODO, make it dynamic
addons_path = ( addons_path = (
"/container_env/src/odoo/addons," "/container_env/src/odoo/odoo/addons" "/container_env/src/odoo/addons," "/container_env/src/odoo/odoo/addons"
) )
database_cmd = database and "--database %s" % database or ""
update_all_cmd = update_all and "--update_all" or "" update_all_cmd = update_all and "--update_all" or ""
return ( return (
f"/container_env/src/odoo/odoo-bin" f"/container_env/src/odoo/odoo-bin"
@ -50,16 +51,17 @@ def generate_odoo_command(
f" --db_user odoo" f" --db_user odoo"
f" --db_password odoo" f" --db_password odoo"
f" --addons-path {addons_path}" f" --addons-path {addons_path}"
f" {database_cmd}"
f" {update_all_cmd}" f" {update_all_cmd}"
) )
def run_odoo(ctx, migration_step: dict): def run_odoo(ctx, migration_step: dict, database: str = False):
client = docker.from_env() client = docker.from_env()
odoo_version = get_odoo_version_from_migration_step(ctx, migration_step) odoo_version = get_odoo_version_from_migration_step(ctx, migration_step)
folder_path = get_odoo_env_path(ctx, odoo_version) folder_path = get_odoo_env_path(ctx, odoo_version)
command = generate_odoo_command(ctx, migration_step) command = generate_odoo_command(ctx, migration_step, database=database)
image_name = get_docker_image_tag(ctx, odoo_version) image_name = get_docker_image_tag(ctx, odoo_version)
container_name = get_docker_container_name(ctx, migration_step) container_name = get_docker_container_name(ctx, migration_step)