Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove reload from arg related tests. #15782

Merged
merged 1 commit into from
May 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 3 additions & 5 deletions test/units/module_utils/basic/test_exit_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
from units.mock.procenv import swap_stdin_and_argv, swap_stdout

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': {}}
Expand All @@ -45,7 +43,7 @@ def setUp(self):
self.stdout_swap_ctx = swap_stdout()
self.fake_stream = self.stdout_swap_ctx.__enter__()

reload(basic)
basic._ANSIBLE_ARGS = None
self.module = basic.AnsibleModule(argument_spec=dict())

def tearDown(self):
Expand Down Expand Up @@ -126,8 +124,8 @@ def test_exit_json_removes_values(self):
params = json.dumps(params)

with swap_stdin_and_argv(stdin_data=params):
reload(basic)
with swap_stdout():
basic._ANSIBLE_ARGS = None
module = basic.AnsibleModule(
argument_spec = dict(
username=dict(),
Expand All @@ -148,8 +146,8 @@ def test_fail_json_removes_values(self):
params = dict(ANSIBLE_MODULE_ARGS=args, ANSIBLE_MODULE_CONSTANTS={})
params = json.dumps(params)
with swap_stdin_and_argv(stdin_data=params):
reload(basic)
with swap_stdout():
basic._ANSIBLE_ARGS = None
module = basic.AnsibleModule(
argument_spec = dict(
username=dict(),
Expand Down
44 changes: 22 additions & 22 deletions test/units/module_utils/basic/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from ansible.compat.tests.mock import patch, MagicMock
from units.mock.procenv import swap_stdin_and_argv

from ansible.module_utils import basic
import ansible.module_utils.basic


try:
Expand All @@ -49,20 +49,20 @@ def setUp(self):
self.stdin_swap = swap_stdin_and_argv(stdin_data=args)
self.stdin_swap.__enter__()

reload(basic)
self.am = basic.AnsibleModule(
ansible.module_utils.basic._ANSIBLE_ARGS = None
self.am = ansible.module_utils.basic.AnsibleModule(
argument_spec = dict(),
)

self.has_journal = basic.has_journal
self.has_journal = ansible.module_utils.basic.has_journal
if self.has_journal:
# Systems with journal can still test syslog
basic.has_journal = False
ansible.module_utils.basic.has_journal = False

def tearDown(self):
# 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)
basic.has_journal = self.has_journal
ansible.module_utils.basic.has_journal = self.has_journal

def test_smoketest_syslog(self):
# These talk to the live daemons on the system. Need to do this to
Expand All @@ -86,16 +86,16 @@ def setUp(self):
self.stdin_swap = swap_stdin_and_argv(stdin_data=args)
self.stdin_swap.__enter__()

reload(basic)
self.am = basic.AnsibleModule(
ansible.module_utils.basic._ANSIBLE_ARGS = None
self.am = ansible.module_utils.basic.AnsibleModule(
argument_spec = dict(),
)

def tearDown(self):
# 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)

@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):
# 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
Expand Down Expand Up @@ -134,19 +134,19 @@ def setUp(self):
self.stdin_swap = swap_stdin_and_argv(stdin_data=args)
self.stdin_swap.__enter__()

reload(basic)
self.am = basic.AnsibleModule(
ansible.module_utils.basic._ANSIBLE_ARGS = None
self.am = ansible.module_utils.basic.AnsibleModule(
argument_spec = dict(),
)

self.has_journal = basic.has_journal
self.has_journal = ansible.module_utils.basic.has_journal
if self.has_journal:
# Systems with journal can still test syslog
basic.has_journal = False
ansible.module_utils.basic.has_journal = False

def tearDown(self):
# 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
self.stdin_swap.__exit__(None, None, None)
Expand Down Expand Up @@ -195,13 +195,13 @@ def setUp(self):
self.stdin_swap = swap_stdin_and_argv(stdin_data=args)
self.stdin_swap.__enter__()

reload(basic)
self.am = basic.AnsibleModule(
ansible.module_utils.basic._ANSIBLE_ARGS = None
self.am = ansible.module_utils.basic.AnsibleModule(
argument_spec = dict(),
)

self.has_journal = basic.has_journal
basic.has_journal = True
self.has_journal = ansible.module_utils.basic.has_journal
ansible.module_utils.basic.has_journal = True

self.module_patcher = None

Expand All @@ -210,20 +210,20 @@ def setUp(self):
self.module_patcher = patch.dict('sys.modules', {'systemd': MagicMock(), 'systemd.journal': MagicMock()})
self.module_patcher.start()
try:
reload(basic)
reload(ansible.module_utils.basic)
except NameError:
self._fake_out_reload(basic)
self._fake_out_reload(ansible.module_utils.basic)

def tearDown(self):
# 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)

# teardown/reset
basic.has_journal = self.has_journal
ansible.module_utils.basic.has_journal = self.has_journal

if self.module_patcher:
self.module_patcher.stop()
reload(basic)
reload(ansible.module_utils.basic)

@patch('systemd.journal.send')
def test_no_log(self, mock_func):
Expand Down
2 changes: 1 addition & 1 deletion test/units/module_utils/basic/test_run_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def mock_os_chdir(path):
self.stdin_swap = swap_stdin_and_argv(stdin_data=args)
self.stdin_swap.__enter__()

reload(basic)
basic._ANSIBLE_ARGS = None
self.module = AnsibleModule(argument_spec=dict())
self.module.fail_json = MagicMock(side_effect=SystemExit)

Expand Down
8 changes: 1 addition & 7 deletions test/units/module_utils/basic/test_safe_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@
from ansible.compat.tests import unittest
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):

def test_module_utils_basic_safe_eval(self):
Expand All @@ -40,7 +34,7 @@ def test_module_utils_basic_safe_eval(self):
args = json.dumps(dict(ANSIBLE_MODULE_ARGS={}, ANSIBLE_MODULE_CONSTANTS={}))

with swap_stdin_and_argv(stdin_data=args):
reload(basic)
basic._ANSIBLE_ARGS = None
am = basic.AnsibleModule(
argument_spec=dict(),
)
Expand Down
40 changes: 17 additions & 23 deletions test/units/module_utils/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@
except ImportError:
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 ansible.compat.tests import unittest
Expand Down Expand Up @@ -297,7 +291,7 @@ def test_module_utils_basic_ansible_module_creation(self):
args = json.dumps(dict(ANSIBLE_MODULE_ARGS={"foo": "hello"}, ANSIBLE_MODULE_CONSTANTS={}))

with swap_stdin_and_argv(stdin_data=args):
reload(basic)
basic._ANSIBLE_ARGS = None
am = basic.AnsibleModule(
argument_spec = arg_spec,
mutually_exclusive = mut_ex,
Expand All @@ -314,7 +308,7 @@ def test_module_utils_basic_ansible_module_creation(self):
args = json.dumps(dict(ANSIBLE_MODULE_ARGS={}, ANSIBLE_MODULE_CONSTANTS={}))

with swap_stdin_and_argv(stdin_data=args):
reload(basic)
basic._ANSIBLE_ARGS = None
self.assertRaises(
SystemExit,
basic.AnsibleModule,
Expand Down Expand Up @@ -361,7 +355,7 @@ def test_module_utils_basic_ansible_module_creation(self):

def test_module_utils_basic_ansible_module_load_file_common_arguments(self):
from ansible.module_utils import basic
reload(basic)
basic._ANSIBLE_ARGS = None

am = basic.AnsibleModule(
argument_spec = dict(),
Expand Down Expand Up @@ -410,7 +404,7 @@ def test_module_utils_basic_ansible_module_load_file_common_arguments(self):

def test_module_utils_basic_ansible_module_selinux_mls_enabled(self):
from ansible.module_utils import basic
reload(basic)
basic._ANSIBLE_ARGS = None

am = basic.AnsibleModule(
argument_spec = dict(),
Expand All @@ -430,7 +424,7 @@ def test_module_utils_basic_ansible_module_selinux_mls_enabled(self):

def test_module_utils_basic_ansible_module_selinux_initial_context(self):
from ansible.module_utils import basic
reload(basic)
basic._ANSIBLE_ARGS = None

am = basic.AnsibleModule(
argument_spec = dict(),
Expand All @@ -444,7 +438,7 @@ def test_module_utils_basic_ansible_module_selinux_initial_context(self):

def test_module_utils_basic_ansible_module_selinux_enabled(self):
from ansible.module_utils import basic
reload(basic)
basic._ANSIBLE_ARGS = None

am = basic.AnsibleModule(
argument_spec = dict(),
Expand Down Expand Up @@ -476,7 +470,7 @@ def test_module_utils_basic_ansible_module_selinux_enabled(self):

def test_module_utils_basic_ansible_module_selinux_default_context(self):
from ansible.module_utils import basic
reload(basic)
basic._ANSIBLE_ARGS = None

am = basic.AnsibleModule(
argument_spec = dict(),
Expand Down Expand Up @@ -512,7 +506,7 @@ def test_module_utils_basic_ansible_module_selinux_default_context(self):

def test_module_utils_basic_ansible_module_selinux_context(self):
from ansible.module_utils import basic
reload(basic)
basic._ANSIBLE_ARGS = None

am = basic.AnsibleModule(
argument_spec = dict(),
Expand Down Expand Up @@ -554,7 +548,7 @@ def test_module_utils_basic_ansible_module_selinux_context(self):

def test_module_utils_basic_ansible_module_is_special_selinux_path(self):
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"}))

Expand Down Expand Up @@ -599,7 +593,7 @@ def _mock_find_mount_point(path):

def test_module_utils_basic_ansible_module_to_filesystem_str(self):
from ansible.module_utils import basic
reload(basic)
basic._ANSIBLE_ARGS = None

am = basic.AnsibleModule(
argument_spec = dict(),
Expand All @@ -624,7 +618,7 @@ def test_module_utils_basic_ansible_module_user_and_group(self):

def test_module_utils_basic_ansible_module_find_mount_point(self):
from ansible.module_utils import basic
reload(basic)
basic._ANSIBLE_ARGS = None

am = basic.AnsibleModule(
argument_spec = dict(),
Expand All @@ -648,7 +642,7 @@ def _mock_ismount(path):

def test_module_utils_basic_ansible_module_set_context_if_different(self):
from ansible.module_utils import basic
reload(basic)
basic._ANSIBLE_ARGS = None

am = basic.AnsibleModule(
argument_spec = dict(),
Expand Down Expand Up @@ -693,7 +687,7 @@ def test_module_utils_basic_ansible_module_set_context_if_different(self):

def test_module_utils_basic_ansible_module_set_owner_if_different(self):
from ansible.module_utils import basic
reload(basic)
basic._ANSIBLE_ARGS = None

am = basic.AnsibleModule(
argument_spec = dict(),
Expand Down Expand Up @@ -732,7 +726,7 @@ def _mock_getpwnam(*args, **kwargs):

def test_module_utils_basic_ansible_module_set_group_if_different(self):
from ansible.module_utils import basic
reload(basic)
basic._ANSIBLE_ARGS = None

am = basic.AnsibleModule(
argument_spec = dict(),
Expand Down Expand Up @@ -771,7 +765,7 @@ def _mock_getgrnam(*args, **kwargs):

def test_module_utils_basic_ansible_module_set_mode_if_different(self):
from ansible.module_utils import basic
reload(basic)
basic._ANSIBLE_ARGS = None

am = basic.AnsibleModule(
argument_spec = dict(),
Expand Down Expand Up @@ -859,7 +853,7 @@ def test_module_utils_basic_ansible_module_atomic_move(
):

from ansible.module_utils import basic
reload(basic)
basic._ANSIBLE_ARGS = None

am = basic.AnsibleModule(
argument_spec = dict(),
Expand Down Expand Up @@ -1037,7 +1031,7 @@ def test_module_utils_basic_ansible_module_atomic_move(
def test_module_utils_basic_ansible_module__symbolic_mode_to_octal(self):

from ansible.module_utils import basic
reload(basic)
basic._ANSIBLE_ARGS = None

am = basic.AnsibleModule(
argument_spec = dict(),
Expand Down