4b0aa1214c
* Ziploader proof of concept (jimi-c) * Cleanups to proof of concept ziploader branch: * python3 compatible base64 encoding * zipfile compression (still need to enable toggling this off for systems without zlib support in python) * Allow non-wildcard imports (still need to make this recusrsive so that we can have module_utils code that imports other module_utils code.) * Better tracebacks: module filename is kept and module_utils directory is kept so that tracebacks show the real filenames that the errors appear in. * Make sure we import modules that are used into the module_utils files that they are used in. * Set ansible version in a more pythonic way for ziploader than we were doing in module replacer * Make it possible to set the module compression as an inventory var This may be necessary on systems where python has been compiled without zlib compression. * Refactoring of module_common code: * module replacer only replaces values that make sense for that type of file (example: don't attempt to replace python imports if we're in a powershell module). * Implement configurable shebang support for ziploader wrapper * Implement client-side constants (for SELINUX_SPECIAL_FS and SYSLOG) via environment variable. * Remove strip_comments param as we're never going to use it (ruins line numbering) * Don't repeat ourselves about detecting REPLACER * Add an easy way to debug * Port test-module to the ziploader-aware modify_module() * strip comments and blank lines from the wrapper so we send less over the wire. * Comments cleanup * Remember to output write the module line itself in powershell modules * for line in lines strips the newlines so we have to add them back in
76 lines
2.9 KiB
Python
76 lines
2.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
# (c) 2016, James Cammarata <jimi@sngx.net>
|
|
#
|
|
# This file is part of Ansible
|
|
#
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
# Make coding more python3-ish
|
|
from __future__ import (absolute_import, division)
|
|
__metaclass__ = type
|
|
|
|
import sys
|
|
import json
|
|
|
|
from ansible.compat.tests import unittest
|
|
from ansible.compat.tests.mock import MagicMock
|
|
|
|
class TestModuleUtilsBasic(unittest.TestCase):
|
|
@unittest.skipIf(sys.version_info[0] >= 3, "Python 3 is not supported on targets (yet)")
|
|
def test_module_utils_basic__log_invocation(self):
|
|
from ansible.module_utils import basic
|
|
|
|
# test basic log invocation
|
|
basic.MODULE_COMPLEX_ARGS = json.dumps(dict(foo=False, bar=[1,2,3], bam="bam", baz=u'baz'))
|
|
basic.MODULE_CONSTANTS = '{}'
|
|
am = basic.AnsibleModule(
|
|
argument_spec=dict(
|
|
foo = dict(default=True, type='bool'),
|
|
bar = dict(default=[], type='list'),
|
|
bam = dict(default="bam"),
|
|
baz = dict(default=u"baz"),
|
|
password = dict(default=True),
|
|
no_log = dict(default="you shouldn't see me", no_log=True),
|
|
),
|
|
)
|
|
|
|
am.log = MagicMock()
|
|
am._log_invocation()
|
|
|
|
# Message is generated from a dict so it will be in an unknown order.
|
|
# have to check this manually rather than with assert_called_with()
|
|
args = am.log.call_args[0]
|
|
self.assertEqual(len(args), 1)
|
|
message = args[0]
|
|
|
|
self.assertEqual(len(message), len('Invoked with bam=bam bar=[1, 2, 3] foo=False baz=baz no_log=NOT_LOGGING_PARAMETER password=NOT_LOGGING_PASSWORD'))
|
|
self.assertTrue(message.startswith('Invoked with '))
|
|
self.assertIn(' bam=bam', message)
|
|
self.assertIn(' bar=[1, 2, 3]', message)
|
|
self.assertIn(' foo=False', message)
|
|
self.assertIn(' baz=baz', message)
|
|
self.assertIn(' no_log=NOT_LOGGING_PARAMETER', message)
|
|
self.assertIn(' password=NOT_LOGGING_PASSWORD', message)
|
|
|
|
kwargs = am.log.call_args[1]
|
|
self.assertEqual(kwargs,
|
|
dict(log_args={
|
|
'foo': 'False',
|
|
'bar': '[1, 2, 3]',
|
|
'bam': 'bam',
|
|
'baz': 'baz',
|
|
'password': 'NOT_LOGGING_PASSWORD',
|
|
'no_log': 'NOT_LOGGING_PARAMETER',
|
|
})
|
|
)
|