|
|
@ -3,7 +3,7 @@
|
|
|
|
import unittest
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
|
|
import ansible.utils
|
|
|
|
import ansible.utils
|
|
|
|
import ansible.template as template
|
|
|
|
import ansible.utils.template as template2
|
|
|
|
|
|
|
|
|
|
|
|
class TestUtils(unittest.TestCase):
|
|
|
|
class TestUtils(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
|
@ -16,14 +16,14 @@ class TestUtils(unittest.TestCase):
|
|
|
|
'who': 'world',
|
|
|
|
'who': 'world',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res = ansible.utils.varReplace(None, template, vars)
|
|
|
|
res = template2.legacy_varReplace(None, template, vars)
|
|
|
|
|
|
|
|
|
|
|
|
assert res == 'hello world'
|
|
|
|
assert res == 'hello world'
|
|
|
|
|
|
|
|
|
|
|
|
def test_varReplace_trailing_dollar(self):
|
|
|
|
def test_varReplace_trailing_dollar(self):
|
|
|
|
template = '$what $who $'
|
|
|
|
template = '$what $who $'
|
|
|
|
vars = dict(what='hello', who='world')
|
|
|
|
vars = dict(what='hello', who='world')
|
|
|
|
res = ansible.utils.varReplace(None, template, vars)
|
|
|
|
res = template2.legacy_varReplace(None, template, vars)
|
|
|
|
assert res == 'hello world $'
|
|
|
|
assert res == 'hello world $'
|
|
|
|
|
|
|
|
|
|
|
|
def test_varReplace_multiple(self):
|
|
|
|
def test_varReplace_multiple(self):
|
|
|
@ -33,7 +33,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
'who': 'world',
|
|
|
|
'who': 'world',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res = ansible.utils.varReplace(None, template, vars)
|
|
|
|
res = template2.legacy_varReplace(None, template, vars)
|
|
|
|
|
|
|
|
|
|
|
|
assert res == 'hello world'
|
|
|
|
assert res == 'hello world'
|
|
|
|
|
|
|
|
|
|
|
@ -43,7 +43,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
'whoVar': 'world',
|
|
|
|
'whoVar': 'world',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res = ansible.utils.varReplace(None, template, vars)
|
|
|
|
res = template2.legacy_varReplace(None, template, vars)
|
|
|
|
print res
|
|
|
|
print res
|
|
|
|
assert res == 'hello world'
|
|
|
|
assert res == 'hello world'
|
|
|
|
|
|
|
|
|
|
|
@ -53,7 +53,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
'who': 'world',
|
|
|
|
'who': 'world',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res = ansible.utils.varReplace(None, template, vars)
|
|
|
|
res = template2.legacy_varReplace(None, template, vars)
|
|
|
|
|
|
|
|
|
|
|
|
assert res == 'hello world!'
|
|
|
|
assert res == 'hello world!'
|
|
|
|
|
|
|
|
|
|
|
@ -63,7 +63,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
'who': 'world',
|
|
|
|
'who': 'world',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res = ansible.utils.varReplace(None, template, vars)
|
|
|
|
res = template2.legacy_varReplace(None, template, vars)
|
|
|
|
|
|
|
|
|
|
|
|
assert res == 'hello world'
|
|
|
|
assert res == 'hello world'
|
|
|
|
|
|
|
|
|
|
|
@ -73,7 +73,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
'who': 'world',
|
|
|
|
'who': 'world',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res = ansible.utils.varReplace(None, template, vars)
|
|
|
|
res = template2.legacy_varReplace(None, template, vars)
|
|
|
|
|
|
|
|
|
|
|
|
assert res == 'hello world}'
|
|
|
|
assert res == 'hello world}'
|
|
|
|
|
|
|
|
|
|
|
@ -83,7 +83,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
'who': 'world',
|
|
|
|
'who': 'world',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res = ansible.utils.varReplace(None, template, vars)
|
|
|
|
res = template2.legacy_varReplace(None, template, vars)
|
|
|
|
|
|
|
|
|
|
|
|
assert res == template
|
|
|
|
assert res == template
|
|
|
|
|
|
|
|
|
|
|
@ -93,7 +93,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
'who': 'world',
|
|
|
|
'who': 'world',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res = ansible.utils.varReplace(None, template, vars)
|
|
|
|
res = template2.legacy_varReplace(None, template, vars)
|
|
|
|
|
|
|
|
|
|
|
|
assert res == 'hello world }'
|
|
|
|
assert res == 'hello world }'
|
|
|
|
|
|
|
|
|
|
|
@ -105,7 +105,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res = ansible.utils.varReplace(None, template, vars)
|
|
|
|
res = template2.legacy_varReplace(None, template, vars)
|
|
|
|
|
|
|
|
|
|
|
|
print res
|
|
|
|
print res
|
|
|
|
assert res == template
|
|
|
|
assert res == template
|
|
|
@ -118,7 +118,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res = ansible.utils.varReplace(None, template, vars)
|
|
|
|
res = template2.legacy_varReplace(None, template, vars)
|
|
|
|
|
|
|
|
|
|
|
|
assert res == 'hello world'
|
|
|
|
assert res == 'hello world'
|
|
|
|
|
|
|
|
|
|
|
@ -131,7 +131,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
'what': 'hello',
|
|
|
|
'what': 'hello',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res = ansible.utils.varReplace(None, template, vars)
|
|
|
|
res = template2.legacy_varReplace(None, template, vars)
|
|
|
|
|
|
|
|
|
|
|
|
assert res == 'hello 2'
|
|
|
|
assert res == 'hello 2'
|
|
|
|
|
|
|
|
|
|
|
@ -141,7 +141,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
'who': u'wórld',
|
|
|
|
'who': u'wórld',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res = ansible.utils.varReplace(None, template, vars)
|
|
|
|
res = template2.legacy_varReplace(None, template, vars)
|
|
|
|
|
|
|
|
|
|
|
|
assert res == u'hello wórld'
|
|
|
|
assert res == u'hello wórld'
|
|
|
|
|
|
|
|
|
|
|
@ -151,7 +151,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
'data': [ 'no-one', 'world' ]
|
|
|
|
'data': [ 'no-one', 'world' ]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res = ansible.utils.varReplace(None, template, vars)
|
|
|
|
res = template2.legacy_varReplace(None, template, vars)
|
|
|
|
|
|
|
|
|
|
|
|
assert res == 'hello world'
|
|
|
|
assert res == 'hello world'
|
|
|
|
|
|
|
|
|
|
|
@ -161,7 +161,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
'data': [ 'no-one', 'world' ]
|
|
|
|
'data': [ 'no-one', 'world' ]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res = ansible.utils.varReplace(None, template, vars)
|
|
|
|
res = template2.legacy_varReplace(None, template, vars)
|
|
|
|
|
|
|
|
|
|
|
|
assert res == template
|
|
|
|
assert res == template
|
|
|
|
|
|
|
|
|
|
|
@ -171,7 +171,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
'data': [ 'no-one', 'world' ]
|
|
|
|
'data': [ 'no-one', 'world' ]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res = ansible.utils.varReplace(None, template, vars)
|
|
|
|
res = template2.legacy_varReplace(None, template, vars)
|
|
|
|
|
|
|
|
|
|
|
|
assert res == template
|
|
|
|
assert res == template
|
|
|
|
|
|
|
|
|
|
|
@ -181,7 +181,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
'data': { 'no-one': 0, 'world': 1 }
|
|
|
|
'data': { 'no-one': 0, 'world': 1 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res = ansible.utils.varReplace(None, template, vars)
|
|
|
|
res = template2.legacy_varReplace(None, template, vars)
|
|
|
|
|
|
|
|
|
|
|
|
assert res == template
|
|
|
|
assert res == template
|
|
|
|
|
|
|
|
|
|
|
@ -191,7 +191,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
'data': [ 'no-one', {'msg': [ 'world'] } ]
|
|
|
|
'data': [ 'no-one', {'msg': [ 'world'] } ]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res = ansible.utils.varReplace(None, template, vars)
|
|
|
|
res = template2.legacy_varReplace(None, template, vars)
|
|
|
|
|
|
|
|
|
|
|
|
assert res == 'hello world'
|
|
|
|
assert res == 'hello world'
|
|
|
|
|
|
|
|
|
|
|
@ -202,7 +202,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template = '${foo}${bar}'
|
|
|
|
template = '${foo}${bar}'
|
|
|
|
res = ansible.utils.varReplace(None, template, vars)
|
|
|
|
res = template2.legacy_varReplace(None, template, vars)
|
|
|
|
assert res == 'foobar'
|
|
|
|
assert res == 'foobar'
|
|
|
|
|
|
|
|
|
|
|
|
def test_varReplace_escape_dot(self):
|
|
|
|
def test_varReplace_escape_dot(self):
|
|
|
@ -215,7 +215,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template = '${hostvars.{test.example.com}.foo}'
|
|
|
|
template = '${hostvars.{test.example.com}.foo}'
|
|
|
|
res = ansible.utils.varReplace(None, template, vars)
|
|
|
|
res = template2.legacy_varReplace(None, template, vars)
|
|
|
|
assert res == 'bar'
|
|
|
|
assert res == 'bar'
|
|
|
|
|
|
|
|
|
|
|
|
def test_varReplace_list_join(self):
|
|
|
|
def test_varReplace_list_join(self):
|
|
|
@ -228,7 +228,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template = 'yum pkg=${list} state=installed'
|
|
|
|
template = 'yum pkg=${list} state=installed'
|
|
|
|
res = ansible.utils.varReplace(None, template, vars, expand_lists=True)
|
|
|
|
res = template2.legacy_varReplace(None, template, vars, expand_lists=True)
|
|
|
|
assert res == 'yum pkg=foo,bar,baz state=installed'
|
|
|
|
assert res == 'yum pkg=foo,bar,baz state=installed'
|
|
|
|
|
|
|
|
|
|
|
|
def test_varReplace_escaped_var(self):
|
|
|
|
def test_varReplace_escaped_var(self):
|
|
|
@ -236,7 +236,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
'foo': 'bar',
|
|
|
|
'foo': 'bar',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
template = 'action \$foo'
|
|
|
|
template = 'action \$foo'
|
|
|
|
res = ansible.utils.varReplace(None, template, vars)
|
|
|
|
res = template2.legacy_varReplace(None, template, vars)
|
|
|
|
assert res == 'action $foo'
|
|
|
|
assert res == 'action $foo'
|
|
|
|
|
|
|
|
|
|
|
|
def test_varReplace_var_part(self):
|
|
|
|
def test_varReplace_var_part(self):
|
|
|
@ -247,7 +247,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
'key': 'bar',
|
|
|
|
'key': 'bar',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
template = 'test ${foo.$key}'
|
|
|
|
template = 'test ${foo.$key}'
|
|
|
|
res = ansible.utils.varReplace(None, template, vars)
|
|
|
|
res = template2.legacy_varReplace(None, template, vars)
|
|
|
|
assert res == 'test result'
|
|
|
|
assert res == 'test result'
|
|
|
|
|
|
|
|
|
|
|
|
def test_varReplace_var_partial_part(self):
|
|
|
|
def test_varReplace_var_partial_part(self):
|
|
|
@ -258,7 +258,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
'key': 'bar',
|
|
|
|
'key': 'bar',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
template = 'test ${foo.${key}baz}'
|
|
|
|
template = 'test ${foo.${key}baz}'
|
|
|
|
res = ansible.utils.varReplace(None, template, vars)
|
|
|
|
res = template2.legacy_varReplace(None, template, vars)
|
|
|
|
assert res == 'test result'
|
|
|
|
assert res == 'test result'
|
|
|
|
|
|
|
|
|
|
|
|
def test_varReplace_var_complex_var(self):
|
|
|
|
def test_varReplace_var_complex_var(self):
|
|
|
@ -269,7 +269,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
template = '${x.foo}'
|
|
|
|
template = '${x.foo}'
|
|
|
|
res = template.template(None, template, vars)
|
|
|
|
res = template2.template(None, template, vars)
|
|
|
|
assert res == 'result'
|
|
|
|
assert res == 'result'
|
|
|
|
|
|
|
|
|
|
|
|
def test_template_varReplace_iterated(self):
|
|
|
|
def test_template_varReplace_iterated(self):
|
|
|
@ -279,21 +279,21 @@ class TestUtils(unittest.TestCase):
|
|
|
|
'person': 'one',
|
|
|
|
'person': 'one',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res = template.template(None, template, vars)
|
|
|
|
res = template2.template(None, template, vars)
|
|
|
|
|
|
|
|
|
|
|
|
assert res == u'hello oh great one'
|
|
|
|
assert res == u'hello oh great one'
|
|
|
|
|
|
|
|
|
|
|
|
def test_varReplace_include(self):
|
|
|
|
def test_varReplace_include(self):
|
|
|
|
template = 'hello $FILE(world) $LOOKUP(file, $filename)'
|
|
|
|
template = 'hello $FILE(world) $LOOKUP(file, $filename)'
|
|
|
|
|
|
|
|
|
|
|
|
res = template.template("test", template, {'filename': 'world'}, expand_lists=True)
|
|
|
|
res = template2.template("test", template, {'filename': 'world'}, expand_lists=True)
|
|
|
|
|
|
|
|
|
|
|
|
assert res == u'hello world world'
|
|
|
|
assert res == u'hello world world'
|
|
|
|
|
|
|
|
|
|
|
|
def test_varReplace_include_script(self):
|
|
|
|
def test_varReplace_include_script(self):
|
|
|
|
template = 'hello $PIPE(echo world) $LOOKUP(pipe, echo world)'
|
|
|
|
template = 'hello $PIPE(echo world) $LOOKUP(pipe, echo world)'
|
|
|
|
|
|
|
|
|
|
|
|
res = template.template("test", template, {}, expand_lists=True)
|
|
|
|
res = template2.template("test", template, {}, expand_lists=True)
|
|
|
|
|
|
|
|
|
|
|
|
assert res == u'hello world world'
|
|
|
|
assert res == u'hello world world'
|
|
|
|
|
|
|
|
|
|
|
@ -325,19 +325,19 @@ class TestUtils(unittest.TestCase):
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template = '${data.var}'
|
|
|
|
template = '${data.var}'
|
|
|
|
res = template.template(None, template, vars)
|
|
|
|
res = template2.template(None, template, vars)
|
|
|
|
assert sorted(res) == sorted(vars['data']['var'])
|
|
|
|
assert sorted(res) == sorted(vars['data']['var'])
|
|
|
|
|
|
|
|
|
|
|
|
template = '${data.types}'
|
|
|
|
template = '${data.types}'
|
|
|
|
res = template.template(None, template, vars)
|
|
|
|
res = template2.template(None, template, vars)
|
|
|
|
assert sorted(res) == sorted(vars['data']['types'])
|
|
|
|
assert sorted(res) == sorted(vars['data']['types'])
|
|
|
|
|
|
|
|
|
|
|
|
template = '${data.alphas}'
|
|
|
|
template = '${data.alphas}'
|
|
|
|
res = template.template(None, template, vars)
|
|
|
|
res = template2.template(None, template, vars)
|
|
|
|
assert sorted(res) == sorted(vars['alphas'])
|
|
|
|
assert sorted(res) == sorted(vars['alphas'])
|
|
|
|
|
|
|
|
|
|
|
|
template = '${data.nonexisting}'
|
|
|
|
template = '${data.nonexisting}'
|
|
|
|
res = template.template(None, template, vars)
|
|
|
|
res = template2.template(None, template, vars)
|
|
|
|
assert res == template
|
|
|
|
assert res == template
|
|
|
|
|
|
|
|
|
|
|
|
#####################################
|
|
|
|
#####################################
|
|
|
@ -348,7 +348,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
'who': 'world',
|
|
|
|
'who': 'world',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res = template.template_from_file("test", "template-basic", vars)
|
|
|
|
res = template2.template_from_file("test", "template-basic", vars)
|
|
|
|
|
|
|
|
|
|
|
|
assert res == 'hello world'
|
|
|
|
assert res == 'hello world'
|
|
|
|
|
|
|
|
|
|
|
@ -357,7 +357,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
'who': 'world',
|
|
|
|
'who': 'world',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res = template.template_from_file("test", "template-whitespace", vars)
|
|
|
|
res = template2.template_from_file("test", "template-whitespace", vars)
|
|
|
|
|
|
|
|
|
|
|
|
assert res == 'hello world\n'
|
|
|
|
assert res == 'hello world\n'
|
|
|
|
|
|
|
|
|
|
|
@ -366,7 +366,7 @@ class TestUtils(unittest.TestCase):
|
|
|
|
'who': u'wórld',
|
|
|
|
'who': u'wórld',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res = template.template_from_file("test", "template-basic", vars)
|
|
|
|
res = template2.template_from_file("test", "template-basic", vars)
|
|
|
|
|
|
|
|
|
|
|
|
assert res == u'hello wórld'
|
|
|
|
assert res == u'hello wórld'
|
|
|
|
|
|
|
|
|
|
|
|