Island: Remove storage error when node wasn't modified
Upserting should throw an error when updating or inserting went wrong, not when a node is already up to date.
This commit is contained in:
parent
2248bdcd67
commit
c90044074d
|
@ -55,12 +55,6 @@ class MongoNodeRepository(INodeRepository):
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
raise StorageError(f"{UPSERT_ERROR_MESSAGE}: {err}")
|
raise StorageError(f"{UPSERT_ERROR_MESSAGE}: {err}")
|
||||||
|
|
||||||
if result.matched_count != 0 and result.modified_count != 1:
|
|
||||||
raise StorageError(
|
|
||||||
f'Error updating node with source ID "{node.machine_id}": Expected to update 1 '
|
|
||||||
f"node, but {result.modified_count} were updated"
|
|
||||||
)
|
|
||||||
|
|
||||||
if result.matched_count == 0 and result.upserted_id is None:
|
if result.matched_count == 0 and result.upserted_id is None:
|
||||||
raise StorageError(
|
raise StorageError(
|
||||||
f'Error inserting node with source ID "{node.machine_id}": Expected to insert 1 '
|
f'Error inserting node with source ID "{node.machine_id}": Expected to insert 1 '
|
||||||
|
|
|
@ -163,21 +163,6 @@ def test_upsert_communication__replace_one_fails(
|
||||||
error_raising_node_repository.upsert_communication(1, 2, CommunicationType.SCANNED)
|
error_raising_node_repository.upsert_communication(1, 2, CommunicationType.SCANNED)
|
||||||
|
|
||||||
|
|
||||||
def test_upsert_communication__replace_one_matched_without_modify(
|
|
||||||
error_raising_mock_mongo_client, error_raising_node_repository
|
|
||||||
):
|
|
||||||
mock_result = MagicMock()
|
|
||||||
mock_result.matched_count = 1
|
|
||||||
mock_result.modified_count = 0
|
|
||||||
error_raising_mock_mongo_client.monkey_island.nodes.find_one = MagicMock(return_value=None)
|
|
||||||
error_raising_mock_mongo_client.monkey_island.nodes.replace_one = MagicMock(
|
|
||||||
return_value=mock_result
|
|
||||||
)
|
|
||||||
|
|
||||||
with pytest.raises(StorageError):
|
|
||||||
error_raising_node_repository.upsert_communication(1, 2, CommunicationType.SCANNED)
|
|
||||||
|
|
||||||
|
|
||||||
def test_upsert_communication__replace_one_insert_fails(
|
def test_upsert_communication__replace_one_insert_fails(
|
||||||
error_raising_mock_mongo_client, error_raising_node_repository
|
error_raising_mock_mongo_client, error_raising_node_repository
|
||||||
):
|
):
|
||||||
|
|
Loading…
Reference in New Issue