From nobody Thu May 15 03:30:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1518055531304190.13481819590697; Wed, 7 Feb 2018 18:05:31 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1C21D8FABB; Thu, 8 Feb 2018 02:05:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C96BB2A2E7; Thu, 8 Feb 2018 02:05:29 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8BCDE18033EA; Thu, 8 Feb 2018 02:05:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w18255VY023189 for ; Wed, 7 Feb 2018 21:05:06 -0500 Received: by smtp.corp.redhat.com (Postfix) id A41F22166BB6; Thu, 8 Feb 2018 02:05:05 +0000 (UTC) Received: from tlap.laine.org.com (ovpn-120-186.rdu2.redhat.com [10.10.120.186]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71CDC2166BB3; Thu, 8 Feb 2018 02:05:05 +0000 (UTC) From: Laine Stump To: libvir-list@redhat.com Date: Wed, 7 Feb 2018 21:04:52 -0500 Message-Id: <20180208020459.16928-3-laine@laine.org> In-Reply-To: <20180208020459.16928-1-laine@laine.org> References: <20180208020459.16928-1-laine@laine.org> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [tck PATCH 2/9] Use $net->get_dhcp_leases() when available X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 08 Feb 2018 02:05:30 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Newer versions of libvirt no longer let dnsmasq create a leases file, they keep track of it themselves and provide an API to retrieve the current list of leases. Use that to get the guest's IP address when it's available. Reviewed-by: Daniel P. Berrange --- I later realized that it might be more appropriate to use $dom->get_interface_addresses(), but I'd already rewritten the existing function this way and it works, so I left it. lib/Sys/Virt/TCK/NetworkHelpers.pm | 9 +++++++++ scripts/nwfilter/100-ping-still-working.t | 2 +- scripts/nwfilter/210-no-mac-spoofing.t | 2 +- scripts/nwfilter/220-no-ip-spoofing.t | 2 +- scripts/nwfilter/230-no-mac-broadcast.t | 2 +- scripts/nwfilter/240-no-arp-spoofing.t | 2 +- scripts/nwfilter/nwfilter_concurrent.sh | 4 ++-- 7 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/Sys/Virt/TCK/NetworkHelpers.pm b/lib/Sys/Virt/TCK/NetworkH= elpers.pm index 133064b..f6bf8f9 100644 --- a/lib/Sys/Virt/TCK/NetworkHelpers.pm +++ b/lib/Sys/Virt/TCK/NetworkHelpers.pm @@ -10,7 +10,16 @@ sub get_first_macaddress { } =20 sub get_ip_from_leases{ + my $conn =3D shift; + my $netname =3D shift; my $mac =3D shift; + + my $net =3D $conn->get_network_by_name($netname); + if ($net->can('get_dhcp_leases')) { + my @leases =3D $net->get_dhcp_leases($mac); + return @leases ? @leases[0]->{'ipaddr'} : undef; + } + my $tmp =3D `grep $mac /var/lib/libvirt/dnsmasq/default.leases`; my @fields =3D split(/ /, $tmp); my $ip =3D $fields[2]; diff --git a/scripts/nwfilter/100-ping-still-working.t b/scripts/nwfilter/1= 00-ping-still-working.t index a20b95d..dc1efd2 100644 --- a/scripts/nwfilter/100-ping-still-working.t +++ b/scripts/nwfilter/100-ping-still-working.t @@ -69,7 +69,7 @@ sleep(10); my $mac =3D get_first_macaddress($dom); diag "mac is $mac"; =20 -my $guestip =3D get_ip_from_leases($mac); +my $guestip =3D get_ip_from_leases($conn, "default", $mac); diag "ip is $guestip"; =20 # check ebtables entry diff --git a/scripts/nwfilter/210-no-mac-spoofing.t b/scripts/nwfilter/210-= no-mac-spoofing.t index b81fc4a..03001a8 100644 --- a/scripts/nwfilter/210-no-mac-spoofing.t +++ b/scripts/nwfilter/210-no-mac-spoofing.t @@ -69,7 +69,7 @@ sleep(10); my $mac =3D get_first_macaddress($dom); diag "mac is $mac"; =20 -my $guestip =3D get_ip_from_leases($mac); +my $guestip =3D get_ip_from_leases($conn, "default", $mac); diag "ip is $guestip"; =20 # check ebtables entry diff --git a/scripts/nwfilter/220-no-ip-spoofing.t b/scripts/nwfilter/220-n= o-ip-spoofing.t index 3a0213d..d447a19 100644 --- a/scripts/nwfilter/220-no-ip-spoofing.t +++ b/scripts/nwfilter/220-no-ip-spoofing.t @@ -60,7 +60,7 @@ sleep(30); my $mac =3D get_first_macaddress($dom); diag "mac is $mac"; =20 -my $guestip =3D get_ip_from_leases($mac); +my $guestip =3D get_ip_from_leases($conn, "default", $mac); diag "ip is $guestip"; =20 # check ebtables entry diff --git a/scripts/nwfilter/230-no-mac-broadcast.t b/scripts/nwfilter/230= -no-mac-broadcast.t index 16ce60d..9d00dc4 100644 --- a/scripts/nwfilter/230-no-mac-broadcast.t +++ b/scripts/nwfilter/230-no-mac-broadcast.t @@ -68,7 +68,7 @@ sleep(10); my $mac =3D get_first_macaddress($dom); diag "mac is $mac"; =20 -my $guestip =3D get_ip_from_leases($mac); +my $guestip =3D get_ip_from_leases($conn, "default", $mac); diag "ip is $guestip"; =20 # check ebtables entry diff --git a/scripts/nwfilter/240-no-arp-spoofing.t b/scripts/nwfilter/240-= no-arp-spoofing.t index 284033d..f1e6870 100644 --- a/scripts/nwfilter/240-no-arp-spoofing.t +++ b/scripts/nwfilter/240-no-arp-spoofing.t @@ -70,7 +70,7 @@ sleep(10); my $mac =3D get_first_macaddress($dom); diag "mac is $mac"; =20 -my $guestip =3D get_ip_from_leases($mac); +my $guestip =3D get_ip_from_leases($conn, "default", $mac); diag "ip is $guestip"; =20 # check ebtables entry diff --git a/scripts/nwfilter/nwfilter_concurrent.sh b/scripts/nwfilter/nwf= ilter_concurrent.sh index 4c9b878..359e2ab 100644 --- a/scripts/nwfilter/nwfilter_concurrent.sh +++ b/scripts/nwfilter/nwfilter_concurrent.sh @@ -242,9 +242,9 @@ runTest() =20 [ $? -ne 0 ] && rm -rf "${tmpdir}" && return 1; =20 - # Test runs for a maximum of 5 minutes + # Test runs for a maximum of 10 minutes now=3D`date +%s` - test_end=3D$(($now + 5 * 60)) + test_end=3D$(($now + 10 * 60)) =20 while :; do --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list