Exemplo n.º 1
0
def main():
    logger = Logger(SYSLOG_IDENTIFIER)
    logger.set_min_log_priority_info()

    if os.getuid() != 0:
        logger.log_error('Root required to clean up core files')
        return

    logger.log_info('Cleaning up core files')
    core_files = [f for f in os.listdir(CORE_FILE_DIR) if os.path.isfile(os.path.join(CORE_FILE_DIR, f))]

    core_files_by_process = defaultdict(list)
    for f in core_files:
        process = f.split('.')[0]
        curr_files = core_files_by_process[process]
        curr_files.append(f)

        if len(curr_files) > MAX_CORE_FILES:
            curr_files.sort(reverse = True, key = lambda x: datetime.utcfromtimestamp(int(x.split('.')[1])))
            oldest_core = curr_files[MAX_CORE_FILES]
            logger.log_info('Deleting {}'.format(oldest_core))
            try:
                os.remove(os.path.join(CORE_FILE_DIR, oldest_core))
            except:
                logger.log_error('Unexpected error occured trying to delete {}'.format(oldest_core))
            core_files_by_process[process] = curr_files[0:MAX_CORE_FILES]

    logger.log_info('Finished cleaning up core files')
Exemplo n.º 2
0
def main():
    logger = Logger(SYSLOG_IDENTIFIER)
    logger.set_min_log_priority_info()

    if len(sys.argv) != 3:
        raise Exception('Pass service and valid asic-id as arguments')

    service = sys.argv[1]
    args_asic_id = sys.argv[2]

    # Get num asics
    num_asics = multi_asic.get_num_asics()
    if num_asics == 0:
        logger.log_error(
            'Detected no asics on this platform for service {}'.format(
                service))
        sys.exit(1)

    # Connect to STATE_DB and subscribe to chassis-module table notifications
    state_db = daemon_base.db_connect("CHASSIS_STATE_DB")

    sel = swsscommon.Select()
    sst = swsscommon.SubscriberStateTable(state_db, CHASSIS_ASIC_INFO_TABLE)
    sel.addSelectable(sst)

    while True:
        (state, c) = sel.select(SELECT_TIMEOUT_MSECS)
        if state == swsscommon.Select.TIMEOUT:
            continue
        if state != swsscommon.Select.OBJECT:
            continue

        (asic_key, asic_op, asic_fvp) = sst.pop()
        asic_id = re.search(r'\d+$', asic_key)
        global_asic_id = asic_id.group(0)

        if asic_op == 'SET':
            asic_fvs = dict(asic_fvp)
            asic_name = asic_fvs.get('name')
            if asic_name is None:
                logger.log_info('Unable to get asic_name for asic{}'.format(
                    global_asic_id))
                continue

            if asic_name.startswith('FABRIC-CARD') is False:
                logger.log_info(
                    'Skipping module with asic_name {} for asic{}'.format(
                        asic_name, global_asic_id))
                continue

            if (global_asic_id == args_asic_id):
                logger.log_info(
                    'Detected asic{} is online'.format(global_asic_id))
                sys.exit(0)
        elif asic_op == 'DEL':
            logger.log_info(
                'Detected asic{} is offline'.format(global_asic_id))
            sys.exit(1)
        else:
            continue
Exemplo n.º 3
0
class SfpEvent:
    ''' Listen to insert/remove sfp events '''

    SFP_NUM_START = 49
    DELAY = 0.05
    INT_PATH = '/sys/devices/platform/e1031.smc/SFP/modabs_int'
    GPIO_SUS7 = '/sys/devices/platform/hlx-ich.0/sci_int_gpio_sus7'

    def __init__(self, sfp_list):
        self._api_helper = APIHelper()
        self._sfp_list = sfp_list
        self._logger = Logger()

        # clear interrupt
        self._api_helper.read_one_line_file(self.INT_PATH)

    def get_sfp_event(self, timeout):
        epoll = select.epoll()
        port_dict = {}
        timeout_sec = timeout / 1000

        try:
            # We get notified when there is an SCI interrupt from GPIO SUS7
            fd = open(self.GPIO_SUS7, "r")
            fd.read()

            epoll.register(fd.fileno(), select.EPOLLIN & select.EPOLLET)
            events = epoll.poll(timeout=timeout_sec if timeout != 0 else -1)
            if events:
                # Read the QSFP ABS interrupt & status registers
                port_changes = self._api_helper.read_one_line_file(
                    self.INT_PATH)
                changes = int(port_changes, 16)
                for sfp in self._sfp_list:
                    if sfp.port_num < self.SFP_NUM_START:
                        continue

                    change = (changes >> sfp.port_num - self.SFP_NUM_START) & 1
                    if change == 1:
                        time.sleep(self.DELAY)
                        port_status = sfp.get_presence()
                        port_dict[str(
                            sfp.port_num)] = '1' if port_status else '0'

                return port_dict
        except Exception as e:
            self._logger.log_error("Failed to detect SfpEvent - " + repr(e))
            return False

        finally:
            fd.close()
            epoll.close()

        return False
Exemplo n.º 4
0
class SfpEvent:
    ''' Listen to insert/remove sfp events '''

    QSFP_MODPRS_IRQ = '/sys/devices/platform/dx010_cpld/qsfp_modprs_irq'
    GPIO_SUS6 = "/sys/devices/platform/slx-ich.0/sci_int_gpio_sus6"

    def __init__(self, sfp_list):
        self._api_helper = APIHelper()
        self._sfp_list = sfp_list
        self._logger = Logger()

    def get_sfp_event(self, timeout):
        epoll = select.epoll()
        port_dict = {}
        timeout_sec = timeout / 1000

        try:
            # We get notified when there is an SCI interrupt from GPIO SUS6
            fd = open(self.GPIO_SUS6, "r")
            fd.read()

            epoll.register(fd.fileno(), select.EPOLLIN & select.EPOLLET)
            events = epoll.poll(timeout=timeout_sec if timeout != 0 else -1)
            if events:
                # Read the QSFP ABS interrupt & status registers
                port_changes = self._api_helper.read_one_line_file(
                    self.QSFP_MODPRS_IRQ)
                changes = int(port_changes, 16)
                for sfp in self._sfp_list:
                    change = (changes >> sfp.port_num - 1) & 1
                    if change == 1:
                        port_dict[str(sfp.port_num)] = str(
                            int(sfp.get_presence()))

                return port_dict
        except Exception as e:
            self._logger.log_error("Failed to detect SfpEvent - " + repr(e))
            return False

        finally:
            fd.close()
            epoll.close()

        return False
                            and key != 'PortConfigDone'):
                        self.update_db(key, op)
            else:
                break


def signal_handler(signum, frame):
    logger.log_notice("got signal {}".format(signum))
    sys.exit(0)


def main():
    port_mapper = PortIndexMapper()
    port_mapper.populate()
    port_mapper.listen()


if __name__ == '__main__':
    rc = 0
    try:
        signal.signal(signal.SIGTERM, signal_handler)
        signal.signal(signal.SIGINT, signal_handler)
        main()
    except Exception as e:
        tb = sys.exc_info()[2]
        traceback.print_tb(tb)
        logger.log_error("%s" % str(e))
        rc = -1
    finally:
        sys.exit(rc)