diff --git a/DEVELOP.md b/DEVELOP.md index e688d54..1501f57 100644 --- a/DEVELOP.md +++ b/DEVELOP.md @@ -10,7 +10,6 @@ to contribute to that project. * poetry (https://python-poetry.org/) * odoorpc (https://github.com/OCA/odoorpc) * git-aggregator (https://github.com/acsone/git-aggregator) -* click-odoo (https://github.com/acsone/click-odoo) # Extra Developper Requirements diff --git a/INTERNAL_NOTES.md b/INTERNAL_NOTES.md index 68339d3..9a84987 100644 --- a/INTERNAL_NOTES.md +++ b/INTERNAL_NOTES.md @@ -50,3 +50,8 @@ in modules.csv.j2 : # TODO, this value are usefull for test for analyse between 13 and 14. # move that values in data/extra_script/modules.csv # and let this template with only 'base' module. + + + +TODO when launching container : +- install odoo : ``pip install -e /odoo/src/odoo`` diff --git a/README.md b/README.md index 7af2b23..b66ecb6 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ It works with Openupgrade OCA tools. (https://github.com/oca/openupgrade) this tool is useful for complex migrations: - migrate several versions - take advantage of the migration to install / uninstall modules -- execute sql requests or click-odoo scripts between each migration +- execute sql requests or odoo shell scripts between each migration - analyse workload It will create a migration environment (with all the code available) @@ -113,7 +113,7 @@ modules.csv before beginning the step. - ``post-migration.py`` can contains extra python command to execute after the execution of the step. - Script will be executed with ``click-odoo`` command. All the ORM is available + Script will be executed with ``odoo shell`` command. All the ORM is available via the ``env`` variable. * ``src`` folder contains a folder per Odoo version. In each environment folder: diff --git a/odoo_openupgrade_wizard/cli/cli.py b/odoo_openupgrade_wizard/cli/cli.py index 1bfbb1a..b3cf4dd 100644 --- a/odoo_openupgrade_wizard/cli/cli.py +++ b/odoo_openupgrade_wizard/cli/cli.py @@ -68,10 +68,6 @@ def main(ctx, env_folder, filestore_folder, log_level): # Define all the folder required by the tools env_folder_path = Path(env_folder) src_folder_path = env_folder_path / Path("./src/") - # Note: postgres folder should be a subfolder, because - # the parent folder will contain a .gitignore file - # that the postgres docker image doesn't like - postgres_folder_path = env_folder_path / Path("./postgres_data/data") script_folder_path = env_folder_path / Path("./scripts/") log_folder_path = env_folder_path / Path("./log/") if not filestore_folder: @@ -80,7 +76,7 @@ def main(ctx, env_folder, filestore_folder, log_level): filestore_folder_path = Path(filestore_folder) # ensure log folder exists - ensure_folder_exists(log_folder_path, mode="777", git_ignore_content=True) + ensure_folder_exists(log_folder_path, git_ignore_content=True) # Create log file log_prefix = "{}__{}".format( @@ -95,7 +91,6 @@ def main(ctx, env_folder, filestore_folder, log_level): # Add all global values in the context ctx.obj["env_folder_path"] = env_folder_path ctx.obj["src_folder_path"] = src_folder_path - ctx.obj["postgres_folder_path"] = postgres_folder_path ctx.obj["script_folder_path"] = script_folder_path ctx.obj["log_folder_path"] = log_folder_path ctx.obj["log_prefix"] = log_prefix diff --git a/odoo_openupgrade_wizard/cli/cli_docker_build.py b/odoo_openupgrade_wizard/cli/cli_docker_build.py index 1008216..611b4bb 100644 --- a/odoo_openupgrade_wizard/cli/cli_docker_build.py +++ b/odoo_openupgrade_wizard/cli/cli_docker_build.py @@ -10,13 +10,14 @@ from odoo_openupgrade_wizard.tools.tools_odoo import ( get_docker_image_tag, get_odoo_env_path, ) +from odoo_openupgrade_wizard.tools.tools_system import get_local_user_id @click.command() @versions_options @click.pass_context def docker_build(ctx, versions): - """Build Odoo Docker Images. (One image per version)""" + """Build Odoo Docker Images and pull Postgres image""" # Pull DB image pull_image(ctx.obj["config"]["postgres_image_name"]) @@ -30,5 +31,6 @@ def docker_build(ctx, versions): image = build_image( get_odoo_env_path(ctx, odoo_version), get_docker_image_tag(ctx, odoo_version), + {"LOCAL_USER_ID": str(get_local_user_id())}, ) logger.info("Docker Image build. '%s'" % image[0].tags[0]) diff --git a/odoo_openupgrade_wizard/cli/cli_init.py b/odoo_openupgrade_wizard/cli/cli_init.py index 24f6ac4..7884ecf 100644 --- a/odoo_openupgrade_wizard/cli/cli_init.py +++ b/odoo_openupgrade_wizard/cli/cli_init.py @@ -4,8 +4,6 @@ import click from odoo_openupgrade_wizard.configuration_version_dependant import ( get_odoo_versions, - get_python_libraries, - get_python_major_version, get_version_options, ) from odoo_openupgrade_wizard.tools.tools_odoo import get_odoo_env_path @@ -49,7 +47,7 @@ from odoo_openupgrade_wizard.tools.tools_system import ( def init( ctx, project_name, initial_version, final_version, extra_repository_list ): - """Initialize OpenUpgrade Wizard Environment based on the initial and + """Initialize OOW Environment based on the initial and the final version of Odoo you want to migrate. """ @@ -69,19 +67,18 @@ def init( float(initial_version), float(final_version) ) - # 2. Compute Migration Steps + # Compute Migration Steps - # Create initial first step + # Create initial Regular step steps = [ { "name": 1, "execution_context": "regular", "version": odoo_versions[0], - "complete_name": "step_01__update__%s" % (odoo_versions[0]), + "complete_name": "step_01__regular__%s" % (odoo_versions[0]), } ] - - # Add all upgrade steps + # Add all Openupgrade steps step_nbr = 2 for odoo_version in odoo_versions[1:]: steps.append( @@ -89,44 +86,33 @@ def init( "name": step_nbr, "execution_context": "openupgrade", "version": odoo_version, - "complete_name": "step_%s__upgrade__%s" + "complete_name": "step_%s__openupgrade__%s" % (str(step_nbr).rjust(2, "0"), odoo_version), } ) step_nbr += 1 - # add final update step + # add final Regular step if len(odoo_versions) > 1: steps.append( { "name": step_nbr, "execution_context": "regular", "version": odoo_versions[-1], - "complete_name": "step_%s__update__%s" + "complete_name": "step_%s__regular__%s" % (str(step_nbr).rjust(2, "0"), odoo_versions[-1]), } ) - # 3. ensure src folder exists + # Ensure src folder exists ensure_folder_exists(ctx.obj["src_folder_path"]) - # 4. ensure filestore folder exists + # Ensure filestore folder exists ensure_folder_exists( - ctx.obj["filestore_folder_path"], mode="777", git_ignore_content=True + ctx.obj["filestore_folder_path"], git_ignore_content=True ) - # 5. ensure postgres data folder exists - ensure_folder_exists( - ctx.obj["postgres_folder_path"].parent, - mode="777", - git_ignore_content=True, - ) - ensure_folder_exists( - ctx.obj["postgres_folder_path"], - mode="777", - ) - - # 6. ensure main configuration file exists + # Znsure main configuration file exists ensure_file_exists_from_template( ctx.obj["config_file_path"], "config.yml.j2", @@ -135,7 +121,7 @@ def init( odoo_versions=odoo_versions, ) - # 7. Ensure module list file exists + # Ensure module list file exists ensure_file_exists_from_template( ctx.obj["module_file_path"], "modules.csv.j2", @@ -144,7 +130,7 @@ def init( odoo_versions=odoo_versions, ) - # 8. Create one folder per version and add files + # Create one folder per version and add files for odoo_version in odoo_versions: # Create main path for each version path_version = get_odoo_env_path(ctx, odoo_version) @@ -152,15 +138,14 @@ def init( # Create python requirements file ensure_file_exists_from_template( - path_version / Path("python_requirements.txt"), - "odoo/python_requirements.txt.j2", - python_libraries=get_python_libraries(odoo_version), + path_version / Path("extra_python_requirements.txt"), + "odoo/extra_python_requirements.txt.j2", ) # Create debian requirements file ensure_file_exists_from_template( - path_version / Path("debian_requirements.txt"), - "odoo/debian_requirements.txt.j2", + path_version / Path("extra_debian_requirements.txt"), + "odoo/extra_debian_requirements.txt.j2", ) # Create odoo config file @@ -180,9 +165,7 @@ def init( # Create Dockerfile file ensure_file_exists_from_template( path_version / Path("Dockerfile"), - "odoo/Dockerfile.j2", - odoo_version=odoo_version, - python_major_version=get_python_major_version(odoo_version), + f"odoo/{odoo_version}/Dockerfile", ) # Create 'src' folder that will contain all the odoo code @@ -190,7 +173,7 @@ def init( path_version / Path("src"), git_ignore_content=True ) - # 9. Create one folder per step and add files + # Create one folder per step and add files ensure_folder_exists(ctx.obj["script_folder_path"]) for step in steps: diff --git a/odoo_openupgrade_wizard/configuration_version_dependant.py b/odoo_openupgrade_wizard/configuration_version_dependant.py index d135b89..49ff271 100644 --- a/odoo_openupgrade_wizard/configuration_version_dependant.py +++ b/odoo_openupgrade_wizard/configuration_version_dependant.py @@ -5,72 +5,31 @@ from loguru import logger _ODOO_VERSION_TEMPLATES = [ { "version": 8.0, - "python_major_version": "python2", - "python_libraries": [], }, { "version": 9.0, - "python_major_version": "python2", - "python_libraries": ["openupgradelib==2.0.0"], }, { "version": 10.0, - "python_major_version": "python2", - "python_libraries": ["openupgradelib==2.0.0"], }, { "version": 11.0, - "python_major_version": "python3", - "python_libraries": ["openupgradelib==2.0.0"], }, { "version": 12.0, - "python_major_version": "python3", - "python_libraries": [ - "git+https://github.com/grap/openupgradelib.git" - "@2.0.1#egg=openupgradelib" - ], }, { "version": 13.0, - "python_major_version": "python3", - "python_libraries": ["openupgradelib"], }, { "version": 14.0, - "python_major_version": "python3", - "python_libraries": ["openupgradelib"], }, { "version": 15.0, - "python_major_version": "python3", - "python_libraries": ["openupgradelib"], }, ] -def get_version_template(version: float) -> dict: - """return a version template dictionnary according to a version - provided""" - for version_template in _ODOO_VERSION_TEMPLATES: - if version_template["version"] == version: - return version_template - else: - raise ValueError - - -def get_python_libraries(version: float) -> list: - """Return a list of python librairies that should be - installed in each docker container for a given version""" - return get_version_template(version)["python_libraries"] - - -def get_python_major_version(version: float) -> str: - """Return the major python version (2.0, 3.0) of Odoo for - a given version""" - return get_version_template(version)["python_major_version"] - - def get_version_options(mode: str) -> list: """Get options available for version click argument. Arguments: @@ -151,11 +110,14 @@ def skip_addon_path(migration_step: dict, path: Path) -> bool: ) and migration_step["version"] < 14.0 -def get_server_wide_modules_upgrade(migration_step: dict) -> list: +def get_server_wide_modules_upgrade( + migration_step: dict, execution_context: str = False +) -> list: """return a list of modules to load, depending on the migration step.""" if ( migration_step["version"] >= 14.0 and migration_step["execution_context"] == "openupgrade" + and execution_context != "regular" ): return ["openupgrade_framework"] return [] diff --git a/odoo_openupgrade_wizard/templates/config.yml.j2 b/odoo_openupgrade_wizard/templates/config.yml.j2 index a3ba7ba..611c5c3 100644 --- a/odoo_openupgrade_wizard/templates/config.yml.j2 +++ b/odoo_openupgrade_wizard/templates/config.yml.j2 @@ -1,7 +1,8 @@ project_name: {{ project_name }} postgres_image_name: postgres:13 -postgres_container_name: {{project_name}}-db +postgres_container_name: {{project_name}}-container-postgres +postgres_volume_name: {{project_name}}-volume-postgres odoo_host_xmlrpc_port: 9069 odoo_default_country_code: FR @@ -12,6 +13,14 @@ odoo_versions: - {{ odoo_version }} {%- endfor %} + +odoo_version_settings: +{%- for odoo_version in odoo_versions %} + {{odoo_version}}: + repo_url: False +{%- endfor %} + + migration_steps: {%- for step in steps %} - name: {{ step['name'] }} diff --git a/odoo_openupgrade_wizard/templates/odoo/12.0/Dockerfile b/odoo_openupgrade_wizard/templates/odoo/12.0/Dockerfile new file mode 100644 index 0000000..09bbdcb --- /dev/null +++ b/odoo_openupgrade_wizard/templates/odoo/12.0/Dockerfile @@ -0,0 +1,74 @@ +# : Copy of https://github.com/odoo/odoo/blob/12.0/setup/package.dfdebian + +FROM debian:stretch + +# 1. Official Odoo Dockerfile. +# Removing: postgresql, locales, rsync + +ENV DEBIAN_FRONTEND noninteractive + +RUN apt-get update -qq && \ + apt-get upgrade -qq -y && \ + apt-get install -yq \ + adduser \ + dh-python \ + packaging-dev \ + postgresql-client \ + python3 \ + python3-babel \ + python3-dateutil \ + python3-decorator \ + python3-docutils \ + python3-gevent \ + python3-html2text \ + python3-pil \ + python3-jinja2 \ + python3-libsass \ + python3-lxml \ + python3-mako \ + python3-mock \ + python3-ofxparse \ + python3-passlib \ + python3-psutil \ + python3-psycopg2 \ + python3-pydot \ + python3-pyparsing \ + python3-pypdf2 \ + python3-reportlab \ + python3-requests \ + python3-serial \ + python3-suds \ + python3-tz \ + python3-usb \ + python3-vatnumber \ + python3-vobject \ + python3-werkzeug \ + python3-xlsxwriter \ + && rm -rf /var/lib/apt/lists/* + +# 2. Add 2 python dependency files and 1 debian dependency file + +COPY ./src/odoo/requirements.txt /odoo_python_requirements.txt +COPY extra_python_requirements.txt /extra_python_requirements.txt +COPY extra_debian_requirements.txt /extra_debian_requirements.txt + +# 3. Install Debian packages +RUN apt-get update || true \ + && apt-get install -y\ + # To allow to run pip install + python3-pip\ + # For python-ldap + libldap2-dev ldap-utils libsasl2-dev\ + && xargs apt-get install -y --no-install-recommends Install Python librairies +RUN python3 -m pip install --no-cache-dir -r /odoo_python_requirements.txt +RUN python3 -m pip install --no-cache-dir -r /extra_python_requirements.txt + +# 5. Get local user id and set it to the odoo user +ARG LOCAL_USER_ID + +RUN useradd --uid $LOCAL_USER_ID odoo + +USER odoo diff --git a/odoo_openupgrade_wizard/templates/odoo/13.0/Dockerfile b/odoo_openupgrade_wizard/templates/odoo/13.0/Dockerfile new file mode 100644 index 0000000..506ca1b --- /dev/null +++ b/odoo_openupgrade_wizard/templates/odoo/13.0/Dockerfile @@ -0,0 +1,78 @@ +# : Copy of https://github.com/odoo/odoo/blob/13.0/setup/package.dfdebian + +FROM debian:buster + +# 1. Official Odoo Dockerfile. +# Removing: postgresql, locales, rsync + +ENV DEBIAN_FRONTEND noninteractive + +RUN apt-get update -qq && \ + apt-get upgrade -qq -y && \ + apt-get install -qq -y\ + adduser \ + dh-python \ + packaging-dev \ + postgresql-client \ + python3 \ + python3-babel \ + python3-dateutil \ + python3-decorator \ + python3-docutils \ + python3-gevent \ + python3-pil \ + python3-jinja2 \ + python3-libsass \ + python3-lxml \ + python3-mako \ + python3-mock \ + python3-ofxparse \ + python3-passlib \ + python3-polib \ + python3-psutil \ + python3-psycopg2 \ + python3-pydot \ + python3-pyparsing \ + python3-pypdf2 \ + python3-qrcode \ + python3-renderpm \ + python3-reportlab \ + python3-requests \ + python3-serial \ + python3-tz \ + python3-usb \ + python3-vatnumber \ + python3-vobject \ + python3-werkzeug \ + python3-xlsxwriter \ + python3-zeep \ + && rm -rf /var/lib/apt/lists/* + +# 2. Add 2 python dependency files and 1 debian dependency file + +COPY ./src/odoo/requirements.txt /odoo_python_requirements.txt +COPY extra_python_requirements.txt /extra_python_requirements.txt +COPY extra_debian_requirements.txt /extra_debian_requirements.txt + +# 3. Install Debian packages +RUN apt-get update || true \ + && apt-get install -y\ + # To allow to run pip install + python3-pip\ + # For python-ldap + libldap2-dev ldap-utils libsasl2-dev\ + # For cffi + build-essential libssl-dev libffi-dev python-dev\ + && xargs apt-get install -y --no-install-recommends Install Python librairies +RUN python3 -m pip install --no-cache-dir -r /odoo_python_requirements.txt +RUN python3 -m pip install --no-cache-dir -r /extra_python_requirements.txt + +# 5. Get local user id and set it to the odoo user +ARG LOCAL_USER_ID + +RUN useradd --uid $LOCAL_USER_ID odoo + +USER odoo diff --git a/odoo_openupgrade_wizard/templates/odoo/14.0/Dockerfile b/odoo_openupgrade_wizard/templates/odoo/14.0/Dockerfile new file mode 100644 index 0000000..c5729d2 --- /dev/null +++ b/odoo_openupgrade_wizard/templates/odoo/14.0/Dockerfile @@ -0,0 +1,77 @@ +# : Copy of https://github.com/odoo/odoo/blob/14.0/setup/package.dfdebian + +FROM debian:buster + +# 1. Official Odoo Dockerfile. +# Removing: postgresql, locales, rsync + +ENV DEBIAN_FRONTEND noninteractive + +RUN apt-get update -qq && \ + apt-get upgrade -qq -y && \ + apt-get install -qq -y\ + adduser \ + dh-python \ + packaging-dev \ + postgresql-client \ + python3 \ + python3-babel \ + python3-dateutil \ + python3-decorator \ + python3-docutils \ + python3-gevent \ + python3-pil \ + python3-jinja2 \ + python3-libsass \ + python3-lxml \ + python3-mako \ + python3-ofxparse \ + python3-passlib \ + python3-polib \ + python3-psutil \ + python3-psycopg2 \ + python3-pydot \ + python3-pypdf2 \ + python3-qrcode \ + python3-renderpm \ + python3-reportlab \ + python3-requests \ + python3-serial \ + python3-setuptools \ + python3-stdnum \ + python3-tz \ + python3-usb \ + python3-vobject \ + python3-werkzeug \ + python3-xlsxwriter \ + python3-zeep \ + && rm -rf /var/lib/apt/lists/* + +# 2. Add 2 python dependency files and 1 debian dependency file + +COPY ./src/odoo/requirements.txt /odoo_python_requirements.txt +COPY extra_python_requirements.txt /extra_python_requirements.txt +COPY extra_debian_requirements.txt /extra_debian_requirements.txt + +# 3. Install Debian packages +RUN apt-get update || true \ + && apt-get install -y\ + # To allow to run pip install + python3-pip\ + # For python-ldap + libldap2-dev ldap-utils libsasl2-dev\ + # For cffi + build-essential libssl-dev libffi-dev python-dev\ + && xargs apt-get install -y --no-install-recommends Install Python librairies +RUN python3 -m pip install --no-cache-dir -r /odoo_python_requirements.txt +RUN python3 -m pip install --no-cache-dir -r /extra_python_requirements.txt + +# 5. Get local user id and set it to the odoo user +ARG LOCAL_USER_ID + +RUN useradd --uid $LOCAL_USER_ID odoo + +USER odoo diff --git a/odoo_openupgrade_wizard/templates/odoo/15.0/Dockerfile b/odoo_openupgrade_wizard/templates/odoo/15.0/Dockerfile new file mode 100644 index 0000000..879024b --- /dev/null +++ b/odoo_openupgrade_wizard/templates/odoo/15.0/Dockerfile @@ -0,0 +1,75 @@ +# : Copy of https://github.com/odoo/odoo/blob/15.0/setup/package.dfdebian + +FROM debian:bullseye + +# 1. Official Odoo Dockerfile. +# Removing: postgresql, locales, rsync + +ENV DEBIAN_FRONTEND noninteractive + +RUN apt-get update -qq && \ + apt-get upgrade -qq -y && \ + apt-get install -qq -y\ + adduser \ + dh-python \ + packaging-dev \ + postgresql-client \ + python3 \ + python3-babel \ + python3-dateutil \ + python3-decorator \ + python3-docutils \ + python3-gevent \ + python3-pil \ + python3-jinja2 \ + python3-libsass \ + python3-lxml \ + python3-ofxparse \ + python3-passlib \ + python3-polib \ + python3-psutil \ + python3-psycopg2 \ + python3-pydot \ + python3-openssl \ + python3-pypdf2 \ + python3-qrcode \ + python3-renderpm \ + python3-reportlab \ + python3-requests \ + python3-serial \ + python3-setuptools \ + python3-stdnum \ + python3-tz \ + python3-usb \ + python3-vobject \ + python3-werkzeug \ + python3-xlsxwriter \ + python3-zeep \ + && rm -rf /var/lib/apt/lists/* + +# 2. Add 2 python dependency files and 1 debian dependency file + +COPY ./src/odoo/requirements.txt /odoo_python_requirements.txt +COPY extra_python_requirements.txt /extra_python_requirements.txt +COPY extra_debian_requirements.txt /extra_debian_requirements.txt + +# 3. Install Debian packages +RUN apt-get update || true \ + && apt-get install -y\ + # To allow to run pip install + python3-pip\ + # For python-ldap + libldap2-dev ldap-utils libsasl2-dev\ + && xargs apt-get install -y --no-install-recommends Install Python librairies +RUN python3 -m pip install --no-cache-dir -r /odoo_python_requirements.txt +RUN python3 -m pip install --no-cache-dir -r /extra_python_requirements.txt + +# 5. Get local user id and set it to the odoo user +ARG LOCAL_USER_ID + +RUN useradd --uid $LOCAL_USER_ID odoo + +USER odoo diff --git a/odoo_openupgrade_wizard/templates/odoo/Dockerfile.j2 b/odoo_openupgrade_wizard/templates/odoo/Dockerfile.j2 deleted file mode 100644 index a2d32e4..0000000 --- a/odoo_openupgrade_wizard/templates/odoo/Dockerfile.j2 +++ /dev/null @@ -1,22 +0,0 @@ -FROM odoo:{{ odoo_version }} -MAINTAINER GRAP, Coop It Easy - -# Set User root for installations -USER root - -# 1. Make available files in the containers - -COPY debian_requirements.txt /debian_requirements.txt - -COPY python_requirements.txt /python_requirements.txt - -# 2. Install extra debian packages -RUN apt-get update || true &&\ - xargs apt-get install -y --no-install-recommends str: + + odoo_env_path = get_odoo_env_path(ctx, migration_step["version"]) + + # Compute 'server_wide_modules' + # For that purpose, read the custom odoo.cfg file + # to know if server_wide_modules is defined + custom_odoo_config_file = odoo_env_path / "odoo.cfg" + parser = configparser.RawConfigParser() + parser.read(custom_odoo_config_file) + server_wide_modules = parser.get( + "options", "server_wide_modules", fallback=[] + ) + server_wide_modules += get_server_wide_modules_upgrade( + migration_step, execution_context + ) + + # compute 'addons_path' + addons_path = ",".join( + [ + str(x) + for x in get_odoo_addons_path( + ctx, Path("/odoo_env"), migration_step, execution_context + ) + ] + ) + + # compute 'log_file' + log_file_name = "{}____{}.log".format( + ctx.obj["log_prefix"], migration_step["complete_name"] + ) + log_file_docker_path = "/env/log/%s" % log_file_name + database_cmd = database and "--database %s" % database or "" + load_cmd = ( + server_wide_modules + and "--load %s" % ",".join(server_wide_modules) + or "" + ) update_cmd = update and "--update %s" % update or "" init_cmd = init and "--init %s" % init or "" stop_after_init_cmd = stop_after_init and "--stop-after-init" or "" @@ -98,11 +136,21 @@ def generate_odoo_command( / Path(get_odoo_folder(migration_step, execution_context)) / Path(get_odoo_run_command(migration_step)) ) + result = ( f" {command}" f" {shell_cmd}" - f" --config /odoo_env/_auto_generated_odoo.cfg" + # f" --config=/etc/odoo.cfg" + f" --data-dir=/env/filestore/" + f" --addons-path={addons_path}" + f" --logfile={log_file_docker_path}" + f" --db_host=db" + f" --db_port=5432" + f" --db_user=odoo" + f" --db_password=odoo" + f" --workers=0" f" {demo_cmd}" + f" {load_cmd}" f" {database_cmd}" f" {update_cmd}" f" {init_cmd}" @@ -111,60 +159,6 @@ def generate_odoo_command( return result -def generate_odoo_config_file( - ctx, migration_step, log_file, execution_context -): - """Create a config file name _auto_generated_odoo.cfg - in the according environment (defined by migration_step) - This configuration file is a merge of the odoo.cfg file that can - contain custom values, and the values required to run the docker container. - """ - odoo_env_path = get_odoo_env_path(ctx, migration_step["version"]) - - custom_odoo_config_file = odoo_env_path / "odoo.cfg" - auto_generated_odoo_config_file = ( - odoo_env_path / "_auto_generated_odoo.cfg" - ) - - parser = configparser.RawConfigParser() - # Read custom file - parser.read(custom_odoo_config_file) - - # compute addons_path - addons_path = ",".join( - [ - str(x) - for x in get_odoo_addons_path( - ctx, Path("/odoo_env"), migration_step, execution_context - ) - ] - ) - - # compute server wides modules - server_wide_modules = parser.get( - "options", "server_wide_modules", fallback=[] - ) - server_wide_modules += get_server_wide_modules_upgrade(migration_step) - - # Add required keys - if "options" not in parser: - parser.add_section("options") - parser.set("options", "db_host", "db") - parser.set("options", "db_port", 5432) - parser.set("options", "db_user", "odoo") - parser.set("options", "db_password", "odoo") - parser.set("options", "workers", 0) - parser.set("options", "data_dir", "/env/filestore/") - parser.set("options", "logfile", log_file) - parser.set("options", "addons_path", addons_path) - if server_wide_modules: - parser.set( - "options", "server_wide_modules", ",".join(server_wide_modules) - ) - - parser.write(open(auto_generated_odoo_config_file, "w")) - - def run_odoo( ctx, migration_step: dict, @@ -195,31 +189,53 @@ def run_odoo( update_text=update and " (Update : %s)" % update or "", ) ) - env_path = ctx.obj["env_folder_path"] - odoo_env_path = get_odoo_env_path(ctx, migration_step["version"]) - log_file = "/env/log/{}____{}.log".format( - ctx.obj["log_prefix"], migration_step["complete_name"] - ) - generate_odoo_config_file(ctx, migration_step, log_file, execution_context) command = generate_odoo_command( ctx, migration_step, execution_context, - database=database, + database, + demo=demo, update=update, init=init, stop_after_init=stop_after_init, shell=shell, - demo=demo, ) + return run_container_odoo( + ctx, + migration_step, + command, + detached_container=detached_container, + database=database, + execution_context=execution_context, + alternative_xml_rpc_port=alternative_xml_rpc_port, + links=links, + ) + + +def run_container_odoo( + ctx, + migration_step: dict, + command: str, + detached_container: bool = False, + database: str = False, + alternative_xml_rpc_port: int = False, + execution_context: str = False, + links: dict = {}, +): + env_path = ctx.obj["env_folder_path"] + odoo_env_path = get_odoo_env_path(ctx, migration_step["version"]) + host_xmlrpc_port = ( alternative_xml_rpc_port and alternative_xml_rpc_port or ctx.obj["config"]["odoo_host_xmlrpc_port"] ) + links.update({ctx.obj["config"]["postgres_container_name"]: "db"}) + + # try: return run_container( get_docker_image_tag(ctx, migration_step["version"]), get_docker_container_name(ctx, migration_step), @@ -235,6 +251,18 @@ def run_odoo( detach=detached_container, auto_remove=True, ) + # except docker.errors.ContainerError as exception: + # host_log_file_path = ctx.obj["log_folder_path"] / log_file_name + # if host_log_file_path.exists(): + # with open(host_log_file_path) as _log_file: + # logger.debug("*" * 50) + # logger.debug("*" * 50) + # logger.debug("*" * 50) + # logger.debug(_log_file.read()) + # logger.debug("*" * 50) + # logger.debug("*" * 50) + # logger.debug("*" * 50) + # raise exception def kill_odoo(ctx, migration_step: dict): @@ -260,27 +288,17 @@ def execute_click_odoo_python_files( ] python_files = sorted(python_files) - # Prepare data information for docker - links = {ctx.obj["config"]["postgres_container_name"]: "db"} - env_path = ctx.obj["env_folder_path"] - odoo_env_path = get_odoo_env_path(ctx, migration_step["version"]) - - # Generate odoo config file - log_file = "/env/log/{}____{}__post_migration.log".format( - ctx.obj["log_prefix"], migration_step["complete_name"] + command = generate_odoo_command( + ctx, + migration_step, + execution_context, + database, + shell=True, ) - generate_odoo_config_file(ctx, migration_step, log_file, execution_context) for python_file in python_files: - # TODO, check if we should set python2 for old version of Odoo - # or just 'python' - command = ( - "click-odoo" - " --database {database}" - " --config /odoo_env/_auto_generated_odoo.cfg" - " /env/{python_file}" - ).format( - database=database, + command = ("/bin/bash -c 'cat /env/{python_file} | {command}'").format( + command=command, python_file=str(python_file), ) try: @@ -288,19 +306,14 @@ def execute_click_odoo_python_files( "Executing script %s / %s" % (migration_step["complete_name"], python_file) ) - run_container( - get_docker_image_tag(ctx, migration_step["version"]), - get_docker_container_name(ctx, migration_step), - command=command, - ports={}, - volumes={ - env_path: "/env/", - odoo_env_path: "/odoo_env/", - }, - links=links, - detach=False, - auto_remove=True, + return run_container_odoo( + ctx, + migration_step, + command, + detached_container=False, + database=database, ) + except Exception as e: traceback.print_exc() logger.error( diff --git a/odoo_openupgrade_wizard/tools/tools_postgres.py b/odoo_openupgrade_wizard/tools/tools_postgres.py index 944a67b..9127c51 100644 --- a/odoo_openupgrade_wizard/tools/tools_postgres.py +++ b/odoo_openupgrade_wizard/tools/tools_postgres.py @@ -2,9 +2,11 @@ import os import time from pathlib import Path +import docker from loguru import logger from odoo_openupgrade_wizard.tools.tools_docker import ( + exec_container, get_docker_client, run_container, ) @@ -15,9 +17,30 @@ def get_postgres_container(ctx): client = get_docker_client() image_name = ctx.obj["config"]["postgres_image_name"] container_name = ctx.obj["config"]["postgres_container_name"] - containers = client.containers.list(filters={"name": container_name}) + volume_name = ctx.obj["config"]["postgres_volume_name"] + + # Check if container exists + containers = client.containers.list( + all=True, filters={"name": container_name} + ) if containers: - return containers[0] + container = containers[0] + if container.status == "exited": + logger.warning( + "Found container %s in a exited status. Removing it..." + % container_name + ) + container.remove() + else: + return container + + # Check if volume exists + try: + client.volumes.get(volume_name) + logger.debug("Recovering existing postgres volume: %s" % volume_name) + except docker.errors.NotFound: + logger.info("Creating Postgres volume: %s" % volume_name) + client.volumes.create(volume_name) logger.info("Launching Postgres Container. (Image %s)" % image_name) container = run_container( @@ -30,10 +53,8 @@ def get_postgres_container(ctx): "PGDATA": "/var/lib/postgresql/data/pgdata", }, volumes={ - ctx.obj["env_folder_path"]: "/env/", - ctx.obj[ - "postgres_folder_path" - ]: "/var/lib/postgresql/data/pgdata/", + ctx.obj["env_folder_path"].absolute(): "/env/", + volume_name: "/var/lib/postgresql/data/pgdata/", }, detach=True, ) @@ -62,24 +83,19 @@ def execute_sql_file(ctx, database, sql_file): ) container_path = Path("/env/") / relative_path - docker_command = ( - "psql" " --username=odoo" " --dbname={database}" " --file {file_path}" + command = ( + "psql --username=odoo --dbname={database} --file {file_path}" ).format(database=database, file_path=container_path) logger.info( "Executing the script '%s' in postgres container" " on database %s" % (relative_path, database) ) - docker_result = container.exec_run(docker_command) - if docker_result.exit_code != 0: - raise Exception( - "The script '%s' failed on database %s. Exit Code : %d" - % (relative_path, database, docker_result.exit_code) - ) + exec_container(container, command) def execute_sql_request(ctx, request, database="postgres"): container = get_postgres_container(ctx) - docker_command = ( + command = ( "psql" " --username=odoo" " --dbname={database}" @@ -90,12 +106,8 @@ def execute_sql_request(ctx, request, database="postgres"): "Executing the following command in postgres container" " on database %s \n %s" % (database, request) ) - docker_result = container.exec_run(docker_command) - if docker_result.exit_code != 0: - raise Exception( - "Request %s failed on database %s. Exit Code : %d" - % (request, database, docker_result.exit_code) - ) + docker_result = exec_container(container, command) + lines = docker_result.output.decode("utf-8").split("\n") result = [] for line in lines: diff --git a/odoo_openupgrade_wizard/tools/tools_system.py b/odoo_openupgrade_wizard/tools/tools_system.py index f309d8e..3f5c95e 100644 --- a/odoo_openupgrade_wizard/tools/tools_system.py +++ b/odoo_openupgrade_wizard/tools/tools_system.py @@ -50,7 +50,16 @@ def ensure_file_exists_from_template( template_folder = ( importlib_resources.files("odoo_openupgrade_wizard") / "templates" ) - text = (template_folder / template_name).read_text() + template_path = template_folder / template_name + if not template_path.exists(): + logger.warning( + f"Unable to generate {file_path}," + f" the template {template_name} has not been found." + f" If it's a Dockerfile," + f" you should maybe contribute to that project ;-)" + ) + return + text = template_path.read_text() template = Template(text) output = template.render(args) @@ -91,3 +100,7 @@ def git_aggregate(folder_path: Path, config_path: Path, jobs: int): % config_path ) gitaggregate_cmd.run(args) + + +def get_local_user_id(): + return os.getuid() diff --git a/poetry.lock b/poetry.lock index d960af0..200def8 100644 --- a/poetry.lock +++ b/poetry.lock @@ -312,7 +312,7 @@ testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest- name = "importlib-resources" version = "5.4.0" description = "Read resources from Python packages" -category = "dev" +category = "main" optional = false python-versions = ">=3.6" @@ -797,7 +797,7 @@ socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"] [[package]] name = "virtualenv" -version = "20.15.0" +version = "20.15.1" description = "Virtual Python Environment builder" category = "dev" optional = false @@ -862,7 +862,7 @@ testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytes [metadata] lock-version = "1.1" python-versions = ">=3.6.3,<4.0.0" -content-hash = "83c796afe3bead38187a2cd46deab78c3b6311c416d583b20fb077014d01f139" +content-hash = "cb073f5cf2ea8d6df3c7e5320419a3bcdd60ac83bf4a308ddea0286de59700b5" [metadata.files] aiocontextvars = [ @@ -1375,8 +1375,8 @@ urllib3 = [ {file = "urllib3-1.26.9.tar.gz", hash = "sha256:aabaf16477806a5e1dd19aa41f8c2b7950dd3c746362d7e3223dbe6de6ac448e"}, ] virtualenv = [ - {file = "virtualenv-20.15.0-py2.py3-none-any.whl", hash = "sha256:804cce4de5b8a322f099897e308eecc8f6e2951f1a8e7e2b3598dff865f01336"}, - {file = "virtualenv-20.15.0.tar.gz", hash = "sha256:4c44b1d77ca81f8368e2d7414f9b20c428ad16b343ac6d226206c5b84e2b4fcc"}, + {file = "virtualenv-20.15.1-py2.py3-none-any.whl", hash = "sha256:b30aefac647e86af6d82bfc944c556f8f1a9c90427b2fb4e3bfbf338cb82becf"}, + {file = "virtualenv-20.15.1.tar.gz", hash = "sha256:288171134a2ff3bfb1a2f54f119e77cd1b81c29fc1265a2356f3e8d14c7d58c4"}, ] websocket-client = [ {file = "websocket-client-1.3.1.tar.gz", hash = "sha256:6278a75065395418283f887de7c3beafb3aa68dada5cacbe4b214e8d26da499b"}, diff --git a/pyproject.toml b/pyproject.toml index 23d6122..67a0050 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,6 +32,7 @@ python = ">=3.6.3,<4.0.0" click = "^7.0" click-loglevel = "^0.4" docker = "^5.0" +importlib-resources = "^5.4" git-aggregator = "^2.1" GitPython = "^3.1" jinja2 = "^3.0" diff --git a/tests/__init__.py b/tests/__init__.py index 217b466..46945f8 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -29,15 +29,32 @@ def move_to_test_folder(): def cli_runner_invoke(cmd): - result = CliRunner().invoke( - main, - cmd, - catch_exceptions=False, - ) - if not result.exit_code == 0: - _logger.error("exit_code: %s" % result.exit_code) - _logger.error("output: %s" % result.output) - assert result.exit_code == 0 + try: + result = CliRunner().invoke( + main, + cmd, + catch_exceptions=False, + ) + if not result.exit_code == 0: + _logger.error("exit_code: %s" % result.exit_code) + _logger.error("output: %s" % result.output) + assert result.exit_code == 0 + except Exception as exception: + if Path("log").exists(): + log_files = [ + Path("log") / Path(f) + for f in os.listdir(Path("log")) + if f[-4:] == ".log" + ] + for log_file in log_files: + print("============================") + print(log_file) + print("============================") + _f = open(log_file) + print(_f.read()) + _f.close() + print("============================") + raise exception def build_ctx_from_config_file() -> dict: @@ -50,7 +67,9 @@ def build_ctx_from_config_file() -> dict: setattr(ctx, "obj", {}) config_file_path = env_folder_path / "config.yml" if not config_file_path.exists(): - raise Exception("Configuration file not found %s" % config_file_path) + raise Exception( + "Configuration file not found %s" % config_file_path.absolute() + ) with open(config_file_path) as file: config = yaml.safe_load(file) ctx.obj["config"] = config @@ -58,7 +77,4 @@ def build_ctx_from_config_file() -> dict: ctx.obj["env_folder_path"] = env_folder_path ctx.obj["src_folder_path"] = env_folder_path / Path("src") - ctx.obj["postgres_folder_path"] = env_folder_path / Path( - "postgres_data/data" - ) return ctx diff --git a/tests/cli_01_init_test.py b/tests/cli_01_init_test.py index 416847d..01e1b0c 100644 --- a/tests/cli_01_init_test.py +++ b/tests/cli_01_init_test.py @@ -6,6 +6,7 @@ from . import cli_runner_invoke, move_to_test_folder def test_cli_init(): move_to_test_folder() + expected_folder_path = Path("../output_expected").absolute() cli_runner_invoke( @@ -13,11 +14,11 @@ def test_cli_init(): "--log-level=DEBUG", "init", "--project-name=test-cli", - "--initial-version=13.0", - "--final-version=14.0", + "--initial-version=14.0", + "--final-version=15.0", "--extra-repository=" "OCA/web,OCA/server-tools,OCA/bank-statement-import", - ] + ], ) assert filecmp.cmp( diff --git a/tests/cli_02_get_code_test.py b/tests/cli_02_get_code_test.py index aaf6ec5..a686c65 100644 --- a/tests/cli_02_get_code_test.py +++ b/tests/cli_02_get_code_test.py @@ -5,21 +5,20 @@ from . import cli_runner_invoke, move_to_test_folder def test_cli_get_code(): move_to_test_folder() + cli_runner_invoke( [ "--log-level=DEBUG", "get-code", - ] + ], ) - # Check V13 - openupgrade_path = Path("./src/env_13.0/src/openupgrade") - assert openupgrade_path.exists() + # Check V14 + web_path = Path("./src/env_14.0/src/OCA/web") + assert web_path.exists() - assert (openupgrade_path / Path("odoo")).exists() - - # check V14 - openupgrade_path = Path("./src/env_14.0/src/openupgrade") + # check V15 + openupgrade_path = Path("./src/env_15.0/src/openupgrade") assert openupgrade_path.exists() diff --git a/tests/cli_03_docker_build_test.py b/tests/cli_03_docker_build_test.py index 7b70191..14a5009 100644 --- a/tests/cli_03_docker_build_test.py +++ b/tests/cli_03_docker_build_test.py @@ -1,24 +1,38 @@ -from odoo_openupgrade_wizard.tools.tools_docker import get_docker_client +from odoo_openupgrade_wizard.tools.tools_docker import ( + get_docker_client, + kill_container, +) -from . import cli_runner_invoke, move_to_test_folder +from . import ( + build_ctx_from_config_file, + cli_runner_invoke, + move_to_test_folder, +) def test_cli_docker_build(): move_to_test_folder() + ctx = build_ctx_from_config_file() + + # Drop postgresql container if exist + # (we ensure that the postgres container is removed to + # be sure that the call (environment, etc...) is correct now.) + kill_container(ctx.obj["config"]["postgres_container_name"]) + cli_runner_invoke( [ "--log-level=DEBUG", "docker-build", - "--versions=13.0,14.0", - ] + "--versions=14.0,15.0", + ], ) docker_client = get_docker_client() assert docker_client.images.get( - "odoo-openupgrade-wizard-image__test-cli__13.0" + "odoo-openupgrade-wizard-image__test-cli__14.0" ) assert docker_client.images.get( - "odoo-openupgrade-wizard-image__test-cli__14.0" + "odoo-openupgrade-wizard-image__test-cli__15.0" ) diff --git a/tests/cli_04_run_test.py b/tests/cli_04_run_test.py index 3006d66..e0a4a59 100644 --- a/tests/cli_04_run_test.py +++ b/tests/cli_04_run_test.py @@ -1,7 +1,10 @@ from pathlib import Path from odoo_openupgrade_wizard.tools.tools_docker import get_docker_client -from odoo_openupgrade_wizard.tools.tools_postgres import execute_sql_request +from odoo_openupgrade_wizard.tools.tools_postgres import ( + ensure_database, + execute_sql_request, +) from . import ( build_ctx_from_config_file, @@ -12,7 +15,11 @@ from . import ( def test_cli_run(): move_to_test_folder() + ctx = build_ctx_from_config_file() + db_name = "database_test_cli___run" + ensure_database(ctx, db_name, state="absent") + cli_runner_invoke( [ "--log-level=DEBUG", @@ -21,7 +28,7 @@ def test_cli_run(): "--database=%s" % db_name, "--init-modules=base", "--stop-after-init", - ] + ], ) # Ensure that a subfolder filestore/DB_NAME has been created @@ -29,7 +36,6 @@ def test_cli_run(): assert db_filestore_path.exists() # Ensure that 'base' module is installed - ctx = build_ctx_from_config_file() request = ( "SELECT id" " FROM ir_module_module" diff --git a/tests/cli_05_execute_script_python_test.py b/tests/cli_05_execute_script_python_test.py index 6060403..4f44e4f 100644 --- a/tests/cli_05_execute_script_python_test.py +++ b/tests/cli_05_execute_script_python_test.py @@ -2,7 +2,10 @@ from pathlib import Path from plumbum.cmd import cp -from odoo_openupgrade_wizard.tools.tools_postgres import execute_sql_request +from odoo_openupgrade_wizard.tools.tools_postgres import ( + ensure_database, + execute_sql_request, +) from . import ( build_ctx_from_config_file, @@ -13,15 +16,20 @@ from . import ( def test_cli_execute_script_python(): move_to_test_folder() - extra_script_path = Path("../extra_script/click_odoo_test.py").absolute() + ctx = build_ctx_from_config_file() + + extra_script_path = Path( + "../extra_script/post-migration-custom_test.py" + ).absolute() cp( extra_script_path, - Path("click_odoo_test.py"), + Path("post-migration-custom_test.py"), ) db_name = "database_test_cli___execute_script_python" + ensure_database(ctx, db_name, state="absent") - # Install Odoo on V13 with base installed + # Install Odoo on V14 with base installed cli_runner_invoke( [ "--log-level=DEBUG", @@ -30,12 +38,11 @@ def test_cli_execute_script_python(): "--database=%s" % db_name, "--init-modules=base", "--stop-after-init", - ] + ], ) # Compute partners quantity - ctx = build_ctx_from_config_file() - request = "SELECT count(*)" " FROM res_partner;" + request = "SELECT count(*) FROM res_partner;" partner_quantity_before = int( execute_sql_request(ctx, request, database=db_name)[0][0] ) @@ -47,8 +54,8 @@ def test_cli_execute_script_python(): "execute-script-python", "--step=1", "--database=%s" % db_name, - "--script-file-path=click_odoo_test.py", - ] + "--script-file-path=post-migration-custom_test.py", + ], ) partner_quantity_after = int( execute_sql_request(ctx, request, database=db_name)[0][0] diff --git a/tests/cli_06_execute_script_sql_test.py b/tests/cli_06_execute_script_sql_test.py index 185e8f4..524f780 100644 --- a/tests/cli_06_execute_script_sql_test.py +++ b/tests/cli_06_execute_script_sql_test.py @@ -16,14 +16,15 @@ from . import ( def test_cli_execute_script_sql(): move_to_test_folder() + ctx = build_ctx_from_config_file() + extra_script_path = Path( "../extra_script/pre-migration-custom_test.sql" ).absolute() # Deploy SQL Script - destination_path = Path("scripts/step_01__update__13.0") + destination_path = Path("scripts/step_01__regular__14.0") cp([extra_script_path, destination_path]) - ctx = build_ctx_from_config_file() # Reset database db_name = "database_test_cli___execute_script_sql" @@ -38,7 +39,7 @@ def test_cli_execute_script_sql(): "execute-script-sql", "--step=1", "--database=%s" % db_name, - ] + ], ) # Ensure that the request has been done correctly diff --git a/tests/cli_07_upgrade_test.py b/tests/cli_07_upgrade_test.py index 37ee9b5..a8b610d 100644 --- a/tests/cli_07_upgrade_test.py +++ b/tests/cli_07_upgrade_test.py @@ -12,10 +12,10 @@ from . import ( def test_cli_upgrade(): move_to_test_folder() + ctx = build_ctx_from_config_file() # Initialize database db_name = "database_test_cli___upgrade" - ctx = build_ctx_from_config_file() ensure_database(ctx, db_name, state="absent") cli_runner_invoke( @@ -26,28 +26,7 @@ def test_cli_upgrade(): "--database=%s" % db_name, "--init-modules=base", "--stop-after-init", - ] - ) - - # Ensure that 'base' module is installed at 13.0 - request = ( - "SELECT latest_version" - " FROM ir_module_module" - " WHERE state ='installed'" - " AND name='base';" - ) - latest_version = execute_sql_request(ctx, request, database=db_name) - - assert latest_version[0][0].startswith("13.") - - cli_runner_invoke( - [ - "--log-level=DEBUG", - "upgrade", - "--database=%s" % db_name, - "--first-step=1", - "--last-step=3", - ] + ], ) # Ensure that 'base' module is installed at 14.0 @@ -60,3 +39,24 @@ def test_cli_upgrade(): latest_version = execute_sql_request(ctx, request, database=db_name) assert latest_version[0][0].startswith("14.") + + cli_runner_invoke( + [ + "--log-level=DEBUG", + "upgrade", + "--database=%s" % db_name, + "--first-step=1", + "--last-step=3", + ], + ) + + # Ensure that 'base' module is installed at 15.0 + request = ( + "SELECT latest_version" + " FROM ir_module_module" + " WHERE state ='installed'" + " AND name='base';" + ) + latest_version = execute_sql_request(ctx, request, database=db_name) + + assert latest_version[0][0].startswith("15.") diff --git a/tests/cli_08_estimate_workload_test.py b/tests/cli_08_estimate_workload_test.py index c9e8e5b..7007611 100644 --- a/tests/cli_08_estimate_workload_test.py +++ b/tests/cli_08_estimate_workload_test.py @@ -14,16 +14,14 @@ class TestCliEstimateWorkload(unittest.TestCase): "estimate-workload", "--extra-modules=" # Done Module - "account" + "base" # Deleted module (because merged) ",account_analytic_default" - # Deleted module (because renamed) - ",account_facturx" # Deleted module (because lost merge) - ",base_gengo" + ",account_edi_extended" # Some modules that are not ported (for the time being) ",l10n_be_invoice_bba,l10n_ch_qriban,l10n_latam_base" - # OCA Portted Modules + # OCA Ported Modules ",web_responsive" # OCA Unported modules ",web_boolean_button" @@ -34,7 +32,7 @@ class TestCliEstimateWorkload(unittest.TestCase): ",web_widget_one2many_tree_line_duplicate" ",web_widget_dropdown_dynamic_example" ",my_module_that_doesnt_exist", - ] + ], ) # We check file has been created diff --git a/tests/cli_20_install_from_csv_test.py b/tests/cli_20_install_from_csv_test.py index 222860c..8bc21fb 100644 --- a/tests/cli_20_install_from_csv_test.py +++ b/tests/cli_20_install_from_csv_test.py @@ -23,7 +23,7 @@ def test_cli_install_from_csv(): "--log-level=DEBUG", "install-from-csv", "--database=%s" % db_name, - ] + ], ) # Ensure that 'base' is installed diff --git a/tests/cli_21_generate_module_analysis_test.py b/tests/cli_21_generate_module_analysis_test.py index 99cc18c..3280e66 100644 --- a/tests/cli_21_generate_module_analysis_test.py +++ b/tests/cli_21_generate_module_analysis_test.py @@ -11,13 +11,14 @@ from . import ( def test_cli_generate_module_analysis(): move_to_test_folder() + ctx = build_ctx_from_config_file() + db_name = "database_test_cli___generate_module_analysis" - ctx = build_ctx_from_config_file() # identify main analysis file of openupgrade - analysis_file_path = get_odoo_env_path(ctx, 14.0) / Path( + analysis_file_path = get_odoo_env_path(ctx, 15.0) / Path( "src/openupgrade/openupgrade_scripts/scripts" - "/base/14.0.1.3/upgrade_general_log.txt" + "/base/15.0.1.3/upgrade_general_log.txt" ) # We remove this file and run the analysis @@ -34,7 +35,7 @@ def test_cli_generate_module_analysis(): "--step=2", "--database=%s" % db_name, "--modules=base", - ] + ], ) # The file should has been recreated by the analysis command diff --git a/tests/data/extra_script/click_odoo_test.py b/tests/data/extra_script/click_odoo_test.py deleted file mode 100644 index f83a671..0000000 --- a/tests/data/extra_script/click_odoo_test.py +++ /dev/null @@ -1,11 +0,0 @@ -import logging - -_logger = logging.getLogger(__name__) -_logger.info("click_odoo_test.py : Begin of script ...") - -env = env # noqa: F821 - -for i in range(0, 10): - env["res.partner"].create({"name": "Partner #%d" % (i)}) - -_logger.info("click_odoo_test.py : End of script.") diff --git a/tests/data/extra_script/post-migration-custom_test.py b/tests/data/extra_script/post-migration-custom_test.py index fffdd04..ba18852 100644 --- a/tests/data/extra_script/post-migration-custom_test.py +++ b/tests/data/extra_script/post-migration-custom_test.py @@ -1,46 +1,15 @@ -# Unused for the time being +import logging -# def _check_orm_usage(self): -# # Classic ORM usage Checks -# partners = self.browse_by_search("res.partner") +_logger = logging.getLogger(__name__) +_logger.info("post-migration-custom_test.py : Begin of script ...") -# self.browse_by_create("res.partner", {"name": "New Partner"}) +env = env # noqa: F821 -# new_partners = self.browse_by_search("res.partner") +for i in range(0, 10): + partner_name = "Partner #%d" % (i) + _logger.info("Create Partner %s" % partner_name) + env["res.partner"].create({"name": partner_name}) -# if len(partners) + 1 != len(new_partners): -# raise Exception("Creation of partner failed.") +_logger.info("post-migration-custom_test.py : End of script.") - -# def _check_modules(self): -# if self.check_modules_installed("sale"): -# self.uninstall_modules("sale") - -# self.install_modules("sale") - -# if not self.check_modules_installed("sale"): -# raise Exception("'sale' module should be installed") - -# self.uninstall_modules(["product"]) - -# if self.check_modules_installed("sale"): -# raise Exception( -# "'sale' module should not be installed" -# " after uninstallation of product" -# ) - - -# def _check_models(self): -# if not self.check_models_present("res.partner"): -# raise Exception("'res.partner' model should be present.") - -# if self.check_models_present("res.partner.unexisting.model"): -# raise Exception( -# "'res.partner.unexisting.model' model" " should not be present." -# ) - - -# def main(self): -# _check_orm_usage(self) -# _check_modules(self) -# _check_models(self) +env.cr.commit() diff --git a/tests/data/output_expected/config.yml b/tests/data/output_expected/config.yml index 207d538..d41e83f 100644 --- a/tests/data/output_expected/config.yml +++ b/tests/data/output_expected/config.yml @@ -1,31 +1,40 @@ project_name: test-cli postgres_image_name: postgres:13 -postgres_container_name: test-cli-db +postgres_container_name: test-cli-container-postgres +postgres_volume_name: test-cli-volume-postgres odoo_host_xmlrpc_port: 9069 odoo_default_country_code: FR odoo_versions: - - 13.0 - 14.0 + - 15.0 + + +odoo_version_settings: + 14.0: + repo_url: False + 15.0: + repo_url: False + migration_steps: - name: 1 - version: 13.0 + version: 14.0 execution_context: regular - complete_name: step_01__update__13.0 + complete_name: step_01__regular__14.0 - name: 2 - version: 14.0 + version: 15.0 execution_context: openupgrade - complete_name: step_02__upgrade__14.0 + complete_name: step_02__openupgrade__15.0 - name: 3 - version: 14.0 + version: 15.0 execution_context: regular - complete_name: step_03__update__14.0 + complete_name: step_03__regular__15.0 workload_settings: