mirror of https://github.com/sipwise/ngcpcfg.git
By setting variables like CONFIG_POOL and TEMPLATE_POOL_BASE we can generate templates on-the-fly, without having to provide any static files as fixtures. Modify t/fixtures/*.cfg accordingly, by checking if a variable is set already (via any tests) and only if it's unset set a default. Change-Id: Ia156447bca368b19e62e94eee81c3949f00aa39achanges/99/17699/6
parent
a2a8b52f13
commit
1b65ad2072
@ -1,37 +1,37 @@
|
||||
# directory name where ngcpcfg is managed through git
|
||||
NGCPCTL_BASE="$(pwd)/"
|
||||
NGCPCTL_MAIN="${NGCPCTL_BASE}/fixtures/repos/"
|
||||
NGCPCTL_CONFIG="${NGCPCTL_MAIN}/config.yml"
|
||||
HOST_CONFIG="${NGCPCTL_MAIN}/config.$(hostname).yml"
|
||||
LOCAL_CONFIG="${NGCPCTL_MAIN}/config.local.yml"
|
||||
CONSTANTS_CONFIG="${NGCPCTL_MAIN}/constants.yml"
|
||||
NETWORK_CONFIG="${NGCPCTL_MAIN}/network.yml"
|
||||
RTP_INTERFACES_CONFIG="/etc/ngcp-rtpengine-daemon/interfaces.yml"
|
||||
EXTRA_CONFIG_DIR="${NGCPCTL_MAIN}/config.d/"
|
||||
[ -n "${NGCPCTL_BASE:-}" ] || NGCPCTL_BASE="$(pwd)/"
|
||||
[ -n "${NGCPCTL_MAIN:-}" ] || NGCPCTL_MAIN="${NGCPCTL_BASE}/fixtures/repos/"
|
||||
[ -n "${NGCPCTL_CONFIG:-}" ] || NGCPCTL_CONFIG="${NGCPCTL_MAIN}/config.yml"
|
||||
[ -n "${HOST_CONFIG:-}" ] || HOST_CONFIG="${NGCPCTL_MAIN}/config.$(hostname).yml"
|
||||
[ -n "${LOCAL_CONFIG:-}" ] || LOCAL_CONFIG="${NGCPCTL_MAIN}/config.local.yml"
|
||||
[ -n "${CONSTANTS_CONFIG:-}" ] || CONSTANTS_CONFIG="${NGCPCTL_MAIN}/constants.yml"
|
||||
[ -n "${NETWORK_CONFIG:-}" ] || NETWORK_CONFIG="${NGCPCTL_MAIN}/network.yml"
|
||||
[ -n "${RTP_INTERFACES_CONFIG:-}" ] || RTP_INTERFACES_CONFIG="/etc/ngcp-rtpengine-daemon/interfaces.yml"
|
||||
[ -n "${EXTRA_CONFIG_DIR:-}" ] || EXTRA_CONFIG_DIR="${NGCPCTL_MAIN}/config.d/"
|
||||
|
||||
# configuration dirs that should be managed
|
||||
CONFIG_POOL='/etc /var'
|
||||
[ -n "${CONFIG_POOL:-}" ] || CONFIG_POOL='/etc /var'
|
||||
|
||||
# location of templates
|
||||
TEMPLATE_POOL_BASE="${NGCPCTL_MAIN}/templates"
|
||||
[ -n "${TEMPLATE_POOL_BASE:-}" ] || TEMPLATE_POOL_BASE="${NGCPCTL_MAIN}/templates"
|
||||
|
||||
# location of service definitions
|
||||
SERVICES_POOL_BASE="${NGCPCTL_MAIN}/templates"
|
||||
[ -n "${SERVICES_POOL_BASE:-}" ] || SERVICES_POOL_BASE="${NGCPCTL_MAIN}/templates"
|
||||
|
||||
# Backward compatibility config for upgrade mr3.4*->mr3.5*
|
||||
# it can be removed when the next LTS is released:
|
||||
TEMPLATE_POOL="${TEMPLATE_POOL_BASE}/etc"
|
||||
SERVICES_POOL="${SERVICES_POOL_BASE}/etc"
|
||||
[ -n "${TEMPLATE_POOL:-}" ] || TEMPLATE_POOL="${TEMPLATE_POOL_BASE}/etc"
|
||||
[ -n "${SERVICES_POOL:-}" ] || SERVICES_POOL="${SERVICES_POOL_BASE}/etc"
|
||||
|
||||
# timestamp format for console output
|
||||
TIME_FORMAT="+%F %T"
|
||||
[ -n "${TIME_FORMAT:-}" ] || TIME_FORMAT="+%F %T"
|
||||
|
||||
# Run-time state directory
|
||||
RUN_DIR='/var/run'
|
||||
[ -n "${RUN_DIR:-}" ] || RUN_DIR='/var/run'
|
||||
|
||||
# directory holding files for internal state of ngcpcfg
|
||||
STATE_FILES_DIR='/var/lib/ngcpcfg/state/'
|
||||
[ -n "${STATE_FILES_DIR:-}" ] || STATE_FILES_DIR='/var/lib/ngcpcfg/state/'
|
||||
|
||||
# validate configs using kwalify schema
|
||||
VALIDATE_SCHEMA="false"
|
||||
[ -n "${VALIDATE_SCHEMA:-}" ] || VALIDATE_SCHEMA="false"
|
||||
## END OF FILE #################################################################
|
||||
|
||||
@ -1,37 +1,37 @@
|
||||
# directory name where ngcpcfg is managed through git
|
||||
NGCPCTL_BASE="$(pwd)/"
|
||||
NGCPCTL_MAIN="${NGCPCTL_BASE}/fixtures/repos/"
|
||||
NGCPCTL_CONFIG="${NGCPCTL_MAIN}/config.yml"
|
||||
HOST_CONFIG="${NGCPCTL_MAIN}/config.$(hostname).yml"
|
||||
LOCAL_CONFIG="${NGCPCTL_MAIN}/config.local.yml"
|
||||
CONSTANTS_CONFIG="${NGCPCTL_MAIN}/constants.yml"
|
||||
NETWORK_CONFIG="${NGCPCTL_MAIN}/network_carrier.yml"
|
||||
RTP_INTERFACES_CONFIG="/etc/ngcp-rtpengine-daemon/interfaces.yml"
|
||||
EXTRA_CONFIG_DIR="${NGCPCTL_MAIN}/config.d/"
|
||||
[ -n "${NGCPCTL_BASE:-}" ] || NGCPCTL_BASE="$(pwd)/"
|
||||
[ -n "${NGCPCTL_MAIN:-}" ] || NGCPCTL_MAIN="${NGCPCTL_BASE}/fixtures/repos/"
|
||||
[ -n "${NGCPCTL_CONFIG:-}" ] || NGCPCTL_CONFIG="${NGCPCTL_MAIN}/config.yml"
|
||||
[ -n "${HOST_CONFIG:-}" ] || HOST_CONFIG="${NGCPCTL_MAIN}/config.$(hostname).yml"
|
||||
[ -n "${LOCAL_CONFIG:-}" ] || LOCAL_CONFIG="${NGCPCTL_MAIN}/config.local.yml"
|
||||
[ -n "${CONSTANTS_CONFIG:-}" ] || CONSTANTS_CONFIG="${NGCPCTL_MAIN}/constants.yml"
|
||||
[ -n "${NETWORK_CONFIG:-}" ] || NETWORK_CONFIG="${NGCPCTL_MAIN}/network_carrier.yml"
|
||||
[ -n "${RTP_INTERFACES_CONFIG:-}" ] || RTP_INTERFACES_CONFIG="/etc/ngcp-rtpengine-daemon/interfaces.yml"
|
||||
[ -n "${EXTRA_CONFIG_DIR:-}" ] || EXTRA_CONFIG_DIR="${NGCPCTL_MAIN}/config.d/"
|
||||
|
||||
# configuration dirs that should be managed
|
||||
CONFIG_POOL='/etc /var'
|
||||
[ -n "${CONFIG_POOL:-}" ] || CONFIG_POOL='/etc /var'
|
||||
|
||||
# location of templates
|
||||
TEMPLATE_POOL_BASE="${NGCPCTL_MAIN}/templates"
|
||||
[ -n "${TEMPLATE_POOL_BASE:-}" ] || TEMPLATE_POOL_BASE="${NGCPCTL_MAIN}/templates"
|
||||
|
||||
# location of service definitions
|
||||
SERVICES_POOL_BASE="${NGCPCTL_MAIN}/templates"
|
||||
[ -n "${SERVICES_POOL_BASE:-}" ] || SERVICES_POOL_BASE="${NGCPCTL_MAIN}/templates"
|
||||
|
||||
# Backward compatibility config for upgrade mr3.4*->mr3.5*
|
||||
# it can be removed when the next LTS is released:
|
||||
TEMPLATE_POOL="${TEMPLATE_POOL_BASE}/etc"
|
||||
SERVICES_POOL="${SERVICES_POOL_BASE}/etc"
|
||||
[ -n "${TEMPLATE_POOL:-}" ] || TEMPLATE_POOL="${TEMPLATE_POOL_BASE}/etc"
|
||||
[ -n "${SERVICES_POOL:-}" ] || SERVICES_POOL="${SERVICES_POOL_BASE}/etc"
|
||||
|
||||
# timestamp format for console output
|
||||
TIME_FORMAT="+%F %T"
|
||||
[ -n "${TIME_FORMAT:-}" ] || TIME_FORMAT="+%F %T"
|
||||
|
||||
# Run-time state directory
|
||||
RUN_DIR='/var/run'
|
||||
[ -n "${RUN_DIR:-}" ] || RUN_DIR='/var/run'
|
||||
|
||||
# directory holding files for internal state of ngcpcfg
|
||||
STATE_FILES_DIR='/var/lib/ngcpcfg/state/'
|
||||
[ -n "${STATE_FILES_DIR:-}" ] || STATE_FILES_DIR='/var/lib/ngcpcfg/state/'
|
||||
|
||||
# validate configs using kwalify schema
|
||||
VALIDATE_SCHEMA="false"
|
||||
[ -n "${VALIDATE_SCHEMA:-}" ] || VALIDATE_SCHEMA="false"
|
||||
## END OF FILE #################################################################
|
||||
|
||||
@ -1,37 +1,37 @@
|
||||
# directory name where ngcpcfg is managed through git
|
||||
NGCPCTL_BASE="$(pwd)/"
|
||||
NGCPCTL_MAIN="${NGCPCTL_BASE}/fixtures/repos/"
|
||||
NGCPCTL_CONFIG="${NGCPCTL_MAIN}/config.yml"
|
||||
HOST_CONFIG="${NGCPCTL_MAIN}/config.$(hostname).yml"
|
||||
LOCAL_CONFIG="${NGCPCTL_MAIN}/config.local.yml"
|
||||
CONSTANTS_CONFIG="${NGCPCTL_MAIN}/constants.yml"
|
||||
NETWORK_CONFIG="${NGCPCTL_MAIN}/network_pro.yml"
|
||||
RTP_INTERFACES_CONFIG="/etc/ngcp-rtpengine-daemon/interfaces.yml"
|
||||
EXTRA_CONFIG_DIR="${NGCPCTL_MAIN}/config.d/"
|
||||
[ -n "${NGCPCTL_BASE:-}" ] || NGCPCTL_BASE="$(pwd)/"
|
||||
[ -n "${NGCPCTL_MAIN:-}" ] || NGCPCTL_MAIN="${NGCPCTL_BASE}/fixtures/repos/"
|
||||
[ -n "${NGCPCTL_CONFIG:-}" ] || NGCPCTL_CONFIG="${NGCPCTL_MAIN}/config.yml"
|
||||
[ -n "${HOST_CONFIG:-}" ] || HOST_CONFIG="${NGCPCTL_MAIN}/config.$(hostname).yml"
|
||||
[ -n "${LOCAL_CONFIG:-}" ] || LOCAL_CONFIG="${NGCPCTL_MAIN}/config.local.yml"
|
||||
[ -n "${CONSTANTS_CONFIG:-}" ] || CONSTANTS_CONFIG="${NGCPCTL_MAIN}/constants.yml"
|
||||
[ -n "${NETWORK_CONFIG:-}" ] || NETWORK_CONFIG="${NGCPCTL_MAIN}/network_pro.yml"
|
||||
[ -n "${RTP_INTERFACES_CONFIG:-}" ] || RTP_INTERFACES_CONFIG="/etc/ngcp-rtpengine-daemon/interfaces.yml"
|
||||
[ -n "${EXTRA_CONFIG_DIR:-}" ] || EXTRA_CONFIG_DIR="${NGCPCTL_MAIN}/config.d/"
|
||||
|
||||
# configuration dirs that should be managed
|
||||
CONFIG_POOL='/etc /var'
|
||||
[ -n "${CONFIG_POOL:-}" ] || CONFIG_POOL='/etc /var'
|
||||
|
||||
# location of templates
|
||||
TEMPLATE_POOL_BASE="${NGCPCTL_MAIN}/templates"
|
||||
[ -n "${TEMPLATE_POOL_BASE:-}" ] || TEMPLATE_POOL_BASE="${NGCPCTL_MAIN}/templates"
|
||||
|
||||
# location of service definitions
|
||||
SERVICES_POOL_BASE="${NGCPCTL_MAIN}/templates"
|
||||
[ -n "${SERVICES_POOL_BASE:-}" ] || SERVICES_POOL_BASE="${NGCPCTL_MAIN}/templates"
|
||||
|
||||
# Backward compatibility config for upgrade mr3.4*->mr3.5*
|
||||
# it can be removed when the next LTS is released:
|
||||
TEMPLATE_POOL="${TEMPLATE_POOL_BASE}/etc"
|
||||
SERVICES_POOL="${SERVICES_POOL_BASE}/etc"
|
||||
[ -n "${TEMPLATE_POOL:-}" ] || TEMPLATE_POOL="${TEMPLATE_POOL_BASE}/etc"
|
||||
[ -n "${SERVICES_POOL:-}" ] || SERVICES_POOL="${SERVICES_POOL_BASE}/etc"
|
||||
|
||||
# timestamp format for console output
|
||||
TIME_FORMAT="+%F %T"
|
||||
[ -n "${TIME_FORMAT:-}" ] || TIME_FORMAT="+%F %T"
|
||||
|
||||
# Run-time state directory
|
||||
RUN_DIR='/var/run'
|
||||
[ -n "${RUN_DIR:-}" ] || RUN_DIR='/var/run'
|
||||
|
||||
# directory holding files for internal state of ngcpcfg
|
||||
STATE_FILES_DIR='/var/lib/ngcpcfg/state/'
|
||||
[ -n "${STATE_FILES_DIR:-}" ] || STATE_FILES_DIR='/var/lib/ngcpcfg/state/'
|
||||
|
||||
# validate configs using kwalify schema
|
||||
VALIDATE_SCHEMA="false"
|
||||
[ -n "${VALIDATE_SCHEMA:-}" ] || VALIDATE_SCHEMA="false"
|
||||
## END OF FILE #################################################################
|
||||
|
||||
@ -0,0 +1,104 @@
|
||||
#!/usr/bin/env py.test-3
|
||||
|
||||
import os
|
||||
import pytest
|
||||
import re
|
||||
import tempfile
|
||||
|
||||
|
||||
@pytest.mark.tt_24920
|
||||
def test_patch_action_no_args(ngcpcfgcli, tmpdir):
|
||||
out = ngcpcfgcli("patch",
|
||||
env={
|
||||
'NGCP_PORTFILE': '/tmp/ngcpcfg.port',
|
||||
})
|
||||
string = r"Patch operation has finished successfully."
|
||||
assert string in out.stdout
|
||||
|
||||
|
||||
@pytest.mark.tt_24920
|
||||
def test_patch_action_generate_customtt_via_patch_file(ngcpcfgcli, tmpdir):
|
||||
template_path = tmpdir.join('/etc')
|
||||
apt_path = template_path.join('/apt/apt.conf.d')
|
||||
os.makedirs(str(apt_path), exist_ok=True)
|
||||
|
||||
tt2 = apt_path.join('71_no_recommended.tt2')
|
||||
tt2.write('''
|
||||
APT::Install-Recommends "0";
|
||||
''')
|
||||
|
||||
patchtt = apt_path.join("71_no_recommended.patchtt.tt2")
|
||||
patchtt.write('''
|
||||
--- 71_no_recommended.tt2.orig 2017-12-08 13:31:49.763402557 +0100
|
||||
+++ 71_no_recommended.tt2 2017-12-08 13:32:00.559382702 +0100
|
||||
@@ -1,2 +1 @@
|
||||
-
|
||||
-APT::Install-Recommends "0";
|
||||
+APT::Install-Recommends "1";
|
||||
''')
|
||||
out = ngcpcfgcli("patch",
|
||||
"/etc/apt/apt.conf.d/",
|
||||
env={
|
||||
'NGCP_BASE_TT2': os.getcwd(),
|
||||
'NGCP_PORTFILE': '/tmp/ngcpcfg.port',
|
||||
'OUTPUT_DIRECTORY': str(tmpdir),
|
||||
'TEMPLATE_POOL_BASE': str(tmpdir),
|
||||
'CONFIG_POOL': '/etc',
|
||||
})
|
||||
|
||||
assert 'Validating patch' in out.stdout
|
||||
assert '71_no_recommended.customtt.tt2' in out.stdout
|
||||
assert 'Patch operation has finished successfully.' in out.stdout
|
||||
|
||||
generated_customtt = str(tmpdir) + \
|
||||
'/etc/apt/apt.conf.d/71_no_recommended.customtt.tt2'
|
||||
|
||||
assert os.path.isfile(generated_customtt)
|
||||
with open(generated_customtt) as customtt:
|
||||
customtt_output = customtt.read()
|
||||
assert customtt_output == '''APT::Install-Recommends "1";\n'''
|
||||
|
||||
|
||||
@pytest.mark.tt_24920
|
||||
def test_patch_action_customtt_does_not_trigger_patch_file(ngcpcfgcli, tmpdir):
|
||||
template_path = tmpdir.join('/etc')
|
||||
apt_path = template_path.join('/apt/apt.conf.d')
|
||||
os.makedirs(str(apt_path), exist_ok=True)
|
||||
|
||||
tt2 = apt_path.join('71_no_recommended.tt2')
|
||||
tt2.write('''
|
||||
APT::Install-Recommends "0";
|
||||
''')
|
||||
|
||||
expected_output = '''
|
||||
# generated via customtt without patch file
|
||||
APT::Install-Recommends "1";
|
||||
'''
|
||||
|
||||
customtt = apt_path.join("71_no_recommended.customtt.tt2")
|
||||
customtt.write(expected_output)
|
||||
|
||||
out = ngcpcfgcli("build", "--ignore-branch-check",
|
||||
"/etc/apt/apt.conf.d/",
|
||||
env={
|
||||
'NGCP_BASE_TT2': os.getcwd(),
|
||||
'NGCP_PORTFILE': '/tmp/ngcpcfg.port',
|
||||
'OUTPUT_DIRECTORY': str(tmpdir) + "/output",
|
||||
'TEMPLATE_POOL_BASE': str(tmpdir),
|
||||
'CONFIG_POOL': '/etc',
|
||||
})
|
||||
|
||||
assert 'Patch operation has finished successfully.' in out.stdout
|
||||
assert 'Generating ' in out.stdout
|
||||
assert '/etc/apt/apt.conf.d/71_no_recommended: OK' in out.stdout
|
||||
assert 'Validating patch' not in out.stdout
|
||||
assert '71_no_recommended.customtt.tt2' not in out.stdout
|
||||
|
||||
generated_config = str(tmpdir) + "/output" + str(tmpdir) + \
|
||||
'/etc/apt/apt.conf.d/71_no_recommended'
|
||||
|
||||
assert os.path.isfile(generated_config)
|
||||
with open(generated_config) as output_file:
|
||||
output = output_file.read()
|
||||
assert output == expected_output
|
||||
# assert 0, out
|
||||
Loading…
Reference in new issue