From nobody Tue Apr 16 23:59:33 2024 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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1541174338819444.78344854363763; Fri, 2 Nov 2018 08:58:58 -0700 (PDT) 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 3184B3965; Fri, 2 Nov 2018 15:58:56 +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 44CDF5D9C9; Fri, 2 Nov 2018 15:58:55 +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 B9EDD180474F; Fri, 2 Nov 2018 15:58:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wA2FqDZB013183 for ; Fri, 2 Nov 2018 11:52:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id D598B600D1; Fri, 2 Nov 2018 15:52:13 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-64.ams2.redhat.com [10.36.112.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 748CF600CD; Fri, 2 Nov 2018 15:52:12 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 2 Nov 2018 15:52:07 +0000 Message-Id: <20181102155209.1331-2-berrange@redhat.com> In-Reply-To: <20181102155209.1331-1-berrange@redhat.com> References: <20181102155209.1331-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [tck PATCH 1/3] Add tests for virtual network <-> guest connections 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: , Content-Type: text/plain; charset="utf-8" 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.26]); Fri, 02 Nov 2018 15:58:57 +0000 (UTC) Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump Tested-by: Laine Stump --- lib/Sys/Virt/TCK.pm | 33 ++++++++ lib/Sys/Virt/TCK/NetworkBuilder.pm | 33 +++++++- scripts/networks/300-guest-network-isolated.t | 82 ++++++++++++++++++ scripts/networks/310-guest-network-nat.t | 83 +++++++++++++++++++ scripts/networks/320-guest-network-route.t | 83 +++++++++++++++++++ scripts/networks/330-guest-network-open.t | 83 +++++++++++++++++++ scripts/networks/340-guest-network-bridge.t | 79 ++++++++++++++++++ scripts/networks/350-guest-network-private.t | 81 ++++++++++++++++++ scripts/networks/360-guest-network-vepa.t | 81 ++++++++++++++++++ .../networks/370-guest-network-passthrough.t | 81 ++++++++++++++++++ scripts/networks/380-guest-network-hostdev.t | 82 ++++++++++++++++++ t/080-network-builder.t | 2 +- 12 files changed, 800 insertions(+), 3 deletions(-) create mode 100644 scripts/networks/300-guest-network-isolated.t create mode 100644 scripts/networks/310-guest-network-nat.t create mode 100644 scripts/networks/320-guest-network-route.t create mode 100644 scripts/networks/330-guest-network-open.t create mode 100644 scripts/networks/340-guest-network-bridge.t create mode 100644 scripts/networks/350-guest-network-private.t create mode 100644 scripts/networks/360-guest-network-vepa.t create mode 100644 scripts/networks/370-guest-network-passthrough.t create mode 100644 scripts/networks/380-guest-network-hostdev.t diff --git a/lib/Sys/Virt/TCK.pm b/lib/Sys/Virt/TCK.pm index 04244bd..9457836 100644 --- a/lib/Sys/Virt/TCK.pm +++ b/lib/Sys/Virt/TCK.pm @@ -29,6 +29,7 @@ use File::Path qw(mkpath); use File::Spec::Functions qw(catfile catdir rootdir); use Cwd qw(cwd); use LWP::UserAgent; +use IO::Interface::Simple; use IO::Uncompress::Gunzip qw(gunzip); use IO::Uncompress::Bunzip2 qw(bunzip2); use XML::XPath; @@ -1285,6 +1286,38 @@ sub get_ip_from_leases{ } =20 =20 +sub find_free_ipv4_subnet { + my $index; + + my %used; + + foreach my $iface (IO::Interface::Simple->interfaces()) { + if ($iface->netmask eq "255.255.255.0" && + $iface->address =3D~ /^192.168.(\d+).\d+/) { + $used{"$1"} =3D 1; + print "Used $1\n"; + } else { + print "Not used ", $iface->address, "\n"; + } + } + + for (my $i =3D 1; $i < 255; $i++) { + if (!exists $used{"$i"}) { + $index =3D $i; + last; + } + } + + return () unless defined $index; + + return ( + address =3D> "192.168.$index.1", + netmask =3D> "255.255.255.0", + dhcpstart =3D> "192.168.$index.100", + dhcpend =3D> "192.168.$index.200" + ); +} + sub shutdown_vm_gracefully { my $dom =3D shift; =20 diff --git a/lib/Sys/Virt/TCK/NetworkBuilder.pm b/lib/Sys/Virt/TCK/NetworkB= uilder.pm index 09ca6b7..ad0cab8 100644 --- a/lib/Sys/Virt/TCK/NetworkBuilder.pm +++ b/lib/Sys/Virt/TCK/NetworkBuilder.pm @@ -61,6 +61,22 @@ sub forward { return $self; } =20 +sub interfaces { + my $self =3D shift; + + $self->{interfaces} =3D [@_]; + + return $self; +} + +sub host_devices { + my $self =3D shift; + + $self->{host_devices} =3D [@_]; + + return $self; +} + sub ipaddr { my $self =3D shift; my $address =3D shift; @@ -98,8 +114,21 @@ sub as_xml { $w->emptyTag("bridge", %{$self->{bridge}}) if $self->{bridge}; =20 - $w->emptyTag("forward", %{$self->{forward}}) - if exists $self->{forward}; + if (exists $self->{forward}) { + $w->startTag("forward", %{$self->{forward}}); + foreach (@{$self->{interfaces}}) { + $w->emptyTag("interface", dev =3D> $_); + } + foreach (@{$self->{host_devices}}) { + $w->emptyTag("address", + type =3D> "pci", + domain =3D> $_->[0], + bus =3D> $_->[1], + slot =3D> $_->[2], + function =3D> $_->[3]); + } + $w->endTag("forward"); + } =20 if ($self->{ipaddr}) { $w->startTag("ip", diff --git a/scripts/networks/300-guest-network-isolated.t b/scripts/networ= ks/300-guest-network-isolated.t new file mode 100644 index 0000000..487e864 --- /dev/null +++ b/scripts/networks/300-guest-network-isolated.t @@ -0,0 +1,82 @@ +# -*- perl -*- +# +# Copyright (C) 2018 Red Hat, Inc. +# +# This program is free software; You can redistribute it and/or modify +# it under the GNU General Public License as published by the Free +# Software Foundation; either version 2, or (at your option) any +# later version +# +# The file "LICENSE" distributed along with this file provides full +# details of the terms and conditions +# + +=3Dpod + +=3Dhead1 NAME + +network/300-guest-network-isolated.t - guest connect to isolated network + +=3Dhead1 DESCRIPTION + +This test case validates that a guest is connected to an isolated +virtual network + +=3Dcut + +use strict; +use warnings; + +use Test::More tests =3D> 4; + +use Sys::Virt::TCK; + +my $tck =3D Sys::Virt::TCK->new(); +my $conn =3D eval { $tck->setup(); }; +BAIL_OUT "failed to setup test harness: $@" if $@; +END { $tck->cleanup if $tck; } + +my %subnet =3D Sys::Virt::TCK->find_free_ipv4_subnet(); + +SKIP: { + skip "No available IPv4 subnet", 4 unless defined $subnet{address}; + + my $b =3D Sys::Virt::TCK::NetworkBuilder->new(name =3D> "tck"); + $b->bridge("tck"); + $b->ipaddr($subnet{address}, $subnet{netmask}); + $b->dhcp_range($subnet{dhcpstart}, $subnet{dhcpend}); + my $xml =3D $b->as_xml(); + + diag "Creating a new transient network"; + diag $xml; + my $net; + ok_network(sub { $net =3D $conn->create_network($xml) }, "created tran= sient network object"); + + $b =3D $tck->generic_domain(name =3D> "tck"); + $b->interface(type =3D> "network", + source =3D> "tck", + model =3D> "virtio", + mac =3D> "52:54:00:11:11:11"); + $xml =3D $b->as_xml(); + + diag "Creating a new transient domain"; + diag $xml; + my $dom; + ok_domain(sub { $dom =3D $conn->create_domain($xml) }, "created transi= ent domain object"); + + diag "Destroying the transient guest"; + $dom->destroy; + + diag "Checking that transient domain has gone away"; + ok_error(sub { $conn->get_domain_by_name("tck") }, "NO_DOMAIN error ra= ised from missing domain", + Sys::Virt::Error::ERR_NO_DOMAIN); + + diag "Destroying the transient network"; + $net->destroy; + + diag "Checking that transient network has gone away"; + ok_error(sub { $conn->get_network_by_name("tck") }, "NO_network error = raised from missing network", + Sys::Virt::Error::ERR_NO_NETWORK); +} + +# end diff --git a/scripts/networks/310-guest-network-nat.t b/scripts/networks/31= 0-guest-network-nat.t new file mode 100644 index 0000000..fe1a926 --- /dev/null +++ b/scripts/networks/310-guest-network-nat.t @@ -0,0 +1,83 @@ +# -*- perl -*- +# +# Copyright (C) 2018 Red Hat, Inc. +# +# This program is free software; You can redistribute it and/or modify +# it under the GNU General Public License as published by the Free +# Software Foundation; either version 2, or (at your option) any +# later version +# +# The file "LICENSE" distributed along with this file provides full +# details of the terms and conditions +# + +=3Dpod + +=3Dhead1 NAME + +network/310-guest-network-nat.t - guest connect to nat network + +=3Dhead1 DESCRIPTION + +This test case validates that a guest is connected to a nat +virtual network + +=3Dcut + +use strict; +use warnings; + +use Test::More tests =3D> 4; + +use Sys::Virt::TCK; + +my $tck =3D Sys::Virt::TCK->new(); +my $conn =3D eval { $tck->setup(); }; +BAIL_OUT "failed to setup test harness: $@" if $@; +END { $tck->cleanup if $tck; } + +my %subnet =3D Sys::Virt::TCK->find_free_ipv4_subnet(); + +SKIP: { + skip "No available IPv4 subnet", 4 unless defined $subnet{address}; + + my $b =3D Sys::Virt::TCK::NetworkBuilder->new(name =3D> "tck"); + $b->bridge("tck"); + $b->forward(mode =3D> "nat"); + $b->ipaddr($subnet{address}, $subnet{netmask}); + $b->dhcp_range($subnet{dhcpstart}, $subnet{dhcpend}); + my $xml =3D $b->as_xml(); + + diag "Creating a new transient network"; + diag $xml; + my $net; + ok_network(sub { $net =3D $conn->create_network($xml) }, "created tran= sient network object"); + + $b =3D $tck->generic_domain(name =3D> "tck"); + $b->interface(type =3D> "network", + source =3D> "tck", + model =3D> "virtio", + mac =3D> "52:54:00:11:11:11"); + $xml =3D $b->as_xml(); + + diag "Creating a new transient domain"; + diag $xml; + my $dom; + ok_domain(sub { $dom =3D $conn->create_domain($xml) }, "created transi= ent domain object"); + + diag "Destroying the transient guest"; + $dom->destroy; + + diag "Checking that transient domain has gone away"; + ok_error(sub { $conn->get_domain_by_name("tck") }, "NO_DOMAIN error ra= ised from missing domain", + Sys::Virt::Error::ERR_NO_DOMAIN); + + diag "Destroying the transient network"; + $net->destroy; + + diag "Checking that transient network has gone away"; + ok_error(sub { $conn->get_network_by_name("tck") }, "NO_network error = raised from missing network", + Sys::Virt::Error::ERR_NO_NETWORK); +} + +# end diff --git a/scripts/networks/320-guest-network-route.t b/scripts/networks/= 320-guest-network-route.t new file mode 100644 index 0000000..91f0b70 --- /dev/null +++ b/scripts/networks/320-guest-network-route.t @@ -0,0 +1,83 @@ +# -*- perl -*- +# +# Copyright (C) 2018 Red Hat, Inc. +# +# This program is free software; You can redistribute it and/or modify +# it under the GNU General Public License as published by the Free +# Software Foundation; either version 2, or (at your option) any +# later version +# +# The file "LICENSE" distributed along with this file provides full +# details of the terms and conditions +# + +=3Dpod + +=3Dhead1 NAME + +network/320-guest-network-route.t - guest connect to routed network + +=3Dhead1 DESCRIPTION + +This test case validates that a guest is connected to a routed +virtual network + +=3Dcut + +use strict; +use warnings; + +use Test::More tests =3D> 4; + +use Sys::Virt::TCK; + +my $tck =3D Sys::Virt::TCK->new(); +my $conn =3D eval { $tck->setup(); }; +BAIL_OUT "failed to setup test harness: $@" if $@; +END { $tck->cleanup if $tck; } + +my %subnet =3D Sys::Virt::TCK->find_free_ipv4_subnet(); + +SKIP: { + skip "No available IPv4 subnet", 4 unless defined $subnet{address}; + + my $b =3D Sys::Virt::TCK::NetworkBuilder->new(name =3D> "tck"); + $b->bridge("tck"); + $b->forward(mode =3D> "route"); + $b->ipaddr($subnet{address}, $subnet{netmask}); + $b->dhcp_range($subnet{dhcpstart}, $subnet{dhcpend}); + my $xml =3D $b->as_xml(); + + diag "Creating a new transient network"; + diag $xml; + my $net; + ok_network(sub { $net =3D $conn->create_network($xml) }, "created tran= sient network object"); + + $b =3D $tck->generic_domain(name =3D> "tck"); + $b->interface(type =3D> "network", + source =3D> "tck", + model =3D> "virtio", + mac =3D> "52:54:00:11:11:11"); + $xml =3D $b->as_xml(); + + diag "Creating a new transient domain"; + diag $xml; + my $dom; + ok_domain(sub { $dom =3D $conn->create_domain($xml) }, "created transi= ent domain object"); + + diag "Destroying the transient guest"; + $dom->destroy; + + diag "Checking that transient domain has gone away"; + ok_error(sub { $conn->get_domain_by_name("tck") }, "NO_DOMAIN error ra= ised from missing domain", + Sys::Virt::Error::ERR_NO_DOMAIN); + + diag "Destroying the transient network"; + $net->destroy; + + diag "Checking that transient network has gone away"; + ok_error(sub { $conn->get_network_by_name("tck") }, "NO_network error = raised from missing network", + Sys::Virt::Error::ERR_NO_NETWORK); +} + +# end diff --git a/scripts/networks/330-guest-network-open.t b/scripts/networks/3= 30-guest-network-open.t new file mode 100644 index 0000000..113f4cc --- /dev/null +++ b/scripts/networks/330-guest-network-open.t @@ -0,0 +1,83 @@ +# -*- perl -*- +# +# Copyright (C) 2018 Red Hat, Inc. +# +# This program is free software; You can redistribute it and/or modify +# it under the GNU General Public License as published by the Free +# Software Foundation; either version 2, or (at your option) any +# later version +# +# The file "LICENSE" distributed along with this file provides full +# details of the terms and conditions +# + +=3Dpod + +=3Dhead1 NAME + +network/330-guest-network-open.t - guest connect to open network + +=3Dhead1 DESCRIPTION + +This test case validates that a guest is connected to an open +virtual network + +=3Dcut + +use strict; +use warnings; + +use Test::More tests =3D> 4; + +use Sys::Virt::TCK; + +my $tck =3D Sys::Virt::TCK->new(); +my $conn =3D eval { $tck->setup(); }; +BAIL_OUT "failed to setup test harness: $@" if $@; +END { $tck->cleanup if $tck; } + +my %subnet =3D Sys::Virt::TCK->find_free_ipv4_subnet(); + +SKIP: { + skip "No available IPv4 subnet", 4 unless defined $subnet{address}; + + my $b =3D Sys::Virt::TCK::NetworkBuilder->new(name =3D> "tck"); + $b->bridge("tck"); + $b->forward(mode =3D> "open"); + $b->ipaddr($subnet{address}, $subnet{netmask}); + $b->dhcp_range($subnet{dhcpstart}, $subnet{dhcpend}); + my $xml =3D $b->as_xml(); + + diag "Creating a new transient network"; + diag $xml; + my $net; + ok_network(sub { $net =3D $conn->create_network($xml) }, "created tran= sient network object"); + + $b =3D $tck->generic_domain(name =3D> "tck"); + $b->interface(type =3D> "network", + source =3D> "tck", + model =3D> "virtio", + mac =3D> "52:54:00:11:11:11"); + $xml =3D $b->as_xml(); + + diag "Creating a new transient domain"; + diag $xml; + my $dom; + ok_domain(sub { $dom =3D $conn->create_domain($xml) }, "created transi= ent domain object"); + + diag "Destroying the transient guest"; + $dom->destroy; + + diag "Checking that transient domain has gone away"; + ok_error(sub { $conn->get_domain_by_name("tck") }, "NO_DOMAIN error ra= ised from missing domain", + Sys::Virt::Error::ERR_NO_DOMAIN); + + diag "Destroying the transient network"; + $net->destroy; + + diag "Checking that transient network has gone away"; + ok_error(sub { $conn->get_network_by_name("tck") }, "NO_network error = raised from missing network", + Sys::Virt::Error::ERR_NO_NETWORK); +} + +# end diff --git a/scripts/networks/340-guest-network-bridge.t b/scripts/networks= /340-guest-network-bridge.t new file mode 100644 index 0000000..e5db0ff --- /dev/null +++ b/scripts/networks/340-guest-network-bridge.t @@ -0,0 +1,79 @@ +# -*- perl -*- +# +# Copyright (C) 2018 Red Hat, Inc. +# +# This program is free software; You can redistribute it and/or modify +# it under the GNU General Public License as published by the Free +# Software Foundation; either version 2, or (at your option) any +# later version +# +# The file "LICENSE" distributed along with this file provides full +# details of the terms and conditions +# + +=3Dpod + +=3Dhead1 NAME + +network/340-guest-network-bridge.t - guest connect to bridge network + +=3Dhead1 DESCRIPTION + +This test case validates that a guest is connected to a bridge +virtual network + +=3Dcut + +use strict; +use warnings; + +use Test::More tests =3D> 4; + +use Sys::Virt::TCK; + +my $tck =3D Sys::Virt::TCK->new(); +my $conn =3D eval { $tck->setup(); }; +BAIL_OUT "failed to setup test harness: $@" if $@; +END { $tck->cleanup if $tck; } + +((system "brctl addbr tck") =3D=3D 0) or die "cannot create bridge 'tck'"; + +END { system "brctl delbr tck" } + +my $b =3D Sys::Virt::TCK::NetworkBuilder->new(name =3D> "tck"); +$b->bridge("tck"); +$b->forward(mode =3D> "bridge"); +my $xml =3D $b->as_xml(); + +diag "Creating a new transient network"; +diag $xml; +my $net; +ok_network(sub { $net =3D $conn->create_network($xml) }, "created transien= t network object"); + +$b =3D $tck->generic_domain(name =3D> "tck"); +$b->interface(type =3D> "network", + source =3D> "tck", + model =3D> "virtio", + mac =3D> "52:54:00:11:11:11"); +$xml =3D $b->as_xml(); + +diag "Creating a new transient domain"; +diag $xml; +my $dom; +ok_domain(sub { $dom =3D $conn->create_domain($xml) }, "created transient = domain object"); + +diag "Destroying the transient guest"; +$dom->destroy; + +diag "Checking that transient domain has gone away"; +ok_error(sub { $conn->get_domain_by_name("tck") }, "NO_DOMAIN error raised= from missing domain", + Sys::Virt::Error::ERR_NO_DOMAIN); + +diag "Destroying the transient network"; +$net->destroy; + +diag "Checking that transient network has gone away"; +ok_error(sub { $conn->get_network_by_name("tck") }, "NO_network error rais= ed from missing network", + Sys::Virt::Error::ERR_NO_NETWORK); + +# end diff --git a/scripts/networks/350-guest-network-private.t b/scripts/network= s/350-guest-network-private.t new file mode 100644 index 0000000..0b98149 --- /dev/null +++ b/scripts/networks/350-guest-network-private.t @@ -0,0 +1,81 @@ +# -*- perl -*- +# +# Copyright (C) 2018 Red Hat, Inc. +# +# This program is free software; You can redistribute it and/or modify +# it under the GNU General Public License as published by the Free +# Software Foundation; either version 2, or (at your option) any +# later version +# +# The file "LICENSE" distributed along with this file provides full +# details of the terms and conditions +# + +=3Dpod + +=3Dhead1 NAME + +network/350-guest-network-private.t - guest connect to private network + +=3Dhead1 DESCRIPTION + +This test case validates that a guest is connected to a private +virtual network + +=3Dcut + +use strict; +use warnings; + +use Test::More tests =3D> 4; + +use Sys::Virt::TCK; + +my $tck =3D Sys::Virt::TCK->new(); +my $conn =3D eval { $tck->setup(); }; +BAIL_OUT "failed to setup test harness: $@" if $@; +END { $tck->cleanup if $tck; } + +my $hostnet =3D $tck->get_host_network_device(); + +SKIP: { + skip "No host device available", 4 unless $hostnet; + + my $b =3D Sys::Virt::TCK::NetworkBuilder->new(name =3D> "tck"); + $b->forward(mode =3D> "private"); + $b->interfaces($hostnet); + my $xml =3D $b->as_xml(); + + diag "Creating a new transient network"; + diag $xml; + my $net; + ok_network(sub { $net =3D $conn->create_network($xml) }, "created tran= sient network object"); + + $b =3D $tck->generic_domain(name =3D> "tck"); + $b->interface(type =3D> "network", + source =3D> "tck", + model =3D> "virtio", + mac =3D> "52:54:00:11:11:11"); + $xml =3D $b->as_xml(); + + diag "Creating a new transient domain"; + diag $xml; + my $dom; + ok_domain(sub { $dom =3D $conn->create_domain($xml) }, "created transi= ent domain object"); + + diag "Destroying the transient guest"; + $dom->destroy; + + diag "Checking that transient domain has gone away"; + ok_error(sub { $conn->get_domain_by_name("tck") }, "NO_DOMAIN error ra= ised from missing domain", + Sys::Virt::Error::ERR_NO_DOMAIN); + + diag "Destroying the transient network"; + $net->destroy; + + diag "Checking that transient network has gone away"; + ok_error(sub { $conn->get_network_by_name("tck") }, "NO_network error = raised from missing network", + Sys::Virt::Error::ERR_NO_NETWORK); +} + +# end diff --git a/scripts/networks/360-guest-network-vepa.t b/scripts/networks/3= 60-guest-network-vepa.t new file mode 100644 index 0000000..f32ad28 --- /dev/null +++ b/scripts/networks/360-guest-network-vepa.t @@ -0,0 +1,81 @@ +# -*- perl -*- +# +# Copyright (C) 2018 Red Hat, Inc. +# +# This program is free software; You can redistribute it and/or modify +# it under the GNU General Public License as published by the Free +# Software Foundation; either version 2, or (at your option) any +# later version +# +# The file "LICENSE" distributed along with this file provides full +# details of the terms and conditions +# + +=3Dpod + +=3Dhead1 NAME + +network/360-guest-network-vepa.t - guest connect to vepa network + +=3Dhead1 DESCRIPTION + +This test case validates that a guest is connected to a VEPA +virtual network + +=3Dcut + +use strict; +use warnings; + +use Test::More tests =3D> 4; + +use Sys::Virt::TCK; + +my $tck =3D Sys::Virt::TCK->new(); +my $conn =3D eval { $tck->setup(); }; +BAIL_OUT "failed to setup test harness: $@" if $@; +END { $tck->cleanup if $tck; } + +my $hostnet =3D $tck->get_host_network_device(); + +SKIP: { + skip "No host device available", 4 unless $hostnet; + + my $b =3D Sys::Virt::TCK::NetworkBuilder->new(name =3D> "tck"); + $b->forward(mode =3D> "vepa"); + $b->interfaces($hostnet); + my $xml =3D $b->as_xml(); + + diag "Creating a new transient network"; + diag $xml; + my $net; + ok_network(sub { $net =3D $conn->create_network($xml) }, "created tran= sient network object"); + + $b =3D $tck->generic_domain(name =3D> "tck"); + $b->interface(type =3D> "network", + source =3D> "tck", + model =3D> "virtio", + mac =3D> "52:54:00:11:11:11"); + $xml =3D $b->as_xml(); + + diag "Creating a new transient domain"; + diag $xml; + my $dom; + ok_domain(sub { $dom =3D $conn->create_domain($xml) }, "created transi= ent domain object"); + + diag "Destroying the transient guest"; + $dom->destroy; + + diag "Checking that transient domain has gone away"; + ok_error(sub { $conn->get_domain_by_name("tck") }, "NO_DOMAIN error ra= ised from missing domain", + Sys::Virt::Error::ERR_NO_DOMAIN); + + diag "Destroying the transient network"; + $net->destroy; + + diag "Checking that transient network has gone away"; + ok_error(sub { $conn->get_network_by_name("tck") }, "NO_network error = raised from missing network", + Sys::Virt::Error::ERR_NO_NETWORK); +} + +# end diff --git a/scripts/networks/370-guest-network-passthrough.t b/scripts/net= works/370-guest-network-passthrough.t new file mode 100644 index 0000000..ebd210d --- /dev/null +++ b/scripts/networks/370-guest-network-passthrough.t @@ -0,0 +1,81 @@ +# -*- perl -*- +# +# Copyright (C) 2018 Red Hat, Inc. +# +# This program is free software; You can redistribute it and/or modify +# it under the GNU General Public License as published by the Free +# Software Foundation; either version 2, or (at your option) any +# later version +# +# The file "LICENSE" distributed along with this file provides full +# details of the terms and conditions +# + +=3Dpod + +=3Dhead1 NAME + +network/370-guest-network-passthrough.t - guest connect to passthrough net= work + +=3Dhead1 DESCRIPTION + +This test case validates that a guest is connected to a passthrough +virtual network + +=3Dcut + +use strict; +use warnings; + +use Test::More tests =3D> 4; + +use Sys::Virt::TCK; + +my $tck =3D Sys::Virt::TCK->new(); +my $conn =3D eval { $tck->setup(); }; +BAIL_OUT "failed to setup test harness: $@" if $@; +END { $tck->cleanup if $tck; } + +my $hostnet =3D $tck->get_host_network_device(); + +SKIP: { + skip "No host device available", 4 unless $hostnet; + + my $b =3D Sys::Virt::TCK::NetworkBuilder->new(name =3D> "tck"); + $b->forward(mode =3D> "passthrough");=20 + $b->interfaces($hostnet); + my $xml =3D $b->as_xml(); + + diag "Creating a new transient network"; + diag $xml; + my $net; + ok_network(sub { $net =3D $conn->create_network($xml) }, "created tran= sient network object"); + + $b =3D $tck->generic_domain(name =3D> "tck"); + $b->interface(type =3D> "network", + source =3D> "tck", + model =3D> "virtio", + mac =3D> "52:54:00:11:11:11"); + $xml =3D $b->as_xml(); + + diag "Creating a new transient domain"; + diag $xml; + my $dom; + ok_domain(sub { $dom =3D $conn->create_domain($xml) }, "created transi= ent domain object"); + + diag "Destroying the transient guest"; + $dom->destroy; + + diag "Checking that transient domain has gone away"; + ok_error(sub { $conn->get_domain_by_name("tck") }, "NO_DOMAIN error ra= ised from missing domain", + Sys::Virt::Error::ERR_NO_DOMAIN); + + diag "Destroying the transient network"; + $net->destroy; + + diag "Checking that transient network has gone away"; + ok_error(sub { $conn->get_network_by_name("tck") }, "NO_network error = raised from missing network", + Sys::Virt::Error::ERR_NO_NETWORK); +} + +# end diff --git a/scripts/networks/380-guest-network-hostdev.t b/scripts/network= s/380-guest-network-hostdev.t new file mode 100644 index 0000000..63fa0c9 --- /dev/null +++ b/scripts/networks/380-guest-network-hostdev.t @@ -0,0 +1,82 @@ +# -*- perl -*- +# +# Copyright (C) 2018 Red Hat, Inc. +# +# This program is free software; You can redistribute it and/or modify +# it under the GNU General Public License as published by the Free +# Software Foundation; either version 2, or (at your option) any +# later version +# +# The file "LICENSE" distributed along with this file provides full +# details of the terms and conditions +# + +=3Dpod + +=3Dhead1 NAME + +network/380-guest-network-hostdev.t - guest connect to a hostdev network + +=3Dhead1 DESCRIPTION + +This test case validates that a guest is connected to a hostdev +virtual network + +=3Dcut + +use strict; +use warnings; + +use Test::More tests =3D> 4; + +use Sys::Virt::TCK; + +my $tck =3D Sys::Virt::TCK->new(); +my $conn =3D eval { $tck->setup(); }; +BAIL_OUT "failed to setup test harness: $@" if $@; +END { $tck->cleanup if $tck; } + +my ($domain, $bus, $slot, $func) =3D $tck->get_host_pci_device(); + +SKIP: { + skip "No available PCI device", 4 unless defined $domain; + + my $b =3D Sys::Virt::TCK::NetworkBuilder->new(name =3D> "tck"); + $b->bridge("tck"); + $b->forward(mode =3D> "hostdev"); + $b->host_devices([$domain, $bus, $slot, $func]); + my $xml =3D $b->as_xml(); + + diag "Creating a new transient network"; + diag $xml; + my $net; + ok_network(sub { $net =3D $conn->create_network($xml) }, "created tran= sient network object"); + + $b =3D $tck->generic_domain(name =3D> "tck"); + $b->interface(type =3D> "network", + source =3D> "tck", + model =3D> "virtio", + mac =3D> "52:54:00:11:11:11"); + $xml =3D $b->as_xml(); + + diag "Creating a new transient domain"; + diag $xml; + my $dom; + ok_domain(sub { $dom =3D $conn->create_domain($xml) }, "created transi= ent domain object"); + + diag "Destroying the transient guest"; + $dom->destroy; + + diag "Checking that transient domain has gone away"; + ok_error(sub { $conn->get_domain_by_name("tck") }, "NO_DOMAIN error ra= ised from missing domain", + Sys::Virt::Error::ERR_NO_DOMAIN); + + diag "Destroying the transient network"; + $net->destroy; + + diag "Checking that transient network has gone away"; + ok_error(sub { $conn->get_network_by_name("tck") }, "NO_network error = raised from missing network", + Sys::Virt::Error::ERR_NO_NETWORK); +} + +# end diff --git a/t/080-network-builder.t b/t/080-network-builder.t index ec2b70c..a99bc63 100644 --- a/t/080-network-builder.t +++ b/t/080-network-builder.t @@ -23,7 +23,7 @@ my $xml =3D < tck - + --=20 2.19.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue Apr 16 23:59:33 2024 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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1541174365494400.4951417056848; Fri, 2 Nov 2018 08:59:25 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 53F7130015E2; Fri, 2 Nov 2018 15:59:23 +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 20FF6600D1; Fri, 2 Nov 2018 15:59:23 +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 BDD881804750; Fri, 2 Nov 2018 15:59:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wA2FqF1X013188 for ; Fri, 2 Nov 2018 11:52:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 17349600D1; Fri, 2 Nov 2018 15:52:15 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-64.ams2.redhat.com [10.36.112.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 40036600CD; Fri, 2 Nov 2018 15:52:14 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 2 Nov 2018 15:52:08 +0000 Message-Id: <20181102155209.1331-3-berrange@redhat.com> In-Reply-To: <20181102155209.1331-1-berrange@redhat.com> References: <20181102155209.1331-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [tck PATCH 2/3] Fix incorrect warning about deleting everything 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: , Content-Type: text/plain; charset="utf-8" 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 02 Nov 2018 15:59:24 +0000 (UTC) The code does not in fact delete everything on the host, only things whose name starts with a "tck" prefix. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- bin/libvirt-tck | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/bin/libvirt-tck b/bin/libvirt-tck index 816234b..d5519dd 100644 --- a/bin/libvirt-tck +++ b/bin/libvirt-tck @@ -38,20 +38,22 @@ test suite for libvirt drivers. =20 =3Dhead2 WARNING =20 -There now follows a few words of warning +The test suite is intended to be moderately safe to run on arbitrary +hosts and takes steps to avoid intentionally breaking things. =20 -The test suite needs to have a completely 'clean' initial -starting state. If your host already has virtual machines -defined and/or running this will cause problems. The test -suite will detect this and refuse to run, allowing you to -remove any preexisting guests. Alternatively you can pass -the --force option and libvirt will DELETE EVERYTHING it -finds. +All objects (guests, networks, storage pools, etc) that are created +will have a name prefix of "tck" to minimize risk of clashes. The +test suite will only ever (intentionally) delete objects with a +"tck" name prefix. =20 -To repeat: ALL YOUR EXISTING DOMAINS, NETWORKS, STORAGE POOLS -WILL BE DELETED IF YOU USE THE --force OPTION. +Where a test suite needs access to a precious host resource (physical +NIC, PCI device, USB device, block device), execution will be skipped +until the admin has white listed one or more suitable resources in +the C configuration file. =20 -The warning is now complete, continue reading +Despite these precautions, running automated tests always carries some +degree of risk to the host system. It is thus advisable to avoid +executing this test suite on hosts with precious state. =20 =3Dhead2 OPTIONS =20 @@ -90,13 +92,11 @@ C option generates a formal XML document of result= s. =20 =3Ditem --force =20 -Forcably remove all running guest domains and all persistent guest -domain configuration files before running any tests. The test suite -requires a pristine install, so all existing managed objects must -be removed before running. This switch will instruct libvirt-tck -to automatically remove all guest domains. YOU WILL NOT GET YOUR -EXISTING GUEST DOMAINS BACK IF THIS HAPPENS. THEY WILL BE GONE -FOREVER. USE AT YOUR OWN RISK. +Forcably remove all previously created objects, including guests, +networks, storage pools, etc which have a "tck" name prefix. + +User created objects whose name does not start with "tck" will be +left untouched. =20 =3Ditem -t, --testdir PATH =20 --=20 2.19.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue Apr 16 23:59:33 2024 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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1541175450053562.2951843230474; Fri, 2 Nov 2018 09:17:30 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EF031307DAA5; Fri, 2 Nov 2018 16:17:27 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B19CC60BE8; Fri, 2 Nov 2018 16:17:27 +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 5968719748; Fri, 2 Nov 2018 16:17:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wA2FqGWf013202 for ; Fri, 2 Nov 2018 11:52:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id B157E600D1; Fri, 2 Nov 2018 15:52:16 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-64.ams2.redhat.com [10.36.112.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 863ED600CD; Fri, 2 Nov 2018 15:52:15 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 2 Nov 2018 15:52:09 +0000 Message-Id: <20181102155209.1331-4-berrange@redhat.com> In-Reply-To: <20181102155209.1331-1-berrange@redhat.com> References: <20181102155209.1331-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [tck PATCH 3/3] Allow tests to be listed as positional arguments 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: , Content-Type: text/plain; charset="utf-8" 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 02 Nov 2018 16:17:28 +0000 (UTC) The -t argument accepts the path to a test file or a test directory. It would be useful if shell wildcards could be used to specify test files, but this doesn't work when using optional arguments. By changing the test path(s) to be positional arguments we can easily allow for shell wildcards. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- bin/libvirt-tck | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/bin/libvirt-tck b/bin/libvirt-tck index d5519dd..bd332a4 100644 --- a/bin/libvirt-tck +++ b/bin/libvirt-tck @@ -8,7 +8,7 @@ libvirt-tck - libvirt Technology Compatability Kit =20 =3Dhead1 SYNOPSIS =20 - # libvirt-tck [OPTIONS] + # libvirt-tck [OPTIONS] [TESTS..] =20 Run with default config, probing for URI to use =20 @@ -62,8 +62,15 @@ the default configuration file from C and will allow libvirt to probe for the hypervisor driver to run. If a reliably repeatable test result set is desired, it is recommended to always give an explicit libvirt connection URI -to choose the driver. The following options are available when -running the C command +to choose the driver. + +Any command line arguments that are not parsed as options will +be considered paths to test scripts to invoke. If no paths are +given, all tests under C will be +executed. + +The following options are available when running the C +command =20 =3Dover 4 =20 @@ -98,11 +105,6 @@ networks, storage pools, etc which have a "tck" name pr= efix. User created objects whose name does not start with "tck" will be left untouched. =20 -=3Ditem -t, --testdir PATH - -Specify an alternate directory path in which to find the test -scripts to be run. If omitted, defaults to C - =3Ditem -a, --archive FILE =20 Generate an archive containing all the raw test results. The @@ -144,7 +146,6 @@ my $timer =3D 0; my $archive; my $config =3D catfile($confdir, "default.cfg"); my $format =3D "text"; -my $testdir =3D catdir($datadir, "tests"); =20 if (!GetOptions("verbose" =3D> \$verbose, "debug" =3D> \$debug, @@ -154,7 +155,6 @@ if (!GetOptions("verbose" =3D> \$verbose, "config=3Ds" =3D> \$config, "force" =3D> \$force, "format=3Ds" =3D> \$format, - "testdir=3Ds" =3D> \$testdir, "timer" =3D> \$timer) || $help) { pod2usage(-verbose =3D> $help, -output =3D> $help ? \*STDOUT : \*STDERR, @@ -181,12 +181,19 @@ if ($verbose && $quiet) { -output =3D> \*STDERR); } =20 -unless (-e $testdir) { - print STDERR "$0: test directory '$testdir' does not exist\n"; - exit 2; +my @testdirs =3D @ARGV; +unless (@testdirs) { + push @testdirs, catdir($datadir, "tests"); +} + +foreach (@testdirs) { + unless (-e $_) { + print STDERR "$0: test path '$_' does not exist\n"; + exit 2; + } } =20 -my @newargv =3D ("-r", "--norc", "--merge", $testdir); +my @newargv =3D ("-r", "--norc", "--merge", @testdirs); =20 if ($archive) { push @newargv, "-a", $archive; --=20 2.19.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list