mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Merge pull request #15100 from s0undt3ch/features/out-file-append
Add support for `--output-file-append`
This commit is contained in:
commit
e2f3c61cf4
@ -987,6 +987,13 @@ class OutputOptionsMixIn(object):
|
||||
default=None,
|
||||
help='Write the output to the specified file'
|
||||
)
|
||||
group.add_option(
|
||||
'--out-file-append', '--output-file-append',
|
||||
action='store_true',
|
||||
dest='output_file_append',
|
||||
default=False,
|
||||
help='Append the output to the specified file'
|
||||
)
|
||||
group.add_option(
|
||||
'--no-color', '--no-colour',
|
||||
default=False,
|
||||
@ -1015,7 +1022,7 @@ class OutputOptionsMixIn(object):
|
||||
self.selected_output_option = self.options.output
|
||||
|
||||
def process_output_file(self):
|
||||
if self.options.output_file is not None:
|
||||
if self.options.output_file is not None and self.options.output_file_append is False:
|
||||
if os.path.isfile(self.options.output_file):
|
||||
try:
|
||||
os.remove(self.options.output_file)
|
||||
|
@ -22,6 +22,7 @@ ensure_in_syspath('../../')
|
||||
|
||||
# Import salt libs
|
||||
import integration
|
||||
import salt.utils
|
||||
|
||||
|
||||
class CallTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
|
||||
@ -276,6 +277,39 @@ class CallTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
|
||||
if os.path.isdir(config_dir):
|
||||
shutil.rmtree(config_dir)
|
||||
|
||||
def test_issue_15074_output_file_append(self):
|
||||
output_file_append = os.path.join(integration.TMP, 'issue-15074')
|
||||
try:
|
||||
# Let's create an initial output file with some data
|
||||
ret = self.run_script(
|
||||
'salt-call',
|
||||
'-c {0} --output-file={1} -g'.format(
|
||||
self.get_config_dir(),
|
||||
output_file_append
|
||||
),
|
||||
catch_stderr=True,
|
||||
with_retcode=True
|
||||
)
|
||||
print ret
|
||||
|
||||
with salt.utils.fopen(output_file_append) as ofa:
|
||||
output = ofa.read()
|
||||
|
||||
self.run_script(
|
||||
'salt-call',
|
||||
'-c {0} --output-file={1} --output-file-append -g'.format(
|
||||
self.get_config_dir(),
|
||||
output_file_append
|
||||
),
|
||||
catch_stderr=True,
|
||||
with_retcode=True
|
||||
)
|
||||
with salt.utils.fopen(output_file_append) as ofa:
|
||||
self.assertEqual(ofa.read(), output + output)
|
||||
finally:
|
||||
if os.path.exists(output_file_append):
|
||||
os.unlink(output_file_append)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
|
Loading…
Reference in New Issue
Block a user