Commit 98434ed5 authored by Tulio Ruiz's avatar Tulio Ruiz
Browse files

[IMP] Allow to test the install with and without demo

[FIX] These options are flags

[FIX] Random error that blocks postgres container to start

[FIX] Use job id instead of the pipeline in case we have containers running in parallel

[FIX] Naming convention

[REF] Refactor install functions
parent c965df74
Pipeline #66251 passed with stage
in 31 seconds
......@@ -44,9 +44,17 @@ signal.signal(signal.SIGINT, common.reciveSignal)
@click.option('--image_repo_url', default=environ.get('IMAGE_REPO_URL', ""),
help=("The URL where the image repository is located."
" Env var: IMAGE_REPO_URL."))
@click.option('--with_demo', default=False, is_flag=True,
help="Test the image with data demo only")
@click.option('--without_demo', default=False, is_flag=True,
help="Test the image without data demo only")
def test_image(**kwargs):
config = common.prepare(**kwargs)
if not config.get('with_demo', False) and not config.get('without_demo', False):
'with_demo': True,
'without_demo': True
......@@ -34,7 +34,7 @@ def pull_images(images):
def check_env_vars(*args, **kwargs):
missing = []
not_required = ['psql_image', 'push_image', 'install']
not_required = ['psql_image', 'push_image', 'install', 'without_demo', 'with_demo']
for key in args:
if key not in not_required and not (key.upper() in environ and environ[key.upper()]):
......@@ -172,7 +172,7 @@ def get_config(**kwargs):
res.update({'private_deploy_key': res.get('private_deploy_key', False)})
img_name = generate_image_name('{0}_{1}'.format(
res['ci_commit_ref_name'], res['ci_job_id']))
res['ci_commit_ref_name'], res['ci_pipeline_id']))
res.update({'base_name': img_name})
if res.get('psql_image'):
......@@ -190,7 +190,7 @@ def get_config(**kwargs):
res.update({'image_repo': image_repo})
instance_image = generate_image_name('instance{0}_{1}'.format(
res.get('base_name'), res.get('ci_pipeline_id')))
res.get('base_name'), res.get('ci_job_id')))
instance_image = '{}:{}'.format(res['image_repo'], res['image_tag'])
......@@ -200,12 +200,13 @@ def get_config(**kwargs):
'customer': customer,
'version_tag': version_tag,
'customer_img': customer_img,
'container_name': '{}_instance_{}_{}'.format(res['base_name'], res['ci_pipeline_id'], rand_str)
'container_name': '{}_instance_{}_{}'.format(res['base_name'], res['ci_job_id'], rand_str)
res.update({'docker_repo': res.get('docker_repo', '')})
res.update({'image_repo_url': res.get('image_repo_url', '')})
res.update({'postgres_container': 'postgres{0}_{1}_{2}'.format(res['base_name'], res['ci_pipeline_id'], rand_str)})
res.update({'postgres_container': 'postgres{0}_{1}_{2}'.format(
res['base_name'], res['ci_job_id'], rand_str)})
'main_app': get_main_app(res)
......@@ -353,11 +354,25 @@ def start_postgres(config):
' Make sure variables are properly set and that the Psql version exists'),
raise'Starting container %s', config['postgres_container'])
container = _cli.create_container(image=config['postgres_image'],
environment={'POSTGRES_PASSWORD': 'postgres'})
check_cmd = "psql -c \"select version();\""
retry = 1
container = None
while retry <= 3:'Starting container %s (try %s / 3)', config['postgres_container'], retry)
container = _cli.create_container(image=config['postgres_image'],
environment={'POSTGRES_PASSWORD': 'postgres'})
res = exec_cmd(config['postgres_container'], check_cmd, 'postgres')'Testing container: %s', res)
if 'the database system is shutting down' in res:'Error starting postgres container: %s', res)'Retry: %s', retry)
_cli.remove_container(container['Id'], force=True)
retry += 1
......@@ -423,38 +438,49 @@ def is_running(config):
def install_module(config):
def install_module(config, wdemo=False):
module = config['main_app']
extra = ''
if config.get('language', False):
extra += ' --load-language={lang}'.format(lang=config.get('language'))
install_wdemo = (
"/home/odoo/instance/odoo/odoo-bin -d wdemo -i {mod}"
"{extra} --stop-after-init".format(mod=module, extra=extra)
install_wodemo = (
"/home/odoo/instance/odoo/odoo-bin -d wodemo -i {mod}"
"{extra} --stop-after-init --without-demo=all".format(mod=module, extra=extra)
demo = 'wodemo --without-demo=all '
msg = 'without demo'
if not wdemo:
demo = 'wdemo '
msg = 'with demo'
install_cmd = (
"/home/odoo/instance/odoo/odoo-bin -d {demo} -i {mod}"
"{extra} --stop-after-init".format(mod=module, extra=extra, demo=demo)
)'Verifying supervisorctl')
is_running(config)'Stopping odoo')
exec_cmd(config['container_name'], 'supervisorctl stop odoo')'\nInstalling %s with demo', module)
_logger.debug('Command : %s', install_wdemo)
wdemo_res = exec_cmd(config['container_name'], install_wdemo, 'odoo', stream=True)
wdemo_log = resume_log(wdemo_res)'\nInstalling %s without demo', module)
_logger.debug('Command : %s', install_wodemo)
wodemo_res = exec_cmd(config['container_name'], install_wodemo, 'odoo', stream=True)
wodemo_log = resume_log(wodemo_res)
show_log(wdemo_log[1], 'Installation with demo')
show_log(wodemo_log[1], 'Installation without demo')
if not wdemo_log[0] or not wodemo_log[0]:'\nInstalling %s %s', module, msg)
_logger.debug('Command : %s', install_cmd)
exec_res = exec_cmd(config['container_name'], install_cmd, 'odoo', stream=True)
log = resume_log(exec_res)
show_log(log[1], 'Installation {}'.format(msg))
if not log[0]:
return False
return True
def run_image_tests(config):
wdemo_res = not config.get('with_demo')
wodemo_res = not config.get('without_demo')
if config.get('with_demo'):
wdemo_res = install_module(config, wdemo=True)
if config.get('without_demo'):
wodemo_res = install_module(config)
return wdemo_res and wodemo_res
def show_log(log, title):'\n%s', title)'='*20)
......@@ -522,6 +548,6 @@ def run_image_tests(config):
resp = create_postgres_user(config)
res = install_module(config)
res = run_image_tests(config)
return res
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment