Esempio n. 1
0
    def test_threshold_met_true(self):
        ns_results = [2 for i in range(8)] + [0, 0]
        result = zone.DNSQueryResult(
            positives=8,
            no_zones=2,
            consensus_serial=2,
            results=ns_results,
        )

        success, status = self.poller._threshold_met(result)

        assert success
        assert status == 'SUCCESS'
Esempio n. 2
0
    def test_threshold_met_true(self):
        ns_results = [2] * 8 + [0] * 2
        result = zone.DNSQueryResult(
            positives=8,
            no_zones=2,
            consensus_serial=2,
            results=ns_results,
        )

        success, status = self.poller._threshold_met(result)

        self.assertTrue(success)
        self.assertEqual('SUCCESS', status)
Esempio n. 3
0
    def test_threshold_met_false_low_positives(self):
        # 6 positives, 4 behind the serial (aka 0 no_zones)
        ns_results = [2 for i in range(6)] + [1 for i in range(4)]
        result = zone.DNSQueryResult(
            positives=6,
            no_zones=0,
            consensus_serial=2,
            results=ns_results,
        )

        success, status = self.poller._threshold_met(result)

        assert not success
        assert status == 'ERROR'
Esempio n. 4
0
    def test_threshold_met_false_low_positives(self):
        # 6 positives, 4 behind the serial (aka 0 no_zones)
        ns_results = [2] * 6 + [1] * 4
        result = zone.DNSQueryResult(
            positives=6,
            no_zones=0,
            consensus_serial=2,
            results=ns_results,
        )

        success, status = self.poller._threshold_met(result)

        self.assertFalse(success)
        self.assertEqual('ERROR', status)
Esempio n. 5
0
    def test_threshold_met_false_no_zones_one_result(self):
        # Change is looking for serial 2
        # 4 positives, 4 no zones
        ns_results = [0]
        result = zone.DNSQueryResult(
            positives=0,
            no_zones=1,
            consensus_serial=2,
            results=ns_results,
        )

        # Set the threshold to 100%
        self.poller._threshold = 100
        self.poller.zone.action = 'UPDATE'

        success, status = self.poller._threshold_met(result)

        assert not success
        assert status == 'NO_ZONE'
Esempio n. 6
0
    def test_threshold_met_true_no_zones(self):
        # Change is looking for serial 2
        # 4 positives, 4 no zones, 2 behind the serial
        ns_results = [2 for i in range(4)] + [0 for i in range(4)] + [1, 1]
        result = zone.DNSQueryResult(
            positives=4,
            no_zones=4,
            consensus_serial=1,
            results=ns_results,
        )

        # Set the threshold to 30%
        self.poller._threshold = 30
        self.poller.zone.action = 'UPDATE'

        success, status = self.poller._threshold_met(result)

        assert success
        assert status == 'SUCCESS'
Esempio n. 7
0
    def test_threshold_met_false_no_zones(self):
        # Change is looking for serial 2
        # 4 positives, 4 no zones
        ns_results = [2] * 4 + [0] * 4
        result = zone.DNSQueryResult(
            positives=4,
            no_zones=4,
            consensus_serial=2,
            results=ns_results,
        )

        # Set the threshold to 100%
        self.poller._threshold = 100
        self.poller.zone.action = 'UPDATE'

        success, status = self.poller._threshold_met(result)

        self.assertFalse(success)
        self.assertEqual('NO_ZONE', status)
Esempio n. 8
0
    def test_threshold_met_true_no_zones(self):
        # Change is looking for serial 2
        # 4 positives, 4 no zones, 2 behind the serial
        ns_results = [2] * 4 + [0] * 4 + [1] * 2
        result = zone.DNSQueryResult(
            positives=4,
            no_zones=4,
            consensus_serial=1,
            results=ns_results,
        )

        # Set the threshold to 30%
        self.poller._threshold = 30
        self.poller.zone.action = 'UPDATE'

        success, status = self.poller._threshold_met(result)

        self.assertTrue(success)
        self.assertEqual('SUCCESS', status)
Esempio n. 9
0
    def test_call_on_success(self):
        ns_results = [2 for i in range(8)] + [0, 0]
        result = zone.DNSQueryResult(
            positives=8,
            no_zones=2,
            consensus_serial=2,
            results=ns_results,
        )
        self.poller.zone.action = 'UPDATE'
        self.poller.zone.serial = 2
        self.poller._do_poll = mock.Mock(return_value=result)
        self.poller._on_success = mock.Mock(return_value=True)
        self.poller._update_status = mock.Mock()

        assert self.poller()

        self.poller._on_success.assert_called_with(result, 'SUCCESS')
        self.poller._update_status.called
        self.poller.zone.serial = 2
        self.poller.zone.status = 'SUCCESS'