Changeset 2ae9b6d in rtems-tools


Ignore:
Timestamp:
Oct 5, 2017, 3:21:33 AM (20 months ago)
Author:
Chris Johns <chrisj@…>
Branches:
master
Children:
68cbfc3
Parents:
0737b46
Message:

tester: Telnet console reopens the connection if it fails or closes.

Some hardware can drop a USB serial enumeration when power is
remove or applied. This changes make the telnet console more
fault tolerant.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tester/rt/telnet.py

    r0737b46 r2ae9b6d  
    3333#
    3434
     35import errno
    3536import os
    3637import sys
     
    4546    def __init__(self, dev):
    4647        self.dev = dev
     48        self.timeout = 5
    4749        self.conn = None
    4850        ds = dev.split(':')
     
    5557            except:
    5658                raise error.general('invalid port: %s' % (dev))
    57         try:
    58             self.conn = telnetlib.Telnet(self.host, self.port, 5)
    59         except IOError as ioe:
    60             raise error.general('opening telnet dev: %s: %s' % (dev, ioe))
    61         except:
    62             raise error.general('opening telnet dev: %s: unknown' % (dev))
     59        self.conn = telnetlib.Telnet()
     60        self._reopen()
    6361
    6462    def __del__(self):
     
    7371        return s
    7472
     73    def _reopen(self):
     74        try:
     75            self.conn.open(self.host, self.port, self.timeout)
     76        except IOError as ioe:
     77            raise error.general('opening telnet dev: %s: %s' % (dev, ioe))
     78        except:
     79            raise error.general('opening telnet dev: %s: unknown' % (dev))
     80
    7581    def off(self):
    7682        self.is_on = False
     
    8389
    8490    def read(self):
     91        reopen = False
    8592        try:
    8693            data = self.conn.read_very_eager()
     94        except IOError as ioe:
     95            if ioe.errno == errno.ECONNREFUSED:
     96                reopen = True
     97            data = ''
    8798        except EOFError:
     99            reopen = True
    88100            data = ''
     101        if reopen:
     102            self._reopen()
    89103        return data
    90104
Note: See TracChangeset for help on using the changeset viewer.