New upstream version 2.0.1

parent e27bdb4c
python-networkmanager - Easy communication with NetworkManager
Copyright (C) 2011 Dennis Kaarsemaker <dennis@kaarsemaker.net>
Copyright (C) 2011-2017 Dennis Kaarsemaker <dennis@kaarsemaker.net>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgement in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
include docs/index.rst
include docs/Makefile
include docs/conf.py
include examples/*
include COPYING
This diff is collapsed.
Metadata-Version: 1.1
Name: python-networkmanager
Version: 0.9.10
Version: 2.0.1
Summary: Easy communication with NetworkManager
Home-page: http://github.com/seveas/python-networkmanager
Author: Dennis Kaarsemaker
......@@ -10,7 +10,8 @@ Description: UNKNOWN
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU General Public License (GPL)
Classifier: License :: OSI Approved :: zlib/libpng License
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: System :: Networking
......@@ -19,10 +19,10 @@ Quick install instructions
Stable version:
$ sudo easy_install python-networkmanager
$ pip install python-networkmanager
Latest code:
$ git clone http://github.com/seveas/python-networkmanager
$ cd python-networkmanager
$ sudo python setup.py install
$ python setup.py install
......@@ -41,16 +41,16 @@ master_doc = 'index'
# General information about the project.
project = u'python-networkmanager'
copyright = u'2011-2013, Dennis Kaarsemaker'
copyright = u'2011-2017, Dennis Kaarsemaker'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.9'
version = '2.0'
# The full version, including alpha/beta/rc tags.
release = '0.9.10'
release = '2.0.1'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
......
This diff is collapsed.
......@@ -20,7 +20,7 @@ for conn in NetworkManager.NetworkManager.ActiveConnections:
if conn.Devices:
devices = " (on %s)" % ", ".join([x.Interface for x in conn.Devices])
print("Active connection: %s%s" % (settings['connection']['id'], devices))
size = max([max([len(y) for y in x.keys()]) for x in settings.values()])
size = max([max([len(y) for y in list(x.keys()) + ['']]) for x in settings.values()])
format = " %%-%ds %%s" % (size + 5)
for key, val in sorted(settings.items()):
print(" %s" % key)
......@@ -30,9 +30,8 @@ for conn in NetworkManager.NetworkManager.ActiveConnections:
print("Device: %s" % dev.Interface)
print(" Type %s" % c('device_type', dev.DeviceType))
# print(" IPv4 address %s" % socket.inet_ntoa(struct.pack('L', dev.Ip4Address)))
devicedetail = dev.SpecificDevice()
if not callable(devicedetail.HwAddress):
print(" MAC address %s" % devicedetail.HwAddress)
if hasattr(dev, 'HwAddress'):
print(" MAC address %s" % dev.HwAddress)
print(" IPv4 config")
print(" Addresses")
for addr in dev.Ip4Config.Addresses:
......
......@@ -2,31 +2,32 @@
Listen to some available signals from NetworkManager
"""
import dbus.mainloop.glib; dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
import dbus.mainloop.glib
from gi.repository import GObject
import NetworkManager
import time
d_args = ('sender', 'destination', 'interface', 'member', 'path')
d_args = dict([(x + '_keyword', 'd_' + x) for x in d_args])
def out(msg):
print("%s %s" % (time.strftime('%H:%M:%S'), msg))
def main():
NetworkManager.NetworkManager.connect_to_signal('CheckPermissions', display_sig, **d_args)
NetworkManager.NetworkManager.connect_to_signal('StateChanged', display_sig, **d_args)
NetworkManager.NetworkManager.connect_to_signal('PropertiesChanged', display_sig, **d_args)
NetworkManager.NetworkManager.connect_to_signal('DeviceAdded', display_sig, **d_args)
NetworkManager.NetworkManager.connect_to_signal('DeviceRemoved', display_sig, **d_args)
def statechange(nm, interface, signal, state):
out("State changed to %s" % NetworkManager.const('STATE', state))
def adddevice(nm, interface, signal, device_path):
try:
out("Device %s added" % device_path.IpInterface)
except NetworkManager.ObjectVanished:
# Sometimes this signal is sent for *removed* devices. Ignore.
pass
print("Waiting for signals")
print("-------------------")
def main():
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
NetworkManager.NetworkManager.OnStateChanged(statechange)
NetworkManager.NetworkManager.OnDeviceAdded(adddevice)
out("Waiting for signals")
loop = GObject.MainLoop()
loop.run()
def display_sig(*args, **kwargs):
print("Received signal: %s.%s" % (kwargs['d_interface'], kwargs['d_member']))
print("Sender: (%s)%s" % (kwargs['d_sender'], kwargs['d_path']))
print("Arguments: (%s)" % ", ".join([str(x) for x in args]))
print("-------------------")
if __name__ == '__main__':
main()
......@@ -3,8 +3,8 @@
# Command-line tool to interact with NetworkManager. With this tool, you can
# inspect various configuration items and (de-)activate connections.
#
# (C) 2011-2013 Dennis Kaarsemaker
# License: GPL3+
# (C) 2011-2016 Dennis Kaarsemaker
# License: zlib
from __future__ import print_function
......
#!/usr/bin/python3
#
# Automate vpn connections that require a one-time password.
# Requirements:
# - secretstorage (find on pypi)
# - pyotp (likewise)
#
# usage: ./otp-agent name-of-connection
#
# The connection will be activated and when networkmanager asks for a secret,
# it will be provided. If the secret isn't known yet, it will be asked and
# stored with the secretstorage api (so in e.g. your gnome keyring)
import dbus.mainloop.glib
from gi.repository import GObject
import NetworkManager
import pyotp
import traceback
import secretstorage
import sys
def main():
print("Connecting to %s" % sys.argv[1])
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
loop = GObject.MainLoop()
agent = SecretAgent(loop)
for connection in NetworkManager.Settings.ListConnections():
settings = connection.GetSettings()['connection']
if settings['id'] == sys.argv[1]:
NetworkManager.NetworkManager.ActivateConnection(connection, "/", "/")
loop.run()
break
else:
print("Connection %s not found" % sys.argv[1])
class SecretAgent(NetworkManager.SecretAgent):
def __init__(self, loop):
self.loop = loop
self.collection = secretstorage.get_default_collection(secretstorage.dbus_init())
super(SecretAgent, self).__init__('net.seveas.otp-agent')
def GetSecrets(self, settings, connection, setting_name, hints, flags):
try:
print("NetworkManager is asking us for a secret")
if setting_name != 'vpn':
return {}
attrs = {
'xdg:schema': 'net.seveas.otp-agent',
'hostname': settings['vpn']['data']['remote'],
}
items = list(self.collection.search_items(attrs))
if not items:
print("No secrets found yet, asking user")
secret = input("Enter secret code for %s: " % settings['vpn']['data']['remote'])
self.collection.create_item(settings['vpn']['data']['remote'], attrs, secret)
items = list(self.collection.search_items(attrs))
else:
print("Found secret key, generating otp code")
secret = items[0].get_secret().decode('ascii')
otp = pyotp.TOTP(secret).now()
print("otp code: %s" % otp)
return {setting_name: {'secrets': {'password': otp}}}
except:
import traceback
traceback.print_exc()
return {}
finally:
self.loop.quit()
if __name__ == '__main__':
main()
"""
Display all visible SSIDs
"""
import NetworkManager
for dev in NetworkManager.NetworkManager.GetDevices():
if dev.DeviceType != NetworkManager.NM_DEVICE_TYPE_WIFI:
continue
for ap in dev.GetAccessPoints():
print('%-30s %dMHz %d%%' % (ap.Ssid, ap.Frequency, ap.Strength))
"""
Show and monitor available access points
"""
from gi.repository import GObject
import dbus.mainloop.glib
import NetworkManager
# Cache the ssids, as the SSid property will be unavailable when an AP
# disappears
ssids = {}
def main():
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
# Listen for added and removed access points
for dev in NetworkManager.Device.all():
if dev.DeviceType == NetworkManager.NM_DEVICE_TYPE_WIFI:
dev.OnAccessPointAdded(ap_added)
dev.OnAccessPointRemoved(ap_removed)
for ap in NetworkManager.AccessPoint.all():
try:
ssids[ap.object_path] = ap.Ssid
print("* %-30s %s %sMHz %s%%" % (ap.Ssid, ap.HwAddress, ap.Frequency, ap.Strength))
ap.OnPropertiesChanged(ap_propchange)
except NetworkManager.ObjectVanished:
pass
GObject.MainLoop().run()
def ap_added(dev, interface, signal, access_point):
ssids[access_point.object_path] = access_point.Ssid
print("+ %-30s %s %sMHz %s%%" % (access_point.Ssid, access_point.HwAddress, access_point.Frequency, access_point.Strength))
access_point.OnPropertiesChanged(ap_propchange)
def ap_removed(dev, interface, signal, access_point):
print("- %-30s" % ssids.pop(access_point.object_path))
def ap_propchange(ap, interface, signal, properties):
if 'Strength' in properties:
print(" %-30s %s %sMHz %s%%" % (ap.Ssid, ap.HwAddress, ap.Frequency, properties['Strength']))
if __name__ == '__main__':
main()
Metadata-Version: 1.1
Name: python-networkmanager
Version: 2.0.1
Summary: Easy communication with NetworkManager
Home-page: http://github.com/seveas/python-networkmanager
Author: Dennis Kaarsemaker
Author-email: dennis@kaarsemaker.net
License: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: zlib/libpng License
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: System :: Networking
COPYING
MANIFEST.in
NetworkManager.py
README
setup.py
docs/Makefile
docs/conf.py
docs/index.rst
examples/activate_connection.py
examples/add_connection.py
examples/connection_detail.py
examples/info.py
examples/listener.py
examples/n-m
examples/openvpn_over_ssh.py
examples/otp-agent
examples/ssids.py
examples/wifi_monitor.py
python_networkmanager.egg-info/PKG-INFO
python_networkmanager.egg-info/SOURCES.txt
python_networkmanager.egg-info/dependency_links.txt
python_networkmanager.egg-info/requires.txt
python_networkmanager.egg-info/top_level.txt
test/test_accesspoint.py
test/test_activeconnection.py
test/test_agentmanager.py
test/test_connection.py
test/test_connection_addremove.py
test/test_devices.py
test/test_ipconfig.py
test/test_networkmanager.py
test/test_settings.py
\ No newline at end of file
[egg_info]
tag_build =
tag_date = 0
tag_svn_revision = 0
#!/usr/bin/python
from distutils.core import setup
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
setup(name = "python-networkmanager",
version = "0.9.10",
version = "2.0.1",
author = "Dennis Kaarsemaker",
author_email = "dennis@kaarsemaker.net",
url = "http://github.com/seveas/python-networkmanager",
description = "Easy communication with NetworkManager",
py_modules = ["NetworkManager"],
scripts = ["n-m"],
install_requires = ["dbus-python", "six"],
classifiers = [
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU General Public License (GPL)',
'License :: OSI Approved :: zlib/libpng License',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Topic :: System :: Networking',
]
)
from test import *
class AccessPointTest(TestCase):
def test_accesspoints(self):
for dev in NetworkManager.NetworkManager.Devices:
if isinstance(dev, NetworkManager.Wireless):
for ap in dev.AccessPoints:
self.assertIsInstance(ap.Flags, int)
# Frequencies from https://en.wikipedia.org/wiki/List_of_WLAN_channels
f = ap.Frequency
if not (
(f > 2400 and f < 2500) or
(f > 3650 and f < 3700) or
(f > 4900 and f < 6000)):
self.fail("Frequency is not a valid wifi frequency")
self.assertIsMacAddress(ap.HwAddress)
self.assertIsInstance(ap.LastSeen, int)
self.assertIsInstance(ap.MaxBitrate, int)
self.assertIsInstance(ap.WpaFlags, int)
self.assertIsInstance(ap.RsnFlags, int)
self.assertLess(ap.Strength, 100)
self.assertIsInstance(ap.Ssid, six.text_type)
self.assertIn(ap.Mode, (NetworkManager.NM_802_11_MODE_ADHOC, NetworkManager.NM_802_11_MODE_INFRA, NetworkManager.NM_802_11_MODE_AP))
if __name__ == '__main__':
unittest.main()
from test import *
class ActiveConnectionTest(TestCase):
def test_properties(self):
for conn in NetworkManager.NetworkManager.ActiveConnections:
self.assertIsInstance(conn.Connection, NetworkManager.Connection)
for device in conn.Devices:
self.assertIsInstance(device, NetworkManager.Device)
if conn.Connection.GetSettings()['connection']['type'] == '802-11-wireless':
self.assertIsInstance(conn.SpecificObject, NetworkManager.AccessPoint)
if conn.Vpn:
self.assertIsInstance(conn, NetworkManager.VPNConnection)
self.assertIsInstance(conn.Banner, six.text_type)
self.assertIsInstance(conn.SpecificObject, NetworkManager.ActiveConnection)
self.assertTrue(conn.State == NetworkManager.NM_ACTIVE_CONNECTION_STATE_ACTIVATED)
self.assertIsInstance(conn.Ip4Config, NetworkManager.IP4Config)
self.assertIsInstance(conn.Ip6Config, (NetworkManager.IP6Config, type(None)))
self.assertIsInstance(conn.Dhcp4Config, (NetworkManager.DHCP4Config, type(None)))
self.assertIsInstance(conn.Dhcp6Config, (NetworkManager.DHCP6Config, type(None)))
if conn.Master != None:
self.assertIsInstance(conn.Master, NetworkManager.Device)
self.assertEqual(conn.Master, conn.SpecificObject.Devices[0])
if __name__ == '__main__':
unittest.main()
from test import *
class AgentManagerTest(TestCase):
def test_registration(self):
NetworkManager.AgentManager.Register('python-network-manager-test')
NetworkManager.AgentManager.Unregister()
if __name__ == '__main__':
unittest.main()
from test import *
class ConnectionTest(TestCase):
def test_settings(self):
for connection in NetworkManager.Settings.ListConnections():
settings = connection.GetSettings()
self.assertIn(settings['connection']['type'], settings)
secrets = connection.GetSecrets()
for key in settings:
self.assertIn(key, secrets)
if 'ipv4' in settings:
for address, prefix, gateway in settings['ipv4']['addresses']:
self.assertIsIpAddress(address)
self.assertIsIpAddress(gateway)
if 'ipv6' in settings:
for address, prefix, gateway in settings['ipv6']['addresses']:
self.assertIsIpAddress(address)
self.assertIsIpAddress(gateway)
def test_update(self):
active = [x.Connection for x in NetworkManager.NetworkManager.ActiveConnections]
for connection in NetworkManager.Settings.Connections:
if connection in active:
continue
settings = connection.GetSettings()
connection.Update(settings)
# FIXME: this causes assertion failures in n-m, which cause the dbus call to hang
#settings['connection']['timestamp'] -= 1
#connection.UpdateUnsaved(settings)
#self.assertTrue(connection.Unsaved)
#print("Saving")
#connection.Save()
#print("Saved")
#self.assertFalse(connection.Unsaved)
break
def test_secrets(self):
active = [x.Connection for x in NetworkManager.NetworkManager.ActiveConnections]
key = '802-11-wireless-security'
for connection in NetworkManager.Settings.Connections:
if connection in active:
continue
settings = connection.GetSettings()
if key not in settings:
continue
secrets = connection.GetSecrets()
if not secrets[key]:
continue
settings[key].update(secrets[key])
connection.ClearSecrets()
secrets = connection.GetSecrets()
self.assertEqual(secrets[key], {})
connection.Update(settings)
secrets = connection.GetSecrets()
self.assertNotEqual(secrets[key], {})
break
if __name__ == '__main__':
unittest.main()
from test import *
class ConnectionAddRemoveTest(TestCase):
def test_activate(self):
active = NetworkManager.NetworkManager.ActiveConnections[0]
ap = active.SpecificObject
conn = active.Connection
dev = active.Devices[0]
NetworkManager.NetworkManager.DeactivateConnection(active)
self.waitForDisconnection()
NetworkManager.NetworkManager.ActivateConnection(conn, dev, ap)
self.waitForConnection()
def test_delete_addactivate(self):
active = NetworkManager.NetworkManager.ActiveConnections[0]
ap = active.SpecificObject
conn = active.Connection
dev = active.Devices[0]
settings = conn.GetSettings()
typ = settings['connection']['type']
if 'security' in settings[typ]:
key2 = settings[typ]['security']
settings[key2].update(conn.GetSecrets(key2)[key2])
conn.Delete()
self.waitForDisconnection()
conn, active = NetworkManager.NetworkManager.AddAndActivateConnection(settings, dev, ap)
self.assertIsInstance(conn, NetworkManager.Connection)
self.assertIsInstance(active, NetworkManager.ActiveConnection)
self.waitForConnection()
def test_delete_add_activate(self):
active = NetworkManager.NetworkManager.ActiveConnections[0]
ap = active.SpecificObject
conn = active.Connection
dev = active.Devices[0]
settings = conn.GetSettings()
typ = settings['connection']['type']
if 'security' in settings[typ]:
key2 = settings[typ]['security']
settings[key2].update(conn.GetSecrets(key2)[key2])
conn.Delete()
self.waitForDisconnection()
conn = NetworkManager.Settings.AddConnection(settings)
self.assertIsInstance(conn, NetworkManager.Connection)
NetworkManager.NetworkManager.ActivateConnection(conn, dev, ap)
self.waitForConnection()
if __name__ == '__main__':
unittest.main()
from test import *
class DeviceTest(TestCase):
def test_devices(self):
for device in NetworkManager.NetworkManager.Devices:
self.assertIsStrictSubclass(type(device), NetworkManager.Device)
if device.Dhcp4Config:
self.assertIsInstance(device.Dhcp4Config, NetworkManager.DHCP4Config)
if device.Dhcp6Config:
self.assertIsInstance(device.Dhcp6Config, NetworkManager.DHCP6Config)
if device.Ip4Config:
self.assertIsInstance(device.Ip4Config, NetworkManager.IP4Config)
if device.Ip6Config:
self.assertIsInstance(device.Ip6Config, NetworkManager.IP6Config)
if device.Ip4Address:
self.assertIsIpAddress(device.Ip4Address)
if hasattr(device, 'HwAddress') and device.HwAddress:
self.assertIsMacAddress(device.HwAddress)
if hasattr(device, 'PermHwAddress') and device.PermHwAddress:
self.assertIsMacAddress(device.PermHwAddress)
if device.DeviceType == NetworkManager.NM_DEVICE_TYPE_WIFI:
for ap in device.AccessPoints:
self.assertIsInstance(ap, NetworkManager.AccessPoint)
device.RequestScan({})
elif device.DeviceType == NetworkManager.NM_DEVICE_TYPE_ETHERNET:
self.assertIn(device.Carrier, (True, False))
elif device.DeviceType == NetworkManager.NM_DEVICE_TYPE_GENERIC:
self.assertIsInstance(device.TypeDescription, six.text_type)
elif device.DeviceType == NetworkManager.NM_DEVICE_TYPE_TUN:
if device.Owner != -1:
import pwd
pwd.getpwuid(device.Owner)
else:
self.fail("I don't know how to test %s devices" % type(device).__name__)
if __name__ == '__main__':
unittest.main()
from test import *
class IpConfigTest(TestCase):
def test_configs(self):
for device in NetworkManager.NetworkManager.Devices:
if device.State != NetworkManager.NM_DEVICE_STATE_ACTIVATED:
continue
self.do_check(device)
for connection in NetworkManager.NetworkManager.ActiveConnections:
self.do_check(connection)
def do_check(self, thing):
if thing.Dhcp4Config:
self.assertIsInstance(thing.Dhcp4Config, NetworkManager.DHCP4Config)
self.assertIsInstance(thing.Dhcp4Config.Options, dict)
o = thing.Dhcp4Config.Options
self.assertIsInstance(o['domain_name_servers'], list)
self.assertIsInstance(o['ntp_servers'], list)
self.assertIsIpAddress(o['ip_address'])
for key in o:
if key.endswith('_requested'):
self.assertTrue(o[key])
if thing.Dhcp6Config:
self.assertIsInstance(thing.Dhcp6Config, NetworkManager.DHCP6Config)
self.assertIsInstance(thing.Dhcp6Config.Options, dict)
for c in (thing.Ip4Config, thing.Ip6Config):
if not c:
continue
for addr, prefix, gateway in c.Addresses:
self.assertIsIpAddress(addr)
self.assertIsIpAddress(gateway)
self.assertIsIpNetwork(addr, prefix)
for data in c.AddressData:
self.assertIsIpAddress(data['address'])
self.assertIsIpNetwork(data['address'], data['prefix'])
if 'peer' in data:
self.assertIsIpAddress(data['peer'])
if c.Gateway:
self.assertIsIpAddress(c.Gateway)
for addr in c.Nameservers:
self.assertIsIpAddress(addr)
for addr in getattr(c, 'WinsServers', []):
self.assertIsIpAddress(addr)
for dest, prefix, next_hop, metric in c.Routes:
self.assertIsIpNetwork(dest, prefix)
self.assertIsIpAddress(next_hop)
self.assertLessEqual(metric, 1000)
for data in c.RouteData:
self.assertIsIpNetwork(data['dest'], data['prefix'])
self.assertIsIpAddress(data['next-hop'])
self.assertLessEqual(data['metric'], 1000)
if __name__ == '__main__':
unittest.main()
from test import *
class NetworkManagerTest(TestCase):
def test_properties(self):
self.assertIsInstance(NetworkManager.NetworkManager.NetworkingEnabled, bool)
self.assertIsInstance(NetworkManager.NetworkManager.Metered, int)
self.assertIsInstance(NetworkManager.NetworkManager.Version, six.string_types)
self.assertIsInstance(NetworkManager.NetworkManager.ActiveConnections, list)
for conn in NetworkManager.NetworkManager.ActiveConnections:
self.assertIsInstance(conn, NetworkManager.ActiveConnection)
self.assertIsInstance(NetworkManager.NetworkManager.Devices, list)
for dev in NetworkManager.NetworkManager.Devices:
self.assertIsInstance(dev, NetworkManager.Device)
self.assertIsInstance(NetworkManager.NetworkManager.PrimaryConnection, NetworkManager.ActiveConnection)
@unittest.skipUnless(have_permission('sleep-wake'), "Not allowed to make networkmanager sleep")
def test_sleep(self):
NetworkManager.NetworkManager.Sleep(True)
self.assertRaisesDBus('AlreadyAsleepOrAwake', NetworkManager.NetworkManager.Sleep, True)
NetworkManager.NetworkManager.Sleep(False)
self.assertRaisesDBus('AlreadyAsleepOrAwake', NetworkManager.NetworkManager.Sleep, False)
self.waitForConnection()
def test_enable(self):
NetworkManager.NetworkManager.Enable(False)
self.assertRaisesDBus('AlreadyEnabledOrDisabled', NetworkManager.NetworkManager.Enable, False)
NetworkManager.NetworkManager.Enable(True)
self.assertRaisesDBus('AlreadyEnabledOrDisabled', NetworkManager.NetworkManager.Enable, True)
self.waitForConnection()
@unittest.skipUnless(os.getuid() == 0, "Must be root to modify logging")
def test_logging(self):
level1, domains = NetworkManager.NetworkManager.GetLogging()
self.assertIn(level1, ['ERR', 'WARN', 'INFO', 'DEBUG', 'TRACE'])
self.assertIn('PLATFORM', domains)