chef / knife-windows

Plugin for Chef's knife tool for working with Windows nodes
Apache License 2.0
152 stars 110 forks source link

Edge condition - WinRM command with no output always succeeds #314

Closed carpnick closed 9 years ago

carpnick commented 9 years ago

If no output is returned in the winrm command, it always succeeds.

More than likely is a WinRM gem issue but opening here so others are not surprised. While debugging issue #311 , I found that this code(taken partially from winrm_session always has a success (0) exit code. If you comment out line 16 and uncomment line 17 it exits with the appropriate exit code (100)

carpnick commented 9 years ago

Weird so debugging the WinRM gem:

Failure case

Body Sent:

<env:Body>
    <rsp:CommandLine>
      <rsp:Command>&quot; exit 100&quot;</rsp:Command>
    </rsp:CommandLine>
  </env:Body>

Received:

<rsp:ReceiveResponse>
      <rsp:CommandState CommandId='469786EF-ACB4-47D6-AC50-087F05B78CD4' State='http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandState/Done'>
        <rsp:ExitCode>0</rsp:ExitCode>
      </rsp:CommandState>
    </rsp:ReceiveResponse>

Expected use case:

Request:

<env:Body>
    <rsp:CommandLine>
      <rsp:Command>&quot;echo hello &amp;&amp; exit 100&quot;</rsp:Command>
    </rsp:CommandLine>
  </env:Body>

Response:

<s:Body>
    <rsp:ReceiveResponse>
      <rsp:Stream Name='stdout' CommandId='BD6AA971-D33B-48A8-A1BC-E2B515770A89'>aGVsbG8gDQo=</rsp:Stream>
      <rsp:Stream Name='stdout' CommandId='BD6AA971-D33B-48A8-A1BC-E2B515770A89' End='true'/>
      <rsp:Stream Name='stderr' CommandId='BD6AA971-D33B-48A8-A1BC-E2B515770A89' End='true'/>
      <rsp:CommandState CommandId='BD6AA971-D33B-48A8-A1BC-E2B515770A89' State='http://schemas.microsoft.com/wbem/wsman/1/windows/shell/CommandState/Done'>
        <rsp:ExitCode>100</rsp:ExitCode>
      </rsp:CommandState>
    </rsp:ReceiveResponse>
  </s:Body>
carpnick commented 9 years ago

Closing as this can be validated within only WinRM in the mix. See issue https://github.com/WinRb/WinRM/issues/154 for updates