From nobody Thu Feb 09 16:11:26 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 4PCMLQ4M4Cz3plb3; Thu, 9 Feb 2023 16:11:26 +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 4PCMLQ2PKyz4JQ8; Thu, 9 Feb 2023 16:11:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675959086; 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=6spWDoFxmIErCIrVHdK+AUGrxt/WzPiSfU3BfPVMmjE=; b=LzfxsHbDTa4xO7q/MBG5Fn9FtjwWPf3y7JWm96j4q6bMLwT96R0P/JKPABttbRMMBj9Qpn FHhLIkfIJ29bAl1fRB4qZ+y/xLyE3WmwwCb6b79VfYQa5vbSoekk/40ZNFLQIc3IJG2oSb +ojvImhL9cHIQr3HvKqJ24ukte3ZoAbUJVCfieAUvUSxyMaJel/MTNNqMSWVwsNPrbZhAf eMW7Y/uli1Vv5KQzN58QBKhzEpUV/okSqkV3u/4ToWm0Ery6Yhjj6+Fpw+vJA0TstZIfhn vYLdzdRAiGxLeD/TLmvafDrFntCOiyUur+ncEA6HKHIY3MZb/vimSWSDEH9nlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675959086; 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=6spWDoFxmIErCIrVHdK+AUGrxt/WzPiSfU3BfPVMmjE=; b=LzGeFknGwVKpjntPIHCAR/erowhHVdqKdG8IXINnpcJvpkBVuG80Ow2SsNX5FY4gt3zgwu eNWBT6iazI/SSDFERbkf+papnBp94ttNNlTgX03CzXWcMQZqXJdF9jzODb2T4slQXXGJUX ZCgfCnJyFgvqYHE9UA1VbLJ9DOrsSA0X+oLbX3M+ZrvjxrVNz7mouMYuDAAJ8Zp1ufRa+j iwpW2BGrNI2TyZN19iYK0PtN1CfM3ZfKjDng8tQTfaFyBoA3T94pm5bYkuwo5u2r9yPB8A rsLyNiZ5U767OCDPlILyaGhfFy9IWXkzyGcjnTerKG0b8zbUocZy0iZmXGFe9A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675959086; a=rsa-sha256; cv=none; b=L5MJMex2WrIwIyE+qSksHzCc2WhIczVmQXUO8KR6hwKwbXZfTRiFOKdoXzQb21Rf4/VrFZ WMQFi8BOvxyr0EP1G9dnlyFkZ8i8dyROye1isnekafDTcxSjrTH+QwbK4ur76bbCy4N/Ul 49HKeyzEeYR8nK/12lqu+nVXfZyTFOE7MSK45EwXlzNeiX4BkRJe5JscZ4PzKmqlOuRaJK wLcwtCgb6ZB8Wunj9iFtfEmKV5XoPsJr3i1lDXtyTIxriJRDTsAFAYpiiRH0XkqhX2F8ew HPUDHdthVKxCMvuFfa6NgQLUAHRbB8q3onnA0Kq7lVtf3XEs0dMEwEmnROrymQ== 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 4PCMLQ0zPTzk4v; Thu, 9 Feb 2023 16:11:26 +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 319GBQ5c005489; Thu, 9 Feb 2023 16:11:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 319GBQPr005488; Thu, 9 Feb 2023 16:11:26 GMT (envelope-from git) Date: Thu, 9 Feb 2023 16:11:26 GMT Message-Id: <202302091611.319GBQPr005488@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: 5e598a761c37 - stable/13 - pytest: delete interfaces from inside the jail. 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/stable/13 X-Git-Reftype: branch X-Git-Commit: 5e598a761c37dbd491579a0805968ae50ac72465 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=5e598a761c37dbd491579a0805968ae50ac72465 commit 5e598a761c37dbd491579a0805968ae50ac72465 Author: Alexander V. Chernikov AuthorDate: 2023-01-25 16:32:52 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-02-09 15:46:25 +0000 pytest: delete interfaces from inside the jail. This change follows the approach used in 80fc25025ffc, to minimise the impact of the delayed interface migration. MFC after: 2 weeks (cherry picked from commit 20ea7f26e41375828a390fba613b86acfe366add) --- tests/atf_python/sys/net/vnet.py | 46 ++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/tests/atf_python/sys/net/vnet.py b/tests/atf_python/sys/net/vnet.py index 1a8efe0d9edc..1f61269ffe6c 100644 --- a/tests/atf_python/sys/net/vnet.py +++ b/tests/atf_python/sys/net/vnet.py @@ -1,6 +1,7 @@ #!/usr/local/bin/python3 import copy import ipaddress +import re import os import socket import sys @@ -150,6 +151,7 @@ class VnetInterface(object): class IfaceFactory(object): INTERFACES_FNAME = "created_ifaces.lst" + AUTODELETE_TYPES = ("epair", "lo", "tap", "tun") def __init__(self): self.file_name = self.INTERFACES_FNAME @@ -158,19 +160,46 @@ class IfaceFactory(object): with open(self.file_name, "a") as f: f.write(iface_name + "\n") + def _list_ifaces(self) -> List[str]: + ret: List[str] = [] + try: + with open(self.file_name, "r") as f: + for line in f: + ret.append(line.strip()) + except OSError: + pass + return ret + def create_iface(self, alias_name: str, iface_name: str) -> List[VnetInterface]: ifaces = VnetInterface.create_iface(alias_name, iface_name) for iface in ifaces: - self._register_iface(iface.name) + if not self.is_autodeleted(iface.name): + self._register_iface(iface.name) return ifaces + @staticmethod + def is_autodeleted(iface_name: str) -> bool: + iface_type = re.split(r"\d+", iface_name)[0] + return iface_type in IfaceFactory.AUTODELETE_TYPES + + def cleanup_vnet_interfaces(self, vnet_name: str) -> List[str]: + """Destroys""" + ifaces_lst = ToolsHelper.get_output( + "/usr/sbin/jexec {} ifconfig -l".format(vnet_name) + ) + for iface_name in ifaces_lst.split(): + if not self.is_autodeleted(iface_name): + if iface_name not in self._list_ifaces(): + print("Skipping interface {}:{}".format(vnet_name, iface_name)) + continue + run_cmd( + "/usr/sbin/jexec {} ifconfig {} destroy".format(vnet_name, iface_name) + ) + def cleanup(self): try: - with open(self.file_name, "r") as f: - for line in f: - run_cmd("/sbin/ifconfig {} destroy".format(line.strip())) os.unlink(self.INTERFACES_FNAME) - except Exception: + except OSError: pass @@ -260,7 +289,7 @@ class VnetFactory(object): try: jid_str = run_cmd(cmd) jid = int(jid_str) - except ValueError as e: + except ValueError: print("Jail creation failed, output: {}".format(jid_str)) raise self._register_vnet(vnet_name) @@ -276,13 +305,12 @@ class VnetFactory(object): return VnetInstance(vnet_alias, vnet_name, jid, ifaces) def cleanup(self): + iface_factory = IfaceFactory() try: with open(self.file_name) as f: for line in f: vnet_name = line.strip() - ToolsHelper.print_output( - "/usr/sbin/jexec {} ifconfig -l".format(vnet_name) - ) + iface_factory.cleanup_vnet_interfaces(vnet_name) run_cmd("/usr/sbin/jail -r {}".format(vnet_name)) os.unlink(self.JAILS_FNAME) except OSError: