Remove reload from arg related tests. Changes to how ziploader passes args mean we don't need reload anymore. (#15782)

pull/15808/head
Toshio Kuratomi 8 years ago
parent ddd9f92255
commit c730af5dc2

@ -28,8 +28,6 @@ from ansible.compat.tests import unittest
from units.mock.procenv import swap_stdin_and_argv, swap_stdout from units.mock.procenv import swap_stdin_and_argv, swap_stdout
from ansible.module_utils import basic from ansible.module_utils import basic
from ansible.module_utils.basic import heuristic_log_sanitize
from ansible.module_utils.basic import return_values, remove_values
empty_invocation = {u'module_args': {}} empty_invocation = {u'module_args': {}}
@ -45,7 +43,7 @@ class TestAnsibleModuleExitJson(unittest.TestCase):
self.stdout_swap_ctx = swap_stdout() self.stdout_swap_ctx = swap_stdout()
self.fake_stream = self.stdout_swap_ctx.__enter__() self.fake_stream = self.stdout_swap_ctx.__enter__()
reload(basic) basic._ANSIBLE_ARGS = None
self.module = basic.AnsibleModule(argument_spec=dict()) self.module = basic.AnsibleModule(argument_spec=dict())
def tearDown(self): def tearDown(self):
@ -126,8 +124,8 @@ class TestAnsibleModuleExitValuesRemoved(unittest.TestCase):
params = json.dumps(params) params = json.dumps(params)
with swap_stdin_and_argv(stdin_data=params): with swap_stdin_and_argv(stdin_data=params):
reload(basic)
with swap_stdout(): with swap_stdout():
basic._ANSIBLE_ARGS = None
module = basic.AnsibleModule( module = basic.AnsibleModule(
argument_spec = dict( argument_spec = dict(
username=dict(), username=dict(),
@ -148,8 +146,8 @@ class TestAnsibleModuleExitValuesRemoved(unittest.TestCase):
params = dict(ANSIBLE_MODULE_ARGS=args, ANSIBLE_MODULE_CONSTANTS={}) params = dict(ANSIBLE_MODULE_ARGS=args, ANSIBLE_MODULE_CONSTANTS={})
params = json.dumps(params) params = json.dumps(params)
with swap_stdin_and_argv(stdin_data=params): with swap_stdin_and_argv(stdin_data=params):
reload(basic)
with swap_stdout(): with swap_stdout():
basic._ANSIBLE_ARGS = None
module = basic.AnsibleModule( module = basic.AnsibleModule(
argument_spec = dict( argument_spec = dict(
username=dict(), username=dict(),

@ -28,7 +28,7 @@ from ansible.compat.tests import unittest
from ansible.compat.tests.mock import patch, MagicMock from ansible.compat.tests.mock import patch, MagicMock
from units.mock.procenv import swap_stdin_and_argv from units.mock.procenv import swap_stdin_and_argv
from ansible.module_utils import basic import ansible.module_utils.basic
try: try:
@ -49,20 +49,20 @@ class TestAnsibleModuleSysLogSmokeTest(unittest.TestCase):
self.stdin_swap = swap_stdin_and_argv(stdin_data=args) self.stdin_swap = swap_stdin_and_argv(stdin_data=args)
self.stdin_swap.__enter__() self.stdin_swap.__enter__()
reload(basic) ansible.module_utils.basic._ANSIBLE_ARGS = None
self.am = basic.AnsibleModule( self.am = ansible.module_utils.basic.AnsibleModule(
argument_spec = dict(), argument_spec = dict(),
) )
self.has_journal = basic.has_journal self.has_journal = ansible.module_utils.basic.has_journal
if self.has_journal: if self.has_journal:
# Systems with journal can still test syslog # Systems with journal can still test syslog
basic.has_journal = False ansible.module_utils.basic.has_journal = False
def tearDown(self): def tearDown(self):
# unittest doesn't have a clean place to use a context manager, so we have to enter/exit manually # unittest doesn't have a clean place to use a context manager, so we have to enter/exit manually
self.stdin_swap.__exit__(None, None, None) self.stdin_swap.__exit__(None, None, None)
basic.has_journal = self.has_journal ansible.module_utils.basic.has_journal = self.has_journal
def test_smoketest_syslog(self): def test_smoketest_syslog(self):
# These talk to the live daemons on the system. Need to do this to # These talk to the live daemons on the system. Need to do this to
@ -86,8 +86,8 @@ class TestAnsibleModuleJournaldSmokeTest(unittest.TestCase):
self.stdin_swap = swap_stdin_and_argv(stdin_data=args) self.stdin_swap = swap_stdin_and_argv(stdin_data=args)
self.stdin_swap.__enter__() self.stdin_swap.__enter__()
reload(basic) ansible.module_utils.basic._ANSIBLE_ARGS = None
self.am = basic.AnsibleModule( self.am = ansible.module_utils.basic.AnsibleModule(
argument_spec = dict(), argument_spec = dict(),
) )
@ -95,7 +95,7 @@ class TestAnsibleModuleJournaldSmokeTest(unittest.TestCase):
# unittest doesn't have a clean place to use a context manager, so we have to enter/exit manually # unittest doesn't have a clean place to use a context manager, so we have to enter/exit manually
self.stdin_swap.__exit__(None, None, None) self.stdin_swap.__exit__(None, None, None)
@unittest.skipUnless(basic.has_journal, 'python systemd bindings not installed') @unittest.skipUnless(ansible.module_utils.basic.has_journal, 'python systemd bindings not installed')
def test_smoketest_journal(self): def test_smoketest_journal(self):
# These talk to the live daemons on the system. Need to do this to # These talk to the live daemons on the system. Need to do this to
# show that what we send doesn't cause an issue once it gets to the # show that what we send doesn't cause an issue once it gets to the
@ -134,19 +134,19 @@ class TestAnsibleModuleLogSyslog(unittest.TestCase):
self.stdin_swap = swap_stdin_and_argv(stdin_data=args) self.stdin_swap = swap_stdin_and_argv(stdin_data=args)
self.stdin_swap.__enter__() self.stdin_swap.__enter__()
reload(basic) ansible.module_utils.basic._ANSIBLE_ARGS = None
self.am = basic.AnsibleModule( self.am = ansible.module_utils.basic.AnsibleModule(
argument_spec = dict(), argument_spec = dict(),
) )
self.has_journal = basic.has_journal self.has_journal = ansible.module_utils.basic.has_journal
if self.has_journal: if self.has_journal:
# Systems with journal can still test syslog # Systems with journal can still test syslog
basic.has_journal = False ansible.module_utils.basic.has_journal = False
def tearDown(self): def tearDown(self):
# teardown/reset # teardown/reset
basic.has_journal = self.has_journal ansible.module_utils.basic.has_journal = self.has_journal
# unittest doesn't have a clean place to use a context manager, so we have to enter/exit manually # unittest doesn't have a clean place to use a context manager, so we have to enter/exit manually
self.stdin_swap.__exit__(None, None, None) self.stdin_swap.__exit__(None, None, None)
@ -195,13 +195,13 @@ class TestAnsibleModuleLogJournal(unittest.TestCase):
self.stdin_swap = swap_stdin_and_argv(stdin_data=args) self.stdin_swap = swap_stdin_and_argv(stdin_data=args)
self.stdin_swap.__enter__() self.stdin_swap.__enter__()
reload(basic) ansible.module_utils.basic._ANSIBLE_ARGS = None
self.am = basic.AnsibleModule( self.am = ansible.module_utils.basic.AnsibleModule(
argument_spec = dict(), argument_spec = dict(),
) )
self.has_journal = basic.has_journal self.has_journal = ansible.module_utils.basic.has_journal
basic.has_journal = True ansible.module_utils.basic.has_journal = True
self.module_patcher = None self.module_patcher = None
@ -210,20 +210,20 @@ class TestAnsibleModuleLogJournal(unittest.TestCase):
self.module_patcher = patch.dict('sys.modules', {'systemd': MagicMock(), 'systemd.journal': MagicMock()}) self.module_patcher = patch.dict('sys.modules', {'systemd': MagicMock(), 'systemd.journal': MagicMock()})
self.module_patcher.start() self.module_patcher.start()
try: try:
reload(basic) reload(ansible.module_utils.basic)
except NameError: except NameError:
self._fake_out_reload(basic) self._fake_out_reload(ansible.module_utils.basic)
def tearDown(self): def tearDown(self):
# unittest doesn't have a clean place to use a context manager, so we have to enter/exit manually # unittest doesn't have a clean place to use a context manager, so we have to enter/exit manually
self.stdin_swap.__exit__(None, None, None) self.stdin_swap.__exit__(None, None, None)
# teardown/reset # teardown/reset
basic.has_journal = self.has_journal ansible.module_utils.basic.has_journal = self.has_journal
if self.module_patcher: if self.module_patcher:
self.module_patcher.stop() self.module_patcher.stop()
reload(basic) reload(ansible.module_utils.basic)
@patch('systemd.journal.send') @patch('systemd.journal.send')
def test_no_log(self, mock_func): def test_no_log(self, mock_func):

@ -67,7 +67,7 @@ class TestAnsibleModuleRunCommand(unittest.TestCase):
self.stdin_swap = swap_stdin_and_argv(stdin_data=args) self.stdin_swap = swap_stdin_and_argv(stdin_data=args)
self.stdin_swap.__enter__() self.stdin_swap.__enter__()
reload(basic) basic._ANSIBLE_ARGS = None
self.module = AnsibleModule(argument_spec=dict()) self.module = AnsibleModule(argument_spec=dict())
self.module.fail_json = MagicMock(side_effect=SystemExit) self.module.fail_json = MagicMock(side_effect=SystemExit)

@ -26,12 +26,6 @@ import json
from ansible.compat.tests import unittest from ansible.compat.tests import unittest
from units.mock.procenv import swap_stdin_and_argv from units.mock.procenv import swap_stdin_and_argv
try:
from importlib import reload
except:
# Py2 has reload as a builtin
pass
class TestAnsibleModuleExitJson(unittest.TestCase): class TestAnsibleModuleExitJson(unittest.TestCase):
def test_module_utils_basic_safe_eval(self): def test_module_utils_basic_safe_eval(self):
@ -40,7 +34,7 @@ class TestAnsibleModuleExitJson(unittest.TestCase):
args = json.dumps(dict(ANSIBLE_MODULE_ARGS={}, ANSIBLE_MODULE_CONSTANTS={})) args = json.dumps(dict(ANSIBLE_MODULE_ARGS={}, ANSIBLE_MODULE_CONSTANTS={}))
with swap_stdin_and_argv(stdin_data=args): with swap_stdin_and_argv(stdin_data=args):
reload(basic) basic._ANSIBLE_ARGS = None
am = basic.AnsibleModule( am = basic.AnsibleModule(
argument_spec=dict(), argument_spec=dict(),
) )

@ -31,12 +31,6 @@ try:
except ImportError: except ImportError:
import __builtin__ as builtins import __builtin__ as builtins
try:
from importlib import reload
except:
# Py2 has reload as a builtin
pass
from units.mock.procenv import swap_stdin_and_argv from units.mock.procenv import swap_stdin_and_argv
from ansible.compat.tests import unittest from ansible.compat.tests import unittest
@ -297,7 +291,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
args = json.dumps(dict(ANSIBLE_MODULE_ARGS={"foo": "hello"}, ANSIBLE_MODULE_CONSTANTS={})) args = json.dumps(dict(ANSIBLE_MODULE_ARGS={"foo": "hello"}, ANSIBLE_MODULE_CONSTANTS={}))
with swap_stdin_and_argv(stdin_data=args): with swap_stdin_and_argv(stdin_data=args):
reload(basic) basic._ANSIBLE_ARGS = None
am = basic.AnsibleModule( am = basic.AnsibleModule(
argument_spec = arg_spec, argument_spec = arg_spec,
mutually_exclusive = mut_ex, mutually_exclusive = mut_ex,
@ -314,7 +308,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
args = json.dumps(dict(ANSIBLE_MODULE_ARGS={}, ANSIBLE_MODULE_CONSTANTS={})) args = json.dumps(dict(ANSIBLE_MODULE_ARGS={}, ANSIBLE_MODULE_CONSTANTS={}))
with swap_stdin_and_argv(stdin_data=args): with swap_stdin_and_argv(stdin_data=args):
reload(basic) basic._ANSIBLE_ARGS = None
self.assertRaises( self.assertRaises(
SystemExit, SystemExit,
basic.AnsibleModule, basic.AnsibleModule,
@ -361,7 +355,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
def test_module_utils_basic_ansible_module_load_file_common_arguments(self): def test_module_utils_basic_ansible_module_load_file_common_arguments(self):
from ansible.module_utils import basic from ansible.module_utils import basic
reload(basic) basic._ANSIBLE_ARGS = None
am = basic.AnsibleModule( am = basic.AnsibleModule(
argument_spec = dict(), argument_spec = dict(),
@ -410,7 +404,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
def test_module_utils_basic_ansible_module_selinux_mls_enabled(self): def test_module_utils_basic_ansible_module_selinux_mls_enabled(self):
from ansible.module_utils import basic from ansible.module_utils import basic
reload(basic) basic._ANSIBLE_ARGS = None
am = basic.AnsibleModule( am = basic.AnsibleModule(
argument_spec = dict(), argument_spec = dict(),
@ -430,7 +424,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
def test_module_utils_basic_ansible_module_selinux_initial_context(self): def test_module_utils_basic_ansible_module_selinux_initial_context(self):
from ansible.module_utils import basic from ansible.module_utils import basic
reload(basic) basic._ANSIBLE_ARGS = None
am = basic.AnsibleModule( am = basic.AnsibleModule(
argument_spec = dict(), argument_spec = dict(),
@ -444,7 +438,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
def test_module_utils_basic_ansible_module_selinux_enabled(self): def test_module_utils_basic_ansible_module_selinux_enabled(self):
from ansible.module_utils import basic from ansible.module_utils import basic
reload(basic) basic._ANSIBLE_ARGS = None
am = basic.AnsibleModule( am = basic.AnsibleModule(
argument_spec = dict(), argument_spec = dict(),
@ -476,7 +470,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
def test_module_utils_basic_ansible_module_selinux_default_context(self): def test_module_utils_basic_ansible_module_selinux_default_context(self):
from ansible.module_utils import basic from ansible.module_utils import basic
reload(basic) basic._ANSIBLE_ARGS = None
am = basic.AnsibleModule( am = basic.AnsibleModule(
argument_spec = dict(), argument_spec = dict(),
@ -512,7 +506,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
def test_module_utils_basic_ansible_module_selinux_context(self): def test_module_utils_basic_ansible_module_selinux_context(self):
from ansible.module_utils import basic from ansible.module_utils import basic
reload(basic) basic._ANSIBLE_ARGS = None
am = basic.AnsibleModule( am = basic.AnsibleModule(
argument_spec = dict(), argument_spec = dict(),
@ -554,7 +548,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
def test_module_utils_basic_ansible_module_is_special_selinux_path(self): def test_module_utils_basic_ansible_module_is_special_selinux_path(self):
from ansible.module_utils import basic from ansible.module_utils import basic
reload(basic) basic._ANSIBLE_ARGS = None
args = json.dumps(dict(ANSIBLE_MODULE_ARGS={}, ANSIBLE_MODULE_CONSTANTS={"SELINUX_SPECIAL_FS": "nfs,nfsd,foos"})) args = json.dumps(dict(ANSIBLE_MODULE_ARGS={}, ANSIBLE_MODULE_CONSTANTS={"SELINUX_SPECIAL_FS": "nfs,nfsd,foos"}))
@ -599,7 +593,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
def test_module_utils_basic_ansible_module_to_filesystem_str(self): def test_module_utils_basic_ansible_module_to_filesystem_str(self):
from ansible.module_utils import basic from ansible.module_utils import basic
reload(basic) basic._ANSIBLE_ARGS = None
am = basic.AnsibleModule( am = basic.AnsibleModule(
argument_spec = dict(), argument_spec = dict(),
@ -624,7 +618,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
def test_module_utils_basic_ansible_module_find_mount_point(self): def test_module_utils_basic_ansible_module_find_mount_point(self):
from ansible.module_utils import basic from ansible.module_utils import basic
reload(basic) basic._ANSIBLE_ARGS = None
am = basic.AnsibleModule( am = basic.AnsibleModule(
argument_spec = dict(), argument_spec = dict(),
@ -648,7 +642,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
def test_module_utils_basic_ansible_module_set_context_if_different(self): def test_module_utils_basic_ansible_module_set_context_if_different(self):
from ansible.module_utils import basic from ansible.module_utils import basic
reload(basic) basic._ANSIBLE_ARGS = None
am = basic.AnsibleModule( am = basic.AnsibleModule(
argument_spec = dict(), argument_spec = dict(),
@ -693,7 +687,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
def test_module_utils_basic_ansible_module_set_owner_if_different(self): def test_module_utils_basic_ansible_module_set_owner_if_different(self):
from ansible.module_utils import basic from ansible.module_utils import basic
reload(basic) basic._ANSIBLE_ARGS = None
am = basic.AnsibleModule( am = basic.AnsibleModule(
argument_spec = dict(), argument_spec = dict(),
@ -732,7 +726,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
def test_module_utils_basic_ansible_module_set_group_if_different(self): def test_module_utils_basic_ansible_module_set_group_if_different(self):
from ansible.module_utils import basic from ansible.module_utils import basic
reload(basic) basic._ANSIBLE_ARGS = None
am = basic.AnsibleModule( am = basic.AnsibleModule(
argument_spec = dict(), argument_spec = dict(),
@ -771,7 +765,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
def test_module_utils_basic_ansible_module_set_mode_if_different(self): def test_module_utils_basic_ansible_module_set_mode_if_different(self):
from ansible.module_utils import basic from ansible.module_utils import basic
reload(basic) basic._ANSIBLE_ARGS = None
am = basic.AnsibleModule( am = basic.AnsibleModule(
argument_spec = dict(), argument_spec = dict(),
@ -859,7 +853,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
): ):
from ansible.module_utils import basic from ansible.module_utils import basic
reload(basic) basic._ANSIBLE_ARGS = None
am = basic.AnsibleModule( am = basic.AnsibleModule(
argument_spec = dict(), argument_spec = dict(),
@ -1037,7 +1031,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
def test_module_utils_basic_ansible_module__symbolic_mode_to_octal(self): def test_module_utils_basic_ansible_module__symbolic_mode_to_octal(self):
from ansible.module_utils import basic from ansible.module_utils import basic
reload(basic) basic._ANSIBLE_ARGS = None
am = basic.AnsibleModule( am = basic.AnsibleModule(
argument_spec = dict(), argument_spec = dict(),

Loading…
Cancel
Save