Vinzenz Feenstra has uploaded a new change for review.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Create GuestAgent instance in __init__ and connect later
This is not only a cosmetic improvement. There are cases where we are trying to call methods of the GuestAgent before the instance was created. To avoid these race conditions we're creating the instance of the guest agent already in the __init__ phase.
Change-Id: I82f7397b01bff48a3c635eee9912cc67cf722b13 Signed-off-by: Vinzenz Feenstra vfeenstr@redhat.com --- M vdsm/guestIF.py M vdsm/vm.py 2 files changed, 7 insertions(+), 6 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/42/26142/1
diff --git a/vdsm/guestIF.py b/vdsm/guestIF.py index 1f8d18d..1eaa42b 100644 --- a/vdsm/guestIF.py +++ b/vdsm/guestIF.py @@ -108,7 +108,7 @@ MAX_MESSAGE_SIZE = 2 ** 20 # 1 MiB for now
def __init__(self, socketName, channelListener, log, user='Unknown', - ips='', connect=True): + ips=''): self.effectiveApiVersion = _IMPLICIT_API_VERSION_ZERO self.log = log self._socketName = socketName @@ -128,7 +128,8 @@ self._agentTimestamp = 0 self._channelListener = channelListener self._messageState = MessageState.NORMAL - if connect: + + def connect(self): try: self._prepare_socket() except: diff --git a/vdsm/vm.py b/vdsm/vm.py index 1390c6e..7fbf07a 100644 --- a/vdsm/vm.py +++ b/vdsm/vm.py @@ -2008,7 +2008,6 @@ self._volPrepareLock = threading.Lock() self._initTimePauseCode = None self._initTimeRTC = long(self.conf.get('timeOffset', 0)) - self.guestAgent = None self._guestEvent = 'Powering up' self._guestEventTime = 0 self._vmStats = None @@ -2028,6 +2027,8 @@ self.conf['vmName'] = 'n%s' % self.id self._guestSocketFile = self._makeChannelPath(_VMCHANNEL_DEVICE_NAME) self._qemuguestSocketFile = self._makeChannelPath(_QEMU_GA_DEVICE_NAME) + self.guestAgent = guestIF.GuestAgent( + self._guestSocketFile, self.cif.channelListener, self.log) self._lastXMLDesc = '<domain><uuid>%s</uuid></domain>' % self.id self._devXmlHash = '0' self._released = False @@ -3128,9 +3129,8 @@ # VmStatsThread may use block devices info from libvirt. # So, run it after you have this info self._initVmStats() - self.guestAgent = guestIF.GuestAgent( - self._guestSocketFile, self.cif.channelListener, self.log, - connect=utils.tobool(self.conf.get('vmchannel', 'true'))) + if utils.tobool(self.conf.get('vmchannel', 'true')): + self.guestAgent.connect()
self._guestCpuRunning = (self._dom.info()[0] == libvirt.VIR_DOMAIN_RUNNING)
oVirt Jenkins CI Server has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 1:
Build Failed
http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit_el/6879/ : FAILURE
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/7669/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit/7779/ : FAILURE
oVirt Jenkins CI Server has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 2:
Build Failed
http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit_el/6880/ : FAILURE
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/7670/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit/7780/ : FAILURE
oVirt Jenkins CI Server has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 3:
Build Failed
http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit_el/6881/ : FAILURE
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/7671/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit/7781/ : FAILURE
oVirt Jenkins CI Server has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 4:
Build Successful
http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit_el/6883/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/7673/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit/7783/ : SUCCESS
Francesco Romani has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 1:
(1 comment)
http://gerrit.ovirt.org/#/c/26142/1//COMMIT_MSG Commit Message:
Line 8: Line 9: This is not only a cosmetic improvement. There are cases where we Line 10: are trying to call methods of the GuestAgent before the instance was Line 11: created. To avoid these race conditions we're creating the instance of Line 12: the guest agent already in the __init__ phase. Makes sense to me and looks like an improvement, but, not being so much familiar with this code, I wonder: what happens if we try to call methods to a GuestAgent instance not yet connected? There can be nasty consequences? Line 13: Line 14: Change-Id: I82f7397b01bff48a3c635eee9912cc67cf722b13
Vinzenz Feenstra has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 1:
(1 comment)
http://gerrit.ovirt.org/#/c/26142/1//COMMIT_MSG Commit Message:
Line 8: Line 9: This is not only a cosmetic improvement. There are cases where we Line 10: are trying to call methods of the GuestAgent before the instance was Line 11: created. To avoid these race conditions we're creating the instance of Line 12: the guest agent already in the __init__ phase.
Makes sense to me and looks like an improvement, but, not being so much fam
Well most of them swallow everything at the moment. And we can make it swallow even more of those things if necessary. Not connected is not such an uncommon thing, unfortunately. At least nowadays Line 13: Line 14: Change-Id: I82f7397b01bff48a3c635eee9912cc67cf722b13
oVirt Jenkins CI Server has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 3:
Build Failed
http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit_el/6881/ : FAILURE
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/7671/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit/7788/ : FAILURE
Antoni Segura Puimedon has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 4: Code-Review+1
oVirt Jenkins CI Server has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 5:
Build Successful
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/7954/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit_el/7164/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_unit_tests_gerrit/8066/ : SUCCESS
Francesco Romani has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 5:
(1 comment)
looks ok except for a minor naming note.
http://gerrit.ovirt.org/#/c/26142/5/tests/vmTests.py File tests/vmTests.py:
Line 47: ( Minor naming note: This is most likely a Fake, not a Mock (see http://martinfowler.com/articles/mocksArentStubs.html)
Dan Kenigsberg has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 5: Code-Review-1
(2 comments)
Let's not leave tautologies behind.
http://gerrit.ovirt.org/#/c/26142/5/vdsm/virt/vm.py File vdsm/virt/vm.py:
Line 2038: return Line 2039: with self._confLock: Line 2040: toSave = deepcopy(self.status()) Line 2041: toSave['startTime'] = self._startTime Line 2042: if self.lastStatus != vmstatus.DOWN and \ no need to check for self.guestAgent now - it is never None. Line 2043: self._vmStats and self.guestAgent: Line 2044: toSave['username'] = self.guestAgent.guestInfo['username'] Line 2045: toSave['guestIPs'] = self.guestAgent.guestInfo['guestIPs'] Line 2046: toSave['guestFQDN'] = self.guestAgent.guestInfo['guestFQDN']
Line 2411: GUEST_WAIT_TIMEOUT = 60 Line 2412: now = time.time() Line 2413: if now - self._guestEventTime < 5 * GUEST_WAIT_TIMEOUT and \ Line 2414: self._guestEvent == vmstatus.POWERING_DOWN: Line 2415: return self._guestEvent and here Line 2416: if self.guestAgent and self.guestAgent.isResponsive() and \ Line 2417: self.guestAgent.getStatus(): Line 2418: return self.guestAgent.getStatus() Line 2419: if now - self._guestEventTime < GUEST_WAIT_TIMEOUT:
Vinzenz Feenstra has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 5:
(3 comments)
http://gerrit.ovirt.org/#/c/26142/5/tests/vmTests.py File tests/vmTests.py:
Line 47: (
Minor naming note: This is most likely a Fake, not a Mock (see http://marti
Done
http://gerrit.ovirt.org/#/c/26142/5/vdsm/virt/vm.py File vdsm/virt/vm.py:
Line 2038: return Line 2039: with self._confLock: Line 2040: toSave = deepcopy(self.status()) Line 2041: toSave['startTime'] = self._startTime Line 2042: if self.lastStatus != vmstatus.DOWN and \
no need to check for self.guestAgent now - it is never None.
Done Line 2043: self._vmStats and self.guestAgent: Line 2044: toSave['username'] = self.guestAgent.guestInfo['username'] Line 2045: toSave['guestIPs'] = self.guestAgent.guestInfo['guestIPs'] Line 2046: toSave['guestFQDN'] = self.guestAgent.guestInfo['guestFQDN']
Line 2411: GUEST_WAIT_TIMEOUT = 60 Line 2412: now = time.time() Line 2413: if now - self._guestEventTime < 5 * GUEST_WAIT_TIMEOUT and \ Line 2414: self._guestEvent == vmstatus.POWERING_DOWN: Line 2415: return self._guestEvent
and here
Done Line 2416: if self.guestAgent and self.guestAgent.isResponsive() and \ Line 2417: self.guestAgent.getStatus(): Line 2418: return self.guestAgent.getStatus() Line 2419: if now - self._guestEventTime < GUEST_WAIT_TIMEOUT:
oVirt Jenkins CI Server has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 6:
Build Successful
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/8787/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit/8923/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit_el/7997/ : SUCCESS
oVirt Jenkins CI Server has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 7:
Build Successful
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/8788/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit/8924/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit_el/7998/ : SUCCESS
Antoni Segura Puimedon has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 7: Code-Review+1
Michal Skrivanek has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 7: Code-Review+1
may make sense to rename stop() to disconnect(), but it's fine as it is too...
Francesco Romani has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 7: Code-Review+1
Dan Kenigsberg has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 7:
(2 comments)
http://gerrit.ovirt.org/#/c/26142/7/vdsm/virt/guestagent.py File vdsm/virt/guestagent.py:
Line 136: self._messageState = MessageState.NORMAL Line 137: Line 138: def connect(self): Line 139: try: Line 140: self._prepare_socket() this patch is a clear improvement; however, it would be nicer if the new connect() method did not swallow this failure. The caller of connect() should decided whether it is fine with the fact that connect() did not succeed. Line 141: except: Line 142: self.log.error("Failed to prepare vmchannel", exc_info=True) Line 143: else: Line 144: self._channelListener.register(
http://gerrit.ovirt.org/#/c/26142/7/vdsm/virt/vm.py File vdsm/virt/vm.py:
Line 4297: # Terminate the VM's creation thread. Line 4298: self._incomingMigrationFinished.set() Line 4299: if self._vmStats: Line 4300: self._vmStats.stop() Line 4301: self.guestAgent.stop() I did not check - does this is bound to succeed even on non-connected guestAgent? Line 4302: if self._dom: Line 4303: try: Line 4304: self._dom.destroyFlags( Line 4305: libvirt.VIR_DOMAIN_DESTROY_GRACEFUL)
Itamar Heim has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 7:
ping
Michal Skrivanek has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 7:
hit a bug with suspend recently, this should better get in
oVirt Jenkins CI Server has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 8: Code-Review-1 Verified-1
Build Failed
http://jenkins.ovirt.org/job/vdsm_master_virt_functional_tests_gerrit/1439/ : There was an infra issue, please contact infra@ovirt.org
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit_el/10804/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/11746/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/11589/ : UNSTABLE
Vinzenz Feenstra has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 7:
(2 comments)
http://gerrit.ovirt.org/#/c/26142/7/vdsm/virt/guestagent.py File vdsm/virt/guestagent.py:
Line 136: self._messageState = MessageState.NORMAL Line 137: Line 138: def connect(self): Line 139: try: Line 140: self._prepare_socket()
this patch is a clear improvement; however, it would be nicer if the new co
ok, done. But not happy with the fact that i have there a 'except Exception' in vm.py Line 141: except: Line 142: self.log.error("Failed to prepare vmchannel", exc_info=True) Line 143: else: Line 144: self._channelListener.register(
http://gerrit.ovirt.org/#/c/26142/7/vdsm/virt/vm.py File vdsm/virt/vm.py:
Line 4297: # Terminate the VM's creation thread. Line 4298: self._incomingMigrationFinished.set() Line 4299: if self._vmStats: Line 4300: self._vmStats.stop() Line 4301: self.guestAgent.stop()
I did not check - does this is bound to succeed even on non-connected guest
Well errno.EBADF is caught and handled gracefully However it is possible that there can be other exceptions which are re-raised or not caught Which would be no different than it is today for that matter, except that we would avoid here the self.guestAgent == None cases Line 4302: if self._dom: Line 4303: try: Line 4304: self._dom.destroyFlags( Line 4305: libvirt.VIR_DOMAIN_DESTROY_GRACEFUL)
oVirt Jenkins CI Server has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 9: Code-Review-1 Verified-1
Build Failed
http://jenkins.ovirt.org/job/vdsm_master_virt_functional_tests_gerrit/1440/ : There was an infra issue, please contact infra@ovirt.org
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit_el/10806/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/11748/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/11591/ : UNSTABLE
oVirt Jenkins CI Server has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 10: Code-Review-1 Verified-1
Build Failed
http://jenkins.ovirt.org/job/vdsm_master_virt_functional_tests_gerrit/1441/ : There was an infra issue, please contact infra@ovirt.org
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit_el/10812/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/11754/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/11597/ : UNSTABLE
oVirt Jenkins CI Server has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 11:
Build Successful
http://jenkins.ovirt.org/job/vdsm_master_virt_functional_tests_gerrit/1451/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit_el/10825/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/11767/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/11610/ : SUCCESS
Vinzenz Feenstra has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 11: Verified+1
Vinzenz Feenstra has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 11:
Verified by starting/stopping/recovering and migrating in and out Virtual Machines on a el6 host.
No issues occurred. Guest agents are still happily reporting.
Francesco Romani has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 11: Code-Review+1
I'm not enterely sure about the exception handling in GuestAgent.connect(), but I see the behaviour seems identical to the old code in face of exceptions, and I don't have suggestions about improvements. Then, given the other clear benefits of this patch, ack from me.
Dan Kenigsberg has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 11: Code-Review-1
(1 comment)
I really want this cleanup patch in - but please simplify it a bit more.
http://gerrit.ovirt.org/#/c/26142/11/vdsm/virt/guestagent.py File vdsm/virt/guestagent.py:
Line 138: def connect(self): Line 139: try: Line 140: self._prepare_socket() Line 141: except: Line 142: self.log.error("Failed to prepare vmchannel", exc_info=True) There is no need to log the backtrace twice. Since we re-raise, the caller of connect() would log it. As far as I see, there is no need for exception handling in this level. Line 143: raise Line 144: else: Line 145: self._channelListener.register( Line 146: self._create,
Vinzenz Feenstra has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 11:
(1 comment)
http://gerrit.ovirt.org/#/c/26142/11/vdsm/virt/guestagent.py File vdsm/virt/guestagent.py:
Line 138: def connect(self): Line 139: try: Line 140: self._prepare_socket() Line 141: except: Line 142: self.log.error("Failed to prepare vmchannel", exc_info=True)
There is no need to log the backtrace twice. Since we re-raise, the caller
ok, I was kind of thinking about this myself, but I did not want to add too much changes in this patch, but since you seem to prefer it. I will remove the error handling here now. Line 143: raise Line 144: else: Line 145: self._channelListener.register( Line 146: self._create,
Dan Kenigsberg has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 12: Code-Review+2
Vinzenz Feenstra has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 12: Verified+1
Verified by starting/stopping/recovering and migrating in and out Virtual Machines on a el6 host.
Dan Kenigsberg has submitted this change and it was merged.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Create GuestAgent instance in __init__ and connect later
This is not only a cosmetic improvement. There are cases where we are trying to call methods of the GuestAgent before the instance was created. To avoid these race conditions we're creating the instance of the guest agent already in the __init__ phase.
Change-Id: I82f7397b01bff48a3c635eee9912cc67cf722b13 Signed-off-by: Vinzenz Feenstra vfeenstr@redhat.com Reviewed-on: http://gerrit.ovirt.org/26142 Reviewed-by: Dan Kenigsberg danken@redhat.com --- M tests/guestagentTests.py M tests/vmTests.py M vdsm/virt/guestagent.py M vdsm/virt/vm.py M vdsm/virt/vmpowerdown.py 5 files changed, 37 insertions(+), 37 deletions(-)
Approvals: Vinzenz Feenstra: Verified Dan Kenigsberg: Looks good to me, approved
oVirt Jenkins CI Server has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 12:
Build Successful
http://jenkins.ovirt.org/job/vdsm_master_virt_functional_tests_gerrit/1481/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit_el/10929/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/11871/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/11714/ : SUCCESS
oVirt Jenkins CI Server has posted comments on this change.
Change subject: Create GuestAgent instance in __init__ and connect later ......................................................................
Patch Set 13:
Build Successful
http://jenkins.ovirt.org/job/vdsm_master_verify-error-codes_merged/5706/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_create-rpms_merged_test_debug/71/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_merged/3864/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_create-rpms_merged/1729/ : SUCCESS
vdsm-patches@lists.fedorahosted.org