RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1212168 - add an event on device attach to the python bindings
Summary: add an event on device attach to the python bindings
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt-python
Version: 7.1
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: rc
: ---
Assignee: Ján Tomko
QA Contact: Virtualization Bugs
URL:
Whiteboard:
Depends On: 1206114
Blocks: 1179138
TreeView+ depends on / blocked
 
Reported: 2015-04-15 17:14 UTC by Ján Tomko
Modified: 2015-11-19 05:34 UTC (History)
9 users (show)

Fixed In Version: libvirt-python-1.2.15-1.el7
Doc Type: Bug Fix
Doc Text:
Clone Of: 1206114
Environment:
Last Closed: 2015-11-19 05:34:40 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2015:2203 0 normal SHIPPED_LIVE libvirt-python bug fix and enhancement update 2015-11-19 08:17:48 UTC

Description Ján Tomko 2015-04-15 17:14:18 UTC
The event should also be accessible via the python bindings.

event-test from /usr/share/doc/libvirt-python should show this event
when a device is attached to a domain:
myDomainEventDeviceAddedCallback: Domain f21(3) device added: net1


+++ This bug was initially created as a clone of Bug #1206114 +++

it seems there is no event that allows libvirt users to detect an attached device (while there is one for detached).

My testing was simply:

# virsh event --loop --all

while I was trying to attach a new device as showed in the 1179138 report.



+++ This bug was initially created as a clone of Bug #1179138 +++

Description:
virt-manager does not show the new added hot-plug devices immediately after virsh command attach device successfully,

Product version
virt-manager-1.1.0-10.el7.noarch
libvirt-1.2.8-11.el7.x86_64
qemu-kvm-rhev-2.1.2-17.el7.x86_64
3.10.0-220.el7.x86_64

How producible
100%

Steps:
1. Prepare a running guest, works well, check the network device in guest and virt-manager
# virsh list
 Id    Name                           State
----------------------------------------------------
 7     rhel7                          running

2. Dumpxml guest for interface list, also checks it in guest
# virsh dumpxml rhel
...
 <interface type='network'>
      <mac address='52:54:00:c6:3b:95'/>
      <source network='default' bridge='virbr0'/>
      <bandwidth>
        <inbound average='1000' peak='5000' burst='1024'/>
        <outbound average='128' peak='256' burst='256'/>
      </bandwidth>
      <target dev='vnet2'/>
      <model type='virtio'/>
      <driver name='vhost' queues='5'/>
      <link state='down'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x10' function='0x0'/>
    </interface>
...

# virsh domiflist rhel7
Interface  Type       Source     Model       MAC
-------------------------------------------------------
vnet2      network    default    virtio      52:54:00:c6:3b:95

in guest:
# lspci |grep Eth
00:10.0 Ethernet controller: Red Hat, Inc Virtio network device

2. Prepare a network xml, attach it to the guest
# cat /tmp/network1.xml
 <interface type='network'>
      <mac address='52:54:00:b0:8d:2c'/>
      <source network='default' bridge='virbr0'/>
      <target dev='vnet0'/>
      <model type='rtl8139'/>
    </interface>

# virsh attach-device rhel7 /tmp/network1.xml
Device attached successfully

3. Recheck the guest interface list and dumpxml to confirm the network device has been hot-plugged to guest success
# virsh domiflist rhel7
Interface  Type       Source     Model       MAC
-------------------------------------------------------
vnet2      network    default    virtio      52:54:00:c6:3b:95
vnet3      network    default    rtl8139     52:54:00:b0:8d:2c

# virsh dumpxml rhel
...
<interface type='network'>
      <mac address='52:54:00:c6:3b:95'/>
      <source network='default' bridge='virbr0'/>
      <bandwidth>
        <inbound average='1000' peak='5000' burst='1024'/>
        <outbound average='128' peak='256' burst='256'/>
      </bandwidth>
      <target dev='vnet2'/>
      <model type='virtio'/>
      <driver name='vhost' queues='5'/>
      <link state='down'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x10' function='0x0'/>
    </interface>
    <interface type='network'>
      <mac address='52:54:00:b0:8d:2c'/>
      <source network='default' bridge='virbr0'/>
      <target dev='vnet3'/>
      <model type='rtl8139'/>
      <alias name='net1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
