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
|
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
|
Ensure that a grain is set
|
||||||
|
|
||||||
@ -28,8 +28,7 @@ def present(name, value=None, delimiter=DEFAULT_TARGET_DELIM, force=False):
|
|||||||
The grain name
|
The grain name
|
||||||
|
|
||||||
value
|
value
|
||||||
The value to set on the grain. If not supplied the grain will only be
|
The value to set on the grain
|
||||||
checked to see that it exists
|
|
||||||
|
|
||||||
force
|
force
|
||||||
If force is True, the existing grain will be overwritten
|
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': ''}
|
'comment': ''}
|
||||||
_non_existent = object()
|
_non_existent = object()
|
||||||
existing = __salt__['grains.get'](name, _non_existent)
|
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:
|
if existing == value:
|
||||||
ret['comment'] = 'Grain is already set'
|
ret['comment'] = 'Grain is already set'
|
||||||
return ret
|
return ret
|
||||||
|
@ -78,26 +78,7 @@ class GrainsTestCase(TestCase):
|
|||||||
with open(grains_file, "w+") as grf:
|
with open(grains_file, "w+") as grf:
|
||||||
grf.write(cstr)
|
grf.write(cstr)
|
||||||
|
|
||||||
# 'present' function tests: 13
|
# 'present' function tests: 12
|
||||||
|
|
||||||
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'], {})
|
|
||||||
|
|
||||||
def test_present_add(self):
|
def test_present_add(self):
|
||||||
# Set a non existing grain
|
# Set a non existing grain
|
||||||
|
Loading…
Reference in New Issue
Block a user