forked from ash-vd/python-networkmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
59 lines (47 loc) · 1.96 KB
/
__init__.py
File metadata and controls
59 lines (47 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Set this variable in your environment if you understand that
#
# THE TESTS WILL MESS WITH YOUR COMPUTER!
#
# You will repeatedly go offline and it will attempt to add and delete
# connections, change the hostname and more nasty things.
import os
if 'NM_TESTS' not in os.environ:
print("Cowardly refusing to run tests")
os._exit(1)
import dbus
import ipaddress
import six
import time
import unittest
import NetworkManager
class TestCase(unittest.TestCase):
def assertRaisesDBus(self, exception, func, *args, **kwargs):
if '.' not in exception:
exception = 'org.freedesktop.NetworkManager.' + exception
with self.assertRaises(dbus.exceptions.DBusException) as cm:
func(*args, **kwargs)
self.assertEqual(cm.exception.get_dbus_name(), exception)
def assertIsStrictSubclass(self, klass1, klass2):
self.assertTrue(issubclass(klass1, klass2) and klass1 != klass2)
def assertIsIpAddress(self, ip):
try:
ipaddress.ip_address(six.text_type(ip))
except ValueError as e:
raise self.failureException(str(e))
def assertIsIpNetwork(self, ip, prefix):
try:
ipaddress.ip_network((ip, prefix), strict=False)
except ValueError as e:
raise self.failureException(str(e))
def assertIsMacAddress(self, address):
self.assertRegex(address, '^[0-9a-fA-F]{2}(?::[0-9a-fA-F]{2}){5}$', '%s is not a mac address' % address)
def waitForConnection(self):
while NetworkManager.NetworkManager.State < NetworkManager.NM_STATE_CONNECTED_LOCAL:
time.sleep(0.5)
def waitForDisconnection(self):
while NetworkManager.NetworkManager.State >= NetworkManager.NM_STATE_CONNECTED_LOCAL:
time.sleep(0.5)
permissions = NetworkManager.NetworkManager.GetPermissions()
def have_permission(permission):
permission = 'org.freedesktop.NetworkManager.' + permission
return permissions.get(permission, None) == 'yes'