Bug 1578337

Summary: event-test.py gets traceback when pool-build or pool-delete
Product: Red Hat Enterprise Linux 7 Reporter: Yanqiu Zhang <yanqzhan>
Component: libvirt-pythonAssignee: Michal Privoznik <mprivozn>
Status: CLOSED ERRATA QA Contact: lcheng
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.5CC: dyuan, fjin, jdenemar, lcheng, lmen, mzhan, xuzhang, yanqzhan, yisun
Target Milestone: rcKeywords: Upstream
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-python-4.4.0-1.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-10-30 11:10:24 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Yanqiu Zhang 2018-05-15 10:26:55 UTC
Description of problem:
libvirt(3.8.0-1) added new events for *PoolBuild() and *PoolDelete(), but "event-test.py" can not adapt to this now and gives traceback.

Version-Release number of selected component (if applicable):
libvirt-python-3.9.0-1.el7.x86_64
libvirt-3.9.0-14.el7_5.5.x86_64
qemu-kvm-rhev-2.10.0-21.el7_5.2.x86_64

How reproducible:
100%

Steps to Reproduce:
1.Prepare a storage pool:
# mkdir /tmp/test
# virsh pool-define test-pool.xml 
# cat test-pool.xml 
<pool type='dir'>
  <name>test-pool</name>
  <capacity unit='bytes'>160982630400</capacity>
  <allocation unit='bytes'>63092301824</allocation>
  <available unit='bytes'>97890328576</available>
  <source>
  </source>
  <target>
    <path>/tmp/test</path>
    <permissions>
      <mode>0711</mode>
      <owner>0</owner>
      <group>0</group>
      <label>system_u:object_r:virt_image_t:s0</label>
    </permissions>
  </target>
</pool>

2.Try to get pool-build event by event-test.py:
[terminal 1]# virsh pool-build test-pool
Pool test-pool built

[terminal 2]# python `locate event-test.py` --loop --all
Using uri 'qemu:///system' and event loop '--all'
Traceback (most recent call last):
  File "/usr/lib64/python2.7/site-packages/libvirt.py", line 5025, in _dispatchStoragePoolEventLifecycleCallback
    cb(self, virStoragePool(self, _obj=pool), event, detail, opaque)
  File "/usr/share/doc/libvirt-python-3.9.0/examples/event-test.py", line 613, in myStoragePoolEventLifecycleCallback
    storageEventToString(event),
  File "/usr/share/doc/libvirt-python-3.9.0/examples/event-test.py", line 609, in storageEventToString
    return storageEventStrings[event]
IndexError: tuple index out of range

3.Try to get pool-delete event by event-test.py:
[terminal 1]# virsh pool-delete test-pool
Pool test-pool deleted

[terminal 2]# python `locate event-test.py` --loop --all
Traceback (most recent call last):
  File "/usr/lib64/python2.7/site-packages/libvirt.py", line 5025, in _dispatchStoragePoolEventLifecycleCallback
    cb(self, virStoragePool(self, _obj=pool), event, detail, opaque)
  File "/usr/share/doc/libvirt-python-3.9.0/examples/event-test.py", line 613, in myStoragePoolEventLifecycleCallback
    storageEventToString(event),
  File "/usr/share/doc/libvirt-python-3.9.0/examples/event-test.py", line 609, in storageEventToString
    return storageEventStrings[event]
IndexError: tuple index out of range


Actual results:
As in step2&3, event-test.py gets traceback when pool-build or pool-delete

Expected results:
    myStoragePoolEventCallback EVENT: Storage pool test Created 0
    myStoragePoolEventCallback EVENT: Storage pool test Deleted 0

Additional info:

Comment 1 Michal Privoznik 2018-05-22 11:49:30 UTC
Patch proposed upstream:

https://www.redhat.com/archives/libvir-list/2018-May/msg01591.html

Comment 2 Michal Privoznik 2018-05-22 12:24:23 UTC
To POST:

commit bae22e3eb7c33ec65bb77e5efeeca925ee787be9
Author:     Michal Privoznik <mprivozn>
AuthorDate: Tue May 22 13:47:05 2018 +0200
Commit:     Michal Privoznik <mprivozn>
CommitDate: Tue May 22 14:22:46 2018 +0200

    event-test.py: Sync list of storage lifecycle events
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1578337
    
    Since libvirt 3.8.0 we have 6 events: defined, undefined,
    started, stopped, created, deleted. However, the last two were
    missing in a string list that translates libvirt events (int)
    into human readable strings.
    
    Signed-off-by: Michal Privoznik <mprivozn>
    Reviewed-by: Pavel Hrdina <phrdina>

v4.3.0-7-gbae22e3

Comment 4 lcheng 2018-06-26 03:59:42 UTC
Verify on libvirt-python-4.4.0-1.el7.x86_64. Don't find error. So move to VERIFIED.

# mkdir /tmp/test
# vim test-pool.xml

On terminal 1, execute virsh pool command.
# virsh pool-define test-pool.xml
Pool test-pool defined from test-pool.xml

# virsh pool-build test-pool
Pool test-pool built

# virsh pool-start test-pool
Pool test-pool started

# virsh pool-refresh test-pool
Pool test-pool refreshed

# virsh pool-destroy test-pool
Pool test-pool destroyed

# virsh pool-undefine test-pool
Pool test-pool has been undefined

# virsh pool-define test-pool.xml
Pool test-pool defined from test-pool.xml

# virsh pool-build test-pool
Pool test-pool built

# virsh pool-delete test-pool
Pool test-pool deleted

On terminal 2, get storage lifecycle events.
# python /usr/share/doc/libvirt-python-4.4.0/examples/event-test.py
Using uri 'qemu:///system' and event loop 'poll'
myStoragePoolEventLifecycleCallback: Storage pool test-pool Defined 0
myStoragePoolEventLifecycleCallback: Storage pool test-pool Created 0
myStoragePoolEventLifecycleCallback: Storage pool test-pool Started 0
myStoragePoolEventRefreshCallback: Storage pool test-pool
myStoragePoolEventLifecycleCallback: Storage pool test-pool Stopped 0
myStoragePoolEventLifecycleCallback: Storage pool test-pool Undefined 0
myStoragePoolEventLifecycleCallback: Storage pool test-pool Defined 0
myStoragePoolEventLifecycleCallback: Storage pool test-pool Created 0
myStoragePoolEventLifecycleCallback: Storage pool test-pool Deleted 0

Comment 6 errata-xmlrpc 2018-10-30 11:10:24 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2018:3204