From: Lucia Guevgeozian Odizzio Date: Tue, 18 Mar 2014 13:10:43 +0000 (+0100) Subject: Fix bug ping X-Git-Tag: nepi-3.1.0~106 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=f5a6589df947b5d25bf488ad6089526dd08a77f1;p=nepi.git Fix bug ping --- diff --git a/src/nepi/resources/planetlab/node.py b/src/nepi/resources/planetlab/node.py index 34e54886..8ea62fd6 100644 --- a/src/nepi/resources/planetlab/node.py +++ b/src/nepi/resources/planetlab/node.py @@ -562,10 +562,10 @@ class PlanetlabNode(LinuxNode): def _get_hostname(self): hostname = self.get("hostname") - ip = self.get("ip") if hostname: return hostname - elif ip: + ip = self.get("ip") + if ip: hostname = socket.gethostbyaddr(ip)[0] self.set('hostname', hostname) return hostname @@ -601,10 +601,10 @@ class PlanetlabNode(LinuxNode): command = "ping -c4 %s" % ip (out, err) = lexec(command) - if not str(out).find("2 received") or not str(out).find("3 received") or not \ + if not str(out).find("2 received") < 0 or not str(out).find("3 received") < 0 or not \ str(out).find("4 received") < 0: ping_ok = True - + return ping_ok def _blacklist_node(self, node): @@ -627,9 +627,10 @@ class PlanetlabNode(LinuxNode): """ Query PLCAPI for the IP of a node with certain node id """ - hostname = self.plapi.get_nodes(node_id, ['hostname'])[0] + hostname = self.get("hostname") or \ + self.plapi.get_nodes(node_id, ['hostname'])[0]['hostname'] try: - ip = sshfuncs.gethostbyname(hostname['hostname']) + ip = sshfuncs.gethostbyname(hostname) except: # Fail while trying to find the IP return None