def get_transceiver_change_event(self, timeout=0):
        phy_port_dict = {}
        status = True

        if self.db_sel == None:
            from swsscommon import swsscommon
            self.state_db = swsscommon.DBConnector(swsscommon.STATE_DB,
                                                   REDIS_HOSTNAME, REDIS_PORT,
                                                   REDIS_TIMEOUT_USECS)

            # Subscribe to state table for SFP change notifications
            self.db_sel = swsscommon.Select()
            self.db_sel_tbl = swsscommon.NotificationConsumer(
                self.state_db, 'TRANSCEIVER_NOTIFY')
            self.db_sel.addSelectable(self.db_sel_tbl)
            self.db_sel_timeout = swsscommon.Select.TIMEOUT
            self.db_sel_object = swsscommon.Select.OBJECT
            self.sfpd_status_tbl = swsscommon.Table(self.state_db,
                                                    'MLNX_SFPD_TASK')

        # Check the liveness of mlnx-sfpd, if it failed, return false
        keys = self.sfpd_status_tbl.getKeys()
        if 'LIVENESS' not in keys:
            return False, phy_port_dict

        (state, c) = self.db_sel.select(timeout)
        if state == self.db_sel_timeout:
            status = True
        elif state != self.db_sel_object:
            status = False
        else:
            (key, op, fvp) = self.db_sel_tbl.pop()
            phy_port_dict[key] = op

        return status, phy_port_dict
Exemple #2
0
    def get_transceiver_change_event(self, timeout=0):
        phy_port_dict = {}
        status = True

        if self.db_sel == None:
            from swsscommon import swsscommon
            self.state_db = swsscommon.DBConnector(swsscommon.STATE_DB,
                                                   REDIS_HOSTNAME, REDIS_PORT,
                                                   REDIS_TIMEOUT_USECS)

            # Subscribe to state table for SFP change notifications
            self.db_sel = swsscommon.Select()
            self.db_sel_tbl = swsscommon.NotificationConsumer(
                self.state_db, 'TRANSCEIVER_NOTIFY')
            self.db_sel.addSelectable(self.db_sel_tbl)
            self.db_sel_timeout = swsscommon.Select.TIMEOUT
            self.db_sel_object = swsscommon.Select.OBJECT

        (state, c) = self.db_sel.select(timeout)
        if state == self.db_sel_timeout:
            status = True
        elif state != self.db_sel_object:
            status = False
        else:
            (key, op, fvp) = self.db_sel_tbl.pop()
            phy_port_dict[key] = op

        return status, phy_port_dict
Exemple #3
0
    def get_transceiver_change_event(self, timeout=0):
        phy_port_dict = {}
        status = True

        if self.db_sel is None:
            from swsscommon import swsscommon
            self.state_db = swsscommon.DBConnector("STATE_DB",
                                                   REDIS_TIMEOUT_USECS, True)

            # Subscribe to state table for SFP change notifications
            self.db_sel = swsscommon.Select()
            self.db_sel_tbl = swsscommon.NotificationConsumer(
                self.state_db, 'TRANSCEIVER_NOTIFY')
            self.db_sel.addSelectable(self.db_sel_tbl)
            self.db_sel_timeout = swsscommon.Select.TIMEOUT
            self.db_sel_object = swsscommon.Select.OBJECT
            self.sfpd_status_tbl = swsscommon.Table(self.state_db,
                                                    'MLNX_SFPD_TASK')

        # Check the liveness of mlnx-sfpd, if it failed, return system_fail event
        # If mlnx-sfpd not started, return system_not_ready event
        keys = self.sfpd_status_tbl.getKeys()
        if 'LIVENESS' not in keys:
            if self.mlnx_sfpd_started:
                log_err("mlnx-sfpd exited, return false to notify xcvrd.")
                phy_port_dict[EVENT_ON_ALL_SFP] = SYSTEM_FAIL
                return False, phy_port_dict
            else:
                log_info("mlnx-sfpd not ready, return false to notify xcvrd.")
                phy_port_dict[EVENT_ON_ALL_SFP] = SYSTEM_NOT_READY
                return False, phy_port_dict
        else:
            if not self.mlnx_sfpd_started:
                self.mlnx_sfpd_started = True
                log_info("mlnx-sfpd is running")
                phy_port_dict[EVENT_ON_ALL_SFP] = SYSTEM_READY
                return False, phy_port_dict

        if timeout:
            (state, c) = self.db_sel.select(timeout)
        else:
            (state, c) = self.db_sel.select()

        if state == self.db_sel_timeout:
            status = True
        elif state != self.db_sel_object:
            status = False
        else:
            (key, op, fvp) = self.db_sel_tbl.pop()
            phy_port_dict[key] = op

        return status, phy_port_dict
Exemple #4
0
def test_Notification():
    db = swsscommon.DBConnector("APPL_DB", 0, True)
    ntfc = swsscommon.NotificationConsumer(db, "testntf")
    sel = swsscommon.Select()
    sel.addSelectable(ntfc)
    fvs = swsscommon.FieldValuePairs([('a', 'b')])
    ntfp = swsscommon.NotificationProducer(db, "testntf")
    ntfp.send("aaa", "bbb", fvs)
    (state, c) = sel.select()
    assert state == swsscommon.Select.OBJECT
    (op, data, cfvs) = ntfc.pop()
    assert op == "aaa"
    assert data == "bbb"
    assert len(cfvs) == 1
    assert cfvs[0] == ('a', 'b')
Exemple #5
0
 def _set_up(self, dvs):
     self._p4rt_mirror_session_wrapper = P4RtMirrorSessionWrapper()
     self._p4rt_mirror_session_wrapper.set_up_databases(dvs)
     self._response_consumer = swsscommon.NotificationConsumer(
         self._p4rt_mirror_session_wrapper.appl_db,
         "APPL_DB_P4RT_TABLE_RESPONSE_CHANNEL")