From 68704ec93fbe0af16384aec03bf4048cf4a571a0 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Thu, 9 Nov 2023 15:42:58 +0100 Subject: [PATCH 1/3] Proper coverage settings --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 7383029..94081fb 100644 --- a/Makefile +++ b/Makefile @@ -17,10 +17,10 @@ unit_tests: ## Run unit tests pytest -v -p no:cacheprovider coverage: ## Run unit tests, display code coverage on terminal - pytest -v -p no:cacheprovider --cov schemas/ + pytest -v -p no:cacheprovider --cov ccx_messaging/ coverage-report: ## Run unit tests, generate code coverage as a HTML report - pytest -v -p no:cacheprovider --cov schemas/ --cov-report=html + pytest -v -p no:cacheprovider --cov ccx_messaging/ --cov-report=html documentation: ## Generate documentation for all sources pydoc3 *.py > docs/sources.txt From 0c51df950f9fb686a0885df97a69b40c423620bb Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Thu, 9 Nov 2023 15:43:16 +0100 Subject: [PATCH 2/3] IO error handling --- ccx_messaging/watchers/cluster_id_watcher.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ccx_messaging/watchers/cluster_id_watcher.py b/ccx_messaging/watchers/cluster_id_watcher.py index 0db448a..445749f 100644 --- a/ccx_messaging/watchers/cluster_id_watcher.py +++ b/ccx_messaging/watchers/cluster_id_watcher.py @@ -73,5 +73,9 @@ def on_extract(self, ctx, broker, extraction): "The archive doesn't contain a valid Cluster Id file. Skipping its extraction" ) + except IOError: + self.last_record["cluster_name"] = None + LOG.warning(f"Could not read file: {id_file_path}") + finally: self.last_record = None From 569700836dfabe22e280ce462cc6cd943c1e5a9f Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Thu, 9 Nov 2023 15:43:30 +0100 Subject: [PATCH 3/3] Updated unit tests accordingly --- test/watchers/cluster_id_watcher_test.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/watchers/cluster_id_watcher_test.py b/test/watchers/cluster_id_watcher_test.py index 9012d3b..ba64171 100644 --- a/test/watchers/cluster_id_watcher_test.py +++ b/test/watchers/cluster_id_watcher_test.py @@ -46,6 +46,23 @@ def test_cluster_id_watcher_file_not_exist(caplog): assert "The archive doesn't contain a valid Cluster Id file" in caplog.text +def test_cluster_id_watcher_io_error(caplog): + """Test the behaviour in case of I/O error.""" + input_msg = {"identity": {}} + + extraction_mock = MagicMock() + # this is a trick mentioned there + # https://unix.stackexchange.com/questions/6301/how-do-i-read-from-proc-pid-mem-under-linux/ + extraction_mock.tmp_dir = "/proc/self/mem" + + sut = ClusterIdWatcher() + sut.on_recv(input_msg) + + sut.on_extract(None, None, extraction_mock) + assert input_msg["cluster_name"] is None + assert "Could not read file: " in caplog.text + + _INCORRECT_UUIDS = [ "0", "---//---",