Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/gms-lite-local-stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ on:
- "smoke-test/env/**"
# The AI smoke leg's job layer; the Docker-free stack never reads it.
- "!smoke-test/env/gen-ai/**"
# The ZDU job layer; the Docker-free stack never reads it.
- "!smoke-test/env/zdu/**"
- "smoke-test/check_env_parity.py"
- "smoke-test/env-parity-allowlist.txt"
- "smoke-test/tests/unit/test_check_env_parity.py"
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/zdu-e2e-daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ jobs:

- name: Run ZDU E2E
env:
DATAHUB_LOCAL_COMMON_ENV: zdu-test.env
# On a clean CI runner the local Docker daemon has no `:debug`
# images for the non-ZDU services (frontend, actions, etc.) that
# the compose stack pulls in. Pin all unbuilt services to the
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ skills-lock.json
!/smoke-test/env/**/*.env
!/e2e-test/ui/playwright/env/**/*.env
!/metadata-integration/java/acryl-spark-lineage/spark-smoke-test/env/**/*.env
# Exception: ZDU test compose override (no secrets — only authz bypass flags)
!docker/profiles/zdu-test.env

# A bunch of binaries we never ever want to add
datahub-frontend/bin/main/
Expand Down
2 changes: 2 additions & 0 deletions env/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ env/
folders, plus any conditional folders the extension adds
smoke-test/env/ job layer for the pytest smoke tests (--job smoke-test)
smoke-test/env/gen-ai/ job layer for the AI embedding smoke leg (docker-unified.yml), compose only
smoke-test/env/zdu/ job layer for the ZDU upgrade framework (Docker only, selected
by the framework itself; not read by the smoke-test layer)
e2e-test/ui/playwright/env/ job layer for Playwright (--job playwright)
metadata-integration/java/acryl-spark-lineage/spark-smoke-test/env/
job layer for the spark lineage smoke test (Docker only,
Expand Down
6 changes: 3 additions & 3 deletions docker/profiles/zdu-test.env → smoke-test/env/zdu/all.env
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# ZDU test override env — disables policy + REST authorization so the
# ZDU test job layer — disables policy + REST authorization so the
# test framework's REST writes via personal access token are not blocked
# by the new master HEAD validators (PrivilegeConstraintsValidator, etc.).
# The ZDU test signal is aspect migration, not authorization; bypassing
# both layers removes that interference.
#
# Used only when DATAHUB_LOCAL_COMMON_ENV=zdu-test.env is set in the
# calling shell (Compose YAML expands ${DATAHUB_LOCAL_COMMON_ENV:-empty.env}).
# The ZDU framework selects this folder itself (DATAHUB_ENV_JOB_DIR, see
# tests/zdu/framework/constants.py); all.env reaches every DataHub service.
AUTH_POLICIES_ENABLED=false
REST_API_AUTHORIZATION_ENABLED=false
# Disable bearer-token authentication entirely. After the nuke wipes
Expand Down
29 changes: 27 additions & 2 deletions smoke-test/tests/unit/zdu/test_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,30 @@ def test_passes_without_recreate_when_gms_already_on_original_tag(
assert result.details["restored"] is False
phase._docker.recreate_service.assert_not_called()

def test_recreates_when_original_tag_still_has_zdu_env(self, phase) -> None:
# GMS was recreated during the run on the original tag, so it still
# carries the ZDU job layer: cleanup must drop it anyway.
phase._docker.get_service_env.return_value["ZDU_TEST_FRAMEWORK_ENABLED"] = (
"true"
)
ctx = TestContext()
ctx.prepare_old_stack = PrepareOldStackResult(
old_image_tag="zdu-old-abc12345",
current_images={"datahub-gms-debug": "acryldata/datahub-gms:debug"},
services_inspected=["datahub-gms-debug"],
recreated_services=[],
health_check_passed=True,
duration_s=0.0,
)
phase._docker.get_all_service_images.return_value = {
"datahub-gms-debug": "acryldata/datahub-gms:debug",
}
with patch.object(phase, "_wait_for_health", return_value=True):
result = phase.run(ctx)
assert result.details["restored"] is True
env = phase._docker.recreate_service.call_args.kwargs["compose_env"]
assert env["DATAHUB_ENV_JOB_DIR"] == ""


class TestRestoresWhenMismatched:
def test_recreates_with_original_tag_and_full_passthrough(self, phase) -> None:
Expand All @@ -194,13 +218,14 @@ def test_recreates_with_original_tag_and_full_passthrough(self, phase) -> None:
assert result.details["restored"] is True

# recreate_service must be called with the original tag + passthrough
# secrets + an empty.env override (so AUTH_POLICIES_ENABLED comes back
# to the dev default).
# secrets, with the ZDU job layer dropped and an empty ad-hoc file (so
# AUTH_POLICIES_ENABLED comes back to the dev default).
phase._docker.recreate_service.assert_called_once()
call = phase._docker.recreate_service.call_args
env = call.kwargs["compose_env"]
assert env["DATAHUB_VERSION"] == "debug"
assert env["DATAHUB_GMS_VERSION"] == "debug"
assert env["DATAHUB_ENV_JOB_DIR"] == ""
assert env["DATAHUB_LOCAL_COMMON_ENV"] == "empty.env"
assert env["DATAHUB_TOKEN_SERVICE_SIGNING_KEY"] == "test-key"
assert env["DATAHUB_TOKEN_SERVICE_SALT"] == "test-salt"
Expand Down
26 changes: 6 additions & 20 deletions smoke-test/tests/unit/zdu/test_nuke_and_redeploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ def test_skipped_when_old_tag_is_debug(self, phase, docker) -> None:

class TestHappyPath:
def test_captures_secrets_wipes_redeploys_and_waits_for_health(
self, phase, docker, monkeypatch
self, phase, docker
) -> None:
cfg = ZDUTestConfig(clean_build=True, old_image_tag="zdu-old-abc12345")
monkeypatch.setenv("DATAHUB_LOCAL_COMMON_ENV", "zdu-test.env")

with patch.object(phase, "_wait_for_health", return_value=True):
result = phase.run(TestContext(), cfg)
Expand Down Expand Up @@ -97,11 +96,11 @@ def test_captures_secrets_wipes_redeploys_and_waits_for_health(
assert compose_env["DATAHUB_GMS_VERSION"] == "zdu-old-abc12345"
assert compose_env["DATAHUB_TOKEN_SERVICE_SIGNING_KEY"] == "captured-key"
assert compose_env["DATAHUB_TOKEN_SERVICE_SALT"] == "captured-salt"
assert compose_env["DATAHUB_LOCAL_COMMON_ENV"] == "zdu-test.env"
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
# G20a — reindex flags do NOT go through compose_env. They reach the
# JVM via env_file (zdu-test.env, loaded by the compose YAML's
# ${DATAHUB_LOCAL_COMMON_ENV} substitution). Asserting absence here
# keeps the contract honest.
# The auth bypass comes from the ZDU job layer, not the ad-hoc file.
assert "DATAHUB_LOCAL_COMMON_ENV" not in compose_env
# G20a — reindex flags do NOT go through compose_env; they are
# one-shot -e flags on the explicit system-update runs. Asserting
# absence here keeps the contract honest.
assert (
"ELASTICSEARCH_BUILD_INDICES_INCREMENTAL_REINDEX_ENABLED" not in compose_env
)
Expand All @@ -111,19 +110,6 @@ def test_captures_secrets_wipes_redeploys_and_waits_for_health(
assert docker.up_stack.call_args.kwargs["services"] is None


class TestMissingLocalCommonEnv:
def test_skips_authz_env_when_not_set(self, phase, docker, monkeypatch) -> None:
# No DATAHUB_LOCAL_COMMON_ENV in env → compose_env shouldn't carry it.
monkeypatch.delenv("DATAHUB_LOCAL_COMMON_ENV", raising=False)
cfg = ZDUTestConfig(clean_build=True, old_image_tag="zdu-old-abc12345")

with patch.object(phase, "_wait_for_health", return_value=True):
phase.run(TestContext(), cfg)

compose_env = docker.up_stack.call_args.kwargs["compose_env"]
assert "DATAHUB_LOCAL_COMMON_ENV" not in compose_env


class TestPartialSecretCapture:
"""If only one of SIGNING_KEY/SALT is available from the running stack,
the missing key is filled in from docker/.local-secrets.env (the
Expand Down
124 changes: 40 additions & 84 deletions smoke-test/tests/unit/zdu/test_preflight.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,15 @@ def _ok_urlopen() -> MagicMock:
return cm


def _write_bypass_env(tmp_path: Path) -> str:
env_file = tmp_path / "zdu-test.env"
env_file.write_text(
"AUTH_POLICIES_ENABLED=false\n"
"REST_API_AUTHORIZATION_ENABLED=false\n"
"METADATA_SERVICE_AUTH_ENABLED=false\n"
)
return "zdu-test.env"
@pytest.fixture(autouse=True)
def _no_adhoc_env(monkeypatch) -> None:
monkeypatch.delenv("DATAHUB_LOCAL_COMMON_ENV", raising=False)


class TestAllChecksPass:
def test_passes_when_stack_up_token_set_and_env_correct(
self, phase: PreflightPhase, tmp_path: Path, monkeypatch
) -> None:
env_file_name = _write_bypass_env(tmp_path)
monkeypatch.setenv("DATAHUB_LOCAL_COMMON_ENV", env_file_name)
cfg = ZDUTestConfig(
gms_token="test-token", clean_build=False, refresh_token=False
)
Expand All @@ -62,8 +55,6 @@ class TestGmsUnreachable:
def test_fails_when_health_endpoint_unreachable(
self, phase: PreflightPhase, tmp_path: Path, monkeypatch
) -> None:
env_file_name = _write_bypass_env(tmp_path)
monkeypatch.setenv("DATAHUB_LOCAL_COMMON_ENV", env_file_name)
cfg = ZDUTestConfig(
gms_token="test-token", clean_build=False, refresh_token=False
)
Expand All @@ -81,8 +72,6 @@ class TestTokenMissing:
def test_fails_when_token_none(
self, phase: PreflightPhase, tmp_path: Path, monkeypatch
) -> None:
env_file_name = _write_bypass_env(tmp_path)
monkeypatch.setenv("DATAHUB_LOCAL_COMMON_ENV", env_file_name)
cfg = ZDUTestConfig(gms_token=None, clean_build=False, refresh_token=False)
ctx = TestContext()
with patch(
Expand All @@ -97,8 +86,6 @@ def test_fails_when_token_none(
def test_fails_when_token_empty_string(
self, phase: PreflightPhase, tmp_path: Path, monkeypatch
) -> None:
env_file_name = _write_bypass_env(tmp_path)
monkeypatch.setenv("DATAHUB_LOCAL_COMMON_ENV", env_file_name)
cfg = ZDUTestConfig(gms_token="", clean_build=False, refresh_token=False)
ctx = TestContext()
with patch(
Expand All @@ -110,76 +97,52 @@ def test_fails_when_token_empty_string(
assert "DATAHUB_GMS_TOKEN" in (result.error or "")


class TestAuthzBypassEnvUnset:
def test_fails_when_local_common_env_unset(
self, phase: PreflightPhase, monkeypatch
) -> None:
monkeypatch.delenv("DATAHUB_LOCAL_COMMON_ENV", raising=False)
cfg = ZDUTestConfig(
gms_token="test-token", clean_build=False, refresh_token=False
)
ctx = TestContext()
with patch(
"tests.zdu.framework.phases.preflight.urllib.request.urlopen",
return_value=_ok_urlopen(),
):
result = phase.run(ctx, cfg)
assert result.status == "failed"
assert "DATAHUB_LOCAL_COMMON_ENV" in (result.error or "")
assert "zdu-test.env" in (result.error or "")
def _run_with_adhoc(phase: PreflightPhase) -> str | None:
cfg = ZDUTestConfig(gms_token="test-token", clean_build=False, refresh_token=False)
with patch(
"tests.zdu.framework.phases.preflight.urllib.request.urlopen",
return_value=_ok_urlopen(),
):
result = phase.run(TestContext(), cfg)
return result.error if result.status == "failed" else None

def test_fails_when_local_common_env_set_to_empty_env(

class TestAdHocEnvFile:
def test_passes_when_unset_or_empty_env(
self, phase: PreflightPhase, monkeypatch
) -> None:
assert _run_with_adhoc(phase) is None
monkeypatch.setenv("DATAHUB_LOCAL_COMMON_ENV", "empty.env")
cfg = ZDUTestConfig(
gms_token="test-token", clean_build=False, refresh_token=False
)
ctx = TestContext()
with patch(
"tests.zdu.framework.phases.preflight.urllib.request.urlopen",
return_value=_ok_urlopen(),
):
result = phase.run(ctx, cfg)
assert result.status == "failed"
assert "DATAHUB_LOCAL_COMMON_ENV" in (result.error or "")
assert _run_with_adhoc(phase) is None

def test_fails_when_file_missing(self, phase: PreflightPhase, monkeypatch) -> None:
# e.g. the removed docker/profiles/zdu-test.env still named by a shell.
monkeypatch.setenv("DATAHUB_LOCAL_COMMON_ENV", "zdu-test.env")
assert "no such file" in (_run_with_adhoc(phase) or "")

class TestAuthzBypassEnvFileBroken:
def test_fails_when_env_file_does_not_exist(
self, phase: PreflightPhase, monkeypatch
def test_passes_when_file_keeps_bypass(
self, phase: PreflightPhase, tmp_path: Path, monkeypatch
) -> None:
monkeypatch.setenv("DATAHUB_LOCAL_COMMON_ENV", "nonexistent.env")
cfg = ZDUTestConfig(
gms_token="test-token", clean_build=False, refresh_token=False
(tmp_path / "extra.env").write_text(
"SOME_OTHER_KEY=true\nAUTH_POLICIES_ENABLED=false\n"
)
ctx = TestContext()
with patch(
"tests.zdu.framework.phases.preflight.urllib.request.urlopen",
return_value=_ok_urlopen(),
):
result = phase.run(ctx, cfg)
assert result.status == "failed"
assert "no such file" in (result.error or "")
monkeypatch.setenv("DATAHUB_LOCAL_COMMON_ENV", "extra.env")
assert _run_with_adhoc(phase) is None

def test_fails_when_env_file_missing_bypass_keys(
def test_fails_when_file_reenables_auth(
self, phase: PreflightPhase, tmp_path: Path, monkeypatch
) -> None:
# File exists but lacks the required bypass keys.
bad_env = tmp_path / "bad.env"
bad_env.write_text("SOME_OTHER_KEY=value\n")
(tmp_path / "bad.env").write_text("METADATA_SERVICE_AUTH_ENABLED=true\n")
monkeypatch.setenv("DATAHUB_LOCAL_COMMON_ENV", "bad.env")
cfg = ZDUTestConfig(
gms_token="test-token", clean_build=False, refresh_token=False
)
ctx = TestContext()
with patch(
"tests.zdu.framework.phases.preflight.urllib.request.urlopen",
return_value=_ok_urlopen(),
):
result = phase.run(ctx, cfg)
assert result.status == "failed"
assert "missing required bypass keys" in (result.error or "")
assert "METADATA_SERVICE_AUTH_ENABLED" in (_run_with_adhoc(phase) or "")

def test_fails_when_file_has_bare_bypass_key(
self, phase: PreflightPhase, tmp_path: Path, monkeypatch
) -> None:
# A bare key unsets the variable, dropping the job layer's false.
(tmp_path / "bare.env").write_text("AUTH_POLICIES_ENABLED\n")
monkeypatch.setenv("DATAHUB_LOCAL_COMMON_ENV", "bare.env")
assert "AUTH_POLICIES_ENABLED" in (_run_with_adhoc(phase) or "")


class TestMultipleFailuresReportedTogether:
Expand All @@ -190,7 +153,7 @@ def test_all_failures_collected_in_single_run(
# we force ALL checks to fire (the default-on flags skip GMS-reachable
# and token-set so SetupOldStackPhase can fix them; here we test the
# "user has explicitly opted out of both" path).
monkeypatch.delenv("DATAHUB_LOCAL_COMMON_ENV", raising=False)
monkeypatch.setenv("DATAHUB_LOCAL_COMMON_ENV", "zdu-test.env")
cfg = ZDUTestConfig(gms_token=None, clean_build=False, refresh_token=False)
ctx = TestContext()
with patch(
Expand All @@ -216,8 +179,6 @@ class TestConditionalSkipping:
def test_gms_check_skipped_when_clean_build_on(
self, phase: PreflightPhase, tmp_path: Path, monkeypatch
) -> None:
env_file_name = _write_bypass_env(tmp_path)
monkeypatch.setenv("DATAHUB_LOCAL_COMMON_ENV", env_file_name)
# clean_build=True (default) → GMS-reachable check should NOT fire.
cfg = ZDUTestConfig(
gms_token="test-token", clean_build=True, refresh_token=False
Expand All @@ -234,8 +195,6 @@ def test_gms_check_skipped_when_clean_build_on(
def test_token_check_skipped_when_refresh_on(
self, phase: PreflightPhase, tmp_path: Path, monkeypatch
) -> None:
env_file_name = _write_bypass_env(tmp_path)
monkeypatch.setenv("DATAHUB_LOCAL_COMMON_ENV", env_file_name)
# refresh_token=True (default) → token-set check should NOT fire.
cfg = ZDUTestConfig(gms_token=None, clean_build=False, refresh_token=True)
ctx = TestContext()
Expand All @@ -250,11 +209,8 @@ def test_both_defaults_on_only_authz_env_checked(
self, phase: PreflightPhase, tmp_path: Path, monkeypatch
) -> None:
# New default: both clean_build and refresh_token are ON. Preflight
# reduces to just the DATAHUB_LOCAL_COMMON_ENV check. With nothing
# else set up (down stack, no token), preflight should still pass
# because the only remaining check is the env-file check.
env_file_name = _write_bypass_env(tmp_path)
monkeypatch.setenv("DATAHUB_LOCAL_COMMON_ENV", env_file_name)
# reduces to just the ad-hoc env-file check. With nothing else set
# up (down stack, no token), preflight should still pass.
cfg = ZDUTestConfig() # all defaults
ctx = TestContext()
with patch(
Expand Down
Loading
Loading