Skip to contentSkip to conversation

iotests: fix wait_until_completed()

PATCH In review Peter Xu 4 participants 5 messages Apr 8, 2018 – Apr 10, 2018

lore
Share & tools
lore

Peter Xu

author
#0 lore raw

PATCH v2 1/1 iotests: fix wait_until_completed()

If there are more than one events, wait_until_completed() might return the 2nd event even if the 1st event is JOB_COMPLETED, since the for loop will continue to run even if completed is set to True.

It never happened before, but it can be triggered when OOB is enabled due to the RESUME startup message. Fix that up.

---
 tests/qemu-iotests/iotests.py | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
tests/qemu-iotests/iotests.py +3 -6
index b5d7945af8..119c8e270a 100644
@@ -470,18 +470,15 @@ class QMPTestCase(unittest.TestCase):
 
     def wait_until_completed(self, drive='drive0', check_offset=True):
         '''Wait for a block job to finish, returning the event'''
-        completed = False
-        while not completed:
+        while True:
             for event in self.vm.get_qmp_events(wait=True):
                 if event['event'] == 'BLOCK_JOB_COMPLETED':
                     self.assert_qmp(event, 'data/device', drive)
                     self.assert_qmp_absent(event, 'data/error')
                     if check_offset:
                         self.assert_qmp(event, 'data/offset', event['data']['len'])
-                    completed = True
-
-        self.assert_no_active_block_jobs()
-        return event
+                    self.assert_no_active_block_jobs()
+                    return event
 
     def wait_ready(self, drive='drive0'):
         '''Wait until a block job BLOCK_JOB_READY event'''
Signature · 1 line
2.14.3
Reviewed-by on v2 1/1
#1 lore raw
Quoted 42 lines · Peter Xu

If there are more than one events, wait_until_completed() might return the 2nd event even if the 1st event is JOB_COMPLETED, since the for loop will continue to run even if completed is set to True.

It never happened before, but it can be triggered when OOB is enabled due to the RESUME startup message. Fix that up.

---
 tests/qemu-iotests/iotests.py | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
tests/qemu-iotests/iotests.py +3 -6
index b5d7945af8..119c8e270a 100644
@@ -470,18 +470,15 @@ class QMPTestCase(unittest.TestCase):
 
     def wait_until_completed(self, drive='drive0', check_offset=True):
         '''Wait for a block job to finish, returning the event'''
-        completed = False
-        while not completed:
+        while True:
             for event in self.vm.get_qmp_events(wait=True):
                 if event['event'] == 'BLOCK_JOB_COMPLETED':
                     self.assert_qmp(event, 'data/device', drive)
                     self.assert_qmp_absent(event, 'data/error')
                     if check_offset:
                         self.assert_qmp(event, 'data/offset', event['data']['len'])
-                    completed = True
-
-        self.assert_no_active_block_jobs()
-        return event
+                    self.assert_no_active_block_jobs()
+                    return event
 
     def wait_ready(self, drive='drive0'):
         '''Wait until a block job BLOCK_JOB_READY event'''
Signature · 1 line
2.14.3
Reviewed-by on v2 1/1
#2 lore raw
In reply to Peter Xu
Quoted 11 lines · Peter Xu

If there are more than one events, wait_until_completed() might return the 2nd event even if the 1st event is JOB_COMPLETED, since the for loop will continue to run even if completed is set to True.

It never happened before, but it can be triggered when OOB is enabled due to the RESUME startup message. Fix that up.

---
 tests/qemu-iotests/iotests.py | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
#3 lore raw
In reply to Peter Xu
Quoted 11 lines · Peter Xu

If there are more than one events, wait_until_completed() might return the 2nd event even if the 1st event is JOB_COMPLETED, since the for loop will continue to run even if completed is set to True.

It never happened before, but it can be triggered when OOB is enabled due to the RESUME startup message. Fix that up.

---
 tests/qemu-iotests/iotests.py | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

If you get the other OOB-related bug fixes working, I can include this along with those for -rc3 through the qapi tree. Otherwise, I'm fine waiting for this until 2.13.

tests/qemu-iotests/iotests.py class QMPTestCase(unittest.TestCase): · line 474

Quoted 9 lines

+++ b/tests/qemu-iotests/iotests.py

tests/qemu-iotests/iotests.py +1 -2
@@ -470,18 +470,15 @@ class QMPTestCase(unittest.TestCase):
 
     def wait_until_completed(self, drive='drive0', check_offset=True):
         '''Wait for a block job to finish, returning the event'''
-        completed = False
-        while not completed:
+        while True:
             for event in self.vm.get_qmp_events(wait=True):

Do we really need two loops? Or can you eliminate the 'while True:' loop and rely on just the 'for event...' loop?

Quoted 15 lines
tests/qemu-iotests/iotests.py +2 -4
                 if event['event'] == 'BLOCK_JOB_COMPLETED':
                     self.assert_qmp(event, 'data/device', drive)
                     self.assert_qmp_absent(event, 'data/error')
                     if check_offset:
                         self.assert_qmp(event, 'data/offset', event['data']['len'])
-                    completed = True
-
-        self.assert_no_active_block_jobs()
-        return event
+                    self.assert_no_active_block_jobs()
+                    return event
 
     def wait_ready(self, drive='drive0'):
         '''Wait until a block job BLOCK_JOB_READY event'''
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
author
#4 lore raw
Quoted 8 lines · Eric Blake
Quoted 7 lines · Peter Xu

If there are more than one events, wait_until_completed() might return the 2nd event even if the 1st event is JOB_COMPLETED, since the for loop will continue to run even if completed is set to True.

It never happened before, but it can be triggered when OOB is enabled due to the RESUME startup message. Fix that up.

Quoted 8 lines
Quoted 4 lines
---
 tests/qemu-iotests/iotests.py | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

If you get the other OOB-related bug fixes working, I can include this along with those for -rc3 through the qapi tree. Otherwise, I'm fine waiting for this until 2.13.

Hi, Eric,

I think we have settled on the other two fix patches with Stefan, it'll be good we can include those two patches for 2.12 now (maybe also together with this one since it's pretty safe).

Quoted 5 lines
Quoted 5 lines

+++ b/tests/qemu-iotests/iotests.py

(quoted diff) +0 -0
@@ -470,18 +470,15 @@ class QMPTestCase(unittest.TestCase):
 
Quoted 9 lines

tests/qemu-iotests/iotests.py class QMPTestCase(unittest.TestCase): · line 474

Quoted 6 lines
tests/qemu-iotests/iotests.py +1 -2
     def wait_until_completed(self, drive='drive0', check_offset=True):
         '''Wait for a block job to finish, returning the event'''
-        completed = False
-        while not completed:
+        while True:
             for event in self.vm.get_qmp_events(wait=True):

Do we really need two loops? Or can you eliminate the 'while True:' loop and rely on just the 'for event...' loop?

Seems not; the old wait_until_completed() will block here if haven't received the JOB_COMPETE event yet until this point. Removing the while loop will let the function return immediately with a None, which might break the old semantics. Thanks,

Signature · 1 line
Peter Xu