diff --git a/05-single-hop-route/test_spec05.py b/05-single-hop-route/test_spec05.py index 3211afc..b387f25 100644 --- a/05-single-hop-route/test_spec05.py +++ b/05-single-hop-route/test_spec05.py @@ -1,10 +1,17 @@ import pytest +import random from riotctrl_shell.gnrc import GNRCICMPv6Echo, GNRCIPv6NIB, GNRCPktbufStats from riotctrl_shell.netif import Ifconfig from testutils.native import bridged -from testutils.shell import ping6, lladdr, check_pktbuf +from testutils.shell import ( + ping6, + lladdr, + check_pktbuf, + has_global_addr, + try_to_remove_global_addr, +) APP = 'examples/gnrc_networking' @@ -42,26 +49,36 @@ def test_task01(riot_ctrl): check_pktbuf(pinged, pinger) -@pytest.mark.flaky(reruns=3, reruns_delay=30) +@pytest.mark.flaky(reruns=0, reruns_delay=30) @pytest.mark.iotlab_creds @pytest.mark.parametrize( 'nodes', [pytest.param(['iotlab-m3', 'iotlab-m3'])], indirect=['nodes'] ) def test_task02(riot_ctrl): pinger, pinged = ( - riot_ctrl(0, APP, Shell, modules=["shell_cmd_gnrc_pktbuf"]), - riot_ctrl(1, APP, Shell, modules=["shell_cmd_gnrc_pktbuf"]), + riot_ctrl(0, APP, Shell, modules=["shell_cmd_gnrc_pktbuf"], cflags="-DCONFIG_IEEE802154_DEFAULT_CHANNEL=13"), + riot_ctrl(1, APP, Shell, modules=["shell_cmd_gnrc_pktbuf"], cflags="-DCONFIG_IEEE802154_DEFAULT_CHANNEL=13"), ) pinged_netif, pinged_lladdr = lladdr(pinged.ifconfig_list()) - pinged.ifconfig_add(pinged_netif, "beef::1/64") pinger_netif, pinger_lladdr = lladdr(pinger.ifconfig_list()) + + if has_global_addr(pinged) or has_global_addr(pinger): + pan_id = format(random.randint(0x1000, 0xFFFF), "x") + pinged.ifconfig_set(pinged_netif, "pan_id", pan_id) + pinger.ifconfig_set(pinger_netif, "pan_id", pan_id) + pinged.ifconfig_set(pinged_netif, "chan", "12") + pinger.ifconfig_set(pinger_netif, "chan", "12") + try_to_remove_global_addr(pinged) + try_to_remove_global_addr(pinger) + + pinged.ifconfig_add(pinged_netif, "beef::1/64") pinger.ifconfig_add(pinger_netif, "affe::1/120") pinged.nib_route_add(pinged_netif, "::", pinger_lladdr) pinger.nib_route_add(pinger_netif, "::", pinged_lladdr) - res = ping6(pinger, "beef::1", count=100, interval=300, packet_size=1024) + res = ping6(pinger, f"beef::1", count=100, interval=300, packet_size=1024) assert res['stats']['packet_loss'] < 10 check_pktbuf(pinged, pinger) diff --git a/testutils/github.py b/testutils/github.py index d59761c..7d95fc2 100644 --- a/testutils/github.py +++ b/testutils/github.py @@ -210,9 +210,9 @@ def create_comment(github, issue): def _generate_outcome_summary(pytest_report, task): # pylint: disable=C0209 return "{a_open}{outcome}{a_close}".format( - a_open=''.format(task["outcome_url"]) - if "outcome_url" in task - else '', + a_open=( + ''.format(task["outcome_url"]) if "outcome_url" in task else '' + ), outcome=pytest_report.outcome.upper(), a_close='' if "outcome_url" in task else '', ) diff --git a/testutils/iotlab.py b/testutils/iotlab.py index 49d5fdd..8f89317 100644 --- a/testutils/iotlab.py +++ b/testutils/iotlab.py @@ -1,4 +1,5 @@ import logging +import random import re from iotlabcli.auth import get_user_credentials @@ -55,14 +56,14 @@ def __init__(self, name, ctrls, site=DEFAULT_SITE): def board_from_iotlab_node(iotlab_node): """Return BOARD matching iotlab_node""" reg = r'([0-9a-zA-Z\-]+)-\d+\.[a-z]+\.iot-lab\.info' - match = re.search(reg, iotlab_node) - if match is None: + matches = re.findall(reg, iotlab_node) + if not matches: raise ValueError( f"Unable to parse {iotlab_node} as IoT-LAB node " "name of format " "..iot-lab.info" ) - iotlab_node_name = match.group(1) + iotlab_node_name = random.choice(matches) dict_values = IoTLABExperiment.BOARD_ARCHI_MAP.values() dict_names = [value['name'] for value in dict_values] dict_keys = list(IoTLABExperiment.BOARD_ARCHI_MAP.keys()) diff --git a/testutils/shell.py b/testutils/shell.py index 0aaeee7..e70ca59 100644 --- a/testutils/shell.py +++ b/testutils/shell.py @@ -222,6 +222,22 @@ def global_addr(ifconfig_out): return first_netif_and_addr_by_scope(ifconfig_out, "global") +def has_global_addr(node): + """Check if node has a global address.""" + try: + global_addr(node.ifconfig_list()) + except (RuntimeError, IndexError): + return False + return True + + +def try_to_remove_global_addr(node): + """Try to remove global address from node.""" + if has_global_addr(node): + netif, addr = global_addr(node.ifconfig_list()) + node.cmd(f"ifconfig {netif} del {addr}") + + def check_pktbuf(*nodes, wait=10): if wait: time.sleep(wait) diff --git a/testutils/tests/test_github.py b/testutils/tests/test_github.py index 824abe2..e3930b3 100644 --- a/testutils/tests/test_github.py +++ b/testutils/tests/test_github.py @@ -983,9 +983,11 @@ def test_upload_results( monkeypatch.setattr( testutils.github, "get_results_gist", - lambda *args, **kwargs: (testutils.github.Git('.'), "", "the_gist_id") - if gist_created - else (None, None, None), + lambda *args, **kwargs: ( + (testutils.github.Git('.'), "", "the_gist_id") + if gist_created + else (None, None, None) + ), ) monkeypatch.setattr( testutils.github, "upload_result_content", lambda *args, **kwargs: head