2013-10-28 04:59:46 +08:00
|
|
|
# Copyright (C) 2013 Red Hat, Inc.
|
2013-03-18 05:06:52 +08:00
|
|
|
#
|
2018-04-04 21:35:41 +08:00
|
|
|
# This work is licensed under the GNU GPLv2 or later.
|
2018-03-21 03:00:02 +08:00
|
|
|
# See the COPYING file in the top-level directory.
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-01-30 21:41:28 +08:00
|
|
|
import logging
|
2013-03-18 05:06:52 +08:00
|
|
|
import os
|
|
|
|
import unittest
|
|
|
|
|
2013-09-20 08:18:12 +08:00
|
|
|
from virtinst import StoragePool, StorageVolume
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-07-05 20:59:58 +08:00
|
|
|
from tests import utils
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-04-03 06:39:43 +08:00
|
|
|
# pylint: disable=protected-access
|
2013-04-12 04:32:00 +08:00
|
|
|
# Access to protected member, needed to unittest stuff
|
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
basepath = os.path.join(os.getcwd(), "tests", "storage-xml")
|
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
def createPool(conn, ptype, poolname=None, fmt=None, target_path=None,
|
2017-12-15 01:42:08 +08:00
|
|
|
source_path=None, source_name=None, iqn=None):
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
if poolname is None:
|
2017-07-19 07:09:58 +08:00
|
|
|
poolname = StoragePool.find_free_name(conn, "%s-pool" % ptype)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-09-20 08:18:12 +08:00
|
|
|
pool_inst = StoragePool(conn)
|
|
|
|
pool_inst.name = poolname
|
|
|
|
pool_inst.type = ptype
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-12-10 05:05:02 +08:00
|
|
|
if pool_inst.supports_property("hosts"):
|
2018-02-08 06:27:56 +08:00
|
|
|
hostobj = pool_inst.hosts.add_new()
|
|
|
|
hostobj.name = "some.random.hostname"
|
2013-09-20 08:18:12 +08:00
|
|
|
if pool_inst.supports_property("source_path"):
|
2013-03-18 05:06:52 +08:00
|
|
|
pool_inst.source_path = source_path or "/some/source/path"
|
2013-09-20 08:18:12 +08:00
|
|
|
if pool_inst.supports_property("target_path"):
|
2013-03-18 05:06:52 +08:00
|
|
|
pool_inst.target_path = target_path or "/some/target/path"
|
2013-09-20 08:18:12 +08:00
|
|
|
if fmt and pool_inst.supports_property("format"):
|
2013-03-18 05:06:52 +08:00
|
|
|
pool_inst.format = fmt
|
2013-09-20 08:18:12 +08:00
|
|
|
if source_name and pool_inst.supports_property("source_name"):
|
2013-03-18 05:06:52 +08:00
|
|
|
pool_inst.source_name = source_name
|
2013-09-20 08:18:12 +08:00
|
|
|
if iqn and pool_inst.supports_property("iqn"):
|
2013-03-18 05:06:52 +08:00
|
|
|
pool_inst.iqn = iqn
|
|
|
|
|
|
|
|
return poolCompare(pool_inst)
|
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2018-02-24 00:42:40 +08:00
|
|
|
def removePool(poolobj):
|
|
|
|
poolobj.destroy()
|
|
|
|
poolobj.undefine()
|
|
|
|
|
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
def poolCompare(pool_inst):
|
2018-09-03 02:47:34 +08:00
|
|
|
pool_inst.validate()
|
2013-03-18 05:06:52 +08:00
|
|
|
filename = os.path.join(basepath, pool_inst.name + ".xml")
|
2018-09-01 04:52:02 +08:00
|
|
|
out_expect = pool_inst.get_xml()
|
2013-03-18 05:06:52 +08: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-14 02:34:52 +08:00
|
|
|
|
2013-07-06 23:20:28 +08:00
|
|
|
def createVol(conn, poolobj, volname=None, input_vol=None, clone_vol=None):
|
2013-04-14 02:34:52 +08:00
|
|
|
if volname is None:
|
2013-03-18 05:06:52 +08:00
|
|
|
volname = poolobj.name() + "-vol"
|
|
|
|
|
2013-12-03 02:41:52 +08:00
|
|
|
# Format here depends on libvirt-1.2.0 and later
|
|
|
|
if clone_vol and conn.local_libvirt_version() < 1002000:
|
2014-01-30 00:36:19 +08:00
|
|
|
logging.debug("skip clone compare")
|
2013-12-03 02:41:52 +08:00
|
|
|
return
|
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
alloc = 5 * 1024 * 1024 * 1024
|
|
|
|
cap = 10 * 1024 * 1024 * 1024
|
2013-09-20 08:18:12 +08:00
|
|
|
vol_inst = StorageVolume(conn)
|
|
|
|
vol_inst.pool = poolobj
|
|
|
|
vol_inst.name = volname
|
|
|
|
vol_inst.capacity = cap
|
|
|
|
vol_inst.allocation = alloc
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-09-20 08:18:12 +08:00
|
|
|
vol_inst.permissions.mode = "0700"
|
|
|
|
vol_inst.permissions.owner = "10736"
|
|
|
|
vol_inst.permissions.group = "10736"
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
if input_vol:
|
|
|
|
vol_inst.input_vol = input_vol
|
2013-09-20 08:18:12 +08:00
|
|
|
vol_inst.sync_input_vol()
|
2013-03-18 05:06:52 +08:00
|
|
|
elif clone_vol:
|
2013-09-20 08:18:12 +08:00
|
|
|
vol_inst = StorageVolume(conn, parsexml=clone_vol.XMLDesc(0))
|
|
|
|
vol_inst.input_vol = clone_vol
|
|
|
|
vol_inst.sync_input_vol()
|
|
|
|
vol_inst.name = volname
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2013-09-20 08:18:12 +08:00
|
|
|
vol_inst.validate()
|
2013-03-18 05:06:52 +08:00
|
|
|
filename = os.path.join(basepath, vol_inst.name + ".xml")
|
2018-09-01 04:52:02 +08:00
|
|
|
utils.diff_compare(vol_inst.get_xml(), filename)
|
2013-03-18 05:06:52 +08:00
|
|
|
return vol_inst.install(meter=False)
|
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
class TestStorage(unittest.TestCase):
|
2018-02-23 03:57:10 +08:00
|
|
|
@property
|
|
|
|
def conn(self):
|
|
|
|
return utils.URIs.open_testdefault_cached()
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
def testDirPool(self):
|
2013-08-09 09:42:44 +08:00
|
|
|
poolobj = createPool(self.conn,
|
2013-09-20 08:18:12 +08:00
|
|
|
StoragePool.TYPE_DIR, "pool-dir")
|
2013-07-06 23:20:28 +08:00
|
|
|
invol = createVol(self.conn, poolobj)
|
|
|
|
createVol(self.conn, poolobj,
|
|
|
|
volname=invol.name() + "input", input_vol=invol)
|
|
|
|
createVol(self.conn, poolobj,
|
|
|
|
volname=invol.name() + "clone", clone_vol=invol)
|
2018-02-24 00:42:40 +08:00
|
|
|
removePool(poolobj)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
def testFSPool(self):
|
2013-08-09 09:42:44 +08:00
|
|
|
poolobj = createPool(self.conn,
|
2013-09-20 08:18:12 +08:00
|
|
|
StoragePool.TYPE_FS, "pool-fs")
|
2013-07-06 23:20:28 +08:00
|
|
|
invol = createVol(self.conn, poolobj)
|
|
|
|
createVol(self.conn, poolobj,
|
|
|
|
volname=invol.name() + "input", input_vol=invol)
|
|
|
|
createVol(self.conn, poolobj,
|
|
|
|
volname=invol.name() + "clone", clone_vol=invol)
|
2018-02-24 00:42:40 +08:00
|
|
|
removePool(poolobj)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
def testNetFSPool(self):
|
2013-08-09 09:42:44 +08:00
|
|
|
poolobj = createPool(self.conn,
|
2013-09-20 08:18:12 +08:00
|
|
|
StoragePool.TYPE_NETFS, "pool-netfs")
|
2013-07-06 23:20:28 +08:00
|
|
|
invol = createVol(self.conn, poolobj)
|
|
|
|
createVol(self.conn, poolobj,
|
|
|
|
volname=invol.name() + "input", input_vol=invol)
|
|
|
|
createVol(self.conn, poolobj,
|
|
|
|
volname=invol.name() + "clone", clone_vol=invol)
|
2018-02-24 00:42:40 +08:00
|
|
|
removePool(poolobj)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
def testLVPool(self):
|
2013-08-09 09:42:44 +08:00
|
|
|
poolobj = createPool(self.conn,
|
2013-09-20 08:18:12 +08:00
|
|
|
StoragePool.TYPE_LOGICAL,
|
2013-07-26 10:06:28 +08:00
|
|
|
"pool-logical",
|
|
|
|
target_path="/dev/pool-logical")
|
2013-07-06 23:20:28 +08:00
|
|
|
invol = createVol(self.conn, poolobj)
|
|
|
|
createVol(self.conn, poolobj,
|
|
|
|
volname=invol.name() + "input", input_vol=invol)
|
|
|
|
createVol(self.conn,
|
|
|
|
poolobj, volname=invol.name() + "clone", clone_vol=invol)
|
2018-02-24 00:42:40 +08:00
|
|
|
removePool(poolobj)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
# Test parsing source name for target path
|
2018-02-24 00:42:40 +08:00
|
|
|
poolobj = createPool(self.conn, StoragePool.TYPE_LOGICAL,
|
2013-03-18 05:06:52 +08:00
|
|
|
"pool-logical-target-srcname",
|
|
|
|
target_path="/dev/vgfoobar")
|
2018-02-24 00:42:40 +08:00
|
|
|
removePool(poolobj)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
# Test with source name
|
2018-02-24 00:42:40 +08:00
|
|
|
poolobj = createPool(self.conn,
|
2013-09-20 08:18:12 +08:00
|
|
|
StoragePool.TYPE_LOGICAL, "pool-logical-srcname",
|
2013-03-18 05:06:52 +08:00
|
|
|
source_name="vgname")
|
2018-02-24 00:42:40 +08:00
|
|
|
removePool(poolobj)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
def testDiskPool(self):
|
2013-08-09 09:42:44 +08:00
|
|
|
poolobj = createPool(self.conn,
|
2013-09-20 08:18:12 +08:00
|
|
|
StoragePool.TYPE_DISK,
|
2013-03-18 05:06:52 +08:00
|
|
|
"pool-disk", fmt="dos")
|
2013-07-06 23:20:28 +08:00
|
|
|
invol = createVol(self.conn, poolobj)
|
|
|
|
createVol(self.conn, poolobj,
|
|
|
|
volname=invol.name() + "input", input_vol=invol)
|
|
|
|
createVol(self.conn, poolobj,
|
|
|
|
volname=invol.name() + "clone", clone_vol=invol)
|
2018-02-24 00:42:40 +08:00
|
|
|
removePool(poolobj)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
def testISCSIPool(self):
|
2018-02-24 00:42:40 +08:00
|
|
|
poolobj = createPool(self.conn,
|
2013-09-20 08:18:12 +08:00
|
|
|
StoragePool.TYPE_ISCSI, "pool-iscsi",
|
2013-03-18 05:06:52 +08:00
|
|
|
iqn="foo.bar.baz.iqn")
|
2018-02-24 00:42:40 +08:00
|
|
|
removePool(poolobj)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
def testSCSIPool(self):
|
2018-02-24 00:42:40 +08:00
|
|
|
poolobj = createPool(self.conn, StoragePool.TYPE_SCSI, "pool-scsi")
|
|
|
|
removePool(poolobj)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
def testMpathPool(self):
|
2018-02-24 00:42:40 +08:00
|
|
|
poolobj = createPool(self.conn, StoragePool.TYPE_MPATH, "pool-mpath")
|
|
|
|
removePool(poolobj)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-02-12 17:39:50 +08:00
|
|
|
def testGlusterPool(self):
|
2018-02-24 00:42:40 +08:00
|
|
|
poolobj = createPool(self.conn,
|
|
|
|
StoragePool.TYPE_GLUSTER, "pool-gluster")
|
|
|
|
removePool(poolobj)
|
2014-02-12 17:39:50 +08:00
|
|
|
|
2014-12-10 05:05:02 +08:00
|
|
|
|
|
|
|
##############################
|
|
|
|
# Tests for pool-sources API #
|
|
|
|
##############################
|
|
|
|
|
2013-09-20 08:18:12 +08:00
|
|
|
def _enumerateCompare(self, name, pool_list):
|
2013-03-18 05:06:52 +08:00
|
|
|
for pool in pool_list:
|
2013-09-20 08:18:12 +08:00
|
|
|
pool.name = name + str(pool_list.index(pool))
|
2018-02-24 00:42:40 +08:00
|
|
|
poolobj = poolCompare(pool)
|
|
|
|
removePool(poolobj)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
def testEnumerateLogical(self):
|
|
|
|
name = "pool-logical-list"
|
2013-09-20 08:18:12 +08:00
|
|
|
lst = StoragePool.pool_list_from_sources(self.conn,
|
|
|
|
StoragePool.TYPE_LOGICAL)
|
|
|
|
self._enumerateCompare(name, lst)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
def testEnumerateNetFS(self):
|
|
|
|
name = "pool-netfs-list"
|
|
|
|
host = "example.com"
|
2013-09-20 08:18:12 +08:00
|
|
|
lst = StoragePool.pool_list_from_sources(self.conn,
|
|
|
|
StoragePool.TYPE_NETFS,
|
2013-03-18 05:06:52 +08:00
|
|
|
host=host)
|
2013-09-20 08:18:12 +08:00
|
|
|
self._enumerateCompare(name, lst)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
def testEnumerateiSCSI(self):
|
|
|
|
host = "example.com"
|
2013-09-20 08:18:12 +08:00
|
|
|
lst = StoragePool.pool_list_from_sources(self.conn,
|
|
|
|
StoragePool.TYPE_ISCSI,
|
2013-03-18 05:06:52 +08:00
|
|
|
host=host)
|
|
|
|
self.assertTrue(len(lst) == 0)
|