Bug 853673

Summary: virsh qemu-agent-command returns 0 and without any error message on parsing json char lexical error
Product: [Community] Virtualization Tools Reporter: Alex Jia <ajia>
Component: libvirtAssignee: Libvirt Maintainers <libvirt-maint>
Status: CLOSED CURRENTRELEASE QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: unspecifiedCC: crobinso, dyuan, jdenemar, mzhan, rbalakri, smitterl
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-03-24 00:45:49 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Alex Jia 2012-09-02 03:26:21 UTC
Description of problem:
To pass a invalid command such as 'hello' to 'virsh qemu-agent-command' then command exits status is 0, but we can find a json lexical error in libvirtd.log. 

Version-Release number of selected component (if applicable):
# rpm -q libvirt qemu-kvm-rhev kernel                                                                                                                 
libvirt-0.10.1-1.el6.x86_64
qemu-kvm-rhev-0.12.1.2-2.302.el6.x86_64
kernel-2.6.32-288.el6.x86_64


How reproducible:
always

Steps to Reproduce:
1. virsh start <domain>
2. virsh qemu-agent-command <domain> hello
3. echo $?

  
Actual results:

# virsh qemu-agent-command foo hello

# echo $?
0

# cat /var/log/libvirt/libvirtd.log  (to enable '1:json' in libvirtd.conf)

<snip>

2012-09-02 03:12:14.660+0000: 30900: debug : qemuDispatchDomainAgentCommandHelper:19 : server=0x2089dc0 client=0x2093140 msg=0x2092570 rerr=0x7fb437755b80 args=0x7fb418000a60 ret=0x7fb418000b40
2012-09-02 03:12:14.660+0000: 30900: debug : virDomainQemuAgentCommand:217 : domain=0x7fb418000c00, cmd=hello, timeout=-1, flags=0
2012-09-02 03:12:14.660+0000: 30900: debug : qemuDomainObjBeginJobInternal:807 : Starting job: modify (async=none)
2012-09-02 03:12:14.660+0000: 30900: debug : virJSONValueFromString:975 : string=hello
2012-09-02 03:12:14.660+0000: 30900: error : virJSONValueFromString:1001 : internal error cannot parse json hello: lexical error: invalid char in json text.
                                       hello
                     (right here) ------^

2012-09-02 03:12:14.660+0000: 30900: debug : virJSONValueFromString:1019 : result=(nil)
2012-09-02 03:12:14.660+0000: 30900: error : qemuDomainAgentCommand:13904 : internal error Failed to execute agent command

</snip>

Expected results:

Libivirt should raise a error information and 'virsh qemu-agent-command' should exit with status 1.

Additional info:

Comment 2 Alex Jia 2012-09-02 03:40:58 UTC
BTW, I haven't do any guest agent configuration in guest XML.

Comment 3 Jiri Denemark 2012-09-03 09:59:28 UTC
*** Bug 853705 has been marked as a duplicate of this bug. ***

Comment 4 Jiri Denemark 2012-09-03 10:01:31 UTC
qemuDomainAgentCommand correctly reports the error but it seems it is not properly propagated to the end user. Anyway, qemu-agent-command (all qemu-* commands to be precise) is not supported, I'm moving this bug upstream.

Comment 5 Alex Jia 2012-09-03 10:32:39 UTC
(In reply to comment #4)
> qemuDomainAgentCommand correctly reports the error but it seems it is not
> properly propagated to the end user. Anyway, qemu-agent-command (all qemu-*
> commands to be precise) is not supported, I'm moving this bug upstream.

Jiri, in fact, the 'qemu-agent-command' does work for me if I passed correct commands to it and correctly configure qemu-guest-agent in the guest, for example:

# virsh qemu-agent-command myRHEL6 --cmd '{"execute":"guest-ping"}'
{"return":{}}

# virsh qemu-agent-command myRHEL6 --cmd '{ "execute": "guest-sync", "arguments": { "id": 123456 } }'
{"return":123456}

# virsh qemu-agent-command myRHEL6 --cmd '{"execute":"guest-fsfreeze-status"}'
{"return":"thawed"}

# virsh qemu-agent-command myRHEL6 --cmd '{"execute":"guest-fsfreeze-freeze"}'
{"return":2}

# virsh qemu-agent-command myRHEL6 --cmd '{"execute":"guest-fsfreeze-status"}'
{"return":"frozen"}

# virsh snapshot-create-as --quiesce myRHEL6 --disk-only
Domain snapshot 1346642071 created

# virsh qemu-agent-command myRHEL6 --cmd '{"execute":"guest-fsfreeze-status"}'
{"return":"thawed"}

# virsh qemu-agent-command myRHEL6 --cmd '{"execute":"guest-network-get-interfaces"}'
{"return":[{"name":"lo","ip-addresses":[{"ip-address-type":"ipv4","ip-address":"127.0.0.1","prefix":8},{"ip-address-type":"ipv6","ip-address":"::1","prefix":128}],"hardware-address":"00:00:00:00:00:00"},{"name":"eth7","ip-addresses":[{"ip-address-type":"ipv4","ip-address":"192.168.122.156","prefix":24},{"ip-address-type":"ipv6","ip-address":"fe80::5054:ff:feda:4aeb","prefix":64}],"hardware-address":"52:54:00:da:4a:eb"}]}

Comment 6 Alex Jia 2013-11-06 02:46:59 UTC
(In reply to Jiri Denemark from comment #4)
> qemuDomainAgentCommand correctly reports the error but it seems it is not
> properly propagated to the end user. Anyway, qemu-agent-command (all qemu-*
> commands to be precise) is not supported, I'm moving this bug upstream.

The qemu-monitor-command has the same issue of the return value on libvirt-0.10.2-29.el6.x86_64.

Comment 7 Cole Robinson 2016-03-24 00:45:49 UTC
Seems fixed upstream:

$ sudo virsh qemu-monitor-command f23 hello
error: internal error: cannot parse json hello: lexical error: invalid char in json text.
                                       hello
                     (right here) ------^