2011-05-26 21:45:41 +04:00
# include <config.h>
2013-04-16 17:41:44 +04:00
# include "testutils.h"
2011-05-26 21:45:41 +04:00
# ifdef WITH_OPENVZ
# include <unistd.h>
# include "internal.h"
2012-12-12 22:06:53 +04:00
# include "viralloc.h"
2011-05-26 21:45:41 +04:00
# include "openvz / openvz_conf.h"
2013-04-03 14:36:23 +04:00
# include "virstring.h"
2011-05-26 21:45:41 +04:00
2013-05-03 16:52:21 +04:00
# define VIR_FROM_THIS VIR_FROM_OPENVZ
2011-05-31 16:58:58 +04:00
static int
2019-10-14 15:45:03 +03:00
testLocateConfFile ( int vpsid G_GNUC_UNUSED , char * * conffile ,
const char * ext G_GNUC_UNUSED )
2011-05-31 16:58:58 +04:00
{
2019-10-22 16:26:14 +03:00
* conffile = g_strdup_printf ( " %s/openvzutilstest.conf " , abs_srcdir ) ;
return 0 ;
2011-05-31 16:58:58 +04:00
}
2011-05-26 21:45:41 +04:00
struct testConfigParam {
const char * param ;
const char * value ;
int ret ;
} ;
static struct testConfigParam configParams [ ] = {
{ " OSTEMPLATE " , " rhel-5-lystor " , 1 } ,
{ " IP_ADDRESS " , " 194.44.18.88 " , 1 } ,
{ " THIS_PARAM_IS_MISSING " , NULL , 0 } ,
} ;
static int
2019-10-14 15:45:03 +03:00
testReadConfigParam ( const void * data G_GNUC_UNUSED )
2011-05-26 21:45:41 +04:00
{
int result = - 1 ;
Convert 'int i' to 'size_t i' in tests/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 18:09:33 +04:00
size_t i ;
2011-05-26 21:45:41 +04:00
char * conf = NULL ;
char * value = NULL ;
2019-10-22 16:26:14 +03:00
conf = g_strdup_printf ( " %s/openvzutilstest.conf " , abs_srcdir ) ;
2011-05-26 21:45:41 +04:00
2019-10-15 14:55:26 +03:00
for ( i = 0 ; i < G_N_ELEMENTS ( configParams ) ; + + i ) {
2011-05-26 21:45:41 +04:00
if ( openvzReadConfigParam ( conf , configParams [ i ] . param ,
& value ) ! = configParams [ i ] . ret ) {
goto cleanup ;
}
2014-11-13 17:20:43 +03:00
if ( configParams [ i ] . ret ! = 1 )
2011-05-26 21:45:41 +04:00
continue ;
if ( STRNEQ ( configParams [ i ] . value , value ) ) {
2016-05-26 18:01:51 +03:00
virTestDifference ( stderr , configParams [ i ] . value , value ) ;
2011-05-26 21:45:41 +04:00
goto cleanup ;
}
}
result = 0 ;
2014-03-25 10:53:44 +04:00
cleanup :
2011-05-26 21:45:41 +04:00
VIR_FREE ( conf ) ;
VIR_FREE ( value ) ;
return result ;
}
2011-05-31 16:58:58 +04:00
static int
2019-10-14 15:45:03 +03:00
testReadNetworkConf ( const void * data G_GNUC_UNUSED )
2011-05-31 16:58:58 +04:00
{
int result = - 1 ;
virDomainDefPtr def = NULL ;
char * actual = NULL ;
const char * expected =
" <domain type='openvz'> \n "
" <uuid>00000000-0000-0000-0000-000000000000</uuid> \n "
2012-02-23 04:48:38 +04:00
" <memory unit='KiB'>0</memory> \n "
" <currentMemory unit='KiB'>0</currentMemory> \n "
2012-05-08 20:04:36 +04:00
" <vcpu placement='static'>0</vcpu> \n "
2011-05-31 16:58:58 +04:00
" <os> \n "
" <type>exe</type> \n "
" <init>/sbin/init</init> \n "
" </os> \n "
" <clock offset='utc'/> \n "
" <on_poweroff>destroy</on_poweroff> \n "
" <on_reboot>destroy</on_reboot> \n "
" <on_crash>destroy</on_crash> \n "
" <devices> \n "
" <interface type='ethernet'> \n "
" <mac address='00:00:00:00:00:00'/> \n "
2014-07-22 13:09:48 +04:00
" <ip address='194.44.18.88' family='ipv4'/> \n "
2011-05-31 16:58:58 +04:00
" </interface> \n "
" <interface type='bridge'> \n "
" <mac address='00:18:51:c1:05:ee'/> \n "
" <target dev='veth105.10'/> \n "
" </interface> \n "
" </devices> \n "
" </domain> \n " ;
2019-12-09 17:37:20 +03:00
struct openvz_driver driver = {
. xmlopt = openvzXMLOption ( & driver ) ,
. caps = openvzCapsInit ( ) ,
} ;
2011-05-31 16:58:58 +04:00
2019-10-20 14:49:46 +03:00
if ( ! ( def = virDomainDefNew ( ) ) )
2011-05-31 16:58:58 +04:00
goto cleanup ;
2019-10-20 14:49:46 +03:00
def - > os . init = g_strdup ( " /sbin/init " ) ;
2011-05-31 16:58:58 +04:00
def - > virtType = VIR_DOMAIN_VIRT_OPENVZ ;
2015-04-17 03:11:06 +03:00
def - > os . type = VIR_DOMAIN_OSTYPE_EXE ;
2011-05-31 16:58:58 +04:00
if ( openvzReadNetworkConf ( def , 1 ) < 0 ) {
2016-05-19 22:10:18 +03:00
fprintf ( stderr , " ERROR: %s \n " , virGetLastErrorMessage ( ) ) ;
2011-05-31 16:58:58 +04:00
goto cleanup ;
}
2019-11-27 14:57:34 +03:00
actual = virDomainDefFormat ( def , driver . xmlopt , VIR_DOMAIN_DEF_FORMAT_INACTIVE ) ;
2011-05-31 16:58:58 +04:00
if ( actual = = NULL ) {
2016-05-19 22:10:18 +03:00
fprintf ( stderr , " ERROR: %s \n " , virGetLastErrorMessage ( ) ) ;
2011-05-31 16:58:58 +04:00
goto cleanup ;
}
if ( STRNEQ ( expected , actual ) ) {
2016-05-26 18:01:51 +03:00
virTestDifference ( stderr , expected , actual ) ;
2011-05-31 16:58:58 +04:00
goto cleanup ;
}
result = 0 ;
2014-03-25 10:53:44 +04:00
cleanup :
2019-12-03 13:49:49 +03:00
virObjectUnref ( driver . xmlopt ) ;
virObjectUnref ( driver . caps ) ;
2011-05-31 16:58:58 +04:00
VIR_FREE ( actual ) ;
virDomainDefFree ( def ) ;
return result ;
}
2011-05-26 21:45:41 +04:00
static int
mymain ( void )
{
int result = 0 ;
2011-05-31 16:58:58 +04:00
openvzLocateConfFile = testLocateConfFile ;
2017-11-03 15:09:47 +03:00
# define DO_TEST(_name) \
do { \
if ( virTestRun ( " OpenVZ " # _name , test # # _name , \
NULL ) < 0 ) { \
result = - 1 ; \
} \
2011-05-26 21:45:41 +04:00
} while ( 0 )
DO_TEST ( ReadConfigParam ) ;
2011-05-31 16:58:58 +04:00
DO_TEST ( ReadNetworkConf ) ;
2011-05-26 21:45:41 +04:00
return result = = 0 ? EXIT_SUCCESS : EXIT_FAILURE ;
}
2017-03-29 17:45:42 +03:00
VIR_TEST_MAIN ( mymain )
2011-05-26 21:45:41 +04:00
# else
int main ( void )
{
return EXIT_AM_SKIP ;
}
# endif /* WITH_OPENVZ */