From nobody Tue May 16 15:04:13 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QLKJY5drbz4B7TM; Tue, 16 May 2023 15:04:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QLKJY55b4z3pNq; Tue, 16 May 2023 15:04:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684249453; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jUjrgWc+VtfE4kiz5+0P102QO6Mj1Wwzu19KetDmriY=; b=jZbpBdQbAycUSHR+dWWSrEWXNHrHHctNMTl3WsV0o7vmYgPOwCz+D6umzqgWtRukgURR4B ZrxfL9HPzkx5mmUDjTPLmworO6lU+bWy6qBED1w9MEirpiHWFiKczcueJA5zWNeMyFGu6Y XOvvjYgMjIUDrnTOvTGlee4u/JfeqJ5pGWhxLiuX0rJl08s0PUhikm5nHVjehhGBazqV97 ei6Q+X8svXcFDQrHCvpq9HJh1pvpZdtboDuk8i3+l4Jotag1W7HuAWOed8zQi//3YernrL PrY+5uGgi3sMgrtFBxODsYxclT7XY2qKUaQHYg6lSrtrXsOTf9Q2tR6FEXh7DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1684249453; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jUjrgWc+VtfE4kiz5+0P102QO6Mj1Wwzu19KetDmriY=; b=PVDghY2uf9pdaZqZA+6+PzX9XYzpO9F99ZTTYyP7aJ4JbjuHISvEG7xGYDiQjG1n2KCGNd GFLGqjnzvBNHKbQoncpZmrM7f7y2ixExNQ9QiI8/PXWl166ZR9w1YtBlg5dDhtJCEFQwbF sMJIaR4u52HLfX5jlW0vYpavDO7QhCJx4ObwY89AF6S3EVgVwY00yWkl+x2QItLWb+8oXb IUPlFPgUcLr6I59wa2Qijhb04LyYU4QfKOZ8vRHMsuyQlHJEhU5ieThmKdh5AOTODKsZYr FZMWjXDgczwgQzeOzlBNN358i+RAdlwIKSAe4stGyW+jBDKiGhPEYCigUcS5Kg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1684249453; a=rsa-sha256; cv=none; b=M83HSwWu22rOU4NQ5q9SevsbpHmxCXhJRxPrMWRPbxXP7RPTtHyH/DxUuJFiV/LhRUKlzT ACzKO9RwmEcY6YXS6OgeaGKO+xihWQDIiOkFvRgbMDBAwlHdJjmYCC4GJT7AIBqRQkBHzo UyZr185K0Jx3pXel4ODtiUroT90sZnB0/kofXP82cvp2QeRnEUQ7rKo1tEQxXItXjQ8Eds mFpHoO5PgUbSsscAh4pMAatTfVH0WU3MxVNAKNdvfF+WPU4gCgl9I7GQUXIzDtXpiVxVbT iOUuYuPzQiuiva3IsVDdhDh0+CmfFyOj32VGEyNQyZyjcWEdQ05e4fITlnhLqg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QLKJY47kdzRny; Tue, 16 May 2023 15:04:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 34GF4Dal077507; Tue, 16 May 2023 15:04:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34GF4DjZ077506; Tue, 16 May 2023 15:04:13 GMT (envelope-from git) Date: Tue, 16 May 2023 15:04:13 GMT Message-Id: <202305161504.34GF4DjZ077506@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: 584ad4126c76 - main - testing: improve vnet support in pytest * Allow vnet object to be directly referenced (self.vnet1 vs self.vnet_map["vnet1"]) * Allow iface object to be directly reference (vnet.bridge vs vnet.iface_alias_map["bridge"]) * Allow arbitrary interface alias names insted of ifX * Add wait_objects_any() method for waiting object from multiple vnets * Add wait() method for indefinite sleep on vnet handlers List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 584ad4126c76721b7f5da39d4ca4818ded7d64db Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=584ad4126c76721b7f5da39d4ca4818ded7d64db commit 584ad4126c76721b7f5da39d4ca4818ded7d64db Author: Alexander V. Chernikov AuthorDate: 2023-05-16 15:00:45 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-05-16 15:00:45 +0000 testing: improve vnet support in pytest * Allow vnet object to be directly referenced (self.vnet1 vs self.vnet_map["vnet1"]) * Allow iface object to be directly reference (vnet.bridge vs vnet.iface_alias_map["bridge"]) * Allow arbitrary interface alias names insted of ifX * Add wait_objects_any() method for waiting object from multiple vnets * Add wait() method for indefinite sleep on vnet handlers MFC after: 2 weeks --- tests/atf_python/sys/net/vnet.py | 46 +++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/tests/atf_python/sys/net/vnet.py b/tests/atf_python/sys/net/vnet.py index a2884b0d7ce2..8942e6839b35 100644 --- a/tests/atf_python/sys/net/vnet.py +++ b/tests/atf_python/sys/net/vnet.py @@ -1,11 +1,12 @@ #!/usr/local/bin/python3 import copy import ipaddress -import re import os +import re import socket import sys import time +from multiprocessing import connection from multiprocessing import Pipe from multiprocessing import Process from typing import Dict @@ -218,6 +219,8 @@ class VnetInstance(object): iface.set_jailed(True) self.iface_alias_map[iface.alias] = iface self.iface_map[iface.name] = iface + # Allow reference to interfce aliases as attributes + setattr(self, iface.alias, iface) self.need_dad = False # Disable duplicate address detection by default self.attached = False self.pipe = None @@ -364,7 +367,8 @@ class VnetTestTemplate(BaseTest): if prefixes6: iface.enable_ipv6() for prefix in prefixes6 + prefixes4: - iface.setup_addr(prefix[idx]) + if prefix[idx]: + iface.setup_addr(prefix[idx]) for iface in ipv6_ifaces: while iface.has_tentative(): time.sleep(0.1) @@ -378,18 +382,28 @@ class VnetTestTemplate(BaseTest): self.drop_privileges() handler(vnet) + def _get_topo_ifmap(self, topo: Dict): + iface_factory = IfaceFactory() + iface_map: Dict[str, SingleInterfaceMap] = {} + iface_aliases = set() + for obj_name, obj_data in topo.items(): + if obj_name.startswith("vnet"): + for iface_alias in obj_data["ifaces"]: + iface_aliases.add(iface_alias) + for iface_alias in iface_aliases: + print("Creating {}".format(iface_alias)) + iface_data = topo[iface_alias] + iface_type = iface_data.get("type", "epair") + ifaces = iface_factory.create_iface(iface_alias, iface_type) + smap = SingleInterfaceMap(ifaces, []) + iface_map[iface_alias] = smap + return iface_map + def setup_topology(self, topo: Dict, topology_id: str): """Creates jails & interfaces for the provided topology""" - iface_map: Dict[str, SingleInterfaceMap] = {} vnet_map = {} - iface_factory = IfaceFactory() vnet_factory = VnetFactory(topology_id) - for obj_name, obj_data in topo.items(): - if obj_name.startswith("if"): - iface_type = obj_data.get("type", "epair") - ifaces = iface_factory.create_iface(obj_name, iface_type) - smap = SingleInterfaceMap(ifaces, []) - iface_map[obj_name] = smap + iface_map = self._get_topo_ifmap(topo) for obj_name, obj_data in topo.items(): if obj_name.startswith("vnet"): vnet_ifaces = [] @@ -401,6 +415,8 @@ class VnetTestTemplate(BaseTest): vnet_ifaces.append(iface_map[iface_alias].ifaces[idx]) vnet = vnet_factory.create_vnet(obj_name, vnet_ifaces) vnet_map[obj_name] = vnet + # Allow reference to VNETs as attributes + setattr(self, obj_name, vnet) # Debug output print("============= TEST TOPOLOGY =============") for vnet_alias, vnet in vnet_map.items(): @@ -484,9 +500,19 @@ class VnetTestTemplate(BaseTest): return pipe.recv() raise TimeoutError + def wait_objects_any(self, pipe_list, timeout=5): + objects = connection.wait(pipe_list, timeout) + if objects: + return objects[0].recv() + raise TimeoutError + def send_object(self, pipe, obj): pipe.send(obj) + def wait(self): + while True: + time.sleep(1) + @property def curvnet(self): pass