Ejemplo n.º 1
0
    def test_user_is_not_sudoer(self):
        check = checkopenbgpd.CheckBgpCtl(None)
        err_message = no_sudoer

        with mock.patch("checkopenbgpd.checkopenbgpd._popen") as _popen:
            _popen.return_value = '', err_message
            with self.assertRaises(CheckError):
                check._get_sessions()  # NOQA
Ejemplo n.º 2
0
    def test_check_idle_session_not_in_idle_list(self):
        check = checkopenbgpd.CheckBgpCtl(['THIRD'])
        output = bgpctl_sh

        with mock.patch("checkopenbgpd.checkopenbgpd._popen") as _popen:
            _popen.return_value = output, ''
            sessions = check._get_sessions()
            result = check.check_session(sessions[0])
            self.assertEquals(result, 'U')
Ejemplo n.º 3
0
    def test_check_session_is_up(self):
        check = checkopenbgpd.CheckBgpCtl(None)
        output = bgpctl_sh

        with mock.patch("checkopenbgpd.checkopenbgpd._popen") as _popen:
            _popen.return_value = output, ''
            sessions = check._get_sessions()
            result = check.check_session(sessions[1])
            self.assertEquals(result, 529001)
Ejemplo n.º 4
0
    def test__get_sessions(self):
        check = checkopenbgpd.CheckBgpCtl(None)
        output = bgpctl_sh

        with mock.patch("checkopenbgpd.checkopenbgpd._popen") as _popen:
            _popen.return_value = output, ''
            sessions = check._get_sessions()
            self.assertEquals(len(sessions), 3)
            self.assertEquals(type(sessions[0]), checkopenbgpd.Session)
Ejemplo n.º 5
0
    def test_check_probe_with_idle_list(self):
        check = checkopenbgpd.CheckBgpCtl(['THIRD'])
        output = bgpctl_sh

        with mock.patch("checkopenbgpd.checkopenbgpd._popen") as _popen:
            _popen.return_value = output, ''
            check._get_sessions()
            probe = check.probe()
            first = next(probe)
            self.assertEqual(type(first), Metric)
            self.assertEquals(first.value, 'U')
            second = next(probe)
            self.assertEquals(second.value, 529001)
            third = next(probe)
            self.assertEquals(third.value, 0)