<s> """<STR_LIT>""" <EOL> import os <EOL> import unittest <EOL> from ganeti import utils <EOL> from ganeti import compat <EOL> from ganeti import vcluster <EOL> from ganeti import pathutils <EOL> import testutils <EOL> _ENV_DOES_NOT_EXIST = "<STR_LIT>" <EOL> _ENV_TEST = "<STR_LIT>" <EOL> class _EnvVarTest ( testutils . GanetiTestCase ) : <EOL> def setUp ( self ) : <EOL> testutils . GanetiTestCase . setUp ( self ) <EOL> os . environ . pop ( _ENV_DOES_NOT_EXIST , None ) <EOL> os . environ . pop ( _ENV_TEST , None ) <EOL> class TestGetRootDirectory ( _EnvVarTest ) : <EOL> def test ( self ) : <EOL> assert os . getenv ( _ENV_TEST ) is None <EOL> self . assertEqual ( vcluster . _GetRootDirectory ( _ENV_DOES_NOT_EXIST ) , "<STR_LIT>" ) <EOL> self . assertEqual ( vcluster . _GetRootDirectory ( _ENV_TEST ) , "<STR_LIT>" ) <EOL> os . environ [ _ENV_TEST ] = "<STR_LIT>" <EOL> self . assertEqual ( vcluster . _GetRootDirectory ( _ENV_TEST ) , "<STR_LIT>" ) <EOL> os . environ [ _ENV_TEST ] = "<STR_LIT>" <EOL> self . assertRaises ( RuntimeError , vcluster . _GetRootDirectory , _ENV_TEST ) <EOL> class TestGetHostname ( _EnvVarTest ) : <EOL> def test ( self ) : <EOL> assert os . getenv ( _ENV_TEST ) is None <EOL> self . assertEqual ( vcluster . _GetRootDirectory ( _ENV_DOES_NOT_EXIST ) , "<STR_LIT>" ) <EOL> self . assertEqual ( vcluster . _GetRootDirectory ( _ENV_TEST ) , "<STR_LIT>" ) <EOL> os . environ [ _ENV_TEST ] = "<STR_LIT>" <EOL> self . assertEqual ( vcluster . _GetHostname ( _ENV_TEST ) , "<STR_LIT>" ) <EOL> class TestCheckHostname ( _EnvVarTest ) : <EOL> def test ( self ) : <EOL> for i in [ "<STR_LIT:/>" , "<STR_LIT>" ] : <EOL> self . assertRaises ( RuntimeError , vcluster . _CheckHostname , i ) <EOL> class TestPreparePaths ( _EnvVarTest ) : <EOL> def testInvalidParameters ( self ) : <EOL> self . assertRaises ( RuntimeError , vcluster . _PreparePaths , <EOL> None , "<STR_LIT>" ) <EOL> self . assertRaises ( RuntimeError , vcluster . _PreparePaths , <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> def testNonNormalizedRootDir ( self ) : <EOL> self . assertRaises ( AssertionError , vcluster . _PreparePaths , <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> def testInvalidHostname ( self ) : <EOL> self . assertRaises ( RuntimeError , vcluster . _PreparePaths , "<STR_LIT>" , "<STR_LIT:/>" ) <EOL> def testPathHostnameMismatch ( self ) : <EOL> self . assertRaises ( RuntimeError , vcluster . _PreparePaths , <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> def testNoVirtCluster ( self ) : <EOL> for i in [ "<STR_LIT>" , None ] : <EOL> self . assertEqual ( vcluster . _PreparePaths ( i , i ) , ( "<STR_LIT>" , "<STR_LIT>" , None ) ) <EOL> def testVirtCluster ( self ) : <EOL> self . assertEqual ( vcluster . _PreparePaths ( "<STR_LIT>" , <EOL> "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> class TestMakeNodeRoot ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> self . assertRaises ( RuntimeError , vcluster . MakeNodeRoot , "<STR_LIT>" , "<STR_LIT:/>" ) <EOL> for i in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> self . assertEqual ( vcluster . MakeNodeRoot ( i , "<STR_LIT>" ) , <EOL> "<STR_LIT>" ) <EOL> class TestEnvironmentForHost ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> self . assertEqual ( vcluster . EnvironmentForHost ( "<STR_LIT>" , <EOL> _basedir = None ) , <EOL> { } ) <EOL> for i in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> self . assertEqual ( vcluster . EnvironmentForHost ( i , _basedir = "<STR_LIT>" ) , { <EOL> vcluster . _ROOTDIR_ENVNAME : "<STR_LIT>" % i , <EOL> vcluster . _HOSTNAME_ENVNAME : i , <EOL> } ) <EOL> class TestExchangeNodeRoot ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> result = vcluster . ExchangeNodeRoot ( "<STR_LIT>" , "<STR_LIT>" , <EOL> _basedir = None , _noderoot = None ) <EOL> self . assertEqual ( result , "<STR_LIT>" ) <EOL> self . assertRaises ( RuntimeError , vcluster . ExchangeNodeRoot , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> _basedir = "<STR_LIT>" , <EOL> _noderoot = "<STR_LIT>" ) <EOL> result = vcluster . ExchangeNodeRoot ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> _basedir = "<STR_LIT>" , <EOL> _noderoot = "<STR_LIT>" ) <EOL> self . assertEqual ( result , "<STR_LIT>" ) <EOL> class TestAddNodePrefix ( unittest . TestCase ) : <EOL> def testRelativePath ( self ) : <EOL> self . assertRaises ( AssertionError , vcluster . AddNodePrefix , <EOL> "<STR_LIT>" , _noderoot = None ) <EOL> def testRelativeNodeRoot ( self ) : <EOL> self . assertRaises ( AssertionError , vcluster . AddNodePrefix , <EOL> "<STR_LIT>" , _noderoot = "<STR_LIT>" ) <EOL> def test ( self ) : <EOL> path = vcluster . AddNodePrefix ( "<STR_LIT>" , <EOL> _noderoot = "<STR_LIT>" ) <EOL> self . assertEqual ( path , "<STR_LIT>" ) <EOL> self . assertEqual ( vcluster . AddNodePrefix ( "<STR_LIT>" , _noderoot = "<STR_LIT>" ) , <EOL> "<STR_LIT>" ) <EOL> class TestRemoveNodePrefix ( unittest . TestCase ) : <EOL> def testRelativePath ( self ) : <EOL> self . assertRaises ( AssertionError , vcluster . _RemoveNodePrefix , <EOL> "<STR_LIT>" , _noderoot = None ) <EOL> def testOutsideNodeRoot ( self ) : <EOL> self . assertRaises ( RuntimeError , vcluster . _RemoveNodePrefix , <EOL> "<STR_LIT>" , _noderoot = "<STR_LIT>" ) <EOL> self . assertRaises ( RuntimeError , vcluster . _RemoveNodePrefix , <EOL> "<STR_LIT>" , _noderoot = "<STR_LIT>" ) <EOL> def test ( self ) : <EOL> path = vcluster . _RemoveNodePrefix ( "<STR_LIT>" , <EOL> _noderoot = "<STR_LIT>" ) <EOL> self . assertEqual ( path , "<STR_LIT>" ) <EOL> path = vcluster . _RemoveNodePrefix ( "<STR_LIT>" , _noderoot = None ) <EOL> self . assertEqual ( path , "<STR_LIT>" ) <EOL> class TestMakeVirtualPath ( unittest . TestCase ) : <EOL> def testRelativePath ( self ) : <EOL> self . assertRaises ( AssertionError , vcluster . MakeVirtualPath , <EOL> "<STR_LIT>" , _noderoot = None ) <EOL> def testOutsideNodeRoot ( self ) : <EOL> self . assertRaises ( RuntimeError , vcluster . MakeVirtualPath , <EOL> "<STR_LIT>" , _noderoot = "<STR_LIT>" ) <EOL> def testWithNodeRoot ( self ) : <EOL> path = vcluster . MakeVirtualPath ( "<STR_LIT>" , <EOL> _noderoot = "<STR_LIT>" ) <EOL> self . assertEqual ( path , "<STR_LIT>" % vcluster . _VIRT_PATH_PREFIX ) <EOL> def testNormal ( self ) : <EOL> self . assertEqual ( vcluster . MakeVirtualPath ( "<STR_LIT>" , _noderoot = None ) , <EOL> "<STR_LIT>" ) <EOL> def testWhitelisted ( self ) : <EOL> mvp = vcluster . MakeVirtualPath <EOL> for path in vcluster . _VPATH_WHITELIST : <EOL> self . assertEqual ( mvp ( path ) , path ) <EOL> self . assertEqual ( mvp ( path , _noderoot = None ) , path ) <EOL> self . assertEqual ( mvp ( path , _noderoot = "<STR_LIT>" ) , path ) <EOL> class TestLocalizeVirtualPath ( unittest . TestCase ) : <EOL> def testWrongPrefix ( self ) : <EOL> self . assertRaises ( RuntimeError , vcluster . LocalizeVirtualPath , <EOL> "<STR_LIT>" , _noderoot = "<STR_LIT>" ) <EOL> def testCorrectPrefixRelativePath ( self ) : <EOL> self . assertRaises ( AssertionError , vcluster . LocalizeVirtualPath , <EOL> vcluster . _VIRT_PATH_PREFIX + "<STR_LIT>" , <EOL> _noderoot = "<STR_LIT>" ) <EOL> def testWithNodeRoot ( self ) : <EOL> lvp = vcluster . LocalizeVirtualPath <EOL> virtpath1 = "<STR_LIT>" % vcluster . _VIRT_PATH_PREFIX <EOL> virtpath2 = "<STR_LIT>" % vcluster . _VIRT_PATH_PREFIX <EOL> for i in [ virtpath1 , virtpath2 ] : <EOL> result = lvp ( i , _noderoot = "<STR_LIT>" ) <EOL> self . assertEqual ( result , "<STR_LIT>" ) <EOL> def testNormal ( self ) : <EOL> self . assertEqual ( vcluster . LocalizeVirtualPath ( "<STR_LIT>" , _noderoot = None ) , <EOL> "<STR_LIT>" ) <EOL> def testWhitelisted ( self ) : <EOL> lvp = vcluster . LocalizeVirtualPath <EOL> for path in vcluster . _VPATH_WHITELIST : <EOL> self . assertEqual ( lvp ( path ) , path ) <EOL> self . assertEqual ( lvp ( path , _noderoot = None ) , path ) <EOL> self . assertEqual ( lvp ( path , _noderoot = "<STR_LIT>" ) , path ) <EOL> class TestVirtualPathPrefix ( unittest . TestCase ) : <EOL> def test ( self ) : <EOL> self . assertTrue ( os . path . isabs ( vcluster . _VIRT_PATH_PREFIX ) ) <EOL> self . assertEqual ( os . path . normcase ( vcluster . _VIRT_PATH_PREFIX ) , <EOL> vcluster . _VIRT_PATH_PREFIX ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> testutils . GanetiTestProgram ( ) </s>
