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: add new guest agent case #1032

Merged
merged 1 commit into from Nov 2, 2018

Conversation

xiangchunfu
Copy link
Contributor

@xiangchunfu xiangchunfu commented Jul 31, 2017

1.frozen guest FS
2.send shutdown agent cmd to guest
3.send reboot agent cmd to guest
4.send fsthaw cmd to guest

id: 1468530, 1476648
Signed-off-by: Xiangchun Fu xfu@redhat.com

:param env: Dictionary with test environment.
"""
vm = env.get_vm(params["main_vm"])
if not self.vm.is_alive():
Copy link
Contributor

Choose a reason for hiding this comment

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

You have get vm in above line, so this line could be:

if not vm.is_alive():

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have removed self.

if not vm.is_alive():

try:
self.gagent.shutdown(self.gagent.SHUTDOWN_MODE_POWERDOWN)
except Exception:
self.test.fail("guest-shutdown command returned a wrong message")
Copy link
Contributor

Choose a reason for hiding this comment

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

param 'test' is passed to this function, so could remove self.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have removed self.

    except Exception:
        test.fail("guest-shutdown command returned a wrong message")

self.gagent.verify_fsfreeze_status(self.gagent.FSFREEZE_STATUS_FROZEN)

if vm.monitor.cmd("system_reset"):
self.gagent.verify_fsfreeze_status(self.gagent.FSFREEZE_STATUS_THAWED)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need an else here to fail the case if above command does not perform as expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add else

    if vm.monitor.cmd("system_reset"):
        self.gagent.verify_fsfreeze_status(self.gagent.FSFREEZE_STATUS_THAWED)
    else:
        test.fail("system_reset command fail,please check qemu process")


"""
Execute "system_reset" and send "shutdown,reboot" command to guest agent after FS fsreezed
:param test: kvm test objecti
Copy link
Contributor

Choose a reason for hiding this comment

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

s/objecti/object

Copy link
Contributor

Choose a reason for hiding this comment

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

s/fsreezed/freeze

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -722,6 +722,40 @@ def _action_after_fsfreeze(self, *args):
" write file")

@error.context_aware
Copy link
Contributor

Choose a reason for hiding this comment

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

better remove all the @error.context_aware and remove from autotest.client.shared import error
use test.error instead of error.TestError

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just confirm, Do I need remove all @error.context_aware and use test.error instead of error.TestError in this qemu_guest_agent.py?

I always @error.context_aware works.

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 remove all the @error.context_aware and use test.error will be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed all the @error.context_aware and from autotest.client.shared import error. and use test.error instead of error.TestError in this qemu_guest_agent.py

try:
self.gagent.shutdown(self.gagent.SHUTDOWN_MODE_REBOOT)
except Exception:
self.test.fail("guest-reboot command returned a wrong message")
Copy link
Contributor

Choose a reason for hiding this comment

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

test.fail

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have removed self.

    except Exception:
        test.fail("guest-reboot command returned a wrong message")

if vm.monitor.cmd("system_reset"):
self.gagent.verify_fsfreeze_status(self.gagent.FSFREEZE_STATUS_THAWED)

@error.context_aware
Copy link
Contributor

Choose a reason for hiding this comment

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

remove

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do I only need remove " @error.context_aware" or remove from 755~758 lines?

Copy link
Contributor

Choose a reason for hiding this comment

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

@error.context_aware only

logging.info("guest FS is still freeze status")
self.gagent.verify_fsfreeze_status(self.gagent.FSFREEZE_STATUS_FROZEN)

try:
Copy link
Member

Choose a reason for hiding this comment

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

useless try, better to raise original exception

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed try. use 'if' to instead of try.
if self.gagent.shutdown(self.gagent.SHUTDOWN_MODE_POWERDOWN):
self.gagent.verify_fsfreeze_status(self.gagent.FSFREEZE_STATUS_FROZEN)

    if self.gagent.shutdown(self.gagent.SHUTDOWN_MODE_REBOOT):
        self.gagent.verify_fsfreeze_status(self.gagent.FSFREEZE_STATUS_FROZEN)

    if vm.monitor.cmd("system_reset"):
        self.gagent.verify_fsfreeze_status(self.gagent.FSFREEZE_STATUS_THAWED)


