Re: [devel] [PATCH 1 of 1] smfd: wait for node destination before command execution [#893]

2014-05-15 Thread Anders Widell
Ack with minor comment: there is no check for the return value from 
sleep(), so sleep time may be shortened if interrupted by a signal. 
Also, sleep() is an old function that according to man page may be 
implemented using SIGALRM, which means there is a risk of interference 
from other threads or a prior call to alarm(). Consider using the new 
OpenSAF utility function osaf_nanosleep() instead, which has no risk of 
interference and handles signal interruption for you. E.g. like this:

#include "osaf_time.h"

struct timespec interval = { 2, 0 };
osaf_nanosleep(&interval);

/ Anders Widell

On 05/12/2014 08:53 AM, Ingvar Bergstrom wrote:
>   osaf/services/saf/smfsv/smfd/SmfUpgradeStep.cc |  58 
> +++--
>   osaf/services/saf/smfsv/smfd/SmfUpgradeStep.hh |   8 ---
>   osaf/services/saf/smfsv/smfd/SmfUtils.cc   |  18 
>   osaf/services/saf/smfsv/smfd/SmfUtils.hh   |   1 +
>   4 files changed, 26 insertions(+), 59 deletions(-)
>
>
> smfd wait for the node destination to appear before any command specified in 
> the campaign is executed.
> If the node destination does not appear within a timeout period the campaign 
> will fail.
>
> diff --git a/osaf/services/saf/smfsv/smfd/SmfUpgradeStep.cc 
> b/osaf/services/saf/smfsv/smfd/SmfUpgradeStep.cc
> --- a/osaf/services/saf/smfsv/smfd/SmfUpgradeStep.cc
> +++ b/osaf/services/saf/smfsv/smfd/SmfUpgradeStep.cc
> @@ -1654,41 +1654,6 @@ SmfUpgradeStep::saveImmContent()
>   }
>   
>   
> //--
> -// executeRemoteCmd()
> -//--
> -bool
> -SmfUpgradeStep::executeRemoteCmd( const std::string  &i_cmd,
> -   const std::string & i_node)
> -{
> - TRACE_ENTER();
> - TRACE("Executing script '%s' on node '%s'", i_cmd.c_str(), 
> i_node.c_str());
> - SaTimeT timeout;
> - uint32_t cmdrc;
> - bool rc = true;
> -SmfndNodeDest nodeDest;
> -if (!getNodeDestination(i_node, &nodeDest)) {
> - LOG_NO("no node destination found for node %s", i_node.c_str());
> - rc = false;
> - goto done;
> - }
> -
> - /* Execute the script remote on node */
> - timeout = smfd_cb->cliTimeout;  /* Default timeout */
> -
> - cmdrc = smfnd_exec_remote_cmd(i_cmd.c_str(), &nodeDest, timeout / 
> 1000, 0);
> - /* convert ns to 10 ms timeout */
> - if (cmdrc != 0) {
> - LOG_NO("executing command '%s' on node '%s' failed (%x)",
> -i_cmd.c_str(), i_node.c_str(), cmdrc);
> - rc = false;
> - goto done;
> - }
> -done:
> - TRACE_LEAVE();
> - return rc;
> -}
> -
> -//--
>   // callActivationCmd()
>   
> //--
>   bool
> @@ -1744,7 +1709,7 @@ SmfUpgradeStep::callActivationCmd()
>   
>   TRACE("Executing activation command '%s' on node '%s' 
> (single-step)",
> actCommand.c_str(), nodeName);
> -if (!getNodeDestination(*n, &nodeDest)) {
> +if (!waitForNodeDestination(*n, &nodeDest)) {
>   LOG_NO("no node destination found for node 
> [%s]", nodeName);
>   result = false;
>   goto done;
> @@ -1897,7 +1862,7 @@ SmfUpgradeStep::callBundleScript(SmfInst
>   char const* nodeName = n->c_str();
>   TRACE("Executing bundle script '%s' on node 
> '%s' (single-step)",
> command.c_str(), nodeName);
> - if (!getNodeDestination(*n, &nodeDest)) {
> + if (!waitForNodeDestination(*n, &nodeDest)) {
>   LOG_NO("no node destination found for 
> node [%s]", nodeName);
>   result = false;
>   goto done;
> @@ -1910,7 +1875,6 @@ SmfUpgradeStep::callBundleScript(SmfInst
>   goto done;
>   }
>   }
> -
>   } else {
>   
>   SmfndNodeDest nodeDest;
> @@ -1918,19 +1882,11 @@ SmfUpgradeStep::callBundleScript(SmfInst
> command.c_str(), i_node.c_str());
>   TRACE("Get node destination for %s", i_node.c_str());
>   
> - int interval = 5;
> - int nodetimeout = smfd_cb->rebootTimeout/10; 
> //seconds
> - while (!getNodeDestination(i_node, &nodeDest)) {
> - if (nodetimeout > 0) {
> - TRACE("No destination found, try 

[devel] [PATCH 1 of 1] smfd: wait for node destination before command execution [#893]

2014-05-11 Thread Ingvar Bergstrom
 osaf/services/saf/smfsv/smfd/SmfUpgradeStep.cc |  58 +++--
 osaf/services/saf/smfsv/smfd/SmfUpgradeStep.hh |   8 ---
 osaf/services/saf/smfsv/smfd/SmfUtils.cc   |  18 
 osaf/services/saf/smfsv/smfd/SmfUtils.hh   |   1 +
 4 files changed, 26 insertions(+), 59 deletions(-)


smfd wait for the node destination to appear before any command specified in 
the campaign is executed.
If the node destination does not appear within a timeout period the campaign 
will fail.

diff --git a/osaf/services/saf/smfsv/smfd/SmfUpgradeStep.cc 
b/osaf/services/saf/smfsv/smfd/SmfUpgradeStep.cc
--- a/osaf/services/saf/smfsv/smfd/SmfUpgradeStep.cc
+++ b/osaf/services/saf/smfsv/smfd/SmfUpgradeStep.cc
@@ -1654,41 +1654,6 @@ SmfUpgradeStep::saveImmContent()
 }
 
 
//--
-// executeRemoteCmd()
-//--
-bool 
-SmfUpgradeStep::executeRemoteCmd( const std::string  &i_cmd,
- const std::string & i_node)
-{
-   TRACE_ENTER();
-   TRACE("Executing script '%s' on node '%s'", i_cmd.c_str(), 
i_node.c_str());
-   SaTimeT timeout;
-   uint32_t cmdrc;
-   bool rc = true;
-SmfndNodeDest nodeDest;
-if (!getNodeDestination(i_node, &nodeDest)) {
-   LOG_NO("no node destination found for node %s", i_node.c_str());
-   rc = false;
-   goto done;
-   }
-
-   /* Execute the script remote on node */
-   timeout = smfd_cb->cliTimeout;  /* Default timeout */
-
-   cmdrc = smfnd_exec_remote_cmd(i_cmd.c_str(), &nodeDest, timeout / 
1000, 0);
-   /* convert ns to 10 ms timeout */
-   if (cmdrc != 0) {
-   LOG_NO("executing command '%s' on node '%s' failed (%x)", 
-  i_cmd.c_str(), i_node.c_str(), cmdrc);
-   rc = false;
-   goto done;
-   }
-done:
-   TRACE_LEAVE();
-   return rc;
-}
-
-//--
 // callActivationCmd()
 
//--
 bool 
@@ -1744,7 +1709,7 @@ SmfUpgradeStep::callActivationCmd()
 
TRACE("Executing activation command '%s' on node '%s' 
(single-step)", 
  actCommand.c_str(), nodeName);
-if (!getNodeDestination(*n, &nodeDest)) {
+if (!waitForNodeDestination(*n, &nodeDest)) {
LOG_NO("no node destination found for node 
[%s]", nodeName);
result = false;
goto done;
@@ -1897,7 +1862,7 @@ SmfUpgradeStep::callBundleScript(SmfInst
char const* nodeName = n->c_str();
TRACE("Executing bundle script '%s' on node 
'%s' (single-step)", 
  command.c_str(), nodeName);
-   if (!getNodeDestination(*n, &nodeDest)) {
+   if (!waitForNodeDestination(*n, &nodeDest)) {
LOG_NO("no node destination found for 
node [%s]", nodeName);
result = false;
goto done;
@@ -1910,7 +1875,6 @@ SmfUpgradeStep::callBundleScript(SmfInst
goto done;
}
}
-
} else {
 
 SmfndNodeDest nodeDest;
@@ -1918,19 +1882,11 @@ SmfUpgradeStep::callBundleScript(SmfInst
  command.c_str(), i_node.c_str());
TRACE("Get node destination for %s", i_node.c_str());
 
-   int interval = 5;
-   int nodetimeout = smfd_cb->rebootTimeout/10; 
//seconds
-   while (!getNodeDestination(i_node, &nodeDest)) {
-   if (nodetimeout > 0) {
-   TRACE("No destination found, try again 
wait %d seconds", interval);
-   sleep(interval);
-   nodetimeout -= interval;
-   } else {
-   LOG_NO("no node destination found for 
node %s", i_node.c_str());
-   result = false;
-   goto done;
-   }
-   }
+if (!waitForNodeDestination(i_node, &nodeDest)) {
+LOG_NO("no node destination found for node 
%s", i_node.c_str());
+result = false;
+goto done;
+}