diff options
author | Scott Moser <smoser@ubuntu.com> | 2014-07-24 11:12:14 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2014-07-24 11:12:14 -0400 |
commit | 986ee27cff1de8afdcbe72f464afef573790d373 (patch) | |
tree | 4ec844fa3ab6b50e2c53bf51d95c2bacbacc3c83 /tests | |
parent | f7e63d61cffde091f0d876e4acc6778943cb7499 (diff) | |
download | vyos-cloud-init-986ee27cff1de8afdcbe72f464afef573790d373.tar.gz vyos-cloud-init-986ee27cff1de8afdcbe72f464afef573790d373.zip |
test: make selinux test skipped if selinux not available.
Also, in debian packaging depend on it (so it wont skip there).
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unittests/test_util.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py index 335ab730..618a317d 100644 --- a/tests/unittests/test_util.py +++ b/tests/unittests/test_util.py @@ -6,12 +6,18 @@ import yaml from mocker import MockerTestCase from . import helpers -from unittest import TestCase +import unittest 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): @@ -31,7 +37,7 @@ class FakeSelinux(object): self.restored.append(path) -class TestGetCfgOptionListOrStr(TestCase): +class TestGetCfgOptionListOrStr(unittest.TestCase): def test_not_found_no_default(self): """None is returned if key is not found and no default given.""" config = {} @@ -122,6 +128,7 @@ 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.""" import_mock = self.mocker.replace(importer.import_module, @@ -201,20 +208,20 @@ class TestDeleteDirContents(MockerTestCase): self.assertDirEmpty(self.tmp) -class TestKeyValStrings(TestCase): +class TestKeyValStrings(unittest.TestCase): def test_keyval_str_to_dict(self): expected = {'1': 'one', '2': 'one+one', 'ro': True} cmdline = "1=one ro 2=one+one" self.assertEqual(expected, util.keyval_str_to_dict(cmdline)) -class TestGetCmdline(TestCase): +class TestGetCmdline(unittest.TestCase): def test_cmdline_reads_debug_env(self): os.environ['DEBUG_PROC_CMDLINE'] = 'abcd 123' self.assertEqual(os.environ['DEBUG_PROC_CMDLINE'], util.get_cmdline()) -class TestLoadYaml(TestCase): +class TestLoadYaml(unittest.TestCase): mydefault = "7b03a8ebace993d806255121073fed52" def test_simple(self): |