|
| 1 | +from test import * |
| 2 | + |
| 3 | +class IpConfigTest(TestCase): |
| 4 | + def test_configs(self): |
| 5 | + for device in NetworkManager.NetworkManager.Devices: |
| 6 | + if device.State != NetworkManager.NM_DEVICE_STATE_ACTIVATED: |
| 7 | + continue |
| 8 | + self.do_check(device) |
| 9 | + for connection in NetworkManager.NetworkManager.ActiveConnections: |
| 10 | + self.do_check(connection) |
| 11 | + |
| 12 | + def do_check(self, thing): |
| 13 | + if thing.Dhcp4Config: |
| 14 | + self.assertIsInstance(thing.Dhcp4Config, NetworkManager.DHCP4Config) |
| 15 | + self.assertIsInstance(thing.Dhcp4Config.Options, dict) |
| 16 | + o = thing.Dhcp4Config.Options |
| 17 | + self.assertIsInstance(o['domain_name_servers'], list) |
| 18 | + self.assertIsInstance(o['ntp_servers'], list) |
| 19 | + self.assertIsIpAddress(o['ip_address']) |
| 20 | + for key in o: |
| 21 | + if key.endswith('_requested'): |
| 22 | + self.assertTrue(o[key]) |
| 23 | + if thing.Dhcp6Config: |
| 24 | + self.assertIsInstance(thing.Dhcp6Config, NetworkManager.DHCP6Config) |
| 25 | + self.assertIsInstance(thing.Dhcp6Config.Options, dict) |
| 26 | + for c in (thing.Ip4Config, thing.Ip6Config): |
| 27 | + if not c: |
| 28 | + continue |
| 29 | + for addr, prefix, gateway in c.Addresses: |
| 30 | + self.assertIsIpAddress(addr) |
| 31 | + self.assertIsIpAddress(gateway) |
| 32 | + self.assertIsIpNetwork(addr, prefix) |
| 33 | + for data in c.AddressData: |
| 34 | + self.assertIsIpAddress(data['address']) |
| 35 | + self.assertIsIpNetwork(data['address'], data['prefix']) |
| 36 | + if 'peer' in data: |
| 37 | + self.assertIsIpAddress(data['peer']) |
| 38 | + if c.Gateway: |
| 39 | + self.assertIsIpAddress(c.Gateway) |
| 40 | + for addr in c.Nameservers: |
| 41 | + self.assertIsIpAddress(addr) |
| 42 | + for addr in getattr(c, 'WinsServers', []): |
| 43 | + self.assertIsIpAddress(addr) |
| 44 | + for dest, prefix, next_hop, metric in c.Routes: |
| 45 | + self.assertIsIpNetwork(dest, prefix) |
| 46 | + self.assertIsIpAddress(next_hop) |
| 47 | + self.assertLessEqual(metric, 1000) |
| 48 | + for data in c.RouteData: |
| 49 | + self.assertIsIpNetwork(data['dest'], data['prefix']) |
| 50 | + self.assertIsIpAddress(data['next-hop']) |
| 51 | + self.assertLessEqual(data['metric'], 1000) |
| 52 | + |
| 53 | +if __name__ == '__main__': |
| 54 | + unittest.main() |
0 commit comments