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
2015-11-29 05:55:32 +03:00
static virCapsPtr caps ;
static virDomainXMLOptionPtr xmlopt ;
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 ;
2015-11-29 05:55:32 +03:00
vmdef = lxcParseConfigString ( config , caps , 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
2016-02-16 20:07:32 +03:00
if ( ! ( actualxml = virDomainDefFormat ( vmdef , caps , 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
testCompareXMLToConfigHelper ( const void * data )
{
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 ;
if ( virAsprintf ( & xml , " %s/lxcconf2xmldata/lxcconf2xml-%s.xml " ,
2014-02-05 18:10:02 +04:00
abs_srcdir , info - > name ) < 0 | |
2014-02-05 18:10:00 +04:00
virAsprintf ( & config , " %s/lxcconf2xmldata/lxcconf2xml-%s.config " ,
2014-02-05 18:10:02 +04:00
abs_srcdir , info - > name ) < 0 )
2014-02-05 18:10:00 +04:00
goto cleanup ;
2014-02-05 18:10:02 +04:00
result = testCompareXMLToConfigFiles ( xml , config , info - > expectError ) ;
2014-02-05 18:10:00 +04:00
2014-03-25 10:53:44 +04:00
cleanup :
2014-02-05 18:10:00 +04:00
VIR_FREE ( xml ) ;
VIR_FREE ( config ) ;
return result ;
}
static int
mymain ( void )
{
int ret = EXIT_SUCCESS ;
2015-11-29 05:55:32 +03:00
if ( ! ( caps = testLXCCapsInit ( ) ) )
return EXIT_FAILURE ;
if ( ! ( xmlopt = lxcDomainXMLConfInit ( ) ) ) {
virObjectUnref ( caps ) ;
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 , \
testCompareXMLToConfigHelper , \
& 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 ) ;
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
2015-11-29 05:55:32 +03:00
virObjectUnref ( xmlopt ) ;
virObjectUnref ( caps ) ;
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 */