Ejemplo n.º 1
0
    def test_scan_history(self):
        # check if scan history data is used
        device0 = DeviceTestFactory()
        source0 = DiscoverySource.IPMI

        # one long one with priority
        DispatchSettingTestFactory(
            device=device0,
            source=source0,
            duration_amount=1,
            duration_unit=DispatchSetting.DurationUnits.days,
        )
        ScanHistoryTestFactory(
            device=device0,
            source=source0,
            duration=60 * 60 * 12,  # 1/2 day
            date=self.jan_fst -
            dateutil.relativedelta.relativedelta(months=2)  # long ago
        )
        ScanHistoryTestFactory(
            device=device0,
            source=source0,
            duration=60 * 60 * 12 * 3,  # 3/2 days
            date=self.jan_fst -
            dateutil.relativedelta.relativedelta(months=1)  # long ago
        )

        dispatcher = DiscoveryDispatcher()
        res = dispatcher.calculate(self.jan_fst, self.jan_snd)

        self.assertEqual(res[0].expected_run_date, self.jan_fst)
        self.assertEqual(res[0].expected_finish_date,
                         self.jan_snd)  # this tests the scan history
Ejemplo n.º 2
0
    def test_device_limit(self):
        device0 = DeviceTestFactory()

        self.create_simple_fixtures(device0, device0)

        dispatcher = DiscoveryDispatcher()
        res = dispatcher.calculate(self.jan_fst, self.jan_fst_three_am)

        self.assert_no_overlaps(res)
Ejemplo n.º 3
0
    def test_min_interval(self):
        device0 = DeviceTestFactory()
        source0 = DiscoverySource.IPMI
        source1 = DiscoverySource.SNMP

        # one long one with priority
        ds_long = DispatchSettingTestFactory(
            device=device0,
            source=source0,
            duration_amount=1,
            duration_unit=DispatchSetting.DurationUnits.weeks,
            run_now=True)
        # this takes long
        ScanHistoryTestFactory(
            device=device0,
            source=source0,
            duration=60 * 60 * 24,
            date=self.jan_fst - dateutil.relativedelta.relativedelta(
                hours=1)  # recently, but run_now is set
        )

        # short ones without priority
        ds_short = DispatchSettingTestFactory(
            device=device0,
            source=source1,
            duration_amount=1,
            duration_unit=DispatchSetting.DurationUnits.hours,
        )

        dispatcher = DiscoveryDispatcher()
        res = dispatcher.calculate(self.jan_fst, self.jan_thrd)

        # we want that the short ones run after the long one, but not in short succession
        # (they shouldn't run more often than their interval)

        self.assertEqual(res[0].dispatch_setting, ds_long)

        for item0, item1 in pairwise(item for item in res
                                     if item.dispatch_setting == ds_short):
            self.assertLessEqual(
                item0.expected_run_date + ds_short.get_interval_as_delta(),
                item1.expected_run_date)
Ejemplo n.º 4
0
    def test_source_limit(self):
        device0 = DeviceTestFactory()
        device1 = DeviceTestFactory()

        self.create_simple_fixtures(device0, device1)

        with mock.patch.object(DiscoverySource, 'get_maximal_concurrent_runs'
                               ) as get_maximal_concurrent_source_runs:
            get_maximal_concurrent_source_runs.return_value = 1
            dispatcher = DiscoveryDispatcher()
            res = dispatcher.calculate(self.jan_fst, self.jan_fst_three_am)
        # print 'final res'
        # pprint.pprint(res)

        # run_now must be considered
        self.assertEqual(res[0].device, device1)
        self.assertEqual(len([item for item in res if item.device == device0]),
                         4)
        self.assertEqual(len([item for item in res if item.device == device1]),
                         2)

        self.assert_no_overlaps(res)
Ejemplo n.º 5
0
 def test_empty(self):
     dispatcher = DiscoveryDispatcher()
     res = dispatcher.calculate(self.jan_fst, self.jan_snd)
     self.assertEqual(res, [])