File: test-domain-define-create-destroy.phpt

package info (click to toggle)
libvirt-php 0.5.8-7
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 3,140 kB
  • sloc: ansic: 9,352; sh: 4,578; php: 269; makefile: 219; xml: 93
file content (42 lines) | stat: -rw-r--r-- 1,209 bytes parent folder | download | duplicates (5)
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
<?php
	require_once('functions.phpt');

	$conn = libvirt_connect('test:///default', false);
	if (!is_resource($conn))
		bail('Connection to default hypervisor failed');

	$xml = file_get_contents($abs_srcdir.'/data/example-no-disk-and-media.xml');

	$res = libvirt_domain_define_xml($conn, $xml);
	if (!is_resource($res))
		bail('Domain definition failed with error: '.libvirt_get_last_error());

	if (!libvirt_domain_create($res))
		bail('Domain creation failed with error: '.libvirt_get_last_error());

	$info = libvirt_domain_get_info($res);
	if (!$info)
		bail('Getting domain information failed with error: '.libvirt_get_last_error());

	$cpuUsed = $info['cpuUsed'];

	sleep(5);

	$info = libvirt_domain_get_info($res);
	if (!$info)
		bail('Getting domain information failed with error: '.libvirt_get_last_error());

	if ($cpuUsed == $info['cpuUsed'])
		bail('No time difference between CPU times after 5 seconds');

	if (!libvirt_domain_destroy($res))
		bail('Domain destroy failed with error: '.libvirt_get_last_error());

	if (!libvirt_domain_undefine($res))
		bail('Domain undefinition failed with error: '.libvirt_get_last_error());

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

	success( basename(__FILE__) );
?>