From: Alina Quereilhac Date: Sat, 31 May 2014 16:50:53 +0000 (+0200) Subject: Making Linux Ping start as early as deployment X-Git-Tag: nepi-3.1.0~54 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=96481ca7771a1bf5afee2acb3606be7dee308498;p=nepi.git Making Linux Ping start as early as deployment --- diff --git a/src/nepi/execution/resource.py b/src/nepi/execution/resource.py index ba84805a..2d24dd1e 100644 --- a/src/nepi/execution/resource.py +++ b/src/nepi/execution/resource.py @@ -429,7 +429,7 @@ class ResourceManager(Logger): :rtype: str """ - return " %s guid: %d - %s " % (self._rtype, self.guid, msg) + return " %s guid %d - %s " % (self._rtype, self.guid, msg) def register_connection(self, guid): """ Registers a connection to the RM identified by guid diff --git a/src/nepi/resources/linux/ccn/fibentry.py b/src/nepi/resources/linux/ccn/fibentry.py index dca91c24..bdf0c681 100644 --- a/src/nepi/resources/linux/ccn/fibentry.py +++ b/src/nepi/resources/linux/ccn/fibentry.py @@ -164,6 +164,7 @@ class LinuxFIBEntry(LinuxApplication): self._ping = self.ec.register_resource("LinuxPing") self.ec.set(self._ping, "printTimestamp", True) self.ec.set(self._ping, "target", self.get("host")) + self.ec.set(self._ping, "earlyStart", True) self.ec.register_connection(self._ping, self.node.guid) # schedule ping deploy self.ec.deploy(guids=[self._ping], group = self.deployment_group) diff --git a/src/nepi/resources/linux/ping.py b/src/nepi/resources/linux/ping.py index a3df5799..0031e187 100644 --- a/src/nepi/resources/linux/ping.py +++ b/src/nepi/resources/linux/ping.py @@ -156,6 +156,12 @@ class LinuxPing(LinuxApplication): "The host to ping .", flags = Flags.Design) + early_start = Attribute("earlyStart", + "Start ping as early as deployment. ", + type = Types.Bool, + default = False, + flags = Flags.Design) + cls._register_attribute(count) cls._register_attribute(mark) cls._register_attribute(interval) @@ -179,17 +185,57 @@ class LinuxPing(LinuxApplication): cls._register_attribute(deadline) cls._register_attribute(timeout) cls._register_attribute(target) + cls._register_attribute(early_start) def __init__(self, ec, guid): super(LinuxPing, self).__init__(ec, guid) self._home = "ping-%s" % self.guid + def upload_start_command(self): + if self.get("earlyStart") == True: + command = self.get("command") + env = self.get("env") + + # We want to make sure the FIB entries are created + # before the experiment starts. + # Run the command as a bash script in the background, + # in the host ( but wait until the command has + # finished to continue ) + env = env and self.replace_paths(env) + command = self.replace_paths(command) + + # 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(): + msg = "Failed to execute command" + self.error(msg, out, err) + raise RuntimeError, msg + else: + super(LinuxPing, self).upload_start_command() + def do_deploy(self): if not self.get("command"): self.set("command", self._start_command) super(LinuxPing, self).do_deploy() + def do_start(self): + if self.get("earlyStart") == True: + if self.state == ResourceState.READY: + command = self.get("command") + self.info("Starting command '%s'" % command) + + self.set_started() + else: + msg = " Failed to execute command '%s'" % command + self.error(msg, out, err) + raise RuntimeError, msg + else: + super(LinuxPing, self).do_start() + @property def _start_command(self): args = []