Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7163738
D2490.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Subscribers
None
D2490.diff
View Options
diff --git a/swh/icinga_plugins/base_check.py b/swh/icinga_plugins/base_check.py
--- a/swh/icinga_plugins/base_check.py
+++ b/swh/icinga_plugins/base_check.py
@@ -7,9 +7,9 @@
class BaseCheck:
def __init__(self, obj):
self.warning_threshold = obj.get(
- '_warning_threshold', self.DEFAULT_WARNING_THRESHOLD)
+ 'warning_threshold', self.DEFAULT_WARNING_THRESHOLD)
self.critical_threshold = obj.get(
- '_critical_threshold', self.DEFAULT_CRITICAL_THRESHOLD)
+ 'critical_threshold', self.DEFAULT_CRITICAL_THRESHOLD)
def get_status(self, value):
if self.critical_threshold and value >= self.critical_threshold:
diff --git a/swh/icinga_plugins/cli.py b/swh/icinga_plugins/cli.py
--- a/swh/icinga_plugins/cli.py
+++ b/swh/icinga_plugins/cli.py
@@ -19,11 +19,14 @@
@click.option('-c', '--critical', type=int,
help='Critical threshold.')
@click.pass_context
-def cli(ctx, **kwargs):
+def cli(ctx, warning, critical):
"""Main command for Icinga plugins
"""
ctx.ensure_object(dict)
- ctx.obj.update(kwargs)
+ if warning:
+ ctx.obj['warning_threshold'] = int(warning)
+ if critical:
+ ctx.obj['critical_threshold'] = int(critical)
@cli.group(name='check-vault')
diff --git a/swh/icinga_plugins/tests/test_deposit.py b/swh/icinga_plugins/tests/test_deposit.py
--- a/swh/icinga_plugins/tests/test_deposit.py
+++ b/swh/icinga_plugins/tests/test_deposit.py
@@ -169,6 +169,75 @@
assert result.exit_code == 0, result.output
+def test_deposit_delay_warning(
+ requests_mock, mocker, sample_archive, sample_metadata, mocked_time):
+ scenario = WebScenario()
+
+ scenario.add_step(
+ 'post', BASE_URL + '/testcol/',
+ ENTRY_TEMPLATE.format(status='deposited'))
+ scenario.add_step(
+ 'get', BASE_URL + '/testcol/42/status/',
+ STATUS_TEMPLATE.format(status='verified', status_detail=''))
+ scenario.add_step(
+ 'get', BASE_URL + '/testcol/42/status/',
+ STATUS_TEMPLATE.format(status='done', status_detail=''))
+
+ scenario.install_mock(requests_mock)
+
+ result = invoke([
+ '--warning', '15',
+ 'check-deposit',
+ *COMMON_OPTIONS,
+ 'single',
+ '--archive', sample_archive,
+ '--metadata', sample_metadata,
+ ], catch_exceptions=True)
+
+ assert result.output == (
+ "DEPOSIT WARNING - Deposit took 20.00s and succeeded.\n"
+ "| 'load_time' = 10.00s\n"
+ "| 'total_time' = 20.00s\n"
+ "| 'upload_time' = 0.00s\n"
+ "| 'validation_time' = 10.00s\n")
+ assert result.exit_code == 1, result.output
+
+
+def test_deposit_delay_critical(
+ requests_mock, mocker, sample_archive, sample_metadata, mocked_time):
+ scenario = WebScenario()
+
+ scenario.add_step(
+ 'post', BASE_URL + '/testcol/',
+ ENTRY_TEMPLATE.format(status='deposited'))
+ scenario.add_step(
+ 'get', BASE_URL + '/testcol/42/status/',
+ STATUS_TEMPLATE.format(status='verified', status_detail=''))
+ scenario.add_step(
+ 'get', BASE_URL + '/testcol/42/status/',
+ STATUS_TEMPLATE.format(status='done', status_detail=''),
+ callback=lambda: time.sleep(60))
+
+ scenario.install_mock(requests_mock)
+
+ result = invoke([
+ '--critical', '50',
+ 'check-deposit',
+ *COMMON_OPTIONS,
+ 'single',
+ '--archive', sample_archive,
+ '--metadata', sample_metadata,
+ ], catch_exceptions=True)
+
+ assert result.output == (
+ "DEPOSIT CRITICAL - Deposit took 80.00s and succeeded.\n"
+ "| 'load_time' = 70.00s\n"
+ "| 'total_time' = 80.00s\n"
+ "| 'upload_time' = 0.00s\n"
+ "| 'validation_time' = 10.00s\n")
+ assert result.exit_code == 2, result.output
+
+
def test_deposit_timeout(
requests_mock, mocker, sample_archive, sample_metadata, mocked_time):
scenario = WebScenario()
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jan 30, 2:28 PM (1 w, 11 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3221136
Attached To
D2490: Add tests for --warning and --critical.
Event Timeline
Log In to Comment