提交 db815c8f 编写于 作者: L Lukáš Doktor 提交者: Cleber Rosa

avocado.utils.iso9660: Enable sudo for Iso9660Mount

The Iso9660Mount requires root, but with this patch it can also use
normal user with sudo configured.
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 0b7d745a
......@@ -82,8 +82,9 @@ def can_mount():
:rtype: bool
"""
if os.getuid() != 0:
logging.debug('Can not use mount: current user is not "root"')
if not process.can_sudo():
logging.debug('Can not use mount: current user is not "root" and'
"sudo is not configured.")
return False
if not has_userland_tool('mount'):
......@@ -301,7 +302,7 @@ class Iso9660Mount(BaseIso9660):
super(Iso9660Mount, self).__init__(path)
self._mnt_dir = tempfile.mkdtemp(prefix='avocado_' + __name__)
process.run('mount -t iso9660 -v -o loop,ro %s %s' %
(path, self.mnt_dir))
(path, self.mnt_dir), sudo=True)
def read(self, path):
"""
......@@ -334,8 +335,9 @@ class Iso9660Mount(BaseIso9660):
"""
if self._mnt_dir:
if os.path.ismount(self._mnt_dir):
process.run('fuser -k %s' % self.mnt_dir, ignore_status=True)
process.run('umount %s' % self.mnt_dir)
process.run('fuser -k %s' % self.mnt_dir, ignore_status=True,
sudo=True)
process.run('umount %s' % self.mnt_dir, sudo=True)
shutil.rmtree(self._mnt_dir)
self._mnt_dir = None
......
......@@ -43,7 +43,8 @@ class BaseIso9660(unittest.TestCase):
self.iso.close()
self.iso.close() # check that double-close won't fail
@unittest.skipIf(os.getuid(), "This test is only available to root")
@unittest.skipIf(not process.can_sudo(),
"This test requires sudo or root")
def mnt_dir_workflow(self):
"""
Check the mnt_dir functionality
......@@ -115,7 +116,8 @@ class IsoMount(BaseIso9660):
Mount-based check
"""
@unittest.skipIf(os.getuid(), "This test is only available to root")
@unittest.skipIf(not process.can_sudo(),
"This test requires sudo or root")
def setUp(self):
super(IsoMount, self).setUp()
self.iso = iso9660.Iso9660Mount(self.iso_path)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册