Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop usage of virtinterfaced #1782

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packaging/cockpit-machines.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ Requires: libvirt-daemon-driver-qemu
Requires: libvirt-daemon-driver-network
Requires: libvirt-daemon-driver-nodedev
Requires: libvirt-daemon-driver-storage-core
Requires: (libvirt-daemon-driver-interface if virt-install)
Requires: (libvirt-daemon-config-network if virt-install)
Recommends: libvirt-daemon-driver-storage-disk
%if 0%{?rhel}
Expand Down
9 changes: 0 additions & 9 deletions src/libvirt-xml-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -899,15 +899,6 @@ export function parseDumpxmlMachinesMetadataElement(metadataElem, name) {
return subElems.length > 0 ? subElems[0].textContent : null;
}

export function parseIfaceDumpxml(ifaceXml) {
const retObj = {};
const ifaceElem = getElem(ifaceXml);

retObj.type = ifaceElem.getAttribute("type");

return retObj;
}

export function parseNetDumpxml(netXml) {
const retObj = {};
const netElem = getElem(netXml);
Expand Down
2 changes: 1 addition & 1 deletion src/libvirtApi/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ export function getApiData({ connectionName }) {
return Promise.allSettled([
domainGetAll({ connectionName }),
storagePoolGetAll({ connectionName }),
interfaceGetAll({ connectionName }),
interfaceGetAll(),
networkGetAll({ connectionName }),
nodeDeviceGetAll({ connectionName }),
getNodeMaxMemory({ connectionName }),
Expand Down
54 changes: 13 additions & 41 deletions src/libvirtApi/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,55 +21,27 @@
* Provider for Libvirt using libvirt-dbus API.
* See https://github.com/libvirt/libvirt-dbus
*/
import cockpit from 'cockpit';

import store from '../store.js';

import { updateOrAddInterface } from '../actions/store-actions.js';
import { parseIfaceDumpxml } from '../libvirt-xml-parse.js';
import { call, Enum, timeout } from './helpers.js';

/*
* Read properties of a single Interface
*
* @param {object} objPath interface object path
* @param {string} connectionName
*/
export async function interfaceGet({
id: objPath,
connectionName,
}) {
const props = {};
export async function interfaceGetAll() {
let ifaces = [];

try {
const [resultProps] = await call(connectionName, objPath, 'org.freedesktop.DBus.Properties', 'GetAll',
['org.libvirt.Interface'], { timeout, type: 's' });
/* Sometimes not all properties are returned; for example when some network got deleted while part
* of the properties got fetched from libvirt. Make sure that there is check before reading the attributes.
*/
if ("Active" in resultProps)
props.active = resultProps.Active.v.v;
if ("MAC" in resultProps)
props.mac = resultProps.MAC.v.v;
if ("Name" in resultProps)
props.name = resultProps.Name.v.v;
props.id = objPath;
props.connectionName = connectionName;

const [xml] = await call(connectionName, objPath, 'org.libvirt.Interface', 'GetXMLDesc', [0], { timeout, type: 'u' });
const iface = parseIfaceDumpxml(xml);
jelly marked this conversation as resolved.
Show resolved Hide resolved
store.dispatch(updateOrAddInterface(Object.assign(props, iface)));
martinpitt marked this conversation as resolved.
Show resolved Hide resolved
const ipData = await cockpit.spawn(["ip", "--json", "a"], { err: "message" });
ifaces = JSON.parse(ipData);
} catch (ex) {
console.log('listInactiveInterfaces action for path', objPath, ex.toString());
console.warn("Failed to get interfaces with ip command:", ex.toString());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test.

}
}

export async function interfaceGetAll({ connectionName }) {
const flags = Enum.VIR_CONNECT_LIST_INTERFACES_ACTIVE | Enum.VIR_CONNECT_LIST_INTERFACES_INACTIVE;

try {
const [ifaces] = await call(connectionName, '/org/libvirt/QEMU', 'org.libvirt.Connect', 'ListInterfaces', [flags], { timeout, type: 'u' });
await Promise.all(ifaces.map(path => interfaceGet({ connectionName, id: path })));
} catch (ex) {
console.warn('getAllInterfaces action failed:', ex.toString());
throw ex;
for (const iface of ifaces) {
store.dispatch(updateOrAddInterface({
name: iface.ifname,
MAC: iface.address,
Active: iface.operstate === "UP",
}));
}
}
1 change: 0 additions & 1 deletion test/browser/browser.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ sh -x test/vm.install

if [ "${PLATFORM_ID:-}" != "platform:el8" ]; then
# https://gitlab.com/libvirt/libvirt/-/issues/219
systemctl start virtinterfaced.socket
systemctl start virtnetworkd.socket
systemctl start virtnodedevd.socket
systemctl start virtstoraged.socket
Expand Down
17 changes: 7 additions & 10 deletions test/check-machines-networks
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Cockpit; If not, see <http://www.gnu.org/licenses/>.

import json
import xml.etree.ElementTree as ET

import machineslib
Expand All @@ -25,16 +26,12 @@ from machinesxmls import TEST_NETWORK2_CLASH_XML, TEST_NETWORK2_XML, TEST_NETWOR


def getNetworkDevice(m):
net_devices_str = m.execute("virsh iface-list")
net_devices_str = net_devices_str.split("\n", 2)[2] # Remove first 2 lines of table header
if net_devices_str not in ["\n", "\r\n"]:
device = net_devices_str.split(' ', 2)[1] # Get the name of device, ignoring spacing before device string
else: # If $virsh-iface list did not return any device, check virsh nodedev-list net:noh
net_devices_str = m.execute("virsh nodedev-list net")
net_devices_str = net_devices_str.split("\n", 2)[0]
device = net_devices_str.split("_", 2)[1] # Ignore prefix (example: net_enp0s31f6_8c_16_45_5f_77_34)

return device
# To replicate `virsh iface-list` behavior, filter active interfaces
# from ip command and get the first active one.
routes = json.loads(m.execute("ip --json a"))
active = list(filter(lambda r: r['operstate'] == "UP", routes))

return active[0]["ifname"]


@testlib.nondestructive
Expand Down
5 changes: 0 additions & 5 deletions test/vm.install
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ if grep -q 'ID=debian' /usr/lib/os-release; then
echo '* soft core unlimited' >> /etc/security/limits.conf
fi

if grep -q 'ID="opensuse' /usr/lib/os-release; then
# Make sure virtinterfaced.socket is enabled
systemctl enable --now virtinterfaced.socket
fi

systemctl enable cockpit.socket

# don't force https:// (self-signed cert)
Expand Down