Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qemu_guest_agent: Update shutdown() #1391

Merged
merged 1 commit into from
Sep 21, 2018

Conversation

xiangchunfu
Copy link
Contributor

@xiangchunfu xiangchunfu commented Mar 8, 2018

guest_agent: Update shutdown()

Currently, shutdown() returns "{}" or no response after sending the shutdown command,
remove success_resp=False option to raise error message,and remove useless
"return True" and ignore VAgentProtocolErro at the same time.

ID: 1468530, 1476648

Signed-off-by: Xiangchun Fu xfu@redhat.com

@xiangchunfu
Copy link
Contributor Author

(1/2) smp_8.8192m.repeat1.run_test.Host_RHEL.m7.u3.qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.7.4.x86_64.myprovider.qemu_guest_agent.virtio_serial.check_reset_reboot_shutdown_fsfreeze: PASS (98.68 s)
(2/2) smp_8.8192m.repeat1.run_test.Host_RHEL.m7.u3.qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.7.4.x86_64.myprovider.qemu_guest_agent.isa_serial.check_reset_reboot_shutdown_fsfreeze: PASS (88.30 s)

@xiangchunfu
Copy link
Contributor Author

tp-qemu patch
autotest/tp-qemu#1032

self.cmd(cmd=cmd, args=args, success_resp=False)
try:
self.cmd(cmd=cmd, args=args, success_resp=True)
except VAgentCmdError:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better return the detailed error msg for debugging usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lijinlijin It will return "The command xxx has been disabled for this instance" error msg when executing shutdown. This msg is from VAgentCmdError, VAgentCmdError depend on qemu monitor. Do you wish like this "except 'The command xxx has been disabled for this instance'": ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lijinlijin In order to tp-qemu can get this error Msg, raise this error Msg.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you need to check the content of the error message in your test context, here should let self.cmd() raise the VAgentCmdError directly instead of catching it and returning False.

So finally the code would be:

- self.cmd(cmd=cmd, args=args, success_resp=False)
- return True
+ self.cmd(cmd=cmd, args=args)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luckyh You are right, cmd() can raise this Error. I have updated it and re-tested it.

(1/2) Host_RHEL.m7.u6.qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.7.6.x86_64.io-github-autotest-qemu.qemu_guest_agent.virtio_serial.check_reset_reboot_shutdown_fsfreeze: PASS (124.79 s)
(2/2) Host_RHEL.m7.u6.qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.7.6.x86_64.io-github-autotest-qemu.qemu_guest_agent.isa_serial.check_reset_reboot_shutdown_fsfreeze: PASS (143.99 s)

try:
self.cmd(cmd=cmd, args=args, success_resp=True)
except VAgentCmdError:
raise
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above approach has the same meaning as self.cmd(cmd=cmd, args=args, success_resp=True), the problem is there are several types of error but only some of them would not be allowed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luckyh I need to cautch this VAgentCmdError's output. when excepting VAgentCmdError, In order not to interrupt this function. I only replace raise with str(e).

@xiangchunfu xiangchunfu force-pushed the guest_agent_shutdown branch 2 times, most recently from 4417434 to bb8a351 Compare March 30, 2018 07:21
Copy link
Contributor Author

@xiangchunfu xiangchunfu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luckyh return False as below

  •    except VAgentCmdError as e:
    
  •        str(e)
    
  •        return False
    

(1/2) smp_4.1024m.repeat1.run_test.Host_RHEL.m7.u5.qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.7.4.x86_64.io-github-autotest-qemu.qemu_guest_agent.virtio_serial.check_reset_reboot_shutdown_fsfreeze: PASS (81.91 s)
(2/2) smp_4.1024m.repeat1.run_test.Host_RHEL.m7.u5.qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.7.4.x86_64.io-github-autotest-qemu.qemu_guest_agent.isa_serial.check_reset_reboot_shutdown_fsfreeze: PASS (81.57 s)

try:
self.cmd(cmd=cmd, args=args, success_resp=True)
except VAgentCmdError:
raise
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luckyh I need to cautch this VAgentCmdError's output. when excepting VAgentCmdError, In order not to interrupt this function. I only replace raise with str(e).

self.cmd(cmd=cmd, args=args, success_resp=True)
except VAgentCmdError as e:
str(e)
return False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on autotest/tp-qemu#1032

        except VAgentCmdError:
            return False

would be enough.

Can you explain what str(e) is for on line 515

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hereischen You are right, Don't need "str(e)". (original idea was to use str(e) to call str(self) method in Class VAgentCmdError).

@xiangchunfu xiangchunfu force-pushed the guest_agent_shutdown branch 2 times, most recently from 8db4d55 to f8c4ce4 Compare August 20, 2018 07:21
Copy link
Contributor

@vivianQizhu vivianQizhu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK

@luckyh
Copy link
Contributor

luckyh commented Aug 22, 2018

@xiangchunfu the code looks good to me now, but I still request a sensible commit message, thanks.

@xiangchunfu xiangchunfu changed the title qemu_guest_agent: send agent shutdown command when guest FS is freezed qemu_guest_agent: Catch agent shutdown command return value Aug 22, 2018
@xiangchunfu xiangchunfu force-pushed the guest_agent_shutdown branch 2 times, most recently from b6caf4d to 30c1bf0 Compare August 23, 2018 06:41
@xiangchunfu xiangchunfu changed the title qemu_guest_agent: Catch agent shutdown command return value qemu_guest_agent: fix agent shutdown() return Null value Aug 23, 2018
@xiangchunfu xiangchunfu force-pushed the guest_agent_shutdown branch 2 times, most recently from f9cad87 to fee5f09 Compare August 27, 2018 05:14
@xiangchunfu xiangchunfu changed the title qemu_guest_agent: fix agent shutdown() return Null value qemu_guest_agent: Update shutdown() Aug 28, 2018
@xiangchunfu xiangchunfu force-pushed the guest_agent_shutdown branch 5 times, most recently from 7d7df45 to cf95c17 Compare September 20, 2018 02:41
@vivianQizhu
Copy link
Contributor

@luckyh Would you please check if the commit message proper and help merge it if so? Thanks.

@@ -509,8 +509,7 @@ def shutdown(self, mode=SHUTDOWN_MODE_POWERDOWN):
if mode in [self.SHUTDOWN_MODE_POWERDOWN, self.SHUTDOWN_MODE_REBOOT,
self.SHUTDOWN_MODE_HALT]:
args = {"mode": mode}
self.cmd(cmd=cmd, args=args, success_resp=False)
return True
self.cmd(cmd=cmd, args=args)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized that it should ignore the error that there is no response after sending the command, so you should catch VAgentProtocolError and ignore it at here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luckyh You are right, I have updated.

Currently, shutdown() returns "{}" or no response after sending the shutdown command,
remove success_resp=False option to raise error message,and remove useless
"return True" and ignore VAgentProtocolErro at the same time.

Signed-off-by: Xiangchun Fu <xfu@redhat.com>
Copy link
Contributor

@luckyh luckyh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK

@luckyh luckyh merged commit 2740da4 into avocado-framework:master Sep 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants