Commit 0a812bf2 authored by Laine Stump's avatar Laine Stump

Don't assume the domain's network interface tap device is named "vnet0"

Some of the tests perform operations on the tap device of the test
domain's network interface. They mostly assume that this tap device is
named "vnet0", which is the case if there is no other domain running
on the host, but isn't true if some other domain was running.

This patch adds a utility function
NetworkHelpers::get_first_interface_target_dev($dom), which learns the
name of the tap device for the first interface in the domain, and uses
the result of that function instead of "vnet0".
Signed-off-by: 's avatarLaine Stump <laine@laine.org>
Reviewed-by: 's avatarDaniel P. Berrangé <berrange@redhat.com>
parent 72dbbd39
......@@ -821,11 +821,12 @@ sub generic_machine_domain {
$dom->create();
# Wait for the first boot to reach network setting
my $iface = get_first_interface_target_dev($dom);
my $stats;
my $tries = 0;
do {
sleep(10);
$stats = $dom->interface_stats("vnet0");
$stats = $dom->interface_stats($iface);
$tries++;
} while ($stats->{"tx_packets"} < 10 && $tries < 10);
......
......@@ -10,6 +10,12 @@ sub get_first_macaddress {
return $mac;
}
sub get_first_interface_target_dev {
my $dom = shift;
my $targetdev = xpath($dom, "string(/domain/devices/interface[1]/target/\@dev)");
return $targetdev;
}
sub get_network_ip {
my $conn = shift;
my $netname = shift;
......
......@@ -33,6 +33,7 @@ use warnings;
use Test::More tests => 10;
use Sys::Virt::TCK;
use Sys::Virt::TCK::NetworkHelpers;
use Test::Exception;
use File::stat;
......@@ -59,12 +60,13 @@ diag "Set/Get interface parameters";
my %params = (Sys::Virt::Domain::BANDWIDTH_IN_AVERAGE=>1000, Sys::Virt::Domain::BANDWIDTH_IN_PEAK=>1001,
Sys::Virt::Domain::BANDWIDTH_IN_BURST=>1002, Sys::Virt::Domain::BANDWIDTH_OUT_AVERAGE=>1003,
Sys::Virt::Domain::BANDWIDTH_OUT_PEAK=>1004, Sys::Virt::Domain::BANDWIDTH_OUT_BURST=>1005);
lives_ok(sub {$dom->set_interface_parameters("vnet0", \%params)}, "Set vnet0 parameters");
my $iface = get_first_interface_target_dev($dom);
lives_ok(sub {$dom->set_interface_parameters($iface, \%params)}, "Set $iface parameters");
for my $key (sort keys %params) {
diag "Set $key => $params{$key} ";
}
my $param = $dom->get_interface_parameters("vnet0", 0);
my $param = $dom->get_interface_parameters($iface, 0);
my $in_average = $param->{Sys::Virt::Domain::BANDWIDTH_IN_AVERAGE};
my $in_burst = $param->{Sys::Virt::Domain::BANDWIDTH_IN_BURST};
my $in_peak = $param->{Sys::Virt::Domain::BANDWIDTH_IN_PEAK};
......
......@@ -55,11 +55,12 @@ $dom->create;
ok($dom->get_id() > 0, "running domain has an ID > 0");
diag "Waiting for guest to finish booting";
my $iface = get_first_interface_target_dev($dom);
my $stats;
my $tries = 0;
do {
sleep(10);
$stats = $dom->interface_stats("vnet0");
$stats = $dom->interface_stats($iface);
$tries++;
} while ($stats->{"tx_packets"} < 10 && $tries < 10);
......
......@@ -59,11 +59,12 @@ $dom->create;
ok($dom->get_id() > 0, "running domain has an ID > 0");
diag "Waiting for guest to finish booting";
my $iface = get_first_interface_target_dev($dom);
my $stats;
my $tries = 0;
do {
sleep(10);
$stats = $dom->interface_stats("vnet0");
$stats = $dom->interface_stats($iface);
$tries++;
} while ($stats->{"tx_packets"} < 10 && $tries < 10);
......
......@@ -85,11 +85,12 @@ $dom->create;
ok($dom->get_id() > 0, "running domain has an ID > 0");
diag "Waiting for guest to finish booting";
my $iface = get_first_interface_target_dev($dom);
my $stats;
my $tries = 0;
do {
sleep(10);
$stats = $dom->interface_stats("vnet0");
$stats = $dom->interface_stats($iface);
$tries++;
} while ($stats->{"tx_packets"} < 10 && $tries < 10);
......
......@@ -58,11 +58,12 @@ $dom->create;
ok($dom->get_id() > 0, "running domain has an ID > 0");
diag "Waiting for guest to finish booting";
my $iface = get_first_interface_target_dev($dom);
my $stats;
my $tries = 0;
do {
sleep(10);
$stats = $dom->interface_stats("vnet0");
$stats = $dom->interface_stats($iface);
$tries++;
} while ($stats->{"tx_packets"} < 10 && $tries < 10);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment