
On Mon, Oct 18, 2010 at 07:18:08AM +0800, Osier Yang wrote:
To test daemon, qemu, lxc hook.
* lib/Sys/Virt/TCK/Hooks.pm --- lib/Sys/Virt/TCK/Hooks.pm | 262 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 262 insertions(+), 0 deletions(-) create mode 100644 lib/Sys/Virt/TCK/Hooks.pm
diff --git a/lib/Sys/Virt/TCK/Hooks.pm b/lib/Sys/Virt/TCK/Hooks.pm
+sub libvirtd_status { + my $self = shift; + my $status = `service libvirtd status`; + my $_ = $status; + + if (/running/) { + $self->{libvirtd_status} = 'running'; + } elsif (/stopped/) { + $self->{libvirtd_status} = 'stopped'; + } + + return $self; +}
+sub service_libvirtd { + my $self = shift; + my $action = $self->{action}; + + truncate $self->{log_name}, 0 if -f $self->{log_name}; + + die "failed on $action daemon" if system "service libvirtd $action"; + + $self->libvirtd_status; +}
Is there any way we can avoid having to start/stop libvirtd for this testing ? The general goal of the TCK is that it is testing an existing deployment, so it should be expecting that libvirtd is already up & running in a desired configuration. If we have to stop/start libvirtd, then the test script using these APIs will need to be protected to make sure it only runs when used with 'qemu:///system' or 'lxc://'. ie is skipped with qemu:///session or vmware, or virtualbox, etc
+ +sub compare_log { + my $self = shift; + + my $expect_log = $self->{expect_log}; + my $log_name = $self->{log_name}; + + open LOG, "< $log_name" or die "failed on opening $log_name: $!"; + + my @lines = <LOG>; + + return 0 unless @lines; + + chomp foreach @lines; + my $actual_log = join "\n", @lines; + + close LOG;
Little perl black magic tip for you.... If you want to read the entire file contents into a single string, then you can do open LOG, "<$log_name"; local $/ = undef; my $actual_log = <LOG>; close LOG; '$/' is the line separator. By setting it to 'undef' we tell Perl that there is no line separator, so it will immediately read until end of file :-) BTW see 'man perlvar' for this particular example 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 :|