dhcp_test.py (1897B)
1 #! /usr/bin/python3 2 3 import unittest 4 import sys, os 5 6 import iwd 7 from iwd import IWD 8 from iwd import PSKAgent 9 from iwd import NetworkType 10 from config import ctx 11 import testutil 12 13 from validation import validate 14 15 class Test(unittest.TestCase): 16 def test_connection_success(self): 17 wd = IWD(True, '/tmp/dhcp') 18 19 # dev1, dev3, and dev4 are all AP's 20 # The configured IP range only supports 2 subnets, so dev4 should fail 21 # to start AP. 22 dev1, dev2, dev3, dev4 = wd.list_devices(4) 23 24 dev1.start_ap('TestAP2', "Password2") 25 dev3.start_ap('TestAP3', 'Password3') 26 27 with self.assertRaises(iwd.AlreadyExistsEx): 28 dev4.start_ap('TestAP4', 'Password4') 29 30 validate(wd, dev2, dev1, 'TestAP2', 'Password2', ip_checks=False) 31 32 network = dev2.get_ordered_network('TestAP2', full_scan=True) 33 34 try: 35 testutil.test_ip_address_match(dev1.name, "192.168.80.1") 36 testutil.test_ip_address_match(dev2.name, "192.168.80.2") 37 ip = "192.168.80.1" 38 except: 39 testutil.test_ip_address_match(dev1.name, "192.168.80.17") 40 testutil.test_ip_address_match(dev2.name, "192.168.80.18") 41 ip = "192.168.80.17" 42 43 dev2.disconnect() 44 45 condition = 'not obj.connected' 46 wd.wait_for_object_condition(network.network_object, condition) 47 48 # This should release the IP */ 49 dev1.stop_ap() 50 51 # This should now succeed and the IP should match the old IP dev1 52 # got initially. 53 dev4.start_ap('TestAP4', 'Password4') 54 55 testutil.test_ip_address_match(dev4.name, ip) 56 57 dev1.stop_ap() 58 dev3.stop_ap() 59 dev4.stop_ap() 60 61 @classmethod 62 def setUpClass(cls): 63 pass 64 65 @classmethod 66 def tearDownClass(cls): 67 IWD.clear_storage() 68 69 if __name__ == '__main__': 70 unittest.main(exit=True)