Commit graph

60 commits

Author SHA1 Message Date
Thomas Haller 7bf10a75db build: extract version macros from "nm-version.h" to new header file "nm-version-macros.h"
For libnm library, "nm-dbus-interface.h" contains defines like the D-Bus
paths of NetworkManager. It is desirable to have this header usable without
having a dependency on "glib.h", for example for a QT application. For that,
commit c0852964a8 removed that dependancy.

For libnm-glib library, the analog to "nm-dbus-interface.h" is
"NetworkManager.h", and the same applies there. Commit
159e827a72 removed that include.
However, that broke build on PackageKit [1] which expected to get the
version macros by including "NetworkManager.h". So at least for libnm-glib,
we need to preserve old behavior so that a user including
"NetworkManager.h" gets the version macros, but not "glib.h".

Extract the version macros to a new header file "nm-version-macros.h".
This header doesn't include "glib.h" and can be included from
"NetworkManager.h". This gives as previous behavior and a glib-free
include.

For libnm we still don't include "nm-version-macros.h" to "nm-dbus-interface.h".
Very few users will actually need the version macros, but not using
libnm.
Users that use libnm, should just include (libnm's) "NetworkManager.h" to
get all headers.
As a special case, a user who doesn't want to use glib/libnm, but still
needs both "nm-dbus-interface.h" and "nm-version-macros.h", can include
them both separately.

[1] https://github.com/hughsie/PackageKit/issues/85

Fixes: 4545a7fe96
2015-09-30 23:10:29 +02:00
Jiří Klimeš 82e4364480 tests: add a test for connection_compatible() for wired devices
Allow setting MAC address and S390 subchannels for ethernet devices in
testing NM service.
2015-09-29 09:31:41 +02:00
Lubomir Rintel 81cc4d27b1 tests: raise the mock service startup timeout
Python is just too slow on some machines. Needed around twice the previous
limit on BCM2835 with Pidora 20, let's add some safety margin too.
2015-08-17 10:53:11 +02:00
Thomas Haller 19c3ea948a all: make use of new header file "nm-default.h" 2015-08-05 15:32:40 +02:00
Dan Winship 3452ee2a0e all: rename nm-glib-compat.h to nm-glib.h, use everywhere
Rather than randomly including one or more of <glib.h>,
<glib-object.h>, and <gio/gio.h> everywhere (and forgetting to include
"nm-glib-compat.h" most of the time), rename nm-glib-compat.h to
nm-glib.h, include <gio/gio.h> from there, and then change all .c
files in NM to include "nm-glib.h" rather than including the glib
headers directly.

(Public headers files still have to include the real glib headers,
since nm-glib.h isn't installed...)

Also, remove glib includes from header files that are already
including a base object header file (which must itself already include
the glib headers).
2015-07-24 13:25:47 -04:00
Dan Winship dd0e198955 include: add nm-dbus-compat.h
Add a file containing the defines like DBUS_INTERFACE_DBUS from
dbus-shared.h, and use it from the gdbus-using files.

Also, convert a bunch of other places that were previously hardcoding
the string values to use the defines instead, and fix the ifcfg-rh
plugin to properly namespace its own D-Bus-related defines.
2015-07-24 13:25:47 -04:00
Thomas Haller 7a3ab5c02f test: initialize tests with nmtst_init() 2015-07-12 13:56:52 +02:00
Lubomir Rintel c47c06470a builds: only enable TAP driver for glib >= 2.37.6
No TAP support for previous versions and --tap argument is silently ignored,
confusing the TAP driver.
2015-05-28 12:51:24 +02:00
Lubomir Rintel 6463ce5dd9 tests: use the TAP formatter
The test results in standard format are easily integrated into CI systems.
2015-05-26 13:51:45 +02:00
Lubomir Rintel 380ed63318 build: switch to parallel test harness
This will make it possible to use the TAP formatter.
2015-05-26 13:51:45 +02:00
Lubomir Rintel d0e25ac8be tests: always spawn private d-bus
Parallel test runs would not be possible without this.
2015-05-26 13:51:44 +02:00
Lubomir Rintel 2981839bde test: initialize auto-destructed pointers
Otherwise the compiler complains that they could be left uninitialized in case
the function returns too early.

Fixes: 76745817c3
2015-02-09 15:19:30 +01:00
Thomas Haller e7356ef0a6 libnm/tests: enable valgrind for libnm tests 2015-02-09 12:10:13 +01:00
Thomas Haller 76745817c3 libnm/tests: fix memleaks in test code for valgrind 2015-02-09 11:51:08 +01:00
Thomas Haller c50f30e79c tests: enable valgrind tests for tests 2015-02-09 11:51:07 +01:00
Jiří Klimeš ce6323d4df tests: mute coverity INFINITE_LOOP error
Error: INFINITE_LOOP (CWE-835): [#def17]
NetworkManager-0.9.11.0/libnm/tests/test-nm-client.c:93: loop_top: Top of the loop.
NetworkManager-0.9.11.0/libnm/tests/test-nm-client.c:94: loop_bottom: Bottom of the loop.
NetworkManager-0.9.11.0/libnm/tests/test-nm-client.c:93: loop_condition: If "notified" is initially true then it will remain true.

Error: INFINITE_LOOP (CWE-835): [#def18]
NetworkManager-0.9.11.0/libnm/tests/test-nm-client.c:191: loop_top: Top of the loop.
NetworkManager-0.9.11.0/libnm/tests/test-nm-client.c:192: loop_bottom: Bottom of the loop.
NetworkManager-0.9.11.0/libnm/tests/test-nm-client.c:191: loop_condition: If "result & NOTIFY_MASK" is initially true then it will remain true.
NetworkManager-0.9.11.0/libnm/tests/test-nm-client.c:191: loop_condition: If "result & SIGNAL_MASK" is initially true then it will remain true.
2014-12-15 16:25:27 +01:00
Dan Winship 71b4c05fca libnm: rename NMSecretAgent to NMSecretAgentOld
As with NMVpnPluginOld, rename NMSecretAgent to NMSecretAgentOld, to
leave the name "NMSecretAgent" open for a new-and-improved version in
NM 1.2.
2014-11-21 12:17:41 -05:00
Dan Winship 3bfb163a74 all: consistently include config.h
config.h should be included from every .c file, and it should be
included before any other include. Fix that.

(As a side effect of how I did this, this also changes us to
consistently use "config.h" rather than <config.h>. To the extent that
it matters [which is not much], quotes are more correct anyway, since
we're talking about a file in our own build tree, not a system
include.)
2014-11-13 17:18:42 -05:00
Lubomir Rintel ba7f17a02b libnm: Fix type mismatch in test
Causes the info->remaining to be counted incorrectly possibly resulting in
g_main_loop_quit() being called twice:

  Program received signal SIGSEGV, Segmentation fault.
  0x00007ffff5a03155 in g_mutex_lock (mutex=0x7ffff7b764b4) at gthread-posix.c:1331
  1331	  if G_UNLIKELY (g_atomic_int_add (&mutex->i[0], 1) != 0)
  Missing separate debuginfos, use: debuginfo-install libgcc-4.9.2-1.fc21.x86_64 libgudev1-216-8.fc21.x86_64 libselinux-2.3-5.fc21.x86_64 libuuid-2.25.2-1.fc21.x86_64 ncurses-libs-5.9-16.20140323.fc21.x86_64 nspr-4.10.7-1.fc21.x86_64 nss-3.17.2-1.fc21.x86_64 nss-softokn-3.17.2-1.fc21.x86_64 nss-softokn-freebl-3.17.2-1.fc21.x86_64 nss-util-3.17.2-1.fc21.x86_64 sqlite-3.8.7-1.fc21.x86_64 systemd-libs-216-8.fc21.x86_64
  (gdb) bt
  #0  0x00007ffff5a03155 in g_mutex_lock (mutex=0x7ffff7b764b4) at gthread-posix.c:1331
  #1  0x00007ffff59bf258 in g_main_loop_quit (loop=0x7fffffffd130) at gmain.c:4000
  #5  0x00007ffff5edc3bf in <emit signal notify:active-connection on instance 0x5555557bd180 [NMDeviceVlan]> (instance=<optimized out>, signal_id=<optimized out>, detail=<optimized out>) at gsignal.c:3365
      #2  0x00007ffff5ec1d35 in g_closure_invoke (closure=0x5555557b3da0, return_value=return_value@entry=0x0, n_param_values=2, param_values=param_values@entry=0x7fffffffd760, invocation_hint=invocation_hint@entry=0x7fffffffd700) at gclosure.c:768
      #3  0x00007ffff5ed3a52 in signal_emit_unlocked_R (node=node@entry=0x555555787040, detail=detail@entry=341, instance=instance@entry=0x5555557bd180, emission_return=emission_return@entry=0x0, instance_and_params=instance_and_params@entry=0x7fffffffd760) at gsignal.c:3553
      #4  0x00007ffff5edc191 in g_signal_emit_valist (instance=<optimized out>, signal_id=<optimized out>, detail=<optimized out>, var_args=var_args@entry=0x7fffffffd8f0) at gsignal.c:3309
  #6  0x00007ffff5ec6465 in g_object_dispatch_properties_changed (object=0x7ffff7b764b4, n_pspecs=1434087776, pspecs=0x5555557ba880) at gobject.c:1056
  #7  0x00007ffff5ec88c1 in g_object_notify (pspec=<optimized out>, object=0x5555557bd180 [NMDeviceVlan])
      at gobject.c:1149
  #8  0x00007ffff5ec88c1 in g_object_notify (object=0x5555557bd180 [NMDeviceVlan], property_name=property_name@entry=0x7ffff7b772f6 "active-connection") at gobject.c:1197
  #9  0x00007ffff7ae57d3 in deferred_notify_cb (data=<optimized out>) at nm-object.c:246
  #10 0x00007ffff59beafb in g_main_context_dispatch (context=0x555555784ac0) at gmain.c:3111
  #11 0x00007ffff59beafb in g_main_context_dispatch (context=context@entry=0x555555784ac0) at gmain.c:3710
  #12 0x00007ffff59bee98 in g_main_context_iterate (context=0x555555784ac0, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at gmain.c:3781
  #13 0x00007ffff59bf1c2 in g_main_loop_run (loop=0x5555557699e0) at gmain.c:3975
  #14 0x000055555555811d in test_activate_virtual () at test-nm-client.c:1103
  #15 0x00007ffff59e4243 in g_test_run_suite_internal (tc=0x555555769a30) at gtestutils.c:2059
  #16 0x00007ffff59e4243 in g_test_run_suite_internal (suite=suite@entry=0x555555766640, path=path@entry=0x7ffff5a6355e "") at gtestutils.c:2120
  #17 0x00007ffff59e4412 in g_test_run_suite_internal (suite=suite@entry=0x555555766620, path=<optimized out>,
      path@entry=0x7ffff5a6355e "") at gtestutils.c:2131
  #18 0x00007ffff59e477b in g_test_run_suite (suite=0x555555766620) at gtestutils.c:2184
  #19 0x00007ffff59e47b1 in g_test_run () at gtestutils.c:1488
  #20 0x0000555555556c01 in main (argc=1, argv=0x7fffffffe028) at test-nm-client.c:1189

https://bugzilla.gnome.org/show_bug.cgi?id=739861
2014-11-10 12:58:36 +01:00
Dan Williams 14537c71d8 libnm-core: emit added/removed signals before property change notifications
Because internal objects do some processing/setup in the various
_added class signal handlers, they need to be emitted before
property change notifications.  Otherwise it leads to situations
where external objects that listen to NMClient property changes
will be called before internal processing has been completed.

Specifically, NMRemoteSettings uses connection_added() to check
connection visibility and assign the new connection to one of
two internal arrays.  If a client got a property notification
for NMClient::connections before NMRemoteSettings can process
the new connection, then nm_client_get_connections() will
return an empty array because NMRemoteSettings hasn't had the
chance to add the new connection to priv->visible yet, which
is done in NMRemoteSettings::connection_added().

Fixes:Beaker:NetworkManager_Test240_nmtui_general_realtime_refresh_edit_screen
2014-11-07 16:58:43 -06:00
Dan Williams 52ae28f6e5 libnm: queue added/removed signals and suppress uninitialized notifications
Property notifications are queued during object initialization and
reloading, but the added/removed signals were emitted immediately
even before the object was fully initialized.

Additionally, depending on how long asynchronous initialization took,
the notifications could have been emitted before the object was
fully initialized as deferred_notify_cb() wasn't being suppressed
until all the properties were complete.

For synchronous intialization, signals could be emitted at various
times during initialization and not all of the object's properties
may be read.  Furthermore property notifications were queued in an
idle handler, which breaks users that may not use a mainloop.  All
signals and notifications should be emitted immediately after
initialization is complete for synchronous initialization.

To make things consistent and ensure that all signals and notifications
are emitted only when initialization is complete, queue signals for
deferred emission and only run notifications/signals when all the
object's properties have been read.  For synchronous initialization,
emit all notifications and signals immediately after initialization
and not from an idle handler.
2014-11-06 20:51:58 -06:00
Lubomir Rintel 48b4f6f830 Merge branch 'lr/rpm-make-check'
https://bugzilla.gnome.org/show_bug.cgi?id=739127
2014-10-30 14:40:47 +01:00
Lubomir Rintel afbc2571a1 libnm/tests: Properly wait for devices in /libnm/activate-virtual
Ignore the signal if we're signalled before the second device is available and
wait for another one.
2014-10-30 14:39:08 +01:00
Lubomir Rintel 5aefbe5658 libnm-core: Don't warn on missing properties
It might simply mean that the object disappeared (which is perfectly fine):

(process:7680): libnm-WARNING **: Could not fetch property 'Vpn' of interface 'org.freedesktop.NetworkManager.Connection.Active' on /org/freedesktop/NetworkManager/ActiveConnection/151: GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: Method "Get" with signature "ss" on interface "org.freedesktop.DBus.Properties" doesn't exist

https://bugzilla.gnome.org/show_bug.cgi?id=739255
2014-10-29 10:04:52 +01:00
Dan Winship 6ae4224850 libnm: change GSList to GPtrArray in libnm methods
libnm mostly used GPtrArrays in its APIs, except that arrays of
connections were usually GSLists. Fix this and make them GPtrArrays
too (and rename nm_client_list_connections() to
nm_client_get_connections() to match everything else).
2014-10-28 17:17:17 -04:00
Lubomir Rintel e9bfd0e29c tests: Don't run session-long dbus daemons for tests
They require a tty or X11 displays, thus are not suitable for headless runs
(such as in mock). Furthermore, they die with the tty or X11 session, which
is somehow late -- a lot of them may accumulate. Let's kill them right away.
2014-10-24 19:16:33 +02:00
Dan Winship 388a0c5e78 libnm: consolidate NMClientError and NMObjectError
Consolidate NMClientError and NMObjectError (such that there is now
only one libnm-API-specific error domain). In particular, merge
NM_CONNECTION_ERROR_CONNECTION_REMOVED with
NM_OBJECT_ERROR_OBJECT_CREATION_FAILURE as the new
NM_CONNECTION_ERROR_OBJECT_CREATION_FAILED.

Also make object_creation_failed() be a plain method rather than a
signal, since there's no reason for anyone to be connecting to it on
another object. And remove its GError argument because the subclass
can just create its own more-specific error.
2014-10-22 08:29:10 -04:00
Dan Winship 821258048b libnm-core, libnm, settings: move NMSecretAgentError to nm-errors
Move the definition of NMSecretAgentError to nm-errors, register it
with D-Bus, and verify in the tests that it maps correctly.

NM_SECRET_AGENT_ERROR_INTERNAL_ERROR is renamed to
NM_SECRET_AGENT_ERROR_FAILED, and NM_SECRET_AGENT_ERROR_NOT_AUTHORIZED
to NM_SECRET_AGENT_ERROR_PERMISSION_DENIED, for consistency with other
error domains. While NMSecretAgentError, unlike most other error
domains, has always been correctly mapped across D-Bus, the renaming
is not an ABI break, because the daemon never checks for either of
those values, so all versions of the daemon will treat
"org.freedesktop.NetworkManager.SecretAgent.InternalError" and
"org.freedesktop.NetworkManager.SecretAgent.Failed" the same (by just
ignoring the error name and keeping only the error message).
2014-10-22 08:29:09 -04:00
Dan Winship 86331d9ef4 libnm-core, settings: move NMAgentManagerError to nm-errors
Move the definition of NMAgentManagerError to nm-errors, register it
with D-Bus, and verify in the tests that it maps correctly.
2014-10-22 08:29:09 -04:00
Dan Winship 3be53899fa libnm-core, settings: move NMSettingsError to nm-errors
Move the definition of NMSettingsError to nm-errors, register it with
D-Bus, and verify in the tests that it maps correctly.

Remove a few unused error codes, simplify a few others, and rename
GENERAL to FAILED and HOSTNAME_INVALID to INVALID_HOSTNAME, for
consistency.
2014-10-22 08:29:09 -04:00
Dan Winship 4f75ff92b4 libnm-core, libnm, devices: merge client and daemon NMDeviceError
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.
2014-10-22 08:29:08 -04:00
Dan Winship 9c67b6fb08 libnm-core, core: register NMConnectionError with D-Bus
Register NMConnectionError with D-Bus on both sides, so that, eg,
connection validation failures in the daemon will translate to the
correct error codes in the client.
2014-10-22 08:29:08 -04:00
Dan Winship be8060f42f libnm: add an object-creation-failed test 2014-10-19 09:27:48 -04:00
Dan Winship f96835b83c libnm: add a virtual device creation-and-activation test
Add a test of creating a (virtual) device and activating a connection
on it at the same time.
2014-10-19 09:27:48 -04:00
Dan Winship e06bd1ef17 libnm: add an active-connection test to test-nm-client
Test NMClient's handling of active connections, and in particular test
that we can correctly resolve the circular reference between an
NMDevice and an NMActiveConnection, both synchronously and
asynchronously.
2014-10-19 09:27:48 -04:00
Dan Winship b9c09a2b0d tools: add a bit more activation support to test-networkmanager-service.py
Now test-networkmanager-service.py can create ActiveConnections, though
they don't actually finish activating.
2014-10-19 09:27:47 -04:00
Dan Winship 08a344d723 libnm: abstract out duplicated device-creating code in tests 2014-10-19 09:27:47 -04:00
Dan Winship 60cce40042 libnm: fix crash in nm_client_new_async(), add a test for it
nm_client_new_async() got broken in the NMManager split. Fix it, and
use it from one of the tests in test-nm-client to make sure it's
getting tested in the future.
2014-10-10 13:44:54 -04:00
Dan Winship 6f3d1f9526 libnm: merge NMRemoteSettings into NMClient
Make NMRemoteSettings internal and have NMClient wrap all of its APIs,
just like it does with NMManager.
2014-10-10 12:40:19 -04:00
Jiří Klimeš 7e67fd2b24 libnm: return errors in nm_client_networking_set_enabled()
and do not print an error in the library. The caller can decide what to do
on an error.
2014-10-01 11:53:07 +02:00
Dan Winship 2237ea3ddb libnm: make sync/async APIs more GLib-like
Make synchronous APIs take GCancellables, and make asynchronous APIs
use GAsyncReadyCallbacks and have names ending in "_async", with
"_finish" functions to retrieve the results.

Also, make nm_client_activate_connection_finish(),
nm_client_add_and_activate_finish(), and
nm_remote_settings_add_connection_finish() be (transfer full) rather
than (transfer none), because the refcounting semantics become
slightly confusing in some edge cases otherwise.
2014-09-25 09:29:20 -04:00
Dan Winship 6ca10677d6 libnm: merge saved and unsaved connection methods
Merge nm_remote_settings_add_connection() and
nm_remote_settings_add_connection_unsaved(), and likewise
nm_remote_connection_commit_changes() and
nm_remote_connection_commit_changes_unsaved(), by adding a boolean
flag to each saying whether to save to disk.
2014-09-25 09:29:20 -04:00
Dan Winship 6793a32a8c libnm: port to GDBus
Port libnm-core/libnm to GDBus.

The NetworkManager daemon continues to use dbus-glib; the
previously-added connection hash/variant conversion methods are now
moved to NetworkManagerUtils (along with a few other utilities that
are now only needed by the daemon code).
2014-09-18 11:51:09 -04:00
Dan Winship acf86f68b3 libnm-core: change connection hash tables to variants in API
In preparation for porting to GDBus, make nm_connection_to_dbus(),
etc, represent connections as GVariants of type 'a{sa{sv}}' rather
than as GHashTables-of-GHashTables-of-GValues.

This means we're constantly converting back and forth internally, but
this is just a stepping stone on the way to the full GDBus port, and
all of that code will go away again later.
2014-09-18 11:51:09 -04:00
Dan Winship d3b53b707a libnm: start glib-ifying NMSecretAgent APIs
Make register() and unregister() have cancellable sync and async
variants. And make NMSecretAgent implement GInitable/GAsyncInitable,
and do the initial auto-registration as part of initialization rather
than doing it asynchronously and emitting a signal.
2014-09-09 12:16:38 -04:00
Dan Winship c9fb96e02e libnm: add test-secret-agent
Implement some basic secret agent functionality in
test-networkmanager-service.py, and add test-secret-agent to test that
NMSecretAgent works as expected.
2014-09-09 12:16:38 -04:00
Dan Winship b732380d1e libnm: drop NMObject:dbus-connection
The only plausible use case for the NMObject:dbus-connection property
is for using the session bus in test programs. So just drop it and use
an environment variable to decide which bus to use instead.
2014-09-09 12:10:13 -04:00
Dan Winship 3e5b3833aa libnm: change empty-GPtrArray-return semantics
libnm functions that return GPtrArrays of objects had a rule that if
the array was empty, they would return NULL rather than a 0-length
array. As it turns out, this is just a nuisance to clients, since in
most places the code for the non-empty case would end up doing the
right thing for the empty case as well (and where it doesn't, we can
check "array->len == 0" just as easily as "array == NULL"). So just
return the 0-length array instead.
2014-09-04 09:21:05 -04:00
Dan Winship 1838db9e71 all: remove a bunch of unnecessary dbus/dbus-glib includes 2014-09-03 10:45:24 -04:00
Dan Winship e1ba13a426 libnm-core, libnm, core: make NMConnection an interface
The fact that NMRemoteConnection has to be an NMConnection and
therefore can't be an NMObject means that it needs to reimplement bits
of NMObject functionality (and likewise NMObject needs some special
magic to deal with it). Likewise, we will need a daemon-side
equivalent of NMObject as part of the gdbus port, and we would want
NMSettingsConnection to be able to inherit from this as well.

Solve this problem by making NMConnection into an interface, and
having NMRemoteConnection and NMSettingsConnection implement it. (We
use some hacks to keep the GHashTable of NMSettings objects inside
nm-connection.c rather than having to be implemented by the
implementations.)

Since NMConnection is no longer an instantiable type, this adds
NMSimpleConnection to replace the various non-D-Bus-based uses of
NMConnection throughout the code. nm_connection_new() becomes
nm_simple_connection_new(), nm_connection_new_from_hash() becomes
nm_simple_connection_new_from_hash(), and nm_connection_duplicate()
becomes nm_simple_connection_new_clone().
2014-08-16 10:17:53 -04:00