aboutsummaryrefslogtreecommitdiff
path: root/rumba
diff options
context:
space:
mode:
authorMarco Capitani <m.capitani@nextworks.it>2017-04-06 12:46:47 +0200
committerMarco Capitani <m.capitani@nextworks.it>2017-04-06 12:46:47 +0200
commit420802234226546208328269793d2afb8cc6e4ec (patch)
tree9bcf39d500d0c692d0be546da2f0a6576f0b899f /rumba
parentafc508dbf2c34eedb93d46dc43d5ec284213cbcb (diff)
downloadrumba-420802234226546208328269793d2afb8cc6e4ec.tar.gz
rumba-420802234226546208328269793d2afb8cc6e4ec.zip
Raising exceptions, authentication through getpass
Diffstat (limited to 'rumba')
-rw-r--r--rumba/testbeds/qemu.py27
1 files changed, 17 insertions, 10 deletions
diff --git a/rumba/testbeds/qemu.py b/rumba/testbeds/qemu.py
index 45e5cc0..7dae921 100644
--- a/rumba/testbeds/qemu.py
+++ b/rumba/testbeds/qemu.py
@@ -18,8 +18,10 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA
from Queue import Empty
+from getpass import getpass, getuser
from multiprocessing import Process, Queue, cpu_count
from os import geteuid
+from time import sleep
import rumba.model as mod
from subprocess import Popen, check_call, CalledProcessError
@@ -68,8 +70,15 @@ class Testbed(mod.Testbed):
:param experiment: The experiment running
"""
if geteuid() != 0:
- print("ERROR: QEMU testbed requires root access: please use sudo.")
- return # TODO I'd rather raise an appropriate error...
+ pw = getpass('[sudo] password for {}:'.format(getuser()))
+ if '"' in pw or "'" in pw:
+ print('Illegal password: contains " or \'')
+ raise Exception('Not authenticated')
+ else:
+ try:
+ check_call("sudo -v -p '{}'".format(pw).split())
+ except CalledProcessError:
+ raise Exception('Not authenticated')
print("[QEMU testbed] swapping in")
@@ -132,8 +141,9 @@ class Testbed(mod.Testbed):
while max_waiting_time > 0 and over_processes < total_processes:
# Check for errors
if not e_queue.empty():
- print('Testbed instantiation failed: {}'.format(str(e_queue.get())))
- return # TODO: again, I would prefer a specific exception
+ error_str = str(e_queue.get())
+ print('Testbed instantiation failed: {}'.format(error_str))
+ raise Exception('Failure: {}'.format(error_str))
try:
# Check for results
result = r_queue.get(timeout=1)
@@ -206,9 +216,9 @@ class Testbed(mod.Testbed):
booting_budget -= 1
if booting_budget <= 0:
- pass # TODO manage the backoff time
- # command_str += 'sleep %s\n' % boot_backoff
- # booting_budget = boot_batch_size
+ print('Sleeping for {} seconds to give the machines time to boot up.'.format(boot_backoff))
+ sleep(boot_backoff)
+ booting_budget = boot_batch_size
with open(self.qemu_folder + '/qemu_out{}'.format(vmid), 'w') as out_file:
print('DEBUG: executing >> {}'.format(command))
@@ -216,7 +226,6 @@ class Testbed(mod.Testbed):
pass
vmid += 1
- return
def __del__(self):
"""
@@ -299,5 +308,3 @@ class Testbed(mod.Testbed):
print('DEBUG: %s of %s tear-down shim processes completed.' % (over_processes, total_processes))
except Empty:
max_waiting_time -= 1
-
- return