Commit 164d1aca authored by Tugdual Saunier's avatar Tugdual Saunier Committed by Michal Novotny

Made tests more universal by using libvirt test driver

parent 38a5a034
......@@ -581,6 +581,8 @@ void set_vnc_location(char *msg TSRMLS_DC)
}
LIBVIRT_G (vnc_location)=estrndup(msg,strlen(msg));
DPRINTF("set_vnc_location: VNC server location set to '%s'\n", LIBVIRT_G (vnc_location));
}
/*
......@@ -2586,7 +2588,7 @@ char *get_disk_xml(unsigned long long size, char *path, char *driver, char *bus,
char *qemu_img_cmd = get_feature_binary("create-image");
if (qemu_img_cmd == NULL) {
DPRINTF("%s: Binary for creating disk images doesn't exist", __FUNCTION__);
DPRINTF("%s: Binary for creating disk images doesn't exist\n", __FUNCTION__);
return NULL;
}
......@@ -3806,15 +3808,12 @@ PHP_FUNCTION(libvirt_domain_new)
snprintf(vncl, sizeof(vncl), "Connection failed, port %s is most likely forbidden on firewall (iptables) on the host (%s)"
" or the emulator VNC server is bound to localhost address only.",
tmp, virConnectGetHostname(conn->conn));
set_vnc_location(vncl TSRMLS_CC);
}
else {
} else {
close(fd);
DPRINTF("%s: Connection to '%s' successfull (%s local connection)\n", PHPFUNC, vncl,
(flags & DOMAIN_FLAG_TEST_LOCAL_VNC) ? "using" : "not using");
set_vnc_location(vncl TSRMLS_CC);
DPRINTF("%s: VNC server location set to '%s'\n", PHPFUNC, vncl);
}
set_vnc_location(vncl TSRMLS_CC);
tmp = installation_get_xml(2,
conn->conn, name, memMB, maxmemMB, NULL /* arch */, NULL, vcpus, iso_image,
......@@ -3854,7 +3853,7 @@ PHP_FUNCTION(libvirt_domain_new)
PHP_FUNCTION(libvirt_domain_new_get_vnc)
{
if (LIBVIRT_G(vnc_location))
RETURN_STRING(LIBVIRT_G(vnc_location),0);
RETURN_STRING(LIBVIRT_G(vnc_location),1);
RETURN_NULL();
}
......
<domain type='kvm'>
<domain type='test'>
<name>test-guest-no-disk-and-media</name>
<uuid>28a15e00-9c40-ddc1-b6df-9a08921b93f0</uuid>
<memory>65535</memory>
......@@ -18,7 +18,6 @@
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/bin/qemu-kvm</emulator>
<controller type='ide' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
......
......@@ -13,6 +13,14 @@
exit(0);
}
function skip($name = false) {
if ($name == false)
bail("Invalid test name!");
printf("Test $name SKIPPED\n");
exit(1);
}
if (!extension_loaded('libvirt')) {
if (!dl('../src/libvirt-php.so'))
bail('Cannot load libvirt-php extension. Please install libvirt-php first (using `make install`)');
......
extension_dir=../src/
extension=libvirt-php.so
#!/bin/bash
nf=$1
tests=( "test-connect" "test-version-check" "test-version-get" "test-domain-define-undefine" "test-domain-define-create-destroy" "test-domain-create"
"test-domain-create-and-get-xpath" "test-domain-create-and-coredump" "test-logging" "test-conn-limit" "test-get-emulator" "test-install" )
tests=( "test-connect" "test-version-check" "test-version-get" "test-domain-define-undefine" "test-domain-define-create-destroy" "test-domain-create" "test-domain-create-and-get-xpath" "test-domain-create-and-coredump" "test-logging" "test-get-emulator" "test-install" "test-conn-limit" )
run_test()
{
......@@ -10,7 +9,7 @@ run_test()
local nf=$2
ret=0
php $name.phpt
php -n -c "./php.ini" $name.phpt
if [ "x$?" != "x0" ]; then
if [ "x$nf" == 'x1' ]; then
ret=1
......
......@@ -14,7 +14,7 @@
$num = $num_ini + 1;
for ($i = 0; $i < $num; $i++)
$conn[] = libvirt_connect('null', false);
$conn[] = @libvirt_connect('test:///default', false);
$tmp = libvirt_print_binding_resources();
if (sizeof($tmp) > $num_ini)
......
<?php
require_once('functions.phpt');
$conn = libvirt_connect('null');
$conn = libvirt_connect('test:///default');
if (!is_resource($conn))
bail('Connection to default hypervisor failed');
$res = libvirt_node_get_info($conn);
if (!is_array($res))
bail('Node get info doesn\'t return an array');
if (!is_numeric($res['memory']))
bail('Invalid memory size');
if (!is_numeric($res['cpus']))
bail('Invalid CPU core count');
unset($res);
if (!libvirt_connect_get_uri($conn))
bail('Invalid URI value');
if (!libvirt_connect_get_hostname($conn))
bail('Invalid hostname value');
if (!($res = libvirt_domain_get_counts($conn)))
bail('Invalid domain count');
if ($res['active'] != count( libvirt_list_active_domains($conn)))
bail('Numbers of active domains mismatch');
if ($res['inactive'] != count( libvirt_list_inactive_domains($conn)))
bail('Numbers of inactive domains mismatch');
if (libvirt_connect_get_hypervisor($conn) == false)
echo "Warning: Getting hypervisor information failed!\n";
if (libvirt_connect_get_maxvcpus($conn) == false)
echo "Warning: Cannot get the maximum number of VCPUs per VM!\n";
if (libvirt_connect_get_capabilities($conn) == false)
bail('Invalid capabilities on the hypervisor connection');
if (libvirt_connect_get_information($conn) == false)
bail('No information on the connection are available');
unset($res);
unset($conn);
success( basename(__FILE__) );
......
<?php
require_once('functions.phpt');
$conn = libvirt_connect('null', false);
$conn = libvirt_connect('test:///default', false);
if (!is_resource($conn))
bail('Connection to default hypervisor failed');
......
<?php
require_once('functions.phpt');
$conn = libvirt_connect('null', false);
$conn = libvirt_connect('test:///default', false);
if (!is_resource($conn))
bail('Connection to default hypervisor failed');
......@@ -12,7 +12,7 @@
if (!is_resource($res))
bail('Domain definition failed with error: '.libvirt_get_last_error());
$info = libvirt_domain_xml_xpath($res, '/domain/devices/emulator');
$info = libvirt_domain_xml_xpath($res, '/domain/name');
if (!$info)
bail('Cannot get domain XML and/or xPath expression');
......
<?php
require_once('functions.phpt');
$conn = libvirt_connect('null', false);
$conn = libvirt_connect('test:///default', false);
if (!is_resource($conn))
bail('Connection to default hypervisor failed');
......
<?php
require_once('functions.phpt');
$conn = libvirt_connect('null', false);
$conn = libvirt_connect('test:///default', false);
if (!is_resource($conn))
bail('Connection to default hypervisor failed');
......
<?php
require_once('functions.phpt');
$conn = libvirt_connect('null', false);
$conn = libvirt_connect('test:///default', false);
if (!is_resource($conn))
bail('Connection to default hypervisor failed');
......
<?php
require_once('functions.phpt');
$conn = libvirt_connect('null', false);
$conn = @libvirt_connect(NULL, false);
if (!is_resource($conn))
bail('Connection to default hypervisor failed');
skip( basename(__FILE__) );
$curdir = getcwd();
$xml = file_get_contents($curdir.'/data/example-qcow2-disk.xml');
......
<?php
$logfile = '/tmp/test.log';
require_once('functions.phpt');
unlink($logfile);
if (!libvirt_logfile_set($logfile, 1))
bail('Cannot enable debug logging to test.log file');
$conn = libvirt_connect('null');
$conn = libvirt_connect('test:///default');
if (!is_resource($conn))
bail('Connection to default hypervisor failed');
......@@ -18,9 +13,6 @@
if (!is_string($tmp))
bail('Cannot get emulator for i686 architecture');
$tmp = libvirt_connect_get_emulator($conn, 'x86_64');
if (!is_string($tmp))
bail('Cannot get emulator for x86_64 architecture');
unset($tmp);
unset($conn);
......
<?php
$logfile = 'test-install.log';
unlink($logfile);
@unlink($logfile);
libvirt_logfile_set($logfile, 10);
$name = 'test';
$image = '/tmp/test-libvirt-php.tmp';
$name = 'test-'.rand(0, 999);
$image = __DIR__.'/data/test-libvirt-php.img';
$disk_image = '/tmp/test-libvirt-php.img';
$local_test = true;
$show_vnc_location = false;
......@@ -12,7 +12,7 @@
require_once('functions.phpt');
$conn = libvirt_connect('null', false); /* Enable read-write connection */
$conn = libvirt_connect('test:///default', false); /* Enable read-write connection */
if (!is_resource($conn))
bail('Connection to default hypervisor failed');
......@@ -53,7 +53,7 @@
unset($conn);
@unlink($disk_image);
unlink($logfile);
@unlink($logfile);
if ($ok) {
if ($show_vnc_location)
......
......@@ -3,11 +3,11 @@
require_once('functions.phpt');
unlink($logfile);
@unlink($logfile);
if (!libvirt_logfile_set($logfile, 1))
bail('Cannot enable debug logging to test.log file');
$conn = libvirt_connect('null');
$conn = libvirt_connect('test:///default');
if (!is_resource($conn))
bail('Connection to default hypervisor failed');
......@@ -45,7 +45,7 @@
if (libvirt_connect_get_capabilities($conn) == false)
bail('Invalid capabilities on the hypervisor connection');
if (libvirt_connect_get_information($conn) == false)
if (@libvirt_connect_get_information($conn) == false)
bail('No information on the connection are available');
unset($res);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment