aboutsummaryrefslogtreecommitdiff
path: root/rumba/testbeds/qemu.py
diff options
context:
space:
mode:
authorMarco Capitani <m.capitani@nextworks.it>2017-04-10 12:07:16 +0200
committerMarco Capitani <m.capitani@nextworks.it>2017-04-10 12:07:16 +0200
commit8797eff49aede4ad06ba668e4cee59accc12d1af (patch)
treebf3213073ff88ae3683acae5d3e2b9f2e07a0877 /rumba/testbeds/qemu.py
parentae113f8d19eb29a0edb50bf790275414125f78ca (diff)
downloadrumba-8797eff49aede4ad06ba668e4cee59accc12d1af.tar.gz
rumba-8797eff49aede4ad06ba668e4cee59accc12d1af.zip
Forced teardown. Ignores errors and makes sure that everything is pulled down.
Diffstat (limited to 'rumba/testbeds/qemu.py')
-rw-r--r--rumba/testbeds/qemu.py44
1 files changed, 24 insertions, 20 deletions
diff --git a/rumba/testbeds/qemu.py b/rumba/testbeds/qemu.py
index 1830b37..1c5d486 100644
--- a/rumba/testbeds/qemu.py
+++ b/rumba/testbeds/qemu.py
@@ -17,7 +17,6 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA
-import getpass
import multiprocessing
import time
import subprocess
@@ -39,7 +38,7 @@ class Testbed(mod.Testbed):
self.boot_processes = []
@staticmethod
- def _run_command_chain(commands, results_queue, error_queue):
+ def _run_command_chain(commands, results_queue, error_queue, ignore_errors=False):
"""
Runs (sequentially) the command list.
@@ -53,16 +52,22 @@ class Testbed(mod.Testbed):
:param error_queue: Queue of error(s) encountered
:return: None
"""
- try:
- for command in commands:
- if not error_queue.empty():
- break
- print('DEBUG: executing >> %s' % command)
+ errors = 0
+ for command in commands:
+ if not error_queue.empty() and not ignore_errors:
+ break
+ print('DEBUG: executing >> %s' % command)
+ try:
subprocess.check_call(command.split())
-
+ except subprocess.CalledProcessError as e:
+ error_queue.put(str(e))
+ errors += 1
+ if not ignore_errors:
+ break
+ if errors == 0:
results_queue.put("Command chain ran correctly.")
- except subprocess.CalledProcessError as e:
- error_queue.put(str(e))
+ else:
+ results_queue.put("Command chain ran with %d errors" % errors)
def swap_in(self, experiment):
"""
@@ -70,15 +75,10 @@ class Testbed(mod.Testbed):
:param experiment: The experiment running
"""
if os.geteuid() != 0:
- pw = getpass.getpass('[sudo] password for %s:' % getpass.getuser())
- if '"' in pw or "'" in pw:
- print('Illegal password: contains " or \'')
+ try:
+ subprocess.check_call(["sudo", "-v"])
+ except subprocess.CalledProcessError:
raise Exception('Not authenticated')
- else:
- try:
- subprocess.check_call("sudo -v -p '{}'".format(pw).split())
- except subprocess.CalledProcessError:
- raise Exception('Not authenticated')
print("[QEMU testbed] swapping in")
@@ -257,7 +257,9 @@ class Testbed(mod.Testbed):
'sudo ip tuntap del mode tap name %(tap)s'
% {'tap': tap, 'br': shim.name}
).split('\n')
- process = multiprocessing.Process(target=self._run_command_chain, args=(commands, results_queue, error_queue))
+ process = multiprocessing.Process(target=self._run_command_chain,
+ args=(commands, results_queue, error_queue),
+ kwargs={'ignore_errors': True})
port_processes.append(process)
process.start()
@@ -289,7 +291,9 @@ class Testbed(mod.Testbed):
'sudo brctl delbr %(br)s'
% {'br': shim.name}
).split('\n')
- process = multiprocessing.Process(target=self._run_command_chain, args=(commands, results_queue, error_queue))
+ process = multiprocessing.Process(target=self._run_command_chain,
+ args=(commands, results_queue, error_queue),
+ kwargs={'ignore_errors': True})
shim_processes.append(process)
process.start()