def test_arm_different_timeout_smaller(self, duthost, platform_api_conn, conf): ''' arm the watchdog with smaller timeout value and verify new timeout was accepted; If platform accepts only single valid timeout value, @greater_timeout should be None. ''' watchdog_timeout = conf['greater_timeout'] if watchdog_timeout is None: pytest.skip( '"greater_timeout" parameter is required for this test case') watchdog_timeout_smaller = conf['valid_timeout'] actual_timeout = watchdog.arm(platform_api_conn, watchdog_timeout) remaining_time = watchdog.get_remaining_time(platform_api_conn) actual_timeout_smaller = watchdog.arm(platform_api_conn, watchdog_timeout_smaller) self.expect( actual_timeout > actual_timeout_smaller, "{}: 1st timeout {} seconds should be greater than 2nd timeout {} seconds" .format(self.test_arm_different_timeout_smaller.__name__, actual_timeout, actual_timeout_smaller)) remaining_time_smaller = watchdog.get_remaining_time(platform_api_conn) self.expect( remaining_time_smaller < remaining_time, "{}: 2nd remaining_timeout {} seconds should be less than 1st remaining timeout {} seconds" .format(self.test_arm_different_timeout_smaller.__name__, remaining_time_smaller, remaining_time)) self.assert_expectations()
def test_periodic_arm(self, duthost, platform_api_conn, conf): ''' arm watchdog several times as watchdog deamon would and verify API behaves correctly ''' watchdog_timeout = conf['valid_timeout'] actual_timeout = watchdog.arm(platform_api_conn, watchdog_timeout) time.sleep(TEST_WAIT_TIME_SECONDS) remaining_time = watchdog.get_remaining_time(platform_api_conn) actual_timeout_new = watchdog.arm(platform_api_conn, watchdog_timeout) remaining_time_new = watchdog.get_remaining_time(platform_api_conn) self.expect(actual_timeout == actual_timeout_new, "{}: new watchdog timeout {} seconds setting should be same as the previous actual watchdog timeout {} seconds".format(self.test_periodic_arm.__name__, actual_timeout_new, actual_timeout)) self.expect(remaining_time_new > remaining_time, "{}: new remaining timeout {} seconds should be greater than the previous remaining timeout {} seconds by {} seconds".format(self.test_periodic_arm.__name__, remaining_time_new, remaining_time, TEST_WAIT_TIME_SECONDS)) self.assert_expectations()
def test_remaining_time(self, duthost, platform_api_conn, conf): ''' arm watchdog with a valid timeout and verify that remaining time API works correctly ''' watchdog_timeout = conf['valid_timeout'] # in the begginging of the test watchdog is not armed, so # get_remaining_time has to return -1 remaining_time = watchdog.get_remaining_time(platform_api_conn) if self.expect(remaining_time is not None and remaining_time is -1, "watchdog should be disabled in the initial state"): actual_timeout = watchdog.arm(platform_api_conn, watchdog_timeout) remaining_time = watchdog.get_remaining_time(platform_api_conn) if self.expect( actual_timeout >= watchdog_timeout, "watchdog arm with {} seconds failed".format( watchdog_timeout)): if self.expect( remaining_time > 0, "Remaining_time {} seconds is not valid".format( remaining_time)): self.expect( remaining_time <= actual_timeout, "Remaining_time {} seconds should be less than watchdog armed timeout {} seconds" .format(remaining_time, actual_timeout)) remaining_time = watchdog.get_remaining_time(platform_api_conn) time.sleep(TEST_WAIT_TIME_SECONDS) remaining_time_new = watchdog.get_remaining_time(platform_api_conn) self.expect( remaining_time_new < remaining_time, "Remaining_time {} seconds should be decreased from previous remaining_time {} seconds" .format(remaining_time_new, remaining_time)) self.assert_expectations()
def test_arm_negative_timeout(self, duthost, platform_api_conn): ''' try to arm the watchdog with negative value ''' watchdog_timeout = -1 actual_timeout = watchdog.arm(platform_api_conn, watchdog_timeout) self.expect(actual_timeout == -1, "{}: Watchdog should be disarmed, but returned timeout of {} seconds".format(self.test_arm_negative_timeout.__name__, watchdog_timeout)) self.assert_expectations()
def test_arm_too_big_timeout(self, duthost, platform_api_conn, conf): ''' try to arm the watchdog with timeout that is too big for hardware watchdog; If no such limitation exist, @too_big_timeout should be None for such platform. ''' watchdog_timeout = conf['too_big_timeout'] if watchdog_timeout is None: pytest.skip('"too_big_timeout" parameter is required for this test case') actual_timeout = watchdog.arm(platform_api_conn, watchdog_timeout) self.expect(actual_timeout == -1, "{}: Watchdog should be disarmed, but returned timeout of {} seconds".format(self.test_arm_too_big_timeout.__name__, watchdog_timeout)) self.assert_expectations()
def test_arm_disarm_states(self, duthost, localhost, platform_api_conn, conf): ''' arm watchdog with a valid timeout value, verify it is in armed state, disarm watchdog and verify it is in disarmed state ''' watchdog_timeout = conf['valid_timeout'] actual_timeout = watchdog.arm(platform_api_conn, watchdog_timeout) if self.expect(actual_timeout is not None, "Watchdog.arm is not supported"): if self.expect(isinstance(actual_timeout, int), "actual_timeout appears incorrect"): if self.expect(actual_timeout != -1, "Failed to arm the watchdog"): self.expect(actual_timeout >= watchdog_timeout, "Actual watchdog timeout {} seconds appears wrong, should be equal or greater than {} seconds".format(actual_timeout, watchdog_timeout)) watchdog_status = watchdog.is_armed(platform_api_conn) if self.expect(watchdog_status is not None, "Failed to retrieve watchdog status"): self.expect(watchdog_status is True, "Watchdog is not armed.") remaining_time = watchdog.get_remaining_time(platform_api_conn) if self.expect(remaining_time is not None, "Failed to get the remaining time of watchdog"): if self.expect(isinstance(remaining_time, int), "remaining_time appears incorrect"): self.expect(remaining_time <= actual_timeout, "Watchdog remaining_time {} seconds appears wrong compared to watchdog timeout {} seocnds".format(remaining_time, actual_timeout)) watchdog_status = watchdog.disarm(platform_api_conn) if self.expect(watchdog_status is not None, "Watchdog.disarm is not supported"): self.expect(watchdog_status is True, "Failed to disarm the watchdog") watchdog_status = watchdog.is_armed(platform_api_conn) if self.expect(watchdog_status is not None, "Failed to check the watchdog status"): self.expect(watchdog_status is False, "Watchdog is not disarmed") remaining_time = watchdog.get_remaining_time(platform_api_conn) if self.expect(remaining_time is not None, "Failed to get the remaining time of watchdog"): self.expect(remaining_time is -1, "Watchdog remaining_time {} seconds is wrong for disarmed state".format(remaining_time)) res = localhost.wait_for(host=duthost.hostname, port=22, state="stopped", delay=5, timeout=watchdog_timeout + TIMEOUT_DEVIATION, module_ignore_errors=True) self.expect('Timeout' in res.get('msg', ''), "unexpected disconnection from dut") self.assert_expectations()