libnm-core, libnm, devices: merge client and daemon NMDeviceError
authorDan Winship <danw@gnome.org>
Wed, 15 Oct 2014 17:47:29 +0000 (13:47 -0400)
committerDan Winship <danw@gnome.org>
Wed, 22 Oct 2014 12:29:08 +0000 (08:29 -0400)
Merge libnm's NMDeviceError and the daemon's NMDeviceError into a
single enum (in nm-errors.h). Register the domain with D-Bus, and add
a test that the client side decodes it correctly.

The daemon's NM_DEVICE_ERROR_CONNECTION_INVALID gets absorbed into
libnm's NM_DEVICE_ERROR_INVALID_CONNECTION, and
NM_DEVICE_ERROR_UNSUPPORTED_DEVICE_TYPE gets dropped, since it was
only returned from one place, which is now using
NM_DEVICE_ERROR_FAILED, since (a) it ought to be a "can't happen", and
(b) the only caller of that function just logs error->message and then
frees the error without ever looking at the code.

libnm-core/nm-errors.c
libnm-core/nm-errors.h
libnm/nm-device.c
libnm/nm-device.h
libnm/tests/test-nm-client.c
src/devices/nm-device.c
src/devices/nm-device.h
tools/test-networkmanager-service.py

index 9469740..cf980e1 100644 (file)
@@ -28,6 +28,7 @@
 
 G_DEFINE_QUARK (nm-connection-error-quark, nm_connection_error)
 G_DEFINE_QUARK (nm-crypto-error-quark, nm_crypto_error)
+G_DEFINE_QUARK (nm-device-error-quark, nm_device_error)
 
 static void
 register_error_domain (GQuark domain,
@@ -57,4 +58,7 @@ _nm_dbus_errors_init (void)
        register_error_domain (NM_CONNECTION_ERROR,
                               NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
                               NM_TYPE_CONNECTION_ERROR);
+       register_error_domain (NM_DEVICE_ERROR,
+                              NM_DBUS_INTERFACE_DEVICE,
+                              NM_TYPE_DEVICE_ERROR);
 }
