[libvirt] question about libvirt-tck/libivrt-perl

Hi, I have a small libvirt-TCK script, which fails in a for me unexpected way: ########################################################## use strict; use warnings; use Term::ReadKey; use Test::More tests => 4; use Sys::Virt::TCK; my $tck = Sys::Virt::TCK->new(); my $conn = eval { $tck->setup(); }; BAIL_OUT "failed to setup test harness: $@" if $@; END { $tck->cleanup if $tck; } # first domain my $xml = $tck->generic_domain("tck")->as_xml; my $dom; ok_domain(sub { $dom = $conn->create_domain($xml) }, "defined domain config"); my $uuid = $dom->get_uuid_string(); diag $uuid; $xml = $dom->get_xml_description; diag "Starting inactive domain config"; ok($dom->get_id() > 0, "running domain has an ID > 0"); $dom->destroy; # new domain my $newxml = $tck->generic_domain("tck")->as_xml; my $newdom; ok_domain(sub { $newdom = $conn->create_domain($newxml) }, "defined domain config"); my $newuuid = $newdom->get_uuid_string(); diag $newuuid; $newxml = $newdom->get_xml_description(); ok($newdom->get_id() > 0, "running domain has an ID > 0"); $newdom->destroy; ########################################################## scripts/network/001-prepare-image.t .. 1..4 ok 1 - defined domain config # 4317db52-00bb-3cac-5639-91cdce05a717 # Starting inactive domain config ok 2 - running domain has an ID > 0 ok 3 - defined domain config # 4317db52-00bb-3cac-5639-91cdce05a717 libvirt error code: 42, message: Domain not found: no domain with matching uuid '4317db52-00bb-3cac-5639-91cdce05a717' # Looks like you planned 4 tests but ran 3. # Looks like your test exited with 255 just after 3. Dubious, test returned 255 (wstat 65280, 0xff00) Failed 1/4 subtests Test Summary Report ------------------- scripts/network/001-prepare-image.t (Wstat: 65280 Tests: 3 Failed: 0) Non-zero exit status: 255 Parse errors: Bad plan. You planned 4 tests but ran 3. Files=1, Tests=3, 1 wallclock secs ( 0.02 usr 0.01 sys + 0.19 cusr 0.04 csys = 0.26 CPU) Result: FAIL ########################################################## If I change my $newxml = $tck->generic_domain("tck")->as_xml; to my $newxml = $tck->generic_domain("tck2")->as_xml; the script works as expected. I am wondering if this is a problem in the libvirt-perl wrapper or working as designed and my expectation is simply wrong? Thanks in advance... -- Best regards, Gerhard Stenzel, ----------------------------------------------------------------------------------------------------------------------------------- IBM Deutschland Research & Development GmbH Vorsitzender des Aufsichtsrats: Martin Jetter Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen Registergericht: Amtsgericht Stuttgart, HRB 243294

On Mon, Apr 12, 2010 at 03:41:44PM +0200, Gerhard Stenzel wrote:
Hi, I have a small libvirt-TCK script, which fails in a for me unexpected way: ########################################################## use strict; use warnings;
use Term::ReadKey;
use Test::More tests => 4;
use Sys::Virt::TCK;
my $tck = Sys::Virt::TCK->new(); my $conn = eval { $tck->setup(); }; BAIL_OUT "failed to setup test harness: $@" if $@; END { $tck->cleanup if $tck; }
# first domain my $xml = $tck->generic_domain("tck")->as_xml; my $dom; ok_domain(sub { $dom = $conn->create_domain($xml) }, "defined domain config"); my $uuid = $dom->get_uuid_string(); diag $uuid; $xml = $dom->get_xml_description;
diag "Starting inactive domain config"; ok($dom->get_id() > 0, "running domain has an ID > 0"); $dom->destroy;
# new domain my $newxml = $tck->generic_domain("tck")->as_xml;
my $newdom; ok_domain(sub { $newdom = $conn->create_domain($newxml) }, "defined domain config"); my $newuuid = $newdom->get_uuid_string(); diag $newuuid; $newxml = $newdom->get_xml_description();
ok($newdom->get_id() > 0, "running domain has an ID > 0"); $newdom->destroy; ##########################################################
scripts/network/001-prepare-image.t .. 1..4 ok 1 - defined domain config # 4317db52-00bb-3cac-5639-91cdce05a717 # Starting inactive domain config ok 2 - running domain has an ID > 0 ok 3 - defined domain config # 4317db52-00bb-3cac-5639-91cdce05a717 libvirt error code: 42, message: Domain not found: no domain with matching uuid '4317db52-00bb-3cac-5639-91cdce05a717'
########################################################## If I change my $newxml = $tck->generic_domain("tck")->as_xml; to my $newxml = $tck->generic_domain("tck2")->as_xml; the script works as expected.
I am wondering if this is a problem in the libvirt-perl wrapper or working as designed and my expectation is simply wrong?
It is a subtle issue crossing several layers. libvirt internally caches virDomainPtr instances based on name. You created a object in the perl layer '$dom' with the name, and then you create a new instance with the same name, but assign to a diferent perl object '$newdom'. This means that the old virDomainPtr associated with $dom still exists. If you explicitly set '$dom = undef' before creating the second domain you should release the old handle & make it all work as expected Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On Mon, 2010-04-12 at 15:21 +0100, Daniel P. Berrange wrote:
It is a subtle issue crossing several layers. libvirt internally caches virDomainPtr instances based on name. You created a object in the perl layer '$dom' with the name, and then you create a new instance with the same name, but assign to a diferent perl object '$newdom'. This means that the old virDomainPtr associated with $dom still exists. If you explicitly set '$dom = undef' before creating the second domain you should release the old handle & make it all work as expected
thanks for the explanation .. my script now works as expected. BTW, additional test cases for libvirt-TCK should be send as patches to this list, correct? -- Best regards, Gerhard Stenzel, ----------------------------------------------------------------------------------------------------------------------------------- IBM Deutschland Research & Development GmbH Vorsitzender des Aufsichtsrats: Martin Jetter Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen Registergericht: Amtsgericht Stuttgart, HRB 243294

On Mon, Apr 12, 2010 at 04:56:19PM +0200, Gerhard Stenzel wrote:
On Mon, 2010-04-12 at 15:21 +0100, Daniel P. Berrange wrote:
It is a subtle issue crossing several layers. libvirt internally caches virDomainPtr instances based on name. You created a object in the perl layer '$dom' with the name, and then you create a new instance with the same name, but assign to a diferent perl object '$newdom'. This means that the old virDomainPtr associated with $dom still exists. If you explicitly set '$dom = undef' before creating the second domain you should release the old handle & make it all work as expected
thanks for the explanation .. my script now works as expected.
BTW, additional test cases for libvirt-TCK should be send as patches to this list, correct?
Yes, use this list for patches against any of the repositories hosted on libvirt.org, with exception of CIM provider code which has a separate dedicated list. Regards, Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On 04/12/2010 08:56 AM, Gerhard Stenzel wrote:
BTW, additional test cases for libvirt-TCK should be send as patches to this list, correct?
Yes. For that matter, we could probably also patch the web page documentation to more prominently mention libvirt-tck.git. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
participants (3)
-
Daniel P. Berrange
-
Eric Blake
-
Gerhard Stenzel