Exemple #1
0
 def test_schedule_fault_msg_interval(self):
     self.clear_buffer_file()
     self.fm.fault_ipc.operational = True
     self.fm.msg_cnt_in_sec = 0
     RpdEventConfig.GLOBAL_CONFIG[
         'Enable'] = rcp_tlv_def.RPD_EVENT_NTF_ENABLE[0]
     self.enable_notify_send()
     EventCommonOperation.store_fault_message("66070200: test message 1",
                                              operational=True)
     RpdEventConfig.GLOBAL_CONFIG[
         'Throttle'] = rcp_tlv_def.RPD_EVENT_THROTTLE_INHIBITED[0]
Exemple #2
0
    def schedule_fault_msg(self, disp):
        """schedule the fault management send plan."""

        if RpdEventConfig.is_notify_en():
            total_msg = EventCommonOperation.read_log(
                EventCommonOperation.BUFFERED_PENDING)
            threshold = RpdEventConfig.GLOBAL_CONFIG['Threshold']

            if RpdEventConfig.is_unconstrained():
                while True:
                    ret = RpdEventOrderedBuffer.pop_operational_event(
                        total_msg)
                    if None is not ret:
                        print ret
                    else:
                        break
                # pop initiating process event
                for key, data in total_msg.items():
                    print data
                    total_msg.pop(key)

            else:
                for _ in range(threshold):
                    ret = RpdEventOrderedBuffer.pop_operational_event(
                        total_msg)
                    if None is not ret:
                        print ret
                        continue
                    # pop initiating process event
                    for key, data in total_msg.items():
                        total_msg.pop(key)
                        break
            EventCommonOperation.write_log(
                total_msg, EventCommonOperation.BUFFERED_PENDING)
        else:
            print("Can not send msg, NotifyEnable(%d)" %
                  RpdEventConfig.is_notify_en())

        self.send_count += 1
        # only send 5 times for test.
        if self.send_count <= self.send_throttle:
            disp.timer_register(RpdEventConfig.GLOBAL_CONFIG["Interval"],
                                self.schedule_fault_msg,
                                arg=disp)
            disp.timer_register(0.1,
                                EventCommonOperation.store_fault_message,
                                arg="66070206: test message 7")
        else:
            disp.end_loop()
Exemple #3
0
 def test_clear_operational_tag_in_buffer(self):
     self.clear_buffer_file()
     self.fm.fault_ipc.operational = False
     self.fm.fault_ipc.op_state_change = True
     RpdEventConfig.GLOBAL_CONFIG[
         'Enable'] = rcp_tlv_def.RPD_EVENT_NTF_ENABLE[0]
     self.enable_notify_send()
     EventCommonOperation.store_fault_message("66070200: test message 1",
                                              operational=True)
     self.fm.clear_operational_tag_in_buffer()
     self.fm.schedule_fault_msg(None)
     self.assertEqual(self.fm.msg_cnt_in_sec, 0)
     ntf_msg = EventCommonOperation.read_log(
         EventCommonOperation.BUFFERED_PENDING)
     ret = RpdEventOrderedBuffer.pop_operational_event(ntf_msg)
     self.assertIsNone(ret)
Exemple #4
0
    def test_schedule_poll_local(self):
        # generate log
        self.clear_buffer_file()
        self.fm.msg_cnt_in_sec = 0
        EventCommonOperation.store_fault_message("66070200: test message 1")
        self.fm.schedule_poll_local(None)
        self.assertEqual(self.fm.msg_cnt_in_sec, 1)

        # reach max limit in sec
        self.fm.msg_cnt_in_sec = 20
        EventCommonOperation.store_fault_message("66070200: test message 1")
        self.fm.schedule_poll_local(None)
        self.assertEqual(self.fm.msg_cnt_in_sec, 20)
        self.assertTrue(
            os.path.exists(EventCommonOperation.BUFFERED_TYPE[
                EventCommonOperation.BUFFERED_LOCAL]))
Exemple #5
0
    def test_send_local_craft_port_open_message(self):
        print '*' * 80
        print 'Send Enclosure Door Open Message'
        print '*' * 80
        # below throttle
        RpdEventConfig.GLOBAL_CONFIG[
            'Throttle'] = rcp_tlv_def.RPD_EVENT_THROTTLE_BELOW[0]
        self.enable_notify_send()

        # generate log
        EventCommonOperation.store_fault_message(
            "66070504: Enclosure Door Open", operational=True)
        dispatcher = Dispatcher()
        dispatcher.timer_register(RpdEventConfig.GLOBAL_CONFIG["Interval"],
                                  self.schedule_fault_msg_operational,
                                  arg=dispatcher)
        dispatcher.loop()
