summaryrefslogtreecommitdiff
path: root/tests/unittests
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2014-07-24 19:41:10 -0400
committerScott Moser <smoser@ubuntu.com>2014-07-24 19:41:10 -0400
commit4b8397a510c4ff6f903e98bef50d350410f41451 (patch)
tree8fe4f85db0c1b77c9ed2bc05314bfd89605cdcfa /tests/unittests
parent986ee27cff1de8afdcbe72f464afef573790d373 (diff)
downloadvyos-cloud-init-4b8397a510c4ff6f903e98bef50d350410f41451.tar.gz
vyos-cloud-init-4b8397a510c4ff6f903e98bef50d350410f41451.zip
SeLinuxGuard: remove invalid check for sanity around restorecon, fix test
previous commit occurred because the selinux test was failing in a schroot where there was no /etc/hosts. Now, fix that test more correctly, and fix some bad assumptions in the SeLinuxGuard.
Diffstat (limited to 'tests/unittests')
-rw-r--r--tests/unittests/test_util.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py
index 618a317d..0cb41520 100644
--- a/tests/unittests/test_util.py
+++ b/tests/unittests/test_util.py
@@ -12,12 +12,6 @@ from cloudinit import importer
from cloudinit import util
-try:
- import selinux
- HAS_SELINUX = True
-except ImportError:
- HAS_SELINUX = False
-
class FakeSelinux(object):
def __init__(self, match_what):
@@ -128,19 +122,23 @@ class TestWriteFile(MockerTestCase):
create_contents = f.read()
self.assertEqual("LINE1\nHey there", create_contents)
- @unittest.skipIf(not HAS_SELINUX, "selinux not available")
def test_restorecon_if_possible_is_called(self):
"""Make sure the selinux guard is called correctly."""
+ my_file = os.path.join(self.tmp, "my_file")
+ with open(my_file, "w") as fp:
+ fp.write("My Content")
+
import_mock = self.mocker.replace(importer.import_module,
passthrough=False)
import_mock('selinux')
- fake_se = FakeSelinux('/etc/hosts')
+
+ fake_se = FakeSelinux(my_file)
self.mocker.result(fake_se)
self.mocker.replay()
- with util.SeLinuxGuard("/etc/hosts") as is_on:
+ with util.SeLinuxGuard(my_file) as is_on:
self.assertTrue(is_on)
self.assertEqual(1, len(fake_se.restored))
- self.assertEqual('/etc/hosts', fake_se.restored[0])
+ self.assertEqual(my_file, fake_se.restored[0])
class TestDeleteDirContents(MockerTestCase):