Description of problem: get_active_connections from NMClient.Client always returns an empty list. Here is the reproducer: from gi.repository import NMClient nmclient = NMClient.Client(dbus_path='/org/freedesktop/NetworkManager') active = nmclient.get_active_connections() print(active) Version-Release number of selected component (if applicable): NetworkManager-0.9.3.995-0.4.git20120302.fc17.x86_64 NetworkManager-glib-0.9.3.995-0.4.git20120302.fc17.x86_64 How reproducible: Always Actual results: empty list Expected results: list of active connections
Still present in: NetworkManager-0.9.3.997-0.7.fc17.x86_64 NetworkManager-glib-0.9.3.997-0.7.fc17.x86_64
Ok, so for some reason I don't understand, this is actually what you want to do: from gi.repository import NMClient c = NMClient.Client.new() print c.get_active_connections() that actually calls the nm_client_new() method in libnm-glib. The other method appears to call the actual glib object constructor which doesn't let the NMClient object do some necessary initialization work. Thankfully this is the only object you really have to care about creating as the others are done internally. I'll work on making this more foolproof to avoid the confusion here.
“Ok, so for some reason I don't understand, this is actually what you want to do:” Python object construction is done by calling the class itself, not by calling its methods. „The other method appears to call the actual glib object constructor which doesn't let the NMClient object do some necessary initialization work.“ This should be easy to fix by just moving the initialization from nm_client_new to nm_client_init where it belongs.
Created attachment 571785 [details] An untested patch to fix NMClient initialization This is a quick and dirty patch that I have not even tested. It shows how to fix construction of NMClient objects. Please note that nm_client_init cannot return a NULL function and thus cannot use "return NULL" in response to dbus_g_bus_get failure.
s/function/value/
NMClient implements GInitable so it will be a bit more complicated...
Created attachment 571870 [details] Modified patch to fix NMClient init Ok, the patch should look like this + plus handling the case with failed connection, but...
NetworkManager-0.9.3.997-1.git20120321.fc17 has been submitted as an update for Fedora 17. https://admin.fedoraproject.org/updates/NetworkManager-0.9.3.997-1.git20120321.fc17
Thanks, it works well with the above testing scenario. Unfortunately, there is a bug in the testing lines. NMClient class already knows the default dbus_path, so it should also work without it. from gi.repository import NMClient nmclient = NMClient.Client() active = nmclient.get_active_connections() print(active) Or in python comand-line simply: from gi.repository import NMClient NMClient.Client().get_active_connections()
It is not working for me on a fully updated Fedora-17 x86_64 machine: $ python Python 2.7.2 (default, Jan 4 2012, 20:44:07) [GCC 4.7.0 20120103 (Red Hat 4.7.0-0)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from gi.repository import NMClient >>> nmclient = NMClient.Client() ** (process:2554): WARNING **: constructor: bus connection and path required. __main__:1: Warning: g_object_unref: assertion `G_IS_OBJECT (object)' failed Segmentation fault (core dumped) $ rpm -q NetworkManager NetworkManager-glib python NetworkManager-0.9.3.997-1.git20120321.fc17.x86_64 NetworkManager-glib-0.9.3.997-1.git20120321.fc17.x86_64 python-2.7.2-18.fc17.x86_64 $ gdb /usr/bin/python GNU gdb (GDB) Fedora (7.4.50.20120120-32.fc17) Copyright (C) 2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-redhat-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /usr/bin/python...(no debugging symbols found)...done. Missing separate debuginfos, use: debuginfo-install python-2.7.2-18.fc17.x86_64 (gdb) run Starting program: /usr/bin/python [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". Python 2.7.2 (default, Jan 4 2012, 20:44:07) [GCC 4.7.0 20120103 (Red Hat 4.7.0-0)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from gi.repository import NMClient >>> nmclient = NMClient.Client() ** (process:2701): WARNING **: constructor: bus connection and path required. __main__:1: Warning: g_object_unref: assertion `G_IS_OBJECT (object)' failed Program received signal SIGSEGV, Segmentation fault. 0x00007ffff056483a in ?? () from /usr/lib64/python2.7/site-packages/gi/_gobject/_gobject.so (gdb) where #0 0x00007ffff056483a in ?? () from /usr/lib64/python2.7/site-packages/gi/_gobject/_gobject.so #1 0x00007ffff055dda5 in ?? () from /usr/lib64/python2.7/site-packages/gi/_gobject/_gobject.so #2 0x00007ffff05660e1 in ?? () from /usr/lib64/python2.7/site-packages/gi/_gobject/_gobject.so #3 0x00000039d0a9c8dc in ?? () from /lib64/libpython2.7.so.1.0 #4 0x00000039d0a49a1e in PyObject_Call () from /lib64/libpython2.7.so.1.0 #5 0x00000039d0ad877c in PyEval_EvalFrameEx () from /lib64/libpython2.7.so.1.0 #6 0x00000039d0adc7c1 in PyEval_EvalCodeEx () from /lib64/libpython2.7.so.1.0 #7 0x00000039d0adc892 in PyEval_EvalCode () from /lib64/libpython2.7.so.1.0 #8 0x00000039d0af566a in ?? () from /lib64/libpython2.7.so.1.0 #9 0x00000039d0af7276 in PyRun_InteractiveOneFlags () from /lib64/libpython2.7.so.1.0 #10 0x00000039d0af741e in PyRun_InteractiveLoopFlags () from /lib64/libpython2.7.so.1.0 #11 0x00000039d0af79bc in PyRun_AnyFileExFlags () from /lib64/libpython2.7.so.1.0 #12 0x00000039d0b07b72 in Py_Main () from /lib64/libpython2.7.so.1.0 #13 0x00000039cea21735 in __libc_start_main () from /lib64/libc.so.6 #14 0x00000000004006f1 in _start () (gdb)
This works: from gi.repository import NMClient NMClient.Client.new().get_active_connections() And this doesn't: from gi.repository import NMClient NMClient.Client().get_active_connections()
The orginal reproducer is working though: $ python Python 2.7.2 (default, Jan 4 2012, 20:44:07) [GCC 4.7.0 20120103 (Red Hat 4.7.0-0)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from gi.repository import NMClient >>> nmclient = NMClient.Client(dbus_path='/org/freedesktop/NetworkManager') >>> active = nmclient.get_active_connections() >>> print(active) [<ActiveConnection object at 0xbfbcd0 (NMActiveConnection at 0xc83820)>] >>>
Yes. The "bigger half" of the problem is fixed. The easier part can be tested with my example above.
NetworkManager-0.9.3.997-1.git20120321.fc17 has been pushed to the Fedora 17 stable repository. If problems still persist, please make note of it in this bug report.
NetworkManager-0.9.4.0-1.git20120328.fc17 has been submitted as an update for Fedora 17. https://admin.fedoraproject.org/updates/NetworkManager-0.9.4.0-1.git20120328.fc17
NetworkManager-0.9.4.0-1.git20120328.fc17 has been pushed to the Fedora 17 stable repository. If problems still persist, please make note of it in this bug report.