def test_retry_hooks_with_retry(self, command_mock, sleep_mock): # BackupManager mock backup_manager = build_backup_manager(name="test_server") backup_manager.config.pre_test_retry_hook = "not_existent_script" # Command mock executed by HookScriptRunner command_mock.return_value.side_effect = [ 1, 1, 1, RetryHookScriptRunner.EXIT_SUCCESS, ] # the actual test script = RetryHookScriptRunner(backup_manager, "test_retry_hook", "pre") expected_env = { "BARMAN_PHASE": "pre", "BARMAN_VERSION": version, "BARMAN_SERVER": "test_server", "BARMAN_CONFIGURATION": "build_config_from_dicts", "BARMAN_HOOK": "test_retry_hook", "BARMAN_RETRY": "1", } # Shorten wait time after failures script.ATTEMPTS_BEFORE_NAP = 2 script.BREAK_TIME = 1 script.NAP_TIME = 1 assert script.run() == RetryHookScriptRunner.EXIT_SUCCESS assert command_mock.call_count == 4 assert command_mock.call_args[1]["env_append"] == expected_env command_mock.reset_mock() # Command mock executed by HookScriptRunner command_mock.return_value.side_effect = [ 1, 2, 3, 4, 5, 6, RetryHookScriptRunner.EXIT_ABORT_CONTINUE, ] # the actual test script = RetryHookScriptRunner(backup_manager, "test_retry_hook", "pre") expected_env = { "BARMAN_PHASE": "pre", "BARMAN_VERSION": version, "BARMAN_SERVER": "test_server", "BARMAN_CONFIGURATION": "build_config_from_dicts", "BARMAN_HOOK": "test_retry_hook", "BARMAN_RETRY": "1", } # Shorten wait time after failures script.ATTEMPTS_BEFORE_NAP = 2 script.BREAK_TIME = 1 script.NAP_TIME = 1 assert script.run() == RetryHookScriptRunner.EXIT_ABORT_CONTINUE assert command_mock.call_count == 7 assert command_mock.call_args[1]["env_append"] == expected_env
def test_retry_hooks_with_retry(self, command_mock, sleep_mock): # BackupManager mock backup_manager = build_backup_manager(name='test_server') backup_manager.config.pre_test_retry_hook = 'not_existent_script' # Command mock executed by HookScriptRunner command_mock.return_value.side_effect = [ 1, 1, 1, RetryHookScriptRunner.EXIT_SUCCESS ] # the actual test script = RetryHookScriptRunner(backup_manager, 'test_retry_hook', 'pre') expected_env = { 'BARMAN_PHASE': 'pre', 'BARMAN_VERSION': version, 'BARMAN_SERVER': 'test_server', 'BARMAN_CONFIGURATION': 'build_config_from_dicts', 'BARMAN_HOOK': 'test_retry_hook', 'BARMAN_RETRY': '1', } # Shorten wait time after failures script.ATTEMPTS_BEFORE_NAP = 2 script.BREAK_TIME = 1 script.NAP_TIME = 1 assert script.run() == RetryHookScriptRunner.EXIT_SUCCESS assert command_mock.call_count == 4 assert command_mock.call_args[1]['env_append'] == expected_env command_mock.reset_mock() # Command mock executed by HookScriptRunner command_mock.return_value.side_effect = [ 1, 2, 3, 4, 5, 6, RetryHookScriptRunner.EXIT_ABORT_CONTINUE ] # the actual test script = RetryHookScriptRunner(backup_manager, 'test_retry_hook', 'pre') expected_env = { 'BARMAN_PHASE': 'pre', 'BARMAN_VERSION': version, 'BARMAN_SERVER': 'test_server', 'BARMAN_CONFIGURATION': 'build_config_from_dicts', 'BARMAN_HOOK': 'test_retry_hook', 'BARMAN_RETRY': '1', } # Shorten wait time after failures script.ATTEMPTS_BEFORE_NAP = 2 script.BREAK_TIME = 1 script.NAP_TIME = 1 assert script.run() == RetryHookScriptRunner.EXIT_ABORT_CONTINUE assert command_mock.call_count == 7 assert command_mock.call_args[1]['env_append'] == expected_env
def test_retry_hooks_with_retry(self, command_mock, sleep_mock): # BackupManager mock backup_manager = build_backup_manager(name='test_server') backup_manager.config.pre_test_retry_hook = 'not_existent_script' # Command mock executed by HookScriptRunner command_mock.return_value.side_effect = [ 1, 1, 1, RetryHookScriptRunner.EXIT_SUCCESS] # the actual test script = RetryHookScriptRunner(backup_manager, 'test_retry_hook', 'pre') expected_env = { 'BARMAN_PHASE': 'pre', 'BARMAN_VERSION': version, 'BARMAN_SERVER': 'test_server', 'BARMAN_CONFIGURATION': 'build_config_from_dicts', 'BARMAN_HOOK': 'test_retry_hook', 'BARMAN_RETRY': '1', } # Shorten wait time after failures script.ATTEMPTS_BEFORE_NAP = 2 script.BREAK_TIME = 1 script.NAP_TIME = 1 assert script.run() == RetryHookScriptRunner.EXIT_SUCCESS assert command_mock.call_count == 4 assert command_mock.call_args[1]['env_append'] == expected_env command_mock.reset_mock() # Command mock executed by HookScriptRunner command_mock.return_value.side_effect = [ 1, 2, 3, 4, 5, 6, RetryHookScriptRunner.EXIT_ABORT_CONTINUE] # the actual test script = RetryHookScriptRunner(backup_manager, 'test_retry_hook', 'pre') expected_env = { 'BARMAN_PHASE': 'pre', 'BARMAN_VERSION': version, 'BARMAN_SERVER': 'test_server', 'BARMAN_CONFIGURATION': 'build_config_from_dicts', 'BARMAN_HOOK': 'test_retry_hook', 'BARMAN_RETRY': '1', } # Shorten wait time after failures script.ATTEMPTS_BEFORE_NAP = 2 script.BREAK_TIME = 1 script.NAP_TIME = 1 assert script.run() == RetryHookScriptRunner.EXIT_ABORT_CONTINUE assert command_mock.call_count == 7 assert command_mock.call_args[1]['env_append'] == expected_env