Skip to content

Commit

Permalink
Merge pull request #104 from tisnik/io-error-catching
Browse files Browse the repository at this point in the history
Proper I/O error catching
  • Loading branch information
tisnik authored Nov 9, 2023
2 parents c89ab37 + 5697008 commit cad78c5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions ccx_messaging/watchers/cluster_id_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions test/watchers/cluster_id_watcher_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"---//---",
Expand Down

0 comments on commit cad78c5

Please sign in to comment.