Example #1
0
 def test_not_installed(self):
     runresult = RunResult()
     runresult.return_code = 1
     runresult.stdout = "error: package 'foo' was not found"
     node = MagicMock()
     node.run.return_value = runresult
     self.assertFalse(pkg_pacman.pkg_installed(node, "foo"))
Example #2
0
 def test_not_running(self):
     runresult = RunResult()
     runresult.return_code = 3
     runresult.stdout = "whatever, does not matter"
     node = MagicMock()
     node.run.return_value = runresult
     self.assertFalse(svc_systemd.svc_running(node, "foo"))
Example #3
0
 def test_installed(self):
     runresult = RunResult()
     runresult.return_code = 0
     runresult.stdout = "foo 1.0.0-1\n"
     node = MagicMock()
     node.run.return_value = runresult
     self.assertTrue(pkg_pacman.pkg_installed(node, "foo"))
Example #4
0
 def test_running(self):
     runresult = RunResult()
     runresult.return_code = 0
     runresult.stdout = "foo start/running, process 1234\n"
     node = MagicMock()
     node.run.return_value = runresult
     self.assertTrue(svc_upstart.svc_running(node, "foo"))
Example #5
0
 def test_installed(self):
     runresult = RunResult()
     runresult.return_code = 0
     runresult.stdout = "Status: install ok installed\n"
     node = MagicMock()
     node.run.return_value = runresult
     self.assertTrue(pkg_apt.pkg_installed(node, "foo"))
Example #6
0
    def test_shadow_fail(self, _groups_for_user):
        _groups_for_user.return_value = ["group1", "group2"]
        bundle = MagicMock()
        user = users.User(
            bundle,
            "blockwart",
            {
                'full_name': "Blöck Wart",
                'gid': 2345,
                'groups': ["group1", "group2"],
                'home': "/home/blockwart",
                'password_hash': "secret",
                'shell': "/bin/bash",
                'uid': 1123,
            },
        )

        passwd_grep_result = RunResult()
        passwd_grep_result.return_code = 0
        passwd_grep_result.stdout = "blockwart:x:1123:2345:Blöck Wart:/home/blockwart:/bin/bash\n"
        shadow_grep_result = RunResult()
        shadow_grep_result.return_code = 1
        results = [shadow_grep_result, passwd_grep_result]

        def pop_result(*args, **kwargs):
            return results.pop()

        bundle.node.run.side_effect = pop_result

        status = user.get_status()
        self.assertFalse(status.correct)
        self.assertEqual(status.info['shadow_hash'], None)
Example #7
0
 def test_locked(self, ask_interactively):
     node = MagicMock()
     runres = RunResult()
     runres.return_code = 1
     node.run.return_value = runres
     with self.assertRaises(NodeAlreadyLockedException):
         with NodeLock(node, False, ignore=False):
             pass
Example #8
0
    def test_groups(self):
        node = MagicMock()
        result = RunResult()
        result.stdout = "group1 group2\n"
        node.run.return_value = result

        groups = users._groups_for_user(node, "jdoe")

        node.run.assert_called_once_with("id -Gn jdoe")
        self.assertEqual(groups, ["group1", "group2"])
Example #9
0
 def test_not_installed(self):
     runresult = RunResult()
     runresult.return_code = 1
     runresult.stdout = (
         "Package `foo' is not installed and no info is available.\n"
         "Use dpkg --info (= dpkg-deb --info) to examine archive files,\n"
         "and dpkg --contents (= dpkg-deb --contents) to list their contents.\n"
     )
     node = MagicMock()
     node.run.return_value = runresult
     self.assertFalse(pkg_apt.pkg_installed(node, "foo"))
Example #10
0
 def test_short_mode(self):
     node = MagicMock()
     run_result = RunResult()
     run_result.stdout = "user:group:666:4321"
     node.run.return_value = run_result
     stat_result = remote.stat(node, "/dev/null")
     self.assertEqual(stat_result, {
         'owner': "user",
         'group': "group",
         'mode': "0666",
         'size': 4321,
     })
Example #11
0
 def test_long_mode(self):
     node = MagicMock()
     run_result = RunResult()
     run_result.stdout = "user:group:7777:1234"
     node.run.return_value = run_result
     stat_result = remote.stat(node, "/dev/null")
     self.assertEqual(stat_result, {
         'owner': "user",
         'group': "group",
         'mode': "7777",
         'size': 1234,
     })
Example #12
0
    def test_group_fail(self):
        bundle = MagicMock()
        group = groups.Group(
            bundle,
            "blockwart",
            { 'gid': 2345 },
        )

        grep_result = RunResult()
        grep_result.return_code = 1

        bundle.node.run.return_value = grep_result

        status = group.get_status()
        self.assertFalse(status.correct)
        self.assertFalse(status.info['exists'])
Example #13
0
    def test_gid(self):
        bundle = MagicMock()
        group = groups.Group(
            bundle,
            "blockwart",
            { 'gid': 2345 },
        )

        grep_result = RunResult()
        grep_result.return_code = 0
        grep_result.stdout = "blockwart:x:5432:user1,user2\n"

        bundle.node.run.return_value = grep_result

        status = group.get_status()
        self.assertFalse(status.correct)
Example #14
0
    def test_delete(self):
        bundle = MagicMock()
        user = users.User(
            bundle,
            "blockwart",
            {'delete': True},
        )

        passwd_grep_result = RunResult()
        passwd_grep_result.return_code = 0
        passwd_grep_result.stdout = "blockwart:x:1123:2345:Blöck Wart:/home/blockwart:/bin/bash\n"

        bundle.node.run.return_value = passwd_grep_result

        status = user.get_status()
        self.assertFalse(status.correct)
        self.assertTrue(status.info['exists'])
Example #15
0
    def test_passwd_fail(self):
        bundle = MagicMock()
        user = users.User(
            bundle,
            "blockwart",
            {
                'full_name': "Blöck Wart",
                'gid': 2345,
                'groups': ["group1", "group2"],
                'home': "/home/blockwart",
                'password_hash': "secret",
                'shell': "/bin/bash",
                'uid': 1123,
            },
        )

        passwd_grep_result = RunResult()
        passwd_grep_result.return_code = 1

        bundle.node.run.return_value = passwd_grep_result

        status = user.get_status()
        self.assertFalse(status.correct)
        self.assertFalse(status.info['exists'])
Example #16
0
 def test_not_running(self):
     runresult = RunResult()
     runresult.stdout = "foo stop/waiting\n"
     node = MagicMock()
     node.run.return_value = runresult
     self.assertFalse(svc_upstart.svc_running(node, "foo"))