GitHub user GabrielBrascher opened a pull request:

    https://github.com/apache/cloudstack/pull/1459

    Cloudstack 8611 Handle SSH if server "forget" to send exit status

    <h5> Continuing the work started by @likitha, I cherry-picked the 
    commit (b9181c689e0e7b5f1e28c81d73710196dfabd0ba) from PR 
<https://github.com/apache/cloudstack/pull/561>. </h5>
    
    I made some changes from the cherry-picked commit adding @wilderrodrigues 
suggestions (create simple methods that could be reused and make unit tests 
feasible).
    
    Also, tried to simplify the logic by assuming that ....
    
        if ((conditions & ChannelCondition.EXIT_STATUS) != 0) {
                if ((conditions & (ChannelCondition.STDOUT_DATA | 
ChannelCondition.STDERR_DATA)) == 0) {
                    break;
                }
        }
    
    ... is the same as `((conditions & ChannelCondition.EXIT_STATUS) != 0) && 
((conditions & (ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA)) 
== 0)`. This expression has the following results according to each possible 
condition.
    
    |Condition|Value|result
    |-----------------|-------|------|
    TIMEOUT  | 0000001|false 
    CLOSED  | 0000010 |false 
    STDERR_DATA | 0000100 | false 
    STDERR_DATA | 0001000 | false
    EOF         | 0010000 | false 
    EXIT_STATUS | 0100000 | **true**
    EXIT_SIGNAL | 1000000 | false 
    
    Testing all the possibilities, it is possible to note that the condition of 
(newConditions & ChannelCondition.EXIT_STATUS) != 0)`` is sufficient; thus the 
simplified "if" conditional can be:
    
    `if ((conditions & ChannelCondition.EXIT_STATUS) != 0) {
        break;
    }`
    
    This proposed work can be explained by quoting @likitha:
    >CheckS2SVpnConnectionsCommand execution involves executing a script 
(checkbatchs2svpn.sh) in the virtual router. Once CS has opened a session to a 
virtual router and executed a script in the router, it waits indefinitely till 
the session either times out or the exit status of the remote process is 
available. But it is possible that an EOF is reached by the process in the 
router and the router never set the exit status.
    
    >References -
    >1. Some servers never send the exit status, or occasionally "forget" to do 
so 
(http://grepcode.com/file/repo1.maven.org/maven2/org.jvnet.hudson/trilead-ssh2/build212-hudson-1/com/trilead/ssh2/ChannelCondition.java).
    >2. Get the exit code/status from the remote command - if available. Be 
careful - not all server implementations return this value - 
(http://grepcode.com/file/repo1.maven.org/maven2/org.jvnet.hudson/trilead-ssh2/build212-hudson-1/com/trilead/ssh2/Session.java#Session.waitForCondition%28int%2Clong%29).

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/GabrielBrascher/cloudstack CLOUDSTACK-8611

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/cloudstack/pull/1459.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1459
    
----
commit 1409f981f298bfe60a1791222ca0e62276659cad
Author: Likitha Shetty <likitha.she...@citrix.com>
Date:   2015-05-01T11:14:51Z

    CLOUDSTACK-8611. CS waits indefinitely for CheckS2SVpnConnectionsCommand to 
return.
    While remote executing commands through ssh, handle channel condition of 
EOF because we wait for the the condition.

commit 96d76d41ab38ab5459e3b3c685633fb8f41cf609
Author: gabrascher <gabrasc...@hotmail.com>
Date:   2016-04-01T06:21:16Z

    Handle SSH if server "forget" to send exit status.
    
    Cherry-picked the work started by https://github.com/likitha
    commit (b9181c689e0e7b5f1e28c81d73710196dfabd0ba) from PR
    https://github.com/apache/cloudstack/pull/561.
    
    CS waits indefinitely for CheckS2SVpnConnectionsComm and to return.
    While remote executing commands through ssh, handle channel condition of
    EOF because we wait for the the condition.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to