[REF][WIP] remove xml_rpc connexion to make CI green, and replace by click_odoo script
This commit is contained in:
parent
c4ef08cf64
commit
ecd03ba392
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -4,5 +4,6 @@ __pycache__
|
||||||
.tox
|
.tox
|
||||||
.coverage
|
.coverage
|
||||||
.pytest_cache
|
.pytest_cache
|
||||||
/tests/output/*
|
/tests/data/output/*
|
||||||
log/
|
log/
|
||||||
|
_auto_generated_odoo.cfg
|
||||||
|
|
|
||||||
|
|
@ -49,11 +49,14 @@ pytest:
|
||||||
tests/cli_02_get_code_test.py
|
tests/cli_02_get_code_test.py
|
||||||
tests/cli_03_docker_build_test.py
|
tests/cli_03_docker_build_test.py
|
||||||
tests/cli_04_run_test.py
|
tests/cli_04_run_test.py
|
||||||
|
tests/cli_05_execute_script_python_test.py
|
||||||
tests/cli_06_execute_script_sql_test.py
|
tests/cli_06_execute_script_sql_test.py
|
||||||
# Disabled : calling OdooRPC on mounted container
|
tests/cli_07_upgrade_test.py
|
||||||
# in a container (gitlab) does'nt seems to work.
|
|
||||||
|
|
||||||
# - poetry run pytest --verbose --verbose tests/cli_05_execute_script_python_test.py
|
# Disabled test on gitlab-ci :
|
||||||
# - poetry run pytest --verbose --verbose
|
# The following tests should work locally but doesn't on gitlab-ci
|
||||||
# - poetry run pytest --verbose --verbose tests/cli_07_upgrade_test.py
|
# because calling OdooRPC on mounted container
|
||||||
# - poetry run pytest --verbose --verbose tests/cli_08_generate_module_analysis_test.py
|
# in a container (gitlab) doesn't work.
|
||||||
|
|
||||||
|
# tests/cli_20_install_from_csv_test.py
|
||||||
|
# tests/cli_21_generate_module_analysis_test.py
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,7 @@ from odoo_openupgrade_wizard.cli_options import (
|
||||||
get_migration_step_from_options,
|
get_migration_step_from_options,
|
||||||
step_option,
|
step_option,
|
||||||
)
|
)
|
||||||
from odoo_openupgrade_wizard.tools_odoo import (
|
from odoo_openupgrade_wizard.tools_odoo import execute_click_odoo_python_files
|
||||||
execute_python_files_post_migration,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
|
|
@ -21,7 +19,6 @@ from odoo_openupgrade_wizard.tools_odoo import (
|
||||||
type=click.Path(
|
type=click.Path(
|
||||||
exists=True,
|
exists=True,
|
||||||
dir_okay=False,
|
dir_okay=False,
|
||||||
resolve_path=True,
|
|
||||||
),
|
),
|
||||||
help="List of python files that will be executed, replacing the default"
|
help="List of python files that will be executed, replacing the default"
|
||||||
" scripts placed in the migration step folder.",
|
" scripts placed in the migration step folder.",
|
||||||
|
|
@ -30,6 +27,6 @@ from odoo_openupgrade_wizard.tools_odoo import (
|
||||||
def execute_script_python(ctx, step, database, script_file_path):
|
def execute_script_python(ctx, step, database, script_file_path):
|
||||||
migration_step = get_migration_step_from_options(ctx, step)
|
migration_step = get_migration_step_from_options(ctx, step)
|
||||||
|
|
||||||
execute_python_files_post_migration(
|
execute_click_odoo_python_files(
|
||||||
ctx, database, migration_step, [Path(x) for x in script_file_path]
|
ctx, database, migration_step, [Path(x) for x in script_file_path]
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ from odoo_openupgrade_wizard.tools_postgres import (
|
||||||
type=click.Path(
|
type=click.Path(
|
||||||
exists=True,
|
exists=True,
|
||||||
dir_okay=False,
|
dir_okay=False,
|
||||||
resolve_path=True,
|
|
||||||
),
|
),
|
||||||
help="List of SQL files that will be executed, replacing the default"
|
help="List of SQL files that will be executed, replacing the default"
|
||||||
" scripts placed in the migration step folder.",
|
" scripts placed in the migration step folder.",
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ from odoo_openupgrade_wizard.cli_options import (
|
||||||
last_step_option,
|
last_step_option,
|
||||||
)
|
)
|
||||||
from odoo_openupgrade_wizard.tools_odoo import (
|
from odoo_openupgrade_wizard.tools_odoo import (
|
||||||
execute_python_files_post_migration,
|
execute_click_odoo_python_files,
|
||||||
kill_odoo,
|
kill_odoo,
|
||||||
run_odoo,
|
run_odoo,
|
||||||
)
|
)
|
||||||
|
|
@ -38,4 +38,4 @@ def upgrade(ctx, first_step, last_step, database):
|
||||||
logger.info("Received Keyboard Interrupt or System Exiting...")
|
logger.info("Received Keyboard Interrupt or System Exiting...")
|
||||||
finally:
|
finally:
|
||||||
kill_odoo(ctx, migration_step)
|
kill_odoo(ctx, migration_step)
|
||||||
execute_python_files_post_migration(ctx, database, migration_step)
|
execute_click_odoo_python_files(ctx, database, migration_step)
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ def skip_addon_path(migration_step: dict, path: Path) -> bool:
|
||||||
) and migration_step["release"] < 14.0
|
) and migration_step["release"] < 14.0
|
||||||
|
|
||||||
|
|
||||||
def get_server_wide_modules_upgrade(migration_step: dict) -> str:
|
def get_server_wide_modules_upgrade(migration_step: dict) -> list:
|
||||||
"""return a list of modules to load, depending on the migration step."""
|
"""return a list of modules to load, depending on the migration step."""
|
||||||
if (
|
if (
|
||||||
migration_step["release"] >= 14.0
|
migration_step["release"] >= 14.0
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ PYTHON_REQUIREMENTS_TXT_TEMPLATE = """
|
||||||
{{ python_librairy }}
|
{{ python_librairy }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
odoorpc
|
odoorpc
|
||||||
|
click-odoo
|
||||||
"""
|
"""
|
||||||
|
|
||||||
DEBIAN_REQUIREMENTS_TXT_TEMPLATE = """
|
DEBIAN_REQUIREMENTS_TXT_TEMPLATE = """
|
||||||
|
|
@ -111,8 +112,13 @@ USER odoo
|
||||||
PRE_MIGRATION_SQL_TEMPLATE = ""
|
PRE_MIGRATION_SQL_TEMPLATE = ""
|
||||||
|
|
||||||
POST_MIGRATION_PY_TEMPLATE = """
|
POST_MIGRATION_PY_TEMPLATE = """
|
||||||
def main(self):
|
import logging
|
||||||
pass
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
_logger.info("Executing post-migration.py script ...")
|
||||||
|
|
||||||
|
env = env # noqa: F821
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
GIT_IGNORE_CONTENT = """
|
GIT_IGNORE_CONTENT = """
|
||||||
|
|
@ -123,6 +129,5 @@ GIT_IGNORE_CONTENT = """
|
||||||
MODULES_CSV_TEMPLATE = """
|
MODULES_CSV_TEMPLATE = """
|
||||||
base,Base
|
base,Base
|
||||||
account,Account Module
|
account,Account Module
|
||||||
product,Product
|
|
||||||
web_responsive,Web Responsive Module
|
web_responsive,Web Responsive Module
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import importlib.util
|
import configparser
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
@ -15,7 +15,6 @@ from odoo_openupgrade_wizard.configuration_version_dependant import (
|
||||||
skip_addon_path,
|
skip_addon_path,
|
||||||
)
|
)
|
||||||
from odoo_openupgrade_wizard.tools_docker import kill_container, run_container
|
from odoo_openupgrade_wizard.tools_docker import kill_container, run_container
|
||||||
from odoo_openupgrade_wizard.tools_odoo_instance import OdooInstance
|
|
||||||
from odoo_openupgrade_wizard.tools_postgres import get_postgres_container
|
from odoo_openupgrade_wizard.tools_postgres import get_postgres_container
|
||||||
from odoo_openupgrade_wizard.tools_system import get_script_folder
|
from odoo_openupgrade_wizard.tools_system import get_script_folder
|
||||||
|
|
||||||
|
|
@ -76,13 +75,6 @@ def get_odoo_version_from_migration_step(ctx, migration_step: dict) -> dict:
|
||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
|
|
||||||
def get_server_wide_modules(ctx, migration_step: dict) -> str:
|
|
||||||
# TODO, read from odoo.cfg file, the key server_wide_modules
|
|
||||||
modules = []
|
|
||||||
modules += get_server_wide_modules_upgrade(migration_step)
|
|
||||||
return modules
|
|
||||||
|
|
||||||
|
|
||||||
def generate_odoo_command(
|
def generate_odoo_command(
|
||||||
ctx,
|
ctx,
|
||||||
migration_step: dict,
|
migration_step: dict,
|
||||||
|
|
@ -93,22 +85,12 @@ def generate_odoo_command(
|
||||||
shell: bool,
|
shell: bool,
|
||||||
demo: bool,
|
demo: bool,
|
||||||
) -> str:
|
) -> str:
|
||||||
addons_path = get_odoo_addons_path(ctx, Path("/odoo_env"), migration_step)
|
|
||||||
server_wide_modules = get_server_wide_modules(ctx, migration_step)
|
|
||||||
server_wide_modules_cmd = (
|
|
||||||
server_wide_modules
|
|
||||||
and "--load %s" % ",".join(server_wide_modules)
|
|
||||||
or ""
|
|
||||||
)
|
|
||||||
database_cmd = database and "--database %s" % database or ""
|
database_cmd = database and "--database %s" % database or ""
|
||||||
update_cmd = update and "--update %s" % update or ""
|
update_cmd = update and "--update %s" % update or ""
|
||||||
init_cmd = init and "--init %s" % init or ""
|
init_cmd = init and "--init %s" % init or ""
|
||||||
stop_after_init_cmd = stop_after_init and "--stop-after-init" or ""
|
stop_after_init_cmd = stop_after_init and "--stop-after-init" or ""
|
||||||
shell_cmd = shell and "shell" or ""
|
shell_cmd = shell and "shell" or ""
|
||||||
demo_cmd = not demo and "--without-demo all" or ""
|
demo_cmd = not demo and "--without-demo all" or ""
|
||||||
log_file = "/env/log/{}____{}.log".format(
|
|
||||||
ctx.obj["log_prefix"], migration_step["complete_name"]
|
|
||||||
)
|
|
||||||
command = (
|
command = (
|
||||||
Path("/odoo_env")
|
Path("/odoo_env")
|
||||||
/ Path(get_odoo_folder(migration_step))
|
/ Path(get_odoo_folder(migration_step))
|
||||||
|
|
@ -117,16 +99,7 @@ def generate_odoo_command(
|
||||||
result = (
|
result = (
|
||||||
f" {command}"
|
f" {command}"
|
||||||
f" {shell_cmd}"
|
f" {shell_cmd}"
|
||||||
f" --db_host db"
|
f" --config /odoo_env/_auto_generated_odoo.cfg"
|
||||||
f" --db_port 5432"
|
|
||||||
f" --db_user odoo"
|
|
||||||
f" --db_password odoo"
|
|
||||||
f" --workers 0"
|
|
||||||
f" --config /odoo_env/odoo.cfg"
|
|
||||||
f" --data-dir /env/filestore/"
|
|
||||||
f" --logfile {log_file}"
|
|
||||||
f" --addons-path {addons_path}"
|
|
||||||
f" {server_wide_modules_cmd}"
|
|
||||||
f" {demo_cmd}"
|
f" {demo_cmd}"
|
||||||
f" {database_cmd}"
|
f" {database_cmd}"
|
||||||
f" {update_cmd}"
|
f" {update_cmd}"
|
||||||
|
|
@ -136,6 +109,52 @@ def generate_odoo_command(
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def generate_odoo_config_file(ctx, migration_step, log_file):
|
||||||
|
"""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_version = get_odoo_version_from_migration_step(ctx, migration_step)
|
||||||
|
odoo_env_path = get_odoo_env_path(ctx, odoo_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 = get_odoo_addons_path(ctx, Path("/odoo_env"), migration_step)
|
||||||
|
|
||||||
|
# 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(
|
def run_odoo(
|
||||||
ctx,
|
ctx,
|
||||||
migration_step: dict,
|
migration_step: dict,
|
||||||
|
|
@ -169,6 +188,10 @@ def run_odoo(
|
||||||
odoo_version = get_odoo_version_from_migration_step(ctx, migration_step)
|
odoo_version = get_odoo_version_from_migration_step(ctx, migration_step)
|
||||||
env_path = ctx.obj["env_folder_path"]
|
env_path = ctx.obj["env_folder_path"]
|
||||||
odoo_env_path = get_odoo_env_path(ctx, odoo_version)
|
odoo_env_path = get_odoo_env_path(ctx, odoo_version)
|
||||||
|
log_file = "/env/log/{}____{}.log".format(
|
||||||
|
ctx.obj["log_prefix"], migration_step["complete_name"]
|
||||||
|
)
|
||||||
|
generate_odoo_config_file(ctx, migration_step, log_file)
|
||||||
|
|
||||||
command = generate_odoo_command(
|
command = generate_odoo_command(
|
||||||
ctx,
|
ctx,
|
||||||
|
|
@ -208,48 +231,65 @@ def kill_odoo(ctx, migration_step: dict):
|
||||||
kill_container(get_docker_container_name(ctx, migration_step))
|
kill_container(get_docker_container_name(ctx, migration_step))
|
||||||
|
|
||||||
|
|
||||||
def execute_python_files_post_migration(
|
def execute_click_odoo_python_files(
|
||||||
ctx, database: str, migration_step: dict, python_files: list = []
|
ctx, database: str, migration_step: dict, python_files: list = []
|
||||||
):
|
):
|
||||||
if not python_files:
|
|
||||||
script_folder = get_script_folder(ctx, migration_step)
|
|
||||||
|
|
||||||
|
if not python_files:
|
||||||
|
# Get post-migration python scripts to execute
|
||||||
|
script_folder = get_script_folder(ctx, migration_step)
|
||||||
python_files = [
|
python_files = [
|
||||||
script_folder / Path(f)
|
Path("scripts") / Path(migration_step["complete_name"]) / Path(f)
|
||||||
for f in os.listdir(script_folder)
|
for f in os.listdir(script_folder)
|
||||||
if os.path.isfile(os.path.join(script_folder, f))
|
if os.path.isfile(os.path.join(script_folder, f))
|
||||||
and f[-3:] == ".py"
|
and f[-3:] == ".py"
|
||||||
]
|
]
|
||||||
python_files = sorted(python_files)
|
python_files = sorted(python_files)
|
||||||
|
|
||||||
try:
|
# Prepare data information for docker
|
||||||
# Launch Odoo
|
odoo_version = get_odoo_version_from_migration_step(ctx, migration_step)
|
||||||
run_odoo(
|
links = {ctx.obj["config"]["postgres_container_name"]: "db"}
|
||||||
ctx,
|
env_path = ctx.obj["env_folder_path"]
|
||||||
migration_step,
|
odoo_env_path = get_odoo_env_path(ctx, odoo_version)
|
||||||
detached_container=True,
|
|
||||||
database=database,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create Odoo instance via Odoo RPC
|
# Generate odoo config file
|
||||||
odoo_instance = OdooInstance(ctx, database)
|
log_file = "/env/log/{}____{}__post_migration.log".format(
|
||||||
|
ctx.obj["log_prefix"], migration_step["complete_name"]
|
||||||
|
)
|
||||||
|
generate_odoo_config_file(ctx, migration_step, log_file)
|
||||||
|
|
||||||
for python_file in python_files:
|
for python_file in python_files:
|
||||||
# Generate Python Script
|
# TODO, check if we should set python2 for old version of Odoo
|
||||||
|
# or just 'python'
|
||||||
logger.info("Running Script Post (Python) %s" % python_file)
|
command = (
|
||||||
package_name = "script.%s.%s" % (
|
"click-odoo"
|
||||||
migration_step["complete_name"],
|
" --database {database}"
|
||||||
python_file.name[:-3],
|
" --config /odoo_env/_auto_generated_odoo.cfg"
|
||||||
|
" /env/{python_file}"
|
||||||
|
).format(
|
||||||
|
database=database,
|
||||||
|
python_file=str(python_file),
|
||||||
)
|
)
|
||||||
module_spec = importlib.util.spec_from_file_location(
|
try:
|
||||||
package_name, python_file
|
logger.info(
|
||||||
|
"Executing script %s / %s"
|
||||||
|
% (migration_step["complete_name"], python_file)
|
||||||
|
)
|
||||||
|
run_container(
|
||||||
|
get_docker_image_tag(ctx, odoo_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,
|
||||||
)
|
)
|
||||||
module = importlib.util.module_from_spec(module_spec)
|
|
||||||
module_spec.loader.exec_module(module)
|
|
||||||
|
|
||||||
module.main(odoo_instance)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
traceback.print_exc()
|
||||||
logger.error(
|
logger.error(
|
||||||
"An error occured. Exiting. %s\n%s"
|
"An error occured. Exiting. %s\n%s"
|
||||||
% (e, traceback.print_exception(*sys.exc_info()))
|
% (e, traceback.print_exception(*sys.exc_info()))
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ def git_aggregate(folder_path: Path, config_path: Path):
|
||||||
do_push=False,
|
do_push=False,
|
||||||
expand_env=False,
|
expand_env=False,
|
||||||
env_file=None,
|
env_file=None,
|
||||||
force=False,
|
force=True,
|
||||||
)
|
)
|
||||||
with working_directory_keeper:
|
with working_directory_keeper:
|
||||||
os.chdir(folder_path)
|
os.chdir(folder_path)
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
[pytest]
|
[pytest]
|
||||||
norecursedirs = tests/output/*
|
norecursedirs=tests/data/*
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
from click.testing import CliRunner
|
from click.testing import CliRunner
|
||||||
|
from plumbum.cmd import mkdir
|
||||||
|
|
||||||
from odoo_openupgrade_wizard.cli import main
|
from odoo_openupgrade_wizard.cli import main
|
||||||
|
|
||||||
|
|
@ -13,6 +15,19 @@ def assert_result_cli_invoke(result):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def move_to_test_folder():
|
||||||
|
"""function to call at the beginning at the tests
|
||||||
|
to change the current working directory.
|
||||||
|
Note : this function is idempotens, to avoid to generate errors
|
||||||
|
if many tests scripts are executed.
|
||||||
|
"""
|
||||||
|
if os.getcwd().endswith("tests/data/output"):
|
||||||
|
return
|
||||||
|
test_folder_path = Path("tests/data/output")
|
||||||
|
mkdir([test_folder_path, "--parents"])
|
||||||
|
os.chdir(test_folder_path)
|
||||||
|
|
||||||
|
|
||||||
def cli_runner_invoke(cmd):
|
def cli_runner_invoke(cmd):
|
||||||
result = CliRunner().invoke(
|
result = CliRunner().invoke(
|
||||||
main,
|
main,
|
||||||
|
|
@ -25,7 +40,9 @@ def cli_runner_invoke(cmd):
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
|
|
||||||
|
|
||||||
def build_ctx_from_config_file(env_folder_path) -> dict:
|
def build_ctx_from_config_file() -> dict:
|
||||||
|
env_folder_path = Path(".")
|
||||||
|
|
||||||
class context:
|
class context:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,16 @@
|
||||||
import filecmp
|
import filecmp
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from plumbum.cmd import mkdir
|
from . import cli_runner_invoke, move_to_test_folder
|
||||||
|
|
||||||
from . import cli_runner_invoke
|
|
||||||
|
|
||||||
|
|
||||||
def test_cli_init():
|
def test_cli_init():
|
||||||
output_folder_path = Path("./tests/output").absolute()
|
move_to_test_folder()
|
||||||
expected_folder_path = Path("./tests/output_expected").absolute()
|
expected_folder_path = Path("../output_expected").absolute()
|
||||||
mkdir([output_folder_path, "--parents"])
|
|
||||||
|
|
||||||
cli_runner_invoke(
|
cli_runner_invoke(
|
||||||
[
|
[
|
||||||
"--log-level=DEBUG",
|
"--log-level=DEBUG",
|
||||||
"--env-folder=%s" % output_folder_path,
|
|
||||||
"init",
|
"init",
|
||||||
"--project-name=test-cli",
|
"--project-name=test-cli",
|
||||||
"--initial-release=13.0",
|
"--initial-release=13.0",
|
||||||
|
|
@ -24,6 +20,6 @@ def test_cli_init():
|
||||||
)
|
)
|
||||||
|
|
||||||
assert filecmp.cmp(
|
assert filecmp.cmp(
|
||||||
output_folder_path / Path("config.yml"),
|
Path("config.yml"),
|
||||||
expected_folder_path / Path("config.yml"),
|
expected_folder_path / Path("config.yml"),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,25 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from . import cli_runner_invoke
|
from . import cli_runner_invoke, move_to_test_folder
|
||||||
|
|
||||||
|
|
||||||
def test_cli_get_code():
|
def test_cli_get_code():
|
||||||
output_folder_path = Path("./tests/output").absolute()
|
move_to_test_folder()
|
||||||
|
|
||||||
cli_runner_invoke(
|
cli_runner_invoke(
|
||||||
[
|
[
|
||||||
"--log-level=DEBUG",
|
"--log-level=DEBUG",
|
||||||
"--env-folder=%s" % output_folder_path,
|
|
||||||
"get-code",
|
"get-code",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check V13
|
# Check V13
|
||||||
openupgrade_path = output_folder_path / Path(
|
openupgrade_path = Path("./src/env_13.0/src/openupgrade")
|
||||||
"./src/env_13.0/src/openupgrade"
|
|
||||||
)
|
|
||||||
assert openupgrade_path.exists()
|
assert openupgrade_path.exists()
|
||||||
|
|
||||||
assert (openupgrade_path / Path("odoo")).exists()
|
assert (openupgrade_path / Path("odoo")).exists()
|
||||||
|
|
||||||
# check V14
|
# check V14
|
||||||
openupgrade_path = output_folder_path / Path(
|
openupgrade_path = Path("./src/env_14.0/src/openupgrade")
|
||||||
"./src/env_14.0/src/openupgrade"
|
|
||||||
)
|
|
||||||
|
|
||||||
assert openupgrade_path.exists()
|
assert openupgrade_path.exists()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,13 @@
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from odoo_openupgrade_wizard.tools_docker import get_docker_client
|
from odoo_openupgrade_wizard.tools_docker import get_docker_client
|
||||||
|
|
||||||
from . import cli_runner_invoke
|
from . import cli_runner_invoke, move_to_test_folder
|
||||||
|
|
||||||
|
|
||||||
def test_cli_docker_build():
|
def test_cli_docker_build():
|
||||||
output_folder_path = Path("./tests/output").absolute()
|
move_to_test_folder()
|
||||||
|
|
||||||
cli_runner_invoke(
|
cli_runner_invoke(
|
||||||
[
|
[
|
||||||
"--log-level=DEBUG",
|
"--log-level=DEBUG",
|
||||||
"--env-folder=%s" % output_folder_path,
|
|
||||||
"docker-build",
|
"docker-build",
|
||||||
"--releases=13.0,14.0",
|
"--releases=13.0,14.0",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,19 @@ from pathlib import Path
|
||||||
from odoo_openupgrade_wizard.tools_docker import get_docker_client
|
from odoo_openupgrade_wizard.tools_docker import get_docker_client
|
||||||
from odoo_openupgrade_wizard.tools_postgres import execute_sql_request
|
from odoo_openupgrade_wizard.tools_postgres import execute_sql_request
|
||||||
|
|
||||||
from . import build_ctx_from_config_file, cli_runner_invoke
|
from . import (
|
||||||
|
build_ctx_from_config_file,
|
||||||
|
cli_runner_invoke,
|
||||||
|
move_to_test_folder,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_cli_run():
|
def test_cli_run():
|
||||||
output_folder_path = Path("./tests/output").absolute()
|
move_to_test_folder()
|
||||||
ctx = build_ctx_from_config_file(output_folder_path)
|
db_name = "database_test_cli___run"
|
||||||
db_name = "database_test_cli_run"
|
|
||||||
cli_runner_invoke(
|
cli_runner_invoke(
|
||||||
[
|
[
|
||||||
"--log-level=DEBUG",
|
"--log-level=DEBUG",
|
||||||
"--env-folder=%s" % output_folder_path,
|
|
||||||
"run",
|
"run",
|
||||||
"--step=1",
|
"--step=1",
|
||||||
"--database=%s" % db_name,
|
"--database=%s" % db_name,
|
||||||
|
|
@ -23,12 +25,11 @@ def test_cli_run():
|
||||||
)
|
)
|
||||||
|
|
||||||
# Ensure that a subfolder filestore/DB_NAME has been created
|
# Ensure that a subfolder filestore/DB_NAME has been created
|
||||||
db_filestore_path = output_folder_path / Path(
|
db_filestore_path = Path("./filestore/filestore/%s" % db_name)
|
||||||
"./filestore/filestore/%s" % db_name
|
|
||||||
)
|
|
||||||
assert db_filestore_path.exists()
|
assert db_filestore_path.exists()
|
||||||
|
|
||||||
# Ensure that 'base' module is installed
|
# Ensure that 'base' module is installed
|
||||||
|
ctx = build_ctx_from_config_file()
|
||||||
request = (
|
request = (
|
||||||
"SELECT id"
|
"SELECT id"
|
||||||
" FROM ir_module_module"
|
" FROM ir_module_module"
|
||||||
|
|
|
||||||
|
|
@ -1,38 +1,58 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from . import cli_runner_invoke
|
from plumbum.cmd import cp
|
||||||
|
|
||||||
|
from odoo_openupgrade_wizard.tools_postgres import execute_sql_request
|
||||||
|
|
||||||
|
from . import (
|
||||||
|
build_ctx_from_config_file,
|
||||||
|
cli_runner_invoke,
|
||||||
|
move_to_test_folder,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_cli_execute_script_python():
|
def test_cli_execute_script_python():
|
||||||
output_folder_path = Path("./tests/output").absolute()
|
move_to_test_folder()
|
||||||
|
extra_script_path = Path("../extra_script/click_odoo_test.py").absolute()
|
||||||
|
cp(
|
||||||
|
extra_script_path,
|
||||||
|
Path("click_odoo_test.py"),
|
||||||
|
)
|
||||||
|
|
||||||
extra_script_path = Path(
|
db_name = "database_test_cli___execute_script_python"
|
||||||
"./tests/extra_script/post-migration-custom_test.py"
|
|
||||||
).absolute()
|
|
||||||
|
|
||||||
db_name = "database_test_cli_execute_script_python"
|
# Install Odoo on V13 with base installed
|
||||||
|
|
||||||
# Install Odoo on V13 with product installed
|
|
||||||
cli_runner_invoke(
|
cli_runner_invoke(
|
||||||
[
|
[
|
||||||
"--log-level=DEBUG",
|
"--log-level=DEBUG",
|
||||||
"--env-folder=%s" % output_folder_path,
|
|
||||||
"run",
|
"run",
|
||||||
"--step=1",
|
"--step=1",
|
||||||
"--database=%s" % db_name,
|
"--database=%s" % db_name,
|
||||||
"--init-modules=product",
|
"--init-modules=base",
|
||||||
"--stop-after-init",
|
"--stop-after-init",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Compute partners quantity
|
||||||
|
ctx = build_ctx_from_config_file()
|
||||||
|
request = "SELECT count(*)" " FROM res_partner;"
|
||||||
|
partner_quantity_before = int(
|
||||||
|
execute_sql_request(ctx, request, database=db_name)[0][0]
|
||||||
|
)
|
||||||
|
|
||||||
|
# Execute Custom Python Script
|
||||||
cli_runner_invoke(
|
cli_runner_invoke(
|
||||||
[
|
[
|
||||||
"--log-level=DEBUG",
|
"--log-level=DEBUG",
|
||||||
"--env-folder=%s" % output_folder_path,
|
|
||||||
"execute-script-python",
|
"execute-script-python",
|
||||||
"--step=1",
|
"--step=1",
|
||||||
"--database=%s" % db_name,
|
"--database=%s" % db_name,
|
||||||
"--script-file-path=%s" % extra_script_path,
|
"--script-file-path=click_odoo_test.py",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
# TODO, add manually script
|
partner_quantity_after = int(
|
||||||
|
execute_sql_request(ctx, request, database=db_name)[0][0]
|
||||||
|
)
|
||||||
|
|
||||||
|
# Ensure that partners have been created by click_odoo_test.py
|
||||||
|
assert partner_quantity_after == (partner_quantity_before + 10)
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,40 @@
|
||||||
import shutil
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from plumbum.cmd import cp
|
||||||
|
|
||||||
from odoo_openupgrade_wizard.tools_postgres import (
|
from odoo_openupgrade_wizard.tools_postgres import (
|
||||||
ensure_database,
|
ensure_database,
|
||||||
execute_sql_request,
|
execute_sql_request,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import build_ctx_from_config_file, cli_runner_invoke
|
from . import (
|
||||||
|
build_ctx_from_config_file,
|
||||||
|
cli_runner_invoke,
|
||||||
|
move_to_test_folder,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_cli_execute_script_sql():
|
def test_cli_execute_script_sql():
|
||||||
output_folder_path = Path("./tests/output").absolute()
|
move_to_test_folder()
|
||||||
|
|
||||||
extra_script_path = Path(
|
extra_script_path = Path(
|
||||||
"./tests/extra_script/pre-migration-custom_test.sql"
|
"../extra_script/pre-migration-custom_test.sql"
|
||||||
).absolute()
|
).absolute()
|
||||||
|
|
||||||
destination_path = output_folder_path / "scripts/step_01__update__13.0"
|
# Deploy SQL Script
|
||||||
shutil.copy(extra_script_path, destination_path)
|
destination_path = Path("scripts/step_01__update__13.0")
|
||||||
ctx = build_ctx_from_config_file(output_folder_path)
|
cp([extra_script_path, destination_path])
|
||||||
db_name = "database_test_cli_execute_script_sql"
|
ctx = build_ctx_from_config_file()
|
||||||
|
|
||||||
|
# Reset database
|
||||||
|
db_name = "database_test_cli___execute_script_sql"
|
||||||
ensure_database(ctx, db_name, state="absent")
|
ensure_database(ctx, db_name, state="absent")
|
||||||
ensure_database(ctx, db_name, state="present")
|
ensure_database(ctx, db_name, state="present")
|
||||||
|
|
||||||
|
# TODO call with script-file-path
|
||||||
|
# to avoid to copy file in scripts/step_xxx folder
|
||||||
cli_runner_invoke(
|
cli_runner_invoke(
|
||||||
[
|
[
|
||||||
"--log-level=DEBUG",
|
"--log-level=DEBUG",
|
||||||
"--env-folder=%s" % output_folder_path,
|
|
||||||
"execute-script-sql",
|
"execute-script-sql",
|
||||||
"--step=1",
|
"--step=1",
|
||||||
"--database=%s" % db_name,
|
"--database=%s" % db_name,
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,26 @@
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from odoo_openupgrade_wizard.tools_postgres import (
|
from odoo_openupgrade_wizard.tools_postgres import (
|
||||||
ensure_database,
|
ensure_database,
|
||||||
execute_sql_request,
|
execute_sql_request,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import build_ctx_from_config_file, cli_runner_invoke
|
from . import (
|
||||||
|
build_ctx_from_config_file,
|
||||||
|
cli_runner_invoke,
|
||||||
|
move_to_test_folder,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_cli_upgrade():
|
def test_cli_upgrade():
|
||||||
output_folder_path = Path("./tests/output").absolute()
|
move_to_test_folder()
|
||||||
|
|
||||||
db_name = "database_test_cli_upgrade"
|
# Initialize database
|
||||||
|
db_name = "database_test_cli___upgrade"
|
||||||
ctx = build_ctx_from_config_file(output_folder_path)
|
ctx = build_ctx_from_config_file()
|
||||||
ensure_database(ctx, db_name, state="absent")
|
ensure_database(ctx, db_name, state="absent")
|
||||||
|
|
||||||
cli_runner_invoke(
|
cli_runner_invoke(
|
||||||
[
|
[
|
||||||
"--log-level=DEBUG",
|
"--log-level=DEBUG",
|
||||||
"--env-folder=%s" % output_folder_path,
|
|
||||||
"run",
|
"run",
|
||||||
"--step=1",
|
"--step=1",
|
||||||
"--database=%s" % db_name,
|
"--database=%s" % db_name,
|
||||||
|
|
@ -42,7 +43,6 @@ def test_cli_upgrade():
|
||||||
cli_runner_invoke(
|
cli_runner_invoke(
|
||||||
[
|
[
|
||||||
"--log-level=DEBUG",
|
"--log-level=DEBUG",
|
||||||
"--env-folder=%s" % output_folder_path,
|
|
||||||
"upgrade",
|
"upgrade",
|
||||||
"--database=%s" % db_name,
|
"--database=%s" % db_name,
|
||||||
"--first-step=1",
|
"--first-step=1",
|
||||||
|
|
|
||||||
39
tests/cli_20_install_from_csv_test.py
Normal file
39
tests/cli_20_install_from_csv_test.py
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
from odoo_openupgrade_wizard.tools_postgres import (
|
||||||
|
ensure_database,
|
||||||
|
execute_sql_request,
|
||||||
|
)
|
||||||
|
|
||||||
|
from . import (
|
||||||
|
build_ctx_from_config_file,
|
||||||
|
cli_runner_invoke,
|
||||||
|
move_to_test_folder,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_cli_install_from_csv():
|
||||||
|
move_to_test_folder()
|
||||||
|
|
||||||
|
# Initialize database
|
||||||
|
db_name = "database_test_cli___install_from_csv"
|
||||||
|
ctx = build_ctx_from_config_file()
|
||||||
|
ensure_database(ctx, db_name, state="absent")
|
||||||
|
|
||||||
|
cli_runner_invoke(
|
||||||
|
[
|
||||||
|
"--log-level=DEBUG",
|
||||||
|
"install-from-csv",
|
||||||
|
"--database=%s" % db_name,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
# Ensure that 'account' is installed
|
||||||
|
# and also 'product', by dependencies
|
||||||
|
request = (
|
||||||
|
"SELECT count(*)"
|
||||||
|
" FROM ir_module_module"
|
||||||
|
" WHERE state ='installed'"
|
||||||
|
" AND name in ('product', 'account');"
|
||||||
|
)
|
||||||
|
module_qty = int(execute_sql_request(ctx, request, database=db_name)[0][0])
|
||||||
|
|
||||||
|
assert module_qty == 2
|
||||||
|
|
@ -2,16 +2,18 @@ from pathlib import Path
|
||||||
|
|
||||||
from odoo_openupgrade_wizard.tools_odoo import get_odoo_env_path
|
from odoo_openupgrade_wizard.tools_odoo import get_odoo_env_path
|
||||||
|
|
||||||
from . import build_ctx_from_config_file, cli_runner_invoke
|
from . import (
|
||||||
|
build_ctx_from_config_file,
|
||||||
|
cli_runner_invoke,
|
||||||
|
move_to_test_folder,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_cli_generate_module_analysis():
|
def test_cli_generate_module_analysis():
|
||||||
# TODO, fixme, this test is not working for the time being
|
move_to_test_folder()
|
||||||
return
|
db_name = "database_test_cli___generate_module_analysis"
|
||||||
output_folder_path = Path("./tests/output").absolute()
|
|
||||||
db_name = "database_test_cli_cli_generate_module_analysis"
|
|
||||||
|
|
||||||
ctx = build_ctx_from_config_file(output_folder_path)
|
ctx = build_ctx_from_config_file()
|
||||||
# identify main analysis file of openupgrade
|
# identify main analysis file of openupgrade
|
||||||
analysis_file_path = get_odoo_env_path(ctx, {"release": 14.0}) / Path(
|
analysis_file_path = get_odoo_env_path(ctx, {"release": 14.0}) / Path(
|
||||||
"src/openupgrade/openupgrade_scripts/scripts"
|
"src/openupgrade/openupgrade_scripts/scripts"
|
||||||
|
|
@ -28,7 +30,6 @@ def test_cli_generate_module_analysis():
|
||||||
cli_runner_invoke(
|
cli_runner_invoke(
|
||||||
[
|
[
|
||||||
"--log-level=DEBUG",
|
"--log-level=DEBUG",
|
||||||
"--env-folder=%s" % output_folder_path,
|
|
||||||
"generate-module-analysis",
|
"generate-module-analysis",
|
||||||
"--step=2",
|
"--step=2",
|
||||||
"--database=%s" % db_name,
|
"--database=%s" % db_name,
|
||||||
11
tests/data/extra_script/click_odoo_test.py
Normal file
11
tests/data/extra_script/click_odoo_test.py
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
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.")
|
||||||
46
tests/data/extra_script/post-migration-custom_test.py
Normal file
46
tests/data/extra_script/post-migration-custom_test.py
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
# Unused for the time being
|
||||||
|
|
||||||
|
# def _check_orm_usage(self):
|
||||||
|
# # Classic ORM usage Checks
|
||||||
|
# partners = self.browse_by_search("res.partner")
|
||||||
|
|
||||||
|
# self.browse_by_create("res.partner", {"name": "New Partner"})
|
||||||
|
|
||||||
|
# new_partners = self.browse_by_search("res.partner")
|
||||||
|
|
||||||
|
# if len(partners) + 1 != len(new_partners):
|
||||||
|
# raise Exception("Creation of partner failed.")
|
||||||
|
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
def _check_orm_usage(self):
|
|
||||||
# Classic ORM usage Checks
|
|
||||||
partners = self.browse_by_search("res.partner")
|
|
||||||
|
|
||||||
self.browse_by_create("res.partner", {"name": "New Partner"})
|
|
||||||
|
|
||||||
new_partners = self.browse_by_search("res.partner")
|
|
||||||
|
|
||||||
if len(partners) + 1 != len(new_partners):
|
|
||||||
raise Exception("Creation of partner failed.")
|
|
||||||
|
|
||||||
|
|
||||||
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)
|
|
||||||
Loading…
Reference in New Issue
Block a user