From 6f979be5d83cdb4c2f752fe1777d1b848184c818 Mon Sep 17 00:00:00 2001 From: Alina Quereilhac Date: Thu, 25 Jul 2013 18:48:39 -0700 Subject: [PATCH] Making CCN FIBEntry issue ccndc with hostname resolved to IP, since PlanetLab name resolution is unstable --- src/nepi/resources/linux/ccn/ccncontent.py | 4 +-- src/nepi/resources/linux/ccn/ccnd.py | 29 +++++++++++----------- src/nepi/resources/linux/ccn/fibentry.py | 29 ++++++++++++++++------ src/nepi/util/sshfuncs.py | 5 ++-- 4 files changed, 40 insertions(+), 27 deletions(-) diff --git a/src/nepi/resources/linux/ccn/ccncontent.py b/src/nepi/resources/linux/ccn/ccncontent.py index 9d531de2..5b9d9252 100644 --- a/src/nepi/resources/linux/ccn/ccncontent.py +++ b/src/nepi/resources/linux/ccn/ccncontent.py @@ -118,8 +118,8 @@ class LinuxCCNContent(LinuxApplication): env = self.replace_paths(env) command = self.replace_paths(command) - (out, err), proc = self.execute_command(command, env, - blocking = True) + (out, err), proc = self.execute_command(command, + env, blocking = True) if proc.poll(): self.fail() diff --git a/src/nepi/resources/linux/ccn/ccnd.py b/src/nepi/resources/linux/ccn/ccnd.py index d2358a4e..20c04fc1 100644 --- a/src/nepi/resources/linux/ccn/ccnd.py +++ b/src/nepi/resources/linux/ccn/ccnd.py @@ -188,22 +188,21 @@ class LinuxCCND(LinuxApplication): command = self.get("command") env = self.get("env") - if command: - # We want to make sure the ccnd is running - # before the experiment starts. - # Run the command as a bash script in background, - # in the host ( but wait until the command has - # finished to continue ) - env = self.replace_paths(env) - command = self.replace_paths(command) + # We want to make sure the ccnd is running + # before the experiment starts. + # Run the command as a bash script in background, + # in the host ( but wait until the command has + # finished to continue ) + env = self.replace_paths(env) + command = self.replace_paths(command) + + shfile = os.path.join(self.app_home, "start.sh") + self.node.run_and_wait(command, self.run_home, + shfile = shfile, + overwrite = False, + env = env, + raise_on_error = True) - shfile = os.path.join(self.app_home, "start.sh") - self.node.run_and_wait(command, self.run_home, - shfile = shfile, - overwrite = False, - env = env, - raise_on_error = True) - def start(self): if self._state == ResourceState.READY: command = self.get("command") diff --git a/src/nepi/resources/linux/ccn/fibentry.py b/src/nepi/resources/linux/ccn/fibentry.py index 1f39a986..62d9049d 100644 --- a/src/nepi/resources/linux/ccn/fibentry.py +++ b/src/nepi/resources/linux/ccn/fibentry.py @@ -26,6 +26,8 @@ from nepi.resources.linux.ccn.ccnd import LinuxCCND from nepi.util.timefuncs import tnow import os +import socket +import time # TODO: Add rest of options for ccndc!!! @@ -51,7 +53,7 @@ class LinuxFIBEntry(LinuxApplication): flags = Flags.ExecReadOnly) host = Attribute("host", - "Peer host used in network connection for this FIB entry. ", + "Peer hostname used in network connection for this FIB entry. ", flags = Flags.ExecReadOnly) port = Attribute("port", @@ -59,10 +61,15 @@ class LinuxFIBEntry(LinuxApplication): "for this FIB entry.", flags = Flags.ExecReadOnly) + ip = Attribute("ip", + "Peer host public IP used in network connection for this FIB entry. ", + flags = Flags.ReadOnly) + cls._register_attribute(uri) cls._register_attribute(protocol) cls._register_attribute(host) cls._register_attribute(port) + cls._register_attribute(ip) @classmethod def _register_traces(cls): @@ -109,6 +116,11 @@ class LinuxFIBEntry(LinuxApplication): self.ec.schedule(reschedule_delay, self.deploy) else: try: + if not self.get("ip"): + host = self.get("host") + ip = socket.gethostbyname(host) + self.set("ip", ip) + if not self.get("command"): self.set("command", self._start_command) @@ -142,14 +154,17 @@ class LinuxFIBEntry(LinuxApplication): env = env and self.replace_paths(env) command = self.replace_paths(command) - (out, err), proc = self.execute_command(command, env) + # ccndc seems to return exitcode OK even if a (dns) error + # occurred, so we need to account for this case here. + (out, err), proc = self.execute_command(command, + env, blocking = True) if proc.poll(): self._state = ResourceState.FAILED msg = "Failed to execute command" self.error(msg, out, err) raise RuntimeError, msg - + def configure(self): if self.trace_enabled("ping"): self.info("Configuring PING trace") @@ -218,14 +233,14 @@ class LinuxFIBEntry(LinuxApplication): def _start_command(self): uri = self.get("uri") or "" protocol = self.get("protocol") or "" - host = self.get("host") or "" + ip = self.get("ip") or "" port = self.get("port") or "" # add ccnx:/example.com/ udp 224.0.0.204 52428 return "ccndc add %(uri)s %(protocol)s %(host)s %(port)s" % ({ "uri" : uri, "protocol": protocol, - "host": host, + "host": ip, "port": port }) @@ -233,14 +248,14 @@ class LinuxFIBEntry(LinuxApplication): def _stop_command(self): uri = self.get("uri") or "" protocol = self.get("protocol") or "" - host = self.get("host") or "" + ip = self.get("ip") or "" port = self.get("port") or "" # add ccnx:/example.com/ udp 224.0.0.204 52428 return "ccndc del %(uri)s %(protocol)s %(host)s %(port)s" % ({ "uri" : uri, "protocol": protocol, - "host": host, + "host": ip, "port": port }) diff --git a/src/nepi/util/sshfuncs.py b/src/nepi/util/sshfuncs.py index cc303486..43ca61c0 100644 --- a/src/nepi/util/sshfuncs.py +++ b/src/nepi/util/sshfuncs.py @@ -292,9 +292,8 @@ def rexec(command, host, user, if blocking: out, err = _communicate(proc, stdin, timeout, err_on_timeout) else: - out = err = "" - if proc.poll(): - err = proc.stderr.read() + err = proc.stderr.read() + out = proc.stdout.read() msg = " rexec - host %s - command %s " % (host, " ".join(args)) log(msg, logging.DEBUG, out, err) -- 2.43.0