<s> """<STR_LIT>""" <EOL> import optparse <EOL> import os <EOL> import os . path <EOL> import re <EOL> import shutil <EOL> import sys <EOL> import tempfile <EOL> import unittest <EOL> try : <EOL> import xml . etree . ElementTree as ET <EOL> except ImportError : <EOL> import elementtree . ElementTree as ET <EOL> from ganeti import constants <EOL> from ganeti import errors <EOL> from ganeti import ovf <EOL> from ganeti import utils <EOL> from ganeti import pathutils <EOL> import testutils <EOL> OUTPUT_DIR = "<STR_LIT>" <EOL> GANETI_DISKS = { <EOL> "<STR_LIT>" : "<STR_LIT:1>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:0>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> GANETI_NETWORKS = { <EOL> "<STR_LIT>" : "<STR_LIT:1>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:none>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> GANETI_HYPERVISOR = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> GANETI_OS = { "<STR_LIT>" : "<STR_LIT>" } <EOL> GANETI_BACKEND = { <EOL> "<STR_LIT>" : "<STR_LIT:1>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:False>" , <EOL> } <EOL> GANETI_NAME = "<STR_LIT>" <EOL> GANETI_TEMPLATE = "<STR_LIT>" <EOL> GANETI_TAGS = None <EOL> GANETI_VERSION = "<STR_LIT:0>" <EOL> VIRTUALBOX_DISKS = { <EOL> "<STR_LIT>" : "<STR_LIT:2>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:0>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:0>" , <EOL> } <EOL> VIRTUALBOX_NETWORKS = { <EOL> "<STR_LIT>" : "<STR_LIT:1>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:none>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> VIRTUALBOX_HYPERVISOR = { "<STR_LIT>" : "<STR_LIT>" } <EOL> VIRTUALBOX_OS = { "<STR_LIT>" : None } <EOL> VIRTUALBOX_BACKEND = { <EOL> "<STR_LIT>" : "<STR_LIT:1>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> VIRTUALBOX_NAME = None <EOL> VIRTUALBOX_TEMPLATE = None <EOL> VIRTUALBOX_TAGS = None <EOL> VIRTUALBOX_VERSION = None <EOL> EMPTY_DISKS = { } <EOL> EMPTY_NETWORKS = { } <EOL> EMPTY_HYPERVISOR = { "<STR_LIT>" : "<STR_LIT>" } <EOL> EMPTY_OS = { } <EOL> EMPTY_BACKEND = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> EMPTY_NAME = None <EOL> EMPTY_TEMPLATE = None <EOL> EMPTY_TAGS = None <EOL> EMPTY_VERSION = None <EOL> CMDARGS_DISKS = { <EOL> "<STR_LIT>" : "<STR_LIT:1>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> CMDARGS_NETWORKS = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:none>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:1>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> CMDARGS_HYPERVISOR = { <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> CMDARGS_OS = { "<STR_LIT>" : "<STR_LIT>" } <EOL> CMDARGS_BACKEND = { <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : "<STR_LIT:1>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> CMDARGS_NAME = "<STR_LIT>" <EOL> CMDARGS_TEMPLATE = "<STR_LIT>" <EOL> CMDARGS_TAGS = "<STR_LIT>" <EOL> ARGS_EMPTY = { <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : False , <EOL> } <EOL> ARGS_EXPORT_DIR = dict ( ARGS_EMPTY , ** { <EOL> "<STR_LIT>" : OUTPUT_DIR , <EOL> "<STR_LIT:name>" : None , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : None , <EOL> } ) <EOL> ARGS_VBOX = dict ( ARGS_EXPORT_DIR , ** { <EOL> "<STR_LIT>" : OUTPUT_DIR , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : ( "<STR_LIT>" , { } ) , <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT>" : [ ] , <EOL> } ) <EOL> ARGS_COMPLETE = dict ( ARGS_VBOX , ** { <EOL> "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT:1>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : False } , <EOL> "<STR_LIT>" : [ ( <NUM_LIT:0> , { "<STR_LIT:size>" : "<STR_LIT>" } ) ] , <EOL> "<STR_LIT>" : [ ( "<STR_LIT:0>" , { "<STR_LIT>" : "<STR_LIT>" } ) ] , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } ) <EOL> ARGS_BROKEN = dict ( ARGS_EXPORT_DIR , ** { <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT>" : { } , <EOL> } ) <EOL> EXP_ARGS_COMPRESSED = dict ( ARGS_EXPORT_DIR , ** { <EOL> "<STR_LIT>" : True , <EOL> } ) <EOL> EXP_DISKS_LIST = [ <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT:path>" : "<STR_LIT>" , <EOL> } , <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:15> , <EOL> "<STR_LIT>" : <NUM_LIT:15> , <EOL> "<STR_LIT:path>" : "<STR_LIT>" , <EOL> } , <EOL> ] <EOL> EXP_NETWORKS_LIST = [ <EOL> { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT:None>" , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT:test>" } , <EOL> ] <EOL> EXP_PARTIAL_GANETI_DICT = { <EOL> "<STR_LIT>" : { "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : "<STR_LIT:True>" , <EOL> "<STR_LIT:version>" : "<STR_LIT:0>" , <EOL> } <EOL> EXP_GANETI_DICT = { <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : "<STR_LIT:False>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } , <EOL> "<STR_LIT:version>" : "<STR_LIT:0>" , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : { "<STR_LIT:name>" : "<STR_LIT>" } <EOL> } <EOL> EXP_NAME = "<STR_LIT>" <EOL> EXP_VCPUS = <NUM_LIT:1> <EOL> EXP_MEMORY = <NUM_LIT> <EOL> EXPORT_EMPTY = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> EXPORT_DISKS_EMPTY = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> EXPORT_DISKS = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> EXPORT_NETWORKS_EMPTY = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> EXPORT_NETWORKS = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> EXPORT_GANETI_INCOMPLETE = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> EXPORT_GANETI = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> EXPORT_SYSTEM = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def _GetArgs ( args , with_name = False ) : <EOL> options = optparse . Values ( ) <EOL> needed = args <EOL> if with_name : <EOL> needed [ "<STR_LIT:name>" ] = "<STR_LIT>" <EOL> options . _update_loose ( needed ) <EOL> return options <EOL> OPTS_EMPTY = _GetArgs ( ARGS_EMPTY ) <EOL> OPTS_EXPORT_NO_NAME = _GetArgs ( ARGS_EXPORT_DIR ) <EOL> OPTS_EXPORT = _GetArgs ( ARGS_EXPORT_DIR , with_name = True ) <EOL> EXP_OPTS = OPTS_EXPORT_NO_NAME <EOL> EXP_OPTS_COMPRESSED = _GetArgs ( EXP_ARGS_COMPRESSED ) <EOL> OPTS_VBOX = _GetArgs ( ARGS_VBOX ) <EOL> OPTS_COMPLETE = _GetArgs ( ARGS_COMPLETE ) <EOL> OPTS_NONIC_NODISK = _GetArgs ( ARGS_BROKEN ) <EOL> def _GetFullFilename ( file_name ) : <EOL> file_path = "<STR_LIT>" % ( testutils . GetSourceDir ( ) , <EOL> file_name ) <EOL> file_path = os . path . abspath ( file_path ) <EOL> return file_path <EOL> class BetterUnitTest ( unittest . TestCase ) : <EOL> def assertRaisesRegexp ( self , exception , regexp_val , function , * args ) : <EOL> try : <EOL> function ( * args ) <EOL> self . fail ( "<STR_LIT>" % exception ) <EOL> except exception , err : <EOL> regexp = re . compile ( regexp_val ) <EOL> if re . search ( regexp , str ( err ) ) == None : <EOL> self . fail ( "<STR_LIT>" % <EOL> ( regexp_val , str ( err ) ) ) <EOL> class TestOVFImporter ( BetterUnitTest ) : <EOL> def setUp ( self ) : <EOL> self . non_existing_file = _GetFullFilename ( "<STR_LIT>" ) <EOL> self . ganeti_ovf = _GetFullFilename ( "<STR_LIT>" ) <EOL> self . virtualbox_ovf = _GetFullFilename ( "<STR_LIT>" ) <EOL> self . ova_package = _GetFullFilename ( "<STR_LIT>" ) <EOL> self . empty_ovf = _GetFullFilename ( "<STR_LIT>" ) <EOL> self . wrong_extension = _GetFullFilename ( "<STR_LIT>" ) <EOL> self . wrong_ova_archive = _GetFullFilename ( "<STR_LIT>" ) <EOL> self . no_ovf_in_ova = _GetFullFilename ( "<STR_LIT>" ) <EOL> self . importer = None <EOL> def tearDown ( self ) : <EOL> if self . importer : <EOL> self . importer . Cleanup ( ) <EOL> del_dir = os . path . abspath ( OUTPUT_DIR ) <EOL> try : <EOL> shutil . rmtree ( del_dir ) <EOL> except OSError : <EOL> pass <EOL> def testFileDoesNotExistError ( self ) : <EOL> self . assertRaisesRegexp ( errors . OpPrereqError , "<STR_LIT>" , <EOL> ovf . OVFImporter , self . non_existing_file , None ) <EOL> def testWrongInputFileExtensionError ( self ) : <EOL> self . assertRaisesRegexp ( errors . OpPrereqError , <EOL> "<STR_LIT>" , ovf . OVFImporter , <EOL> self . wrong_extension , None ) <EOL> def testOVAUnpackingDirectories ( self ) : <EOL> self . importer = ovf . OVFImporter ( self . ova_package , OPTS_EMPTY ) <EOL> self . assertTrue ( self . importer . input_dir != None ) <EOL> self . assertEquals ( self . importer . output_dir , pathutils . EXPORT_DIR ) <EOL> self . assertTrue ( self . importer . temp_dir != None ) <EOL> def testOVFUnpackingDirectories ( self ) : <EOL> self . importer = ovf . OVFImporter ( self . virtualbox_ovf , <EOL> OPTS_EMPTY ) <EOL> self . assertEquals ( self . importer . input_dir , _GetFullFilename ( "<STR_LIT>" ) ) <EOL> self . assertEquals ( self . importer . output_dir , pathutils . EXPORT_DIR ) <EOL> self . assertEquals ( self . importer . temp_dir , None ) <EOL> def testOVFSetOutputDirDirectories ( self ) : <EOL> self . importer = ovf . OVFImporter ( self . ganeti_ovf , OPTS_EXPORT ) <EOL> self . assertEquals ( self . importer . input_dir , _GetFullFilename ( "<STR_LIT>" ) ) <EOL> self . assertTrue ( OUTPUT_DIR in self . importer . output_dir ) <EOL> self . assertEquals ( self . importer . temp_dir , None ) <EOL> def testWrongOVAArchiveError ( self ) : <EOL> self . assertRaisesRegexp ( errors . OpPrereqError , "<STR_LIT>" , <EOL> ovf . OVFImporter , self . wrong_ova_archive , None ) <EOL> def testNoOVFFileInOVAPackageError ( self ) : <EOL> self . assertRaisesRegexp ( errors . OpPrereqError , "<STR_LIT>" , <EOL> ovf . OVFImporter , self . no_ovf_in_ova , None ) <EOL> def testParseGanetiOvf ( self ) : <EOL> self . importer = ovf . OVFImporter ( self . ganeti_ovf , OPTS_EXPORT_NO_NAME ) <EOL> self . importer . Parse ( ) <EOL> self . assertTrue ( "<STR_LIT>" % OUTPUT_DIR in <EOL> self . importer . output_dir ) <EOL> self . assertEqual ( self . importer . results_disk , GANETI_DISKS ) <EOL> self . assertEqual ( self . importer . results_network , GANETI_NETWORKS ) <EOL> self . assertEqual ( self . importer . results_hypervisor , GANETI_HYPERVISOR ) <EOL> self . assertEqual ( self . importer . results_os , GANETI_OS ) <EOL> self . assertEqual ( self . importer . results_backend , GANETI_BACKEND ) <EOL> self . assertEqual ( self . importer . results_name , GANETI_NAME ) <EOL> self . assertEqual ( self . importer . results_template , GANETI_TEMPLATE ) <EOL> self . assertEqual ( self . importer . results_tags , GANETI_TAGS ) <EOL> self . assertEqual ( self . importer . results_version , GANETI_VERSION ) <EOL> def testParseVirtualboxOvf ( self ) : <EOL> self . importer = ovf . OVFImporter ( self . virtualbox_ovf , OPTS_VBOX ) <EOL> self . importer . Parse ( ) <EOL> self . assertTrue ( "<STR_LIT>" % OUTPUT_DIR in self . importer . output_dir ) <EOL> self . assertEquals ( self . importer . results_disk , VIRTUALBOX_DISKS ) <EOL> self . assertEquals ( self . importer . results_network , VIRTUALBOX_NETWORKS ) <EOL> self . assertEquals ( self . importer . results_hypervisor , CMDARGS_HYPERVISOR ) <EOL> self . assertEquals ( self . importer . results_os , CMDARGS_OS ) <EOL> self . assertEquals ( self . importer . results_backend , VIRTUALBOX_BACKEND ) <EOL> self . assertEquals ( self . importer . results_name , CMDARGS_NAME ) <EOL> self . assertEquals ( self . importer . results_template , VIRTUALBOX_TEMPLATE ) <EOL> self . assertEqual ( self . importer . results_tags , VIRTUALBOX_TAGS ) <EOL> self . assertEqual ( self . importer . results_version , constants . EXPORT_VERSION ) <EOL> def testParseEmptyOvf ( self ) : <EOL> self . importer = ovf . OVFImporter ( self . empty_ovf , OPTS_COMPLETE ) <EOL> self . importer . Parse ( ) <EOL> self . assertTrue ( "<STR_LIT>" % OUTPUT_DIR in self . importer . output_dir ) <EOL> self . assertEquals ( self . importer . results_disk , CMDARGS_DISKS ) <EOL> self . assertEquals ( self . importer . results_network , CMDARGS_NETWORKS ) <EOL> self . assertEquals ( self . importer . results_hypervisor , CMDARGS_HYPERVISOR ) <EOL> self . assertEquals ( self . importer . results_os , CMDARGS_OS ) <EOL> self . assertEquals ( self . importer . results_backend , CMDARGS_BACKEND ) <EOL> self . assertEquals ( self . importer . results_name , CMDARGS_NAME ) <EOL> self . assertEquals ( self . importer . results_template , CMDARGS_TEMPLATE ) <EOL> self . assertEqual ( self . importer . results_tags , CMDARGS_TAGS ) <EOL> self . assertEqual ( self . importer . results_version , constants . EXPORT_VERSION ) <EOL> def testParseNameOptions ( self ) : <EOL> self . importer = ovf . OVFImporter ( self . empty_ovf , OPTS_COMPLETE ) <EOL> results = self . importer . _ParseNameOptions ( ) <EOL> self . assertEquals ( results , CMDARGS_NAME ) <EOL> def testParseHypervisorOptions ( self ) : <EOL> self . importer = ovf . OVFImporter ( self . empty_ovf , OPTS_COMPLETE ) <EOL> results = self . importer . _ParseHypervisorOptions ( ) <EOL> self . assertEquals ( results , CMDARGS_HYPERVISOR ) <EOL> def testParseOSOptions ( self ) : <EOL> self . importer = ovf . OVFImporter ( self . empty_ovf , OPTS_COMPLETE ) <EOL> results = self . importer . _ParseOSOptions ( ) <EOL> self . assertEquals ( results , CMDARGS_OS ) <EOL> def testParseBackendOptions ( self ) : <EOL> self . importer = ovf . OVFImporter ( self . empty_ovf , OPTS_COMPLETE ) <EOL> results = self . importer . _ParseBackendOptions ( ) <EOL> self . assertEquals ( results , CMDARGS_BACKEND ) <EOL> def testParseTags ( self ) : <EOL> self . importer = ovf . OVFImporter ( self . empty_ovf , OPTS_COMPLETE ) <EOL> results = self . importer . _ParseTags ( ) <EOL> self . assertEquals ( results , CMDARGS_TAGS ) <EOL> def testParseNicOptions ( self ) : <EOL> self . importer = ovf . OVFImporter ( self . empty_ovf , OPTS_COMPLETE ) <EOL> results = self . importer . _ParseNicOptions ( ) <EOL> self . assertEquals ( results , CMDARGS_NETWORKS ) <EOL> def testParseDiskOptionsFromGanetiOVF ( self ) : <EOL> self . importer = ovf . OVFImporter ( self . ganeti_ovf , OPTS_EXPORT ) <EOL> os . mkdir ( OUTPUT_DIR ) <EOL> results = self . importer . _GetDiskInfo ( ) <EOL> self . assertEquals ( results , GANETI_DISKS ) <EOL> def testParseTemplateOptions ( self ) : <EOL> self . importer = ovf . OVFImporter ( self . empty_ovf , OPTS_COMPLETE ) <EOL> results = self . importer . _ParseTemplateOptions ( ) <EOL> self . assertEquals ( results , GANETI_TEMPLATE ) <EOL> def testParseDiskOptionsFromCmdLine ( self ) : <EOL> self . importer = ovf . OVFImporter ( self . empty_ovf , OPTS_COMPLETE ) <EOL> os . mkdir ( OUTPUT_DIR ) <EOL> results = self . importer . _ParseDiskOptions ( ) <EOL> self . assertEquals ( results , CMDARGS_DISKS ) <EOL> def testGetDiskFormat ( self ) : <EOL> self . importer = ovf . OVFImporter ( self . ganeti_ovf , OPTS_EXPORT ) <EOL> disks_list = self . importer . ovf_reader . GetDisksNames ( ) <EOL> results = [ self . importer . _GetDiskQemuInfo ( "<STR_LIT>" % <EOL> ( self . importer . input_dir , path ) , "<STR_LIT>" ) <EOL> for ( path , _ ) in disks_list ] <EOL> self . assertEqual ( results , [ "<STR_LIT>" ] ) <EOL> def testNoInstanceNameOVF ( self ) : <EOL> self . importer = ovf . OVFImporter ( self . empty_ovf , OPTS_EXPORT_NO_NAME ) <EOL> self . assertRaisesRegexp ( errors . OpPrereqError , "<STR_LIT>" , <EOL> self . importer . Parse ) <EOL> def testErrorNoOSNameOVF ( self ) : <EOL> self . importer = ovf . OVFImporter ( self . virtualbox_ovf , OPTS_EXPORT ) <EOL> self . assertRaisesRegexp ( errors . OpPrereqError , "<STR_LIT>" , <EOL> self . importer . Parse ) <EOL> def testErrorNoDiskAndNoNetwork ( self ) : <EOL> self . importer = ovf . OVFImporter ( self . empty_ovf , OPTS_NONIC_NODISK ) <EOL> self . assertRaisesRegexp ( errors . OpPrereqError , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , self . importer . Parse ) <EOL> class TestOVFExporter ( BetterUnitTest ) : <EOL> def setUp ( self ) : <EOL> self . exporter = None <EOL> self . wrong_config_file = _GetFullFilename ( "<STR_LIT>" ) <EOL> self . unsafe_path_to_disk = _GetFullFilename ( "<STR_LIT>" ) <EOL> self . disk_image_not_exist = _GetFullFilename ( "<STR_LIT>" ) <EOL> self . empty_config = _GetFullFilename ( "<STR_LIT>" ) <EOL> self . standard_export = _GetFullFilename ( "<STR_LIT>" ) <EOL> self . wrong_network_mode = self . disk_image_not_exist <EOL> self . no_memory = self . disk_image_not_exist <EOL> self . no_vcpus = self . disk_image_not_exist <EOL> self . no_os = _GetFullFilename ( "<STR_LIT>" ) <EOL> self . no_hypervisor = self . disk_image_not_exist <EOL> def tearDown ( self ) : <EOL> if self . exporter : <EOL> self . exporter . Cleanup ( ) <EOL> del_dir = os . path . abspath ( OUTPUT_DIR ) <EOL> try : <EOL> shutil . rmtree ( del_dir ) <EOL> except OSError : <EOL> pass <EOL> def testErrorWrongConfigFile ( self ) : <EOL> self . assertRaisesRegexp ( errors . OpPrereqError , <EOL> "<STR_LIT>" , ovf . OVFExporter , <EOL> self . wrong_config_file , EXP_OPTS ) <EOL> def testErrorPathToTheDiskIncorrect ( self ) : <EOL> self . exporter = ovf . OVFExporter ( self . unsafe_path_to_disk , EXP_OPTS ) <EOL> self . assertRaisesRegexp ( errors . OpPrereqError , "<STR_LIT>" , <EOL> self . exporter . _ParseDisks ) <EOL> def testErrorDiskImageNotExist ( self ) : <EOL> self . exporter = ovf . OVFExporter ( self . disk_image_not_exist , EXP_OPTS ) <EOL> self . assertRaisesRegexp ( errors . OpPrereqError , "<STR_LIT>" , <EOL> self . exporter . _ParseDisks ) <EOL> def testParseNetworks ( self ) : <EOL> self . exporter = ovf . OVFExporter ( self . standard_export , EXP_OPTS ) <EOL> results = self . exporter . _ParseNetworks ( ) <EOL> self . assertEqual ( results , EXP_NETWORKS_LIST ) <EOL> def testErrorWrongNetworkMode ( self ) : <EOL> self . exporter = ovf . OVFExporter ( self . wrong_network_mode , EXP_OPTS ) <EOL> self . assertRaisesRegexp ( errors . OpPrereqError , <EOL> "<STR_LIT>" , self . exporter . _ParseNetworks ) <EOL> def testParseVCPusMem ( self ) : <EOL> self . exporter = ovf . OVFExporter ( self . standard_export , EXP_OPTS ) <EOL> vcpus = self . exporter . _ParseVCPUs ( ) <EOL> memory = self . exporter . _ParseMemory ( ) <EOL> self . assertEqual ( vcpus , EXP_VCPUS ) <EOL> self . assertEqual ( memory , EXP_MEMORY ) <EOL> def testErrorNoVCPUs ( self ) : <EOL> self . exporter = ovf . OVFExporter ( self . no_vcpus , EXP_OPTS ) <EOL> self . assertRaisesRegexp ( errors . OpPrereqError , "<STR_LIT>" , <EOL> self . exporter . _ParseVCPUs ) <EOL> def testErrorNoMemory ( self ) : <EOL> self . exporter = ovf . OVFExporter ( self . no_memory , EXP_OPTS ) <EOL> self . assertRaisesRegexp ( errors . OpPrereqError , "<STR_LIT>" , <EOL> self . exporter . _ParseMemory ) <EOL> def testParseGaneti ( self ) : <EOL> self . exporter = ovf . OVFExporter ( self . standard_export , EXP_OPTS ) <EOL> results = self . exporter . _ParseGaneti ( ) <EOL> self . assertEqual ( results , EXP_GANETI_DICT ) <EOL> def testErrorNoHypervisor ( self ) : <EOL> self . exporter = ovf . OVFExporter ( self . no_hypervisor , EXP_OPTS ) <EOL> self . assertRaisesRegexp ( errors . OpPrereqError , <EOL> "<STR_LIT>" , self . exporter . _ParseGaneti ) <EOL> def testErrorNoOS ( self ) : <EOL> self . exporter = ovf . OVFExporter ( self . no_os , EXP_OPTS ) <EOL> self . assertRaisesRegexp ( errors . OpPrereqError , <EOL> "<STR_LIT>" , self . exporter . _ParseGaneti ) <EOL> def testErrorParseNoInstanceName ( self ) : <EOL> self . exporter = ovf . OVFExporter ( self . empty_config , EXP_OPTS ) <EOL> self . assertRaisesRegexp ( errors . OpPrereqError , "<STR_LIT>" , <EOL> self . exporter . Parse ) <EOL> class TestOVFReader ( BetterUnitTest ) : <EOL> def setUp ( self ) : <EOL> self . wrong_xml_file = _GetFullFilename ( "<STR_LIT>" ) <EOL> self . ganeti_ovf = _GetFullFilename ( "<STR_LIT>" ) <EOL> self . virtualbox_ovf = _GetFullFilename ( "<STR_LIT>" ) <EOL> self . corrupted_ovf = _GetFullFilename ( "<STR_LIT>" ) <EOL> self . wrong_manifest_ovf = _GetFullFilename ( "<STR_LIT>" ) <EOL> self . no_disk_in_ref_ovf = _GetFullFilename ( "<STR_LIT>" ) <EOL> self . empty_ovf = _GetFullFilename ( "<STR_LIT>" ) <EOL> self . compressed_disk = _GetFullFilename ( "<STR_LIT>" ) <EOL> def tearDown ( self ) : <EOL> pass <EOL> def testXMLParsingError ( self ) : <EOL> self . assertRaisesRegexp ( errors . OpPrereqError , <EOL> "<STR_LIT>" , ovf . OVFReader , self . wrong_xml_file ) <EOL> def testFileInResourcesDoesNotExistError ( self ) : <EOL> self . assertRaisesRegexp ( errors . OpPrereqError , "<STR_LIT>" , <EOL> ovf . OVFReader , self . corrupted_ovf ) <EOL> def testWrongManifestChecksumError ( self ) : <EOL> reader = ovf . OVFReader ( self . wrong_manifest_ovf ) <EOL> self . assertRaisesRegexp ( errors . OpPrereqError , <EOL> "<STR_LIT>" , reader . VerifyManifest ) <EOL> def testGoodManifestChecksum ( self ) : <EOL> reader = ovf . OVFReader ( self . ganeti_ovf ) <EOL> self . assertEqual ( reader . VerifyManifest ( ) , None ) <EOL> def testGetDisksNamesOVFCorruptedError ( self ) : <EOL> reader = ovf . OVFReader ( self . no_disk_in_ref_ovf ) <EOL> self . assertRaisesRegexp ( errors . OpPrereqError , <EOL> "<STR_LIT>" , reader . GetDisksNames ) <EOL> def testGetDisksNamesVirtualbox ( self ) : <EOL> reader = ovf . OVFReader ( self . virtualbox_ovf ) <EOL> disk_names = reader . GetDisksNames ( ) <EOL> expected_names = [ <EOL> ( "<STR_LIT>" , None ) , <EOL> ( "<STR_LIT>" , None ) , <EOL> ] <EOL> self . assertEqual ( sorted ( disk_names ) , sorted ( expected_names ) ) <EOL> def testGetDisksNamesEmpty ( self ) : <EOL> reader = ovf . OVFReader ( self . empty_ovf ) <EOL> disk_names = reader . GetDisksNames ( ) <EOL> self . assertEqual ( disk_names , [ ] ) <EOL> def testGetDisksNamesCompressed ( self ) : <EOL> reader = ovf . OVFReader ( self . compressed_disk ) <EOL> disk_names = reader . GetDisksNames ( ) <EOL> self . assertEqual ( disk_names , [ ( "<STR_LIT>" , "<STR_LIT>" ) ] ) <EOL> def testGetNetworkDataGaneti ( self ) : <EOL> reader = ovf . OVFReader ( self . ganeti_ovf ) <EOL> networks = reader . GetNetworkData ( ) <EOL> self . assertEqual ( networks , GANETI_NETWORKS ) <EOL> def testGetNetworkDataVirtualbox ( self ) : <EOL> reader = ovf . OVFReader ( self . virtualbox_ovf ) <EOL> networks = reader . GetNetworkData ( ) <EOL> self . assertEqual ( networks , VIRTUALBOX_NETWORKS ) <EOL> def testGetNetworkDataEmpty ( self ) : <EOL> reader = ovf . OVFReader ( self . empty_ovf ) <EOL> networks = reader . GetNetworkData ( ) <EOL> self . assertEqual ( networks , EMPTY_NETWORKS ) <EOL> def testGetHypervisorDataGaneti ( self ) : <EOL> reader = ovf . OVFReader ( self . ganeti_ovf ) <EOL> hypervisor = reader . GetHypervisorData ( ) <EOL> self . assertEqual ( hypervisor , GANETI_HYPERVISOR ) <EOL> def testGetHypervisorDataEmptyOvf ( self ) : <EOL> reader = ovf . OVFReader ( self . empty_ovf ) <EOL> hypervisor = reader . GetHypervisorData ( ) <EOL> self . assertEqual ( hypervisor , EMPTY_HYPERVISOR ) <EOL> def testGetOSDataGaneti ( self ) : <EOL> reader = ovf . OVFReader ( self . ganeti_ovf ) <EOL> osys = reader . GetOSData ( ) <EOL> self . assertEqual ( osys , GANETI_OS ) <EOL> def testGetOSDataEmptyOvf ( self ) : <EOL> reader = ovf . OVFReader ( self . empty_ovf ) <EOL> osys = reader . GetOSData ( ) <EOL> self . assertEqual ( osys , EMPTY_OS ) <EOL> def testGetBackendDataGaneti ( self ) : <EOL> reader = ovf . OVFReader ( self . ganeti_ovf ) <EOL> backend = reader . GetBackendData ( ) <EOL> self . assertEqual ( backend , GANETI_BACKEND ) <EOL> def testGetBackendDataVirtualbox ( self ) : <EOL> reader = ovf . OVFReader ( self . virtualbox_ovf ) <EOL> backend = reader . GetBackendData ( ) <EOL> self . assertEqual ( backend , VIRTUALBOX_BACKEND ) <EOL> def testGetBackendDataEmptyOvf ( self ) : <EOL> reader = ovf . OVFReader ( self . empty_ovf ) <EOL> backend = reader . GetBackendData ( ) <EOL> self . assertEqual ( backend , EMPTY_BACKEND ) <EOL> def testGetInstanceNameGaneti ( self ) : <EOL> reader = ovf . OVFReader ( self . ganeti_ovf ) <EOL> name = reader . GetInstanceName ( ) <EOL> self . assertEqual ( name , GANETI_NAME ) <EOL> def testGetInstanceNameDataEmptyOvf ( self ) : <EOL> reader = ovf . OVFReader ( self . empty_ovf ) <EOL> name = reader . GetInstanceName ( ) <EOL> self . assertEqual ( name , EMPTY_NAME ) <EOL> def testGetDiskTemplateGaneti ( self ) : <EOL> reader = ovf . OVFReader ( self . ganeti_ovf ) <EOL> name = reader . GetDiskTemplate ( ) <EOL> self . assertEqual ( name , GANETI_TEMPLATE ) <EOL> def testGetDiskTemplateEmpty ( self ) : <EOL> reader = ovf . OVFReader ( self . empty_ovf ) <EOL> name = reader . GetDiskTemplate ( ) <EOL> self . assertEqual ( name , EMPTY_TEMPLATE ) <EOL> def testGetTagsGaneti ( self ) : <EOL> reader = ovf . OVFReader ( self . ganeti_ovf ) <EOL> tags = reader . GetTagsData ( ) <EOL> self . assertEqual ( tags , GANETI_TAGS ) <EOL> def testGetTagsEmpty ( self ) : <EOL> reader = ovf . OVFReader ( self . empty_ovf ) <EOL> tags = reader . GetTagsData ( ) <EOL> self . assertEqual ( tags , EMPTY_TAGS ) <EOL> def testGetVersionGaneti ( self ) : <EOL> reader = ovf . OVFReader ( self . ganeti_ovf ) <EOL> version = reader . GetVersionData ( ) <EOL> self . assertEqual ( version , GANETI_VERSION ) <EOL> def testGetVersionEmpty ( self ) : <EOL> reader = ovf . OVFReader ( self . empty_ovf ) <EOL> version = reader . GetVersionData ( ) <EOL> self . assertEqual ( version , EMPTY_VERSION ) <EOL> class TestOVFWriter ( BetterUnitTest ) : <EOL> def setUp ( self ) : <EOL> self . writer = ovf . OVFWriter ( True ) <EOL> def tearDown ( self ) : <EOL> pass <EOL> def testOVFWriterInit ( self ) : <EOL> result = ET . tostring ( self . writer . tree ) <EOL> self . assertTrue ( EXPORT_EMPTY in result ) <EOL> def testSaveDisksDataEmpty ( self ) : <EOL> self . writer . SaveDisksData ( [ ] ) <EOL> result = ET . tostring ( self . writer . tree ) <EOL> self . assertTrue ( EXPORT_DISKS_EMPTY in result ) <EOL> def testSaveDisksData ( self ) : <EOL> self . writer . SaveDisksData ( EXP_DISKS_LIST ) <EOL> result = ET . tostring ( self . writer . tree ) <EOL> self . assertTrue ( EXPORT_DISKS in result ) <EOL> def testSaveNetworkDataEmpty ( self ) : <EOL> self . writer . SaveNetworksData ( [ ] ) <EOL> result = ET . tostring ( self . writer . tree ) <EOL> self . assertTrue ( EXPORT_NETWORKS_EMPTY in result ) <EOL> def testSaveNetworksData ( self ) : <EOL> self . writer . SaveNetworksData ( EXP_NETWORKS_LIST ) <EOL> result = ET . tostring ( self . writer . tree ) <EOL> self . assertTrue ( EXPORT_NETWORKS in result ) <EOL> def testSaveGanetiDataIncomplete ( self ) : <EOL> self . writer . SaveGanetiData ( EXP_PARTIAL_GANETI_DICT , EXP_NETWORKS_LIST ) <EOL> result = ET . tostring ( self . writer . tree ) <EOL> self . assertTrue ( EXPORT_GANETI_INCOMPLETE in result ) <EOL> def testSaveGanetiDataComplete ( self ) : <EOL> self . writer . SaveGanetiData ( EXP_GANETI_DICT , EXP_NETWORKS_LIST ) <EOL> result = ET . tostring ( self . writer . tree ) <EOL> self . assertTrue ( EXPORT_GANETI in result ) <EOL> def testSaveVirtualSystem ( self ) : <EOL> self . writer . SaveDisksData ( EXP_DISKS_LIST ) <EOL> self . writer . SaveNetworksData ( EXP_NETWORKS_LIST ) <EOL> self . writer . SaveVirtualSystemData ( EXP_NAME , EXP_VCPUS , EXP_MEMORY ) <EOL> result = ET . tostring ( self . writer . tree ) <EOL> self . assertTrue ( EXPORT_SYSTEM in result ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> testutils . GanetiTestProgram ( ) </s>