Exemple #6
0
    def test_send_self_diagnostic_message(self):
        print '*' * 80
        print 'Send Self Diagnostic Message'
        print '*' * 80
        # below throttle
        RpdEventConfig.GLOBAL_CONFIG[
            'Throttle'] = rcp_tlv_def.RPD_EVENT_THROTTLE_BELOW[0]
        self.enable_notify_send()

        # generate log
        EventCommonOperation.store_fault_message(
            "66070218: Diagnostic Self Test Failure", operational=True)
        dispatcher = Dispatcher()
        dispatcher.timer_register(RpdEventConfig.GLOBAL_CONFIG["Interval"],
                                  self.schedule_fault_msg_operational,
                                  arg=dispatcher)
        dispatcher.loop()
Exemple #7
0
    def test_move_all_event_to_nonoperational(self):
        print '*' * 80
        print 'test operational event log pop'
        print '*' * 80
        self.enable_notify_send()

        # generate log
        EventCommonOperation.store_fault_message("66070200: test message 1")
        EventCommonOperation.store_fault_message("66070200: test message 1",
                                                 operational=True)
        EventCommonOperation.store_fault_message("66070201: test message 2",
                                                 operational=True)
        EventCommonOperation.store_fault_message("66070202: test message 3",
                                                 operational=True)

        RpdEventOrderedBuffer.move_all_event_to_nonoperational()

        ntf_msg = EventCommonOperation.read_log(
            EventCommonOperation.BUFFERED_PENDING)
        self.assertEqual(len(ntf_msg), 4)
        ret = RpdEventOrderedBuffer.pop_operational_event(ntf_msg)
        self.assertIsNone(ret)
Exemple #8
0
    def test_schedule_fault_msg(self):
        self.clear_buffer_file()
        self.fm.fault_ipc.operational = True
        self.fm.msg_cnt_in_sec = 0
        RpdEventConfig.GLOBAL_CONFIG[
            'Enable'] = rcp_tlv_def.RPD_EVENT_NTF_ENABLE[0]
        self.enable_notify_send()
        EventCommonOperation.store_fault_message("66070200: test message 1",
                                                 operational=True)
        self.fm.schedule_fault_msg(None)
        self.assertEqual(self.fm.msg_cnt_in_sec, 1)

        # reach max limit in sec, reset
        self.fm.msg_cnt_in_sec = 20
        EventCommonOperation.store_fault_message("66070200: test message 1",
                                                 operational=True)
        self.fm.schedule_fault_msg(None)
        self.assertEqual(self.fm.msg_cnt_in_sec, 1)
        self.assertTrue(
            os.path.exists(EventCommonOperation.BUFFERED_TYPE[
                EventCommonOperation.BUFFERED_PENDING]))

        # reach max limit in interval
        RpdEventConfig.GLOBAL_CONFIG[
            'Throttle'] = rcp_tlv_def.RPD_EVENT_THROTTLE_BELOW[0]
        self.fm.msg_cnt_in_interval = RpdEventConfig.GLOBAL_CONFIG['Threshold']
        EventCommonOperation.store_fault_message("66070200: test message 1",
                                                 operational=True)
        self.fm.schedule_fault_msg(None)
        self.assertEqual(self.fm.msg_cnt_in_interval,
                         RpdEventConfig.GLOBAL_CONFIG['Threshold'])
        self.assertTrue(
            os.path.exists(EventCommonOperation.BUFFERED_TYPE[
                EventCommonOperation.BUFFERED_PENDING]))

        # set the poll timer
        self.fm.fault_ipc.poll_local_flag = True
        self.fm.fault_ipc.poll_pending_flag = True

        self.fm.schedule_fault_msg(None)
        self.assertIsNotNone(self.fm.poll_local_timer)
        self.assertIsNotNone(self.fm.poll_pending_timer)
        self.assertFalse(self.fm.fault_ipc.poll_local_flag)
        self.assertFalse(self.fm.fault_ipc.poll_pending_flag)

        # set refresh config
        self.clear_buffer_file()
        self.fm.fault_ipc.config_refreshed = True
        self.fm.schedule_fault_msg(None)
        self.assertFalse(self.fm.fault_ipc.config_refreshed)
        self.assertEqual(self.fm.msg_cnt_in_interval, 0)
Exemple #9
0
    def test_send_ptp_message(self):
        print '*' * 80
        print 'Send PTP SYNC/LOST SYNC/HOLDOVER Message'
        print '*' * 80
        # below throttle
        RpdEventConfig.GLOBAL_CONFIG[
            'Throttle'] = rcp_tlv_def.RPD_EVENT_THROTTLE_BELOW[0]
        self.enable_notify_send()

        # generate log
        EventCommonOperation.store_fault_message(
            "66070700: PTP clock synchronized to Master", operational=True)
        EventCommonOperation.store_fault_message(
            "66070701: PTP clock lost synchronized to Master",
            operational=True)
        EventCommonOperation.store_fault_message(
            "66070702: PTP clock ecxessive holdover to Master",
            operational=True)
        dispatcher = Dispatcher()
        dispatcher.timer_register(RpdEventConfig.GLOBAL_CONFIG["Interval"],
                                  self.schedule_fault_msg_operational,
                                  arg=dispatcher)
        dispatcher.loop()
