Hi all,
Here are a few patches to get the TCK run properly against opensuse image.
The patch adding the opensuse images to virt-builder is still pending, but
the main issues were:
* Waiting for 30 seconds for the guest to be started is pretty fragile.
For the tests pinging the guest, wait for domifstats to report 10 sent
packets.
* The first boot of the opensuse image runs dracut and takes quite a long
time. We need to wait for the first boot to complete before shutting
down the guest to avoid inconsistent states.
* Yum isn't in all distros by default you know ;)
diff to v1:
* set the proper email address
Cédric Bosdonnat (5):
Ping test: use domifstats to wait for dhcp to be setup in guest
Create has_disk_image from code of get_virt_builder_disk
Add DomainBuilder->rminterface function.
Make sure the image has been started properly started the first time.
240-no-arp-spoofing.t: get virt-builder install dsniff
lib/Sys/Virt/TCK.pm | 54 +++++++++++++++++++++++++++++--
lib/Sys/Virt/TCK/DomainBuilder.pm | 7 ++++
scripts/nwfilter/100-ping-still-working.t | 13 ++++++--
scripts/nwfilter/210-no-mac-spoofing.t | 13 ++++++--
scripts/nwfilter/230-no-mac-broadcast.t | 13 ++++++--
scripts/nwfilter/240-no-arp-spoofing.t | 14 ++++++--
6 files changed, 103 insertions(+), 11 deletions(-)
--
2.1.4
Show replies by date
Some guests may be slower to start than 30 seconds. Use domifstats
to wait for 10 packets to be sent by the guest (usually the DHCP ones
are the first ones).
---
scripts/nwfilter/100-ping-still-working.t | 13 +++++++++++--
scripts/nwfilter/210-no-mac-spoofing.t | 13 +++++++++++--
scripts/nwfilter/230-no-mac-broadcast.t | 13 +++++++++++--
scripts/nwfilter/240-no-arp-spoofing.t | 13 +++++++++++--
4 files changed, 44 insertions(+), 8 deletions(-)
diff --git a/scripts/nwfilter/100-ping-still-working.t
b/scripts/nwfilter/100-ping-still-working.t
index f65bf37..a20b95d 100644
--- a/scripts/nwfilter/100-ping-still-working.t
+++ b/scripts/nwfilter/100-ping-still-working.t
@@ -54,8 +54,17 @@ diag "Start domain";
$dom->create;
ok($dom->get_id() > 0, "running domain has an ID > 0");
-diag "Waiting 30 seconds for guest to finish booting";
-sleep(30);
+diag "Waiting for guest to finish booting";
+my $stats;
+my $tries = 0;
+do {
+ sleep(10);
+ $stats = $dom->interface_stats("vnet0");
+ $tries++;
+} while ($stats->{"tx_packets"} < 10 && $tries < 10);
+
+# Wait a little bit more to make sure dhcp is started in the guest
+sleep(10);
my $mac = get_first_macaddress($dom);
diag "mac is $mac";
diff --git a/scripts/nwfilter/210-no-mac-spoofing.t
b/scripts/nwfilter/210-no-mac-spoofing.t
index 7e80216..b81fc4a 100644
--- a/scripts/nwfilter/210-no-mac-spoofing.t
+++ b/scripts/nwfilter/210-no-mac-spoofing.t
@@ -53,8 +53,17 @@ diag "Start domain";
$dom->create;
ok($dom->get_id() > 0, "running domain has an ID > 0");
-diag "Waiting 30 seconds for guest to finish booting";
-sleep(30);
+diag "Waiting for guest to finish booting";
+my $stats;
+my $tries = 0;
+do {
+ sleep(10);
+ $stats = $dom->interface_stats("vnet0");
+ $tries++;
+} while ($stats->{"tx_packets"} < 10 && $tries < 10);
+
+# Wait a little bit more to make sure dhcp is started in the guest
+sleep(10);
# ping guest first nic
my $mac = get_first_macaddress($dom);
diff --git a/scripts/nwfilter/230-no-mac-broadcast.t
b/scripts/nwfilter/230-no-mac-broadcast.t
index 2e616d6..16ce60d 100644
--- a/scripts/nwfilter/230-no-mac-broadcast.t
+++ b/scripts/nwfilter/230-no-mac-broadcast.t
@@ -52,8 +52,17 @@ diag "Start domain";
$dom->create;
ok($dom->get_id() > 0, "running domain has an ID > 0");
-diag "Waiting 30 seconds for guest to finish booting";
-sleep(30);
+diag "Waiting for guest to finish booting";
+my $stats;
+my $tries = 0;
+do {
+ sleep(10);
+ $stats = $dom->interface_stats("vnet0");
+ $tries++;
+} while ($stats->{"tx_packets"} < 10 && $tries < 10);
+
+# Wait a little bit more to make sure dhcp is started in the guest
+sleep(10);
# ping guest first nic
my $mac = get_first_macaddress($dom);
diff --git a/scripts/nwfilter/240-no-arp-spoofing.t
b/scripts/nwfilter/240-no-arp-spoofing.t
index 596a0ce..6b346aa 100644
--- a/scripts/nwfilter/240-no-arp-spoofing.t
+++ b/scripts/nwfilter/240-no-arp-spoofing.t
@@ -54,8 +54,17 @@ diag "Start domain";
$dom->create;
ok($dom->get_id() > 0, "running domain has an ID > 0");
-diag "Waiting 30 seconds for guest to finish booting";
-sleep(30);
+diag "Waiting for guest to finish booting";
+my $stats;
+my $tries = 0;
+do {
+ sleep(10);
+ $stats = $dom->interface_stats("vnet0");
+ $tries++;
+} while ($stats->{"tx_packets"} < 10 && $tries < 10);
+
+# Wait a little bit more to make sure dhcp is started in the guest
+sleep(10);
# ping guest first nic
my $mac = get_first_macaddress($dom);
--
2.1.4
This function will later be reused to check if a first boot is needed.
---
lib/Sys/Virt/TCK.pm | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/lib/Sys/Virt/TCK.pm b/lib/Sys/Virt/TCK.pm
index a3d06a2..04bdbf4 100644
--- a/lib/Sys/Virt/TCK.pm
+++ b/lib/Sys/Virt/TCK.pm
@@ -375,6 +375,19 @@ sub create_sparse_disk {
}
+sub has_disk_image {
+ my $self = shift;
+ my $bucket = shift;
+ my $name = shift;
+ my $osname = shift;
+
+ my $dir = $self->bucket_dir($bucket);
+
+ my $target = catfile($dir, $name);
+
+ return -f $target
+}
+
sub create_virt_builder_disk {
my $self = shift;
my $bucket = shift;
@@ -387,7 +400,7 @@ sub create_virt_builder_disk {
my $password = $self->root_password;
- if (-f $target) {
+ if ($self->has_disk_image($bucket, $name, $osname)) {
return $target;
}
--
2.1.4
---
lib/Sys/Virt/TCK/DomainBuilder.pm | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/lib/Sys/Virt/TCK/DomainBuilder.pm b/lib/Sys/Virt/TCK/DomainBuilder.pm
index 7a20008..e9453ee 100644
--- a/lib/Sys/Virt/TCK/DomainBuilder.pm
+++ b/lib/Sys/Virt/TCK/DomainBuilder.pm
@@ -271,6 +271,13 @@ sub disk {
return $self;
}
+
+sub rminterface {
+ my $self = shift;
+
+ return pop @{$self->{interfaces}};
+}
+
sub interface {
my $self = shift;
my %params = @_;
--
2.1.4
openSUSE images have a special first boot generating initrd and grub.cfg
according to get rid of the generic one. To ensure this runs properly,
force a first boot right after having generated the disk image.
---
lib/Sys/Virt/TCK.pm | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/lib/Sys/Virt/TCK.pm b/lib/Sys/Virt/TCK.pm
index 04bdbf4..f6fce93 100644
--- a/lib/Sys/Virt/TCK.pm
+++ b/lib/Sys/Virt/TCK.pm
@@ -738,6 +738,7 @@ sub get_image {
my $bucket = "os-$arch-$ostype";
+ my $needs_firstboot = ! $self->has_disk_image($bucket,
"disk-$osname.img", $osname);
my $dfile = $self->create_virt_builder_disk($bucket, "disk-$osname.img",
$osname);
my $dev = $self->get_disk_dev($ostype, $domain);
@@ -750,6 +751,7 @@ sub get_image {
loader => $loader,
root => $dfile,
dev => $dev,
+ firstboot => $needs_firstboot,
);
}
@@ -785,6 +787,41 @@ sub generic_machine_domain {
$b->disk(src => $config{root},
dst => $config{dev},
type => "file");
+
+ if ($config{firstboot}) {
+ print "# Running the first boot\n";
+
+ $b->interface(type => "network",
+ source => "default",
+ mac => "52:54:00:11:11:11",
+ filterref => "clean-traffic");
+ my $xml = $b->as_xml();
+ # Cleanup the temporary interface
+ $b->rminterface();
+
+ my $dom = $self->conn->define_domain($xml);
+ $dom->create();
+
+ # Wait for the first boot to reach network setting
+ my $stats;
+ my $tries = 0;
+ do {
+ sleep(10);
+ $stats = $dom->interface_stats("vnet0");
+ $tries++;
+ } while ($stats->{"tx_packets"} < 10 && $tries < 10);
+
+ # Safe to shutdown domain now
+ my $target = time() + 30;
+ $dom->shutdown;
+ while ($dom->is_active()) {
+ sleep(1);
+ $dom->destroy() if time() > $target;
+ }
+ sleep(1);
+ $dom->undefine();
+ }
+
return $b;
} else {
my %config = $self->get_kernel($caps, $ostype);
--
2.1.4
We can't be sure the guest will have yum installed as package manager.
Thus delegate the dsniff package install to virt-builder as it provides
an abstraction for that.
---
lib/Sys/Virt/TCK.pm | 2 +-
scripts/nwfilter/240-no-arp-spoofing.t | 1 -
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/lib/Sys/Virt/TCK.pm b/lib/Sys/Virt/TCK.pm
index f6fce93..5d9378d 100644
--- a/lib/Sys/Virt/TCK.pm
+++ b/lib/Sys/Virt/TCK.pm
@@ -405,7 +405,7 @@ sub create_virt_builder_disk {
}
print "# running virt-builder $osname\n";
- `virt-builder --root-password 'password:$password' --output $target
$osname`;
+ `virt-builder --install dsniff --root-password 'password:$password' --output
$target $osname`;
return $target;
}
diff --git a/scripts/nwfilter/240-no-arp-spoofing.t
b/scripts/nwfilter/240-no-arp-spoofing.t
index 6b346aa..284033d 100644
--- a/scripts/nwfilter/240-no-arp-spoofing.t
+++ b/scripts/nwfilter/240-no-arp-spoofing.t
@@ -92,7 +92,6 @@ $ssh->login("root", $tck->root_password());
# now generate a arp spoofing packets
diag "generate arpspoof";
my $cmdfile = <<EOF;
-echo '/usr/bin/yum -y install dsniff
/usr/sbin/arpspoof ${spoofid} &
/bin/sleep 10
kill -15 `/sbin/pidof arpspoof`' > /test.sh
--
2.1.4