2 # Start a KVM machine and run a number of tests against it.
3 # Copyright (C) 2005-2008 Jelmer Vernooij <jelmer@samba.org>
4 # Published under the GNU GPL, v3 or later.
10 use FindBin
qw($RealBin);
14 my ($classname, $dc_image, $vdesocket) = @_;
16 dc_image => $dc_image,
17 vdesocket => $vdesocket,
23 sub write_kvm_ifup($$$)
25 my ($self, $path, $ip_prefix) = @_;
26 open(SCRIPT, ">$path/kvm-ifup");
28 print SCRIPT <<__EOF__;
33 /sbin/ifconfig \$1 \$PREFIX.1 up
35 cat <<EOF>$path/udhcpd.conf
40 lease_file $path/udhcpd.leases
41 pidfile $path/udhcpd.pid
44 touch
$path/udhcpd
.leases
46 /usr/sbin
/udhcpd $path/udhcpd
.conf
51 chmod(0755, "$path/kvm-ifup");
53 return ("$path/kvm-ifup", "$path/udhcpd.pid", "$ip_prefix.20");
58 my ($self, $envvars) = @_;
60 print "Killing kvm instance $envvars->{KVM_PID}\n";
62 kill 9, $envvars->{KVM_PID
};
64 if (defined($envvars->{DHCPD_PID
})) {
65 print "Killing dhcpd instance $envvars->{DHCPD_PID}\n";
66 kill 9, $envvars->{DHCPD_PID
};
74 my ($self, $envvars) = @_;
81 my ($self, $envvars) = @_;
83 # FIXME: Check whether $self->{pid} is still running
101 my ($self, $path, $image) = @_;
103 my $pidfile = "$path/kvm.pid";
105 my $opts = (defined($ENV{KVM_OPTIONS
})?
$ENV{KVM_OPTIONS
}:"-nographic");
107 if (defined($ENV{KVM_SNAPSHOT
})) {
108 $opts .= " -loadvm $ENV{KVM_SNAPSHOT}";
115 if ($self->{vdesocket
}) {
116 $netopts = "vde,socket=$self->{vdesocket}";
118 my $ifup_script, $dhcpd_pidfile;
119 ($ifup_script, $dhcpd_pidfile, $ip_address) = $self->write_kvm_ifup($path, "192.168.9");
120 $netopts = "tap,script=$ifup_script";
121 $dhcp_pid = read_pidfile
($dhcpd_pidfile);
124 system("kvm -name \"Samba 4 Test Subject\" $opts -monitor unix:$path/kvm.monitor,server,nowait -daemonize -pidfile $pidfile -snapshot $image -net nic -net $netopts");
126 return (read_pidfile
($pidfile), $dhcp_pid, $ip_address);
131 my ($self, $envname, $path) = @_;
133 if ($envname eq "dc") {
134 ($self->{dc_pid
}, $self->{dc_dhcpd_pid
}, $self->{dc_ip
}) = $self->start($path, $self->{dc_image
});
137 my ($name, $default) = @_;
138 return defined($ENV{"KVM_DC_$name"})?
$ENV{"KVM_DC_$name"}:$default;
141 if ($envname eq "dc") {
143 KVM_PID
=> $self->{dc_pid
},
144 DHCPD_PID
=> $self->{dc_dhcpd_pid
},
145 USERNAME
=> choose_var
("USERNAME", "Administrator"),
146 PASSWORD
=> choose_var
("PASSWORD", "penguin"),
147 DOMAIN
=> choose_var
("DOMAIN", "SAMBA"),
148 REALM
=> choose_var
("REALM", "SAMBA"),
149 SERVER
=> choose_var
("SERVER", "DC"),
150 SERVER_IP
=> $self->{dc_ip
},
151 NETBIOSNAME
=> choose_var
("NETBIOSNAME", "DC"),
152 NETBIOSALIAS
=> choose_var
("NETBIOSALIAS", "DC"),