summaryrefslogtreecommitdiff
path: root/tests/unittests/test_distros/test_generic.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@gmail.com>2012-11-10 10:15:16 -0800
committerJoshua Harlow <harlowja@gmail.com>2012-11-10 10:15:16 -0800
commita17a69c35c1de0a6bd6f054f76d3da9e4a9c5364 (patch)
treea7091c10d9bf07ed3f743a111fecf5a9135fbb98 /tests/unittests/test_distros/test_generic.py
parent2c79c14b510751ab455888ab46f70c27b219bd19 (diff)
downloadvyos-cloud-init-a17a69c35c1de0a6bd6f054f76d3da9e4a9c5364.tar.gz
vyos-cloud-init-a17a69c35c1de0a6bd6f054f76d3da9e4a9c5364.zip
Sudoers.d creation cleanups + tests.
Diffstat (limited to 'tests/unittests/test_distros/test_generic.py')
-rw-r--r--tests/unittests/test_distros/test_generic.py32
1 files changed, 29 insertions, 3 deletions
diff --git a/tests/unittests/test_distros/test_generic.py b/tests/unittests/test_distros/test_generic.py
index 2df4c2f0..704699b5 100644
--- a/tests/unittests/test_distros/test_generic.py
+++ b/tests/unittests/test_distros/test_generic.py
@@ -1,6 +1,9 @@
-from mocker import MockerTestCase
-
from cloudinit import distros
+from cloudinit import util
+
+from tests.unittests import helpers
+
+import os
unknown_arch_info = {
'arches': ['default'],
@@ -27,7 +30,7 @@ gpmi = distros._get_package_mirror_info # pylint: disable=W0212
gapmi = distros._get_arch_package_mirror_info # pylint: disable=W0212
-class TestGenericDistro(MockerTestCase):
+class TestGenericDistro(helpers.FilesystemMockingTestCase):
def return_first(self, mlist):
if not mlist:
@@ -52,6 +55,29 @@ class TestGenericDistro(MockerTestCase):
# Make a temp directoy for tests to use.
self.tmp = self.makeDir()
+ def test_sudoers_ensure_new(self):
+ cls = distros.fetch("ubuntu")
+ d = cls("ubuntu", {}, None)
+ self.patchOS(self.tmp)
+ self.patchUtils(self.tmp)
+ d.ensure_sudo_dir("/b")
+ contents = util.load_file("/etc/sudoers")
+ self.assertIn("includedir /b", contents)
+ self.assertTrue(os.path.isdir("/b"))
+
+ def test_sudoers_ensure_append(self):
+ cls = distros.fetch("ubuntu")
+ d = cls("ubuntu", {}, None)
+ self.patchOS(self.tmp)
+ self.patchUtils(self.tmp)
+ util.write_file("/etc/sudoers", "josh, josh\n")
+ d.ensure_sudo_dir("/b")
+ contents = util.load_file("/etc/sudoers")
+ self.assertIn("includedir /b", contents)
+ self.assertTrue(os.path.isdir("/b"))
+ self.assertIn("josh", contents)
+ self.assertEquals(2, contents.count("josh"))
+
def test_arch_package_mirror_info_unknown(self):
"""for an unknown arch, we should get back that with arch 'default'."""
arch_mirrors = gapmi(package_mirrors, arch="unknown")