diff --git a/libs/utils/env.py b/libs/utils/env.py index 8d8ba5f42e230868d19bc1b70fd58c40a7ab171e..0785068c6fc91a0a2c32163d3500ebcbc9436281 100644 --- a/libs/utils/env.py +++ b/libs/utils/env.py @@ -615,6 +615,12 @@ class TestEnv(ShareState): logging.debug('%14s - %s', 'HostResolver', cmd) os.popen(cmd) + return self.parse_arp_cache(host) + + def parse_arp_cache(self, host): + output = os.popen(r'arp -n') + ipaddr = None + macaddr = None if ':' in host: # Assuming this is a MAC address # TODO add a suitable check on MAC address format @@ -622,6 +628,13 @@ class TestEnv(ShareState): ARP_RE = re.compile( r'([^ ]*).*({}|{})'.format(host.lower(), host.upper()) ) + macaddr = host + for line in output: + match = ARP_RE.search(line) + if not match: + continue + ipaddr = match.group(1) + break else: # Assuming this is an IP address # TODO add a suitable check on IP address format @@ -629,26 +642,35 @@ class TestEnv(ShareState): ARP_RE = re.compile( r'{}.*ether *([0-9a-fA-F:]*)'.format(host) ) - - output = os.popen(r'arp -n') - ipaddr = '0.0.0.0' - for line in output: - match = ARP_RE.search(line) - if not match: - continue - ipaddr = match.group(1) - break - if ipaddr == '0.0.0.0': - raise ValueError('Unable to lookup for target IP address') + ipaddr = host + for line in output: + match = ARP_RE.search(line) + if not match: + continue + macaddr = match.group(1) + break + + if not ipaddr or not macaddr: + raise ValueError('Unable to lookup for target IP/MAC address') logging.info('%14s - Target (%s) at IP address: %s', - 'HostResolver', host, ipaddr) - return (host, ipaddr) + 'HostResolver', macaddr, ipaddr) + return (macaddr, ipaddr) - def reboot(self, reboot_time=120): + def reboot(self, reboot_time=120, ping_time=15): # Send remote target a reboot command if self._feature('no-reboot'): logging.warning('%14s - Reboot disabled by conf features', 'Reboot') else: + if 'reboot_time' in self.conf: + reboot_time = int(self.conf['reboot_time']) + + if 'ping_time' in self.conf: + ping_time = int(self.conf['ping_time']) + + # Before rebooting make sure to have IP and MAC addresses + # of the target + (self.mac, self.ip) = self.parse_arp_cache(self.ip) + self.target.execute('sleep 2 && reboot -f &', as_root=True) # Wait for the target to complete the reboot @@ -659,14 +681,19 @@ class TestEnv(ShareState): elapsed = 0 start = time.time() while elapsed <= reboot_time: - time.sleep(5) + time.sleep(ping_time) logging.debug('%14s - Trying to connect to [%s] target...', 'Reboot', self.ip) if os.system(ping_cmd) == 0: break elapsed = time.time() - start if elapsed > reboot_time: - logging.warning('%14s - target [%s] not reposing to PINGs, trying to continue...', + if self.mac: + logging.warning('%14s - target [%s] not responding to \ + PINGs, trying to resolve MAC address...', 'Reboot', self.ip) + (self.mac, self.ip) = self.resolv_host(self.mac) + else: + logging.warning('%14s - target [%s] not responding to PINGs, trying to continue...', 'Reboot', self.ip) # Force re-initialization of all the devlib modules diff --git a/target.config b/target.config index ade4bd746a10a546f4db3d195a7444c6e3d9de88..47a0e7da8d583cac648d2f45cf60bd7af19656cc 100644 --- a/target.config +++ b/target.config @@ -1,3 +1,11 @@ +/* target.config */ +/* */ +/* Configuration file to specify target parameters such as: the */ +/* kind of platform/board, and login credentials. */ +/* */ +/* NOTE: all commented parameters are optional and report their */ +/* default value. */ + { /* Platform */ /* - linux : accessed via SSH connection */ @@ -19,7 +27,7 @@ "username" : "root", /* Login credentials */ - /* You can specified either a password or keyfile */ + /* You can specify either a password or keyfile */ "password" : "", // "keyfile" : "/complete/path/of/your/keyfile", @@ -49,6 +57,12 @@ /* Binary tools to install by default for all experiments */ "tools" : [], + /* Wait time before trying to access the target after reboot */ + // "ping_time" : "15", + + /* Maximum time to wait after rebooting the target */ + // "reboot_time" : "120", + /* List of test environment features to enable */ /* no-kernel : do not deploy kernel/dtb images */ /* no-reboot : do not force reboot the target at each */