From 4545f80e58bc941fa40cf2d7d2fd45fb830a9650 Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Mon, 22 Aug 2022 10:01:48 -0700 Subject: [PATCH] auto-t: update tests to use set_address/group_neighbors This reduces the big blocks of copied code with a few function calls. --- .../testFT-8021x-roam/connection_test.py | 24 ++--------- autotests/testFT-FILS/connection_test.py | 22 ++-------- autotests/testPSK-roam/connection_test.py | 22 ++-------- .../testPSK-roam/roam_ap_disconnect_test.py | 12 ++---- autotests/testPreauth-roam/connection_test.py | 13 +----- autotests/testRoamRetry/fast_retry_test.py | 15 +------ autotests/testRoamRetry/stop_retry_test.py | 15 +------ autotests/testSAE-roam/connection_test.py | 40 ++----------------- 8 files changed, 19 insertions(+), 144 deletions(-) diff --git a/autotests/testFT-8021x-roam/connection_test.py b/autotests/testFT-8021x-roam/connection_test.py index 6853bdb0..d3f8e2c6 100644 --- a/autotests/testFT-8021x-roam/connection_test.py +++ b/autotests/testFT-8021x-roam/connection_test.py @@ -66,28 +66,10 @@ class Test(unittest.TestCase): cls.bss_hostapd = [ HostapdCLI(config='ft-eap-ccmp-1.conf'), HostapdCLI(config='ft-eap-ccmp-2.conf') ] - # Set interface addresses to those expected by hostapd config files - os.system('ip link set dev "' + cls.bss_hostapd[0].ifname + '" down') - os.system('ip link set dev "' + cls.bss_hostapd[0].ifname + \ - '" address 12:00:00:00:00:01 up') - os.system('ip link set dev "' + cls.bss_hostapd[1].ifname + '" down') - os.system('ip link set dev "' + cls.bss_hostapd[1].ifname + \ - '" address 12:00:00:00:00:02 up') + cls.bss_hostapd[0].set_address('12:00:00:00:00:01') + cls.bss_hostapd[1].set_address('12:00:00:00:00:02') - cls.bss_hostapd[0].reload() - cls.bss_hostapd[0].wait_for_event("AP-ENABLED") - cls.bss_hostapd[1].reload() - cls.bss_hostapd[1].wait_for_event("AP-ENABLED") - - # Fill in the neighbor AP tables in both BSSes. By default each - # instance knows only about current BSS, even inside one hostapd - # process. - # FT still works without the neighbor AP table but neighbor reports - # have to be disabled in the .conf files - cls.bss_hostapd[0].set_neighbor('12:00:00:00:00:02', 'TestFT', - '1200000000028f0000005102060603000000') - cls.bss_hostapd[1].set_neighbor('12:00:00:00:00:01', 'TestFT', - '1200000000018f0000005101060603000000') + HostapdCLI.group_neighbors(*cls.bss_hostapd) @classmethod def tearDownClass(cls): diff --git a/autotests/testFT-FILS/connection_test.py b/autotests/testFT-FILS/connection_test.py index c1deb77c..b1ec42e0 100644 --- a/autotests/testFT-FILS/connection_test.py +++ b/autotests/testFT-FILS/connection_test.py @@ -128,26 +128,10 @@ class Test(unittest.TestCase): cls.bss_hostapd = [ HostapdCLI(config='ft-eap-ccmp-1.conf'), HostapdCLI(config='ft-eap-ccmp-2.conf') ] - # Set interface addresses to those expected by hostapd config files - os.system('ip link set dev "' + cls.bss_hostapd[0].ifname + '" down') - os.system('ip link set dev "' + cls.bss_hostapd[0].ifname + '" addr 12:00:00:00:00:01 up') - os.system('ip link set dev "' + cls.bss_hostapd[1].ifname + '" down') - os.system('ip link set dev "' + cls.bss_hostapd[1].ifname + '" addr 12:00:00:00:00:02 up') + cls.bss_hostapd[0].set_address('12:00:00:00:00:01') + cls.bss_hostapd[1].set_address('12:00:00:00:00:02') - cls.bss_hostapd[0].reload() - cls.bss_hostapd[0].wait_for_event("AP-ENABLED") - cls.bss_hostapd[1].reload() - cls.bss_hostapd[1].wait_for_event("AP-ENABLED") - - # Fill in the neighbor AP tables in both BSSes. By default each - # instance knows only about current BSS, even inside one hostapd - # process. - # FT still works without the neighbor AP table but neighbor reports - # have to be disabled in the .conf files - cls.bss_hostapd[0].set_neighbor('12:00:00:00:00:02', 'TestFT', - '1200000000028f0000005102060603000000') - cls.bss_hostapd[1].set_neighbor('12:00:00:00:00:01', 'TestFT', - '1200000000018f0000005101060603000000') + HostapdCLI.group_neighbors(*cls.bss_hostapd) @classmethod def tearDownClass(cls): diff --git a/autotests/testPSK-roam/connection_test.py b/autotests/testPSK-roam/connection_test.py index 364f75c2..2206f120 100644 --- a/autotests/testPSK-roam/connection_test.py +++ b/autotests/testPSK-roam/connection_test.py @@ -199,26 +199,10 @@ class Test(unittest.TestCase): cls.rule2.source = rad0.addresses[0] cls.rule2.signal = -7000 - # Set interface addresses to those expected by hostapd config files - os.system('ip link set dev "' + cls.bss_hostapd[0].ifname + '" down') - os.system('ip link set dev "' + cls.bss_hostapd[0].ifname + '" addr 12:00:00:00:00:01 up') - os.system('ip link set dev "' + cls.bss_hostapd[1].ifname + '" down') - os.system('ip link set dev "' + cls.bss_hostapd[1].ifname + '" addr 12:00:00:00:00:02 up') + cls.bss_hostapd[0].set_address('12:00:00:00:00:01') + cls.bss_hostapd[1].set_address('12:00:00:00:00:02') - cls.bss_hostapd[0].reload() - cls.bss_hostapd[0].wait_for_event("AP-ENABLED") - cls.bss_hostapd[1].reload() - cls.bss_hostapd[1].wait_for_event("AP-ENABLED") - - # Fill in the neighbor AP tables in both BSSes. By default each - # instance knows only about current BSS, even inside one hostapd - # process. - # FT still works without the neighbor AP table but neighbor reports - # have to be disabled in the .conf files - cls.bss_hostapd[0].set_neighbor('12:00:00:00:00:02', 'TestFT', - '1200000000028f0000005102060603000000') - cls.bss_hostapd[1].set_neighbor('12:00:00:00:00:01', 'TestFT', - '1200000000018f0000005101060603000000') + HostapdCLI.group_neighbors(*cls.bss_hostapd) @classmethod def tearDownClass(cls): diff --git a/autotests/testPSK-roam/roam_ap_disconnect_test.py b/autotests/testPSK-roam/roam_ap_disconnect_test.py index 760c25fa..416541ce 100644 --- a/autotests/testPSK-roam/roam_ap_disconnect_test.py +++ b/autotests/testPSK-roam/roam_ap_disconnect_test.py @@ -46,10 +46,7 @@ class Test(unittest.TestCase): self.validate() def test_ap_disconnect_neighbors(self): - self.bss_hostapd[0].set_neighbor('12:00:00:00:00:02', 'TestFT', - '1200000000028f0000005102060603000000') - self.bss_hostapd[1].set_neighbor('12:00:00:00:00:01', 'TestFT', - '1200000000018f0000005101060603000000') + HostapdCLI.group_neighbors(*self.bss_hostapd) self.validate() @@ -85,11 +82,8 @@ class Test(unittest.TestCase): cls.rule0.signal = -8000 cls.rule0.enabled = True - # Set interface addresses to those expected by hostapd config files - os.system('ip link set dev "' + cls.bss_hostapd[0].ifname + '" down') - os.system('ip link set dev "' + cls.bss_hostapd[0].ifname + '" addr 12:00:00:00:00:01 up') - os.system('ip link set dev "' + cls.bss_hostapd[1].ifname + '" down') - os.system('ip link set dev "' + cls.bss_hostapd[1].ifname + '" addr 12:00:00:00:00:02 up') + cls.bss_hostapd[0].set_address('12:00:00:00:00:01') + cls.bss_hostapd[1].set_address('12:00:00:00:00:02') @classmethod def tearDownClass(cls): diff --git a/autotests/testPreauth-roam/connection_test.py b/autotests/testPreauth-roam/connection_test.py index 26475698..3c8fa0bb 100644 --- a/autotests/testPreauth-roam/connection_test.py +++ b/autotests/testPreauth-roam/connection_test.py @@ -17,18 +17,7 @@ class Test(unittest.TestCase): bss0_addr = bss_hostapd[0].bssid bss1_addr = bss_hostapd[1].bssid - # Fill in the neighbor AP tables in both BSSes. By default each - # instance knows only about current BSS, even inside one hostapd - # process. - # Roaming still works without the neighbor AP table but neighbor - # reports have to be disabled in the .conf files - bss0_nr = ''.join(bss0_addr.split(':')) + \ - '8f0000005101060603000000' - bss1_nr = ''.join(bss1_addr.split(':')) + \ - '8f0000005102060603000000' - - bss_hostapd[0].set_neighbor(bss1_addr, 'TestPreauth', bss1_nr) - bss_hostapd[1].set_neighbor(bss0_addr, 'TestPreauth', bss0_nr) + HostapdCLI.group_neighbors(*bss_hostapd) wd = IWD(True) diff --git a/autotests/testRoamRetry/fast_retry_test.py b/autotests/testRoamRetry/fast_retry_test.py index b45daada..373f3d45 100644 --- a/autotests/testRoamRetry/fast_retry_test.py +++ b/autotests/testRoamRetry/fast_retry_test.py @@ -36,20 +36,7 @@ class Test(unittest.TestCase): rule1.bidirectional = True rule1.enabled = True - # Fill in the neighbor AP tables in both BSSes. By default each - # instance knows only about current BSS, even inside one hostapd - # process. - # Roaming still works without the neighbor AP table but neighbor - # reports have to be disabled in the .conf files - bss0_nr = ''.join(bss_radio[0].addresses[0].split(':')) + \ - '8f0000005101060603000000' - bss1_nr = ''.join(bss_radio[1].addresses[0].split(':')) + \ - '8f0000005102060603000000' - - bss_hostapd[0].set_neighbor(bss_radio[1].addresses[0], 'TestRoamRetry', - bss1_nr) - bss_hostapd[1].set_neighbor(bss_radio[0].addresses[0], 'TestRoamRetry', - bss0_nr) + HostapdCLI.group_neighbors(*bss_hostapd) # Start in the vicinity of BSS 0, check that iwd connects to BSS 0 rule0.signal = -2000 diff --git a/autotests/testRoamRetry/stop_retry_test.py b/autotests/testRoamRetry/stop_retry_test.py index 3957d12d..b5eb6f77 100644 --- a/autotests/testRoamRetry/stop_retry_test.py +++ b/autotests/testRoamRetry/stop_retry_test.py @@ -35,20 +35,7 @@ class Test(unittest.TestCase): rule1.bidirectional = True rule1.enabled = True - # Fill in the neighbor AP tables in both BSSes. By default each - # instance knows only about current BSS, even inside one hostapd - # process. - # Roaming still works without the neighbor AP table but neighbor - # reports have to be disabled in the .conf files - bss0_nr = ''.join(bss_radio[0].addresses[0].split(':')) + \ - '8f0000005101060603000000' - bss1_nr = ''.join(bss_radio[1].addresses[0].split(':')) + \ - '8f0000005102060603000000' - - bss_hostapd[0].set_neighbor(bss_radio[1].addresses[0], 'TestRoamRetry', - bss1_nr) - bss_hostapd[1].set_neighbor(bss_radio[0].addresses[0], 'TestRoamRetry', - bss0_nr) + HostapdCLI.group_neighbors(*bss_hostapd) # Start in the vicinity of BSS 0, check that iwd connects to BSS 0 rule0.signal = -2000 diff --git a/autotests/testSAE-roam/connection_test.py b/autotests/testSAE-roam/connection_test.py index 2c8cd799..ac44b4b2 100644 --- a/autotests/testSAE-roam/connection_test.py +++ b/autotests/testSAE-roam/connection_test.py @@ -120,43 +120,11 @@ class Test(unittest.TestCase): HostapdCLI(config='ft-sae-2.conf'), HostapdCLI(config='ft-psk-3.conf') ] - ctx.start_process(['ip', 'link', 'set', 'dev', cls.bss_hostapd[0].ifname, 'down']).wait() - ctx.start_process(['ip', 'link', 'set', 'dev', cls.bss_hostapd[0].ifname, \ - 'addr', '12:00:00:00:00:01', 'up']).wait() - ctx.start_process(['ip', 'link', 'set', 'dev', cls.bss_hostapd[1].ifname, 'down']).wait() - ctx.start_process(['ip', 'link', 'set', 'dev', cls.bss_hostapd[1].ifname, \ - 'addr', '12:00:00:00:00:02', 'up']).wait() - ctx.start_process(['ip', 'link', 'set', 'dev', cls.bss_hostapd[2].ifname, 'down']).wait() - ctx.start_process(['ip', 'link', 'set', 'dev', cls.bss_hostapd[2].ifname, \ - 'addr', '12:00:00:00:00:03', 'up']).wait() + cls.bss_hostapd[0].set_address('12:00:00:00:00:01') + cls.bss_hostapd[1].set_address('12:00:00:00:00:02') + cls.bss_hostapd[2].set_address('12:00:00:00:00:03') - # Set interface addresses to those expected by hostapd config files - cls.bss_hostapd[0].reload() - cls.bss_hostapd[0].wait_for_event("AP-ENABLED") - cls.bss_hostapd[1].reload() - cls.bss_hostapd[1].wait_for_event("AP-ENABLED") - cls.bss_hostapd[2].reload() - cls.bss_hostapd[2].wait_for_event("AP-ENABLED") - - # Fill in the neighbor AP tables in both BSSes. By default each - # instance knows only about current BSS, even inside one hostapd - # process. - # FT still works without the neighbor AP table but neighbor reports - # have to be disabled in the .conf files - cls.bss_hostapd[0].set_neighbor('12:00:00:00:00:02', 'TestFT', - '1200000000028f0000005102060603000000') - cls.bss_hostapd[0].set_neighbor('12:00:00:00:00:03', 'TestFT', - '1200000000038f0000005102060603000000') - - cls.bss_hostapd[1].set_neighbor('12:00:00:00:00:01', 'TestFT', - '1200000000018f0000005101060603000000') - cls.bss_hostapd[1].set_neighbor('12:00:00:00:00:03', 'TestFT', - '1200000000038f0000005101060603000000') - - cls.bss_hostapd[2].set_neighbor('12:00:00:00:00:01', 'TestFT', - '1200000000018f0000005101060603000000') - cls.bss_hostapd[2].set_neighbor('12:00:00:00:00:02', 'TestFT', - '1200000000028f0000005101060603000000') + HostapdCLI.group_neighbors(*cls.bss_hostapd) IWD.copy_to_storage('TestFT.psk')