2022-03-15 19:05:52 +00:00
|
|
|
import json
|
2023-10-10 16:08:34 +05:30
|
|
|
|
|
|
|
import pytest
|
2025-01-17 23:50:13 +05:30
|
|
|
|
2024-07-25 20:06:14 +01:00
|
|
|
from datahub.metadata.schema_classes import (
|
|
|
|
BrowsePathsV2Class,
|
|
|
|
EditableDatasetPropertiesClass,
|
|
|
|
)
|
2023-06-06 14:44:52 -07:00
|
|
|
from tests.utils import ingest_file_via_rest, wait_for_writes_to_sync
|
2022-03-15 19:05:52 +00:00
|
|
|
|
2022-05-13 03:02:13 +01:00
|
|
|
ingested_dataset_run_id = ""
|
|
|
|
ingested_editable_run_id = ""
|
|
|
|
|
2022-11-15 20:03:11 -06:00
|
|
|
|
2022-05-13 03:02:13 +01:00
|
|
|
@pytest.fixture(autouse=True)
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_setup(auth_session, graph_client):
|
2022-05-13 03:02:13 +01:00
|
|
|
"""Fixture to execute asserts before and after a test is run"""
|
|
|
|
|
|
|
|
global ingested_dataset_run_id
|
|
|
|
global ingested_editable_run_id
|
|
|
|
|
|
|
|
platform = "urn:li:dataPlatform:kafka"
|
|
|
|
dataset_name = "test-rollback"
|
|
|
|
|
|
|
|
env = "PROD"
|
|
|
|
dataset_urn = f"urn:li:dataset:({platform},{dataset_name},{env})"
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
gms_host = graph_client.config.server
|
2022-05-13 03:02:13 +01:00
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
assert graph_client.get_aspect(dataset_urn, BrowsePathsV2Class) is None
|
|
|
|
assert graph_client.get_aspect(dataset_urn, EditableDatasetPropertiesClass) is None
|
2022-05-13 03:02:13 +01:00
|
|
|
|
2023-10-10 16:08:34 +05:30
|
|
|
ingested_dataset_run_id = ingest_file_via_rest(
|
2024-09-27 11:31:25 -05:00
|
|
|
auth_session, "tests/cli/cli_test_data.json"
|
2023-10-10 16:08:34 +05:30
|
|
|
).config.run_id
|
2022-05-13 03:02:13 +01:00
|
|
|
print("Setup ingestion id: " + ingested_dataset_run_id)
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
assert graph_client.get_aspect(dataset_urn, BrowsePathsV2Class) is not None
|
2022-05-13 03:02:13 +01:00
|
|
|
|
|
|
|
yield
|
|
|
|
|
|
|
|
# Clean up
|
|
|
|
rollback_url = f"{gms_host}/runs?action=rollback"
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
auth_session.post(
|
2023-10-10 16:08:34 +05:30
|
|
|
rollback_url,
|
|
|
|
data=json.dumps(
|
|
|
|
{"runId": ingested_editable_run_id, "dryRun": False, "hardDelete": True}
|
|
|
|
),
|
|
|
|
)
|
2024-09-27 11:31:25 -05:00
|
|
|
auth_session.post(
|
2023-10-10 16:08:34 +05:30
|
|
|
rollback_url,
|
|
|
|
data=json.dumps(
|
|
|
|
{"runId": ingested_dataset_run_id, "dryRun": False, "hardDelete": True}
|
|
|
|
),
|
|
|
|
)
|
2022-05-13 03:02:13 +01:00
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
assert graph_client.get_aspect(dataset_urn, BrowsePathsV2Class) is None
|
|
|
|
assert graph_client.get_aspect(dataset_urn, EditableDatasetPropertiesClass) is None
|
2022-03-15 19:05:52 +00:00
|
|
|
|
2022-11-15 20:03:11 -06:00
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_rollback_editable(auth_session, graph_client):
|
2022-05-13 03:02:13 +01:00
|
|
|
global ingested_dataset_run_id
|
|
|
|
global ingested_editable_run_id
|
2022-03-15 19:05:52 +00:00
|
|
|
platform = "urn:li:dataPlatform:kafka"
|
2023-10-10 16:08:34 +05:30
|
|
|
dataset_name = "test-rollback"
|
2022-03-15 19:05:52 +00:00
|
|
|
env = "PROD"
|
|
|
|
dataset_urn = f"urn:li:dataset:({platform},{dataset_name},{env})"
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
gms_host = graph_client.config.server
|
2022-03-15 19:05:52 +00:00
|
|
|
|
|
|
|
print("Ingested dataset id:", ingested_dataset_run_id)
|
|
|
|
# Assert that second data ingestion worked
|
2024-07-25 20:06:14 +01:00
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
assert graph_client.get_aspect(dataset_urn, BrowsePathsV2Class) is not None
|
2022-03-15 19:05:52 +00:00
|
|
|
|
|
|
|
# Make editable change
|
2023-10-10 16:08:34 +05:30
|
|
|
ingested_editable_run_id = ingest_file_via_rest(
|
2024-09-27 11:31:25 -05:00
|
|
|
auth_session, "tests/cli/cli_editable_test_data.json"
|
2023-10-10 16:08:34 +05:30
|
|
|
).config.run_id
|
2022-03-15 19:05:52 +00:00
|
|
|
print("ingested editable id:", ingested_editable_run_id)
|
|
|
|
# Assert that second data ingestion worked
|
2024-07-25 20:06:14 +01:00
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
assert (
|
|
|
|
graph_client.get_aspect(dataset_urn, EditableDatasetPropertiesClass) is not None
|
|
|
|
)
|
2022-03-15 19:05:52 +00:00
|
|
|
|
|
|
|
# rollback ingestion 1
|
|
|
|
rollback_url = f"{gms_host}/runs?action=rollback"
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
auth_session.post(
|
2023-10-10 16:08:34 +05:30
|
|
|
rollback_url,
|
|
|
|
data=json.dumps(
|
|
|
|
{"runId": ingested_dataset_run_id, "dryRun": False, "hardDelete": False}
|
|
|
|
),
|
|
|
|
)
|
2022-03-15 19:05:52 +00:00
|
|
|
|
|
|
|
# Allow async MCP processor to handle ingestions & rollbacks
|
2023-06-06 14:44:52 -07:00
|
|
|
wait_for_writes_to_sync()
|
2022-03-15 19:05:52 +00:00
|
|
|
|
|
|
|
# EditableDatasetProperties should still be part of the entity that was soft deleted.
|
2024-09-27 11:31:25 -05:00
|
|
|
assert (
|
|
|
|
graph_client.get_aspect(dataset_urn, EditableDatasetPropertiesClass) is not None
|
|
|
|
)
|
2024-07-25 20:06:14 +01:00
|
|
|
|
2022-03-15 19:05:52 +00:00
|
|
|
# But first ingestion aspects should not be present
|
2024-09-27 11:31:25 -05:00
|
|
|
assert graph_client.get_aspect(dataset_urn, BrowsePathsV2Class) is None
|