diff options
author | Sander Vrijders <sander.vrijders@ugent.be> | 2017-03-28 18:14:32 +0200 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@ugent.be> | 2017-03-28 18:14:32 +0200 |
commit | 92d2849f76c3395f9a51ab79a5726e1df5348ba8 (patch) | |
tree | a6edcfde2679f0377c6d34e16f292ffd5a2391a7 | |
parent | 28556357ef43a549d18bf9a38d3c81b16f0ccbe6 (diff) | |
download | rumba-92d2849f76c3395f9a51ab79a5726e1df5348ba8.tar.gz rumba-92d2849f76c3395f9a51ab79a5726e1df5348ba8.zip |
Fix pylint warnings and errors
This fixes several warnings and errors as reported by pylint.
-rw-r--r-- | rumba/model.py | 40 | ||||
-rw-r--r-- | rumba/prototypes/irati.py | 6 | ||||
-rw-r--r-- | rumba/prototypes/ouroboros.py | 8 | ||||
-rw-r--r-- | rumba/prototypes/rlite.py | 8 | ||||
-rw-r--r-- | rumba/ssh_support.py | 26 | ||||
-rw-r--r-- | rumba/testbeds/emulab.py | 34 | ||||
-rw-r--r-- | rumba/testbeds/faketestbed.py | 3 | ||||
-rw-r--r-- | rumba/testbeds/jfed.py | 17 | ||||
-rw-r--r-- | rumba/testbeds/qemu.py | 3 |
9 files changed, 72 insertions, 73 deletions
diff --git a/rumba/model.py b/rumba/model.py index 0659cb1..c8c00ab 100644 --- a/rumba/model.py +++ b/rumba/model.py @@ -44,7 +44,7 @@ class Testbed: # @name [string] DIF name # class DIF: - def __init__(self, name, members = None): + def __init__(self, name, members=None): self.name = name if members is None: members = list() @@ -62,7 +62,7 @@ class DIF: return other != None and self.name == other.name def __neq__(self, other): - return not (self == other) + return not self == other def add_member(self, node): self.members.append(node) @@ -76,7 +76,7 @@ class DIF: # Shim over UDP # class ShimUDPDIF(DIF): - def __init__(self, name, members = None): + def __init__(self, name, members=None): DIF.__init__(self, name, members) def get_ipcp_class(self): @@ -87,7 +87,7 @@ class ShimUDPDIF(DIF): # @link_speed [int] Speed of the Ethernet network, in Mbps # class ShimEthDIF(DIF): - def __init__(self, name, members = None, link_speed = 0): + def __init__(self, name, members=None, link_speed=0): DIF.__init__(self, name, members) self.link_speed = int(link_speed) if self.link_speed < 0: @@ -101,7 +101,7 @@ class ShimEthDIF(DIF): # @policies [dict] Policies of the normal DIF # class NormalDIF(DIF): - def __init__(self, name, members = None, policies = None): + def __init__(self, name, members=None, policies=None): DIF.__init__(self, name, members) if policies is None: policies = dict() @@ -127,10 +127,8 @@ class NormalDIF(DIF): # @bindings: Binding of names on the processing system # class Node: - def __init__(self, name, difs = None, - dif_registrations = None, - registrations = None, - bindings = None): + def __init__(self, name, difs=None, dif_registrations=None, + registrations=None, bindings=None): self.name = name if difs is None: difs = list() @@ -208,7 +206,7 @@ class Node: return other != None and self.name == other.name def __neq__(self, other): - return not (self == other) + return not self == other def add_dif(self, dif): self.difs.append(dif) @@ -237,11 +235,11 @@ class Node: self._validate() def add_binding(self, name, ap): - self.dif_bindings[name] = ap + self.bindings[name] = ap self._validate() def del_binding(self, name): - del self.dif_bindings[name] + del self.bindings[name] self._validate() # Base class representing an IPC Process to be created in the experiment @@ -276,17 +274,17 @@ class IPCP: and self.dif == other.dif def __neq__(self, other): - return not (self == other) + return not self == other class ShimEthIPCP(IPCP): - def __init__(self, name, node, dif, ifname = None): + def __init__(self, name, node, dif, ifname=None): IPCP.__init__(self, name, node, dif) self.ifname = ifname class ShimUDPIPCP(IPCP): def __init__(self, name, node, dif): IPCP.__init__(self, name, node, dif) - # TODO add IP and port + # TODO: add IP and port # Base class for ARCFIRE experiments # @@ -294,7 +292,7 @@ class ShimUDPIPCP(IPCP): # @nodes: Nodes in the experiment # class Experiment: - def __init__(self, testbed, nodes = None): + def __init__(self, testbed, nodes=None): if nodes is None: nodes = list() self.nodes = nodes @@ -396,7 +394,7 @@ class Experiment: for node in self.nodes: if dif in node.dif_registrations: dif_graphs[dif][node] = [] # init for later use - if first == None: # pick any node for later use + if first is None: # pick any node for later use first = node for lower_dif in node.dif_registrations[dif]: if lower_dif not in neighsets: @@ -413,7 +411,7 @@ class Experiment: self.enrollments.append([]) - if first == None: + if first is None: # This is a shim DIF, nothing to do continue @@ -452,7 +450,7 @@ class Experiment: else: # This is a bug - assert(False) + assert False print("Enrollments:") for el in self.enrollments: @@ -475,8 +473,8 @@ class Experiment: continue ipcp = dif.get_ipcp_class()( - name = '%s.%s' % (dif.name, node.name), - node = node, dif = dif) + name='%s.%s' % (dif.name, node.name), + node=node, dif=dif) if dif in node.dif_registrations: for lower in node.dif_registrations[dif]: diff --git a/rumba/prototypes/irati.py b/rumba/prototypes/irati.py index 90d0861..1babd57 100644 --- a/rumba/prototypes/irati.py +++ b/rumba/prototypes/irati.py @@ -23,7 +23,7 @@ import rumba.model as mod # An experiment over the IRATI implementation class Experiment(mod.Experiment): - def __init__(self, testbed, nodes = None): + def __init__(self, testbed, nodes=None): mod.Experiment.__init__(self, testbed, nodes) def setup(self): @@ -31,7 +31,7 @@ class Experiment(mod.Experiment): cmds.append("sudo apt-get update") cmds.append("sudo apt-get install g++ gcc " - "protobuf-compiler libprotobuf-dev git --yes") + "protobuf-compiler libprotobuf-dev git --yes") cmds.append("sudo rm -rf ~/irati") cmds.append("cd && git clone https://github.com/IRATI/stack irati") cmds.append("cd ~/irati && sudo ./install-from-scratch") @@ -39,7 +39,7 @@ class Experiment(mod.Experiment): for node in self.nodes: ssh.execute_commands(self.testbed, node.full_name, - cmds, time_out = None) + cmds, time_out=None) def run(self): print("[IRATI experiment] start") diff --git a/rumba/prototypes/ouroboros.py b/rumba/prototypes/ouroboros.py index 4359f19..57358cf 100644 --- a/rumba/prototypes/ouroboros.py +++ b/rumba/prototypes/ouroboros.py @@ -23,7 +23,7 @@ import rumba.model as mod # An experiment over the Ouroboros implementation class Experiment(mod.Experiment): - def __init__(self, testbed, nodes = None): + def __init__(self, testbed, nodes=None): mod.Experiment.__init__(self, testbed, nodes) def setup_ouroboros(self): @@ -36,7 +36,8 @@ class Experiment(mod.Experiment): cmds.append("sudo nohup irmd > /dev/null &") for node in self.nodes: - ssh.execute_commands(self.testbed, node.full_name, cmds, time_out = None) + ssh.execute_commands(self.testbed, node.full_name, + cmds, time_out=None) return def bind_names(self): @@ -45,7 +46,8 @@ class Experiment(mod.Experiment): for name, ap in node.bindings.items(): cmds.append("irm b ap " + ap + " n " + name) - ssh.execute_commands(self.testbed, node.full_name, cmds, time_out = None) + ssh.execute_commands(self.testbed, node.full_name, + cmds, time_out=None) def run(self): print("[Ouroboros experiment] start") diff --git a/rumba/prototypes/rlite.py b/rumba/prototypes/rlite.py index 5fa2c37..b175e92 100644 --- a/rumba/prototypes/rlite.py +++ b/rumba/prototypes/rlite.py @@ -23,7 +23,7 @@ import rumba.model as mod # An experiment over the RLITE implementation class Experiment(mod.Experiment): - def __init__(self, testbed, nodes = None): + def __init__(self, testbed, nodes=None): mod.Experiment.__init__(self, testbed, nodes) def setup(self): @@ -31,8 +31,8 @@ class Experiment(mod.Experiment): cmds.append("sudo apt-get update") cmds.append("sudo apt-get install g++ gcc cmake " - "linux-headers-$(uname -r) " - "protobuf-compiler libprotobuf-dev git --yes") + "linux-headers-$(uname -r) " + "protobuf-compiler libprotobuf-dev git --yes") cmds.append("sudo rm -rf ~/rlite") cmds.append("cd ~; git clone https://github.com/vmaffione/rlite") cmds.append("cd ~/rlite && ./configure && make && sudo make install") @@ -40,7 +40,7 @@ class Experiment(mod.Experiment): for node in self.nodes: ssh.execute_commands(self.testbed, node.full_name, - cmds, time_out = None) + cmds, time_out=None) def run(self): print("[RLITE experiment] start") diff --git a/rumba/ssh_support.py b/rumba/ssh_support.py index 552c43f..13ac1c6 100644 --- a/rumba/ssh_support.py +++ b/rumba/ssh_support.py @@ -27,7 +27,7 @@ def get_ssh_client(): return ssh_client -def execute_commands(testbed, hostname, commands, time_out = 3): +def execute_commands(testbed, hostname, commands, time_out=3): ''' Remote execution of a list of shell command on hostname. By default this function will exit (timeout) after 3 seconds. @@ -44,9 +44,10 @@ def execute_commands(testbed, hostname, commands, time_out = 3): try: ssh_client.connect(hostname, 22, testbed.username, testbed.password, - look_for_keys = True, timeout = time_out) + look_for_keys=True, timeout=time_out) for command in commands: stdin, stdout, stderr = ssh_client.exec_command(command) + del stdin, stdout err = str(stderr.read()).strip('b\'\"\\n') if err != "": err_array = err.split('\\n') @@ -58,7 +59,7 @@ def execute_commands(testbed, hostname, commands, time_out = 3): print(str(e)) return -def execute_command(testbed, hostname, command, time_out = 3): +def execute_command(testbed, hostname, command, time_out=3): ''' Remote execution of a list of shell command on hostname. By default this function will exit (timeout) after 3 seconds. @@ -77,8 +78,9 @@ def execute_command(testbed, hostname, command, time_out = 3): try: ssh_client.connect(hostname, 22, testbed.username, testbed.password, - look_for_keys = True, timeout = time_out) + look_for_keys=True, timeout=time_out) stdin, stdout, stderr = ssh_client.exec_command(command) + del stdin err = str(stderr.read()).strip('b\'\"\\n') if err != "": print(err) @@ -113,6 +115,7 @@ def copy_file_to_testbed(testbed, hostname, text, file_name): "; chmod a+rwx " + file_name stdin, stdout, stderr = ssh_client.exec_command(cmd) + del stdin, stdout err = str(stderr.read()).strip('b\'\"\\n') if err != "": print(err) @@ -126,31 +129,30 @@ def copy_file_to_testbed(testbed, hostname, text, file_name): except Exception as e: print(str(e)) -def setup_vlan(testbed, node_name, vlan_id, int_name): +def setup_vlan(testbed, node, vlan_id, int_name): ''' Gets the interface (ethx) to link mapping @param testbed: testbed info - @param node_name: the node to create the VLAN on + @param node: the node to create the VLAN on @param vlan_id: the VLAN id @param int_name: the name of the interface ''' - print("Setting up VLAN on node " + node_name) + print("Setting up VLAN on node " + node.name) - node_full_name = full_name(node_name, testbed) cmd = "sudo ip link add link " + \ str(int_name) + \ " name " + str(int_name) + \ "." + str(vlan_id) + \ " type vlan id " + str(vlan_id) - execute_command(testbed, node_full_name, cmd) + execute_command(testbed, node.full_name, cmd) cmd = "sudo ifconfig " + \ str(int_name) + "." + \ str(vlan_id) + " up" - execute_command(node_full_name, cmd, testbed) + execute_command(node.full_name, cmd, testbed) cmd = "sudo ethtool -K " + \ str(int_name) + " rxvlan off" - execute_command(node_full_name, cmd, testbed) + execute_command(node.full_name, cmd, testbed) cmd = "sudo ethtool -K " + \ str(int_name) + " txvlan off" - execute_command(node_full_name, cmd, testbed) + execute_command(node.full_name, cmd, testbed) diff --git a/rumba/testbeds/emulab.py b/rumba/testbeds/emulab.py index 971202b..134d344 100644 --- a/rumba/testbeds/emulab.py +++ b/rumba/testbeds/emulab.py @@ -23,11 +23,11 @@ import os import time import re from ast import literal_eval +import warnings import rumba.ssh_support as ssh import rumba.model as mod -import warnings warnings.filterwarnings("ignore") # Represents an emulab testbed info @@ -36,9 +36,9 @@ warnings.filterwarnings("ignore") # @image [string] specific image to use # class Testbed(mod.Testbed): - def __init__(self, exp_name, username, password = "", - proj_name = "ARCFIRE", url = "wall2.ilabt.iminds.be", - image = "UBUNTU14-64-STD"): + def __init__(self, exp_name, username, password="", + proj_name="ARCFIRE", url="wall2.ilabt.iminds.be", + image="UBUNTU14-64-STD"): mod.Testbed.__init__(self, exp_name, username, password, proj_name) self.url = url self.image = image @@ -66,7 +66,7 @@ class Testbed(mod.Testbed): return node_name + '.' + self.exp_name + '.' + \ self.proj_name + '.' + self.url - def get_experiment_list(self, project_name = None): + def get_experiment_list(self, project_name=None): ''' Get list of made emulab experiments accessible with your credentials @@ -80,11 +80,11 @@ class Testbed(mod.Testbed): try: if project_name != None: - return literal_eval(out)[project_name][project_name] + return literal_eval(out)[project_name][project_name] else: - return literal_eval(out) + return literal_eval(out) except: - return { project_name: { project_name: [] }} + return {project_name: {project_name: []}} def swap_exp_in(self): ''' @@ -131,8 +131,8 @@ class Testbed(mod.Testbed): '" exp="' + exp_name + '" noswapin=true ' + \ 'nsfilepath="' + dest_file_name + '"' - ssh.execute_command(self, self.ops_server(), cmd, time_out = None) - ssh.execute_command(self, self.ops_server(),'rm ' + dest_file_name) + ssh.execute_command(self, self.ops_server(), cmd, time_out=None) + ssh.execute_command(self, self.ops_server(), 'rm ' + dest_file_name) print("New experiment succesfully created.") def generate_ns_script(self, experiment): @@ -151,12 +151,12 @@ class Testbed(mod.Testbed): ns2_script += "source tb_compat.tcl\n" for node in experiment.nodes: - ns2_script += "set " + node.name + " [$ns node]\n" - ns2_script += "tb-set-node-os $" + node.name + " " + \ - self.image + "\n" + ns2_script += "set " + node.name + " [$ns node]\n" + ns2_script += "tb-set-node-os $" + node.name + " " + \ + self.image + "\n" for dif in experiment.dif_ordering: - if type(dif) is mod.ShimEthDIF: + if isinstance(dif, mod.ShimEthDIF): if len(dif.ipcps) != 2: continue ns2_script += "set " + dif.name + \ @@ -220,17 +220,17 @@ class Testbed(mod.Testbed): continue for ipcp in node.ipcps: if ipcp.dif.name == link_name: - self.ip[ipcp] = link_ip + self.ip[ipcp] = link_ip for node in experiment.nodes: cmd = 'cat /var/emulab/boot/ifmap' - node_full_name = self.full_name(node.name) + node_full_name = self.full_name(node.name) output = ssh.execute_command(self, node_full_name, cmd) output = re.split('\\\\n', output) for item in output: item = item.split() for ipcp in node.ipcps: - if type(ipcp) is mod.ShimEthIPCP: + if isinstance(ipcp, mod.ShimEthIPCP): if self.ip[ipcp] == item[1]: ipcp.ifname = item[0] node.full_name = self.full_name(node.name) diff --git a/rumba/testbeds/faketestbed.py b/rumba/testbeds/faketestbed.py index 8d5e724..4821aa8 100644 --- a/rumba/testbeds/faketestbed.py +++ b/rumba/testbeds/faketestbed.py @@ -22,8 +22,7 @@ import rumba.model as mod # Fake testbed, useful for testing class Testbed(mod.Testbed): - def __init__(self, exp_name, username, proj_name = "ARCFIRE", - password = ""): + def __init__(self, exp_name, username, proj_name="ARCFIRE", password=""): mod.Testbed.__init__(self, exp_name, username, password, proj_name) def create_experiment(self, experiment): diff --git a/rumba/testbeds/jfed.py b/rumba/testbeds/jfed.py index 4a36d4a..e606846 100644 --- a/rumba/testbeds/jfed.py +++ b/rumba/testbeds/jfed.py @@ -25,9 +25,9 @@ import xml.dom.minidom as xml import rumba.model as mod class Testbed(mod.Testbed): - def __init__(self, exp_name, username, cert_file, jfed_jar, exp_hours = "2", - proj_name = "ARCFIRE", authority = "wall2.ilabt.iminds.be"): - passwd = getpass.getpass(prompt = "Password for certificate file: ") + def __init__(self, exp_name, username, cert_file, jfed_jar, exp_hours="2", + proj_name="ARCFIRE", authority="wall2.ilabt.iminds.be"): + passwd = getpass.getpass(prompt="Password for certificate file: ") mod.Testbed.__init__(self, exp_name, username, passwd, proj_name) self.authority = "urn:publicid:IDN+" + authority + "+authority+cm" self.auth_name = authority @@ -35,10 +35,10 @@ class Testbed(mod.Testbed): self.jfed_jar = jfed_jar self.exp_hours = exp_hours self.if_id = dict() - - def create_rspec(self, experiment): self.rspec = self.exp_name + ".rspec" + self.manifest = self.exp_name + ".rrspec" + def create_rspec(self, experiment): impl = xml.getDOMImplementation() doc = impl.createDocument(None, "rspec", None) @@ -80,7 +80,7 @@ class Testbed(mod.Testbed): node.ifs = 0 for ipcp in node.ipcps: - if type(ipcp) is mod.ShimEthIPCP: + if isinstance(ipcp, mod.ShimEthIPCP): el3 = doc.createElement("interface") self.if_id[ipcp] = node.name + ":if" + str(node.ifs) el3.setAttribute("client_id", self.if_id[ipcp]) @@ -88,7 +88,7 @@ class Testbed(mod.Testbed): el.appendChild(el3) for dif in experiment.dif_ordering: - if type(dif) is mod.ShimEthDIF: + if isinstance(dif, mod.ShimEthDIF): el = doc.createElement("link") top_el.appendChild(el) el.setAttribute("client_id", dif.name) @@ -108,7 +108,6 @@ class Testbed(mod.Testbed): def create_experiment(self, experiment): self.create_rspec(experiment) - self.manifest = self.exp_name + ".rrspec" for node in experiment.nodes: auth_name_r = self.auth_name.replace(".", "-") @@ -140,7 +139,7 @@ class Testbed(mod.Testbed): for intf in intfs: i_name = intf.getAttribute("client_id") for ipcp in node_n.ipcps: - if type(ipcp) is mod.ShimEthIPCP: + if isinstance(ipcp, mod.ShimEthIPCP): if self.if_id[ipcp] == i_name: comp_id = intf.getAttribute("component_id") comp_arr = comp_id.split(":") diff --git a/rumba/testbeds/qemu.py b/rumba/testbeds/qemu.py index 3f4cb4a..158f360 100644 --- a/rumba/testbeds/qemu.py +++ b/rumba/testbeds/qemu.py @@ -22,8 +22,7 @@ import rumba.model as mod # Fake testbed, useful for testing class Testbed(mod.Testbed): - def __init__(self, exp_name, username, proj_name = "ARCFIRE", - password = ""): + def __init__(self, exp_name, username, proj_name="ARCFIRE", password=""): mod.Testbed.__init__(self, exp_name, username, password, proj_name) def create_experiment(self, experiment): |