diff options
author | vmaffione <v.maffione@gmail.com> | 2017-04-10 10:28:14 +0000 |
---|---|---|
committer | vmaffione <v.maffione@gmail.com> | 2017-04-10 10:28:14 +0000 |
commit | 01bed194b2fbba025d0d3500db83c8ebed2f2fb4 (patch) | |
tree | bf3213073ff88ae3683acae5d3e2b9f2e07a0877 | |
parent | ae113f8d19eb29a0edb50bf790275414125f78ca (diff) | |
parent | 8797eff49aede4ad06ba668e4cee59accc12d1af (diff) | |
download | rumba-01bed194b2fbba025d0d3500db83c8ebed2f2fb4.tar.gz rumba-01bed194b2fbba025d0d3500db83c8ebed2f2fb4.zip |
Merge branch 'master-marco' into 'master'
Forced teardown.
See merge request !21
-rw-r--r-- | rumba/model.py | 17 | ||||
-rw-r--r-- | rumba/testbeds/qemu.py | 44 |
2 files changed, 33 insertions, 28 deletions
diff --git a/rumba/model.py b/rumba/model.py index 99bf5ed..faf353c 100644 --- a/rumba/model.py +++ b/rumba/model.py @@ -615,12 +615,13 @@ class Experiment: raise Exception('run_prototype() method not implemented') def run(self): - # Realize the experiment testbed (testbed-specific) - self.testbed.swap_in(self) - - # Run the experiment using the prototype (prototype-specific) - self.run_prototype() - - # Undo the testbed (testbed-specific) - self.testbed.swap_out(self) + try: + # Realize the experiment testbed (testbed-specific) + self.testbed.swap_in(self) + + # Run the experiment using the prototype (prototype-specific) + self.run_prototype() + finally: + # No matter what happens, undo the testbed (testbed-specific) + self.testbed.swap_out(self) 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() |