Revert "For #31309. If value not supplied only check for existence"

This commit is contained in:
Mike Place 2016-08-31 18:06:49 +09:00 committed by GitHub
parent 3634b79152
commit 6559cf347b
2 changed files with 3 additions and 30 deletions

View File

@ -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

View File

@ -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