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', "quay.io/vauxoo"),
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):
config.update({
'with_demo': True,
'without_demo': True
})
common.pull_images([config['instance_image'],
config['postgres_image']])
......
......@@ -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()]):
missing.append(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):
image=customer_img)
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')))
else:
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', 'quay.io')})
res.update({'image_repo_url': res.get('image_repo_url', 'quay.io/vauxoo')})
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)})
res.update({
'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'),
config['postgres_image'])
raise
_logger.info('Starting container %s', config['postgres_container'])
container = _cli.create_container(image=config['postgres_image'],
name=config['postgres_container'],
environment={'POSTGRES_PASSWORD': 'postgres'})
_cli.start(container=container.get('Id'))
check_cmd = "psql -c \"select version();\""
retry = 1
container = None
while retry <= 3:
_logger.info('Starting container %s (try %s / 3)', config['postgres_container'], retry)
container = _cli.create_container(image=config['postgres_image'],
name=config['postgres_container'],
environment={'POSTGRES_PASSWORD': 'postgres'})
_cli.start(container=container.get('Id'))
time.sleep(3)
res = exec_cmd(config['postgres_container'], check_cmd, 'postgres')
_logger.info('Testing container: %s', res)
if 'the database system is shutting down' in res:
_logger.info('Error starting postgres container: %s', res)
_logger.info('Retry: %s', retry)
_cli.remove_container(container['Id'], force=True)
retry += 1
else:
break
_logger.info(container)
......@@ -423,38 +438,49 @@ def is_running(config):
time.sleep(5)
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)
)
_logger.info('Verifying supervisorctl')
is_running(config)
_logger.info('Stopping odoo')
exec_cmd(config['container_name'], 'supervisorctl stop odoo')
_logger.info('\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)
_logger.info('\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]:
_logger.info('\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):
_logger.info('\n%s', title)
_logger.info('='*20)
......@@ -522,6 +548,6 @@ def run_image_tests(config):
resp = create_postgres_user(config)
_logger.info(resp)
start_instance(config)
res = install_module(config)
res = run_image_tests(config)
clean_containers(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