From nobody Tue May 7 09:01:13 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 155120447869723.34854634244391; Tue, 26 Feb 2019 10:07:58 -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 95D693091761; Tue, 26 Feb 2019 18:07:56 +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 727DB5D9CC; Tue, 26 Feb 2019 18:07:56 +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 2E12E41F3D; Tue, 26 Feb 2019 18:07:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1QI7sMr007419 for ; Tue, 26 Feb 2019 13:07:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id 69D1E60BFC; Tue, 26 Feb 2019 18:07:54 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-70.ams2.redhat.com [10.36.112.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id ACE3760BFB; Tue, 26 Feb 2019 18:07:46 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 26 Feb 2019 18:07:45 +0000 Message-Id: <20190226180745.31154-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [tck PATCH] Add script testing network bandwidth functionality 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.41]); Tue, 26 Feb 2019 18:07:57 +0000 (UTC) Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Laine Stump --- lib/Sys/Virt/TCK/DomainBuilder.pm | 10 ++ lib/Sys/Virt/TCK/NetworkBuilder.pm | 20 ++++ scripts/networks/400-guest-bandwidth.t | 147 +++++++++++++++++++++++++ 3 files changed, 177 insertions(+) create mode 100644 scripts/networks/400-guest-bandwidth.t diff --git a/lib/Sys/Virt/TCK/DomainBuilder.pm b/lib/Sys/Virt/TCK/DomainBui= lder.pm index 399534c..45336b5 100644 --- a/lib/Sys/Virt/TCK/DomainBuilder.pm +++ b/lib/Sys/Virt/TCK/DomainBuilder.pm @@ -466,6 +466,16 @@ sub as_xml { $w->emptyTag("model", type =3D> $interface->{model}); } + if ($interface->{bandwidth}) { + $w->startTag("bandwidth"); + if ($interface->{bandwidth}->{"in"}) { + $w->emptyTag("inbound", %{$interface->{bandwidth}->{"in"}}); + } + if ($interface->{bandwidth}->{"out"}) { + $w->emptyTag("outbound", %{$interface->{bandwidth}->{"out"}}); + } + $w->endTag("bandwidth"); + } if ($interface->{filterref}) { $w->startTag("filterref", filter =3D> $interface->{filterref}); diff --git a/lib/Sys/Virt/TCK/NetworkBuilder.pm b/lib/Sys/Virt/TCK/NetworkB= uilder.pm index ad0cab8..446cc4f 100644 --- a/lib/Sys/Virt/TCK/NetworkBuilder.pm +++ b/lib/Sys/Virt/TCK/NetworkBuilder.pm @@ -87,6 +87,15 @@ sub ipaddr { return $self; } =20 +sub bandwidth { + my $self =3D shift; + my %bw =3D @_; + + $self->{bandwidth} =3D \%bw; + + return $self; +} + sub dhcp_range { my $self =3D shift; my $start =3D shift; @@ -114,6 +123,17 @@ sub as_xml { $w->emptyTag("bridge", %{$self->{bridge}}) if $self->{bridge}; =20 + if ($self->{bandwidth}) { + $w->startTag("bandwidth"); + if ($self->{bandwidth}->{"in"}) { + $w->emptyTag("inbound", %{$self->{bandwidth}->{"in"}}); + } + if ($self->{bandwidth}->{"out"}) { + $w->emptyTag("outbound", %{$self->{bandwidth}->{"out"}}); + } + $w->endTag("bandwidth"); + } + if (exists $self->{forward}) { $w->startTag("forward", %{$self->{forward}}); foreach (@{$self->{interfaces}}) { diff --git a/scripts/networks/400-guest-bandwidth.t b/scripts/networks/400-= guest-bandwidth.t new file mode 100644 index 0000000..3a865fd --- /dev/null +++ b/scripts/networks/400-guest-bandwidth.t @@ -0,0 +1,147 @@ +# -*- perl -*- +# +# Copyright (C) 2019 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/400-guest-bandwidth.t - guest with bandwidth limits + +=3Dhead1 DESCRIPTION + +This test case validates that a guest is connected a network +can have bandwidth limits set + +=3Dcut + +use strict; +use warnings; + +use Test::More tests =3D> 8; +use Test::Exception; + +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 $netbuilder =3D Sys::Virt::TCK::NetworkBuilder->new(name =3D> "tck"= ); + $netbuilder->bridge("tck"); + $netbuilder->ipaddr($subnet{address}, $subnet{netmask}); + $netbuilder->dhcp_range($subnet{dhcpstart}, $subnet{dhcpend}); + my $netxml =3D $netbuilder->as_xml(); + + diag "Creating a new transient network"; + diag $netxml; + my $net; + ok_network(sub { $net =3D $conn->create_network($netxml) }, "created t= ransient network object"); + + my $dombuilder =3D $tck->generic_domain(name =3D> "tck"); + $dombuilder->interface(type =3D> "network", + source =3D> "tck", + model =3D> "virtio", + mac =3D> "52:54:00:11:11:11", + bandwidth =3D> { + in =3D> { + average =3D> 1000, + peak =3D> 5000, + floor =3D> 2000, + burst =3D> 1024, + }, + out =3D> { + average =3D> 128, + peak =3D> 256, + burst =3D> 256, + }, + }); + my $domxml =3D $dombuilder->as_xml(); + + diag "Creating a new transient domain"; + diag $domxml; + my $dom; + ok_error(sub { $dom =3D $conn->create_domain($domxml) }, "Unsupported = op requesting bandwidth", + Sys::Virt::Error::ERR_OPERATION_UNSUPPORTED); + + diag "Destroying the transient network"; + $net->destroy; + + $netbuilder->bandwidth( + in =3D> { + average =3D> 1000, + peak =3D> 5000, + burst =3D> 1024, + }, + out =3D> { + average =3D> 128, + peak =3D> 256, + burst =3D> 256, + }); + + $netxml =3D $netbuilder->as_xml(); + + diag "Creating a new transient network"; + diag $netxml; + ok_network(sub { $net =3D $conn->create_network($netxml) }, "created t= ransient network object"); + + ok_domain(sub { $dom =3D $conn->create_domain($domxml) }, "created tra= nsient domain object"); + + lives_ok(sub { + $dom->set_interface_parameters( + "52:54:00:11:11:11", + { + Sys::Virt::Domain::BANDWIDTH_IN_AVERAGE =3D> 1000, + Sys::Virt::Domain::BANDWIDTH_IN_PEAK =3D> 5000, + Sys::Virt::Domain::BANDWIDTH_IN_FLOOR =3D> 4000, + Sys::Virt::Domain::BANDWIDTH_IN_BURST =3D> 1024, + Sys::Virt::Domain::BANDWIDTH_OUT_AVERAGE =3D> 128, + Sys::Virt::Domain::BANDWIDTH_OUT_PEAK =3D> 256, + Sys::Virt::Domain::BANDWIDTH_OUT_BURST =3D> 256, + })}); + =20 + ok_error(sub { + $dom->set_interface_parameters( + "52:54:00:11:11:11", + { + Sys::Virt::Domain::BANDWIDTH_IN_AVERAGE =3D> 1000, + Sys::Virt::Domain::BANDWIDTH_IN_PEAK =3D> 5000, + Sys::Virt::Domain::BANDWIDTH_IN_FLOOR =3D> 40000, + Sys::Virt::Domain::BANDWIDTH_IN_BURST =3D> 1024, + Sys::Virt::Domain::BANDWIDTH_OUT_AVERAGE =3D> 128, + Sys::Virt::Domain::BANDWIDTH_OUT_PEAK =3D> 256, + Sys::Virt::Domain::BANDWIDTH_OUT_BURST =3D> 256, + }) }, "Canot overcommit bandwidth", + Sys::Virt::Error::ERR_OPERATION_INVALID); + =20 + 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 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list