[asterisk-dev] [Code Review] 4391: Add blank line between headers and output for Command action response

gareth reviewboard at asterisk.org
Thu Apr 9 22:51:56 CDT 2015



> On April 3, 2015, 11:37 p.m., Corey Farrell wrote:
> > /trunk/main/manager.c, line 4873
> > <https://reviewboard.asterisk.org/r/4391/diff/3/?file=72904#file72904line4873>
> >
> >     If we successfully ran the command, it seems unsafe to claim failure.  We have to assume the the caller doesn't actually care about any of the CLI output, they only care about having the command perform an action.  So I think we need to respond with success if the command ran.  I'm leaning towards thinking that this error should be provided through a single "Output: Command response construction error\r\n", so move astman_start_ack to just below ast_cli_command.
> >     
> >     On a related issue, there are a couple errors that can occur in ast_cli_command_full which print error messages and return success.  I don't know if it's safe to modify ast_cli_command_full to return errors for more situations, it might be worth looking at to allow us to trust the return value of ast_cli_command_full.  CLI commands themselves can return an error, but this error is not returned by ast_cli_command_full.  It would be nice if this action could use the return value from ast_cli_command_full to determine if it should respond success or failure.
> 
> gareth wrote:
>     If the caller is executing any of the '<module> show ...' commands then they likely care about the output. In this case, I think it would be better to provide a more descriptive error message to the caller so they can detect if the command was executed.
>     
>     Yes, ast_cli_commmand_full should indicate whether the command failed, I will modify it so that an Error response can sent if the command fails. There don't appear to be any callers of that function who check the return code.
> 
> Corey Farrell wrote:
>     I do not feel this issue is resolved.  If a command has side-effects, we should respond with Success/Failure based on if the command ran - regardless of our (in)ability to process output.  Since there is no way to determine if a CLI command is meant to retrieve information or manipulate it, we have to assume that it is manipulating something.  So I agree that descriptive error messages are useful, we need to avoid lying to the caller by claiming that the command failed to run if it did run.
>     
>     For times where people are just retrieving information, couldn't we respond with success, put the error in 'Message:', and provide no 'Output:' headers?  This way if you care about the output, you can detect the lack of output.
> 
> Matt Jordan wrote:
>     This is a tricky one, but I think I agree with Corey on this.
>     
>     We will already send an Error with a Message value if the command was executed but returned a failure response code. The fact that we executed the command successfully but had an internal error that precluded showing the response feels like it should be different from conditions where we either never ran the command at all.
>     
>     How about changing the astman_send_error to the Message: that is sent with a status of Error? In those cases, there wouldn't be any response that follows - since we can't send it - but there is still an overall indication that the command succeeded (sorta).

My concern with indicating 'Success' on failed commands is that the caller then needs to check the output for a known string to determine if the command executed. That would be different for every command.

I am fine with putting the error in the Message: header. Whether the command actually succeeded (Message: Command executed) can be put there as well.

Perhaps it would be easier to agree on the output with a few examples, this is the proposed behaviour:

1. Command NOT executed:

Response: Error
Message: Failed to create temporary file: Read-only file system

2. Command NOT executed, output available (eg: No such command 'XXX'):

Response: Success
Message: Command failed
Output: <failure reason>

3. Command WAS executed, but output is unavailable due to an internal error:

Response: Success
Message: Failed to allocate memory

4. Command WAS executed, output available:

Response: Success
Message: Command executed
Output: <output from the command>

While we are here, the temporary file path is hard-coded to /tmp/ast-ami-XXXXXX, should that be AST_SPOOL_DIR/tmp/ast-ami-XXXXXX?


- gareth


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviewboard.asterisk.org/r/4391/#review15039
-----------------------------------------------------------


On April 9, 2015, 5:05 p.m., gareth wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviewboard.asterisk.org/r/4391/
> -----------------------------------------------------------
> 
> (Updated April 9, 2015, 5:05 p.m.)
> 
> 
> Review request for Asterisk Developers.
> 
> 
> Bugs: ASTERISK-24730
>     https://issues.asterisk.org/jira/browse/ASTERISK-24730
> 
> 
> Repository: Asterisk
> 
> 
> Description
> -------
> 
> This patch adds a blank line between the headers and the output in the Command action response. The reason for this change is to make it easier to determine where the headers end and the output from the command starts.
> 
> Currently, to parse a response to a Command action, one has to:
> 
> 1. Read one line, if line is "Response: Error", parse the remaining as a standard AMI response and stop.
> 2. Read one more line - or two if you used an ActionID - those lines are the headers.
> 3. Then read everything up to "--END COMMAND--\r\n\r\n".
> 
> That could be changed to:
> 
> 1. Read standard AMI response.
> 2. If "Response: Follows", then read everything up to "--END COMMAND--\r\n\r\n".
> 
> The AMI version has been increased to 2.8.0 as this is a protocol change and so that clients detect the new behavior.
> 
> Adding a blank line should not cause older parsers to fail as they have to read everything up to "--END COMMAND--\r\n\r\n" anyway.
> 
> Adding a blank line will also not cause the AMI to HTML/XML encoder to fail to separate the headers from the output as it checks for the presence of a ":" character, which a blank line does not contain.
> 
> 
> Diffs
> -----
> 
>   /trunk/main/manager.c 434448 
>   /trunk/main/cli.c 434448 
>   /trunk/include/asterisk/manager.h 434448 
>   /trunk/UPGRADE.txt 434448 
> 
> Diff: https://reviewboard.asterisk.org/r/4391/diff/
> 
> 
> Testing
> -------
> 
> Connected to manager, issued 'core show uptime' command and verified that there was a blank line between the headers and output.
> 
> 
> Thanks,
> 
> gareth
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20150410/f20e3120/attachment.html>


More information about the asterisk-dev mailing list