summaryrefslogtreecommitdiff
path: root/source4/selftest/target/Kvm.pm
blob: 74b726d1830a097f7a889fc7d4d059099037cc3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/perl
# Start a KVM machine and run a number of tests against it.
# Copyright (C) 2005-2008 Jelmer Vernooij <jelmer@samba.org>
# Published under the GNU GPL, v3 or later.

package Kvm;

use strict;
use Cwd qw(abs_path);
use FindBin qw($RealBin);
use POSIX;

sub new($$$$) {
	my ($classname, $image) = @_;
	my $self = { 
		image => $image
	};
	bless $self;
	return $self;
}

sub teardown_env($$)
{
	my ($self, $envvars) = @_;

	return 0;
}

sub getlog_env($$)
{
	my ($self, $envvars) = @_;

	return "";
}

sub check_env($$)
{
	my ($self, $envvars) = @_;

	return 1;
}

sub start($)
{
	my ($self) = @_;

	my $pidfile = "kvm.pid";

	my $opts = ($ENV{KVM_OPTIONS} or "");

	system("kvm $opts -daemonize -pidfile $pidfile -vnc unix:kvm.vnc -snapshot $self->{image}");

	open(PID, $pidfile);
	$self->{pid} = <PID>;
	close(PID);
}

sub setup_env($$$)
{
	my ($self, $envname, $path) = @_;

	if ($envname eq "dc") {
		unless (defined($self->{pid})) {
			$self->start();
		}
	} elsif ($envname eq "member") {
		return undef;
	}

	die("No implemented yet");
}

sub stop($)
{
	my ($self) = @_;

	kill $self->{pid};
}

1;