mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-07 14:43:01 -06:00
virtinst: Unify test code paths when run as root
CI runs the code as root by default, fix up some of the differences Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
aa89a48371
commit
2170efc9a5
@ -195,7 +195,6 @@ class TestXMLMisc(unittest.TestCase):
|
||||
g._metadata.libosinfo.os_id = "http://example.com/idontexit" # pylint: disable=protected-access
|
||||
self.assertEqual(g.osinfo.name, "generic")
|
||||
|
||||
@utils.run_without_testsuite_hacks
|
||||
def test_dir_searchable(self):
|
||||
# Normally the dir searchable test is skipped in the unittest,
|
||||
# but let's contrive an example that should trigger all the code
|
||||
|
@ -128,8 +128,8 @@ class DeviceDisk(Device):
|
||||
user, uid = conn.caps.host.get_qemu_baselabel()
|
||||
if not user:
|
||||
return searchdata
|
||||
if uid == 0:
|
||||
return searchdata
|
||||
if uid == 0 and not xmlutil.in_testsuite():
|
||||
return searchdata # pragma: no cover
|
||||
|
||||
searchdata.user = user
|
||||
searchdata.uid = uid
|
||||
|
@ -50,12 +50,12 @@ def _lookup_vol_by_basename(pool, path):
|
||||
return pool.storageVolLookupByName(name)
|
||||
|
||||
|
||||
def _get_block_size(path):
|
||||
def _get_block_size(path): # pragma: no cover
|
||||
try:
|
||||
fd = os.open(path, os.O_RDONLY)
|
||||
# os.SEEK_END is not present on all systems
|
||||
size = os.lseek(fd, 0, 2) # pragma: no cover
|
||||
os.close(fd) # pragma: no cover
|
||||
size = os.lseek(fd, 0, 2)
|
||||
os.close(fd)
|
||||
except Exception:
|
||||
size = 0
|
||||
return size
|
||||
@ -65,7 +65,7 @@ def _get_size(path):
|
||||
if not os.path.exists(path):
|
||||
return 0
|
||||
if _stat_is_block(path):
|
||||
return _get_block_size(path)
|
||||
return _get_block_size(path) # pragma: no cover
|
||||
return os.path.getsize(path)
|
||||
|
||||
|
||||
@ -214,7 +214,7 @@ def _get_dev_type(path, vol_xml, vol_object, pool_xml, remote):
|
||||
if os.path.isdir(path):
|
||||
return "dir"
|
||||
elif _stat_is_block(path):
|
||||
return "block"
|
||||
return "block" # pragma: no cover
|
||||
|
||||
return "file"
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
import os
|
||||
|
||||
from .. import progress
|
||||
from .. import xmlutil
|
||||
from ..devices import DeviceDisk
|
||||
from ..logger import log
|
||||
from ..storage import StoragePool, StorageVolume
|
||||
@ -136,7 +137,8 @@ def upload_kernel_initrd(conn, scratchdir, system_scratchdir,
|
||||
tmpvols = []
|
||||
|
||||
if (not conn.is_remote() and
|
||||
(conn.is_unprivileged() or scratchdir == system_scratchdir)):
|
||||
(conn.is_unprivileged() or scratchdir == system_scratchdir) and
|
||||
not xmlutil.in_testsuite()):
|
||||
# We have access to system scratchdir, don't jump through hoops
|
||||
log.debug("Have access to preferred scratchdir so"
|
||||
" nothing to upload") # pragma: no cover
|
||||
|
@ -20,6 +20,18 @@ from .. import progress
|
||||
from ..logger import log
|
||||
|
||||
|
||||
def _is_user_login_safe(login):
|
||||
return login != "root"
|
||||
|
||||
|
||||
def _login_from_hostuser():
|
||||
hostuser = getpass.getuser()
|
||||
realname = pwd.getpwnam(hostuser).pw_gecos
|
||||
if not _is_user_login_safe(hostuser):
|
||||
return None, None # pragma: no cover
|
||||
return hostuser, realname # pragma: no cover
|
||||
|
||||
|
||||
def _make_installconfig(script, osobj, unattended_data, arch, hostname, url):
|
||||
"""
|
||||
Build a Libosinfo.InstallConfig instance
|
||||
@ -34,9 +46,6 @@ def _make_installconfig(script, osobj, unattended_data, arch, hostname, url):
|
||||
def get_language():
|
||||
return locale.getlocale()[0]
|
||||
|
||||
def is_user_login_safe(login):
|
||||
return login != "root"
|
||||
|
||||
config = Libosinfo.InstallConfig()
|
||||
|
||||
# Set user login and name
|
||||
@ -45,14 +54,11 @@ def _make_installconfig(script, osobj, unattended_data, arch, hostname, url):
|
||||
login = unattended_data.user_login
|
||||
realname = unattended_data.user_login
|
||||
if not login:
|
||||
hostuser = getpass.getuser()
|
||||
if is_user_login_safe(hostuser):
|
||||
login = getpass.getuser()
|
||||
realname = pwd.getpwnam(login).pw_gecos
|
||||
login, realname = _login_from_hostuser()
|
||||
|
||||
if login:
|
||||
login = login.lower()
|
||||
if not is_user_login_safe(login):
|
||||
if not _is_user_login_safe(login):
|
||||
raise RuntimeError(
|
||||
_("%(osname)s cannot use '%(loginname)s' as user-login.") %
|
||||
{"osname": osobj.name, "loginname": login})
|
||||
|
Loading…
Reference in New Issue
Block a user