Exemple #10
0
 def error(self, event_id, *args):
     msg = EventCommonOperation.construct_event_msg(event_id, *args)
     self.logger.error(msg)
Exemple #11
0
 def critical(self, event_id, *args):
     msg = EventCommonOperation.construct_event_msg(event_id, *args)
     self.logger.critical(msg)
Exemple #12
0
 def info(self, event_id, *args):
     msg = EventCommonOperation.construct_event_msg(event_id, *args)
     self.logger.info(msg)
Exemple #13
0
 def tearDown(self):
     EventCommonOperation.read_log(EventCommonOperation.BUFFERED_LOCAL)
     EventCommonOperation.read_log(EventCommonOperation.BUFFERED_PENDING)
Exemple #14
0
    def test_pop_operational_event(self):
        print '*' * 80
        print 'test operational event log pop'
        print '*' * 80
        self.enable_notify_send()

        # generate log
        EventCommonOperation.store_fault_message("66070200: test message 1")
        EventCommonOperation.store_fault_message("66070200: test message 1",
                                                 operational=True)
        EventCommonOperation.store_fault_message("66070201: test message 2",
                                                 operational=True)
        EventCommonOperation.store_fault_message("66070202: test message 3",
                                                 operational=True)
        # as 203 stored in pending file, so not generate it.
        # EventCommonOperation.store_fault_message("66070203: test message 4", operational=True)
        EventCommonOperation.store_fault_message("66070204: test message 4",
                                                 operational=True)
        EventCommonOperation.store_fault_message("66070205: test message 5",
                                                 operational=True)

        cfg = config()
        notify_req = cfg.EventNotification.add()
        notify_req.RpdEvLogIndex = 3
        notify_req.PendingOrLocalLog = 1
        if notify_req.HasField("PendingOrLocalLog"):
            if notify_req.PendingOrLocalLog:
                local = EventCommonOperation.BUFFERED_LOCAL
            else:
                local = EventCommonOperation.BUFFERED_PENDING
            ntf_msg = EventCommonOperation.read_log(local)
            operational_cnt = 5

            cnt = 0
            while True:
                ret = RpdEventOrderedBuffer.pop_operational_event(ntf_msg)
                if None is not ret:
                    print ret
                    cnt += 1
                else:
                    break

            # pop initiating process event
            for key, data in ntf_msg.items():
                print data
                ntf_msg.pop(key)

            # verify the result
            self.assertEqual(
                operational_cnt,
                cnt,
                msg="pop operational event from local fail %d, %d" %
                (operational_cnt, cnt))
            self.assertEqual("operational" not in ntf_msg,
                             True,
                             msg="pop whole operational event fail")
            self.assertEqual(len(ntf_msg),
                             0,
                             msg="pop  initiating process event fail")
Exemple #15
0
    def test_event_operational(self):
        print '*' * 80
        print 'Send message when operational'
        print '*' * 80
        # below throttle
        RpdEventConfig.GLOBAL_CONFIG[
            'Throttle'] = rcp_tlv_def.RPD_EVENT_THROTTLE_BELOW[0]
        self.enable_notify_send()

        # generate log
        EventCommonOperation.store_fault_message("66070200: test message 1",
                                                 operational=True)
        EventCommonOperation.store_fault_message("66070201: test message 2",
                                                 operational=True)
        EventCommonOperation.store_fault_message("66070202: test message 3",
                                                 operational=True)
        EventCommonOperation.store_fault_message("66070203: test message 4",
                                                 operational=True)
        EventCommonOperation.store_fault_message("66070204: test message 5",
                                                 operational=True)
        EventCommonOperation.store_fault_message("66070205: test message 6",
                                                 operational=True)
        dispatcher = Dispatcher()
        dispatcher.timer_register(RpdEventConfig.GLOBAL_CONFIG["Interval"],
                                  self.schedule_fault_msg_operational,
                                  arg=dispatcher)
        dispatcher.loop()
Exemple #16
0
    def test_event_send_unconstrained(self):
        print '*' * 80
        print 'Send message unconstrained'
        print '*' * 80
        # unconstrained throttle
        RpdEventConfig.GLOBAL_CONFIG[
            'Throttle'] = rcp_tlv_def.RPD_EVENT_THROTTLE_UNCONSTRAINED[0]
        self.enable_notify_send()

        # generate log
        EventCommonOperation.store_fault_message("66070200: test message 1")
        EventCommonOperation.store_fault_message("66070201: test message 2")
        EventCommonOperation.store_fault_message("66070202: test message 3")
        EventCommonOperation.store_fault_message("66070203: test message 4")
        EventCommonOperation.store_fault_message("66070204: test message 5")
        EventCommonOperation.store_fault_message("66070205: test message 6")
        dispatcher = Dispatcher()
        dispatcher.timer_register(RpdEventConfig.GLOBAL_CONFIG["Interval"],
                                  self.schedule_fault_msg,
                                  arg=dispatcher)
        dispatcher.loop()