|
|
|
@ -31,6 +31,12 @@ try:
|
|
|
|
|
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
|
|
|
|
@ -291,6 +297,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
|
|
|
|
|
args = json.dumps(dict(ANSIBLE_MODULE_ARGS={"foo": "hello"}, ANSIBLE_MODULE_CONSTANTS={}))
|
|
|
|
|
|
|
|
|
|
with swap_stdin_and_argv(stdin_data=args):
|
|
|
|
|
reload(basic)
|
|
|
|
|
am = basic.AnsibleModule(
|
|
|
|
|
argument_spec = arg_spec,
|
|
|
|
|
mutually_exclusive = mut_ex,
|
|
|
|
@ -307,6 +314,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
|
|
|
|
|
args = json.dumps(dict(ANSIBLE_MODULE_ARGS={}, ANSIBLE_MODULE_CONSTANTS={}))
|
|
|
|
|
|
|
|
|
|
with swap_stdin_and_argv(stdin_data=args):
|
|
|
|
|
reload(basic)
|
|
|
|
|
self.assertRaises(
|
|
|
|
|
SystemExit,
|
|
|
|
|
basic.AnsibleModule,
|
|
|
|
@ -353,6 +361,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_module_utils_basic_ansible_module_load_file_common_arguments(self):
|
|
|
|
|
from ansible.module_utils import basic
|
|
|
|
|
reload(basic)
|
|
|
|
|
|
|
|
|
|
am = basic.AnsibleModule(
|
|
|
|
|
argument_spec = dict(),
|
|
|
|
@ -401,6 +410,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_module_utils_basic_ansible_module_selinux_mls_enabled(self):
|
|
|
|
|
from ansible.module_utils import basic
|
|
|
|
|
reload(basic)
|
|
|
|
|
|
|
|
|
|
am = basic.AnsibleModule(
|
|
|
|
|
argument_spec = dict(),
|
|
|
|
@ -420,6 +430,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_module_utils_basic_ansible_module_selinux_initial_context(self):
|
|
|
|
|
from ansible.module_utils import basic
|
|
|
|
|
reload(basic)
|
|
|
|
|
|
|
|
|
|
am = basic.AnsibleModule(
|
|
|
|
|
argument_spec = dict(),
|
|
|
|
@ -433,6 +444,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_module_utils_basic_ansible_module_selinux_enabled(self):
|
|
|
|
|
from ansible.module_utils import basic
|
|
|
|
|
reload(basic)
|
|
|
|
|
|
|
|
|
|
am = basic.AnsibleModule(
|
|
|
|
|
argument_spec = dict(),
|
|
|
|
@ -464,6 +476,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_module_utils_basic_ansible_module_selinux_default_context(self):
|
|
|
|
|
from ansible.module_utils import basic
|
|
|
|
|
reload(basic)
|
|
|
|
|
|
|
|
|
|
am = basic.AnsibleModule(
|
|
|
|
|
argument_spec = dict(),
|
|
|
|
@ -499,6 +512,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_module_utils_basic_ansible_module_selinux_context(self):
|
|
|
|
|
from ansible.module_utils import basic
|
|
|
|
|
reload(basic)
|
|
|
|
|
|
|
|
|
|
am = basic.AnsibleModule(
|
|
|
|
|
argument_spec = dict(),
|
|
|
|
@ -540,6 +554,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_module_utils_basic_ansible_module_is_special_selinux_path(self):
|
|
|
|
|
from ansible.module_utils import basic
|
|
|
|
|
reload(basic)
|
|
|
|
|
|
|
|
|
|
args = json.dumps(dict(ANSIBLE_MODULE_ARGS={}, ANSIBLE_MODULE_CONSTANTS={"SELINUX_SPECIAL_FS": "nfs,nfsd,foos"}))
|
|
|
|
|
|
|
|
|
@ -584,6 +599,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_module_utils_basic_ansible_module_to_filesystem_str(self):
|
|
|
|
|
from ansible.module_utils import basic
|
|
|
|
|
reload(basic)
|
|
|
|
|
|
|
|
|
|
am = basic.AnsibleModule(
|
|
|
|
|
argument_spec = dict(),
|
|
|
|
@ -608,6 +624,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_module_utils_basic_ansible_module_find_mount_point(self):
|
|
|
|
|
from ansible.module_utils import basic
|
|
|
|
|
reload(basic)
|
|
|
|
|
|
|
|
|
|
am = basic.AnsibleModule(
|
|
|
|
|
argument_spec = dict(),
|
|
|
|
@ -631,18 +648,19 @@ class TestModuleUtilsBasic(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_module_utils_basic_ansible_module_set_context_if_different(self):
|
|
|
|
|
from ansible.module_utils import basic
|
|
|
|
|
reload(basic)
|
|
|
|
|
|
|
|
|
|
am = basic.AnsibleModule(
|
|
|
|
|
argument_spec = dict(),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
basic.HAS_SELINUX = False
|
|
|
|
|
basic.HAVE_SELINUX = False
|
|
|
|
|
|
|
|
|
|
am.selinux_enabled = MagicMock(return_value=False)
|
|
|
|
|
self.assertEqual(am.set_context_if_different('/path/to/file', ['foo_u', 'foo_r', 'foo_t', 's0'], True), True)
|
|
|
|
|
self.assertEqual(am.set_context_if_different('/path/to/file', ['foo_u', 'foo_r', 'foo_t', 's0'], False), False)
|
|
|
|
|
|
|
|
|
|
basic.HAS_SELINUX = True
|
|
|
|
|
basic.HAVE_SELINUX = True
|
|
|
|
|
|
|
|
|
|
am.selinux_enabled = MagicMock(return_value=True)
|
|
|
|
|
am.selinux_context = MagicMock(return_value=['bar_u', 'bar_r', None, None])
|
|
|
|
@ -675,6 +693,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_module_utils_basic_ansible_module_set_owner_if_different(self):
|
|
|
|
|
from ansible.module_utils import basic
|
|
|
|
|
reload(basic)
|
|
|
|
|
|
|
|
|
|
am = basic.AnsibleModule(
|
|
|
|
|
argument_spec = dict(),
|
|
|
|
@ -713,6 +732,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_module_utils_basic_ansible_module_set_group_if_different(self):
|
|
|
|
|
from ansible.module_utils import basic
|
|
|
|
|
reload(basic)
|
|
|
|
|
|
|
|
|
|
am = basic.AnsibleModule(
|
|
|
|
|
argument_spec = dict(),
|
|
|
|
@ -751,6 +771,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_module_utils_basic_ansible_module_set_mode_if_different(self):
|
|
|
|
|
from ansible.module_utils import basic
|
|
|
|
|
reload(basic)
|
|
|
|
|
|
|
|
|
|
am = basic.AnsibleModule(
|
|
|
|
|
argument_spec = dict(),
|
|
|
|
@ -838,6 +859,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
from ansible.module_utils import basic
|
|
|
|
|
reload(basic)
|
|
|
|
|
|
|
|
|
|
am = basic.AnsibleModule(
|
|
|
|
|
argument_spec = dict(),
|
|
|
|
@ -1015,6 +1037,7 @@ class TestModuleUtilsBasic(unittest.TestCase):
|
|
|
|
|
def test_module_utils_basic_ansible_module__symbolic_mode_to_octal(self):
|
|
|
|
|
|
|
|
|
|
from ansible.module_utils import basic
|
|
|
|
|
reload(basic)
|
|
|
|
|
|
|
|
|
|
am = basic.AnsibleModule(
|
|
|
|
|
argument_spec = dict(),
|
|
|
|
|