[virt-tools-list] [PATCH 1/1] virtinst: Use sudo where root permission is needed
Andrew Wong
andrew.kw.w at gmail.com
Sat Sep 9 03:49:48 UTC 2017
---
virtinst/urlfetcher.py | 6 +++---
virtinst/util.py | 9 ++++++++-
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/virtinst/urlfetcher.py b/virtinst/urlfetcher.py
index 89943f63..1fcaacd6 100644
--- a/virtinst/urlfetcher.py
+++ b/virtinst/urlfetcher.py
@@ -26,7 +26,6 @@ import os
import re
import stat
import StringIO
-import subprocess
import tempfile
import urllib2
import urlparse
@@ -34,6 +33,7 @@ import urlparse
import requests
from .osdict import OSDB
+from . import util
#########################################################################
@@ -313,7 +313,7 @@ class _MountedURLFetcher(_LocalURLFetcher):
logging.debug("mount cmd: %s", cmd)
if not self._in_test_suite:
- ret = subprocess.call(cmd)
+ ret = util.subprocess_call_as_root(cmd)
if ret != 0:
self.cleanupLocation()
raise ValueError(_("Mounting location '%s' failed") %
@@ -329,7 +329,7 @@ class _MountedURLFetcher(_LocalURLFetcher):
try:
if not self._in_test_suite:
cmd = ["/bin/umount", self._srcdir]
- subprocess.call(cmd)
+ util.subprocess_call_as_root(cmd)
try:
os.rmdir(self._srcdir)
except Exception:
diff --git a/virtinst/util.py b/virtinst/util.py
index 495a0841..48842b47 100644
--- a/virtinst/util.py
+++ b/virtinst/util.py
@@ -22,11 +22,11 @@ import logging
import os
import random
import re
+import subprocess
import sys
import libvirt
-
def listify(l):
if l is None:
return []
@@ -317,3 +317,10 @@ def make_meter(quiet):
if quiet:
return progress.BaseMeter()
return progress.TextMeter(fo=sys.stdout)
+
+def subprocess_call_as_root(cmd):
+ if os.getuid() != 0:
+ from cli import print_stdout
+ print_stdout("Need sudo to run: %s" % cmd)
+ cmd.insert(0, "sudo")
+ return subprocess.call(cmd)
--
2.14.1
More information about the virt-tools-list
mailing list