2013-10-28 04:59:46 +08:00
|
|
|
# Copyright (C) 2013 Red Hat, Inc.
|
2013-03-18 05:06:52 +08:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2013-10-28 04:59:47 +08:00
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
2013-03-18 05:06:52 +08:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
# MA 02110-1301 USA.
|
|
|
|
|
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
|
|
|
|
|
2013-09-20 08:18:12 +08:00
|
|
|
pool_inst.validate()
|
2013-03-18 05:06:52 +08:00
|
|
|
return poolCompare(pool_inst)
|
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2013-03-18 05:06:52 +08:00
|
|
|
def poolCompare(pool_inst):
|
|
|
|
filename = os.path.join(basepath, pool_inst.name + ".xml")
|
|
|
|
out_expect = pool_inst.get_xml_config()
|
|
|
|
|
|
|
|
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")
|
|
|
|
utils.diff_compare(vol_inst.get_xml_config(), filename)
|
|
|
|
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):
|
|
|
|
|
|
|
|
def setUp(self):
|
2013-07-05 20:59:58 +08:00
|
|
|
self.conn = utils.open_testdefault()
|
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)
|
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)
|
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)
|
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)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
# Test parsing source name for target path
|
2013-09-20 08:18:12 +08:00
|
|
|
createPool(self.conn, StoragePool.TYPE_LOGICAL,
|
2013-03-18 05:06:52 +08:00
|
|
|
"pool-logical-target-srcname",
|
|
|
|
target_path="/dev/vgfoobar")
|
|
|
|
|
|
|
|
# Test with source name
|
2013-08-09 09:42:44 +08:00
|
|
|
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")
|
|
|
|
|
|
|
|
# Test creating with many devices
|
2013-09-20 08:18:12 +08:00
|
|
|
# XXX: Need to wire this up
|
2014-05-02 22:20:59 +08:00
|
|
|
# createPool(self.conn,
|
|
|
|
# StoragePool.TYPE_LOGICAL, "pool-logical-manydev",
|
|
|
|
# source_path=["/tmp/path1", "/tmp/path2", "/tmp/path3"],
|
|
|
|
# target_path=None)
|
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)
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
def testISCSIPool(self):
|
2013-08-09 09:42:44 +08:00
|
|
|
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")
|
|
|
|
|
|
|
|
def testSCSIPool(self):
|
2013-09-20 08:18:12 +08:00
|
|
|
createPool(self.conn, StoragePool.TYPE_SCSI, "pool-scsi")
|
2013-03-18 05:06:52 +08:00
|
|
|
|
|
|
|
def testMpathPool(self):
|
2013-09-20 08:18:12 +08:00
|
|
|
createPool(self.conn, StoragePool.TYPE_MPATH, "pool-mpath")
|
2013-03-18 05:06:52 +08:00
|
|
|
|
2014-02-12 17:39:50 +08:00
|
|
|
def testGlusterPool(self):
|
2014-03-07 00:29:23 +08:00
|
|
|
if not self.conn.check_support(self.conn.SUPPORT_CONN_POOL_GLUSTERFS):
|
|
|
|
raise unittest.SkipTest("Gluster pools not supported with this "
|
|
|
|
"libvirt version.")
|
|
|
|
|
2014-02-12 17:39:50 +08:00
|
|
|
createPool(self.conn, StoragePool.TYPE_GLUSTER, "pool-gluster")
|
|
|
|
|
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))
|
2013-03-18 05:06:52 +08:00
|
|
|
poolCompare(pool)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|