Bug 802536

Summary: get_active_connections is always empty
Product: [Fedora] Fedora Reporter: Thomas Woerner <twoerner>
Component: NetworkManagerAssignee: Dan Williams <dcbw>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 17CC: dcbw, psimerda, the.ridikulus.rat
Target Milestone: ---Keywords: Reopened
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: NetworkManager-0.9.4.0-1.git20120328.fc17 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-03-29 04:13:47 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
An untested patch to fix NMClient initialization
none
Modified patch to fix NMClient init none

Description Thomas Woerner 2012-03-12 19:03:41 UTC
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

Comment 1 Pavel Šimerda (pavlix) 2012-03-20 21:51:54 UTC
Still present in:

NetworkManager-0.9.3.997-0.7.fc17.x86_64
NetworkManager-glib-0.9.3.997-0.7.fc17.x86_64

Comment 2 Dan Williams 2012-03-21 16:13:08 UTC
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.

Comment 3 Pavel Šimerda (pavlix) 2012-03-21 17:31:11 UTC
“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.

Comment 4 Pavel Šimerda (pavlix) 2012-03-21 17:36:45 UTC
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.

Comment 5 Pavel Šimerda (pavlix) 2012-03-21 17:37:42 UTC
s/function/value/

Comment 6 Pavel Šimerda (pavlix) 2012-03-21 18:34:24 UTC
NMClient implements GInitable so it will be a bit more complicated...

Comment 7 Pavel Šimerda (pavlix) 2012-03-21 21:28:14 UTC
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...

Comment 8 Fedora Update System 2012-03-21 23:51:30 UTC
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

Comment 9 Pavel Šimerda (pavlix) 2012-03-22 16:11:09 UTC
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()

Comment 10 Thomas Woerner 2012-03-22 16:25:46 UTC
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)

Comment 11 Pavel Šimerda (pavlix) 2012-03-22 16:33:23 UTC
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()

Comment 12 Thomas Woerner 2012-03-22 16:36:04 UTC
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)>]
>>>

Comment 13 Pavel Šimerda (pavlix) 2012-03-22 21:56:22 UTC
Yes. The "bigger half" of the problem is fixed. The easier part can be tested
with my example above.

Comment 14 Fedora Update System 2012-03-23 17:43:10 UTC
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.

Comment 15 Fedora Update System 2012-03-28 08:47:05 UTC
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

Comment 16 Fedora Update System 2012-03-29 04:13:47 UTC
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.