2013-10-28 00:59:46 +04:00
# Copyright (C) 2013 Red Hat, Inc.
2013-03-18 01:06:52 +04:00
#
2018-04-04 16:35:41 +03:00
# This work is licensed under the GNU GPLv2 or later.
2018-03-20 22:00:02 +03:00
# See the COPYING file in the top-level directory.
2013-03-18 01:06:52 +04:00
import os
2013-09-20 04:18:12 +04:00
from virtinst import StoragePool , StorageVolume
2019-06-17 04:12:39 +03:00
from virtinst import log
2013-03-18 01:06:52 +04:00
2013-07-05 16:59:58 +04:00
from tests import utils
2013-03-18 01:06:52 +04:00
2014-04-03 02:39:43 +04:00
# pylint: disable=protected-access
2013-04-12 00:32:00 +04:00
2020-08-30 15:54:41 +03:00
BASEPATH = os . path . join ( utils . DATADIR , " storage " )
2013-03-18 01:06:52 +04:00
2013-04-13 22:34:52 +04:00
2013-03-18 01:06:52 +04:00
def createPool ( conn , ptype , poolname = None , fmt = None , target_path = None ,
2017-12-14 20:42:08 +03:00
source_path = None , source_name = None , iqn = None ) :
2013-03-18 01:06:52 +04:00
if poolname is None :
2017-07-19 02:09:58 +03:00
poolname = StoragePool . find_free_name ( conn , " %s -pool " % ptype )
2013-03-18 01:06:52 +04:00
2013-09-20 04:18:12 +04:00
pool_inst = StoragePool ( conn )
pool_inst . name = poolname
pool_inst . type = ptype
2013-03-18 01:06:52 +04:00
2019-07-03 00:03:39 +03:00
if pool_inst . supports_hosts ( ) :
2018-02-08 01:27:56 +03:00
hostobj = pool_inst . hosts . add_new ( )
hostobj . name = " some.random.hostname "
2019-07-03 00:03:39 +03:00
if pool_inst . supports_source_path ( ) :
2013-03-18 01:06:52 +04:00
pool_inst . source_path = source_path or " /some/source/path "
2019-07-03 00:03:39 +03:00
if pool_inst . supports_target_path ( ) :
2019-07-03 03:03:45 +03:00
pool_inst . target_path = ( target_path or
pool_inst . default_target_path ( ) )
2019-07-03 00:03:39 +03:00
if fmt and pool_inst . supports_format ( ) :
2013-03-18 01:06:52 +04:00
pool_inst . format = fmt
2019-07-03 02:55:54 +03:00
if pool_inst . supports_source_name ( ) :
pool_inst . source_name = ( source_name or
pool_inst . default_source_name ( ) )
2019-07-03 00:03:39 +03:00
if iqn and pool_inst . supports_iqn ( ) :
2013-03-18 01:06:52 +04:00
pool_inst . iqn = iqn
return poolCompare ( pool_inst )
2013-04-13 22:34:52 +04:00
2018-02-23 19:42:40 +03:00
def removePool ( poolobj ) :
poolobj . destroy ( )
poolobj . undefine ( )
2013-03-18 01:06:52 +04:00
def poolCompare ( pool_inst ) :
2018-09-02 21:47:34 +03:00
pool_inst . validate ( )
2020-08-30 15:54:41 +03:00
filename = os . path . join ( BASEPATH , pool_inst . name + " .xml " )
2018-08-31 23:52:02 +03:00
out_expect = pool_inst . get_xml ( )
2013-03-18 01:06:52 +04:00
if not os . path . exists ( filename ) :
open ( filename , " w " ) . write ( out_expect )
utils . diff_compare ( out_expect , filename )
return pool_inst . install ( build = True , meter = None , create = True )
2013-04-13 22:34:52 +04:00
2013-07-06 19:20:28 +04:00
def createVol ( conn , poolobj , volname = None , input_vol = None , clone_vol = None ) :
2013-04-13 22:34:52 +04:00
if volname is None :
2013-03-18 01:06:52 +04:00
volname = poolobj . name ( ) + " -vol "
alloc = 5 * 1024 * 1024 * 1024
cap = 10 * 1024 * 1024 * 1024
2013-09-20 04:18:12 +04:00
vol_inst = StorageVolume ( conn )
vol_inst . pool = poolobj
vol_inst . name = volname
vol_inst . capacity = cap
vol_inst . allocation = alloc
2013-03-18 01:06:52 +04:00
2013-09-20 04:18:12 +04:00
vol_inst . permissions . mode = " 0700 "
vol_inst . permissions . owner = " 10736 "
vol_inst . permissions . group = " 10736 "
2013-03-18 01:06:52 +04:00
if input_vol :
2020-09-04 17:41:17 +03:00
vol_inst . set_input_vol ( input_vol )
2013-03-18 01:06:52 +04:00
elif clone_vol :
2013-09-20 04:18:12 +04:00
vol_inst = StorageVolume ( conn , parsexml = clone_vol . XMLDesc ( 0 ) )
2020-09-04 17:41:17 +03:00
vol_inst . set_input_vol ( clone_vol )
2013-09-20 04:18:12 +04:00
vol_inst . name = volname
2013-03-18 01:06:52 +04:00
2013-09-20 04:18:12 +04:00
vol_inst . validate ( )
2020-08-30 15:54:41 +03:00
filename = os . path . join ( BASEPATH , vol_inst . name + " .xml " )
2021-04-06 22:21:00 +03:00
# Format here depends on libvirt-7.2.0 and later
if clone_vol and conn . local_libvirt_version ( ) < 7002000 :
log . debug ( " skip clone compare " )
return
2018-08-31 23:52:02 +03:00
utils . diff_compare ( vol_inst . get_xml ( ) , filename )
2013-03-18 01:06:52 +04:00
return vol_inst . install ( meter = False )
2013-04-13 22:34:52 +04:00
2020-09-18 23:26:28 +03:00
##############
# Test cases #
##############
def testDirPool ( ) :
conn = utils . URIs . open_testdefault_cached ( )
poolobj = createPool ( conn ,
2022-02-27 21:00:56 +03:00
StoragePool . TYPE_DIR , " pool-dir2 " )
2020-09-18 23:26:28 +03:00
invol = createVol ( conn , poolobj )
createVol ( conn , poolobj ,
volname = invol . name ( ) + " input " , input_vol = invol )
createVol ( conn , poolobj ,
volname = invol . name ( ) + " clone " , clone_vol = invol )
removePool ( poolobj )
def testFSPool ( ) :
conn = utils . URIs . open_testdefault_cached ( )
poolobj = createPool ( conn ,
StoragePool . TYPE_FS , " pool-fs " )
invol = createVol ( conn , poolobj )
createVol ( conn , poolobj ,
volname = invol . name ( ) + " input " , input_vol = invol )
createVol ( conn , poolobj ,
volname = invol . name ( ) + " clone " , clone_vol = invol )
removePool ( poolobj )
def testNetFSPool ( ) :
conn = utils . URIs . open_testdefault_cached ( )
poolobj = createPool ( conn ,
StoragePool . TYPE_NETFS , " pool-netfs " )
invol = createVol ( conn , poolobj )
createVol ( conn , poolobj ,
volname = invol . name ( ) + " input " , input_vol = invol )
createVol ( conn , poolobj ,
volname = invol . name ( ) + " clone " , clone_vol = invol )
removePool ( poolobj )
def testLVPool ( ) :
conn = utils . URIs . open_testdefault_cached ( )
poolobj = createPool ( conn ,
StoragePool . TYPE_LOGICAL ,
" pool-logical " ,
source_name = " pool-logical " )
invol = createVol ( conn , poolobj )
createVol ( conn , poolobj ,
volname = invol . name ( ) + " input " , input_vol = invol )
createVol ( conn ,
poolobj , volname = invol . name ( ) + " clone " , clone_vol = invol )
removePool ( poolobj )
# Test parsing source name for target path
poolobj = createPool ( conn , StoragePool . TYPE_LOGICAL ,
" pool-logical-target-srcname " ,
target_path = " /dev/vgfoobar " )
removePool ( poolobj )
# Test with source name
poolobj = createPool ( conn ,
StoragePool . TYPE_LOGICAL , " pool-logical-srcname " ,
source_name = " vgname " )
removePool ( poolobj )
def testDiskPool ( ) :
conn = utils . URIs . open_testdefault_cached ( )
poolobj = createPool ( conn ,
StoragePool . TYPE_DISK ,
" pool-disk " , fmt = " auto " ,
target_path = " /some/target/path " )
invol = createVol ( conn , poolobj )
createVol ( conn , poolobj ,
volname = invol . name ( ) + " input " , input_vol = invol )
createVol ( conn , poolobj ,
volname = invol . name ( ) + " clone " , clone_vol = invol )
removePool ( poolobj )
def testISCSIPool ( ) :
conn = utils . URIs . open_testdefault_cached ( )
poolobj = createPool ( conn ,
StoragePool . TYPE_ISCSI , " pool-iscsi " ,
iqn = " foo.bar.baz.iqn " )
removePool ( poolobj )
def testSCSIPool ( ) :
conn = utils . URIs . open_testdefault_cached ( )
poolobj = createPool ( conn , StoragePool . TYPE_SCSI , " pool-scsi " )
removePool ( poolobj )
def testMpathPool ( ) :
conn = utils . URIs . open_testdefault_cached ( )
poolobj = createPool ( conn , StoragePool . TYPE_MPATH , " pool-mpath " )
removePool ( poolobj )
def testGlusterPool ( ) :
conn = utils . URIs . open_testdefault_cached ( )
poolobj = createPool ( conn ,
StoragePool . TYPE_GLUSTER , " pool-gluster " )
removePool ( poolobj )
def testRBDPool ( ) :
conn = utils . URIs . open_testdefault_cached ( )
poolobj = createPool ( conn ,
StoragePool . TYPE_RBD , " pool-rbd " )
removePool ( poolobj )
def testMisc ( ) :
conn = utils . URIs . open_testdefault_cached ( )
# Misc coverage testing
vol = StorageVolume ( conn )
assert vol . is_size_conflict ( ) [ 0 ] is False
fullconn = utils . URIs . open_testdriver_cached ( )
2022-02-27 21:30:46 +03:00
glusterpool = fullconn . storagePoolLookupByName ( " pool-gluster " )
2022-02-27 20:54:39 +03:00
diskpool = fullconn . storagePoolLookupByName ( " pool-logical " )
2020-09-18 23:26:28 +03:00
glustervol = StorageVolume ( fullconn )
glustervol . pool = glusterpool
2020-09-20 23:44:24 +03:00
assert glustervol . supports_format ( ) is False
2020-09-18 23:26:28 +03:00
diskvol = StorageVolume ( fullconn )
diskvol . pool = diskpool
assert diskvol . supports_format ( ) is False
glusterpool . destroy ( )
StoragePool . ensure_pool_is_running ( glusterpool )
# Check pool collision detection
2022-02-27 21:30:46 +03:00
name = StoragePool . find_free_name ( fullconn , " pool-gluster " )
assert name == " pool-gluster-1 "
2020-09-18 23:26:28 +03:00
def testEnumerateLogical ( ) :
conn = utils . URIs . open_testdefault_cached ( )
lst = StoragePool . pool_list_from_sources ( conn ,
StoragePool . TYPE_LOGICAL )
assert lst == [ " testvg1 " , " testvg2 " ]