From fce6fa47c40c07491bd114fc5c4b0812956aa48c Mon Sep 17 00:00:00 2001 From: Dipti Date: Tue, 8 Dec 2020 15:15:24 -0800 Subject: [PATCH] added pass/fail method in lfcli and edited example_x functions --- py-json/LANforge/lfcli_base.py | 9 +++++++++ py-scripts/example_open_connection.py | 9 +++++---- py-scripts/example_wep_connection.py | 9 +++++---- py-scripts/example_wpa2_connection.py | 13 ++++++++----- py-scripts/example_wpa3_connection.py | 9 +++++---- py-scripts/example_wpa_connection.py | 11 +++++++---- 6 files changed, 39 insertions(+), 21 deletions(-) diff --git a/py-json/LANforge/lfcli_base.py b/py-json/LANforge/lfcli_base.py index 165a699e..f0619d25 100644 --- a/py-json/LANforge/lfcli_base.py +++ b/py-json/LANforge/lfcli_base.py @@ -365,6 +365,10 @@ class LFCliBase: if (fail_counter == 0) and (pass_counter > 0): return True return False + #use this function to + def failed(self): + print("Test failed. Exiting now.") + sys.exit(1) # use this inside the class to log a failure result def _fail(self, message, print_=False): @@ -374,6 +378,11 @@ class LFCliBase: if self.exit_on_fail: sys.exit(1) + def passed(self): + print("Test passed conclusively.") + sys.exit(0) + + # use this inside the class to log a pass result def _pass(self, message, print_=False): self.test_results.append(self.pass_pref + message) diff --git a/py-scripts/example_open_connection.py b/py-scripts/example_open_connection.py index 2b0ef99e..94c708d8 100755 --- a/py-scripts/example_open_connection.py +++ b/py-scripts/example_open_connection.py @@ -52,11 +52,12 @@ class IPv4Test(LFCliBase): self.station_profile.create(radio="wiphy0", sta_names_=self.sta_list, debug=self.debug) self.station_profile.admin_up() if self.local_realm.wait_for_ip(station_list=self.sta_list, debug=self.debug, timeout_sec=30): - self._pass("Station build finished", print_=True) - exit(0) + self._pass("Station build finished") + self.passed() else: - self._fail("Stations not able to acquire IP. Please check network input.", print_=True) - exit(1) + self._fail("Stations not able to acquire IP. Please check network input.") + print(self.get_failed_result_list()) + self.failed() def cleanup(self, sta_list): diff --git a/py-scripts/example_wep_connection.py b/py-scripts/example_wep_connection.py index 3ad8b0c9..6c211281 100755 --- a/py-scripts/example_wep_connection.py +++ b/py-scripts/example_wep_connection.py @@ -53,11 +53,12 @@ class IPv4Test(LFCliBase): self.station_profile.create(radio=self.radio, sta_names_=self.sta_list, debug=self.debug) self.station_profile.admin_up() if self.local_realm.wait_for_ip(station_list=self.sta_list, debug=self.debug, timeout_sec=30): - self._pass("Station build finished", print_=True) - exit(0) + self._pass("Station build finished") + self.passed() else: - self._fail("Stations not able to acquire IP. Please check network input.", print_=True) - exit(1) + self._fail("Stations not able to acquire IP. Please check network input.") + print(self.get_failed_result_list()) + self.failed() def cleanup(self, sta_list): self.station_profile.cleanup(sta_list) diff --git a/py-scripts/example_wpa2_connection.py b/py-scripts/example_wpa2_connection.py index e349095e..096f1dae 100755 --- a/py-scripts/example_wpa2_connection.py +++ b/py-scripts/example_wpa2_connection.py @@ -53,12 +53,15 @@ class IPv4Test(LFCliBase): self.station_profile.create(radio=self.radio, sta_names_=self.sta_list, debug=self.debug) self.station_profile.admin_up() if self.local_realm.wait_for_ip(station_list=self.sta_list, debug=self.debug, timeout_sec=30): - self._pass("Station build finished", print_=True) - exit(0) + self._pass("Station build finished") + self.passed() else: - self._fail("Stations not able to acquire IP. Please check network input.", print_=True) - exit(1) - + self._fail("Stations not able to acquire IP. Please check network input.") + self + self._fail("Stations not able to acquire IP. Please check network input.") + print(self.get_failed_result_list()) + self.failed() + def cleanup(self, sta_list): self.station_profile.cleanup(sta_list) LFUtils.wait_until_ports_disappear(base_url=self.lfclient_url, port_list=sta_list, diff --git a/py-scripts/example_wpa3_connection.py b/py-scripts/example_wpa3_connection.py index 329056a1..6e663c17 100755 --- a/py-scripts/example_wpa3_connection.py +++ b/py-scripts/example_wpa3_connection.py @@ -53,11 +53,12 @@ class IPv4Test(LFCliBase): self.station_profile.create(radio=self.radio, sta_names_=self.sta_list, debug=self.debug) self.station_profile.admin_up() if self.local_realm.wait_for_ip(station_list=self.sta_list, debug=self.debug, timeout_sec=30): - self._pass("Station build finished", print_=True) - exit(0) + self._pass("Station build finished") + self.passed() else: - self._fail("Stations not able to acquire IP. Please check network input.", print_=True) - exit(1) + self._fail("Stations not able to acquire IP. Please check network input.") + print(self.get_failed_result_list()) + self.failed() def cleanup(self, sta_list): diff --git a/py-scripts/example_wpa_connection.py b/py-scripts/example_wpa_connection.py index 9331f70f..85921c82 100755 --- a/py-scripts/example_wpa_connection.py +++ b/py-scripts/example_wpa_connection.py @@ -53,11 +53,14 @@ class IPv4Test(LFCliBase): self.station_profile.create(radio=self.radio, sta_names_=self.sta_list, debug=self.debug) self.station_profile.admin_up() if self.local_realm.wait_for_ip(station_list=self.sta_list, debug=self.debug, timeout_sec=30): - self._pass("Station build finished", print_=True) - exit(0) + self._pass("Station build finished") + self.passed() + else: - self._fail("Stations not able to acquire IP. Please check network input.", print_=True) - exit(1) + self._fail("Stations not able to acquire IP. Please check network input.") + print(self.get_failed_result_list()) + self.failed() + def cleanup(self, sta_list): self.station_profile.cleanup(sta_list)