libnm/tests: turn all mock objects into ExportedObjs
This way they will all be able to register with the ObjectManager mock.
This commit is contained in:
@@ -92,9 +92,14 @@ class ExportedObj(dbus.service.Object):
|
||||
dbus.service.Object.__init__(self, bus, object_path)
|
||||
self._bus = bus
|
||||
self.path = object_path
|
||||
self.__dbus_ifaces = {}
|
||||
self.__ensure_dbus_ifaces()
|
||||
|
||||
def __ensure_dbus_ifaces(self):
|
||||
if not hasattr(self, '_ExportedObj__dbus_ifaces'):
|
||||
self.__dbus_ifaces = {}
|
||||
|
||||
def add_dbus_interface(self, dbus_iface, get_props_func, prop_changed_func):
|
||||
self.__ensure_dbus_ifaces()
|
||||
self.__dbus_ifaces[dbus_iface] = ExportedObj.DBusInterface(dbus_iface, get_props_func, prop_changed_func)
|
||||
|
||||
def __dbus_interface_get(self, dbus_iface):
|
||||
@@ -957,7 +962,7 @@ class InvalidSettingException(dbus.DBusException):
|
||||
class MissingSettingException(dbus.DBusException):
|
||||
_dbus_error_name = IFACE_CONNECTION + '.MissingSetting'
|
||||
|
||||
class Connection(dbus.service.Object):
|
||||
class Connection(ExportedObj):
|
||||
def __init__(self, bus, object_path, settings, remove_func, verify_connection=True):
|
||||
|
||||
if self.get_uuid(settings) is None:
|
||||
@@ -966,8 +971,6 @@ class Connection(dbus.service.Object):
|
||||
settings['connection']['uuid'] = uuid.uuid4()
|
||||
self.verify(settings, verify_strict=verify_connection)
|
||||
|
||||
dbus.service.Object.__init__(self, bus, object_path)
|
||||
|
||||
self.path = object_path
|
||||
self.settings = settings
|
||||
self.remove_func = remove_func
|
||||
@@ -975,6 +978,9 @@ class Connection(dbus.service.Object):
|
||||
self.props = {}
|
||||
self.props['Unsaved'] = False
|
||||
|
||||
self.add_dbus_interface(IFACE_CONNECTION, self.__get_props, None)
|
||||
ExportedObj.__init__(self, bus, object_path)
|
||||
|
||||
def get_uuid(self, settings=None):
|
||||
if settings is None:
|
||||
settings = self.settings
|
||||
@@ -1014,20 +1020,11 @@ class Connection(dbus.service.Object):
|
||||
self.settings = settings;
|
||||
self.Updated()
|
||||
|
||||
# Properties interface
|
||||
@dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='s', out_signature='a{sv}')
|
||||
def GetAll(self, iface):
|
||||
if iface != IFACE_CONNECTION:
|
||||
raise UnknownInterfaceException()
|
||||
def __get_props(self):
|
||||
return self.props
|
||||
|
||||
@dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='ss', out_signature='v')
|
||||
def Get(self, iface, name):
|
||||
if iface != IFACE_CONNECTION:
|
||||
raise UnknownInterfaceException()
|
||||
if not name in self.props.keys():
|
||||
raise UnknownPropertyException()
|
||||
return self.props[name]
|
||||
def __notify(self, propname):
|
||||
self._dbus_property_notify(IFACE_CONNECTION, propname)
|
||||
|
||||
# Connection methods
|
||||
@dbus.service.method(dbus_interface=IFACE_CONNECTION, in_signature='', out_signature='a{sa{sv}}')
|
||||
@@ -1065,9 +1062,8 @@ IFACE_SETTINGS = 'org.freedesktop.NetworkManager.Settings'
|
||||
class InvalidHostnameException(dbus.DBusException):
|
||||
_dbus_error_name = IFACE_SETTINGS + '.InvalidHostname'
|
||||
|
||||
class Settings(dbus.service.Object):
|
||||
class Settings(ExportedObj):
|
||||
def __init__(self, bus, object_path):
|
||||
dbus.service.Object.__init__(self, bus, object_path)
|
||||
self.connections = {}
|
||||
self.bus = bus
|
||||
self.counter = 1
|
||||
@@ -1077,6 +1073,9 @@ class Settings(dbus.service.Object):
|
||||
self.props['CanModify'] = True
|
||||
self.props['Connections'] = dbus.Array([], 'o')
|
||||
|
||||
self.add_dbus_interface(IFACE_SETTINGS, self.__get_props, Settings.PropertiesChanged)
|
||||
ExportedObj.__init__(self, bus, object_path)
|
||||
|
||||
def auto_remove_next_connection(self):
|
||||
self.remove_next_connection = True;
|
||||
|
||||
@@ -1103,7 +1102,7 @@ class Settings(dbus.service.Object):
|
||||
self.connections[path] = con
|
||||
self.props['Connections'] = dbus.Array(self.connections.keys(), 'o')
|
||||
self.NewConnection(path)
|
||||
self.PropertiesChanged({ 'connections': self.props['Connections'] })
|
||||
self.__notify('Connections')
|
||||
|
||||
if self.remove_next_connection:
|
||||
self.remove_next_connection = False
|
||||
@@ -1122,7 +1121,7 @@ class Settings(dbus.service.Object):
|
||||
def delete_connection(self, connection):
|
||||
del self.connections[connection.path]
|
||||
self.props['Connections'] = dbus.Array(self.connections.keys(), 'o')
|
||||
self.PropertiesChanged({ 'connections': self.props['Connections'] })
|
||||
self.__notify('Connections')
|
||||
|
||||
@dbus.service.method(dbus_interface=IFACE_SETTINGS, in_signature='s', out_signature='')
|
||||
def SaveHostname(self, hostname):
|
||||
@@ -1130,21 +1129,13 @@ class Settings(dbus.service.Object):
|
||||
if hostname.find('.') == -1:
|
||||
raise InvalidHostnameException()
|
||||
self.props['Hostname'] = hostname
|
||||
self.PropertiesChanged({ 'hostname': hostname })
|
||||
self.__notify('Hostname')
|
||||
|
||||
@dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='s', out_signature='a{sv}')
|
||||
def GetAll(self, iface):
|
||||
if iface != IFACE_SETTINGS:
|
||||
raise UnknownInterfaceException()
|
||||
def __get_props(self):
|
||||
return self.props
|
||||
|
||||
@dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='ss', out_signature='v')
|
||||
def Get(self, iface, name):
|
||||
if iface != IFACE_SETTINGS:
|
||||
raise UnknownInterfaceException()
|
||||
if not name in self.props.keys():
|
||||
raise UnknownPropertyException()
|
||||
return self.props[name]
|
||||
def __notify(self, propname):
|
||||
self._dbus_property_notify(IFACE_SETTINGS, propname)
|
||||
|
||||
@dbus.service.signal(IFACE_SETTINGS, signature='o')
|
||||
def NewConnection(self, path):
|
||||
|
Reference in New Issue
Block a user