|
@@ -1,5 +1,6 @@
|
|
import logging
|
|
import logging
|
|
import subprocess
|
|
import subprocess
|
|
|
|
+import time
|
|
|
|
|
|
from flexmock import flexmock
|
|
from flexmock import flexmock
|
|
|
|
|
|
@@ -257,6 +258,52 @@ def test_run_retries_one_passes():
|
|
results = list(module.run_configuration('test.yaml', config, arguments))
|
|
results = list(module.run_configuration('test.yaml', config, arguments))
|
|
assert results == expected_results
|
|
assert results == expected_results
|
|
|
|
|
|
|
|
+def test_run_retry_timeout():
|
|
|
|
+ flexmock(module.borg_environment).should_receive('initialize')
|
|
|
|
+ flexmock(module.command).should_receive('execute_hook')
|
|
|
|
+ flexmock(module).should_receive('run_actions').and_raise(OSError).times(4)
|
|
|
|
+ expected_results = [flexmock(), flexmock(), flexmock(), flexmock()]
|
|
|
|
+ flexmock(module).should_receive('make_error_log_records') \
|
|
|
|
+ .with_args('foo: Error running actions for repository', OSError).and_return(expected_results[0:1]).ordered()
|
|
|
|
+
|
|
|
|
+ flexmock(time).should_receive('sleep').with_args(10).and_return().ordered()
|
|
|
|
+ flexmock(module).should_receive('make_error_log_records') \
|
|
|
|
+ .with_args('foo: Error running actions for repository', OSError).and_return(expected_results[1:2]).ordered()
|
|
|
|
+
|
|
|
|
+ flexmock(time).should_receive('sleep').with_args(20).and_return().ordered()
|
|
|
|
+ flexmock(module).should_receive('make_error_log_records') \
|
|
|
|
+ .with_args('foo: Error running actions for repository', OSError).and_return(expected_results[2:3]).ordered()
|
|
|
|
+
|
|
|
|
+ flexmock(time).should_receive('sleep').with_args(30).and_return().ordered()
|
|
|
|
+ flexmock(module).should_receive('make_error_log_records') \
|
|
|
|
+ .with_args('foo: Error running actions for repository', OSError).and_return(expected_results[3:4]).ordered()
|
|
|
|
+ config = {'location': {'repositories': ['foo']}, 'storage': {'retries':3, 'retry_timeout':10}}
|
|
|
|
+ arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
|
|
|
|
+ results = list(module.run_configuration('test.yaml', config, arguments))
|
|
|
|
+ assert results == expected_results
|
|
|
|
+
|
|
|
|
+def test_run_retries_timeout_multiple_repos():
|
|
|
|
+ flexmock(module.borg_environment).should_receive('initialize')
|
|
|
|
+ flexmock(module.command).should_receive('execute_hook')
|
|
|
|
+ flexmock(module).should_receive('run_actions').and_raise(OSError).and_raise(OSError).and_return([]).and_raise(OSError).times(4)
|
|
|
|
+ expected_results = [flexmock(), flexmock(), flexmock()]
|
|
|
|
+ flexmock(module).should_receive('make_error_log_records') \
|
|
|
|
+ .with_args('foo: Error running actions for repository', OSError).and_return(expected_results[0:1]).ordered()
|
|
|
|
+ flexmock(module).should_receive('make_error_log_records') \
|
|
|
|
+ .with_args('bar: Error running actions for repository', OSError).and_return(expected_results[1:2]).ordered()
|
|
|
|
+
|
|
|
|
+ # Sleep before retrying foo (and passing)
|
|
|
|
+ flexmock(time).should_receive('sleep').with_args(10).and_return().ordered()
|
|
|
|
+
|
|
|
|
+ # Sleep before retrying bar (and failing)
|
|
|
|
+ flexmock(time).should_receive('sleep').with_args(10).and_return().ordered()
|
|
|
|
+ flexmock(module).should_receive('make_error_log_records') \
|
|
|
|
+ .with_args('bar: Error running actions for repository', OSError).and_return(expected_results[2:3]).ordered()
|
|
|
|
+ config = {'location': {'repositories': ['foo','bar']}, 'storage': {'retries':1, 'retry_timeout':10}}
|
|
|
|
+ arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
|
|
|
|
+ results = list(module.run_configuration('test.yaml', config, arguments))
|
|
|
|
+ assert results == expected_results
|
|
|
|
+
|
|
def test_load_configurations_collects_parsed_configurations():
|
|
def test_load_configurations_collects_parsed_configurations():
|
|
configuration = flexmock()
|
|
configuration = flexmock()
|
|
other_configuration = flexmock()
|
|
other_configuration = flexmock()
|