DCD-1467: Add code and test to enable forced overwrite of the config file where appropriate.

This commit is contained in:
Steve Smith 2022-04-19 12:32:43 +10:00
parent 63f8c95cd3
commit d22949ea9d
2 changed files with 32 additions and 2 deletions

View File

@ -1,12 +1,13 @@
#!/usr/bin/python3 -B #!/usr/bin/python3 -B
from entrypoint_helpers import env, gen_cfg, str2bool, exec_app from entrypoint_helpers import env, gen_cfg, str2bool_or, exec_app
RUN_USER = env['run_user'] RUN_USER = env['run_user']
RUN_GROUP = env['run_group'] RUN_GROUP = env['run_group']
CONFLUENCE_INSTALL_DIR = env['confluence_install_dir'] CONFLUENCE_INSTALL_DIR = env['confluence_install_dir']
CONFLUENCE_HOME = env['confluence_home'] CONFLUENCE_HOME = env['confluence_home']
UPDATE_CFG = str2bool_or(env.get('atl_force_cfg_update'), False)
gen_cfg('server.xml.j2', f'{CONFLUENCE_INSTALL_DIR}/conf/server.xml') gen_cfg('server.xml.j2', f'{CONFLUENCE_INSTALL_DIR}/conf/server.xml')
gen_cfg('seraph-config.xml.j2', gen_cfg('seraph-config.xml.j2',
@ -14,7 +15,7 @@ gen_cfg('seraph-config.xml.j2',
gen_cfg('confluence-init.properties.j2', gen_cfg('confluence-init.properties.j2',
f'{CONFLUENCE_INSTALL_DIR}/confluence/WEB-INF/classes/confluence-init.properties') f'{CONFLUENCE_INSTALL_DIR}/confluence/WEB-INF/classes/confluence-init.properties')
gen_cfg('confluence.cfg.xml.j2', f'{CONFLUENCE_HOME}/confluence.cfg.xml', gen_cfg('confluence.cfg.xml.j2', f'{CONFLUENCE_HOME}/confluence.cfg.xml',
user=RUN_USER, group=RUN_GROUP, overwrite=False) user=RUN_USER, group=RUN_GROUP, overwrite=UPDATE_CFG)
exec_app([f'{CONFLUENCE_INSTALL_DIR}/bin/start-confluence.sh', '-fg'], CONFLUENCE_HOME, exec_app([f'{CONFLUENCE_INSTALL_DIR}/bin/start-confluence.sh', '-fg'], CONFLUENCE_HOME,
name='Confluence', env_cleanup=True) name='Confluence', env_cleanup=True)

View File

@ -444,6 +444,7 @@ def test_confluence_xml_snapshot_properties(docker_cli, image, run_user):
assert xml.findall('.//buildNumber')[0].text == "8703" assert xml.findall('.//buildNumber')[0].text == "8703"
assert xml.findall('.//property[@name="hibernate.setup"]')[0].text == "true" assert xml.findall('.//property[@name="hibernate.setup"]')[0].text == "true"
def test_confluence_xml_no_overwrite(docker_cli, image, run_user): def test_confluence_xml_no_overwrite(docker_cli, image, run_user):
environment = { environment = {
'ATL_TOMCAT_CONTEXTPATH': 'myconf', 'ATL_TOMCAT_CONTEXTPATH': 'myconf',
@ -467,3 +468,31 @@ def test_confluence_xml_no_overwrite(docker_cli, image, run_user):
xml = parse_xml(tihost, cfg) xml = parse_xml(tihost, cfg)
assert xml.findall('.//property[@name="confluence.webapp.context.path"]')[0].text == "/otherval" assert xml.findall('.//property[@name="confluence.webapp.context.path"]')[0].text == "/otherval"
def test_confluence_xml_force_overwrite(docker_cli, image, run_user):
environment = {
'ATL_TOMCAT_CONTEXTPATH': 'myconf',
'ATL_FORCE_CFG_UPDATE': 'y',
}
container = docker_cli.containers.run(image, detach=True, user=run_user, environment=environment)
tihost = testinfra.get_host("docker://"+container.id)
cfg = f'{get_app_home(tihost)}/confluence.cfg.xml'
_jvm = wait_for_proc(tihost, get_bootstrap_proc(tihost))
xml = parse_xml(tihost, cfg)
assert xml.findall('.//property[@name="confluence.webapp.context.path"]')[0].text == "/myconf"
container.exec_run(f"sed -i 's/myconf/otherval/' {cfg}")
xml = parse_xml(tihost, cfg)
assert xml.findall('.//property[@name="confluence.webapp.context.path"]')[0].text == "/otherval"
container.stop(timeout=60)
container.start()
_jvm = wait_for_proc(tihost, get_bootstrap_proc(tihost))
xml = parse_xml(tihost, cfg)
assert xml.findall('.//property[@name="confluence.webapp.context.path"]')[0].text == "/myconf"