Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ is set to your host computer's clone of the CALDP repo.

caldp-sh <any program and parameters to run in docker...>

In the dev Batch environment, a dataset's processing can be intentionally failed by
creating the S3 object ``s3://calcloud-processing-dev/control/<dataset>/causeerror``.
The environment is determined by the suffix of ``AWS_BATCH_JQ_NAME``. The job
must have permission to check the object; S3 access errors fail the job rather
than being treated as an absent marker.


Native Runs
-----------
Expand Down Expand Up @@ -356,7 +362,7 @@ A CALCLOUD Batch event handler is triggered upon CALDP job failure. The event
handler interprets the combination of CALDP exit code, Batch exit code, and
Batch exit reason to determine the error type and react appropriately.
Reactions include automatically rescuing jobs with memory errors, retrying
Docker failures, recording error-ipppssoot messages, etc.
Docker failures, recording caldperror-ipppssoot messages, etc.

Normalizing Error Codes
=======================
Expand Down
6 changes: 3 additions & 3 deletions caldp/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Messages:
1: 'submit-dataset'
2: 'processing-dataset'
3: 'processed-dataset.trigger'
-1: 'error-dataset'
-1: 'caldperror-dataset'
"""

def __init__(self, output_uri, output_path, dataset):
Expand All @@ -91,7 +91,7 @@ def __init__(self, output_uri, output_path, dataset):

def clear_messages(self):
previous_files = [
f"error-{self.dataset}",
f"caldperror-{self.dataset}",
f"processing-{self.dataset}",
f"processed-{self.dataset}.trigger",
]
Expand Down Expand Up @@ -141,7 +141,7 @@ def final_message(self):
prev_stat = int(prev.readlines()[-1].rsplit(":", 1)[-1].strip())

if proc_stat != 0 or prev_stat != 0:
self.name = f"error-{self.dataset}"
self.name = f"caldperror-{self.dataset}"
self.stat = -1
else:
self.name = f"processed-{self.dataset}.trigger"
Expand Down
12 changes: 12 additions & 0 deletions caldp/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# -----------------------------------------------------------------------------

import boto3
from botocore.exceptions import ClientError

from astropy.io import fits

Expand All @@ -33,6 +34,7 @@
from caldp import messages
from caldp import exit_codes
from caldp import sysexit
from caldp import utils

# import caldp (see track_versions)

Expand Down Expand Up @@ -1358,6 +1360,16 @@ def process(dataset, input_uri, output_uri):
msg.init()
msg.process_message() # processing-ipst

if utils.get_environment() == "dev":
key = f"control/{dataset}/causeerror"
try:
boto3.client("s3").head_object(Bucket="calcloud-processing-dev", Key=key)
except ClientError as exc:
if exc.response["Error"]["Code"] != "404":
raise
else:
raise RuntimeError(f"Simulated processing error: s3://calcloud-processing-dev/{key} exists")

manager = get_manager(dataset, input_uri, output_uri)
manager.main()

Expand Down
61 changes: 58 additions & 3 deletions caldp/tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

import os
import tempfile
from unittest.mock import Mock

import pytest
from botocore.exceptions import ClientError

from caldp import process
from caldp import create_previews
Expand Down Expand Up @@ -994,7 +996,7 @@ def check_messages(ipppssoot, output_uri, status):
else:
working_dir = os.getcwd()
proc_msg = os.path.join(working_dir, "messages", f"{status}-{ipppssoot}{suffix}")
err_msg = os.path.join(working_dir, "messages", f"error-{ipppssoot}")
err_msg = os.path.join(working_dir, "messages", f"caldperror-{ipppssoot}")
assert os.path.exists(proc_msg) or os.path.exists(err_msg)


Expand All @@ -1012,7 +1014,7 @@ def test_final_message_exit_status(tmp_path, monkeypatch, process_status, previe
msg.final_message()

success = process_status == 0 and preview_status == 0
expected_name = f"processed-{dataset}.trigger" if success else f"error-{dataset}"
expected_name = f"processed-{dataset}.trigger" if success else f"caldperror-{dataset}"
assert msg.stat == (3 if success else -1)
assert msg.name == expected_name
assert (tmp_path / "messages" / expected_name).is_file()
Expand Down Expand Up @@ -1043,7 +1045,7 @@ def message_status_check(input_uri, output_uri, ipppssoot):

msg.final_message()
if msg.stat == -1:
assert msg.name == f"error-{ipppssoot}"
assert msg.name == f"caldperror-{ipppssoot}"
elif msg.stat == 3:
assert msg.name == f"processed-{ipppssoot}.trigger"

Expand Down Expand Up @@ -1111,3 +1113,56 @@ def exc_func(arg1=True):
retry_no_exc()
with pytest.raises(NotImplementedError):
retry_exc()


@pytest.fixture
def forced_error_process(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
s3 = Mock()
client = Mock(return_value=s3)
manager = Mock()
monkeypatch.setattr(process.boto3, "client", client)
monkeypatch.setattr(process, "get_manager", Mock(return_value=manager))
return client, s3, manager


def test_forced_error_marker_stops_processing(monkeypatch, forced_error_process):
monkeypatch.setenv("AWS_BATCH_JQ_NAME", "calcloud-hst-queue-02g-dev")
client, s3, manager = forced_error_process

with pytest.raises(RuntimeError, match="control/j8cb010b0/causeerror"):
process.process("j8cb010b0", "file:inputs", "file:outputs")

client.assert_called_once_with("s3")
s3.head_object.assert_called_once_with(Bucket="calcloud-processing-dev", Key="control/j8cb010b0/causeerror")
manager.main.assert_not_called()
assert process.get_manager.call_count == 0


@pytest.mark.parametrize("queue", ["calcloud-hst-queue-02g-test", "calcloud-hst-queue-02g-ops", None])
def test_forced_error_marker_only_checked_in_dev(monkeypatch, forced_error_process, queue):
if queue is None:
monkeypatch.delenv("AWS_BATCH_JQ_NAME", raising=False)
else:
monkeypatch.setenv("AWS_BATCH_JQ_NAME", queue)
client, _, manager = forced_error_process

process.process("j8cb010b0", "file:inputs", "file:outputs")

client.assert_not_called()
manager.main.assert_called_once_with()


@pytest.mark.parametrize("error_code", ["404", "403"])
def test_forced_error_marker_s3_errors(monkeypatch, forced_error_process, error_code):
monkeypatch.setenv("AWS_BATCH_JQ_NAME", "calcloud-hst-queue-02g-dev")
_, s3, manager = forced_error_process
s3.head_object.side_effect = ClientError({"Error": {"Code": error_code, "Message": "S3 error"}}, "HeadObject")

if error_code == "404":
process.process("j8cb010b0", "file:inputs", "file:outputs")
manager.main.assert_called_once_with()
else:
with pytest.raises(ClientError, match="403"):
process.process("j8cb010b0", "file:inputs", "file:outputs")
manager.main.assert_not_called()
7 changes: 7 additions & 0 deletions caldp/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os


def get_environment():
queue_name = os.environ.get("AWS_BATCH_JQ_NAME", "")
environment = queue_name.rsplit("-", 1)[-1] if queue_name else None
return environment
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns.append("_templates")
exclude_patterns.append("_templates") # noqa: F405 # type: ignore

# This is added to the end of RST files - a good place to put substitutions to
# be used globally.
rst_epilog += """
"""
""" # noqa: F405 # type: ignore

# -- Project information ------------------------------------------------------

Expand Down Expand Up @@ -154,7 +154,7 @@

if setup_cfg.get("edit_on_github").lower() == "true":

extensions += ["sphinx_astropy.ext.edit_on_github"]
extensions += ["sphinx_astropy.ext.edit_on_github"] # noqa: F405 # type: ignore

edit_on_github_project = setup_cfg["github_project"]
edit_on_github_branch = "master"
Expand Down
Loading