diff options
author | Scott Moser <smoser@ubuntu.com> | 2012-12-04 10:01:46 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2012-12-04 10:01:46 -0500 |
commit | 81ea305461777d5e5bec9f92a0b14c544aa6fd1e (patch) | |
tree | dde2cd2ef65f03cf48cdd51638d0332b0a32d4cc /tests/unittests/test_distros/test_generic.py | |
parent | 52a1884822ecb9474e12e6c16b62dbd0728a4a0e (diff) | |
parent | 1e7b96743314f566814848ad05c5bc7271a5de91 (diff) | |
download | vyos-cloud-init-81ea305461777d5e5bec9f92a0b14c544aa6fd1e.tar.gz vyos-cloud-init-81ea305461777d5e5bec9f92a0b14c544aa6fd1e.zip |
merge from trunk
Diffstat (limited to 'tests/unittests/test_distros/test_generic.py')
-rw-r--r-- | tests/unittests/test_distros/test_generic.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/unittests/test_distros/test_generic.py b/tests/unittests/test_distros/test_generic.py index 704699b5..7befb8c8 100644 --- a/tests/unittests/test_distros/test_generic.py +++ b/tests/unittests/test_distros/test_generic.py @@ -55,6 +55,59 @@ class TestGenericDistro(helpers.FilesystemMockingTestCase): # Make a temp directoy for tests to use. self.tmp = self.makeDir() + def _write_load_sudoers(self, _user, rules): + cls = distros.fetch("ubuntu") + d = cls("ubuntu", {}, None) + os.makedirs(os.path.join(self.tmp, "etc")) + os.makedirs(os.path.join(self.tmp, "etc", 'sudoers.d')) + self.patchOS(self.tmp) + self.patchUtils(self.tmp) + d.write_sudo_rules("harlowja", rules) + contents = util.load_file(d.ci_sudoers_fn) + self.restore() + return contents + + def _count_in(self, lines_look_for, text_content): + found_amount = 0 + for e in lines_look_for: + for line in text_content.splitlines(): + line = line.strip() + if line == e: + found_amount += 1 + return found_amount + + def test_sudoers_ensure_rules(self): + rules = 'ALL=(ALL:ALL) ALL' + contents = self._write_load_sudoers('harlowja', rules) + expected = ['harlowja ALL=(ALL:ALL) ALL'] + self.assertEquals(len(expected), self._count_in(expected, contents)) + not_expected = [ + 'harlowja A', + 'harlowja L', + 'harlowja L', + ] + self.assertEquals(0, self._count_in(not_expected, contents)) + + def test_sudoers_ensure_rules_list(self): + rules = [ + 'ALL=(ALL:ALL) ALL', + 'B-ALL=(ALL:ALL) ALL', + 'C-ALL=(ALL:ALL) ALL', + ] + contents = self._write_load_sudoers('harlowja', rules) + expected = [ + 'harlowja ALL=(ALL:ALL) ALL', + 'harlowja B-ALL=(ALL:ALL) ALL', + 'harlowja C-ALL=(ALL:ALL) ALL', + ] + self.assertEquals(len(expected), self._count_in(expected, contents)) + not_expected = [ + 'harlowja A', + 'harlowja L', + 'harlowja L', + ] + self.assertEquals(0, self._count_in(not_expected, contents)) + def test_sudoers_ensure_new(self): cls = distros.fetch("ubuntu") d = cls("ubuntu", {}, None) |