From 3a00712bbf78d4a3d296c8180edd954ea649eab4 Mon Sep 17 00:00:00 2001 From: Gerrit Holl Date: Thu, 16 Feb 2023 15:25:20 +0100 Subject: [PATCH 1/2] More informative error message when not updating timestamp file --- cspp_runner/runner.py | 10 ++++++---- cspp_runner/tests/test_runner.py | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/cspp_runner/runner.py b/cspp_runner/runner.py index e41554d..d90efdc 100644 --- a/cspp_runner/runner.py +++ b/cspp_runner/runner.py @@ -190,8 +190,10 @@ def update_files(url_jpss_remote_dir, update_stampfile_prefix, mirror_jpss, try: fpt = open(filename, "w") fpt.write(timestamp) - except OSError: - LOG.warning(f'Failed to write {what:s}-update time-stamp file') + except OSError as e: + LOG.warning( + f'Failed to write {what:s}-update time-stamp file to ' + f"{filename!s}: {e.args[1]:s}") return else: fpt.close() @@ -292,11 +294,11 @@ def publish_sdr(publisher, result_files, mda, site, mode, to_send = mda.copy() # Delete the RDR uri and uid from the message: try: - del(to_send['uri']) + del to_send['uri'] except KeyError: LOG.warning("Couldn't remove URI from message") try: - del(to_send['uid']) + del to_send['uid'] except KeyError: LOG.warning("Couldn't remove UID from message") diff --git a/cspp_runner/tests/test_runner.py b/cspp_runner/tests/test_runner.py index e4659db..3df9d81 100644 --- a/cspp_runner/tests/test_runner.py +++ b/cspp_runner/tests/test_runner.py @@ -169,6 +169,22 @@ def test_update_nominal(monkeypatch, tmp_path, caplog, funcname, label): assert exp1.exists() or exp2.exists() +@pytest.mark.parametrize( + "funcname,label", [("update_lut_files", "LUT"), + ("update_ancillary_files", "ANC")]) +def test_update_stampfile_fails(monkeypatch, tmp_path, caplog, funcname, label): + """Test update case when writing stampfile files.""" + import cspp_runner.runner + updater = getattr(cspp_runner.runner, funcname) + monkeypatch.setenv("CSPP_WORKDIR", os.fspath(tmp_path / "env")) + stampfile = os.fspath(tmp_path / "stampfile" / "directory" / "does" / "not" / "exist") + with caplog.at_level(logging.INFO): + updater("gopher://dummy/location", stampfile, "echo") + assert (f"Failed to write {label:s}-update time-stamp file to " + f"{stampfile:s}" in caplog.text) + assert "No such file or directory" in caplog.text + + @pytest.mark.parametrize( "funcname", ["update_lut_files", "update_ancillary_files"]) def test_update_error(monkeypatch, tmp_path, caplog, funcname): From 51269dfa6414f7f246c290f85a1e505ecb152aa5 Mon Sep 17 00:00:00 2001 From: Gerrit Holl Date: Fri, 17 Feb 2023 08:48:09 +0100 Subject: [PATCH 2/2] More portable/readable way of error reporting When reporting an error related to updating the timestamp, use a more portable way to report what the error message was. --- cspp_runner/runner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cspp_runner/runner.py b/cspp_runner/runner.py index 3b6fcea..5d294cb 100644 --- a/cspp_runner/runner.py +++ b/cspp_runner/runner.py @@ -193,7 +193,7 @@ def update_files(url_jpss_remote_dir, update_stampfile_prefix, mirror_jpss, except OSError as e: LOG.warning( f'Failed to write {what:s}-update time-stamp file to ' - f"{filename!s}: {e.args[1]:s}") + f"{filename!s}: {e.strerror:s}") return else: fpt.close()