aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincenzo Maffione <v.maffione@gmail.com>2017-04-08 12:01:54 +0200
committerVincenzo Maffione <v.maffione@gmail.com>2017-04-08 12:08:13 +0200
commitd07592d34d1636a41be214e7df5c828c6d4aa3c2 (patch)
tree3740ed4610d0a712ff4fc44d0600ae7cb0de75ec
parentf1630941a0c47fdd025219340e5383cbaefcd85e (diff)
downloadrumba-d07592d34d1636a41be214e7df5c828c6d4aa3c2.tar.gz
rumba-d07592d34d1636a41be214e7df5c828c6d4aa3c2.zip
testbeds: qemu: port to python3, use explicit module names
-rw-r--r--rumba/testbeds/qemu.py55
1 files changed, 27 insertions, 28 deletions
diff --git a/rumba/testbeds/qemu.py b/rumba/testbeds/qemu.py
index 49bfcc2..8079f28 100644
--- a/rumba/testbeds/qemu.py
+++ b/rumba/testbeds/qemu.py
@@ -17,14 +17,13 @@
# License along with this library; if not, write to the Free Software
# 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 getpass
+import multiprocessing
+import time
+import subprocess
+import os
import rumba.model as mod
-from subprocess import Popen, check_call, CalledProcessError
class Testbed(mod.Testbed):
@@ -58,10 +57,10 @@ class Testbed(mod.Testbed):
if not error_queue.empty():
break
print('DEBUG: executing >> {}'.format(command))
- check_call(command.split())
+ subprocess.check_call(command.split())
results_queue.put("Command chain ran correctly.")
- except CalledProcessError as e:
+ except subprocess.CalledProcessError as e:
error_queue.put(str(e))
def swap_in(self, experiment):
@@ -69,23 +68,23 @@ class Testbed(mod.Testbed):
:type experiment mod.Experiment
:param experiment: The experiment running
"""
- if geteuid() != 0:
- pw = getpass('[sudo] password for {}:'.format(getuser()))
+ if os.geteuid() != 0:
+ pw = getpass.getpass('[sudo] password for {}:'.format(getpass.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:
+ subprocess.check_call("sudo -v -p '{}'".format(pw).split())
+ except subprocess.CalledProcessError:
raise Exception('Not authenticated')
print("[QEMU testbed] swapping in")
# Building bridges and taps
shim_processes = []
- r_queue = Queue()
- e_queue = Queue()
+ r_queue = multiprocessing.Queue()
+ e_queue = multiprocessing.Queue()
print(experiment.dif_ordering)
for shim in experiment.dif_ordering:
command_list = []
@@ -129,7 +128,7 @@ class Testbed(mod.Testbed):
if not e_queue.empty():
break
# Launch commands asynchronously
- process = Process(target=self._run_command_chain, args=(command_list, r_queue, e_queue))
+ process = multiprocessing.Process(target=self._run_command_chain, args=(command_list, r_queue, e_queue))
shim_processes.append(process)
process.start()
@@ -150,12 +149,12 @@ class Testbed(mod.Testbed):
if result == "Command chain ran correctly.":
over_processes += 1
print('DEBUG: %s of %s processes completed.' % (over_processes, total_processes))
- except Empty:
+ except:
max_waiting_time -= 1
# Building vms
- boot_batch_size = max(1, cpu_count() // 2)
+ boot_batch_size = max(1, multiprocessing.cpu_count() // 2)
booting_budget = boot_batch_size
boot_backoff = 12
base_port = 2222
@@ -217,17 +216,17 @@ class Testbed(mod.Testbed):
booting_budget -= 1
if booting_budget <= 0:
print('Sleeping for {} seconds to give the machines time to boot up.'.format(boot_backoff))
- sleep(boot_backoff)
+ time.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))
- self.boot_processes.append(Popen(command.split(), stdout=out_file))
+ self.boot_processes.append(subprocess.Popen(command.split(), stdout=out_file))
pass
vmid += 1
- def swap_out(self):
+ def swap_out(self, experiment):
"""
:rtype str
:return: The script to tear down the experiment
@@ -241,8 +240,8 @@ class Testbed(mod.Testbed):
process.wait()
port_processes = []
- error_queue = Queue()
- results_queue = Queue()
+ error_queue = multiprocessing.Queue()
+ results_queue = multiprocessing.Queue()
for vm_name, vm in self.vms.items():
for port in vm['ports']:
tap = port['tap_id']
@@ -255,7 +254,7 @@ class Testbed(mod.Testbed):
'sudo ip tuntap del mode tap name %(tap)s'
% {'tap': tap, 'br': shim.name}
).split('\n')
- process = 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))
port_processes.append(process)
process.start()
@@ -274,11 +273,11 @@ class Testbed(mod.Testbed):
if result == "Command chain ran correctly.":
over_processes += 1
print('DEBUG: %s of %s tear-down port processes completed.' % (over_processes, total_processes))
- except Empty:
+ except:
max_waiting_time -= 1
- error_queue = Queue()
- results_queue = Queue()
+ error_queue = multiprocessing.Queue()
+ results_queue = multiprocessing.Queue()
shim_processes = []
for shim in self.shims:
@@ -287,7 +286,7 @@ class Testbed(mod.Testbed):
'sudo brctl delbr %(br)s'
% {'br': shim.name}
).split('\n')
- process = 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))
shim_processes.append(process)
process.start()
@@ -306,5 +305,5 @@ class Testbed(mod.Testbed):
if result == "Command chain ran correctly.":
over_processes += 1
print('DEBUG: %s of %s tear-down shim processes completed.' % (over_processes, total_processes))
- except Empty:
+ except:
max_waiting_time -= 1