Merge pull request #11194 from makinacorpus/hotfix2

Yet another fix for ImmutableProxyList
This commit is contained in:
Pedro Algarvio 2014-03-13 16:03:12 +00:00
commit cb5c2dd5f7
3 changed files with 35 additions and 17 deletions

View File

@ -233,6 +233,7 @@ import salt.utils
import salt.utils.templates
from salt.exceptions import CommandExecutionError
from salt.utils.yamldumper import OrderedDumper
from salt.utils.immutabletypes import ImmutableList
from salt._compat import string_types, integer_types
log = logging.getLogger(__name__)
@ -2940,8 +2941,10 @@ def accumulated(name, filename, text, **kwargs):
'result': True,
'comment': ''
}
require_in = __low__.get('require_in', [])
watch_in = __low__.get('watch_in', [])
require_in = __low__.get('require_in',
ImmutableList([]))
watch_in = __low__.get('watch_in',
ImmutableList([]))
deps = []
map(deps.append, require_in + watch_in)
if not filter(lambda x: 'file' in x, deps):

View File

@ -53,11 +53,16 @@ class ImmutableList(collections.Sequence):
def __iter__(self):
return iter(self.__obj)
def _get_raw(self, other):
if isinstance(other, ImmutableLazyProxy):
other = other.__obj
return other
def __add__(self, other):
return self.__obj + other
return self.__obj + self._get_raw(other)
def __radd__(self, other):
return other + self.__obj
return self._get_raw(other) + self.__obj
def __getitem__(self, key):
return ImmutableLazyProxy(self.__obj[key])

View File

@ -901,7 +901,7 @@ class FileTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn):
' - show_changes: True',
'']
open(template_path, 'w').write(
'\n'.join(sls_template).format(testcase_filedest))
'\n'.join(sls_template).format(testcase_filedest))
try:
ret = self.run_function('state.sls', mods='issue-8343')
for name, step in ret.items():
@ -925,10 +925,20 @@ class FileTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn):
for filename in glob.glob('{0}.bak*'.format(testcase_filedest)):
os.unlink(filename)
def __test_issue_11003_immutable_lazy_proxy_sum(self):
template_path = os.path.join(integration.TMP_STATE_TREE, 'issue-11003.sls')
def test_issue_11003_immutable_lazy_proxy_sum(self):
template_path = os.path.join(
integration.TMP_STATE_TREE, 'issue-11003.sls')
testcase_filedest = os.path.join(integration.TMP, 'issue-11003.txt')
sls_template = [
'a{0}:',
' file.absent:',
' - name: {0}',
'',
'{0}:',
' file.managed:',
' - contents: |',
' #',
'',
'test-acc1:',
' file.accumulated:',
' - require_in:',
@ -936,6 +946,7 @@ class FileTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn):
' - filename: {0}',
' - text: |',
' bar',
'',
'test-acc2:',
' file.accumulated:',
' - watch_in:',
@ -943,32 +954,31 @@ class FileTest(integration.ModuleCase, integration.SaltReturnAssertsMixIn):
' - filename: {0}',
' - text: |',
' baz',
'',
'final:',
' file.blockreplace:',
' - name: {0}',
' - marker_start: "#-- start salt managed zoneend -- PLEASE, DO NOT EDIT"',
' - marker_end: "#-- end salt managed zoneend --"',
' - marker_start: "#-- start managed zone PLEASE, DO NOT EDIT"',
' - marker_end: "#-- end managed zone"',
' - content: \'\'',
' - append_if_not_found: True',
' - show_changes: True'
]
open(template_path, 'w').write(
'\n'.join(sls_template).format(testcase_filedest))
'\n'.join(sls_template).format(testcase_filedest))
try:
ret = self.run_function('state.sls', mods='issue-11003')
for name, step in ret.items():
self.assertSaltTrueReturn({name: step})
self.assertEqual(
['#-- start salt managed zonestart -- PLEASE, DO NOT EDIT',
'foo',
'',
'#-- end salt managed zonestart --',
'#',
'#-- start salt managed zoneend -- PLEASE, DO NOT EDIT',
['#',
'#-- start managed zone PLEASE, DO NOT EDIT',
'bar',
'',
'#-- end salt managed zoneend --',
'baz',
'',
'#-- end managed zone',
''],
open(testcase_filedest).read().split('\n')
)