aboutsummaryrefslogtreecommitdiff
path: root/rumba/testbeds/emulab.py
diff options
context:
space:
mode:
authorMarco Capitani <m.capitani@nextworks.it>2017-04-21 15:58:56 +0200
committerMarco Capitani <m.capitani@nextworks.it>2017-04-21 15:58:56 +0200
commit26e3e22cd6ca6676b7b99624764f8e6f1ae1479d (patch)
tree65764b5ce423dc88a318e3b7325281bf3a094070 /rumba/testbeds/emulab.py
parentee2f6e5c21c0ba94048dbf1c86024e3181718fc2 (diff)
downloadrumba-26e3e22cd6ca6676b7b99624764f8e6f1ae1479d.tar.gz
rumba-26e3e22cd6ca6676b7b99624764f8e6f1ae1479d.zip
rumba: log: Added logging support, migrated from print to logging.
+ Added logging, migrated, default logging configuration is to stdout. + Minor PEP8 adjustments all-around
Diffstat (limited to 'rumba/testbeds/emulab.py')
-rw-r--r--rumba/testbeds/emulab.py57
1 files changed, 33 insertions, 24 deletions
diff --git a/rumba/testbeds/emulab.py b/rumba/testbeds/emulab.py
index c031327..cc7ce76 100644
--- a/rumba/testbeds/emulab.py
+++ b/rumba/testbeds/emulab.py
@@ -27,9 +27,15 @@ import warnings
import rumba.ssh_support as ssh
import rumba.model as mod
+import rumba.log as log
+
+
+logger = log.get_logger(__name__)
+
warnings.filterwarnings("ignore")
+
# Represents an emulab testbed info
#
# @url [string] URL of the testbed
@@ -46,41 +52,41 @@ class Testbed(mod.Testbed):
self.ops_ssh_config = mod.SSHConfig(self.ops_server())
def ops_server(self):
- '''
+ """
Return server name of the ops-server (is testbed specific)
@param self: testbed info
@return: server name of the ops-server
- '''
+ """
return 'ops.' + self.url
def full_name(self, node_name):
- '''
+ """
Return server name of a node
@param node_name: name of the node
@param self: testbed info
@return: server name of the node
- '''
+ """
return node_name + '.' + self.exp_name + '.' + \
self.proj_name + '.' + self.url
def get_experiment_list(self, project_name=None):
- '''
+ """
Get list of made emulab experiments accessible with your credentials
@param self: testbed info
@param project_name: optional filter on project
@return: list of created experiments (strings)
- '''
+ """
cmd = '/usr/testbed/bin/sslxmlrpc_client.py -m experiment getlist'
out = ssh.execute_command(self, self.ops_ssh_config, cmd)
try:
- if project_name != None:
+ if project_name is not None:
return literal_eval(out)[project_name][project_name]
else:
return literal_eval(out)
@@ -88,11 +94,11 @@ class Testbed(mod.Testbed):
return {project_name: {project_name: []}}
def swap_exp_in(self):
- '''
+ """
Swaps experiment in
@param self: testbed info
- '''
+ """
cmd = '/usr/testbed/bin/sslxmlrpc_client.py swapexp proj=' + \
self.proj_name + \
' exp=' + \
@@ -104,12 +110,12 @@ class Testbed(mod.Testbed):
return output
def _create_experiment(self, experiment):
- '''
+ """
Creates an emulab experiment
@param self: testbed info
@param experiment: the experiment
- '''
+ """
proj_name = self.proj_name
exp_name = self.exp_name
@@ -117,13 +123,13 @@ class Testbed(mod.Testbed):
try:
if exp_name in exp_list[proj_name][proj_name]:
- print("Experiment already exists.")
+ logger.info("Experiment already exists.")
return
except:
- print("First experiment to be created for that project.")
+ logger.info("First experiment to be created for that project.")
ns = self.generate_ns_script(experiment)
- dest_file_name = '/users/'+ self.username + \
+ dest_file_name = '/users/' + self.username + \
'/temp_ns_file.%s.ns' % os.getpid()
ssh.copy_file_to_testbed(self, self.ops_ssh_config, ns, dest_file_name)
@@ -134,10 +140,10 @@ class Testbed(mod.Testbed):
ssh.execute_command(self, self.ops_ssh_config, cmd, time_out=None)
ssh.execute_command(self, self.ops_ssh_config, 'rm ' + dest_file_name)
- print("New experiment succesfully created.")
+ logger.info("New experiment succesfully created.")
def generate_ns_script(self, experiment):
- '''
+ """
Generate ns script based on network graph.
Enables to customize default node image.
@@ -145,7 +151,7 @@ class Testbed(mod.Testbed):
@param self: testbed info
@return: ns2 script for Emulab experiment
- '''
+ """
ns2_script = "# ns script generated by Rumba\n"
ns2_script += "set ns [new Simulator]\n"
@@ -170,12 +176,12 @@ class Testbed(mod.Testbed):
return ns2_script
def wait_until_nodes_up(self):
- '''
+ """
Checks if nodes are up
@param self: testbed info
- '''
- print("Waiting until all nodes are up")
+ """
+ logger.info("Waiting until all nodes are up")
cmd = '/usr/testbed/bin/script_wrapper.py expinfo -e' + \
self.proj_name + \
@@ -187,20 +193,20 @@ class Testbed(mod.Testbed):
active = False
if res == "active":
active = True
- while active != True:
+ while not active:
res = ssh.execute_command(self, self.ops_ssh_config, cmd)
if res == "active":
active = True
- print("Still waiting")
+ logger.info("Still waiting")
time.sleep(5)
def complete_experiment_graph(self, experiment):
- '''
+ """
Gets the interface (ethx) to link mapping
@param self: testbed info
@param experiment: the experiment
- '''
+ """
for node in experiment.nodes:
node.ssh_config.hostname = self.full_name(node.name)
@@ -241,3 +247,6 @@ class Testbed(mod.Testbed):
self.swap_exp_in()
self.wait_until_nodes_up()
self.complete_experiment_graph(experiment)
+
+ def swap_out(self, experiment):
+ pass