Beispiel #1
0
    def test_absent(self):
        '''
        Test to verifies that the specified host is not known by the given user.
        '''
        name = 'github.com'
        user = '******'

        ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}

        with patch.object(os.path, 'isabs', MagicMock(return_value=False)):
            comt = ('If not specifying a "user", '
                    'specify an absolute "config".')
            ret.update({'comment': comt})
            self.assertDictEqual(ssh_known_hosts.absent(name), ret)

        mock = MagicMock(return_value=False)
        with patch.dict(ssh_known_hosts.__salt__,
                        {'ssh.get_known_host_entries': mock}):
            comt = ('Host is already absent')
            ret.update({'comment': comt, 'result': True})
            self.assertDictEqual(ssh_known_hosts.absent(name, user), ret)

        mock = MagicMock(return_value=True)
        with patch.dict(ssh_known_hosts.__salt__,
                        {'ssh.get_known_host_entries': mock}):
            with patch.dict(ssh_known_hosts.__opts__, {'test': True}):
                comt = ('Key for github.com is set to be'
                        ' removed from .ssh/known_hosts')
                ret.update({'comment': comt, 'result': None})
                self.assertDictEqual(ssh_known_hosts.absent(name, user), ret)

            with patch.dict(ssh_known_hosts.__opts__, {'test': False}):
                result = {'status': 'error', 'error': ''}
                mock = MagicMock(return_value=result)
                with patch.dict(ssh_known_hosts.__salt__,
                                {'ssh.rm_known_host': mock}):
                    ret.update({'comment': '', 'result': False})
                    self.assertDictEqual(ssh_known_hosts.absent(name, user),
                                         ret)

                result = {
                    'status': 'removed',
                    'error': '',
                    'comment': 'removed'
                }
                mock = MagicMock(return_value=result)
                with patch.dict(ssh_known_hosts.__salt__,
                                {'ssh.rm_known_host': mock}):
                    ret.update({
                        'comment': 'removed',
                        'result': True,
                        'changes': {
                            'new': None,
                            'old': True
                        }
                    })
                    self.assertDictEqual(ssh_known_hosts.absent(name, user),
                                         ret)
Beispiel #2
0
    def test_absent(self):
        '''
        Test to verifies that the specified host is not known by the given user.
        '''
        name = 'github.com'
        user = '******'

        ret = {'name': name,
               'changes': {},
               'result': False,
               'comment': ''}

        with patch.object(os.path, 'isabs', MagicMock(return_value=False)):
            comt = ('If not specifying a "user", '
                    'specify an absolute "config".')
            ret.update({'comment': comt})
            self.assertDictEqual(ssh_known_hosts.absent(name), ret)

        mock = MagicMock(return_value=False)
        with patch.dict(ssh_known_hosts.__salt__,
                        {'ssh.get_known_host': mock}):
            comt = ('Host is already absent')
            ret.update({'comment': comt, 'result': True})
            self.assertDictEqual(ssh_known_hosts.absent(name, user), ret)

        mock = MagicMock(return_value=True)
        with patch.dict(ssh_known_hosts.__salt__,
                        {'ssh.get_known_host': mock}):
            with patch.dict(ssh_known_hosts.__opts__, {'test': True}):
                comt = ('Key for github.com is set to be'
                        ' removed from .ssh/known_hosts')
                ret.update({'comment': comt, 'result': None})
                self.assertDictEqual(ssh_known_hosts.absent(name, user), ret)

            with patch.dict(ssh_known_hosts.__opts__, {'test': False}):
                result = {'status': 'error', 'error': ''}
                mock = MagicMock(return_value=result)
                with patch.dict(ssh_known_hosts.__salt__,
                                {'ssh.rm_known_host': mock}):
                    ret.update({'comment': '', 'result': False})
                    self.assertDictEqual(ssh_known_hosts.absent(name, user),
                                         ret)

                result = {'status': 'removed', 'error': '',
                          'comment': 'removed'}
                mock = MagicMock(return_value=result)
                with patch.dict(ssh_known_hosts.__salt__,
                                {'ssh.rm_known_host': mock}):
                    ret.update({'comment': 'removed', 'result': True,
                                'changes': {'new': None, 'old': True}})
                    self.assertDictEqual(ssh_known_hosts.absent(name, user),
                                         ret)
def test_absent():
    """
    Test to verifies that the specified host is not known by the given user.
    """
    name = "github.com"
    user = "******"

    ret = {"name": name, "changes": {}, "result": False, "comment": ""}

    with patch.object(os.path, "isabs", MagicMock(return_value=False)):
        comt = 'If not specifying a "user", specify an absolute "config".'
        ret.update({"comment": comt})
        assert ssh_known_hosts.absent(name) == ret

    mock = MagicMock(return_value=False)
    with patch.dict(ssh_known_hosts.__salt__,
                    {"ssh.get_known_host_entries": mock}):
        comt = "Host is already absent"
        ret.update({"comment": comt, "result": True})
        assert ssh_known_hosts.absent(name, user) == ret

    mock = MagicMock(return_value=True)
    with patch.dict(ssh_known_hosts.__salt__,
                    {"ssh.get_known_host_entries": mock}):
        with patch.dict(ssh_known_hosts.__opts__, {"test": True}):
            comt = "Key for github.com is set to be removed from .ssh/known_hosts"
            ret.update({"comment": comt, "result": None})
            assert ssh_known_hosts.absent(name, user) == ret

        with patch.dict(ssh_known_hosts.__opts__, {"test": False}):
            result = {"status": "error", "error": ""}
            mock = MagicMock(return_value=result)
            with patch.dict(ssh_known_hosts.__salt__,
                            {"ssh.rm_known_host": mock}):
                ret.update({"comment": "", "result": False})
                assert ssh_known_hosts.absent(name, user) == ret

            result = {"status": "removed", "error": "", "comment": "removed"}
            mock = MagicMock(return_value=result)
            with patch.dict(ssh_known_hosts.__salt__,
                            {"ssh.rm_known_host": mock}):
                ret.update({
                    "comment": "removed",
                    "result": True,
                    "changes": {
                        "new": None,
                        "old": True
                    },
                })
                assert ssh_known_hosts.absent(name, user) == ret