Bug 2165466

Summary: Can not update interface link state by domif-setlink
Product: Red Hat Enterprise Linux 9 Reporter: yalzhang <yalzhang>
Component: libvirtAssignee: Michal Privoznik <mprivozn>
libvirt sub component: General QA Contact: yalzhang <yalzhang>
Status: CLOSED ERRATA Docs Contact:
Severity: unspecified    
Priority: unspecified CC: jdenemar, pkrempa, virt-maint
Version: 9.2Keywords: Automation, Regression, Triaged
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-9.0.0-3.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-05-09 07:27:45 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 yalzhang@redhat.com 2023-01-30 07:23:56 UTC
Description of problem:
Can not update interface link state by domif-setlink

Version-Release number of selected component (if applicable):
libvirt-9.0.0-2.el9.x86_64

How reproducible:
100%

Steps to Reproduce:
1. prepare a vm with interface xml with link state setting:
# virsh dumpxml rhel --xpath //interface
<interface type="network">
  <mac address="52:54:00:60:8a:32"/>
  <source network="default"/>
  <model type="virtio"/>
  <link state="up"/>
  <address type="pci" domain="0x0000" bus="0x01" slot="0x00" function="0x0"/>
</interface>

2. start the vm, then live update the link state by domif-setlink:
# virsh start rhel
Domain 'rhel' started

# virsh domiflist rhel
 Interface   Type      Source    Model    MAC
-------------------------------------------------------------
 vnet3       network   default   virtio   52:54:00:60:8a:32

# virsh domif-setlink rhel vnet3 down
error: Failed to update interface link state
error: (device_definition):6: Attribute state redefined
      <link state="up" state="down"/>
-----------------------------------^

Actual results:
In step 2, the xml  parsing doesn't make sense

Expected results:
The domif-setlink should work properly

Additional info:

Comment 1 Peter Krempa 2023-01-31 09:13:57 UTC
Fixed upstream by:

commit 6f3f6c0f763b9ffd8ef93eb124c88dd0b79138fc
Author: Michal Prívozník <mprivozn>
Date:   Mon Jan 30 10:55:22 2023 +0100

    virsh: Make domif-setlink work more than once
    
    In virsh, we have this convenient domif-setlink command, which is
    just a wrapper over virDomainUpdateDeviceFlags() and which allows
    setting link state of given guest NIC. It does so by fetching
    corresponding <interface/> XML snippet and either putting <link
    state=''/> into it, OR if the element already exists setting the
    attribute to desired value. The XML is then fed into the update
    API.
    
    There's, however, a small bug in detecting the pre-existence of
    the element and its attribute. The code looks at "link"
    attribute, while in fact, the attribute is called "state".
    
    Resolves: https://gitlab.com/libvirt/libvirt/-/issues/426
    Fixes: e575bf082ed4889280be07c986375f1ca15bb7ee
    Signed-off-by: Michal Privoznik <mprivozn>
    Reviewed-by: Ján Tomko <jtomko>

Comment 3 yalzhang@redhat.com 2023-02-02 07:41:13 UTC
Test on libvirt-9.0.0-3.el9.x86_64, the result is as expected.

# virsh dumpxml rhel --xpath //interface 
<interface type="network">
  <mac address="52:54:00:60:8a:32"/>
  <source network="default" portid="c6ec8acd-ddb8-46b6-ab45-f0f949b2a3e6" bridge="virbr0"/>
  <target dev="vnet0"/>
  <model type="virtio"/>
  <link state="up"/>
  <alias name="net0"/>
  <address type="pci" domain="0x0000" bus="0x01" slot="0x00" function="0x0"/>
</interface>

# virsh domif-setlink rhel vnet0 down
Device updated successfully

# virsh dumpxml rhel --xpath //interface 
<interface type="network">
  <mac address="52:54:00:60:8a:32"/>
  <source network="default" portid="c6ec8acd-ddb8-46b6-ab45-f0f949b2a3e6" bridge="virbr0"/>
  <target dev="vnet0"/>
  <model type="virtio"/>
  <link state="down"/>
  <alias name="net0"/>
  <address type="pci" domain="0x0000" bus="0x01" slot="0x00" function="0x0"/>
</interface>

Comment 6 yalzhang@redhat.com 2023-02-02 10:31:08 UTC
Run auto cases "virsh.domif_setlink_getlink", no such issue any more.

Comment 8 errata-xmlrpc 2023-05-09 07:27:45 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 (libvirt bug fix and enhancement update), 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/RHBA-2023:2171