if vm.monitor.cmd("system_reset"):
self.gagent.verify_fsfreeze_status(self.gagent.FSFREEZE_STATUS_THAWED)
else:
Copy link
Member

Choose a reason for hiding this comment

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

this part will not be execute, because monitor.cmd() always return c,md output .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we have also discover this problem. monitor.cmd() can properly deal with cmd return. removed else part.

if vm.monitor.cmd("system_reset"):
self.gagent.verify_fsfreeze_status(self.gagent.FSFREEZE_STATUS_THAWED)

@vivianQizhu
Copy link
Contributor

Why two commits?

@suqinhuang
Copy link
Contributor

the configure file is a little long, do we need to seperate it?

@xiangchunfu
Copy link
Contributor Author

@suqinhuang It is currently acceptable. As all test cases are very similar for this feature. the confiure file is more clear. I will consider to seperate when a large number of test case are added.

def gagent_install(self, params, vm, *args):
if args and isinstance(args, tuple):
gagent_install_cmd = args[0]
else:
raise error.TestError("Missing config 'gagent_install_cmd'")
raise test.error("Missing config 'gagent_install_cmd'")
Copy link
Contributor

Choose a reason for hiding this comment

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

do not need 'raise', remember to modify all in this file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

modified the whole file

@@ -137,14 +134,13 @@ def gagent_start(self, params, vm, *args):
raise error.TestFail("Could not start qemu-guest-agent in VM"
" '%s', detail: '%s'" % (vm.name, o))

@error.context_aware
def gagent_create(self, params, vm, *args):
if self.gagent:
return self.gagent

error.context("Create a QemuAgent object.", logging.info)
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 remove "from autotest.client.shared import error", can this file still be execute successfully?
error.context should not be run correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

use logging.info instead of error.context