...

4. in guest, network exist
# lspci |grep Eth
00:03.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL-8100/8101L/8139 PCI Fast Ethernet Adapter (rev 20)  ----> the is the new added hot-plug network device
00:10.0 Ethernet controller: Red Hat, Inc Virtio network device

5. check with virt-manager for the new added hot-plug network interface device, click "Show virtual hardware details" menu.
the new added NIC device doest not shown, only the old one can be seen.

6. Close virt-manger window and open it again,  or restart libvirtd, the new added hot-plug devices can be seen from virt-manger.

Additional info:
The same issue also hit on hot-plug for disk, console, usb hostdev devices.

Actual result:
Although, virsh command has attached device successfully, but virt-manager does not sync with guest new added hot-plug devices immediately. It is abnormal.

Expected result:
Virt-manage can sync with virsh command immediately for hot-plug device attach.

--- Additional comment from Ján Tomko on 2015-04-04 19:21:28 CEST ---

Upstream patches proposing the VIR_DOMAIN_EVENT_ID_DEVICE_ADDED event:
https://www.redhat.com/archives/libvir-list/2015-April/msg00183.html
and adding it to the python bindings:
https://www.redhat.com/archives/libvir-list/2015-April/msg00186.html

Note that both the new event and DEVICE_REMOVED are only emitted by the qemu driver.

Comment 1 Ján Tomko 2015-04-15 17:15:24 UTC
Pushed upstream:
commit cd2d02ab0d92078b4addcbf1e650add92730bc4d
Author:     Ján Tomko <jtomko>
CommitDate: 2015-04-15 18:48:23 +0200

    Implement the DEVICE_ADDED event

git describe: v1.2.14-2-gcd2d02a

Comment 4 hongming 2015-05-12 09:31:13 UTC
Verify it as follows. The result is expected. Move its status to VERIFIED.

# rpm -q libvirt libvirt-python
libvirt-1.2.15-2.el7.x86_64
libvirt-python-1.2.13-1.el7.x86_64

Execute the event-test.py
# python /usr/share/doc/libvirt-python-1.2.15/examples/event-test.py 



In another terminal , execute the following steps

# virsh start r7a
Domain r7a started

# cat nic.xml
<interface type='network'>
  <source network='default'/>
</interface>

# virsh domiflist r7a
Interface  Type       Source     Model       MAC
-------------------------------------------------------
vnet0      network    default    rtl8139     52:54:00:cc:6d:e8

# virsh attach-device r7a nic.xml
Device attached successfully

# virsh domiflist r7a
Interface  Type       Source     Model       MAC
-------------------------------------------------------
vnet0      network    default    rtl8139     52:54:00:cc:6d:e8
vnet1      network    default    rtl8139     52:54:00:8c:3d:27



Check the output of event-test.py , it is capture the 'device-added' event.

# # python /usr/share/doc/libvirt-python-1.2.15/examples/event-test.py 
Using uri:qemu:///system
myDomainEventAgentLifecycleCallback: Domain r7a(8) disconnected domain started
myDomainEventCallback1 EVENT: Domain r7a(8) Resumed Unpaused
myDomainEventCallback2 EVENT: Domain r7a(8) Resumed Unpaused
myDomainEventCallback1 EVENT: Domain r7a(8) Started Booted
myDomainEventCallback2 EVENT: Domain r7a(8) Started Booted
myDomainEventAgentLifecycleCallback: Domain r7a(8) connected channel event
myDomainEventDeviceAddedCallback: Domain r7a(8) device added: net1

Comment 5 hongming 2015-05-12 09:35:23 UTC
It is verified in the following versions. The versions in the above comment is wrong when copy and paste  

# rpm -q libvirt libvirt-python
libvirt-1.2.15-2.el7.x86_64
libvirt-python-1.2.15-1.el7.x86_64

Comment 7 errata-xmlrpc 2015-11-19 05:34:40 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://rhn.redhat.com/errata/RHBA-2015-2203.html


Note You need to log in before you can comment on or make changes to this bug.