From: Thierry Parmentelat Date: Wed, 14 Oct 2015 15:04:49 +0000 (+0200) Subject: still making both branches closer X-Git-Tag: nepi-6.0.0-pypi~21 X-Git-Url: http://git.onelab.eu/?p=nepi.git;a=commitdiff_plain;h=58a2b493f8df1072a1faa653c8abb6a3f9ba21fa still making both branches closer merge in master branch changes made on py3 that make total sense in py2 assertEquals will be handled separately --- diff --git a/examples/ccn_emu_live/dce.py b/examples/ccn_emu_live/dce.py index 4b51b170..ef56243f 100644 --- a/examples/ccn_emu_live/dce.py +++ b/examples/ccn_emu_live/dce.py @@ -162,7 +162,7 @@ def avg_interests(ec, run): ### Compute metric: Avg number of Interests seen per content name ### normalized by the number of nodes in the shortest path - content_name_count = len(content_names.values()) + content_name_count = len(content_names) nodes_in_shortest_path = len(shortest_path) - 1 metric = interest_count / (float(content_name_count) * float(nodes_in_shortest_path)) diff --git a/examples/ccn_emu_live/dce_4_nodes_linear.py b/examples/ccn_emu_live/dce_4_nodes_linear.py index b738798d..a2c7bb21 100644 --- a/examples/ccn_emu_live/dce_4_nodes_linear.py +++ b/examples/ccn_emu_live/dce_4_nodes_linear.py @@ -46,7 +46,7 @@ def avg_interest_rtt(ec, run): # statistics on RTT rtts = [content_names[content_name]["rtt"] \ - for content_name in content_names.keys()] + for content_name in content_names] # sample mean and standard deviation sample = numpy.array(rtts) diff --git a/examples/ccn_emu_live/planetlab.py b/examples/ccn_emu_live/planetlab.py index b51925d9..fc165604 100644 --- a/examples/ccn_emu_live/planetlab.py +++ b/examples/ccn_emu_live/planetlab.py @@ -166,7 +166,7 @@ def avg_interests(ec, run): ### Compute metric: Avg number of Interests seen per content name ### normalized by the number of nodes in the shortest path - content_name_count = len(content_names.values()) + content_name_count = len(content_names) nodes_in_shortest_path = len(shortest_path) - 1 metric = interest_count / (float(content_name_count) * float(nodes_in_shortest_path)) diff --git a/examples/ccn_emu_live/planetlab_4_nodes_linear.py b/examples/ccn_emu_live/planetlab_4_nodes_linear.py index b48f496e..e3736196 100644 --- a/examples/ccn_emu_live/planetlab_4_nodes_linear.py +++ b/examples/ccn_emu_live/planetlab_4_nodes_linear.py @@ -74,7 +74,7 @@ def avg_interest_rtt(ec, run): # statistics on RTT rtts = [content_names[content_name]["rtt"] \ - for content_name in content_names.keys()] + for content_name in content_names] # sample mean and standard deviation sample = numpy.array(rtts) diff --git a/examples/linux/ccn_transfer_using_linuxapp.py b/examples/linux/ccn_transfer_using_linuxapp.py index 1db375d5..8bf7cfc0 100644 --- a/examples/linux/ccn_transfer_using_linuxapp.py +++ b/examples/linux/ccn_transfer_using_linuxapp.py @@ -118,7 +118,7 @@ def add_ccnd(ec, peers): # BASH command -> ' ccndstart ; ccndc add ccnx:/ udp host ; ccnr ' command = "ccndstart && " - peers = map(lambda peer: "ccndc add ccnx:/ udp %s" % peer, peers) + peers = ["ccndc add ccnx:/ udp %s" % peer for peer in peers] command += " ; ".join(peers) + " && " command += " ccnr & " diff --git a/examples/linux/testing/ccncat_2_nodes.py b/examples/linux/testing/ccncat_2_nodes.py index 2dc39abb..cc47d829 100644 --- a/examples/linux/testing/ccncat_2_nodes.py +++ b/examples/linux/testing/ccncat_2_nodes.py @@ -96,7 +96,7 @@ def add_ccnd(ec, os_type, peers): # BASH command -> ' ccndstart ; ccndc add ccnx:/ udp host ; ccnr ' command = "ccndstart && " - peers = map(lambda peer: "ccndc add ccnx:/ udp %s" % peer, peers) + peers = ["ccndc add ccnx:/ udp %s" % peer for peer in peers] command += " ; ".join(peers) + " && " command += " ccnr & " diff --git a/examples/linux/testing/ccncat_extended_ring_topo.py b/examples/linux/testing/ccncat_extended_ring_topo.py index 6a46abc2..27932e24 100644 --- a/examples/linux/testing/ccncat_extended_ring_topo.py +++ b/examples/linux/testing/ccncat_extended_ring_topo.py @@ -213,7 +213,7 @@ if __name__ == '__main__': # Register a collector to automatically collect traces collector = add_collector(ec, "stderr") - for ccnd in ccnds.values(): + for ccnd in ccnds: ec.register_connection(collector, ccnd) # deploy all ResourceManagers diff --git a/examples/omf/testing/nepi_omf5_nitos_ccncat.py b/examples/omf/testing/nepi_omf5_nitos_ccncat.py index 5e36795e..a7bf10b1 100644 --- a/examples/omf/testing/nepi_omf5_nitos_ccncat.py +++ b/examples/omf/testing/nepi_omf5_nitos_ccncat.py @@ -88,7 +88,7 @@ def add_ccnd(ec, peers, xmppServer, xmppUser, xmppPort = "5222", xmppPassword = CCNR_DIRECTORY="/root" CCNR_STATUS_PORT="8080"' # BASH command -> ' ccndstart ; ccndc add ccnx:/ udp host ; ccnr ' - peers = map(lambda peer: "ccndc add ccnx:/ udp %s" % peer, peers) + peers = ["ccndc add ccnx:/ udp %s" % peer for peer in peers] #command += " ; ".join(peers) + " && " command = peers[0] diff --git a/examples/omf/testing/nepi_omf5_nitos_ccnring.py b/examples/omf/testing/nepi_omf5_nitos_ccnring.py index 98a41a06..d38ba6bf 100644 --- a/examples/omf/testing/nepi_omf5_nitos_ccnring.py +++ b/examples/omf/testing/nepi_omf5_nitos_ccnring.py @@ -176,23 +176,23 @@ if __name__ == '__main__': nodes = dict() chann = add_channel(ec, channel, xmpp_slice, xmpp_host) - for i in xrange(len(all_hosts)): - node = add_node(ec,all_hosts[i], xmpp_slice, xmpp_host) + for i, host in enumerate(all_hosts): + node = add_node(ec ,host, xmpp_slice, xmpp_host) iface = add_interface(ec, all_ip[i], xmpp_slice, xmpp_host) ec.register_connection(node, iface) ec.register_connection(iface, chann) - nodes[all_hosts[i]] = node + nodes[host] = node # CCN setup for the node ccnds = dict() ccnrs = dict() - for i in xrange(len(all_hosts)): - ccndstart = add_app(ec, nodes[all_hosts[i]], "#ccndstart", "ccndstart &", + for i, host in enumerate(all_hosts): + ccndstart = add_app(ec, nodes[host], "#ccndstart", "ccndstart &", env, xmpp_slice, xmpp_host) - ccnr = add_app(ec, nodes[all_hosts[i]], "#ccnr", "ccnr &", + ccnr = add_app(ec, nodes[host], "#ccnr", "ccnr &", env, xmpp_slice, xmpp_host) - ccnds[all_hosts[i]] = ccndstart - ccnrs[all_hosts[i]] = ccnr + ccnds[host] = ccndstart + ccnrs[host] = ccnr ec.register_condition(ccnr, ResourceAction.START, ccndstart, ResourceState.STARTED, "1s") # CCNDC setup @@ -226,9 +226,9 @@ if __name__ == '__main__': link = [l1u, l1d, l2u, l2d, l3u, l3d, l4u, l4d, l5u, l5d, b1u, b1d, b2u, b2d] # List of condition - for i in xrange(len(all_hosts)): - ec.register_condition(ccnrs[all_hosts[i]], ResourceAction.START, ccnds[all_hosts[i]], ResourceState.STARTED, "1s") - ec.register_condition(link, ResourceAction.START, ccnrs[all_hosts[i]], ResourceState.STARTED, "1s") + for host in all_hosts: + ec.register_condition(ccnrs[host], ResourceAction.START, ccnds[host], ResourceState.STARTED, "1s") + ec.register_condition(link, ResourceAction.START, ccnrs[host], ResourceState.STARTED, "1s") # Streaming Server pub = add_publish(ec, nodes[host5], movie, xmpp_slice, xmpp_host) @@ -255,17 +255,17 @@ if __name__ == '__main__': # Cleaning when the experiment stop ccndstops = [] - for i in xrange(len(all_hosts)): - ccndstop = add_app(ec, nodes[all_hosts[i]], "#ccndstop", "ccndstop", env, xmpp_slice, xmpp_host) + for host all_hosts: + ccndstop = add_app(ec, nodes[host], "#ccndstop", "ccndstop", env, xmpp_slice, xmpp_host) ccndstops.append(ccndstop) killall = add_app(ec, nodes[host6], "#kill", "killall sh", "", xmpp_slice, xmpp_host) # Condition to stop and clean the experiment apps = [] - for i in xrange(len(all_hosts)): - apps.append(ccnds[all_hosts[i]]) - apps.append(ccnrs[all_hosts[i]]) + for host in all_hosts: + apps.append(ccnds[host]) + apps.append(ccnrs[host]) apps += link apps.append(pub) apps.append(stream) diff --git a/examples/omf/testing/nepi_omf5_plexus_ccncat_linear.py b/examples/omf/testing/nepi_omf5_plexus_ccncat_linear.py index 7e37435b..bb812ef5 100644 --- a/examples/omf/testing/nepi_omf5_plexus_ccncat_linear.py +++ b/examples/omf/testing/nepi_omf5_plexus_ccncat_linear.py @@ -166,12 +166,12 @@ if __name__ == '__main__': nodes = dict() chann = add_channel(ec, channel, xmpp_slice, xmpp_host) - for i in xrange(len(all_hosts)): - node = add_node(ec,all_hosts[i], xmpp_slice, xmpp_host) + for i, host in enumerate(all_hosts): + node = add_node(ec,host, xmpp_slice, xmpp_host) iface = add_interface(ec, all_ip[i], xmpp_slice, xmpp_host) ec.register_connection(node, iface) ec.register_connection(iface, chann) - nodes[all_hosts[i]] = node + nodes[host] = node #### CCN setup for the node ### ccnds = dict() @@ -213,28 +213,28 @@ if __name__ == '__main__': # Do the iperf iperfserv = dict() iperfclient = dict() - for i in xrange(len(all_hosts)): - perfserv = add_app(ec, nodes[all_hosts[i]], "#perfserv", "iperf -s > /opt/iperfserv.txt", + for i, host in enumerate(all_hosts): + perfserv = add_app(ec, nodes[host], "#perfserv", "iperf -s > /opt/iperfserv.txt", env, xmpp_slice, xmpp_host) - iperfclient[all_hosts[i]] = [] + iperfclient[host] = [] if i > 0: cmd = "iperf -c " + all_ip[i-1] + " > /opt/iperclient1.txt" - perfclient1 = add_app(ec, nodes[all_hosts[i]], "#perfclient1", cmd, + perfclient1 = add_app(ec, nodes[host], "#perfclient1", cmd, env, xmpp_slice, xmpp_host) - iperfclient[all_hosts[i]].append(perfclient1) + iperfclient[host].append(perfclient1) if i < (len(all_hosts)-1): cmd = "iperf -c " + all_ip[i+1] + " > /opt/iperclient2.txt" - perfclient2 = add_app(ec, nodes[all_hosts[i]], "#perfclient2", cmd, + perfclient2 = add_app(ec, nodes[host], "#perfclient2", cmd, env, xmpp_slice, xmpp_host) - iperfclient[all_hosts[i]].append(perfclient2) + iperfclient[host].append(perfclient2) - iperfserv[all_hosts[i]] = perfserv + iperfserv[host] = perfserv - for i in xrange(len(all_hosts)): - #ec.register_condition(iperfserv[all_hosts[i]], ResourceAction.START, link, ResourceState.STARTED, "2s") - for elt in iperfclient[all_hosts[i]]: - ec.register_condition(elt, ResourceAction.START, iperfserv[all_hosts[i]], ResourceState.STARTED, "3s") + for host in all_hosts: + #ec.register_condition(iperfserv[host], ResourceAction.START, link, ResourceState.STARTED, "2s") + for elt in iperfclient[host]: + ec.register_condition(elt, ResourceAction.START, iperfserv[host], ResourceState.STARTED, "3s") ## Streaming Server @@ -257,18 +257,18 @@ if __name__ == '__main__': ## ccndstop = add_app(ec, nodes[all_hosts[i]], "#ccndstop", "ccndstop", env, xmpp_slice, xmpp_host) ## ccndstops.append(ccndstop) perfkill = dict() - for i in xrange(len(all_hosts)): - kill = add_app(ec, nodes[all_hosts[i]], "#kill", "killall iperf", "", xmpp_slice, xmpp_host) - perfkill[all_hosts[i]] = kill + for host in all_hosts: + kill = add_app(ec, nodes[host], "#kill", "killall iperf", "", xmpp_slice, xmpp_host) + perfkill[host] = kill # Condition to stop and clean the experiment apps = [] - for i in xrange(len(all_hosts)): -# apps.append(ccnds[all_hosts[i]]) -# apps.append(ccnrs[all_hosts[i]]) - apps.append(iperfserv[all_hosts[i]]) - for elt in iperfclient[all_hosts[i]]: + for host in all_hosts: +# apps.append(ccnds[host]) +# apps.append(ccnrs[host]) + apps.append(iperfserv[host]) + for elt in iperfclient[host]: apps.append(elt) # apps += link #apps.append(pub) @@ -280,8 +280,8 @@ if __name__ == '__main__': # ec.register_condition(ccndstops + [killall], ResourceAction.STOP, ccndstops, ResourceState.STARTED, "1s") killall = [] - for i in xrange(len(all_hosts)): - killall.append(perfkill[all_hosts[i]]) + for host in all_hosts: + killall.append(perfkill[host]) ec.register_condition(killall, ResourceAction.START, apps, ResourceState.STOPPED, "1s") ec.register_condition(killall, ResourceAction.STOP, killall, ResourceState.STARTED, "1s") diff --git a/examples/openvswitch/ovs_ping_3_switches.py b/examples/openvswitch/ovs_ping_3_switches.py index c97b3a77..25e9b7f7 100644 --- a/examples/openvswitch/ovs_ping_3_switches.py +++ b/examples/openvswitch/ovs_ping_3_switches.py @@ -225,8 +225,8 @@ r2ip = dict({ }) # Ping from all resources to all other resources -for r1, (n1, ip1) in r2ip.iteritems(): - for r2, (n2, ip2) in r2ip.iteritems(): +for r1, (n1, ip1) in r2ip.items(): + for r2, (n2, ip2) in r2ip.items(): if r1 == r2: continue @@ -239,7 +239,7 @@ ec.deploy() ec.wait_finished(apps.values()) # collect results -for key, app in apps.iteritems(): +for key, app in apps.items(): stdout = ec.trace(app, "stdout") print("***************************", key, "************************") print(stdout) diff --git a/examples/planetlab/select_nodes.py b/examples/planetlab/select_nodes.py index f856f52c..465e9493 100644 --- a/examples/planetlab/select_nodes.py +++ b/examples/planetlab/select_nodes.py @@ -85,7 +85,7 @@ ec = ExperimentController(exp_id="host_select") nodes = [] -for i in xrange(node_count): +for i in range(node_count): node = add_node(ec, pl_slice, pl_ssh_key, pl_user, pl_password, country, os) nodes.append(node) diff --git a/examples/planetlab/update_fedora_repo.py b/examples/planetlab/update_fedora_repo.py index cd2a9cde..71ec4d8f 100644 --- a/examples/planetlab/update_fedora_repo.py +++ b/examples/planetlab/update_fedora_repo.py @@ -67,7 +67,7 @@ pl_user = options.pl_user pl_password = options.pl_password hosts = options.hosts -hosts = map(str.strip, hosts.split(",")) +hosts = [host.strip() for host in hosts.split(",")] apps = [] ## Create the experiment controller diff --git a/src/nepi/data/processing/ccn/parser.py b/src/nepi/data/processing/ccn/parser.py index cd895492..64e2ada6 100644 --- a/src/nepi/data/processing/ccn/parser.py +++ b/src/nepi/data/processing/ccn/parser.py @@ -278,7 +278,7 @@ def process_content_history(graph): fname = graph.node[nid]["history"] history = load_content_history(fname) - for content_name in history.keys(): + for content_name in history: hist = history[content_name] for (timestamp, message_type, nid1, nid2, nonce, size, line) in hist: @@ -331,13 +331,13 @@ def process_content_history(graph): # Compute the time elapsed between the time an interest is sent # in the consumer node and when the content is received back - for content_name in content_names.keys(): + for content_name in content_names: # order content and interest messages by timestamp content_names[content_name]["content"] = sorted( content_names[content_name]["content"]) for nonce, timestamps in content_names[content_name][ - "interest"].iteritems(): + "interest"].items(): content_names[content_name]["interest"][nonce] = sorted( timestamps) diff --git a/src/nepi/execution/ec.py b/src/nepi/execution/ec.py index 3f8d42fd..d93ef7a7 100644 --- a/src/nepi/execution/ec.py +++ b/src/nepi/execution/ec.py @@ -538,7 +538,7 @@ class ExperimentController(object): """ rms = [] - for guid, rm in self._resources.iteritems(): + for guid, rm in self._resources.items(): if rm.get_rtype() == rtype: rms.append(rm) return rms @@ -554,7 +554,7 @@ class ExperimentController(object): :rtype: list """ - keys = self._resources.keys() + keys = list(self._resources.keys()) return keys @@ -568,7 +568,7 @@ class ExperimentController(object): """ rms = [] - for guid, rm in self._resources.iteritems(): + for guid, rm in self._resources.items(): if rm.get_rtype() == rtype: rms.append(rm.guid) return rms @@ -973,7 +973,7 @@ class ExperimentController(object): if not guids: # If no guids list was passed, all 'NEW' RMs will be deployed guids = [] - for guid, rm in self._resources.iteritems(): + for guid, rm in self._resources.items(): if rm.state == ResourceState.NEW: guids.append(guid) diff --git a/src/nepi/execution/resource.py b/src/nepi/execution/resource.py index 525b8fdf..4394130d 100644 --- a/src/nepi/execution/resource.py +++ b/src/nepi/execution/resource.py @@ -267,7 +267,7 @@ class ResourceManager(Logger): """ Returns a copy of the attributes """ - return copy.deepcopy(cls._attributes.values()) + return copy.deepcopy(list(cls._attributes.values())) @classmethod def get_attribute(cls, name): @@ -281,7 +281,7 @@ class ResourceManager(Logger): """ Returns a copy of the traces """ - return copy.deepcopy(cls._traces.values()) + return copy.deepcopy(list(cls._traces.values())) @classmethod def get_help(cls): @@ -765,7 +765,7 @@ class ResourceManager(Logger): if not isinstance(group, list): group = [group] - for act, conditions in self.conditions.iteritems(): + for act, conditions in self.conditions.items(): if action and act != action: continue diff --git a/src/nepi/resources/linux/application.py b/src/nepi/resources/linux/application.py index 1574f63c..9fd605d8 100644 --- a/src/nepi/resources/linux/application.py +++ b/src/nepi/resources/linux/application.py @@ -399,7 +399,7 @@ class LinuxApplication(ResourceManager): if sources: self.info("Uploading sources ") - sources = map(str.strip, sources.split(";")) + sources = [str.strip(source) for source in sources.split(";")] # Separate sources that should be downloaded from # the web, from sources that should be uploaded from diff --git a/src/nepi/resources/linux/ccn/ccnd.py b/src/nepi/resources/linux/ccn/ccnd.py index 48ce86f9..eb397374 100644 --- a/src/nepi/resources/linux/ccn/ccnd.py +++ b/src/nepi/resources/linux/ccn/ccnd.py @@ -340,8 +340,8 @@ class LinuxCCND(LinuxApplication): }) env = self.path - env += " ".join(map(lambda k: "%s=%s" % (envs.get(k), str(self.get(k))) \ - if self.get(k) else "", envs.keys())) + env += " ".join(["%s=%s" % (envs.get(k), str(self.get(k))) \ + if self.get(k) else "" for k in list(envs.keys())]) return env diff --git a/src/nepi/resources/linux/ccn/ccnr.py b/src/nepi/resources/linux/ccn/ccnr.py index 53e4ccd5..316818d7 100644 --- a/src/nepi/resources/linux/ccn/ccnr.py +++ b/src/nepi/resources/linux/ccn/ccnr.py @@ -295,8 +295,8 @@ class LinuxCCNR(LinuxApplication): }) env = self.ccnd.path - env += " ".join(map(lambda k: "%s=%s" % (envs.get(k), self.get(k)) \ - if self.get(k) else "", envs.keys())) + env += " ".join(["%s=%s" % (envs.get(k), self.get(k)) \ + if self.get(k) else "" for k in list(envs.keys())]) return env diff --git a/src/nepi/resources/linux/debfuncs.py b/src/nepi/resources/linux/debfuncs.py index ed507c8c..9b5901c4 100644 --- a/src/nepi/resources/linux/debfuncs.py +++ b/src/nepi/resources/linux/debfuncs.py @@ -22,9 +22,8 @@ def install_packages_command(os, packages): if not isinstance(packages, list): packages = [packages] - cmd = " && ".join(map(lambda p: - " { dpkg -s %(package)s || sudo -S apt-get -y install %(package)s ; } " % { - 'package': p}, packages)) + cmd = " && ".join([" { dpkg -s %(package)s || sudo -S apt-get -y install %(package)s ; } " % { + 'package': p} for p in packages]) #cmd = { dpkg -s vim || sudo -S apt-get -y install vim ; } && .. return cmd @@ -33,9 +32,8 @@ def remove_packages_command(os, packages): if not isinstance(packages, list): packages = [packages] - cmd = " && ".join(map(lambda p: - " { dpkg -s %(package)s && sudo -S apt-get -y purge %(package)s ; } " % { - 'package': p}, packages)) + cmd = " && ".join([" { dpkg -s %(package)s && sudo -S apt-get -y purge %(package)s ; } " % { + 'package': p} for p in packages]) #cmd = { dpkg -s vim && sudo -S apt-get -y purge vim ; } && .. return cmd diff --git a/src/nepi/resources/linux/netns/netnsclient.py b/src/nepi/resources/linux/netns/netnsclient.py index ee7369bc..1ad54054 100644 --- a/src/nepi/resources/linux/netns/netnsclient.py +++ b/src/nepi/resources/linux/netns/netnsclient.py @@ -17,7 +17,7 @@ # Author: Alina Quereilhac import base64 -import cPickle +import pickle import errno import os import socket @@ -44,7 +44,7 @@ class LinuxNetNSClient(NetNSClient): msg = [msg_type, args, kwargs] def encode(item): - item = cPickle.dumps(item) + item = pickle.dumps(item) return base64.b64encode(item) encoded = "|".join(map(encode, msg)) @@ -78,7 +78,7 @@ class LinuxNetNSClient(NetNSClient): self.emulation.error(msg, reply, err) raise RuntimeError(msg) - reply = cPickle.loads(base64.b64decode(reply)) + reply = pickle.loads(base64.b64decode(reply)) return reply diff --git a/src/nepi/resources/linux/netns/netnsemulation.py b/src/nepi/resources/linux/netns/netnsemulation.py index 904be9f1..e39831cd 100644 --- a/src/nepi/resources/linux/netns/netnsemulation.py +++ b/src/nepi/resources/linux/netns/netnsemulation.py @@ -369,7 +369,7 @@ class LinuxNetNSEmulation(LinuxApplication, NetNSEmulation): """ command = " [ -e %s ] && echo 'DONE' " % self.remote_socket - for i in xrange(200): + for i in range(200): (out, err), proc = self.node.execute(command, retry = 1, with_lock = True) diff --git a/src/nepi/resources/linux/node.py b/src/nepi/resources/linux/node.py index ee7e2e1d..a411c644 100644 --- a/src/nepi/resources/linux/node.py +++ b/src/nepi/resources/linux/node.py @@ -490,7 +490,8 @@ class LinuxNode(ResourceManager): # adding the avoided pids filtered above (avoid_kill) to allow users keep process # alive when using besides ssh connections kill_pids = set(pids_temp.items()) - set(pids.items()) - kill_pids = ' '.join(dict(kill_pids).keys()) + # py2/py3 : keep it simple + kill_pids = ' '.join(kill_pids) # removing pids from beside connections and its process kill_pids = kill_pids.split(' ') @@ -766,15 +767,17 @@ class LinuxNode(ResourceManager): if text and not os.path.isfile(src): # src is text input that should be uploaded as file # create a temporal file with the content to upload - f = tempfile.NamedTemporaryFile(delete=False) + # in python3 we need to open in binary mode if str is bytes + mode = 'w' if isinstance(src, str) else 'wb' + f = tempfile.NamedTemporaryFile(mode=mode, delete=False) f.write(src) f.close() src = f.name # If dst files should not be overwritten, check that the files do not - # exits already + # exist already if isinstance(src, str): - src = map(str.strip, src.split(";")) + src = [s.strip() for s in src.split(";")] if overwrite == False: src = self.filter_existing_files(src, dst) @@ -904,7 +907,7 @@ class LinuxNode(ResourceManager): if isinstance(paths, str): paths = [paths] - cmd = " ; ".join(map(lambda path: "rm -rf {}".format(path), paths)) + cmd = " ; ".join(["rm -rf {}".format(path) for path in paths]) return self.execute(cmd, with_lock = True) @@ -1074,7 +1077,7 @@ class LinuxNode(ResourceManager): pid = ppid = None delay = 1.0 - for i in xrange(2): + for i in range(2): pidtuple = self.getpid(home = home, pidfile = pidfile) if pidtuple: @@ -1177,14 +1180,14 @@ class LinuxNode(ResourceManager): if len(src) > 1 else {dst: src[0]} command = [] - for d in dests.keys(): + for d in dests: command.append(" [ -f {dst} ] && echo '{dst}' ".format(dst=d) ) command = ";".join(command) (out, err), proc = self.execute(command, retry = 1, with_lock = True) - for d in dests.keys(): + for d in dests: if out.find(d) > -1: del dests[d] diff --git a/src/nepi/resources/linux/ns3/ccn/ns3ccnddceapplication.py b/src/nepi/resources/linux/ns3/ccn/ns3ccnddceapplication.py index caa8e5b0..445f774d 100644 --- a/src/nepi/resources/linux/ns3/ccn/ns3ccnddceapplication.py +++ b/src/nepi/resources/linux/ns3/ccn/ns3ccnddceapplication.py @@ -197,8 +197,7 @@ class LinuxNS3DceCCND(LinuxNS3CCNDceApplication): "prefix" : "CCND_PREFIX", }) - env = ";".join(map(lambda k: "%s=%s" % (envs.get(k), str(self.get(k))), - [k for k in envs.keys() if self.get(k)])) + env = ";".join(["%s=%s" % (envs.get(k), str(self.get(k))) for k in [k for k in list(envs.keys()) if self.get(k)]]) return env diff --git a/src/nepi/resources/linux/ns3/ccn/ns3ccnrdceapplication.py b/src/nepi/resources/linux/ns3/ccn/ns3ccnrdceapplication.py index b5a9ee04..248edbdd 100644 --- a/src/nepi/resources/linux/ns3/ccn/ns3ccnrdceapplication.py +++ b/src/nepi/resources/linux/ns3/ccn/ns3ccnrdceapplication.py @@ -221,8 +221,7 @@ class LinuxNS3DceCCNR(LinuxNS3CCNDceApplication): "ccnsSyncScope": "CCNS_SYNC_SCOPE", }) - env = ";".join(map(lambda k: "%s=%s" % (envs.get(k), str(self.get(k))), - [k for k in envs.keys() if self.get(k)])) + env = ";".join(["%s=%s" % (envs.get(k), str(self.get(k))) for k in [k for k in list(envs.keys()) if self.get(k)]]) return env diff --git a/src/nepi/resources/linux/ns3/ccn/ns3fibentrydceapplication.py b/src/nepi/resources/linux/ns3/ccn/ns3fibentrydceapplication.py index 087ccda3..edb4222c 100644 --- a/src/nepi/resources/linux/ns3/ccn/ns3fibentrydceapplication.py +++ b/src/nepi/resources/linux/ns3/ccn/ns3fibentrydceapplication.py @@ -81,8 +81,7 @@ class LinuxNS3DceFIBEntry(LinuxNS3CCNDceApplication): "home": "HOME", }) - env = ";".join(map(lambda k: "%s=%s" % (envs.get(k), str(self.get(k))), - [k for k in envs.keys() if self.get(k)])) + env = ";".join(["%s=%s" % (envs.get(k), str(self.get(k))) for k in [k for k in list(envs.keys()) if self.get(k)]]) return env diff --git a/src/nepi/resources/linux/ns3/fdudptunnel.py b/src/nepi/resources/linux/ns3/fdudptunnel.py index 5e766f1b..9cc20d0d 100644 --- a/src/nepi/resources/linux/ns3/fdudptunnel.py +++ b/src/nepi/resources/linux/ns3/fdudptunnel.py @@ -263,7 +263,7 @@ class LinuxNs3FdUdpTunnel(LinuxUdpTunnel): node = self.endpoint_node(endpoint) run_home = self.run_home(endpoint) - for i in xrange(20): + for i in range(20): (out, err), proc = node.check_output(run_home, filename) if out: diff --git a/src/nepi/resources/linux/ns3/ns3client.py b/src/nepi/resources/linux/ns3/ns3client.py index 4d91938c..ed41bdbc 100644 --- a/src/nepi/resources/linux/ns3/ns3client.py +++ b/src/nepi/resources/linux/ns3/ns3client.py @@ -17,7 +17,7 @@ # Author: Alina Quereilhac import base64 -import cPickle +import pickle import errno import os import socket @@ -44,7 +44,7 @@ class LinuxNS3Client(NS3Client): msg = [msg_type, args, kwargs] def encode(item): - item = cPickle.dumps(item) + item = pickle.dumps(item) return base64.b64encode(item) encoded = "|".join(map(encode, msg)) @@ -79,7 +79,7 @@ class LinuxNS3Client(NS3Client): self.simulation.error(msg, reply, err) raise RuntimeError(msg) - reply = cPickle.loads(base64.b64decode(reply)) + reply = pickle.loads(base64.b64decode(reply)) return reply diff --git a/src/nepi/resources/linux/ns3/ns3simulation.py b/src/nepi/resources/linux/ns3/ns3simulation.py index 0a44d7ae..3ace4373 100644 --- a/src/nepi/resources/linux/ns3/ns3simulation.py +++ b/src/nepi/resources/linux/ns3/ns3simulation.py @@ -723,7 +723,7 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation): """ command = " [ -e %s ] && echo 'DONE' " % self.remote_socket - for i in xrange(200): + for i in range(200): (out, err), proc = self.node.execute(command, retry = 1, with_lock = True) diff --git a/src/nepi/resources/linux/rpmfuncs.py b/src/nepi/resources/linux/rpmfuncs.py index 4d22bc34..ae70e75b 100644 --- a/src/nepi/resources/linux/rpmfuncs.py +++ b/src/nepi/resources/linux/rpmfuncs.py @@ -29,9 +29,8 @@ def install_packages_command(os, packages): cmd = install_rpmfusion_command(os) if cmd: cmd += " ; " - cmd += " && ".join(map(lambda p: - " { rpm -q %(package)s || sudo -S yum -y install --nogpgcheck %(package)s ; } " % { - 'package': p}, packages)) + cmd += " && ".join([" { rpm -q %(package)s || sudo -S yum -y install --nogpgcheck %(package)s ; } " % { + 'package': p} for p in packages]) #cmd = { rpm -q rpmfusion-free-release || sudo -s rpm -i ... ; } && { rpm -q vim || sudo yum -y install vim ; } && .. return cmd @@ -40,9 +39,8 @@ def remove_packages_command(os, packages): if not isinstance(packages, list): packages = [packages] - cmd = " && ".join(map(lambda p: - " { rpm -q %(package)s && sudo -S yum -y remove %(package)s ; } " % { - 'package': p}, packages)) + cmd = " && ".join([" { rpm -q %(package)s && sudo -S yum -y remove %(package)s ; } " % { + 'package': p} for p in packages]) #cmd = { rpm -q vim && sudo yum -y remove vim ; } && .. return cmd diff --git a/src/nepi/resources/linux/scripts/fd-udp-connect.py b/src/nepi/resources/linux/scripts/fd-udp-connect.py index 7096cf1a..2c058e26 100644 --- a/src/nepi/resources/linux/scripts/fd-udp-connect.py +++ b/src/nepi/resources/linux/scripts/fd-udp-connect.py @@ -128,7 +128,7 @@ if __name__ == '__main__': # even if the file exists and had the port number, # the read operation returns empty string! # Maybe a race condition? - for i in xrange(10): + for i in range(10): with open(remote_port_file, 'r') as f: remote_port = f.read() diff --git a/src/nepi/resources/linux/scripts/linux-udp-connect.py b/src/nepi/resources/linux/scripts/linux-udp-connect.py index f8f8502c..3e5706c7 100644 --- a/src/nepi/resources/linux/scripts/linux-udp-connect.py +++ b/src/nepi/resources/linux/scripts/linux-udp-connect.py @@ -153,7 +153,7 @@ if __name__ == '__main__': # even if the file exists and had the port number, # the read operation returns empty string! # Maybe a race condition? - for i in xrange(10): + for i in range(10): with open(remote_port_file, 'r') as f: remote_port = f.read() diff --git a/src/nepi/resources/linux/scripts/tunchannel.py b/src/nepi/resources/linux/scripts/tunchannel.py index 8a3047c9..6f404608 100644 --- a/src/nepi/resources/linux/scripts/tunchannel.py +++ b/src/nepi/resources/linux/scripts/tunchannel.py @@ -37,8 +37,7 @@ import ctypes import time def ipfmt(ip): - ipbytes = map(ord,ip.decode("hex")) - return '.'.join(map(str,ipbytes)) + return '.'.join(str(ord(x)) for x in ip.decode("hex")) tagtype = { '0806' : 'arp', @@ -182,7 +181,7 @@ def piWrap(buf, ether_mode, etherProto=etherProto): buf, )) -_padmap = [ chr(padding) * padding for padding in xrange(127) ] +_padmap = [ chr(padding) * padding for padding in range(127) ] del padding def encrypt(packet, crypter, len=len, padmap=_padmap): @@ -442,7 +441,7 @@ def tun_fwd(tun, remote, with_pi, ether_mode, cipher_key, udp, TERMINATE, SUSPEN sent = 0 try: try: - for x in xrange(maxbatch): + for x in range(maxbatch): packet = pullPacket(fwbuf) if crypto_mode: @@ -485,7 +484,7 @@ def tun_fwd(tun, remote, with_pi, ether_mode, cipher_key, udp, TERMINATE, SUSPEN bwfree -= sent if tun in wrdy: try: - for x in xrange(maxtbatch): + for x in range(maxtbatch): packet = pullPacket(bkbuf) twrite(tunfd, packet) #wt += 1 @@ -513,7 +512,7 @@ def tun_fwd(tun, remote, with_pi, ether_mode, cipher_key, udp, TERMINATE, SUSPEN # check incoming data packets if tun in rdrdy: try: - for x in xrange(maxbatch): + for x in range(maxbatch): packet = tread(tunfd,2000) # tun.read blocks until it gets 2k! if not packet: continue @@ -531,7 +530,7 @@ def tun_fwd(tun, remote, with_pi, ether_mode, cipher_key, udp, TERMINATE, SUSPEN if remote in rdrdy: try: try: - for x in xrange(maxbatch): + for x in range(maxbatch): packet = rread(remote,2000) #rr += 1 @@ -583,7 +582,7 @@ def tun_fwd(tun, remote, with_pi, ether_mode, cipher_key, udp, TERMINATE, SUSPEN def udp_connect(TERMINATE, local_addr, local_port, peer_addr, peer_port): rsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0) retrydelay = 1.0 - for i in xrange(30): + for i in range(30): # TERMINATE is a array. An item can be added to TERMINATE, from # outside this function to force termination of the loop if TERMINATE: @@ -618,7 +617,7 @@ def udp_handshake(TERMINATE, rsock): pass keepalive_thread = threading.Thread(target=keepalive) keepalive_thread.start() - for i in xrange(900): + for i in range(900): if TERMINATE: raise OSError("Killed") try: @@ -644,7 +643,7 @@ def tcp_connect(TERMINATE, stop, rsock, peer_addr, peer_port): # will be forever blocked in the connect, so we put a reasonable timeout. rsock.settimeout(10) # We wait for - for i in xrange(30): + for i in range(30): if stop: break if TERMINATE: @@ -674,7 +673,7 @@ def tcp_listen(TERMINATE, stop, lsock, local_addr, local_port): retrydelay = 1.0 # We try to bind to the local virtual interface. # It might not exist yet so we wait in a loop. - for i in xrange(30): + for i in range(30): if stop: break if TERMINATE: @@ -695,7 +694,7 @@ def tcp_listen(TERMINATE, stop, lsock, local_addr, local_port): # The other side might not be ready yet, so we also wait in a loop for timeouts. timeout = 1 lsock.listen(1) - for i in xrange(30): + for i in range(30): if TERMINATE: raise OSError("Killed") rlist, wlist, xlist = select.select([lsock], [], [], timeout) @@ -751,7 +750,7 @@ def tcp_establish(TERMINATE, local_addr, local_port, peer_addr, peer_port): end = False sock = None - for i in xrange(0, 50): + for i in range(0, 50): if end: break if TERMINATE: diff --git a/src/nepi/resources/linux/tap.py b/src/nepi/resources/linux/tap.py index ac11eb0a..d7bad1c8 100644 --- a/src/nepi/resources/linux/tap.py +++ b/src/nepi/resources/linux/tap.py @@ -422,7 +422,7 @@ class LinuxTap(LinuxApplication): result = None delay = 1.0 - for i in xrange(20): + for i in range(20): (out, err), proc = self.node.check_output(home, filename) if out: result = out.strip() diff --git a/src/nepi/resources/netns/netnsserver.py b/src/nepi/resources/netns/netnsserver.py index 224a6032..f2c37f23 100644 --- a/src/nepi/resources/netns/netnsserver.py +++ b/src/nepi/resources/netns/netnsserver.py @@ -17,7 +17,7 @@ # Author: Alina Quereilhac import base64 -import cPickle +import pickle import errno import logging import os @@ -110,9 +110,9 @@ def recv_msg(conn): def decode(item): item = base64.b64decode(item).rstrip() - return cPickle.loads(item) + return pickle.loads(item) - decoded = map(decode, msg.split("|")) + decoded = [ decode(x) for x in msg.split("|")] # decoded message dmsg_type = decoded.pop(0) @@ -122,7 +122,7 @@ def recv_msg(conn): return (dmsg_type, dargs, dkwargs) def send_reply(conn, reply): - encoded = base64.b64encode(cPickle.dumps(reply)) + encoded = base64.b64encode(pickle.dumps(reply)) conn.send("%s\n" % encoded) def get_options(): diff --git a/src/nepi/resources/netns/netnswrapper.py b/src/nepi/resources/netns/netnswrapper.py index 4456f976..f574ee0b 100644 --- a/src/nepi/resources/netns/netnswrapper.py +++ b/src/nepi/resources/netns/netnswrapper.py @@ -184,7 +184,7 @@ class NetNSWrapper(object): def replace_kwargs(self, kwargs): realkwargs = dict([(k, self.get_object(v) \ if str(v).startswith("uuid") else v) \ - for k,v in kwargs.iteritems()]) + for k,v in kwargs.items()]) return realkwargs diff --git a/src/nepi/resources/netns/netnswrapper_debug.py b/src/nepi/resources/netns/netnswrapper_debug.py index 462b7308..84434204 100644 --- a/src/nepi/resources/netns/netnswrapper_debug.py +++ b/src/nepi/resources/netns/netnswrapper_debug.py @@ -146,13 +146,10 @@ wrapper = NS3Wrapper() return pprint.pformat(value) def format_args(self, args): - fargs = map(self.format_value, args) - return "[%s]" % ",".join(fargs) + return "[%s]" % ",".join(self.format_value(arg) for arg in args) def format_kwargs(self, kwargs): - fkwargs = map(lambda (k,w): - "%s: %s" % (self.format_value(k), self.format_value(w)), - kwargs.iteritems()) + fkwargs = ["%s: %s" % (self.format_value(k), self.format_value(v)) for (k, v) in kwargs.items()] return "dict({%s})" % ",".join(fkwargs) diff --git a/src/nepi/resources/ns3/ns3route.py b/src/nepi/resources/ns3/ns3route.py index 15d40054..48a03586 100644 --- a/src/nepi/resources/ns3/ns3route.py +++ b/src/nepi/resources/ns3/ns3route.py @@ -21,8 +21,6 @@ from nepi.execution.resource import clsinit_copy from nepi.execution.trace import Trace from nepi.resources.ns3.ns3base import NS3Base -import ipaddr - @clsinit_copy class NS3Route(NS3Base): _rtype = "ns3::Route" diff --git a/src/nepi/resources/ns3/ns3server.py b/src/nepi/resources/ns3/ns3server.py index 8b3cd79a..589e3d41 100644 --- a/src/nepi/resources/ns3/ns3server.py +++ b/src/nepi/resources/ns3/ns3server.py @@ -17,7 +17,7 @@ # Author: Alina Quereilhac import base64 -import cPickle +import pickle import errno import logging import os @@ -136,9 +136,9 @@ def recv_msg(conn): def decode(item): item = base64.b64decode(item).rstrip() - return cPickle.loads(item) + return pickle.loads(item) - decoded = map(decode, msg.split("|")) + decoded = [ decode(x) for x in msg.split("|") ] # decoded message dmsg_type = decoded.pop(0) @@ -148,7 +148,7 @@ def recv_msg(conn): return (dmsg_type, dargs, dkwargs) def send_reply(conn, reply): - encoded = base64.b64encode(cPickle.dumps(reply)) + encoded = base64.b64encode(pickle.dumps(reply)) conn.send("%s\n" % encoded) def get_options(): diff --git a/src/nepi/resources/ns3/ns3wrapper.py b/src/nepi/resources/ns3/ns3wrapper.py index f6cc2475..92510066 100644 --- a/src/nepi/resources/ns3/ns3wrapper.py +++ b/src/nepi/resources/ns3/ns3wrapper.py @@ -154,7 +154,7 @@ class NS3Wrapper(object): tid_count = type_id.GetRegisteredN() base = type_id.LookupByName("ns3::Object") - for i in xrange(tid_count): + for i in range(tid_count): tid = type_id.GetRegistered(i) if tid.MustHideFromDocumentation() or \ @@ -213,7 +213,7 @@ class NS3Wrapper(object): factory = self.ns3.ObjectFactory() factory.SetTypeId(type_name) - for name, value in kwargs.iteritems(): + for name, value in kwargs.items(): ns3_value = self._attr_from_string_to_ns3_value(type_name, name, value) factory.Set(name, ns3_value) @@ -575,11 +575,11 @@ class NS3Wrapper(object): def replace_kwargs(self, kwargs): realkwargs = dict([(k, self.get_object(v) \ if str(v).startswith("uuid") else v) \ - for k,v in kwargs.iteritems()]) + for k,v in kwargs.items()]) realkwargs = dict([(k, self._singleton(v) \ if str(v).startswith(SINGLETON) else v )\ - for k, v in realkwargs.iteritems()]) + for k, v in realkwargs.items()]) return realkwargs @@ -645,10 +645,10 @@ class NS3Wrapper(object): # For all the interfaces registered with the ipv4 object, find # the one that matches the network of the nexthop nifaces = ipv4.GetNInterfaces() - for ifidx in xrange(nifaces): + for ifidx in range(nifaces): iface = ipv4.GetInterface(ifidx) naddress = iface.GetNAddresses() - for addridx in xrange(naddress): + for addridx in range(naddress): ifaddr = iface.GetAddress(addridx) ifmask = ifaddr.GetMask() @@ -668,7 +668,7 @@ class NS3Wrapper(object): newuuid = None if search: # search object - for ouuid, oobj in self._objects.iteritems(): + for ouuid, oobj in self._objects.items(): if nobj == oobj: newuuid = ouuid break diff --git a/src/nepi/resources/ns3/ns3wrapper_debug.py b/src/nepi/resources/ns3/ns3wrapper_debug.py index 332f63bf..70a84b7a 100644 --- a/src/nepi/resources/ns3/ns3wrapper_debug.py +++ b/src/nepi/resources/ns3/ns3wrapper_debug.py @@ -166,13 +166,10 @@ wrapper = NS3Wrapper() return pprint.pformat(value) def format_args(self, args): - fargs = map(self.format_value, args) - return "[%s]" % ",".join(fargs) + return "[%s]" % ",".join(self.format_value(arg) for arg in args) def format_kwargs(self, kwargs): - fkwargs = map(lambda (k,w): - "%s: %s" % (self.format_value(k), self.format_value(w)), - kwargs.iteritems()) + fkwargs = ["%s: %s" % (self.format_value(k), self.format_value(v)) for (k, v) in kwargs.items()] return "dict({%s})" % ",".join(fkwargs) diff --git a/src/nepi/resources/ns3/resource_manager_generator.py b/src/nepi/resources/ns3/resource_manager_generator.py index de737757..6bd9b896 100644 --- a/src/nepi/resources/ns3/resource_manager_generator.py +++ b/src/nepi/resources/ns3/resource_manager_generator.py @@ -96,7 +96,7 @@ def create_ns3_rms(): base = type_id.LookupByName("ns3::Object") # Create a .py file using the ns-3 RM template for each ns-3 TypeId - for i in xrange(tid_count): + for i in range(tid_count): tid = type_id.GetRegistered(i) (base_class_import, base_class) = select_base_class(ns3, tid) @@ -156,7 +156,7 @@ def template_attributes(ns3, tid): attributes = "" attr_count = tid.GetAttributeN() - for i in xrange(attr_count): + for i in range(attr_count): attr_info = tid.GetAttribute(i) if not attr_info.accessor.HasGetter(): continue @@ -192,7 +192,7 @@ def template_attributes(ns3, tid): elif isinstance(value, ns3.EnumValue): attr_type = "Types.Enumerate" allowed = checker.GetUnderlyingTypeInformation().split("|") - attr_allowed = "[%s]" % ",".join(map(lambda x: "\"%s\"" % x, allowed)) + attr_allowed = "[%s]" % ",".join(["\"%s\"" % x for x in allowed]) elif isinstance(value, ns3.DoubleValue): attr_type = "Types.Double" # TODO: range @@ -220,7 +220,7 @@ def template_traces(ns3, tid): traces = "" trace_count = tid.GetTraceSourceN() - for i in xrange(trace_count): + for i in range(trace_count): trace_info = tid.GetTraceSource(i) trace_name = trace_info.name trace_help = trace_info.help.replace('"', '\\"').replace("'", "\\'") diff --git a/src/nepi/resources/omf/messages_6.py b/src/nepi/resources/omf/messages_6.py index 5b8203c8..b7f3044e 100644 --- a/src/nepi/resources/omf/messages_6.py +++ b/src/nepi/resources/omf/messages_6.py @@ -114,17 +114,17 @@ class MessageHandler(): else: properties = self._attr_element(payload,"props","") - for prop in props.keys(): + for prop in props: if isinstance(props[prop],str): self._attr_element(properties,prop,props[prop],type_key="type", type_value = "string") elif isinstance(props[prop],dict): key = self._attr_element(properties,prop,"",type_key="type", type_value = "hash") - for comp in props[prop].keys(): + for comp in props[prop]: self._attr_element(key,comp,props[prop][comp],type_key="type", type_value = "string") if guards : guardians = self._attr_element(payload,"guard","") - for guard in guards.keys(): + for guard in guards: self._attr_element(guardians,guard,guards[guard],type_key="type", type_value = "string") return payload @@ -149,12 +149,12 @@ class MessageHandler(): if props : properties = self._attr_element(payload,"props","") - for prop in props.keys(): + for prop in props: self._attr_element(properties,prop,props[prop],type_key="type", type_value = "symbol") if guards : guardians = self._attr_element(payload,"guard","") - for guard in guards.keys(): + for guard in guards: self._attr_element(guardians,guard,guards[guard],type_key="type", type_value = "string") return payload @@ -179,12 +179,12 @@ class MessageHandler(): if props : properties = self._attr_element(payload,"props","") - for prop in props.keys(): + for prop in list(props.keys()): self._attr_element(properties,prop,props[prop]) if guards : guardians = self._attr_element(payload,"guard","") - for guard in guards.keys(): + for guard in list(guards.keys()): self._attr_element(guardians,guard,guards[guard]) return payload @@ -240,12 +240,12 @@ class MessageHandler(): if props : properties = self._id_element(payload,"props","xmlns:frcp", "http://schema.mytestbed.net/omf/6.0/protocol") - for prop in props.keys(): + for prop in list(props.keys()): self._attr_element(properties,prop,props[prop]) if guards : guardians = self._attr_element(payload,"guard","") - for guard in guards.keys(): + for guard in list(guards.keys()): self._attr_element(guardians,guard,guards[guard]) return payload diff --git a/src/nepi/resources/omf/omf6_api.py b/src/nepi/resources/omf/omf6_api.py index 3401c322..7a4f5b2c 100644 --- a/src/nepi/resources/omf/omf6_api.py +++ b/src/nepi/resources/omf/omf6_api.py @@ -114,7 +114,7 @@ class OMF6API(Logger): def check_ready(self, xmpp): delay = 1.0 - for i in xrange(15): + for i in range(15): if xmpp.ready: break else: diff --git a/src/nepi/resources/omf/omf6_parser.py b/src/nepi/resources/omf/omf6_parser.py index b542e8cc..68786b6e 100644 --- a/src/nepi/resources/omf/omf6_parser.py +++ b/src/nepi/resources/omf/omf6_parser.py @@ -175,7 +175,7 @@ class OMF6Parser(Logger): event = self._check_for_tag(root, namespaces, "event") log = "STATUS -- " - for elt in props.keys(): + for elt in props: ns, tag = elt.split('}') if tag == "it": log = log + "membership : " + props[elt]+" -- " diff --git a/src/nepi/resources/omf/wilabt_node.py b/src/nepi/resources/omf/wilabt_node.py index f9b118f4..8ce3e21e 100644 --- a/src/nepi/resources/omf/wilabt_node.py +++ b/src/nepi/resources/omf/wilabt_node.py @@ -393,7 +393,7 @@ class WilabtSfaNode(OMFNode): attribute hostname, it will over write the previous value. """ hosts_hrn = self.sfaapi.get_resources_hrn() - for host, hrn in hosts_hrn.iteritems(): + for host, hrn in hosts_hrn.items(): if hrn == node: host = host + '.wilab2.ilabt.iminds.be' self.set("host", host) diff --git a/src/nepi/resources/planetlab/node.py b/src/nepi/resources/planetlab/node.py index c6f7bde8..fb4aad6e 100644 --- a/src/nepi/resources/planetlab/node.py +++ b/src/nepi/resources/planetlab/node.py @@ -430,7 +430,7 @@ class PlanetlabNode(LinuxNode): nodes_id = [] filters = {} - for attr_name, attr_obj in self._attrs.iteritems(): + for attr_name, attr_obj in self._attrs.items(): attr_value = self.get(attr_name) if attr_value is not None and attr_obj.has_flag(Flags.Filter) and \ diff --git a/src/nepi/resources/planetlab/plcapi.py b/src/nepi/resources/planetlab/plcapi.py index d2970e8c..01e3c102 100644 --- a/src/nepi/resources/planetlab/plcapi.py +++ b/src/nepi/resources/planetlab/plcapi.py @@ -26,7 +26,7 @@ import xmlrpclib def _retry(fn): def rv(*p, **kw): - for x in xrange(5): + for x in range(5): try: return fn(*p, **kw) except (socket.error, IOError, OSError): @@ -343,7 +343,7 @@ class PLCAPI(object): filters = filters, peer=None, **kw) ) else: - peer_filter = map(name_to_id, peer) + peer_filter = [name_to_id(x) for x in peer] elif peer is None or peer == self._local_peer: peer_filter = None diff --git a/src/nepi/resources/planetlab/sfa_node.py b/src/nepi/resources/planetlab/sfa_node.py index fca374e4..e05a3a78 100644 --- a/src/nepi/resources/planetlab/sfa_node.py +++ b/src/nepi/resources/planetlab/sfa_node.py @@ -534,7 +534,7 @@ class PlanetlabSfaNode(LinuxNode): if not self._blacklisted(host_hrn): if not self._reserved(host_hrn): print(self.sfaapi._reserved ,self.guid) - for hostname, hrn in nodes.iteritems(): + for hostname, hrn in nodes.items(): if host_hrn == hrn: print('hostname' ,hostname) ping_ok = self._do_ping(hostname) @@ -586,7 +586,7 @@ class PlanetlabSfaNode(LinuxNode): attribute hostname, it will over write the previous value. """ hosts_hrn = self.sfaapi.get_resources_hrn() - for hostname, hrn in hosts_hrn.iteritems(): + for hostname, hrn in hosts_hrn.items(): if hrn == node: self.set("hostname", hostname) diff --git a/src/nepi/resources/planetlab/tap.py b/src/nepi/resources/planetlab/tap.py index 56517c3f..5b1dc1ec 100644 --- a/src/nepi/resources/planetlab/tap.py +++ b/src/nepi/resources/planetlab/tap.py @@ -133,7 +133,7 @@ class PlanetlabTap(LinuxTap): if not exec_run_home: exec_run_home = self.run_home - for i in xrange(20): + for i in range(20): (out, err), proc = self.node.check_output(self.run_home, "vif_name") if proc.poll() > 0: diff --git a/src/nepi/util/execfuncs.py b/src/nepi/util/execfuncs.py index cc95bdf0..1f7b6b9b 100644 --- a/src/nepi/util/execfuncs.py +++ b/src/nepi/util/execfuncs.py @@ -31,7 +31,7 @@ def lexec(command, """ if env: export = '' - for envkey, envval in env.iteritems(): + for envkey, envval in env.items(): export += '%s=%s ' % (envkey, envval) command = "%s %s" % (export, command) @@ -179,7 +179,7 @@ def lgetpid(pidfile): if out: try: - return map(int,out.strip().split(' ',1)) + return [ int(x) for x in out.strip().split(' ',1))] except: # Ignore, many ways to fail that don't matter that much return None diff --git a/src/nepi/util/manifoldapi.py b/src/nepi/util/manifoldapi.py index 5827d4fb..51724102 100644 --- a/src/nepi/util/manifoldapi.py +++ b/src/nepi/util/manifoldapi.py @@ -72,7 +72,7 @@ class MANIFOLDAPI(object): filters = self._map_attr_to_resource_filters(filters) qfilters = list() - for filtername, filtervalue in filters.iteritems(): + for filtername, filtervalue in filters.items(): newfilter = [filtername, "==", filtervalue] qfilters.append(newfilter) @@ -202,7 +202,7 @@ class MANIFOLDAPI(object): } mapped_filters = dict() - for filtername, filtervalue in filters.iteritems(): + for filtername, filtervalue in filters.items(): if attr_to_filter[filtername]: new_filtername = attr_to_filter[filtername] mapped_filters[new_filtername] = filtervalue diff --git a/src/nepi/util/netgraph.py b/src/nepi/util/netgraph.py index 49a194bd..7a681ec3 100644 --- a/src/nepi/util/netgraph.py +++ b/src/nepi/util/netgraph.py @@ -155,9 +155,9 @@ class NetGraph(object): nodesinbranch = (node_count - 1)/ BRANCHES c = 1 - for i in xrange(BRANCHES): + for i in range(BRANCHES): prev = 0 - for n in xrange(1, nodesinbranch + 1): + for n in range(1, nodesinbranch + 1): graph.add_node(c) graph.add_edge(prev, c) prev = c @@ -333,7 +333,7 @@ class NetGraph(object): source = leaves.pop(random.randint(0, len(leaves) - 1)) else: # options must not be already sources or targets - options = [ k for k,v in self.topology.degree().iteritems() \ + options = [ k for k,v in self.topology.degree().items() \ if (not kwargs.get("is_leaf") or v == 1) \ and not self.topology.node[k].get("source") \ and not self.topology.node[k].get("target")] diff --git a/src/nepi/util/parallel.py b/src/nepi/util/parallel.py index 49b27b55..04c9d17f 100644 --- a/src/nepi/util/parallel.py +++ b/src/nepi/util/parallel.py @@ -96,7 +96,7 @@ class ParallelRun(object): self.workers = [] # initialize workers - for x in xrange(maxthreads): + for x in range(maxthreads): worker = WorkerThread() worker.attach(self.queue, self.rvqueue, self.delayed_exceptions) worker.setDaemon(True) diff --git a/src/nepi/util/parsers/xml_parser.py b/src/nepi/util/parsers/xml_parser.py index 18b7a7da..c11782d7 100644 --- a/src/nepi/util/parsers/xml_parser.py +++ b/src/nepi/util/parsers/xml_parser.py @@ -102,7 +102,7 @@ class ECXMLParser(object): rmsnode = doc.createElement("rms") ecnode.appendChild(rmsnode) - for guid, rm in ec._resources.iteritems(): + for guid, rm in ec._resources.items(): self._rm_to_xml(doc, rmsnode, ec, guid, rm) return doc @@ -225,7 +225,7 @@ class ECXMLParser(object): cnnode = doc.createElement("conditions") conditions = False - for action, conds in rm._conditions.iteritems(): + for action, conds in rm._conditions.items(): conditions = True for (group, state, time) in conds: ccnnode = doc.createElement("condition") diff --git a/src/nepi/util/plotter.py b/src/nepi/util/plotter.py index 3cec9729..f480ab3f 100644 --- a/src/nepi/util/plotter.py +++ b/src/nepi/util/plotter.py @@ -56,7 +56,7 @@ class ECPlotter(object): networkx.draw(graph, pos = pos, node_color="white", node_size = 500, with_labels=True) - label = "\n".join(map(lambda v: "%s: %s" % (v[0], v[1]), labels.iteritems())) + label = "\n".join(["%s: %s" % (v[0], v[1]) for v in iter(labels.items())]) plt.annotate(label, xy=(0.05, 0.95), xycoords='axes fraction') fpath += ".png" @@ -84,7 +84,7 @@ class ECPlotter(object): labels = dict() connections = set() - for guid, rm in ec._resources.iteritems(): + for guid, rm in ec._resources.items(): label = rm.get_rtype() graph.add_node(guid, diff --git a/src/nepi/util/sfaapi.py b/src/nepi/util/sfaapi.py index 136ae70b..f460b7e8 100644 --- a/src/nepi/util/sfaapi.py +++ b/src/nepi/util/sfaapi.py @@ -211,7 +211,7 @@ class SFAAPI(object): else: slice_resources = [] if slice_resources: slice_resources_hrn = self.get_resources_hrn(slice_resources) - for s_hrn_key, s_hrn_value in slice_resources_hrn.iteritems(): + for s_hrn_key, s_hrn_value in slice_resources_hrn.items(): s_parts = s_hrn_value.split('.') s_hrn = '.'.join(s_parts[:2]) + '.' + '\\.'.join(s_parts[2:]) resources_hrn_new.append(s_hrn) diff --git a/src/nepi/util/sshfuncs.py b/src/nepi/util/sshfuncs.py index 1899de23..0d0c17dc 100644 --- a/src/nepi/util/sshfuncs.py +++ b/src/nepi/util/sshfuncs.py @@ -208,7 +208,7 @@ def eintr_retry(func): @functools.wraps(func) def rv(*p, **kw): retry = kw.pop("_retry", False) - for i in xrange(0 if retry else 4): + for i in range(0 if retry else 4): try: return func(*p, **kw) except (select.error, socket.error) as args: @@ -554,7 +554,7 @@ def rgetpid(pidfile, if out: try: - return map(int,out.strip().split(' ',1)) + return [ int(x) for x in out.strip().split(' ',1)) ] except: # Ignore, many ways to fail that don't matter that much return None @@ -697,7 +697,7 @@ def _retry_rexec(args, tmp_known_hosts = None, blocking = True): - for x in xrange(retry): + for x in range(retry): # display command actually invoked when debug is turned on message = " ".join( [ "'{}'".format(arg) for arg in args ] ) log("sshfuncs: invoking {}".format(message), logging.DEBUG) @@ -722,7 +722,9 @@ def _retry_rexec(args, # The method communicate was re implemented for performance issues # when using python subprocess communicate method the ssh commands # last one minute each + #log("BEFORE communicate", level=logging.INFO); import time; beg=time.time() out, err = _communicate(proc, input=None) + #log("AFTER communicate - {}s".format(time.time()-beg), level=logging.INFO) elif stdout: out = proc.stdout.read() diff --git a/test/execution/resource.py b/test/execution/resource.py index 0945e9b5..56449381 100755 --- a/test/execution/resource.py +++ b/test/execution/resource.py @@ -269,7 +269,7 @@ class ResourceManagerTestCase(unittest.TestCase): node = ec.register_resource("Node") apps = list() - for i in xrange(1000): + for i in range(1000): app = ec.register_resource("Application") ec.register_connection(app, node) apps.append(app) @@ -327,7 +327,7 @@ class ResourceManagerTestCase(unittest.TestCase): ec.register_connection(eapp, node) apps.append(eapp) - for i in xrange(10): + for i in range(10): app = ec.register_resource("Application") ec.register_connection(app, node) apps.append(app) diff --git a/test/execution/runner.py b/test/execution/runner.py index 155e9b99..1b2163b7 100755 --- a/test/execution/runner.py +++ b/test/execution/runner.py @@ -101,7 +101,7 @@ class RunnerTestCase(unittest.TestCase): apps = list() ifaces = list() - for i in xrange(node_count): + for i in range(node_count): node = ec.register_resource("dummy::Node") nodes.append(node) @@ -109,7 +109,7 @@ class RunnerTestCase(unittest.TestCase): ec.register_connection(node, iface) ifaces.append(iface) - for i in xrange(app_count): + for i in range(app_count): app = ec.register_resource("dummy::Application") ec.register_connection(node, app) apps.append(app) @@ -136,7 +136,7 @@ class RunnerTestCase(unittest.TestCase): apps = list() ifaces = list() - for i in xrange(node_count): + for i in range(node_count): node = ec.register_resource("dummy::Node") nodes.append(node) @@ -144,7 +144,7 @@ class RunnerTestCase(unittest.TestCase): ec.register_connection(node, iface) ifaces.append(iface) - for i in xrange(app_count): + for i in range(app_count): app = ec.register_resource("dummy::Application") ec.register_connection(node, app) apps.append(app) diff --git a/test/lib/test_utils.py b/test/lib/test_utils.py index c6a08d39..cd67dcdd 100644 --- a/test/lib/test_utils.py +++ b/test/lib/test_utils.py @@ -76,7 +76,7 @@ def skipIfAnyNotAlive(func): argss = list(args) argss.pop(0) - for i in xrange(len(argss)/2): + for i in range(len(argss)/2): username = argss[i*2] hostname = argss[i*2+1] node, ec = create_node(hostname, username) @@ -95,7 +95,7 @@ def skipIfAnyNotAliveWithIdentity(func): def wrapped(*args, **kwargs): argss = list(args) argss.pop(0) - for i in xrange(len(argss)/3): + for i in range(len(argss)/3): username = argss[i*3] hostname = argss[i*3+1] identity = argss[i*3+2] diff --git a/test/resources/linux/application.py b/test/resources/linux/application.py index 4bda4f9d..bd6b0fe9 100755 --- a/test/resources/linux/application.py +++ b/test/resources/linux/application.py @@ -156,7 +156,7 @@ main (void) ec.set(node, "cleanProcesses", True) apps = list() - for i in xrange(50): + for i in range(50): app = ec.register_resource("linux::Application") cmd = "ping -c5 %s" % self.target ec.set(app, "command", cmd) diff --git a/test/util/parallel.py b/test/util/parallel.py index fb329908..e5785c6f 100755 --- a/test/util/parallel.py +++ b/test/util/parallel.py @@ -33,7 +33,7 @@ class ParallelRunTestCase(unittest.TestCase): def inc(count): count[0] += 1 - for x in xrange(10): + for x in range(10): runner.put(inc, count) runner.destroy() @@ -51,7 +51,7 @@ class ParallelRunTestCase(unittest.TestCase): runner = ParallelRun(maxthreads = 4) runner.start() - for x in xrange(100): + for x in range(100): runner.put(sleep) runner.empty() @@ -73,7 +73,7 @@ class ParallelRunTestCase(unittest.TestCase): runner = ParallelRun(maxthreads = 4) runner.start() - for x in xrange(4): + for x in range(4): runner.put(inc, count) runner.put(error) diff --git a/test/util/plotter.py b/test/util/plotter.py index b1d83cd4..b4ef5dc0 100755 --- a/test/util/plotter.py +++ b/test/util/plotter.py @@ -99,7 +99,7 @@ class PlotterTestCase(unittest.TestCase): apps = list() ifaces = list() - for i in xrange(node_count): + for i in range(node_count): node = ec.register_resource("dummy::Node") nodes.append(node) @@ -107,7 +107,7 @@ class PlotterTestCase(unittest.TestCase): ec.register_connection(node, iface) ifaces.append(iface) - for i in xrange(app_count): + for i in range(app_count): app = ec.register_resource("dummy::Application") ec.register_connection(node, app) apps.append(app) diff --git a/test/util/serializer.py b/test/util/serializer.py index a381fed8..3ee85c10 100755 --- a/test/util/serializer.py +++ b/test/util/serializer.py @@ -101,7 +101,7 @@ class SerializerTestCase(unittest.TestCase): apps = list() ifaces = list() - for i in xrange(node_count): + for i in range(node_count): node = ec.register_resource("dummy::Node") nodes.append(node) @@ -109,7 +109,7 @@ class SerializerTestCase(unittest.TestCase): ec.register_connection(node, iface) ifaces.append(iface) - for i in xrange(app_count): + for i in range(app_count): app = ec.register_resource("dummy::Application") ec.register_connection(node, app) apps.append(app) diff --git a/test/util/sshfuncs.py b/test/util/sshfuncs.py index 2c9c30b6..44c272a2 100755 --- a/test/util/sshfuncs.py +++ b/test/util/sshfuncs.py @@ -204,9 +204,9 @@ class SSHfuncsTestCase(unittest.TestCase): files.extend(names) os.path.walk(destdir, recls, files) - origfiles = map(lambda s: os.path.basename(s), [dirpath, f.name, f1.name]) + origfiles = [os.path.basename(s) for s in [dirpath, f.name, f1.name]] - self.assertEquals(sorted(origfiles), sorted(files)) + self.assertEqual(sorted(origfiles), sorted(files)) os.remove(f1.name) shutil.rmtree(dirpath) @@ -236,9 +236,9 @@ class SSHfuncsTestCase(unittest.TestCase): files.extend(names) os.path.walk(destdir, recls, files) - origfiles = map(lambda s: os.path.basename(s), [dirpath, f.name, f1.name]) + origfiles = [os.path.basename(s) for s in [dirpath, f.name, f1.name]] - self.assertEquals(sorted(origfiles), sorted(files)) + self.assertEqual(sorted(origfiles), sorted(files)) def test_rproc_manage(self): env = test_environment()