mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-20 14:03:52 +03:00
tests: Drop most unittest usage from virtinst tests
Kill usage of the TestCase class, move more to pytest standard style Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
b79ee9565f
commit
fa322588b4
@ -4,7 +4,6 @@
|
|||||||
# See the COPYING file in the top-level directory.
|
# See the COPYING file in the top-level directory.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import unittest
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -17,18 +16,18 @@ from virtinst import DomainCapabilities
|
|||||||
DATADIR = utils.DATADIR + "/capabilities"
|
DATADIR = utils.DATADIR + "/capabilities"
|
||||||
|
|
||||||
|
|
||||||
class TestCapabilities(unittest.TestCase):
|
def _buildCaps(filename):
|
||||||
def _buildCaps(self, filename):
|
|
||||||
path = os.path.join(DATADIR, filename)
|
path = os.path.join(DATADIR, filename)
|
||||||
conn = utils.URIs.open_testdefault_cached()
|
conn = utils.URIs.open_testdefault_cached()
|
||||||
return Capabilities(conn, open(path).read())
|
return Capabilities(conn, open(path).read())
|
||||||
|
|
||||||
def testCapsCPUFeaturesNewSyntax(self):
|
|
||||||
|
def testCapsCPUFeaturesNewSyntax():
|
||||||
filename = "test-qemu-with-kvm.xml"
|
filename = "test-qemu-with-kvm.xml"
|
||||||
host_feature_list = ['lahf_lm', 'xtpr', 'cx16', 'tm2', 'est', 'vmx',
|
host_feature_list = ['lahf_lm', 'xtpr', 'cx16', 'tm2', 'est', 'vmx',
|
||||||
'ds_cpl', 'pbe', 'tm', 'ht', 'ss', 'acpi', 'ds']
|
'ds_cpl', 'pbe', 'tm', 'ht', 'ss', 'acpi', 'ds']
|
||||||
|
|
||||||
caps = self._buildCaps(filename)
|
caps = _buildCaps(filename)
|
||||||
for f in host_feature_list:
|
for f in host_feature_list:
|
||||||
assert f in [feat.name for feat in caps.host.cpu.features]
|
assert f in [feat.name for feat in caps.host.cpu.features]
|
||||||
|
|
||||||
@ -38,10 +37,11 @@ class TestCapabilities(unittest.TestCase):
|
|||||||
assert caps.host.cpu.topology.cores == 5
|
assert caps.host.cpu.topology.cores == 5
|
||||||
assert caps.host.cpu.topology.sockets == 7
|
assert caps.host.cpu.topology.sockets == 7
|
||||||
|
|
||||||
def testCapsUtilFuncs(self):
|
|
||||||
caps_with_kvm = self._buildCaps("test-qemu-with-kvm.xml")
|
def testCapsUtilFuncs():
|
||||||
caps_no_kvm = self._buildCaps("test-qemu-no-kvm.xml")
|
caps_with_kvm = _buildCaps("test-qemu-with-kvm.xml")
|
||||||
caps_empty = self._buildCaps("test-empty.xml")
|
caps_no_kvm = _buildCaps("test-qemu-no-kvm.xml")
|
||||||
|
caps_empty = _buildCaps("test-empty.xml")
|
||||||
|
|
||||||
def test_utils(caps, has_guests, is_kvm):
|
def test_utils(caps, has_guests, is_kvm):
|
||||||
assert caps.has_install_options() == has_guests
|
assert caps.has_install_options() == has_guests
|
||||||
@ -52,24 +52,26 @@ class TestCapabilities(unittest.TestCase):
|
|||||||
test_utils(caps_with_kvm, True, True)
|
test_utils(caps_with_kvm, True, True)
|
||||||
test_utils(caps_no_kvm, True, False)
|
test_utils(caps_no_kvm, True, False)
|
||||||
|
|
||||||
# Small test for extra unittest coverage
|
# Small test for extra coverage
|
||||||
with pytest.raises(ValueError, match=r".*virtualization type 'xen'.*"):
|
with pytest.raises(ValueError, match=r".*virtualization type 'xen'.*"):
|
||||||
caps_empty.guest_lookup(os_type="linux")
|
caps_empty.guest_lookup(os_type="linux")
|
||||||
with pytest.raises(ValueError, match=r".*not support any.*"):
|
with pytest.raises(ValueError, match=r".*not support any.*"):
|
||||||
caps_empty.guest_lookup()
|
caps_empty.guest_lookup()
|
||||||
|
|
||||||
def testCapsNuma(self):
|
|
||||||
cells = self._buildCaps("lxc.xml").host.topology.cells
|
def testCapsNuma():
|
||||||
|
cells = _buildCaps("lxc.xml").host.topology.cells
|
||||||
assert len(cells) == 1
|
assert len(cells) == 1
|
||||||
assert len(cells[0].cpus) == 8
|
assert len(cells[0].cpus) == 8
|
||||||
assert cells[0].cpus[3].id == '3'
|
assert cells[0].cpus[3].id == '3'
|
||||||
|
|
||||||
|
|
||||||
##############################
|
##############################
|
||||||
# domcapabilities.py testing #
|
# domcapabilities.py testing #
|
||||||
##############################
|
##############################
|
||||||
|
|
||||||
def testDomainCapabilities(self):
|
|
||||||
|
def testDomainCapabilities():
|
||||||
xml = open(DATADIR + "/test-domcaps.xml").read()
|
xml = open(DATADIR + "/test-domcaps.xml").read()
|
||||||
caps = DomainCapabilities(utils.URIs.open_testdriver_cached(), xml)
|
caps = DomainCapabilities(utils.URIs.open_testdriver_cached(), xml)
|
||||||
|
|
||||||
@ -79,7 +81,8 @@ class TestCapabilities(unittest.TestCase):
|
|||||||
assert caps.os.loader.get_enum("type").get_values() == [
|
assert caps.os.loader.get_enum("type").get_values() == [
|
||||||
"rom", "pflash"]
|
"rom", "pflash"]
|
||||||
|
|
||||||
def testDomainCapabilitiesx86(self):
|
|
||||||
|
def testDomainCapabilitiesx86():
|
||||||
xml = open(DATADIR + "/kvm-x86_64-domcaps.xml").read()
|
xml = open(DATADIR + "/kvm-x86_64-domcaps.xml").read()
|
||||||
caps = DomainCapabilities(utils.URIs.open_testdriver_cached(), xml)
|
caps = DomainCapabilities(utils.URIs.open_testdriver_cached(), xml)
|
||||||
|
|
||||||
@ -102,7 +105,8 @@ class TestCapabilities(unittest.TestCase):
|
|||||||
assert "Custom:" in caps.label_for_firmware_path("/foobar")
|
assert "Custom:" in caps.label_for_firmware_path("/foobar")
|
||||||
assert "UEFI" in caps.label_for_firmware_path("OVMF")
|
assert "UEFI" in caps.label_for_firmware_path("OVMF")
|
||||||
|
|
||||||
def testDomainCapabilitiesAArch64(self):
|
|
||||||
|
def testDomainCapabilitiesAArch64():
|
||||||
xml = open(DATADIR + "/kvm-aarch64-domcaps.xml").read()
|
xml = open(DATADIR + "/kvm-aarch64-domcaps.xml").read()
|
||||||
caps = DomainCapabilities(utils.URIs.open_testdriver_cached(), xml)
|
caps = DomainCapabilities(utils.URIs.open_testdriver_cached(), xml)
|
||||||
|
|
||||||
|
@ -10,7 +10,8 @@ import shlex
|
|||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
import unittest
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import argcomplete
|
import argcomplete
|
||||||
@ -155,7 +156,7 @@ class SkipChecks:
|
|||||||
msg = "Skipping check due to version < %s" % check
|
msg = "Skipping check due to version < %s" % check
|
||||||
|
|
||||||
if skip:
|
if skip:
|
||||||
raise unittest.case.SkipTest(msg)
|
raise pytest.skip(msg)
|
||||||
|
|
||||||
def prerun_skip(self, conn):
|
def prerun_skip(self, conn):
|
||||||
self._check(conn, self.prerun_check)
|
self._check(conn, self.prerun_check)
|
||||||
@ -338,15 +339,8 @@ class Command(object):
|
|||||||
if self.compare_file:
|
if self.compare_file:
|
||||||
self._check_compare_file(conn, output)
|
self._check_compare_file(conn, output)
|
||||||
|
|
||||||
def run(self, tests):
|
def run(self):
|
||||||
err = None
|
|
||||||
|
|
||||||
try:
|
|
||||||
self._run()
|
self._run()
|
||||||
except AssertionError as e:
|
|
||||||
err = self.cmdstr + "\n" + str(e)
|
|
||||||
if err:
|
|
||||||
tests.fail(err)
|
|
||||||
|
|
||||||
|
|
||||||
class _CategoryProxy(object):
|
class _CategoryProxy(object):
|
||||||
@ -1453,9 +1447,8 @@ _add_argcomplete_cmd("virt-xml --sound mode", "model")
|
|||||||
##############
|
##############
|
||||||
|
|
||||||
|
|
||||||
class CLIMiscTests(unittest.TestCase):
|
@utils.run_without_testsuite_hacks
|
||||||
@utils.run_without_testsuite_hacks
|
def test_virtinstall_no_testsuite():
|
||||||
def test_virtinstall_no_testsuite(self):
|
|
||||||
"""
|
"""
|
||||||
Run virt-install stub command without the testsuite hacks, to test
|
Run virt-install stub command without the testsuite hacks, to test
|
||||||
some code paths like proper logging etc.
|
some code paths like proper logging etc.
|
||||||
@ -1464,21 +1457,25 @@ class CLIMiscTests(unittest.TestCase):
|
|||||||
"virt-install --connect %s "
|
"virt-install --connect %s "
|
||||||
"--test-stub-command --noautoconsole" %
|
"--test-stub-command --noautoconsole" %
|
||||||
(utils.URIs.test_suite))
|
(utils.URIs.test_suite))
|
||||||
cmd.run(self)
|
cmd.run()
|
||||||
|
|
||||||
|
|
||||||
#########################
|
#########################
|
||||||
# Test runner functions #
|
# Test runner functions #
|
||||||
#########################
|
#########################
|
||||||
|
|
||||||
newidx = 0
|
_CURTEST = 0
|
||||||
curtest = 0
|
|
||||||
|
|
||||||
|
|
||||||
def setup():
|
def setup():
|
||||||
"""
|
"""
|
||||||
Create initial test files/dirs
|
Create initial test files/dirs
|
||||||
"""
|
"""
|
||||||
|
global _CURTEST
|
||||||
|
_CURTEST += 1
|
||||||
|
if _CURTEST != 1:
|
||||||
|
return
|
||||||
|
|
||||||
for i in EXIST_FILES:
|
for i in EXIST_FILES:
|
||||||
open(i, "a")
|
open(i, "a")
|
||||||
|
|
||||||
@ -1500,40 +1497,41 @@ def cleanup(clean_all=True):
|
|||||||
os.unlink(i)
|
os.unlink(i)
|
||||||
|
|
||||||
|
|
||||||
class CLITests(unittest.TestCase):
|
def _create_testfunc(cmd, do_setup):
|
||||||
def setUp(self):
|
def cmdtemplate():
|
||||||
global curtest
|
if do_setup:
|
||||||
curtest += 1
|
|
||||||
# Only run this for first test
|
|
||||||
if curtest == 1:
|
|
||||||
setup()
|
setup()
|
||||||
|
cmd.run()
|
||||||
def tearDown(self):
|
return cmdtemplate
|
||||||
# Only run this on the last test
|
|
||||||
if curtest == newidx:
|
|
||||||
cleanup()
|
|
||||||
|
|
||||||
|
|
||||||
def maketest(cmd):
|
def _make_testcases():
|
||||||
def cmdtemplate(self, _cmdobj):
|
"""
|
||||||
_cmdobj.run(self)
|
Turn all the registered cli strings into test functions that
|
||||||
return lambda s: cmdtemplate(s, cmd)
|
the test runner can scoop up
|
||||||
|
"""
|
||||||
|
cmdlist = []
|
||||||
|
cmdlist += vinst.cmds
|
||||||
|
cmdlist += vclon.cmds
|
||||||
|
cmdlist += vixml.cmds
|
||||||
|
cmdlist += ARGCOMPLETE_CMDS
|
||||||
|
|
||||||
_cmdlist = []
|
newidx = 0
|
||||||
_cmdlist += vinst.cmds
|
for cmd in cmdlist:
|
||||||
_cmdlist += vclon.cmds
|
|
||||||
_cmdlist += vixml.cmds
|
|
||||||
_cmdlist += ARGCOMPLETE_CMDS
|
|
||||||
|
|
||||||
# Generate numbered names like testCLI%d
|
|
||||||
for _cmd in _cmdlist:
|
|
||||||
newidx += 1
|
newidx += 1
|
||||||
_name = "testCLI%.4d" % newidx
|
# Generate numbered names like testCLI%d
|
||||||
if _cmd.compare_file:
|
name = "testCLI%.4d" % newidx
|
||||||
_base = os.path.splitext(os.path.basename(_cmd.compare_file))[0]
|
|
||||||
_name += _base.replace("-", "_")
|
|
||||||
else:
|
|
||||||
_name += os.path.basename(_cmd.app.replace("-", "_"))
|
|
||||||
setattr(CLITests, _name, maketest(_cmd))
|
|
||||||
|
|
||||||
|
if cmd.compare_file:
|
||||||
|
base = os.path.splitext(os.path.basename(cmd.compare_file))[0]
|
||||||
|
name += base.replace("-", "_")
|
||||||
|
else:
|
||||||
|
name += os.path.basename(cmd.app.replace("-", "_"))
|
||||||
|
|
||||||
|
do_setup = newidx == 1
|
||||||
|
testfunc = _create_testfunc(cmd, do_setup)
|
||||||
|
globals()[name] = testfunc
|
||||||
|
|
||||||
|
|
||||||
|
_make_testcases()
|
||||||
atexit.register(cleanup)
|
atexit.register(cleanup)
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
# See the COPYING file in the top-level directory.
|
# See the COPYING file in the top-level directory.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import unittest
|
|
||||||
import unittest.mock
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -13,11 +11,11 @@ from virtinst import StoragePool
|
|||||||
from virtinst import URI
|
from virtinst import URI
|
||||||
|
|
||||||
|
|
||||||
class TestConn(unittest.TestCase):
|
############################
|
||||||
"""
|
# VirtinstConnection tests #
|
||||||
VirtinstConnection tests
|
############################
|
||||||
"""
|
|
||||||
def test_misc(self):
|
def test_misc():
|
||||||
# Misc API checks
|
# Misc API checks
|
||||||
conn = cli.getConnection("test:///default")
|
conn = cli.getConnection("test:///default")
|
||||||
conn.invalidate_caps()
|
conn.invalidate_caps()
|
||||||
@ -49,16 +47,17 @@ class TestConn(unittest.TestCase):
|
|||||||
with pytest.raises(RuntimeError):
|
with pytest.raises(RuntimeError):
|
||||||
cli.getConnection(fakeuri + ",qemu")
|
cli.getConnection(fakeuri + ",qemu")
|
||||||
|
|
||||||
@unittest.mock.patch.dict(os.environ,
|
|
||||||
{"LIBVIRT_DEFAULT_URI": "test:///default"})
|
def test_default_uri(monkeypatch):
|
||||||
def test_default_uri(self):
|
monkeypatch.setitem(os.environ, "LIBVIRT_DEFAULT_URI", "test:///default")
|
||||||
|
|
||||||
# Handle connecting to None conn
|
# Handle connecting to None conn
|
||||||
conn = cli.getConnection(None)
|
conn = cli.getConnection(None)
|
||||||
assert conn.getURI() == "test:///default"
|
assert conn.getURI() == "test:///default"
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
def test_poll(self):
|
def test_poll():
|
||||||
# Add coverage for conn fetch_* handling, and pollhelpers
|
# Add coverage for conn fetch_* handling, and pollhelpers
|
||||||
conn = cli.getConnection("test:///default")
|
conn = cli.getConnection("test:///default")
|
||||||
objmap = {}
|
objmap = {}
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -50,8 +49,8 @@ def test_disk_numtotarget():
|
|||||||
assert disk.generate_target(['hda', 'hdd']) == 'hdb'
|
assert disk.generate_target(['hda', 'hdd']) == 'hdb'
|
||||||
|
|
||||||
|
|
||||||
def test_disk_dir_searchable():
|
def test_disk_dir_searchable(monkeypatch):
|
||||||
# Normally the dir searchable test is skipped in the unittest,
|
# Normally the dir searchable test is skipped in the test suite,
|
||||||
# but let's contrive an example that should trigger all the code
|
# but let's contrive an example that should trigger all the code
|
||||||
# to ensure it isn't horribly broken
|
# to ensure it isn't horribly broken
|
||||||
conn = utils.URIs.open_kvm()
|
conn = utils.URIs.open_kvm()
|
||||||
@ -87,8 +86,8 @@ def test_disk_dir_searchable():
|
|||||||
assert not bool(errdict)
|
assert not bool(errdict)
|
||||||
|
|
||||||
# Mock setfacl to definitely fail
|
# Mock setfacl to definitely fail
|
||||||
with unittest.mock.patch("virtinst.diskbackend.SETFACL",
|
with monkeypatch.context() as m:
|
||||||
"getfacl"):
|
m.setattr("virtinst.diskbackend.SETFACL", "getfacl")
|
||||||
errdict = virtinst.DeviceDisk.fix_path_search(searchdata)
|
errdict = virtinst.DeviceDisk.fix_path_search(searchdata)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
|
||||||
|
|
||||||
|
|
||||||
_alldistros = {}
|
_alldistros = {}
|
||||||
@ -89,15 +88,7 @@ def _test_distro(distro):
|
|||||||
os.system(cmd)
|
os.system(cmd)
|
||||||
|
|
||||||
|
|
||||||
_printinitrd = False
|
def _print_intro():
|
||||||
|
|
||||||
|
|
||||||
class InjectTests(unittest.TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
global _printinitrd
|
|
||||||
if _printinitrd:
|
|
||||||
return
|
|
||||||
|
|
||||||
print("""
|
print("""
|
||||||
|
|
||||||
|
|
||||||
@ -109,17 +100,25 @@ failure pattern to confirm that initrd injections are working as expected.
|
|||||||
|
|
||||||
""")
|
""")
|
||||||
prompt()
|
prompt()
|
||||||
_printinitrd = True
|
|
||||||
|
|
||||||
|
def _build_testfunc(dobj, do_setup):
|
||||||
|
def testfunc():
|
||||||
|
if do_setup:
|
||||||
|
_print_intro()
|
||||||
|
_test_distro(dobj)
|
||||||
|
return testfunc
|
||||||
|
|
||||||
|
|
||||||
def _make_tests():
|
def _make_tests():
|
||||||
def _make_check_cb(_d):
|
|
||||||
return lambda s: _test_distro(_d)
|
|
||||||
|
|
||||||
idx = 0
|
idx = 0
|
||||||
for dname, dobj in _alldistros.items():
|
for dname, dobj in _alldistros.items():
|
||||||
idx += 1
|
idx += 1
|
||||||
setattr(InjectTests, "testInitrd%.3d_%s" %
|
name = "testInitrd%.3d_%s" % (idx, dname.replace("-", "_"))
|
||||||
(idx, dname.replace("-", "_")), _make_check_cb(dobj))
|
|
||||||
|
do_setup = idx == 1
|
||||||
|
testfunc = _build_testfunc(dobj, do_setup)
|
||||||
|
globals()[name] = testfunc
|
||||||
|
|
||||||
|
|
||||||
_make_tests()
|
_make_tests()
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
# See the COPYING file in the top-level directory.
|
# See the COPYING file in the top-level directory.
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
import unittest
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -27,86 +26,98 @@ funky_chars_xml = """
|
|||||||
DATADIR = utils.DATADIR + "/nodedev/"
|
DATADIR = utils.DATADIR + "/nodedev/"
|
||||||
|
|
||||||
|
|
||||||
class TestNodeDev(unittest.TestCase):
|
def _nodeDevFromName(conn, devname):
|
||||||
@property
|
node = conn.nodeDeviceLookupByName(devname)
|
||||||
def conn(self):
|
|
||||||
return utils.URIs.open_testdriver_cached()
|
|
||||||
|
|
||||||
def _nodeDevFromName(self, devname):
|
|
||||||
node = self.conn.nodeDeviceLookupByName(devname)
|
|
||||||
xml = node.XMLDesc(0)
|
xml = node.XMLDesc(0)
|
||||||
return NodeDevice(self.conn, xml)
|
return NodeDevice(conn, xml)
|
||||||
|
|
||||||
def _testNode2DeviceCompare(self, nodename, devfile, nodedev=None):
|
|
||||||
|
def _testNode2DeviceCompare(conn, nodename, devfile, nodedev=None):
|
||||||
devfile = os.path.join(DATADIR, "devxml", devfile)
|
devfile = os.path.join(DATADIR, "devxml", devfile)
|
||||||
if not nodedev:
|
if not nodedev:
|
||||||
nodedev = self._nodeDevFromName(nodename)
|
nodedev = _nodeDevFromName(conn, nodename)
|
||||||
|
|
||||||
dev = DeviceHostdev(self.conn)
|
dev = DeviceHostdev(conn)
|
||||||
dev.set_from_nodedev(nodedev)
|
dev.set_from_nodedev(nodedev)
|
||||||
dev.set_defaults(Guest(self.conn))
|
dev.set_defaults(Guest(conn))
|
||||||
utils.diff_compare(dev.get_xml() + "\n", devfile)
|
utils.diff_compare(dev.get_xml() + "\n", devfile)
|
||||||
|
|
||||||
def testFunkyChars(self):
|
|
||||||
|
def testFunkyChars():
|
||||||
# Ensure parsing doesn't fail
|
# Ensure parsing doesn't fail
|
||||||
dev = NodeDevice(self.conn, funky_chars_xml)
|
conn = utils.URIs.open_testdriver_cached()
|
||||||
|
dev = NodeDevice(conn, funky_chars_xml)
|
||||||
assert dev.name == "L3B2616"
|
assert dev.name == "L3B2616"
|
||||||
assert dev.device_type == "LENOVO"
|
assert dev.device_type == "LENOVO"
|
||||||
|
|
||||||
def testNetDevice(self):
|
|
||||||
|
def testNetDevice():
|
||||||
|
conn = utils.URIs.open_testdriver_cached()
|
||||||
devname = "net_00_1c_25_10_b1_e4"
|
devname = "net_00_1c_25_10_b1_e4"
|
||||||
dev = self._nodeDevFromName(devname)
|
dev = _nodeDevFromName(conn, devname)
|
||||||
assert dev.name == devname
|
assert dev.name == devname
|
||||||
assert dev.parent == "pci_8086_1049"
|
assert dev.parent == "pci_8086_1049"
|
||||||
assert dev.device_type == "net"
|
assert dev.device_type == "net"
|
||||||
assert dev.interface == "eth0"
|
assert dev.interface == "eth0"
|
||||||
|
|
||||||
def testPCIDevice(self):
|
|
||||||
|
def testPCIDevice():
|
||||||
|
conn = utils.URIs.open_testdriver_cached()
|
||||||
nodename = "pci_8086_10fb"
|
nodename = "pci_8086_10fb"
|
||||||
obj = self._nodeDevFromName(nodename)
|
obj = _nodeDevFromName(conn, nodename)
|
||||||
assert obj.is_pci_sriov() is True
|
assert obj.is_pci_sriov() is True
|
||||||
nodename = "pci_8086_2448"
|
nodename = "pci_8086_2448"
|
||||||
obj = self._nodeDevFromName(nodename)
|
obj = _nodeDevFromName(conn, nodename)
|
||||||
assert obj.is_pci_bridge() is True
|
assert obj.is_pci_bridge() is True
|
||||||
|
|
||||||
|
|
||||||
def testUSBDevDevice(self):
|
|
||||||
|
def testUSBDevDevice():
|
||||||
|
conn = utils.URIs.open_testdriver_cached()
|
||||||
devname = "usb_device_781_5151_2004453082054CA1BEEE"
|
devname = "usb_device_781_5151_2004453082054CA1BEEE"
|
||||||
dev = self._nodeDevFromName(devname)
|
dev = _nodeDevFromName(conn, devname)
|
||||||
assert dev.vendor_name == "SanDisk Corp."
|
assert dev.vendor_name == "SanDisk Corp."
|
||||||
assert dev.product_name == "Cruzer Micro 256/512MB Flash Drive"
|
assert dev.product_name == "Cruzer Micro 256/512MB Flash Drive"
|
||||||
|
|
||||||
devname = "usb_device_1d6b_1_0000_00_1a_0"
|
devname = "usb_device_1d6b_1_0000_00_1a_0"
|
||||||
dev = self._nodeDevFromName(devname)
|
dev = _nodeDevFromName(conn, devname)
|
||||||
assert dev.is_usb_linux_root_hub() is True
|
assert dev.is_usb_linux_root_hub() is True
|
||||||
|
|
||||||
def testSCSIDevice(self):
|
|
||||||
|
def testSCSIDevice():
|
||||||
|
conn = utils.URIs.open_testdriver_cached()
|
||||||
devname = "pci_8086_2829_scsi_host_scsi_device_lun0"
|
devname = "pci_8086_2829_scsi_host_scsi_device_lun0"
|
||||||
dev = self._nodeDevFromName(devname)
|
dev = _nodeDevFromName(conn, devname)
|
||||||
assert dev.host == "0"
|
assert dev.host == "0"
|
||||||
assert dev.bus == "0"
|
assert dev.bus == "0"
|
||||||
assert dev.target == "0"
|
assert dev.target == "0"
|
||||||
|
|
||||||
def testStorageDevice(self):
|
|
||||||
|
def testStorageDevice():
|
||||||
|
conn = utils.URIs.open_testdriver_cached()
|
||||||
devname = "storage_serial_SATA_WDC_WD1600AAJS__WD_WCAP95119685"
|
devname = "storage_serial_SATA_WDC_WD1600AAJS__WD_WCAP95119685"
|
||||||
dev = self._nodeDevFromName(devname)
|
dev = _nodeDevFromName(conn, devname)
|
||||||
assert dev.block == "/dev/sda"
|
assert dev.block == "/dev/sda"
|
||||||
assert dev.drive_type == "disk"
|
assert dev.drive_type == "disk"
|
||||||
assert dev.media_available is None
|
assert dev.media_available is None
|
||||||
|
|
||||||
devname = "storage_model_DVDRAM_GSA_U1200N"
|
devname = "storage_model_DVDRAM_GSA_U1200N"
|
||||||
dev = self._nodeDevFromName(devname)
|
dev = _nodeDevFromName(conn, devname)
|
||||||
assert dev.media_label == "Fedora12_media"
|
assert dev.media_label == "Fedora12_media"
|
||||||
assert dev.media_available == 1
|
assert dev.media_available == 1
|
||||||
|
|
||||||
def testSCSIBus(self):
|
|
||||||
|
def testSCSIBus():
|
||||||
|
conn = utils.URIs.open_testdriver_cached()
|
||||||
devname = "pci_8086_2829_scsi_host_1"
|
devname = "pci_8086_2829_scsi_host_1"
|
||||||
dev = self._nodeDevFromName(devname)
|
dev = _nodeDevFromName(conn, devname)
|
||||||
assert dev.host == "2"
|
assert dev.host == "2"
|
||||||
|
|
||||||
def testDRMDevice(self):
|
|
||||||
|
def testDRMDevice():
|
||||||
|
conn = utils.URIs.open_testdriver_cached()
|
||||||
devname = "drm_renderD129"
|
devname = "drm_renderD129"
|
||||||
dev = self._nodeDevFromName(devname)
|
dev = _nodeDevFromName(conn, devname)
|
||||||
assert dev.devnodes[0].path == "/dev/dri/renderD129"
|
assert dev.devnodes[0].path == "/dev/dri/renderD129"
|
||||||
assert dev.devnodes[0].node_type == "dev"
|
assert dev.devnodes[0].node_type == "dev"
|
||||||
assert dev.devnodes[1].path == "/dev/dri/by-path/pci-0000:00:02.0-render"
|
assert dev.devnodes[1].path == "/dev/dri/by-path/pci-0000:00:02.0-render"
|
||||||
@ -115,29 +126,37 @@ class TestNodeDev(unittest.TestCase):
|
|||||||
assert dev.get_devnode("frob")
|
assert dev.get_devnode("frob")
|
||||||
|
|
||||||
|
|
||||||
# NodeDevice 2 Device XML tests
|
# NodeDevice 2 Device XML tests
|
||||||
def testNodeDev2USB1(self):
|
|
||||||
|
def testNodeDev2USB1():
|
||||||
|
conn = utils.URIs.open_testdriver_cached()
|
||||||
nodename = "usb_device_781_5151_2004453082054CA1BEEE"
|
nodename = "usb_device_781_5151_2004453082054CA1BEEE"
|
||||||
devfile = "usbdev1.xml"
|
devfile = "usbdev1.xml"
|
||||||
self._testNode2DeviceCompare(nodename, devfile)
|
_testNode2DeviceCompare(conn, nodename, devfile)
|
||||||
|
|
||||||
def testNodeDev2USB2(self):
|
|
||||||
|
def testNodeDev2USB2():
|
||||||
|
conn = utils.URIs.open_testdriver_cached()
|
||||||
nodename = "usb_device_1d6b_2_0000_00_1d_7"
|
nodename = "usb_device_1d6b_2_0000_00_1d_7"
|
||||||
devfile = "usbdev2.xml"
|
devfile = "usbdev2.xml"
|
||||||
nodedev = self._nodeDevFromName(nodename)
|
nodedev = _nodeDevFromName(conn, nodename)
|
||||||
|
|
||||||
self._testNode2DeviceCompare(nodename, devfile, nodedev=nodedev)
|
_testNode2DeviceCompare(conn, nodename, devfile, nodedev=nodedev)
|
||||||
|
|
||||||
def testNodeDev2PCI(self):
|
|
||||||
|
def testNodeDev2PCI():
|
||||||
|
conn = utils.URIs.open_testdriver_cached()
|
||||||
nodename = "pci_1180_592"
|
nodename = "pci_1180_592"
|
||||||
devfile = "pcidev.xml"
|
devfile = "pcidev.xml"
|
||||||
self._testNode2DeviceCompare(nodename, devfile)
|
_testNode2DeviceCompare(conn, nodename, devfile)
|
||||||
|
|
||||||
def testNodeDevFail(self):
|
|
||||||
|
def testNodeDevFail():
|
||||||
|
conn = utils.URIs.open_testdriver_cached()
|
||||||
nodename = "usb_device_1d6b_1_0000_00_1d_1_if0"
|
nodename = "usb_device_1d6b_1_0000_00_1d_1_if0"
|
||||||
devfile = ""
|
devfile = ""
|
||||||
|
|
||||||
# This should exist, since usbbus is not a valid device to
|
# This should exist, since usbbus is not a valid device to
|
||||||
# pass to a guest.
|
# pass to a guest.
|
||||||
pytest.raises(ValueError,
|
with pytest.raises(ValueError):
|
||||||
self._testNode2DeviceCompare, nodename, devfile)
|
_testNode2DeviceCompare(conn, nodename, devfile)
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
# This work is licensed under the GNU GPLv2 or later.
|
# This work is licensed under the GNU GPLv2 or later.
|
||||||
# See the COPYING file in the top-level directory.
|
# See the COPYING file in the top-level directory.
|
||||||
|
|
||||||
import unittest
|
import pytest
|
||||||
|
|
||||||
from virtinst import Guest
|
from virtinst import Guest
|
||||||
from virtinst import OSDB
|
from virtinst import OSDB
|
||||||
@ -13,11 +13,12 @@ from virtinst.install import urldetect
|
|||||||
from tests import utils
|
from tests import utils
|
||||||
|
|
||||||
|
|
||||||
class TestOSDB(unittest.TestCase):
|
##################
|
||||||
"""
|
# Test osdict.py #
|
||||||
Test osdict/OSDB
|
##################
|
||||||
"""
|
|
||||||
def test_osdict_aliases_ro(self):
|
|
||||||
|
def test_osdict_aliases_ro():
|
||||||
aliases = getattr(OSDB, "_aliases")
|
aliases = getattr(OSDB, "_aliases")
|
||||||
|
|
||||||
if len(aliases) != 42:
|
if len(aliases) != 42:
|
||||||
@ -25,10 +26,12 @@ class TestOSDB(unittest.TestCase):
|
|||||||
"should never be extended, since it is only for back "
|
"should never be extended, since it is only for back "
|
||||||
"compat with pre-libosinfo osdict.py"))
|
"compat with pre-libosinfo osdict.py"))
|
||||||
|
|
||||||
def test_list_os(self):
|
|
||||||
|
def test_list_os():
|
||||||
OSDB.list_os()
|
OSDB.list_os()
|
||||||
|
|
||||||
def test_recommended_resources(self):
|
|
||||||
|
def test_recommended_resources():
|
||||||
conn = utils.URIs.open_testdefault_cached()
|
conn = utils.URIs.open_testdefault_cached()
|
||||||
guest = Guest(conn)
|
guest = Guest(conn)
|
||||||
res = OSDB.lookup_os("generic").get_recommended_resources()
|
res = OSDB.lookup_os("generic").get_recommended_resources()
|
||||||
@ -37,7 +40,8 @@ class TestOSDB(unittest.TestCase):
|
|||||||
res = OSDB.lookup_os("fedora21").get_recommended_resources()
|
res = OSDB.lookup_os("fedora21").get_recommended_resources()
|
||||||
assert res.get_recommended_ncpus(guest.os.arch) == 2
|
assert res.get_recommended_ncpus(guest.os.arch) == 2
|
||||||
|
|
||||||
def test_urldetct_matching_distros(self):
|
|
||||||
|
def test_urldetct_matching_distros():
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
allstores = urldetect._build_distro_list(OSDB.lookup_os("generic"))
|
allstores = urldetect._build_distro_list(OSDB.lookup_os("generic"))
|
||||||
|
|
||||||
@ -50,7 +54,8 @@ class TestOSDB(unittest.TestCase):
|
|||||||
(store.PRETTY_NAME, distro))
|
(store.PRETTY_NAME, distro))
|
||||||
seen_distro.append(distro)
|
seen_distro.append(distro)
|
||||||
|
|
||||||
def test_tree_url(self):
|
|
||||||
|
def test_tree_url():
|
||||||
f26 = OSDB.lookup_os("fedora26")
|
f26 = OSDB.lookup_os("fedora26")
|
||||||
f29 = OSDB.lookup_os("fedora29")
|
f29 = OSDB.lookup_os("fedora29")
|
||||||
winxp = OSDB.lookup_os("winxp")
|
winxp = OSDB.lookup_os("winxp")
|
||||||
@ -82,11 +87,12 @@ class TestOSDB(unittest.TestCase):
|
|||||||
# Trigger an error path for code coverage
|
# Trigger an error path for code coverage
|
||||||
assert OSDB.guess_os_by_tree(utils.TESTDIR) is None
|
assert OSDB.guess_os_by_tree(utils.TESTDIR) is None
|
||||||
|
|
||||||
def test_kernel_url(self):
|
|
||||||
|
def test_kernel_url():
|
||||||
def _c(name):
|
def _c(name):
|
||||||
osobj = OSDB.lookup_os(name)
|
osobj = OSDB.lookup_os(name)
|
||||||
if not osobj:
|
if not osobj:
|
||||||
self.skipTest("osinfo-db doesn't have '%s'" % name)
|
pytest.skip("osinfo-db doesn't have '%s'" % name)
|
||||||
return osobj.get_kernel_url_arg()
|
return osobj.get_kernel_url_arg()
|
||||||
|
|
||||||
assert _c("rhel7-unknown") == "inst.repo"
|
assert _c("rhel7-unknown") == "inst.repo"
|
||||||
@ -97,14 +103,16 @@ class TestOSDB(unittest.TestCase):
|
|||||||
assert _c("win10") is None
|
assert _c("win10") is None
|
||||||
assert _c("sle15") == "install"
|
assert _c("sle15") == "install"
|
||||||
|
|
||||||
def test_related_to(self):
|
|
||||||
|
def test_related_to():
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
win10 = OSDB.lookup_os("win10")
|
win10 = OSDB.lookup_os("win10")
|
||||||
assert win10._is_related_to("winxp") is True
|
assert win10._is_related_to("winxp") is True
|
||||||
assert win10._is_related_to("win10") is True
|
assert win10._is_related_to("win10") is True
|
||||||
assert win10._is_related_to("fedora26") is False
|
assert win10._is_related_to("fedora26") is False
|
||||||
|
|
||||||
def test_drivers(self):
|
|
||||||
|
def test_drivers():
|
||||||
win7 = OSDB.lookup_os("win7")
|
win7 = OSDB.lookup_os("win7")
|
||||||
generic = OSDB.lookup_os("generic")
|
generic = OSDB.lookup_os("generic")
|
||||||
assert generic.supports_unattended_drivers("x86_64") is False
|
assert generic.supports_unattended_drivers("x86_64") is False
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
# See the COPYING file in the top-level directory.
|
# See the COPYING file in the top-level directory.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import unittest
|
|
||||||
|
|
||||||
from virtinst import StoragePool, StorageVolume
|
from virtinst import StoragePool, StorageVolume
|
||||||
from virtinst import log
|
from virtinst import log
|
||||||
@ -12,7 +11,6 @@ from virtinst import log
|
|||||||
from tests import utils
|
from tests import utils
|
||||||
|
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
# Access to protected member, needed to unittest stuff
|
|
||||||
|
|
||||||
BASEPATH = os.path.join(utils.DATADIR, "storage")
|
BASEPATH = os.path.join(utils.DATADIR, "storage")
|
||||||
|
|
||||||
@ -97,104 +95,124 @@ def createVol(conn, poolobj, volname=None, input_vol=None, clone_vol=None):
|
|||||||
return vol_inst.install(meter=False)
|
return vol_inst.install(meter=False)
|
||||||
|
|
||||||
|
|
||||||
class TestStorage(unittest.TestCase):
|
##############
|
||||||
@property
|
# Test cases #
|
||||||
def conn(self):
|
##############
|
||||||
return utils.URIs.open_testdefault_cached()
|
|
||||||
|
|
||||||
def testDirPool(self):
|
def testDirPool():
|
||||||
poolobj = createPool(self.conn,
|
conn = utils.URIs.open_testdefault_cached()
|
||||||
|
poolobj = createPool(conn,
|
||||||
StoragePool.TYPE_DIR, "pool-dir")
|
StoragePool.TYPE_DIR, "pool-dir")
|
||||||
invol = createVol(self.conn, poolobj)
|
invol = createVol(conn, poolobj)
|
||||||
createVol(self.conn, poolobj,
|
createVol(conn, poolobj,
|
||||||
volname=invol.name() + "input", input_vol=invol)
|
volname=invol.name() + "input", input_vol=invol)
|
||||||
createVol(self.conn, poolobj,
|
createVol(conn, poolobj,
|
||||||
volname=invol.name() + "clone", clone_vol=invol)
|
volname=invol.name() + "clone", clone_vol=invol)
|
||||||
removePool(poolobj)
|
removePool(poolobj)
|
||||||
|
|
||||||
def testFSPool(self):
|
|
||||||
poolobj = createPool(self.conn,
|
def testFSPool():
|
||||||
|
conn = utils.URIs.open_testdefault_cached()
|
||||||
|
poolobj = createPool(conn,
|
||||||
StoragePool.TYPE_FS, "pool-fs")
|
StoragePool.TYPE_FS, "pool-fs")
|
||||||
invol = createVol(self.conn, poolobj)
|
invol = createVol(conn, poolobj)
|
||||||
createVol(self.conn, poolobj,
|
createVol(conn, poolobj,
|
||||||
volname=invol.name() + "input", input_vol=invol)
|
volname=invol.name() + "input", input_vol=invol)
|
||||||
createVol(self.conn, poolobj,
|
createVol(conn, poolobj,
|
||||||
volname=invol.name() + "clone", clone_vol=invol)
|
volname=invol.name() + "clone", clone_vol=invol)
|
||||||
removePool(poolobj)
|
removePool(poolobj)
|
||||||
|
|
||||||
def testNetFSPool(self):
|
|
||||||
poolobj = createPool(self.conn,
|
def testNetFSPool():
|
||||||
|
conn = utils.URIs.open_testdefault_cached()
|
||||||
|
poolobj = createPool(conn,
|
||||||
StoragePool.TYPE_NETFS, "pool-netfs")
|
StoragePool.TYPE_NETFS, "pool-netfs")
|
||||||
invol = createVol(self.conn, poolobj)
|
invol = createVol(conn, poolobj)
|
||||||
createVol(self.conn, poolobj,
|
createVol(conn, poolobj,
|
||||||
volname=invol.name() + "input", input_vol=invol)
|
volname=invol.name() + "input", input_vol=invol)
|
||||||
createVol(self.conn, poolobj,
|
createVol(conn, poolobj,
|
||||||
volname=invol.name() + "clone", clone_vol=invol)
|
volname=invol.name() + "clone", clone_vol=invol)
|
||||||
removePool(poolobj)
|
removePool(poolobj)
|
||||||
|
|
||||||
def testLVPool(self):
|
|
||||||
poolobj = createPool(self.conn,
|
def testLVPool():
|
||||||
|
conn = utils.URIs.open_testdefault_cached()
|
||||||
|
poolobj = createPool(conn,
|
||||||
StoragePool.TYPE_LOGICAL,
|
StoragePool.TYPE_LOGICAL,
|
||||||
"pool-logical",
|
"pool-logical",
|
||||||
source_name="pool-logical")
|
source_name="pool-logical")
|
||||||
invol = createVol(self.conn, poolobj)
|
invol = createVol(conn, poolobj)
|
||||||
createVol(self.conn, poolobj,
|
createVol(conn, poolobj,
|
||||||
volname=invol.name() + "input", input_vol=invol)
|
volname=invol.name() + "input", input_vol=invol)
|
||||||
createVol(self.conn,
|
createVol(conn,
|
||||||
poolobj, volname=invol.name() + "clone", clone_vol=invol)
|
poolobj, volname=invol.name() + "clone", clone_vol=invol)
|
||||||
removePool(poolobj)
|
removePool(poolobj)
|
||||||
|
|
||||||
# Test parsing source name for target path
|
# Test parsing source name for target path
|
||||||
poolobj = createPool(self.conn, StoragePool.TYPE_LOGICAL,
|
poolobj = createPool(conn, StoragePool.TYPE_LOGICAL,
|
||||||
"pool-logical-target-srcname",
|
"pool-logical-target-srcname",
|
||||||
target_path="/dev/vgfoobar")
|
target_path="/dev/vgfoobar")
|
||||||
removePool(poolobj)
|
removePool(poolobj)
|
||||||
|
|
||||||
# Test with source name
|
# Test with source name
|
||||||
poolobj = createPool(self.conn,
|
poolobj = createPool(conn,
|
||||||
StoragePool.TYPE_LOGICAL, "pool-logical-srcname",
|
StoragePool.TYPE_LOGICAL, "pool-logical-srcname",
|
||||||
source_name="vgname")
|
source_name="vgname")
|
||||||
removePool(poolobj)
|
removePool(poolobj)
|
||||||
|
|
||||||
def testDiskPool(self):
|
|
||||||
poolobj = createPool(self.conn,
|
def testDiskPool():
|
||||||
|
conn = utils.URIs.open_testdefault_cached()
|
||||||
|
poolobj = createPool(conn,
|
||||||
StoragePool.TYPE_DISK,
|
StoragePool.TYPE_DISK,
|
||||||
"pool-disk", fmt="auto",
|
"pool-disk", fmt="auto",
|
||||||
target_path="/some/target/path")
|
target_path="/some/target/path")
|
||||||
invol = createVol(self.conn, poolobj)
|
invol = createVol(conn, poolobj)
|
||||||
createVol(self.conn, poolobj,
|
createVol(conn, poolobj,
|
||||||
volname=invol.name() + "input", input_vol=invol)
|
volname=invol.name() + "input", input_vol=invol)
|
||||||
createVol(self.conn, poolobj,
|
createVol(conn, poolobj,
|
||||||
volname=invol.name() + "clone", clone_vol=invol)
|
volname=invol.name() + "clone", clone_vol=invol)
|
||||||
removePool(poolobj)
|
removePool(poolobj)
|
||||||
|
|
||||||
def testISCSIPool(self):
|
|
||||||
poolobj = createPool(self.conn,
|
def testISCSIPool():
|
||||||
|
conn = utils.URIs.open_testdefault_cached()
|
||||||
|
poolobj = createPool(conn,
|
||||||
StoragePool.TYPE_ISCSI, "pool-iscsi",
|
StoragePool.TYPE_ISCSI, "pool-iscsi",
|
||||||
iqn="foo.bar.baz.iqn")
|
iqn="foo.bar.baz.iqn")
|
||||||
removePool(poolobj)
|
removePool(poolobj)
|
||||||
|
|
||||||
def testSCSIPool(self):
|
|
||||||
poolobj = createPool(self.conn, StoragePool.TYPE_SCSI, "pool-scsi")
|
def testSCSIPool():
|
||||||
|
conn = utils.URIs.open_testdefault_cached()
|
||||||
|
poolobj = createPool(conn, StoragePool.TYPE_SCSI, "pool-scsi")
|
||||||
removePool(poolobj)
|
removePool(poolobj)
|
||||||
|
|
||||||
def testMpathPool(self):
|
|
||||||
poolobj = createPool(self.conn, StoragePool.TYPE_MPATH, "pool-mpath")
|
def testMpathPool():
|
||||||
|
conn = utils.URIs.open_testdefault_cached()
|
||||||
|
poolobj = createPool(conn, StoragePool.TYPE_MPATH, "pool-mpath")
|
||||||
removePool(poolobj)
|
removePool(poolobj)
|
||||||
|
|
||||||
def testGlusterPool(self):
|
|
||||||
poolobj = createPool(self.conn,
|
def testGlusterPool():
|
||||||
|
conn = utils.URIs.open_testdefault_cached()
|
||||||
|
poolobj = createPool(conn,
|
||||||
StoragePool.TYPE_GLUSTER, "pool-gluster")
|
StoragePool.TYPE_GLUSTER, "pool-gluster")
|
||||||
removePool(poolobj)
|
removePool(poolobj)
|
||||||
|
|
||||||
def testRBDPool(self):
|
|
||||||
poolobj = createPool(self.conn,
|
def testRBDPool():
|
||||||
|
conn = utils.URIs.open_testdefault_cached()
|
||||||
|
poolobj = createPool(conn,
|
||||||
StoragePool.TYPE_RBD, "pool-rbd")
|
StoragePool.TYPE_RBD, "pool-rbd")
|
||||||
removePool(poolobj)
|
removePool(poolobj)
|
||||||
|
|
||||||
def testMisc(self):
|
|
||||||
|
def testMisc():
|
||||||
|
conn = utils.URIs.open_testdefault_cached()
|
||||||
# Misc coverage testing
|
# Misc coverage testing
|
||||||
vol = StorageVolume(self.conn)
|
vol = StorageVolume(conn)
|
||||||
assert vol.is_size_conflict()[0] is False
|
assert vol.is_size_conflict()[0] is False
|
||||||
|
|
||||||
fullconn = utils.URIs.open_testdriver_cached()
|
fullconn = utils.URIs.open_testdriver_cached()
|
||||||
@ -216,7 +234,9 @@ class TestStorage(unittest.TestCase):
|
|||||||
name = StoragePool.find_free_name(fullconn, "gluster-pool")
|
name = StoragePool.find_free_name(fullconn, "gluster-pool")
|
||||||
assert name == "gluster-pool-1"
|
assert name == "gluster-pool-1"
|
||||||
|
|
||||||
def testEnumerateLogical(self):
|
|
||||||
lst = StoragePool.pool_list_from_sources(self.conn,
|
def testEnumerateLogical():
|
||||||
|
conn = utils.URIs.open_testdefault_cached()
|
||||||
|
lst = StoragePool.pool_list_from_sources(conn,
|
||||||
StoragePool.TYPE_LOGICAL)
|
StoragePool.TYPE_LOGICAL)
|
||||||
assert lst == ["testvg1", "testvg2"]
|
assert lst == ["testvg1", "testvg2"]
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
# This work is licensed under the GNU GPLv2 or later.
|
# This work is licensed under the GNU GPLv2 or later.
|
||||||
# See the COPYING file in the top-level directory.
|
# See the COPYING file in the top-level directory.
|
||||||
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from virtinst import URI
|
from virtinst import URI
|
||||||
@ -12,11 +10,11 @@ from virtinst import URI
|
|||||||
import tests
|
import tests
|
||||||
|
|
||||||
|
|
||||||
class TestURI(unittest.TestCase):
|
############################
|
||||||
"""
|
# Test virtinst URI module #
|
||||||
Test virtinst URI module
|
############################
|
||||||
"""
|
|
||||||
def _compare(self, uri, scheme='',
|
def _compare(uri, scheme='',
|
||||||
transport='', port='', username='', path='',
|
transport='', port='', username='', path='',
|
||||||
hostname='', query='', fragment='',
|
hostname='', query='', fragment='',
|
||||||
is_ipv6=False, host_is_ipv4_string=False):
|
is_ipv6=False, host_is_ipv4_string=False):
|
||||||
@ -32,33 +30,35 @@ class TestURI(unittest.TestCase):
|
|||||||
assert is_ipv6 == uriinfo.is_ipv6
|
assert is_ipv6 == uriinfo.is_ipv6
|
||||||
assert host_is_ipv4_string == uriinfo.host_is_ipv4_string
|
assert host_is_ipv4_string == uriinfo.host_is_ipv4_string
|
||||||
|
|
||||||
def testURIs(self):
|
|
||||||
self._compare("lxc://", scheme="lxc")
|
def testURIs():
|
||||||
self._compare("qemu:///session", scheme="qemu", path="/session")
|
_compare("lxc://", scheme="lxc")
|
||||||
self._compare("http://foobar.com:5901/my/example.path#my-frag",
|
_compare("qemu:///session", scheme="qemu", path="/session")
|
||||||
|
_compare("http://foobar.com:5901/my/example.path#my-frag",
|
||||||
scheme="http", hostname="foobar.com",
|
scheme="http", hostname="foobar.com",
|
||||||
port="5901", path='/my/example.path',
|
port="5901", path='/my/example.path',
|
||||||
fragment="my-frag")
|
fragment="my-frag")
|
||||||
self._compare(
|
_compare(
|
||||||
"gluster+tcp://[1:2:3:4:5:6:7:8]:24007/testvol/dir/a.img",
|
"gluster+tcp://[1:2:3:4:5:6:7:8]:24007/testvol/dir/a.img",
|
||||||
scheme="gluster", transport="tcp",
|
scheme="gluster", transport="tcp",
|
||||||
hostname="1:2:3:4:5:6:7:8", port="24007",
|
hostname="1:2:3:4:5:6:7:8", port="24007",
|
||||||
path="/testvol/dir/a.img", is_ipv6=True)
|
path="/testvol/dir/a.img", is_ipv6=True)
|
||||||
self._compare(
|
_compare(
|
||||||
"qemu+ssh://root@192.168.2.3/system?no_verify=1",
|
"qemu+ssh://root@192.168.2.3/system?no_verify=1",
|
||||||
scheme="qemu", transport="ssh", username="root",
|
scheme="qemu", transport="ssh", username="root",
|
||||||
hostname="192.168.2.3", path="/system",
|
hostname="192.168.2.3", path="/system",
|
||||||
query="no_verify=1", host_is_ipv4_string=True)
|
query="no_verify=1", host_is_ipv4_string=True)
|
||||||
self._compare(
|
_compare(
|
||||||
"qemu+ssh://foo%5Cbar@hostname/system",
|
"qemu+ssh://foo%5Cbar@hostname/system",
|
||||||
scheme="qemu", path="/system", transport="ssh",
|
scheme="qemu", path="/system", transport="ssh",
|
||||||
hostname="hostname", username="foo\\bar")
|
hostname="hostname", username="foo\\bar")
|
||||||
self._compare(
|
_compare(
|
||||||
"qemu+ssh://user%40domain.org@hostname/system",
|
"qemu+ssh://user%40domain.org@hostname/system",
|
||||||
scheme="qemu", path="/system", transport="ssh",
|
scheme="qemu", path="/system", transport="ssh",
|
||||||
hostname="hostname", username="user@domain.org")
|
hostname="hostname", username="user@domain.org")
|
||||||
|
|
||||||
def test_magicuri_connver(self):
|
|
||||||
|
def test_magicuri_connver():
|
||||||
uri = tests.utils.URIs.test_default + ",connver=1,libver=2"
|
uri = tests.utils.URIs.test_default + ",connver=1,libver=2"
|
||||||
conn = tests.utils.URIs.openconn(uri)
|
conn = tests.utils.URIs.openconn(uri)
|
||||||
assert conn.conn_version() == 1
|
assert conn.conn_version() == 1
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -126,7 +125,7 @@ def _testGuest(testdata, guest):
|
|||||||
|
|
||||||
msg = _skipmsg(testdata)
|
msg = _skipmsg(testdata)
|
||||||
if msg:
|
if msg:
|
||||||
raise unittest.SkipTest(msg)
|
raise pytest.skip(msg)
|
||||||
|
|
||||||
installer = Installer(guest.conn, location=url)
|
installer = Installer(guest.conn, location=url)
|
||||||
try:
|
try:
|
||||||
@ -190,9 +189,7 @@ def _testURL(testdata):
|
|||||||
_testGuest(testdata, xenguest)
|
_testGuest(testdata, xenguest)
|
||||||
|
|
||||||
|
|
||||||
# Register tests to be picked up by unittest
|
def test001BadURL():
|
||||||
class URLTests(unittest.TestCase):
|
|
||||||
def test001BadURL(self):
|
|
||||||
badurl = "http://aksdkakskdfa-idontexist.com/foo/tree"
|
badurl = "http://aksdkakskdfa-idontexist.com/foo/tree"
|
||||||
|
|
||||||
with pytest.raises(ValueError, match=".*maybe you mistyped.*"):
|
with pytest.raises(ValueError, match=".*maybe you mistyped.*"):
|
||||||
@ -238,7 +235,7 @@ def _make_tests():
|
|||||||
for key, testdata in sorted(urls.items()):
|
for key, testdata in sorted(urls.items()):
|
||||||
def _make_wrapper(d):
|
def _make_wrapper(d):
|
||||||
return lambda _self: _testURL(d)
|
return lambda _self: _testURL(d)
|
||||||
methodname = "testURL%s" % key.replace("-", "_")
|
methodname = "test_URL%s" % key.replace("-", "_")
|
||||||
setattr(URLTests, methodname, _make_wrapper(testdata))
|
globals()[methodname] = _make_wrapper(testdata)
|
||||||
|
|
||||||
_make_tests()
|
_make_tests()
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -5,9 +5,9 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
|
||||||
|
|
||||||
import libvirt
|
import libvirt
|
||||||
|
import pytest
|
||||||
|
|
||||||
import virtinst
|
import virtinst
|
||||||
import virtinst.uri
|
import virtinst.uri
|
||||||
@ -16,7 +16,6 @@ from virtinst import xmlutil
|
|||||||
|
|
||||||
|
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
# Access to protected member, needed to unittest stuff
|
|
||||||
|
|
||||||
class _TestConfig(object):
|
class _TestConfig(object):
|
||||||
"""
|
"""
|
||||||
@ -138,7 +137,7 @@ class _URIs(object):
|
|||||||
print(self._testdriver_error, file=sys.stderr)
|
print(self._testdriver_error, file=sys.stderr)
|
||||||
|
|
||||||
if is_testdriver_xml and self._testdriver_error:
|
if is_testdriver_xml and self._testdriver_error:
|
||||||
raise unittest.SkipTest(self._testdriver_error)
|
pytest.skip(self._testdriver_error)
|
||||||
|
|
||||||
uri = conn._open_uri
|
uri = conn._open_uri
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user