...
 
Commits (17)
......@@ -33,6 +33,7 @@ polkit_DATA = \
interfaces_files = \
org.libvirt.Connect.xml \
org.libvirt.Domain.xml \
org.libvirt.Interface.xml \
org.libvirt.Network.xml \
org.libvirt.NodeDevice.xml \
org.libvirt.NWFilter.xml \
......
......@@ -148,12 +148,52 @@
<arg name="flags" type="u" direction="in"/>
<arg name="sysinfo" type="s" direction="out"/>
</method>
<method name="InterfaceChangeBegin">
<annotation name="org.gtk.GDBus.DocString"
value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceChangeBegin"/>
<arg name="flags" type="u" direction="in"/>
</method>
<method name="InterfaceChangeCommit">
<annotation name="org.gtk.GDBus.DocString"
value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceChangeCommit"/>
<arg name="flags" type="u" direction="in"/>
</method>
<method name="InterfaceChangeRollback">
<annotation name="org.gtk.GDBus.DocString"
value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceChangeRollback"/>
<arg name="flags" type="u" direction="in"/>
</method>
<method name="InterfaceDefineXML">
<annotation name="org.gtk.GDBus.DocString"
value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceDefineXML"/>
<arg name="xml" type="s" direction="in"/>
<arg name="flags" type="u" direction="in"/>
<arg name="interface" type="o" direction="out"/>
</method>
<method name="InterfaceLookupByMAC">
<annotation name="org.gtk.GDBus.DocString"
value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceLookupByMACString"/>
<arg name="mac" type="s" direction="in"/>
<arg name="interface" type="o" direction="out"/>
</method>
<method name="InterfaceLookupByName">
<annotation name="org.gtk.GDBus.DocString"
value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceLookupByName"/>
<arg name="name" type="s" direction="in"/>
<arg name="interface" type="o" direction="out"/>
</method>
<method name="ListDomains">
<annotation name="org.gtk.GDBus.DocString"
value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectListAllDomains"/>
<arg name="flags" type="u" direction="in"/>
<arg name="domains" type="ao" direction="out"/>
</method>
<method name="ListInterfaces">
<annotation name="org.gtk.GDBus.DocString"
value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virConnectListAllInterfaces"/>
<arg name="flags" type="u" direction="in"/>
<arg name="interfaces" type="ao" direction="out"/>
</method>
<method name="ListNetworks">
<annotation name="org.gtk.GDBus.DocString"
value="See https://libvirt.org/html/libvirt-libvirt-network.html#virConnectListAllNetworks"/>
......
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node name="/org/libvirt/interface">
<interface name="org.libvirt.Interface">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="false"/>
<property name="Active" type="b" access="read">
<annotation name="org.gtk.GDBus.DocString"
value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceIsActive"/>
</property>
<property name="MAC" type="s" access="read">
<annotation name="org.gtk.GDBus.DocString"
value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetMACString"/>
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/>
</property>
<property name="Name" type="s" access="read">
<annotation name="org.gtk.GDBus.DocString"
value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetName"/>
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/>
</property>
<method name="Create">
<annotation name="org.gtk.GDBus.DocString"
value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceCreate"/>
<arg name="flags" type="u" direction="in"/>
</method>
<method name="Destroy">
<annotation name="org.gtk.GDBus.DocString"
value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceDestroy"/>
<arg name="flags" type="u" direction="in"/>
</method>
<method name="GetXMLDesc">
<annotation name="org.gtk.GDBus.DocString"
value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetXMLDesc"/>
<arg name="flags" type="u" direction="in"/>
<arg name="xml" type="s" direction="out"/>
</method>
<method name="Undefine">
<annotation name="org.gtk.GDBus.DocString"
value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceUndefine"/>
</method>
</interface>
</node>
......@@ -41,6 +41,8 @@ libvirt_dbus_SOURCES = \
events.h \
gdbus.c \
gdbus.h \
interface.c \
interface.h \
main.c \
network.c \
network.h \
......
#include "connect.h"
#include "domain.h"
#include "events.h"
#include "interface.h"
#include "network.h"
#include "nodedev.h"
#include "nwfilter.h"
......@@ -734,6 +735,154 @@ virtDBusConnectGetSysinfo(GVariant *inArgs,
*outArgs = g_variant_new("(s)", sysinfo);
}
static void
virtDBusConnectInterfaceChangeBegin(GVariant *inArgs,
GUnixFDList *inFDs G_GNUC_UNUSED,
const gchar *objectPath G_GNUC_UNUSED,
gpointer userData,
GVariant **outArgs G_GNUC_UNUSED,
GUnixFDList **outFDs G_GNUC_UNUSED,
GError **error)
{
virtDBusConnect *connect = userData;
guint flags;
g_variant_get(inArgs, "(u)", &flags);
if (!virtDBusConnectOpen(connect, error))
return;
if (virInterfaceChangeBegin(connect->connection, flags) < 0)
virtDBusUtilSetLastVirtError(error);
}
static void
virtDBusConnectInterfaceChangeCommit(GVariant *inArgs,
GUnixFDList *inFDs G_GNUC_UNUSED,
const gchar *objectPath G_GNUC_UNUSED,
gpointer userData,
GVariant **outArgs G_GNUC_UNUSED,
GUnixFDList **outFDs G_GNUC_UNUSED,
GError **error)
{
virtDBusConnect *connect = userData;
guint flags;
g_variant_get(inArgs, "(u)", &flags);
if (!virtDBusConnectOpen(connect, error))
return;
if (virInterfaceChangeCommit(connect->connection, flags) < 0)
virtDBusUtilSetLastVirtError(error);
}
static void
virtDBusConnectInterfaceChangeRollback(GVariant *inArgs,
GUnixFDList *inFDs G_GNUC_UNUSED,
const gchar *objectPath G_GNUC_UNUSED,
gpointer userData,
GVariant **outArgs G_GNUC_UNUSED,
GUnixFDList **outFDs G_GNUC_UNUSED,
GError **error)
{
virtDBusConnect *connect = userData;
guint flags;
g_variant_get(inArgs, "(u)", &flags);
if (!virtDBusConnectOpen(connect, error))
return;
if (virInterfaceChangeRollback(connect->connection, flags) < 0)
virtDBusUtilSetLastVirtError(error);
}
static void
virtDBusConnectInterfaceDefineXML(GVariant *inArgs,
GUnixFDList *inFDs G_GNUC_UNUSED,
const gchar *objectPath G_GNUC_UNUSED,
gpointer userData,
GVariant **outArgs,
GUnixFDList **outFDs G_GNUC_UNUSED,
GError **error)
{
virtDBusConnect *connect = userData;
g_autoptr(virInterface) interface = NULL;
g_autofree gchar *path = NULL;
const gchar *xml;
guint flags;
g_variant_get(inArgs, "(&su)", &xml, &flags);
if (!virtDBusConnectOpen(connect, error))
return;
interface = virInterfaceDefineXML(connect->connection, xml, flags);
if (!interface)
return virtDBusUtilSetLastVirtError(error);
path = virtDBusUtilBusPathForVirInterface(interface, connect->interfacePath);
*outArgs = g_variant_new("(o)", path);
}
static void
virtDBusConnectInterfaceLookupByMAC(GVariant *inArgs,
GUnixFDList *inFDs G_GNUC_UNUSED,
const gchar *objectPath G_GNUC_UNUSED,
gpointer userData,
GVariant **outArgs,
GUnixFDList **outFDs G_GNUC_UNUSED,
GError **error)
{
virtDBusConnect *connect = userData;
g_autoptr(virInterface) interface = NULL;
g_autofree gchar *path = NULL;
const gchar *mac;
g_variant_get(inArgs, "(&s)", &mac);
if (!virtDBusConnectOpen(connect, NULL))
return;
interface = virInterfaceLookupByMACString(connect->connection, mac);
if (!interface)
return virtDBusUtilSetLastVirtError(error);
path = virtDBusUtilBusPathForVirInterface(interface, connect->interfacePath);
*outArgs = g_variant_new("(o)", path);
}
static void
virtDBusConnectInterfaceLookupByName(GVariant *inArgs,
GUnixFDList *inFDs G_GNUC_UNUSED,
const gchar *objectPath G_GNUC_UNUSED,
gpointer userData,
GVariant **outArgs,
GUnixFDList **outFDs G_GNUC_UNUSED,
GError **error)
{
virtDBusConnect *connect = userData;
g_autoptr(virInterface) interface = NULL;
g_autofree gchar *path = NULL;
const gchar *name;
g_variant_get(inArgs, "(&s)", &name);
if (!virtDBusConnectOpen(connect, NULL))
return;
interface = virInterfaceLookupByName(connect->connection, name);
if (!interface)
return virtDBusUtilSetLastVirtError(error);
path = virtDBusUtilBusPathForVirInterface(interface, connect->interfacePath);
*outArgs = g_variant_new("(o)", path);
}
static void
virtDBusConnectListDomains(GVariant *inArgs,
GUnixFDList *inFDs G_GNUC_UNUSED,
......@@ -771,6 +920,43 @@ virtDBusConnectListDomains(GVariant *inArgs,
*outArgs = g_variant_new_tuple(&gdomains, 1);
}
static void
virtDBusConnectListInterfaces(GVariant *inArgs,
GUnixFDList *inFDs G_GNUC_UNUSED,
const gchar *objectPath G_GNUC_UNUSED,
gpointer userData,
GVariant **outArgs,
GUnixFDList **outFDs G_GNUC_UNUSED,
GError **error)
{
virtDBusConnect *connect = userData;
g_autoptr(virInterfacePtr) interfaces = NULL;
guint flags;
GVariantBuilder builder;
GVariant *ginterfaces;
g_variant_get(inArgs, "(u)", &flags);
if (!virtDBusConnectOpen(connect, error))
return;
if (virConnectListAllInterfaces(connect->connection, &interfaces, flags) < 0)
return virtDBusUtilSetLastVirtError(error);
g_variant_builder_init(&builder, G_VARIANT_TYPE("ao"));
for (gint i = 0; interfaces[i]; i++) {
g_autofree gchar *path = NULL;
path = virtDBusUtilBusPathForVirInterface(interfaces[i],
connect->interfacePath);
g_variant_builder_add(&builder, "o", path);
}
ginterfaces = g_variant_builder_end(&builder);
*outArgs = g_variant_new_tuple(&ginterfaces, 1);
}
static void
virtDBusConnectListNetworks(GVariant *inArgs,
GUnixFDList *inFDs G_GNUC_UNUSED,
......@@ -1765,7 +1951,14 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = {
{ "GetCPUModelNames", virtDBusConnectGetCPUModelNames },
{ "GetDomainCapabilities", virtDBusConnectGetDomainCapabilities },
{ "GetSysinfo", virtDBusConnectGetSysinfo },
{ "InterfaceChangeBegin", virtDBusConnectInterfaceChangeBegin },
{ "InterfaceChangeCommit", virtDBusConnectInterfaceChangeCommit },
{ "InterfaceChangeRollback", virtDBusConnectInterfaceChangeRollback },
{ "InterfaceDefineXML", virtDBusConnectInterfaceDefineXML },
{ "InterfaceLookupByMAC", virtDBusConnectInterfaceLookupByMAC },
{ "InterfaceLookupByName", virtDBusConnectInterfaceLookupByName },
{ "ListDomains", virtDBusConnectListDomains },
{ "ListInterfaces", virtDBusConnectListInterfaces },
{ "ListNetworks", virtDBusConnectListNetworks },
{ "ListNodeDevices", virtDBusConnectListNodeDevices },
{ "ListNWFilters", virtDBusConnectListNWFilters },
......@@ -1809,6 +2002,7 @@ virtDBusConnectFree(virtDBusConnect *connect)
virtDBusConnectClose(connect, TRUE);
g_free(connect->domainPath);
g_free(connect->interfacePath);
g_free(connect->networkPath);
g_free(connect->nodeDevPath);
g_free(connect->nwfilterPath);
......@@ -1869,6 +2063,10 @@ virtDBusConnectNew(virtDBusConnect **connectp,
if (error && *error)
return;
virtDBusInterfaceRegister(connect, error);
if (error && *error)
return;
virtDBusNetworkRegister(connect, error);
if (error && *error)
return;
......
......@@ -13,6 +13,7 @@ struct virtDBusConnect {
const gchar *uri;
const gchar *connectPath;
gchar *domainPath;
gchar *interfacePath;
gchar *networkPath;
gchar *nodeDevPath;
gchar *nwfilterPath;
......
#include "interface.h"
#include "util.h"
#include <libvirt/libvirt.h>
static virInterfacePtr
virtDBusInterfaceGetVirInterface(virtDBusConnect *connect,
const gchar *objectPath,
GError **error)
{
virInterfacePtr interface;
if (virtDBusConnectOpen(connect, error) < 0)
return NULL;
interface = virtDBusUtilVirInterfaceFromBusPath(connect->connection,
objectPath,
connect->interfacePath);
if (!interface) {
virtDBusUtilSetLastVirtError(error);
return NULL;
}
return interface;
}
static void
virtDBusInterfaceCreate(GVariant *inArgs,
GUnixFDList *inFDs G_GNUC_UNUSED,
const gchar *objectPath,
gpointer userData,
GVariant **outArgs G_GNUC_UNUSED,
GUnixFDList **outFDs G_GNUC_UNUSED,
GError **error)
{
virtDBusConnect *connect = userData;
g_autoptr(virInterface) interface = NULL;
guint flags;
g_variant_get(inArgs, "(u)", &flags);
interface = virtDBusInterfaceGetVirInterface(connect, objectPath, error);
if (!interface)
return;
if (virInterfaceCreate(interface, flags) < 0)
virtDBusUtilSetLastVirtError(error);
}
static void
virtDBusInterfaceDestroy(GVariant *inArgs,
GUnixFDList *inFDs G_GNUC_UNUSED,
const gchar *objectPath,
gpointer userData,
GVariant **outArgs G_GNUC_UNUSED,
GUnixFDList **outFDs G_GNUC_UNUSED,
GError **error)
{
virtDBusConnect *connect = userData;
g_autoptr(virInterface) interface = NULL;
guint flags;
g_variant_get(inArgs, "(u)", &flags);
interface = virtDBusInterfaceGetVirInterface(connect, objectPath, error);
if (!interface)
return;
if (virInterfaceDestroy(interface, flags) < 0)
virtDBusUtilSetLastVirtError(error);
}
static void
virtDBusInterfaceGetActive(const gchar *objectPath,
gpointer userData,
GVariant **value,
GError **error)
{
virtDBusConnect *connect = userData;
g_autoptr(virInterface) interface = NULL;
gint active;
interface = virtDBusInterfaceGetVirInterface(connect, objectPath, error);
if (!interface)
return;
active = virInterfaceIsActive(interface);
if (active < 0)
return virtDBusUtilSetLastVirtError(error);
*value = g_variant_new("b", !!active);
}
static void
virtDBusInterfaceGetMAC(const gchar *objectPath,
gpointer userData,
GVariant **value,
GError **error)
{
virtDBusConnect *connect = userData;
g_autoptr(virInterface) interface = NULL;
const gchar *mac;
interface = virtDBusInterfaceGetVirInterface(connect, objectPath, error);
if (!interface)
return;
mac = virInterfaceGetMACString(interface);
if (!mac)
return virtDBusUtilSetLastVirtError(error);
*value = g_variant_new("s", mac);
}
static void
virtDBusInterfaceGetName(const gchar *objectPath,
gpointer userData,
GVariant **value,
GError **error)
{
virtDBusConnect *connect = userData;
g_autoptr(virInterface) interface = NULL;
const gchar *name;
interface = virtDBusInterfaceGetVirInterface(connect, objectPath, error);
if (!interface)
return;
name = virInterfaceGetName(interface);
if (!name)
return virtDBusUtilSetLastVirtError(error);
*value = g_variant_new("s", name);
}
static void
virtDBusInterfaceGetXMLDesc(GVariant *inArgs,
GUnixFDList *inFDs G_GNUC_UNUSED,
const gchar *objectPath,
gpointer userData,
GVariant **outArgs,
GUnixFDList **outFDs G_GNUC_UNUSED,
GError **error)
{
virtDBusConnect *connect = userData;
g_autoptr(virInterface) interface = NULL;
g_autofree gchar *xml = NULL;
guint flags;
g_variant_get(inArgs, "(u)", &flags);
interface = virtDBusInterfaceGetVirInterface(connect, objectPath, error);
if (!interface)
return;
xml = virInterfaceGetXMLDesc(interface, flags);
if (!xml)
return virtDBusUtilSetLastVirtError(error);
*outArgs = g_variant_new("(s)", xml);
}
static void
virtDBusInterfaceUndefine(GVariant *inArgs G_GNUC_UNUSED,
GUnixFDList *inFDs G_GNUC_UNUSED,
const gchar *objectPath,
gpointer userData,
GVariant **outArgs G_GNUC_UNUSED,
GUnixFDList **outFDs G_GNUC_UNUSED,
GError **error)
{
virtDBusConnect *connect = userData;
g_autoptr(virInterface) interface = NULL;
interface = virtDBusInterfaceGetVirInterface(connect, objectPath, error);
if (!interface)
return;
if (virInterfaceUndefine(interface) < 0)
virtDBusUtilSetLastVirtError(error);
}
static virtDBusGDBusPropertyTable virtDBusInterfacePropertyTable[] = {
{ "Active", virtDBusInterfaceGetActive, NULL },
{ "MAC", virtDBusInterfaceGetMAC, NULL },
{ "Name", virtDBusInterfaceGetName, NULL },
{ 0 }
};
static virtDBusGDBusMethodTable virtDBusInterfaceMethodTable[] = {
{ "Create", virtDBusInterfaceCreate },
{ "Destroy", virtDBusInterfaceDestroy },
{ "GetXMLDesc", virtDBusInterfaceGetXMLDesc },
{ "Undefine", virtDBusInterfaceUndefine },
{ 0 }
};
static gchar **
virtDBusInterfaceEnumerate(gpointer userData)
{
virtDBusConnect *connect = userData;
g_autoptr(virInterfacePtr) interfaces = NULL;
gint num = 0;
gchar **ret = NULL;
if (!virtDBusConnectOpen(connect, NULL))
return NULL;
num = virConnectListAllInterfaces(connect->connection, &interfaces, 0);
if (num < 0)
return NULL;
if (num == 0)
return NULL;
ret = g_new0(gchar *, num + 1);
for (gint i = 0; i < num; i++) {
ret[i] = virtDBusUtilBusPathForVirInterface(interfaces[i],
connect->interfacePath);
}
return ret;
}
static GDBusInterfaceInfo *interfaceInfo;
void
virtDBusInterfaceRegister(virtDBusConnect *connect,
GError **error)
{
connect->interfacePath = g_strdup_printf("%s/interface",
connect->connectPath);
if (!interfaceInfo) {
interfaceInfo = virtDBusGDBusLoadIntrospectData(VIRT_DBUS_INTERFACE_INTERFACE,
error);
if (!interfaceInfo)
return;
}
virtDBusGDBusRegisterSubtree(connect->bus,
connect->interfacePath,
interfaceInfo,
virtDBusInterfaceEnumerate,
virtDBusInterfaceMethodTable,
virtDBusInterfacePropertyTable,
connect);
}
#pragma once
#include "connect.h"
#define VIRT_DBUS_INTERFACE_INTERFACE "org.libvirt.Interface"
void
virtDBusInterfaceRegister(virtDBusConnect *connect,
GError **error);
......@@ -278,6 +278,41 @@ virtDBusUtilVirDomainListFree(virDomainPtr *domains)
g_free(domains);
}
virInterfacePtr
virtDBusUtilVirInterfaceFromBusPath(virConnectPtr connection,
const gchar *path,
const gchar *interfacePath)
{
g_autofree gchar *macstr = NULL;
gsize prefixLen = strlen(interfacePath) + 1;
macstr = virtDBusUtilDecodeStr(path + prefixLen);
return virInterfaceLookupByMACString(connection, macstr);
}
gchar *
virtDBusUtilBusPathForVirInterface(virInterfacePtr interface,
const gchar *interfacePath)
{
const gchar *macstr = NULL;
g_autofree const gchar *encodedMACStr = NULL;
macstr = virInterfaceGetMACString(interface);
encodedMACStr = virtDBusUtilEncodeStr(macstr);
return g_strdup_printf("%s/%s", interfacePath, encodedMACStr);
}
void
virtDBusUtilVirInterfaceListFree(virInterfacePtr *interfaces)
{
for (gint i = 0; interfaces[i] != NULL; i++)
virInterfaceFree(interfaces[i]);
g_free(interfaces);
}
virNetworkPtr
virtDBusUtilVirNetworkFromBusPath(virConnectPtr connection,
const gchar *path,
......
......@@ -65,6 +65,21 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainPtr, virtDBusUtilVirDomainListFree);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainStatsRecordPtr, virDomainStatsRecordListFree);
virInterfacePtr
virtDBusUtilVirInterfaceFromBusPath(virConnectPtr connection,
const gchar *path,
const gchar *interfacePath);
gchar *
virtDBusUtilBusPathForVirInterface(virInterfacePtr interface,
const gchar *interfacePath);
void
virtDBusUtilVirInterfaceListFree(virInterfacePtr *interfaces);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virInterface, virInterfaceFree);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virInterfacePtr, virtDBusUtilVirInterfaceListFree);
virNetworkPtr
virtDBusUtilVirNetworkFromBusPath(virConnectPtr connection,
const gchar *path,
......
......@@ -11,6 +11,7 @@ test_helpers = \
test_programs = \
test_connect.py \
test_domain.py \
test_interface.py \
test_network.py \
test_nodedev.py \
test_storage.py \
......
......@@ -71,6 +71,18 @@ class BaseTestClass():
if self.timeout:
raise TimeoutError()
def interface_create(self):
""" Fixture to define dummy interface on the test driver
This fixture should be used in the setup of every test manipulating
with interfaces.
"""
path = self.connect.InterfaceDefineXML(xmldata.minimal_interface_xml, 0)
obj = self.bus.get_object('org.libvirt', path)
interface_obj = dbus.Interface(obj, 'org.libvirt.Interface')
interface_obj.Create(0)
return path, interface_obj
@pytest.fixture
def node_device_create(self):
""" Fixture to create dummy node device on the test driver
......
......@@ -84,6 +84,23 @@ class TestConnect(libvirttest.BaseTestClass):
sysinfo = self.connect.GetSysinfo(0)
assert isinstance(sysinfo, dbus.String)
def test_connect_interface_define_xml(self):
path = self.connect.InterfaceDefineXML(xmldata.minimal_interface_xml, 0)
assert isinstance(path, dbus.ObjectPath)
@pytest.mark.parametrize("lookup_method_name,lookup_item", [
("InterfaceLookupByName", 'Name'),
("InterfaceLookupByMAC", 'MAC'),
])
def test_connect_interface_lookup_by_property(self, lookup_method_name, lookup_item):
"""Parameterized test for all InterfaceLookupBy* API calls of Connect interface
"""
original_path,_ = self.interface_create()
obj = self.bus.get_object('org.libvirt', original_path)
prop = obj.Get('org.libvirt.Interface', lookup_item, dbus_interface=dbus.PROPERTIES_IFACE)
path = getattr(self.connect, lookup_method_name)(prop)
assert original_path == path
def test_connect_list_networks(self):
networks = self.connect.ListNetworks(0)
assert isinstance(networks, dbus.Array)
......
#!/usr/bin/python3
import dbus
import libvirttest
class TestInterface(libvirttest.BaseTestClass):
""" Tests for methods and properties of the Interface interface
"""
def test_interface_undefine(self):
_,interface_obj = self.interface_create()
interface_obj.Destroy(0)
interface_obj.Undefine()
def test_interface_destroy(self):
_,interface_obj = self.interface_create()
interface_obj.Destroy(0)
def test_interface_create(self):
_,interface_obj = self.interface_create()
interface_obj.Destroy(0)
interface_obj.Create(0)
def test_interface_get_xml_description(self):
_,interface_obj = self.interface_create()
assert isinstance(interface_obj.GetXMLDesc(0), dbus.String)
def test_interface_properties_type(self):
""" Ensure correct return type for Interface properties
"""
test_interface_path,_ = self.interface_create()
obj = self.bus.get_object('org.libvirt', test_interface_path)
props = obj.GetAll('org.libvirt.Interface', dbus_interface=dbus.PROPERTIES_IFACE)
assert isinstance(props['Name'], dbus.String)
assert isinstance(props['MAC'], dbus.String)
assert isinstance(props['Active'], dbus.Boolean)
if __name__ == '__main__':
libvirttest.run()
......@@ -12,6 +12,18 @@ minimal_domain_xml = '''
</domain>
'''
minimal_interface_xml = '''
<interface type='ethernet' name='test-iface'>
<start mode='onboot'/>
<mac address='11:22:33:44:55:66'/>
<mtu size='1492'/>
<protocol family='ipv4'>
<ip address='192.168.15.5' prefix='24'/>
<route gateway='192.168.15.1'/>
</protocol>
</interface>
'''
minimal_network_xml = '''
<network>
<name>bar</name>
......