mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Revert "For #31309. If value not supplied only check for existence"
This commit is contained in:
parent
3634b79152
commit
6559cf347b
@ -18,7 +18,7 @@ import re
|
||||
from salt.defaults import DEFAULT_TARGET_DELIM
|
||||
|
||||
|
||||
def present(name, value=None, delimiter=DEFAULT_TARGET_DELIM, force=False):
|
||||
def present(name, value, delimiter=DEFAULT_TARGET_DELIM, force=False):
|
||||
'''
|
||||
Ensure that a grain is set
|
||||
|
||||
@ -28,8 +28,7 @@ def present(name, value=None, delimiter=DEFAULT_TARGET_DELIM, force=False):
|
||||
The grain name
|
||||
|
||||
value
|
||||
The value to set on the grain. If not supplied the grain will only be
|
||||
checked to see that it exists
|
||||
The value to set on the grain
|
||||
|
||||
force
|
||||
If force is True, the existing grain will be overwritten
|
||||
@ -79,13 +78,6 @@ def present(name, value=None, delimiter=DEFAULT_TARGET_DELIM, force=False):
|
||||
'comment': ''}
|
||||
_non_existent = object()
|
||||
existing = __salt__['grains.get'](name, _non_existent)
|
||||
if value is None:
|
||||
if existing is _non_existent:
|
||||
ret['result'] = False
|
||||
ret['comment'] = 'Grain is not present'
|
||||
else:
|
||||
ret['comment'] = 'Grain is present'
|
||||
return ret
|
||||
if existing == value:
|
||||
ret['comment'] = 'Grain is already set'
|
||||
return ret
|
||||
|
@ -78,26 +78,7 @@ class GrainsTestCase(TestCase):
|
||||
with open(grains_file, "w+") as grf:
|
||||
grf.write(cstr)
|
||||
|
||||
# 'present' function tests: 13
|
||||
|
||||
def test_present_no_value(self):
|
||||
self.setGrains({'a': 'aval', 'foo': 'bar'})
|
||||
# Grain already set
|
||||
ret = grains.present(
|
||||
name='foo',
|
||||
value=None)
|
||||
self.assertEqual(ret['result'], True)
|
||||
self.assertEqual(ret['comment'], 'Grain is present')
|
||||
self.assertEqual(ret['changes'], {})
|
||||
|
||||
# Grain not present
|
||||
self.setGrains({'a': 'aval'})
|
||||
ret = grains.present(
|
||||
name='foo',
|
||||
value=None)
|
||||
self.assertEqual(ret['result'], False)
|
||||
self.assertEqual(ret['comment'], 'Grain is not present')
|
||||
self.assertEqual(ret['changes'], {})
|
||||
# 'present' function tests: 12
|
||||
|
||||
def test_present_add(self):
|
||||
# Set a non existing grain
|
||||
|
Loading…
Reference in New Issue
Block a user