Hello Bing Bu Cao,
I'd like you to do a code review. Please visit
to review the following change.
Change subject: Add shutdown based on qemu-ga(qemu guest agent) in vdsm ......................................................................
Add shutdown based on qemu-ga(qemu guest agent) in vdsm
As previously what we agreed, the agent-assisted shutdown and fsfreeze would be handled by the qemu guest agent while oVirt-specific functionality such as Single-Sign-On would continue to be managed by the ovirt guest agent.
http://www.ovirt.org/wiki/Guest_agent_proposals
This patch changes the shutdown verb, add an shutdown approach by qemu guest agent
Change-Id: I86977c1b717d63de21ba4818c6b66e43976d65de Signed-off-by: ShaoHe Feng shaohef@linux.vnet.ibm.com Signed-off-by: BingBu Cao mars@linux.vnet.ibm.com --- M vdsm/libvirtvm.py M vdsm/vm.py 2 files changed, 84 insertions(+), 28 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/55/9655/1
diff --git a/vdsm/libvirtvm.py b/vdsm/libvirtvm.py index f20968f..f1d82d7 100644 --- a/vdsm/libvirtvm.py +++ b/vdsm/libvirtvm.py @@ -1222,6 +1222,8 @@ self._releaseLock = threading.Lock() self.saveState()
+ self.shutdownMethodUpdate() + def _buildLease(self, domainID, volumeID, leasePath, leaseOffset): """ Add a single SANLock lease. @@ -2326,9 +2328,45 @@ physical, alloc) self.extendDriveVolume(d)
+ def shutdownMethodUpdate(self): + self._shutdownMethods = [] + self._shutdownMethods.append({'qemugaShutdown': + self.qemugaShutdown}) + self._shutdownMethods.append({'guestAgentShutdown': + self.guestAgentShutdown}) + self._shutdownMethods.append({'acpiShutdown': + self.acpiShutdown}) + def _acpiShutdown(self): self._dom.shutdownFlags(libvirt.VIR_DOMAIN_SHUTDOWN_ACPI_POWER_BTN)
+ def acpiShutdown(self, now, *args): + if utils.tobool(self.conf.get('acpiEnable', 'true')): + self.log.debug("acpiShutdown vm") + self._guestEventTime = now + self._guestEvent = 'Powering down' + self._acpiShutdown() + else: + return None + + return {'status': {'code': doneCode['code'], + 'message': 'Machine shut down'}} + + def _qemugaShutdown(self): + self._dom.shutdownFlags(libvirt.VIR_DOMAIN_SHUTDOWN_GUEST_AGENT) + + def qemugaShutdown(self, now, *args): + if utils.tobool(self.conf.get('qgaEnable', 'true')): + self.log.debug("qemugaShutdown vm") + self._guestEventTime = now + self._guestEvent = 'Powering down' + self._qemugaShutdown() + else: + return None + + return {'status': {'code': doneCode['code'], + 'message': 'Machine shut down'}} + def _getPid(self): pid = '0' try: diff --git a/vdsm/vm.py b/vdsm/vm.py index cb0e552..bf6ee8b 100644 --- a/vdsm/vm.py +++ b/vdsm/vm.py @@ -364,6 +364,8 @@ CONTROLLER_DEVICES: [], GENERAL_DEVICES: [], BALLOON_DEVICES: [], REDIR_DEVICES: [], WATCHDOG_DEVICES: []} + self._shutdownMethods = [] + self.shutdownMethodUpdate()
def _get_lastStatus(self): PAUSED_STATES = ('Powering down', 'RebootInProgress', 'Up') @@ -970,35 +972,51 @@ if not guestCpuLocked: self._guestCpuLock.release()
+ def shutdownMethodUpdate(self): + self._shutdownMethods = [] + self._shutdownMethods.append({'guestAgentShutdown': + self._guestAgentShutdown}) + def shutdown(self, timeout, message): - try: - now = time.time() - if self.lastStatus == 'Down': - return - if self.guestAgent and self.guestAgent.isResponsive(): - self._guestEventTime = now - self._guestEvent = 'Powering down' - self.log.debug('guestAgent shutdown called') - self.guestAgent.desktopShutdown(timeout, message) - agent_timeout = (int(timeout) + - config.getint('vars', 'sys_shutdown_timeout')) - timer = threading.Timer(agent_timeout, self._timedShutdown) - timer.start() - elif utils.tobool(self.conf.get('acpiEnable', 'true')): - self._guestEventTime = now - self._guestEvent = 'Powering down' - self._acpiShutdown() - # No tools, no ACPI - else: - return { - 'status': { - 'code': errCode['exist']['status']['code'], - 'message': 'VM without ACPI or active SolidICE tools. ' - 'Try Forced Shutdown.'}} - except: - self.log.error("Shutdown failed", exc_info=True) - return {'status': {'code': errCode['exist']['status']['code'], - 'message': 'Failed to shutdown VM. Try Forced Shutdown.'}} + if self.lastStatus == 'Down': + return + now = time.time() + + status = None + for method, func in self._shutdownMethods: + try: + status = func(now, timeout, message) + except: + self.log.error("%s failed", method, exc_info=True) + status = {'status': + {'code': errCode['exist']['status']['code'], + 'message': 'Failed to shutdown VM. ' + 'Try Forced Shutdown.'}} + # if one shutdown method failed, will try another method + # the loop will stop once a shutdown method is successful + if doneCode['code'] == status['status']['code']: + return status + if not status: + return {'status': + {'code': errCode['exist']['status']['code'], + 'message': 'VM without ACPI or active SolidICE tools. ' + 'Try Forced Shutdown.'}} + + return status + + def guestAgentShutdown(self, now, timeout, message): + if self.guestAgent and self.guestAgent.isResponsive(): + self._guestEventTime = time.time() + self._guestEvent = 'Powering down' + self.log.debug('guestAgent shutdown called') + self.guestAgent.desktopShutdown(timeout, message) + agent_timeout = (int(timeout) + + config.getint('vars', 'sys_shutdown_timeout')) + timer = threading.Timer(agent_timeout, self._timedShutdown) + timer.start() + else: + return None + return {'status': {'code': doneCode['code'], 'message': 'Machine shut down'}}
-- To view, visit http://gerrit.ovirt.org/9655 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange Gerrit-Change-Id: I86977c1b717d63de21ba4818c6b66e43976d65de Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: ShaoHe Feng shaohef@linux.vnet.ibm.com Gerrit-Reviewer: Bing Bu Cao mars@linux.vnet.ibm.com
Yaniv Kaul has posted comments on this change.
Change subject: Add shutdown based on qemu-ga(qemu guest agent) in vdsm ......................................................................
Patch Set 2: (1 inline comment)
.................................................... File vdsm/vm.py Line 998: return status Line 999: if not status: Line 1000: return {'status': Line 1001: {'code': errCode['exist']['status']['code'], Line 1002: 'message': 'VM without ACPI or active SolidICE tools. ' SolidICE -> oVirt Line 1003: 'Try Forced Shutdown.'}} Line 1004: Line 1005: return status Line 1006:
-- To view, visit http://gerrit.ovirt.org/9655 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: I86977c1b717d63de21ba4818c6b66e43976d65de Gerrit-PatchSet: 2 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: ShaoHe Feng shaohef@linux.vnet.ibm.com Gerrit-Reviewer: Barak Azulay bazulay@redhat.com Gerrit-Reviewer: Bing Bu Cao mars@linux.vnet.ibm.com Gerrit-Reviewer: Dan Kenigsberg danken@redhat.com Gerrit-Reviewer: Michal Skrivanek michal.skrivanek@redhat.com Gerrit-Reviewer: ShaoHe Feng shaohef@linux.vnet.ibm.com Gerrit-Reviewer: Vinzenz Feenstra vfeenstr@redhat.com Gerrit-Reviewer: Yaniv Kaul ykaul@redhat.com Gerrit-Reviewer: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com
oVirt Jenkins CI Server has posted comments on this change.
Change subject: Add shutdown based on qemu-ga(qemu guest agent) in vdsm ......................................................................
Patch Set 3:
Build Started http://jenkins.ovirt.org/job/vdsm_pep8_gerrit/221/ (1/2)
-- To view, visit http://gerrit.ovirt.org/9655 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: I86977c1b717d63de21ba4818c6b66e43976d65de Gerrit-PatchSet: 3 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: ShaoHe Feng shaohef@linux.vnet.ibm.com Gerrit-Reviewer: Barak Azulay bazulay@redhat.com Gerrit-Reviewer: Bing Bu Cao mars@linux.vnet.ibm.com Gerrit-Reviewer: Dan Kenigsberg danken@redhat.com Gerrit-Reviewer: Michal Skrivanek michal.skrivanek@redhat.com Gerrit-Reviewer: ShaoHe Feng shaohef@linux.vnet.ibm.com Gerrit-Reviewer: Vinzenz Feenstra vfeenstr@redhat.com Gerrit-Reviewer: Yaniv Kaul ykaul@redhat.com Gerrit-Reviewer: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: oVirt Jenkins CI Server
oVirt Jenkins CI Server has posted comments on this change.
Change subject: Add shutdown based on qemu-ga(qemu guest agent) in vdsm ......................................................................
Patch Set 3:
Build Started http://jenkins.ovirt.org/job/vdsm_unit_tests_manual_gerrit/255/ (2/2)
-- To view, visit http://gerrit.ovirt.org/9655 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: I86977c1b717d63de21ba4818c6b66e43976d65de Gerrit-PatchSet: 3 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: ShaoHe Feng shaohef@linux.vnet.ibm.com Gerrit-Reviewer: Barak Azulay bazulay@redhat.com Gerrit-Reviewer: Bing Bu Cao mars@linux.vnet.ibm.com Gerrit-Reviewer: Dan Kenigsberg danken@redhat.com Gerrit-Reviewer: Michal Skrivanek michal.skrivanek@redhat.com Gerrit-Reviewer: ShaoHe Feng shaohef@linux.vnet.ibm.com Gerrit-Reviewer: Vinzenz Feenstra vfeenstr@redhat.com Gerrit-Reviewer: Yaniv Kaul ykaul@redhat.com Gerrit-Reviewer: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: oVirt Jenkins CI Server
oVirt Jenkins CI Server has posted comments on this change.
Change subject: Add shutdown based on qemu-ga(qemu guest agent) in vdsm ......................................................................
Patch Set 3:
Build Successful
http://jenkins.ovirt.org/job/vdsm_pep8_gerrit/221/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_unit_tests_manual_gerrit/255/ : SUCCESS
-- To view, visit http://gerrit.ovirt.org/9655 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: I86977c1b717d63de21ba4818c6b66e43976d65de Gerrit-PatchSet: 3 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: ShaoHe Feng shaohef@linux.vnet.ibm.com Gerrit-Reviewer: Barak Azulay bazulay@redhat.com Gerrit-Reviewer: Bing Bu Cao mars@linux.vnet.ibm.com Gerrit-Reviewer: Dan Kenigsberg danken@redhat.com Gerrit-Reviewer: Michal Skrivanek michal.skrivanek@redhat.com Gerrit-Reviewer: ShaoHe Feng shaohef@linux.vnet.ibm.com Gerrit-Reviewer: Vinzenz Feenstra vfeenstr@redhat.com Gerrit-Reviewer: Yaniv Kaul ykaul@redhat.com Gerrit-Reviewer: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: oVirt Jenkins CI Server
Vinzenz Feenstra has posted comments on this change.
Change subject: Add shutdown based on qemu-ga(qemu guest agent) in vdsm ......................................................................
Patch Set 3: I would prefer that you didn't submit this
This patch is duplicating too much code which could be unified, it should respect the behaviour which was originally there and it is scattered over two classes for no reason.
Please unify the shutdown methods and put them in one place, and there's no obvious reason for having them split over two classes like it is done now.
The guest agent shutdown, if it is QEMU GA or oVirt GA should both use the timed shutdown to be able to fall back on ACPI shutdown if the GA in question is not performing the shutdown, or fails to do so.
-- To view, visit http://gerrit.ovirt.org/9655 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: I86977c1b717d63de21ba4818c6b66e43976d65de Gerrit-PatchSet: 3 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: ShaoHe Feng shaohef@linux.vnet.ibm.com Gerrit-Reviewer: Barak Azulay bazulay@redhat.com Gerrit-Reviewer: Bing Bu Cao mars@linux.vnet.ibm.com Gerrit-Reviewer: Dan Kenigsberg danken@redhat.com Gerrit-Reviewer: Michal Skrivanek michal.skrivanek@redhat.com Gerrit-Reviewer: ShaoHe Feng shaohef@linux.vnet.ibm.com Gerrit-Reviewer: Vinzenz Feenstra vfeenstr@redhat.com Gerrit-Reviewer: Yaniv Kaul ykaul@redhat.com Gerrit-Reviewer: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: oVirt Jenkins CI Server
ShaoHe Feng has posted comments on this change.
Change subject: Add shutdown based on qemu-ga(qemu guest agent) in vdsm ......................................................................
Patch Set 3:
Vinzenz: you can have a look at this patch: http://gerrit.ovirt.org/#/c/5640/
Gal Hammer's comment: "I think that the code that handle the qga and qga's shutdown should only be in libvirtvm.
I'm not sure if we still support running a vm without libvirt (Dan?) but since the code call libvirt functions it should not be in the vm.Vm class."
so I'm not sure if we will run a vm without libvirt. So I refactor this code as duty chain pattern. It is flexible for new child class. The VM is the parent class and the libvirtvm is children class. in order to run vm with other hyper manager not libvirt which means maybe another child class, some attributions of parent class should be Override.
Barak Azulay's comment: "The logic around the shutdown should be something like this,
if qga.isResponsive(): .... send shutdown to libvirt ... elif guestAgent.isResponsive(): ... do rhev seaquence elif acpi ... .... " so the guestAgent is in VM class, and qga is in libvirtVm class. and acpi should be in both parent class and child class. The children class should override it.
-- To view, visit http://gerrit.ovirt.org/9655 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: I86977c1b717d63de21ba4818c6b66e43976d65de Gerrit-PatchSet: 3 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: ShaoHe Feng shaohef@linux.vnet.ibm.com Gerrit-Reviewer: Barak Azulay bazulay@redhat.com Gerrit-Reviewer: Bing Bu Cao mars@linux.vnet.ibm.com Gerrit-Reviewer: Dan Kenigsberg danken@redhat.com Gerrit-Reviewer: Michal Skrivanek michal.skrivanek@redhat.com Gerrit-Reviewer: ShaoHe Feng shaohef@linux.vnet.ibm.com Gerrit-Reviewer: Vinzenz Feenstra vfeenstr@redhat.com Gerrit-Reviewer: Yaniv Kaul ykaul@redhat.com Gerrit-Reviewer: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: oVirt Jenkins CI Server
Vinzenz Feenstra has posted comments on this change.
Change subject: Add shutdown based on qemu-ga(qemu guest agent) in vdsm ......................................................................
Patch Set 3:
The point is that we're not supporting anything but libvirt, and therefore, there's no real reason to have this split up. Having this separated will make the upcoming need for refactoring the Vm and LibvirtVm classes into one, just harder.
I understand your concern, however you quoted exactly the reasoning by Gal, why it would be best to implement all of this into one class and split it between libvirtvm and vm.
-- To view, visit http://gerrit.ovirt.org/9655 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: I86977c1b717d63de21ba4818c6b66e43976d65de Gerrit-PatchSet: 3 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: ShaoHe Feng shaohef@linux.vnet.ibm.com Gerrit-Reviewer: Barak Azulay bazulay@redhat.com Gerrit-Reviewer: Bing Bu Cao mars@linux.vnet.ibm.com Gerrit-Reviewer: Dan Kenigsberg danken@redhat.com Gerrit-Reviewer: Michal Skrivanek michal.skrivanek@redhat.com Gerrit-Reviewer: ShaoHe Feng shaohef@linux.vnet.ibm.com Gerrit-Reviewer: Vinzenz Feenstra vfeenstr@redhat.com Gerrit-Reviewer: Yaniv Kaul ykaul@redhat.com Gerrit-Reviewer: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: oVirt Jenkins CI Server
Vinzenz Feenstra has posted comments on this change.
Change subject: Add shutdown based on qemu-ga(qemu guest agent) in vdsm ......................................................................
Patch Set 4: Looks good to me, but someone else must approve
-- To view, visit http://gerrit.ovirt.org/9655 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: I86977c1b717d63de21ba4818c6b66e43976d65de Gerrit-PatchSet: 4 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: ShaoHe Feng shaohef@linux.vnet.ibm.com Gerrit-Reviewer: Barak Azulay bazulay@redhat.com Gerrit-Reviewer: Bing Bu Cao mars@linux.vnet.ibm.com Gerrit-Reviewer: Dan Kenigsberg danken@redhat.com Gerrit-Reviewer: Michal Skrivanek michal.skrivanek@redhat.com Gerrit-Reviewer: ShaoHe Feng shaohef@linux.vnet.ibm.com Gerrit-Reviewer: Vinzenz Feenstra vfeenstr@redhat.com Gerrit-Reviewer: Yaniv Kaul ykaul@redhat.com Gerrit-Reviewer: Zhou Zheng Sheng zhshzhou@linux.vnet.ibm.com Gerrit-Reviewer: oVirt Jenkins CI Server
Itamar Heim has posted comments on this change.
Change subject: Add shutdown based on qemu-ga(qemu guest agent) in vdsm ......................................................................
Patch Set 4:
still relevant or should be abandoned?
Zhou Zheng Sheng has posted comments on this change.
Change subject: Add shutdown based on qemu-ga(qemu guest agent) in vdsm ......................................................................
Patch Set 4:
I think it can be abandoned.
Itamar Heim has abandoned this change.
Change subject: Add shutdown based on qemu-ga(qemu guest agent) in vdsm ......................................................................
Abandoned
vdsm-patches@lists.fedorahosted.org