index a6b34e3..7a680e0 100644 (file)
@@ -95,4 +95,31 @@ typedef enum {
 #define NM_CRYPTO_ERROR nm_crypto_error_quark ()
 GQuark nm_crypto_error_quark (void);
 
+/**
+ * NMDeviceError:
+ * @NM_DEVICE_ERROR_FAILED: unknown or unclassified error
+ * @NM_DEVICE_ERROR_INVALID_CONNECTION: the specified connection is not valid
+ * @NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION: the specified connection is not
+ *   compatible with this device.
+ * @NM_DEVICE_ERROR_NOT_ACTIVE: the device does not have an active connection
+ * @NM_DEVICE_ERROR_NOT_SOFTWARE: the requested operation is only valid on
+ *   software devices.
+ *
+ * Device-related errors.
+ *
+ * These errors may be returned directly from #NMDevice methods, or may be
+ * returned from D-Bus operations (where they correspond to errors in the
+ * "org.freedesktop.NetworkManager.Device" namespace).
+ */
+typedef enum {
+       NM_DEVICE_ERROR_FAILED = 0,                /*< nick=Failed >*/
+       NM_DEVICE_ERROR_INVALID_CONNECTION,        /*< nick=InvalidConnection >*/
+       NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,   /*< nick=IncompatibleConnection >*/
+       NM_DEVICE_ERROR_NOT_ACTIVE,                /*< nick=NotActive >*/
+       NM_DEVICE_ERROR_NOT_SOFTWARE,              /*< nick=NotSoftware >*/
+} NMDeviceError;
+
+#define NM_DEVICE_ERROR nm_device_error_quark ()
+GQuark nm_device_error_quark (void);
+
 #endif /* __NM_ERRORS_H__ */
index b715910..89d8e7d 100644 (file)
@@ -139,23 +139,6 @@ enum {
 
 static guint signals[LAST_SIGNAL] = { 0 };
 
-/**
- * nm_device_error_quark:
- *
- * Registers an error quark for #NMDevice if necessary.
- *
- * Returns: the error quark used for #NMDevice errors.
- **/
-GQuark
-nm_device_error_quark (void)
-{
-       static GQuark quark = 0;
-
-       if (G_UNLIKELY (quark == 0))
-               quark = g_quark_from_static_string ("nm-device-error-quark");
-       return quark;
-}
-
 static void
 nm_device_init (NMDevice *device)
 {
index 4b209b8..cbfe6d4 100644 (file)
@@ -37,24 +37,6 @@ G_BEGIN_DECLS
 #define NM_IS_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE))
 #define NM_DEVICE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE, NMDeviceClass))
 
-/**
- * NMDeviceError:
- * @NM_DEVICE_ERROR_FAILED: unknown or unclassified error
- * @NM_DEVICE_ERROR_INVALID_CONNECTION: the connection is not valid
- * @NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION: the connection is not compatible
- *   with this device.
- *
- * Errors from #NMDevice methods.
- */
-typedef enum {
-       NM_DEVICE_ERROR_FAILED = 0,              /*< nick=Failed >*/
-       NM_DEVICE_ERROR_INVALID_CONNECTION,      /*< nick=InvalidConnection >*/
-       NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, /*< nick=IncompatibleConnection >*/
-} NMDeviceError;
-
-#define NM_DEVICE_ERROR nm_device_error_quark ()
-GQuark nm_device_error_quark (void);
-
 #define NM_DEVICE_DEVICE_TYPE "device-type"
 #define NM_DEVICE_UDI "udi"
 #define NM_DEVICE_INTERFACE "interface"
index 26ffbec..bad9e83 100644 (file)
@@ -101,6 +101,10 @@ test_device_added (void)
        g_assert (device);
        g_assert_cmpstr (nm_device_get_iface (device), ==, "eth0");
 
+       /* Try deleting the device via the ordinary NM interface, which should fail */
+       nm_device_delete (device, NULL, &error);
+       g_assert_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_NOT_SOFTWARE);
+
        g_object_unref (client);
        g_clear_pointer (&sinfo, nm_test_service_cleanup);
 }
index 10dd77d..45bcd22 100644 (file)
@@ -334,19 +334,6 @@ static void nm_device_update_hw_address (NMDevice *self);
 
 /***********************************************************/
 
-static GQuark
-nm_device_error_quark (void)
-{
-       static GQuark quark = 0;
-       if (!quark)
-               quark = g_quark_from_static_string ("nm-device-error");
-       return quark;
-}
-
-#define NM_DEVICE_ERROR (nm_device_error_quark ())
-
-/***********************************************************/
-
 #define QUEUED_PREFIX "queued state change to "
 
 static const char *state_table[] = {
@@ -1731,7 +1718,7 @@ nm_device_master_update_slave_connection (NMDevice *self,
 
        g_set_error (error,
                     NM_DEVICE_ERROR,
-                    NM_DEVICE_ERROR_UNSUPPORTED_DEVICE_TYPE,
+                    NM_DEVICE_ERROR_FAILED,
                     "master device '%s' cannot update a slave connection for slave device '%s' (master type not supported?)",
                     nm_device_get_iface (self), nm_device_get_iface (slave));
        return FALSE;
@@ -1837,7 +1824,7 @@ nm_device_complete_connection (NMDevice *self,
        g_return_val_if_fail (connection != NULL, FALSE);
 
        if (!NM_DEVICE_GET_CLASS (self)->complete_connection) {
-               g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CONNECTION_INVALID,
+               g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION,
                             "Device class %s had no complete_connection method",
                             G_OBJECT_TYPE_NAME (self));
                return FALSE;
index 00da022..b053070 100644 (file)
@@ -85,14 +85,6 @@ G_BEGIN_DECLS
 
 typedef enum NMActStageReturn NMActStageReturn;
 
-typedef enum {
-       NM_DEVICE_ERROR_CONNECTION_ACTIVATING = 0, /*< nick=ConnectionActivating >*/
-       NM_DEVICE_ERROR_CONNECTION_INVALID,        /*< nick=ConnectionInvalid >*/
-       NM_DEVICE_ERROR_NOT_ACTIVE,                /*< nick=NotActive >*/
-       NM_DEVICE_ERROR_UNSUPPORTED_DEVICE_TYPE,   /*< nick=UnsupportedDeviceType >*/
-       NM_DEVICE_ERROR_NOT_SOFTWARE,              /*< nick=NotSoftware >*/
-} NMDeviceError;
-
 struct _NMDevice {
        GObject parent;
 };
index 9be2e85..2973fd9 100755 (executable)
@@ -113,6 +113,9 @@ class ExportedObj(dbus.service.Object):
 ###################################################################
 IFACE_DEVICE = 'org.freedesktop.NetworkManager.Device'
 
+class NotSoftwareException(dbus.DBusException):
+    _dbus_error_name = IFACE_DEVICE + '.NotSoftware'
+
 PD_UDI = "Udi"
 PD_IFACE = "Interface"
 PD_DRIVER = "Driver"
@@ -170,6 +173,12 @@ class Device(ExportedObj):
     def Disconnect(self):
         pass
 
+    @dbus.service.method(dbus_interface=IFACE_DEVICE, in_signature='', out_signature='')
+    def Delete(self):
+        # We don't currently support any software device types, so...
+        raise NotSoftwareException()
+        pass
+
     def __notify(self, propname):
         props = self._get_dbus_properties(IFACE_DEVICE)
         changed = { propname: props[propname] }