@ -5,6 +5,9 @@ import pytest
import re
import tempfile
###############################################################################
# tests for "ngcpcfg patch" (no options provides)
###############################################################################
@pytest.mark.tt_24920
def test_patch_action_no_args ( ngcpcfgcli , tmpdir ) :
@ -19,7 +22,7 @@ def test_patch_action_no_args(ngcpcfgcli, tmpdir):
@pytest.mark.tt_24920
def test_patch_action_help ( ngcpcfgcli , tmpdir ) :
# ensure 'ngcpcfg patch ' assert on corrupted patchtt file
# ensure 'ngcpcfg patch --help' works as expected
template_path = tmpdir . join ( ' /etc ' )
apt_path = template_path . join ( ' /apt/apt.conf.d ' )
@ -50,7 +53,7 @@ APT::Install-Recommends "0";
assert " ' ngcpcfg patch ' walks through all templates " in out . stdout
assert " Validating patch " not in out . stdout
assert ' Patch operation has finished successfully.' not in out . stdout
assert ' Requested patchtt operation has finished successfully.' not in out . stdout
assert out . stderr == " b ' ' "
@ -87,7 +90,7 @@ APT::Install-Recommends "0";
assert " Validating patch ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.patchtt.tt2 ' " in out . stdout
assert ' Patch operation has finished successfully.' in out . stdout
assert ' Requested patchtt operation has finished successfully.' in out . stdout
assert out . stderr == " b ' ' "
generated_customtt = str ( tmpdir ) + \
@ -134,8 +137,8 @@ APT::Install-Recommends "0";
" /apt/apt.conf.d/71_no_recommended.patchtt.tt2 ' " in out . stdout
assert " Error: The patch ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.patchtt.tt2 ' cannot be applied " in out . stderr
assert " Error: Some operations above finished with an error for the patch(e s)" in out . stderr
assert ' Patch operation has finished successfully.' not in out . stdout
assert " Error: Some operations above finished with an error for the file( s)" in out . stderr
assert ' Requested patchtt operation has finished successfully.' not in out . stdout
# TODO: ensure no customtt.tt2 were generated
@ -154,7 +157,7 @@ def test_patch_action_template_missing_for_patchtt(ngcpcfgcli, tmpdir):
@ @ - 1 , 2 + 1 @ @
-
- the changes here
+ doesn ' t matter as no t tt2 file available
+ doesn ' t matter as no tt2 file available
''' )
out = ngcpcfgcli ( " patch " ,
@ -171,8 +174,8 @@ def test_patch_action_template_missing_for_patchtt(ngcpcfgcli, tmpdir):
" /apt/apt.conf.d/71_no_recommended.patchtt.tt2 ' " in out . stdout
assert " Error: Missing template for patch ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.patchtt.tt2 ' " in out . stderr
assert " Error: Some operations above finished with an error for the patch(e s)" in out . stderr
assert ' Patch operation has finished successfully.' not in out . stdout
assert " Error: Some operations above finished with an error for the file( s)" in out . stderr
assert ' Requested patchtt operation has finished successfully.' not in out . stdout
@pytest.mark.tt_24920
@ -226,7 +229,72 @@ APT::Install-Recommends "0";
assert " Successfully created ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.customtt.tt2 ' " in out . stdout
assert ' 72_another_file.customtt.tt2 ' not in out . stdout
assert ' Patch operation has finished successfully. ' in out . stdout
assert ' Requested patchtt operation has finished successfully. ' in out . stdout
assert out . stderr == " b ' ' "
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 '''
# TODO ensure file '/etc/apt/apt.conf.d/72_another_file.tt2' was not created
@pytest.mark.tt_24920
def test_patch_action_generate_requested_customtt_only_shortname ( ngcpcfgcli , tmpdir ) :
# ensure 'ngcpcfg patch .../some.patchtt.tt2' will build one
# requested patchtt only using the short filename
template_path = tmpdir . join ( ' /etc ' )
apt_path = template_path . join ( ' /apt/apt.conf.d ' )
os . makedirs ( str ( apt_path ) , exist_ok = True )
apt_path . join ( ' 71_no_recommended.tt2 ' ) . write ( '''
APT : : Install - Recommends " 0 " ;
''' )
apt_path . join ( " 71_no_recommended.patchtt.tt2 " ) . 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 " ;
''' )
apt_path . join ( ' 72_another_file.tt2 ' ) . write ( '''
# This is a dummy message you should not see
''' )
apt_path . join ( " 72_another_file.patchtt.tt2 " ) . 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 @ @
-
- # This is a dummy message you should not see
+ # This is a dummy message you should not see on 'ngcpcfg build'
''' )
out = ngcpcfgcli ( " patch " ,
" 71_no_recommended.patchtt.tt2 " ,
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 ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.patchtt.tt2 ' " in out . stdout
assert " Applying patch ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.patchtt.tt2 ' " in out . stdout
assert " Successfully created ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.customtt.tt2 ' " in out . stdout
assert ' 72_another_file.customtt.tt2 ' not in out . stdout
assert ' Requested patchtt operation has finished successfully. ' in out . stdout
assert out . stderr == " b ' ' "
generated_customtt = str ( tmpdir ) + \
@ -269,15 +337,18 @@ APT::Install-Recommends "0";
def test_patch_action_build_generate_and_overwrite_customtt_file ( ngcpcfgcli , tmpdir ) :
# Ensure here "ngcpcfg build" will:
# * find available patchtt file
# * validate available patchtt file
# * validate available patchtt file (necessary only)
# * use available patchtt file
# * generate proper customtt file using tt2 + patchtt
# * overwrite old/available customtt file
# * build proper config using new customtt file
# * care about patchtt.tt2.sp1 file
# * generate proper customtt files using tt2 + patchtt
# * overwrite old/available customtt files
# * build proper config using new customtt files
template_path = tmpdir . join ( ' /etc ' )
apt_path = template_path . join ( ' /apt/apt.conf.d ' )
dummy_path = template_path . join ( ' /dummy ' )
os . makedirs ( str ( apt_path ) , exist_ok = True )
os . makedirs ( str ( dummy_path ) , exist_ok = True )
apt_path . join ( ' 71_no_recommended.tt2 ' ) . write ( '''
APT : : Install - Recommends " 0 " ;
@ -288,6 +359,10 @@ APT::Install-Recommends "0";
APT : : Install - Recommends " 2 " ;
''' )
expected_output = '''
APT : : Install - Recommends " 1 " ;
'''
apt_path . join ( " 71_no_recommended.patchtt.tt2 " ) . write ( '''
- - - 71 _no_recommended . tt2 . orig 2018 - 01 - 10 15 : 24 : 06.951855880 + 0100
+ + + 71 _no_recommended . tt2 2018 - 01 - 10 15 : 27 : 14.891237633 + 0100
@ -297,9 +372,36 @@ APT::Install-Recommends "2";
''' )
expected_output = '''
apt_path . join ( ' 71_no_recommended.customtt.tt2.sp1 ' ) . write ( '''
# generated via customtt.sp1 without patch file
APT : : Install - Recommends " 3 " ;
''' )
apt_path . join ( " 71_no_recommended.patchtt.tt2.sp1 " ) . write ( '''
@ @ - 1 + 1 @ @
- APT : : Install - Recommends " 0 " ;
+ APT : : Install - Recommends " 3 " ;
''' )
expected_output_sp1 = '''
APT : : Install - Recommends " 1 " ;
'''
dummy_path . join ( ' dummy.tt2 ' ) . write ( '''
dome dummy template message
''' )
dummy_path . join ( ' dummy.customtt.tt2 ' ) . write ( '''
dome dummy customtt message
''' )
dummy_path . join ( " dummy.patchtt.tt2 " ) . write ( '''
@ @ - 1 + 1 @ @
- dome dummy template message
+ dome dummy customtt message
''' )
out = ngcpcfgcli ( " build " , " --ignore-branch-check " ,
" /etc/apt/apt.conf.d/ " ,
env = {
@ -311,13 +413,20 @@ APT::Install-Recommends "1";
} )
assert ' No patchtt files found, nothing to patch. ' not in out . stdout
assert ' dummy ' not in out . stdout
assert " Validating patch ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.patchtt.tt2 ' " in out . stdout
assert " Validating patch ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.patchtt.tt2.sp1 ' " in out . stdout
assert " Applying patch ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.patchtt.tt2 ' " in out . stdout
assert " Successfully created ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.customtt.tt2 ' " in out . stdout
assert ' Patch operation has finished successfully. ' in out . stdout
assert " Applying patch ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.patchtt.tt2.sp1 ' " in out . stdout
assert " Successfully created ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.customtt.tt2.sp1 ' " in out . stdout
assert ' Requested patchtt operation has finished successfully. ' in out . stdout
assert " Generating " + str ( tmpdir ) + " /output/ " + str ( tmpdir ) + \
" //etc/apt/apt.conf.d/71_no_recommended: OK " in out . stdout
# disabled for the moment, see https://gerrit.mgm.sipwise.com/#/c/17739/4/t/test_ngcpcfg_patch.py@99
@ -331,6 +440,136 @@ APT::Install-Recommends "1";
output = output_file . read ( )
assert output == expected_output
generated_customtt_sp1 = str ( template_path ) + \
' /apt/apt.conf.d/71_no_recommended.customtt.tt2.sp1 '
assert os . path . isfile ( generated_customtt )
with open ( generated_customtt ) as output_file :
output = output_file . read ( )
assert output == expected_output_sp1
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
@pytest.mark.tt_24920
def test_patch_action_build_generate_all_file ( ngcpcfgcli , tmpdir ) :
# the same as test 'test_patch_action_build_generate_and_overwrite_customtt_file'
# while build all available files
template_path = tmpdir . join ( ' /etc ' )
apt_path = template_path . join ( ' /apt/apt.conf.d ' )
dummy_path = template_path . join ( ' /dummy ' )
os . makedirs ( str ( apt_path ) , exist_ok = True )
os . makedirs ( str ( dummy_path ) , exist_ok = True )
apt_path . join ( ' 71_no_recommended.tt2 ' ) . write ( '''
APT : : Install - Recommends " 0 " ;
''' )
apt_path . join ( ' 71_no_recommended.customtt.tt2 ' ) . write ( '''
# generated via customtt without patch file
APT : : Install - Recommends " 2 " ;
''' )
expected_output = '''
APT : : Install - Recommends " 1 " ;
'''
apt_path . join ( " 71_no_recommended.patchtt.tt2 " ) . write ( '''
- - - 71 _no_recommended . tt2 . orig 2018 - 01 - 10 15 : 24 : 06.951855880 + 0100
+ + + 71 _no_recommended . tt2 2018 - 01 - 10 15 : 27 : 14.891237633 + 0100
@ @ - 1 + 1 @ @
- APT : : Install - Recommends " 0 " ;
+ APT : : Install - Recommends " 1 " ;
''' )
apt_path . join ( ' 71_no_recommended.customtt.tt2.sp1 ' ) . write ( '''
# generated via customtt.sp1 without patch file
APT : : Install - Recommends " 3 " ;
''' )
apt_path . join ( " 71_no_recommended.patchtt.tt2.sp1 " ) . write ( '''
@ @ - 1 + 1 @ @
- APT : : Install - Recommends " 0 " ;
+ APT : : Install - Recommends " 3 " ;
''' )
expected_output_sp1 = '''
APT : : Install - Recommends " 1 " ;
'''
dummy_path . join ( ' dummy.tt2 ' ) . write ( '''
dome dummy template message
''' )
dummy_path . join ( ' dummy.customtt.tt2 ' ) . write ( '''
dome dummy customtt message
''' )
dummy_path . join ( " dummy.patchtt.tt2 " ) . write ( '''
@ @ - 1 + 1 @ @
- dome dummy template message
+ dome dummy customtt message
''' )
out = ngcpcfgcli ( " build " , " --ignore-branch-check " ,
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 ' No patchtt files found, nothing to patch. ' not in out . stdout
assert " Validating patch ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.patchtt.tt2 ' " in out . stdout
assert " Validating patch ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.patchtt.tt2.sp1 ' " in out . stdout
assert " Validating patch ' " + str ( template_path ) + \
" /dummy/dummy.patchtt.tt2 ' " in out . stdout
assert " Applying patch ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.patchtt.tt2 ' " in out . stdout
assert " Successfully created ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.customtt.tt2 ' " in out . stdout
assert " Applying patch ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.patchtt.tt2.sp1 ' " in out . stdout
assert " Successfully created ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.customtt.tt2.sp1 ' " in out . stdout
assert " Applying patch ' " + str ( template_path ) + \
" /dummy/dummy.patchtt.tt2 ' " in out . stdout
assert " Successfully created ' " + str ( template_path ) + \
" /dummy/dummy.customtt.tt2 ' " in out . stdout
assert ' Requested patchtt operation has finished successfully. ' in out . stdout
assert " Generating " + str ( tmpdir ) + " /output/ " + str ( tmpdir ) + \
" //etc/apt/apt.conf.d/71_no_recommended: OK " in out . stdout
# disabled for the moment, see https://gerrit.mgm.sipwise.com/#/c/17739/4/t/test_ngcpcfg_patch.py@99
#assert out.stderr == "b''"
generated_customtt = str ( template_path ) + \
' /apt/apt.conf.d/71_no_recommended.customtt.tt2 '
assert os . path . isfile ( generated_customtt )
with open ( generated_customtt ) as output_file :
output = output_file . read ( )
assert output == expected_output
generated_customtt_sp1 = str ( template_path ) + \
' /apt/apt.conf.d/71_no_recommended.customtt.tt2.sp1 '
assert os . path . isfile ( generated_customtt )
with open ( generated_customtt ) as output_file :
output = output_file . read ( )
assert output == expected_output_sp1
generated_config = str ( tmpdir ) + " /output " + str ( tmpdir ) + \
' /etc/apt/apt.conf.d/71_no_recommended '
@ -372,7 +611,7 @@ APT::Install-Recommends "1";
} )
assert ' No patchtt files found, nothing to patch. ' in out . stdout
assert ' Patch operation has finished successfully.' not in out . stdout
assert ' Requested patchtt operation has finished successfully.' not 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
@ -424,7 +663,183 @@ APT::Install-Recommends "0";
" /apt/apt.conf.d/71_no_recommended.patchtt.tt2 ' " in out . stdout
assert " Error: The patch ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.patchtt.tt2 ' cannot be applied " in out . stderr
assert " Error: Some operations above finished with an error for the patch(e s)" in out . stderr
assert ' Patch operation has finished successfully.' not in out . stdout
assert " Error: Some operations above finished with an error for the file( s)" in out . stderr
assert ' Requested patchtt operation has finished successfully.' not in out . stdout
assert ' Generating ' not in out . stdout
assert ' /etc/apt/apt.conf.d/71_no_recommended: OK ' not in out . stdout
###############################################################################
# tests for "ngcpcfg patch --from-customtt"
###############################################################################
@pytest.mark.tt_24920
def test_patch_action_from_customtt_files ( ngcpcfgcli , tmpdir ) :
# Ensure here "ngcpcfg patch --from-customtt" will:
# * find all available customtt file
# * create all necessary patchtt files
template_path = tmpdir . join ( ' /etc ' )
apt_path = template_path . join ( ' /apt/apt.conf.d ' )
os . makedirs ( str ( apt_path ) , exist_ok = True )
apt_path . join ( ' 71_no_recommended.tt2 ' ) . write ( '''
# some comment
APT : : Install - Recommends " 0 " ;
''' )
apt_path . join ( ' 71_no_recommended.customtt.tt2 ' ) . write ( '''
# some comment
APT : : Install - Recommends " 2 " ;
''' )
template_path . join ( ' expected_patch.diff ' ) . write ( ''' @@ -1,3 +1,3 @@
# some comment
- APT : : Install - Recommends " 0 " ;
+ APT : : Install - Recommends " 2 " ;
''' )
out = ngcpcfgcli ( " patch " , " --from-customtt " ,
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 ' No patchtt files found, nothing to patch. ' not in out . stdout
assert " Validating customtt ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.customtt.tt2 ' " in out . stdout
assert " Creating patchtt file ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.patchtt.tt2 ' " in out . stdout
assert ' Requested customtt operation has finished successfully. ' in out . stdout
# disabled for the moment, see https://gerrit.mgm.sipwise.com/#/c/17739/4/t/test_ngcpcfg_patch.py@99
#assert out.stderr == "b''"
generated_patchtt = str ( template_path ) + \
' /apt/apt.conf.d/71_no_recommended.patchtt.tt2 '
expected_patchtt = str ( template_path ) + \
' /expected_patch.diff '
assert os . path . isfile ( generated_patchtt )
assert os . path . isfile ( expected_patchtt )
with open ( generated_patchtt ) as output_file :
output = output_file . read ( )
with open ( expected_patchtt ) as expected_file :
expected = expected_file . read ( )
assert output == expected
@pytest.mark.tt_24920
def test_patch_action_from_customtt_missing_file_argument ( ngcpcfgcli , tmpdir ) :
# ensure "ngcpcfg patch --from-customtt missing.customtt.tt2" will be handled properly if
# no some.customtt.tt2 file are available
out = ngcpcfgcli ( " patch " ,
" --from-customtt " ,
" missing.customtt.tt2 " ,
env = {
' NGCP_BASE_TT2 ' : os . getcwd ( ) ,
' NGCP_PORTFILE ' : ' /tmp/ngcpcfg.port ' ,
' OUTPUT_DIRECTORY ' : str ( tmpdir ) ,
' TEMPLATE_POOL_BASE ' : str ( tmpdir ) ,
' CONFIG_POOL ' : ' /etc ' ,
} )
assert ' No customtt files found, nothing to patch. ' in out . stdout
assert " Creating patchtt file ' " not in out . stdout
# disabled for the moment, see https://gerrit.mgm.sipwise.com/#/c/17739/4/t/test_ngcpcfg_patch.py@99
#assert out.stderr == "b''"
@pytest.mark.tt_24920
def test_patch_action_from_customtt_filename_only ( ngcpcfgcli , tmpdir ) :
# ensure "ngcpcfg patch --from-customtt valid.customtt.tt2" will be handled properly if
# no filename only valid.customtt.tt2 has been passed instead of full path
template_path = tmpdir . join ( ' /etc ' )
apt_path = template_path . join ( ' /apt/apt.conf.d ' )
os . makedirs ( str ( apt_path ) , exist_ok = True )
apt_path . join ( ' 71_no_recommended.tt2 ' ) . write ( '''
# some comment
APT : : Install - Recommends " 0 " ;
''' )
apt_path . join ( ' 71_no_recommended.customtt.tt2 ' ) . write ( '''
# some comment
APT : : Install - Recommends " 2 " ;
''' )
template_path . join ( ' expected_patch.diff ' ) . write ( ''' @@ -1,3 +1,3 @@
# some comment
- APT : : Install - Recommends " 0 " ;
+ APT : : Install - Recommends " 2 " ;
''' )
out = ngcpcfgcli ( " patch " ,
" --from-customtt " ,
" 71_no_recommended.customtt.tt2 " ,
env = {
' NGCP_BASE_TT2 ' : os . getcwd ( ) ,
' NGCP_PORTFILE ' : ' /tmp/ngcpcfg.port ' ,
' OUTPUT_DIRECTORY ' : str ( tmpdir ) ,
' TEMPLATE_POOL_BASE ' : str ( tmpdir ) ,
' CONFIG_POOL ' : ' /etc ' ,
} )
assert ' No patchtt files found, nothing to patch. ' not in out . stdout
assert " Validating customtt ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.customtt.tt2 ' " in out . stdout
assert " Creating patchtt file ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.patchtt.tt2 ' " in out . stdout
assert ' Requested customtt operation has finished successfully. ' in out . stdout
# disabled for the moment, see https://gerrit.mgm.sipwise.com/#/c/17739/4/t/test_ngcpcfg_patch.py@99
#assert out.stderr == "b''"
generated_patchtt = str ( template_path ) + \
' /apt/apt.conf.d/71_no_recommended.patchtt.tt2 '
expected_patchtt = str ( template_path ) + \
' /expected_patch.diff '
assert os . path . isfile ( generated_patchtt )
assert os . path . isfile ( expected_patchtt )
with open ( generated_patchtt ) as output_file :
output = output_file . read ( )
with open ( expected_patchtt ) as expected_file :
expected = expected_file . read ( )
assert output == expected
@pytest.mark.tt_24920
def test_patch_action_from_customtt_missing_templates ( ngcpcfgcli , tmpdir ) :
# ensure "ngcpcfg patch --from-customtt" will be aborted if template is missing for customtt
template_path = tmpdir . join ( ' /etc ' )
apt_path = template_path . join ( ' /apt/apt.conf.d ' )
os . makedirs ( str ( apt_path ) , exist_ok = True )
apt_path . join ( " 71_no_recommended.customtt.tt2 " ) . write ( '''
the content here doesn ' t matter as no tt2 file available
''' )
out = ngcpcfgcli ( " patch " ,
" --from-customtt " ,
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 customtt ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.customtt.tt2 ' " in out . stdout
assert " Error: Missing template for customtt ' " + str ( template_path ) + \
" /apt/apt.conf.d/71_no_recommended.customtt.tt2 ' " in out . stderr
assert " Error: Some operations above finished with an error for the file(s) " in out . stderr
assert ' Requested patchtt operation has finished successfully. ' not in out . stdout