From 4b8397a510c4ff6f903e98bef50d350410f41451 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Thu, 24 Jul 2014 19:41:10 -0400 Subject: 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. --- tests/unittests/test_util.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'tests') 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): -- cgit v1.2.3