2014-02-05 18:10:00 +04:00
# include <config.h>
# include "testutils.h"
# ifdef WITH_LXC
# include "lxc / lxc_native.h"
2015-11-29 05:55:32 +03:00
# include "lxc / lxc_conf.h"
# include "testutilslxc.h"
2014-02-05 18:10:00 +04:00
# define VIR_FROM_THIS VIR_FROM_NONE
2019-12-03 13:49:49 +03:00
static virLXCDriverPtr driver ;
2015-11-29 05:55:32 +03:00
2016-02-16 20:07:32 +03:00
static int testSanitizeDef ( virDomainDefPtr vmdef )
2014-02-05 18:10:00 +04:00
{
2016-02-16 20:07:32 +03:00
/* Remove UUID randomness */
if ( virUUIDParse ( " c7a5fdbd-edaf-9455-926a-d65c16db1809 " , vmdef - > uuid ) < 0 )
2014-02-05 18:10:00 +04:00
return - 1 ;
return 0 ;
}
static int
2016-02-16 20:07:32 +03:00
testCompareXMLToConfigFiles ( const char * xmlfile ,
2014-02-05 18:10:02 +04:00
const char * configfile ,
bool expectError )
2014-02-05 18:10:00 +04:00
{
int ret = - 1 ;
char * config = NULL ;
char * actualxml = NULL ;
virDomainDefPtr vmdef = NULL ;
2016-05-26 18:01:52 +03:00
if ( virTestLoadFile ( configfile , & config ) < 0 )
2014-02-05 18:10:00 +04:00
goto fail ;
2019-12-03 13:49:49 +03:00
vmdef = lxcParseConfigString ( config , driver - > caps , driver - > xmlopt ) ;
2014-02-05 18:10:02 +04:00
if ( ( vmdef & & expectError ) | | ( ! vmdef & & ! expectError ) )
2014-02-05 18:10:00 +04:00
goto fail ;
2014-02-05 18:10:02 +04:00
if ( vmdef ) {
2016-02-16 20:07:32 +03:00
if ( testSanitizeDef ( vmdef ) < 0 )
2014-02-05 18:10:02 +04:00
goto fail ;
2014-02-05 18:10:00 +04:00
2019-11-27 14:57:34 +03:00
if ( ! ( actualxml = virDomainDefFormat ( vmdef , driver - > xmlopt , 0 ) ) )
2014-02-05 18:10:02 +04:00
goto fail ;
2016-05-26 18:01:53 +03:00
if ( virTestCompareToFile ( actualxml , xmlfile ) < 0 )
2014-02-05 18:10:02 +04:00
goto fail ;
2014-02-05 18:10:00 +04:00
}
ret = 0 ;
2014-03-25 10:53:44 +04:00
fail :
2014-02-05 18:10:00 +04:00
VIR_FREE ( actualxml ) ;
VIR_FREE ( config ) ;
virDomainDefFree ( vmdef ) ;
return ret ;
}
2014-02-05 18:10:02 +04:00
struct testInfo {
const char * name ;
bool expectError ;
} ;
2014-02-05 18:10:00 +04:00
static int
2018-11-14 20:25:46 +03:00
testCompareXMLToConfigHelperLegacy ( const void * data )
2014-02-05 18:10:00 +04:00
{
int result = - 1 ;
2014-02-05 18:10:02 +04:00
const struct testInfo * info = data ;
2014-02-05 18:10:00 +04:00
char * xml = NULL ;
char * config = NULL ;
2019-10-22 16:26:14 +03:00
xml = g_strdup_printf ( " %s/lxcconf2xmldata/lxcconf2xml-%s.xml " ,
abs_srcdir , info - > name ) ;
config = g_strdup_printf ( " %s/lxcconf2xmldata/lxcconf2xml-%s.config " ,
abs_srcdir , info - > name ) ;
2014-02-05 18:10:00 +04:00
2014-02-05 18:10:02 +04:00
result = testCompareXMLToConfigFiles ( xml , config , info - > expectError ) ;
2014-02-05 18:10:00 +04:00
VIR_FREE ( xml ) ;
VIR_FREE ( config ) ;
return result ;
}
2018-11-14 20:25:46 +03:00
static int
testCompareXMLToConfigHelperV3 ( const void * data )
{
int result = - 1 ;
const struct testInfo * info = data ;
char * xml = NULL ;
char * config = NULL ;
2019-10-22 16:26:14 +03:00
xml = g_strdup_printf ( " %s/lxcconf2xmldata/lxcconf2xml-%s.xml " ,
abs_srcdir , info - > name ) ;
config = g_strdup_printf ( " %s/lxcconf2xmldata/lxcconf2xml-%s-v3.config " ,
abs_srcdir , info - > name ) ;
2018-11-14 20:25:46 +03:00
result = testCompareXMLToConfigFiles ( xml , config , info - > expectError ) ;
VIR_FREE ( xml ) ;
VIR_FREE ( config ) ;
return result ;
}
2014-02-05 18:10:00 +04:00
static int
mymain ( void )
{
int ret = EXIT_SUCCESS ;
2019-12-03 13:49:49 +03:00
if ( ! ( driver = testLXCDriverInit ( ) ) )
2015-11-29 05:55:32 +03:00
return EXIT_FAILURE ;
2017-11-03 15:09:47 +03:00
# define DO_TEST(name, expectError) \
do { \
2014-02-05 18:10:02 +04:00
const struct testInfo info = { name , expectError } ; \
2017-11-03 15:09:47 +03:00
if ( virTestRun ( " LXC Native-2-XML " name , \
2018-11-14 20:25:46 +03:00
testCompareXMLToConfigHelperLegacy , \
2017-11-03 15:09:47 +03:00
& info ) < 0 ) \
ret = EXIT_FAILURE ; \
2014-02-05 18:10:02 +04:00
} while ( 0 )
DO_TEST ( " simple " , false ) ;
DO_TEST ( " fstab " , true ) ;
2014-02-05 18:10:03 +04:00
DO_TEST ( " nonetwork " , false ) ;
DO_TEST ( " nonenetwork " , false ) ;
2014-02-05 18:10:05 +04:00
DO_TEST ( " physnetwork " , false ) ;
2014-02-05 18:10:07 +04:00
DO_TEST ( " macvlannetwork " , false ) ;
2014-02-05 18:10:15 +04:00
DO_TEST ( " vlannetwork " , false ) ;
2018-11-30 15:43:37 +03:00
DO_TEST ( " miscnetwork " , false ) ;
2014-02-05 18:10:08 +04:00
DO_TEST ( " idmap " , false ) ;
2014-02-05 18:10:09 +04:00
DO_TEST ( " memtune " , false ) ;
2014-02-05 18:10:10 +04:00
DO_TEST ( " cputune " , false ) ;
2014-02-05 18:10:11 +04:00
DO_TEST ( " cpusettune " , false ) ;
2014-02-05 18:10:12 +04:00
DO_TEST ( " blkiotune " , false ) ;
2016-05-13 20:20:54 +03:00
DO_TEST ( " ethernet " , false ) ;
2014-02-05 18:10:00 +04:00
2018-11-14 20:25:46 +03:00
/* Tests for LXC 3.0 and higher */
# define DO_TEST3(name, expectError) \
do { \
const struct testInfo info = { name , expectError } ; \
if ( virTestRun ( " LXC Native-3-XML " name , \
testCompareXMLToConfigHelperV3 , \
& info ) < 0 ) \
ret = EXIT_FAILURE ; \
} while ( 0 )
DO_TEST3 ( " simple " , false ) ;
DO_TEST3 ( " fstab " , true ) ;
DO_TEST3 ( " nonetwork " , false ) ;
DO_TEST3 ( " nonenetwork " , false ) ;
DO_TEST3 ( " physnetwork " , false ) ;
DO_TEST3 ( " macvlannetwork " , false ) ;
DO_TEST3 ( " vlannetwork " , false ) ;
2018-11-30 15:43:37 +03:00
DO_TEST3 ( " miscnetwork " , false ) ;
2018-11-14 20:25:46 +03:00
DO_TEST3 ( " idmap " , false ) ;
DO_TEST3 ( " memtune " , false ) ;
DO_TEST3 ( " cputune " , false ) ;
DO_TEST3 ( " cpusettune " , false ) ;
DO_TEST3 ( " blkiotune " , false ) ;
DO_TEST3 ( " ethernet " , false ) ;
2019-12-03 13:49:49 +03:00
testLXCDriverFree ( driver ) ;
2015-11-29 05:55:32 +03:00
2014-02-05 18:10:00 +04:00
return ret ;
}
2017-03-29 17:45:42 +03:00
VIR_TEST_MAIN ( mymain )
2014-02-05 18:10:00 +04:00
# else
int
main ( void )
{
return EXIT_AM_SKIP ;
}
# endif /* WITH_LXC */