2014-05-12 17:31:59 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
:codeauthor: :email:`Nicole Thomas <nicole@saltstack.com>`
|
|
|
|
'''
|
|
|
|
|
|
|
|
# Import Salt Libs
|
2014-11-21 19:05:13 +00:00
|
|
|
from __future__ import absolute_import
|
2014-10-11 16:37:24 +00:00
|
|
|
import os
|
2014-11-21 19:05:13 +00:00
|
|
|
import traceback
|
2014-05-12 17:31:59 +00:00
|
|
|
|
|
|
|
# Import Salt Testing Libs
|
|
|
|
from salttesting.helpers import ensure_in_syspath
|
2015-08-27 19:46:29 +00:00
|
|
|
from salttesting.mixins import RUNTIME_VARS
|
2016-06-15 19:41:00 +00:00
|
|
|
|
2014-05-12 17:31:59 +00:00
|
|
|
ensure_in_syspath('../../')
|
|
|
|
|
2014-11-21 19:05:13 +00:00
|
|
|
# Import Salt libs
|
|
|
|
import integration
|
2016-06-15 19:41:00 +00:00
|
|
|
import salt.config
|
2015-02-25 09:50:53 +00:00
|
|
|
from salt.output import display_output
|
2015-08-27 19:46:29 +00:00
|
|
|
import salt.config
|
2014-11-21 19:05:13 +00:00
|
|
|
|
2014-05-12 17:31:59 +00:00
|
|
|
|
|
|
|
class OutputReturnTest(integration.ShellCase):
|
|
|
|
'''
|
|
|
|
Integration tests to ensure outputters return their expected format.
|
|
|
|
Tests against situations where the loader might not be returning the
|
|
|
|
right outputter even though it was explicitly requested.
|
|
|
|
'''
|
|
|
|
|
|
|
|
def test_output_json(self):
|
|
|
|
'''
|
|
|
|
Tests the return of json-formatted data
|
|
|
|
'''
|
|
|
|
ret = self.run_call('test.ping --out=json')
|
2016-10-12 10:39:48 +00:00
|
|
|
self.assertIn('{', ret)
|
2016-10-12 14:05:29 +00:00
|
|
|
self.assertIn('"local": true', ''.join(ret))
|
|
|
|
self.assertIn('}', ''.join(ret))
|
2014-05-12 17:31:59 +00:00
|
|
|
|
|
|
|
def test_output_nested(self):
|
|
|
|
'''
|
|
|
|
Tests the return of nested-formatted data
|
|
|
|
'''
|
|
|
|
expected = ['local:', ' True']
|
|
|
|
ret = self.run_call('test.ping --out=nested')
|
|
|
|
self.assertEqual(ret, expected)
|
|
|
|
|
|
|
|
def test_output_quiet(self):
|
|
|
|
'''
|
|
|
|
Tests the return of an out=quiet query
|
|
|
|
'''
|
|
|
|
expected = []
|
|
|
|
ret = self.run_call('test.ping --out=quiet')
|
|
|
|
self.assertEqual(ret, expected)
|
|
|
|
|
|
|
|
def test_output_pprint(self):
|
|
|
|
'''
|
|
|
|
Tests the return of pprint-formatted data
|
|
|
|
'''
|
|
|
|
expected = ["{'local': True}"]
|
|
|
|
ret = self.run_call('test.ping --out=pprint')
|
|
|
|
self.assertEqual(ret, expected)
|
|
|
|
|
|
|
|
def test_output_raw(self):
|
|
|
|
'''
|
|
|
|
Tests the return of raw-formatted data
|
|
|
|
'''
|
|
|
|
expected = ["{'local': True}"]
|
|
|
|
ret = self.run_call('test.ping --out=raw')
|
|
|
|
self.assertEqual(ret, expected)
|
|
|
|
|
|
|
|
def test_output_txt(self):
|
|
|
|
'''
|
|
|
|
Tests the return of txt-formatted data
|
|
|
|
'''
|
|
|
|
expected = ['local: True']
|
|
|
|
ret = self.run_call('test.ping --out=txt')
|
|
|
|
self.assertEqual(ret, expected)
|
|
|
|
|
|
|
|
def test_output_yaml(self):
|
|
|
|
'''
|
|
|
|
Tests the return of yaml-formatted data
|
|
|
|
'''
|
|
|
|
expected = ['local: true']
|
|
|
|
ret = self.run_call('test.ping --out=yaml')
|
|
|
|
self.assertEqual(ret, expected)
|
2014-10-11 16:37:24 +00:00
|
|
|
|
|
|
|
def test_output_unicodebad(self):
|
|
|
|
'''
|
|
|
|
Tests outputter reliability with utf8
|
|
|
|
'''
|
2016-06-15 19:41:00 +00:00
|
|
|
opts = salt.config.minion_config(os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'minion'))
|
2014-10-11 16:37:24 +00:00
|
|
|
opts['output_file'] = os.path.join(
|
2016-08-02 22:25:22 +00:00
|
|
|
integration.SYS_TMP_DIR,
|
|
|
|
'salt-tests-tmpdir',
|
|
|
|
'outputtest'
|
|
|
|
)
|
2014-10-11 16:37:24 +00:00
|
|
|
data = {'foo': {'result': False,
|
|
|
|
'aaa': 'azerzaeréééé',
|
|
|
|
'comment': u'ééééàààà'}}
|
|
|
|
try:
|
|
|
|
# this should not raises UnicodeEncodeError
|
2016-06-15 19:41:00 +00:00
|
|
|
display_output(data, opts=opts)
|
2014-10-11 16:37:24 +00:00
|
|
|
self.assertTrue(True)
|
2014-10-12 10:15:58 +00:00
|
|
|
except Exception:
|
2014-10-12 09:37:17 +00:00
|
|
|
# display trace in error message for debugging on jenkins
|
2014-10-12 10:15:58 +00:00
|
|
|
trace = traceback.format_exc()
|
2014-10-12 09:37:17 +00:00
|
|
|
self.assertEqual(trace, '')
|
2014-10-11 16:37:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(OutputReturnTest)
|