test-install.phpt 1.86 KB
Newer Older
1
<?php
Michal Novotny's avatar
Michal Novotny committed
2
	$logfile = 'test-install.log';
3
	@unlink($logfile);
Michal Novotny's avatar
Michal Novotny committed
4 5
	libvirt_logfile_set($logfile, 10);

6
	$name = 'test';
7
	$image = __DIR__.'/data/test-libvirt-php.img';
Michal Novotny's avatar
Michal Novotny committed
8
	$disk_image = '/tmp/test-libvirt-php.img';
9 10 11 12 13 14
	$local_test = true;
	$show_vnc_location = false;
	$memory = 64;

	require_once('functions.phpt');

15
	$conn = libvirt_connect('test:///default', false); /* Enable read-write connection */
16 17 18
	if (!is_resource($conn))
		bail('Connection to default hypervisor failed');

19 20 21 22 23 24
	//cleaning
	if ($res = libvirt_domain_lookup_by_name($conn, "test")) {
		libvirt_domain_destroy($res);
		libvirt_domain_undefine($res);
	}

25
	$disks = array(
Michal Novotny's avatar
Michal Novotny committed
26
			array( 'path' => $disk_image, 'driver' => 'raw', 'bus' => 'ide', 'dev' => 'hda', 'size' => '1M',
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
				'flags' => VIR_DOMAIN_DISK_FILE | VIR_DOMAIN_DISK_ACCESS_ALL )
		);

	$networks = array(
			array( 'mac' => '00:11:22:33:44:55', 'network' => 'default', 'model' => 'e1000')
		);

	$networks = array();

	$flags = VIR_DOMAIN_FLAG_FEATURE_ACPI | VIR_DOMAIN_FLAG_FEATURE_APIC | VIR_DOMAIN_FLAG_FEATURE_PAE;

	if ($local_test)
		$flags |= VIR_DOMAIN_FLAG_TEST_LOCAL_VNC;

	$res = libvirt_domain_new($conn, $name, false, $memory, $memory, 1, $image, $disks, $networks, $flags);
Michal Novotny's avatar
Michal Novotny committed
42 43 44
	if ($res == false)
		bail('Installation test failed with error: '.libvirt_get_last_error().'. More info saved into '.$logfile);

45 46 47 48 49
	$ok = is_resource($res);

	$vncloc = libvirt_domain_new_get_vnc();

	if (!libvirt_domain_destroy($res))
Michal Novotny's avatar
Michal Novotny committed
50
		bail('Domain destroy failed with error: '.libvirt_get_last_error().'. More info saved into '.$logfile);
51 52 53 54 55 56 57 58 59 60

	unset($res);

	$res = libvirt_domain_lookup_by_name($conn, $name);
	if (is_resource($res))
		libvirt_domain_undefine($res);

	unset($res);
	unset($conn);

Michal Novotny's avatar
Michal Novotny committed
61
	@unlink($disk_image);
62
	@unlink($logfile);
63 64 65 66 67 68 69 70 71

	if ($ok) {
		if ($show_vnc_location)
			echo "VNC Server location is: $vncloc\n";
		success( basename(__FILE__) );
	}
	else
		bail('Invalid domain resource');
?>