mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 00:55:19 +00:00
Merge pull request #46613 from myinitialsarepm/fix_puppet.fact_and_puppet.facts
Fix puppet.fact and puppet.facts to use stdout.
This commit is contained in:
commit
39d65a39cf
@ -372,7 +372,12 @@ def facts(puppet=False):
|
||||
'''
|
||||
ret = {}
|
||||
opt_puppet = '--puppet' if puppet else ''
|
||||
output = __salt__['cmd.run']('facter {0}'.format(opt_puppet))
|
||||
cmd_ret = __salt__['cmd.run_all']('facter {0}'.format(opt_puppet))
|
||||
|
||||
if cmd_ret['retcode'] != 0:
|
||||
raise CommandExecutionError(cmd_ret['stderr'])
|
||||
|
||||
output = cmd_ret['stdout']
|
||||
|
||||
# Loop over the facter output and properly
|
||||
# parse it into a nice dictionary for using
|
||||
@ -398,9 +403,13 @@ def fact(name, puppet=False):
|
||||
salt '*' puppet.fact kernel
|
||||
'''
|
||||
opt_puppet = '--puppet' if puppet else ''
|
||||
ret = __salt__['cmd.run'](
|
||||
ret = __salt__['cmd.run_all'](
|
||||
'facter {0} {1}'.format(opt_puppet, name),
|
||||
python_shell=False)
|
||||
if not ret:
|
||||
|
||||
if ret['retcode'] != 0:
|
||||
raise CommandExecutionError(ret['stderr'])
|
||||
|
||||
if not ret['stdout']:
|
||||
return ''
|
||||
return ret
|
||||
return ret['stdout']
|
||||
|
@ -164,22 +164,27 @@ class PuppetTestCase(TestCase, LoaderModuleMockMixin):
|
||||
'''
|
||||
Test to run facter and return the results
|
||||
'''
|
||||
mock_lst = MagicMock(return_value=[])
|
||||
with patch.dict(puppet.__salt__, {'cmd.run': mock_lst}):
|
||||
mock_lst = MagicMock(return_value="True")
|
||||
with patch.dict(puppet.__salt__, {'cmd.run': mock_lst}):
|
||||
mock = MagicMock(return_value=["a", "b"])
|
||||
with patch.object(puppet, '_format_fact', mock):
|
||||
self.assertDictEqual(puppet.facts(), {'a': 'b'})
|
||||
mock = MagicMock(return_value={
|
||||
'retcode': 0,
|
||||
'stdout': "1\n2"
|
||||
})
|
||||
with patch.dict(puppet.__salt__, {'cmd.run_all': mock}):
|
||||
mock = MagicMock(side_effect=[
|
||||
['a', 'b'],
|
||||
['c', 'd'],
|
||||
])
|
||||
with patch.object(puppet, '_format_fact', mock):
|
||||
self.assertDictEqual(puppet.facts(), {'a': 'b', 'c': 'd'})
|
||||
|
||||
def test_fact(self):
|
||||
'''
|
||||
Test to run facter for a specific fact
|
||||
'''
|
||||
mock_lst = MagicMock(return_value=[])
|
||||
with patch.dict(puppet.__salt__, {'cmd.run': mock_lst}):
|
||||
mock_lst = MagicMock(side_effect=[False, True])
|
||||
with patch.dict(puppet.__salt__, {'cmd.run': mock_lst}):
|
||||
self.assertEqual(puppet.fact("salt"), "")
|
||||
mock = MagicMock(side_effect=[
|
||||
{'retcode': 0, 'stdout': False},
|
||||
{'retcode': 0, 'stdout': True},
|
||||
])
|
||||
with patch.dict(puppet.__salt__, {'cmd.run_all': mock}):
|
||||
self.assertEqual(puppet.fact('salt'), '')
|
||||
|
||||
self.assertTrue(puppet.fact("salt"))
|
||||
self.assertTrue(puppet.fact('salt'))
|
||||
|
Loading…
Reference in New Issue
Block a user