"""
vm = env.get_vm(params["main_vm"])
if not vm.is_alive():
test.skip("VM died,can't continue the test loop.")
Copy link
Contributor

Choose a reason for hiding this comment

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

test.cancel should be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

use test.cancel instead of test.skip

@@ -582,7 +562,7 @@ def get_allocation_bitmap():
bitmap = get_allocation_bitmap()
if bitmap:
logging.debug("block allocation bitmap: %s" % bitmap)
raise error.TestError("block allocation bitmap"
raise test.error("block allocation bitmap"
" not empty before test.")
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is failed checked by "inspekt style".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I resoved inspekt style's problem already

@@ -86,6 +86,9 @@
no Windows
gagent_check_type = fsfreeze
gagent_fs_test_cmd = "rm -f /tmp/foo; echo foo > /tmp/foo"
- check_reset_reboot_shutdown_fsfreeze:
no Windows
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, this case supports windows guest. remove 'no windows' line

if not vm.is_alive():
test.skip("VM died,can't continue the test loop.")
self.gagent.fsfreeze()
self.gagent.verify_fsfreeze_status(self.gagent.FSFREEZE_STATUS_FROZEN)
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a status verify command in fsfreeze() function 'self.verify_fsfreeze_status(self.FSFREEZE_STATUS_FROZEN)'.

Copy link
Contributor

Choose a reason for hiding this comment

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

So I think this line can be deleted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are right, fsfreeze() function verified guest file system status after fsfreeze command. I haven't to verify it again. deleted this line.

self.gagent.verify_fsfreeze_status(self.gagent.FSFREEZE_STATUS_FROZEN)

if vm.monitor.cmd("system_reset"):
self.gagent.verify_fsfreeze_status(self.gagent.FSFREEZE_STATUS_THAWED)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to check 'vm.is_alive()' again?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

all guest agent command need agent service response in guest. if send agent command to vm but vm is dead. I am afraid that agent command will get error message.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for explaining.

@xiangchunfu xiangchunfu force-pushed the qemu_guest_agent branch 2 times, most recently from ab288dd to 73fc57d Compare August 16, 2017 08:11
@sssst315
Copy link
Contributor

sssst315 commented Aug 16, 2017

smp_4.2048m.repeat1.pre_test.Host_RHEL.m7.u4.qcow2.virtio_blk.up.virtio_net.RHEL.7.4.x86_64.myprovider.unattended_install.cdrom.extra_cdrom_ks.default_install.aio_native: PASS (1699.28 s)

smp_4.2048m.repeat1.pre_test.Host_RHEL.m7.u4.qcow2.virtio_blk.up.virtio_net.RHEL.7.4.x86_64.myprovider.rh_kernel_update: PASS (957.87 s)

smp_4.2048m.repeat1.run_test.Host_RHEL.m7.u4.qcow2.virtio_blk.up.virtio_net.RHEL.7.4.x86_64.myprovider.qemu_guest_agent.virtio_serial.check_reset_reboot_shutdown_fsfreeze: PASS (426.97 s)

Acked-by: Sitong Liu siliu@redhat.com

@xiangchunfu
Copy link
Contributor Author

Thanks Sitong,

(1/1) smp_2.512m.repeat1.run_test.Host_RHEL.m7.u4.qcow2.virtio_blk.up.virtio_net.RHEL.7.4.x86_64.myprovider.qemu_guest_agent.virtio_serial.check_reset_reboot_shutdown_fsfreeze: PASS

session = self._get_session(params, vm)
s, o = session.cmd_status_output(gagent_install_cmd)
if s:
raise error.TestFail("Could not install qemu-guest-agent package"
" in VM '%s', detail: '%s'" % (vm.name, o))
error.TestFail("Could not install qemu-guest-agent package in VM '%s'",
Copy link
Contributor

Choose a reason for hiding this comment

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

test.fail()


if not gagent_start_cmd:
return

error.context("Try to start 'qemu-guest-agent'.", logging.info)
logging.info("Try to start 'qemu-guest-agent'.")
session = self._get_session(params, vm)
s, o = self._session_cmd_close(session, gagent_start_cmd)
if s and "already been started" not in o:
raise error.TestFail("Could not start qemu-guest-agent in VM"
Copy link
Contributor

Choose a reason for hiding this comment

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

test.fail(), please check again to make sure all error module replaced.

rebooted = self.__gagent_check_serial_output(pattern)
if not rebooted:
raise error.TestFail("Could not reboot VM via guest agent")
error.context("Try to re-login to guest after reboot")
logging.info("Try to re-login to guest after reboot")
try:
session = self._get_session(self.params, None)
session.close()
except Exception, detail:
raise error.TestFail("Could not login to guest,"
Copy link
Contributor

Choose a reason for hiding this comment

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

test.fail()

@@ -386,7 +366,6 @@ def gagent_check_set_vcpus(self, test, params, env):
if vcpus_info[vcpus_num - 1]["online"] is not False:
raise error.TestFail("the vcpu status is not changed as expected")
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

% int(guest_time), logging.info)
test.error("can't get the guest time for contrast")
logging.info("the time get inside guest by shell cmd is '%d' "
% int(guest_time))
delta = abs(int(guest_time) - nanoseconds_time / 1000000000)
if delta > 3:
raise error.TestFail("the time get by guest agent is not the same "
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

error.context("the time after being moved back into past is '%d' "
% int(guest_time_after), logging.info)
logging.info("the time after being moved back into past is '%d' "
% int(guest_time_after))
delta = abs(int(guest_time_after) - target_time / 1000000000)
if delta > 3:
raise error.TestFail("the time set for guest is not the same "
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

@xiangchunfu
Copy link
Contributor Author

@lijinlijin For debug log. As system_reset command is success. and check guest's status is correct. don't need wait guest boot up fully. It is normal debug log.

@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 (93.19 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 (74.06 s)

test.fail("agent shutdown command shouldn't succeed for freeze FS")
except guest_agent.VAgentCmdError as detail:
if not re.search('guest-shutdown has been disabled', str(detail)):
test.fail("qemu monitor return 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.

show "detail" is better:
test.fail(detail)

@xiangchunfu xiangchunfu force-pushed the qemu_guest_agent branch 2 times, most recently from 6814abd to 8ddea06 Compare March 28, 2018 03:18
gagent.verify_fsfreeze_status(gagent.FSFREEZE_STATUS_FROZEN)

if not vm.monitor.cmd("system_reset"):
time.sleep(120)
Copy link
Contributor

Choose a reason for hiding this comment

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

why need to sleep 120s ?

@xiangchunfu xiangchunfu force-pushed the qemu_guest_agent branch 2 times, most recently from a29f154 to 91c5fb8 Compare March 29, 2018 06:42
@lijinlijin
Copy link
Contributor

Acked-by: Li Jin lijin@redhat.com

@miyachen
Copy link

@luckyh @hereischen Hi Hanxu, Haotong, please give suggestion to this pr since it has been pending for more than 100 days, Thanks.

@hereischen
Copy link
Contributor

This patch depends on avocado-framework/avocado-vt#1391.

@xiangchunfu
Copy link
Contributor Author

@hereischen I have updated avocado-vt patch 1391. and re-tested this 2 patches.

(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 (120.34 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 (117.38 s)

test.fail("agent shutdown command shouldn't succeed for freeze FS")
except guest_agent.VAgentCmdError as detail:
if not re.search('guest-shutdown has been disabled', str(detail)):
test.fail(str(detail))
Copy link
Contributor

Choose a reason for hiding this comment

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

Per avocado-framework/avocado-vt#1391 You dropped return True, so should not judge it with if gagent.shutdow(). Here should be:

try:
    gagent.shutdown(mode)
except guest_agent.VAgentCmdError as detail:
    if not re.search('guest-shutdown has been disabled', str(detail)):
        test.fail(str(detail))
else:
    test.fail("agent shutdown command shouldn't succeed for freeze FS")

@xiangchunfu
Copy link
Contributor Author

@vivianQizhu updated

(1/4) Host_RHEL.m7.u6.qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.7.6.x86_64.io-github-autotest-qemu.unattended_install.cdrom.extra_cdrom_ks.default_install.aio_threads: PASS (2186.04 s)
(2/4) Host_RHEL.m7.u6.qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.7.6.x86_64.io-github-autotest-qemu.rh_kernel_update: PASS (377.02 s)
(3/4) 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 (81.74 s)
(4/4) 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 (82.81 s)

@vivianQizhu
Copy link
Contributor

@luckyh Would you help review it again? Thanks.

@xiangchunfu xiangchunfu force-pushed the qemu_guest_agent branch 8 times, most recently from 9a3c396 to f8fbf3d Compare November 2, 2018 05:52
1.frozen guest FS
2.send shutdown agent cmd to guest
3.send reboot agent cmd to guest
4.send fsthaw cmd to guest

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

updated, and This is the latest testing result.

(1/2) Host_RHEL.m8.u0.qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.8.0.x86_64.io-github-autotest-qemu.qemu_guest_agent.virtio_serial.check_reboot_shutdown_fsfreeze: PASS (56.43 s)
(2/2) Host_RHEL.m8.u0.qcow2.virtio_scsi.up.virtio_net.Guest.RHEL.8.0.x86_64.io-github-autotest-qemu.qemu_guest_agent.isa_serial.check_reboot_shutdown_fsfreeze: PASS (54.22 s)

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
Copy link
Contributor

luckyh commented Nov 2, 2018

Thanks all.

@luckyh luckyh merged commit f3db11c into autotest:master Nov 2, 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