Commit b45d460a authored by Ramon Nou's avatar Ramon Nou
Browse files

test: use clean hostfiles in malleability tests

Update malleability integration tests to run commands and clients against
the intended active topology hostfiles. Add helpers to derive clean hostfiles
from marker files and update client hostfile environment after mutation
finalization to avoid stale or marker-based topology state.
parent 86b1a802
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -67,12 +67,12 @@ def test_expand_start_with_same_node_count(gkfwd_daemon_factory, gkfs_shell):
            if not line.startswith("#"):
                hf_out.write(line)

    cmd_str = f"LIBGKFS_HOSTS_FILE={hostfile} gkfs_malleability mutate start"
    cmd_str = f"LIBGKFS_HOSTS_FILE={new_hostfile} gkfs_malleability mutate start"
    cmd = gkfs_shell.script(cmd_str, intercept_shell=False, timeout=340)
    time.sleep(3)

    # Verify daemon is still running (didn't crash)
    cmd_str = f"LIBGKFS_HOSTS_FILE={hostfile} gkfs_malleability mutate status"
    cmd_str = f"LIBGKFS_HOSTS_FILE={new_hostfile} gkfs_malleability mutate status"
    cmd = gkfs_shell.script(cmd_str, intercept_shell=False)
    assert cmd.exit_code == 0, \
        f"Daemon crashed after expand start: {cmd.stderr.decode()}"
@@ -94,12 +94,12 @@ def test_shrink_status_after_failed_expand(gkfwd_daemon_factory, gkfs_shell):
            if not line.startswith("#"):
                hf_out.write(line)

    cmd_str = f"LIBGKFS_HOSTS_FILE={hostfile} gkfs_malleability mutate start"
    cmd_str = f"LIBGKFS_HOSTS_FILE={new_hostfile} gkfs_malleability mutate start"
    cmd = gkfs_shell.script(cmd_str, intercept_shell=False, timeout=340)
    time.sleep(3)

    # Verify mutate status works
    cmd_str = f"LIBGKFS_HOSTS_FILE={hostfile} gkfs_malleability mutate status"
    cmd_str = f"LIBGKFS_HOSTS_FILE={new_hostfile} gkfs_malleability mutate status"
    cmd = gkfs_shell.script(cmd_str, intercept_shell=False)
    assert cmd.exit_code == 0, \
        f"shrink status after failed expand failed: {cmd.stderr.decode()}"
@@ -127,17 +127,20 @@ def test_malleability_expand_with_data(gkfwd_daemon_factory, gkfs_client, gkfs_s
        assert ret.retval == 0, f"write_validate failed for {f}"

    hostfile = Path(d00.hostfile)
    same_hostfile = hostfile.parent / "gkfs_hosts_expand_with_data_same.txt"
    with open(hostfile, "r") as hf_in, open(same_hostfile, "w") as hf_out:
        hf_out.writelines(hf_in.readlines())

    # Verify no running mutation
    cmd_str = f"LIBGKFS_HOSTS_FILE={hostfile} gkfs_malleability mutate status"
    cmd_str = f"LIBGKFS_HOSTS_FILE={same_hostfile} gkfs_malleability mutate status"
    cmd = gkfs_shell.script(cmd_str, intercept_shell=False)
    assert cmd.exit_code == 0

    cmd_str = f"LIBGKFS_HOSTS_FILE={hostfile} gkfs_malleability mutate start"
    cmd_str = f"LIBGKFS_HOSTS_FILE={same_hostfile} gkfs_malleability mutate start"
    cmd = gkfs_shell.script(cmd_str, intercept_shell=False, timeout=340)

    # Verify daemon is still running
    cmd_str = f"LIBGKFS_HOSTS_FILE={hostfile} gkfs_malleability mutate status"
    cmd_str = f"LIBGKFS_HOSTS_FILE={same_hostfile} gkfs_malleability mutate status"
    cmd = gkfs_shell.script(cmd_str, intercept_shell=False)
    assert cmd.exit_code == 0, \
        f"Daemon crashed after expand start: {cmd.stderr.decode()}"
+41 −8
Original line number Diff line number Diff line
@@ -59,6 +59,29 @@ def _run_cmd(hosts_file, args, gkfs_shell, timeout=None):
    return cmd


def _write_clean_hostfile(marker_hostfile, clean_hostfile):
    """Write final active topology from a marker hostfile."""
    with open(marker_hostfile, "r") as hf_in, open(clean_hostfile, "w") as hf_out:
        for line in hf_in:
            stripped = line.strip()
            if not stripped or stripped.startswith("#"):
                hf_out.write(line)
            elif stripped.startswith("-"):
                continue
            elif stripped.startswith("+"):
                hf_out.write(line[1:])
            else:
                hf_out.write(line)


def _set_client_hostfile(client, hostfile):
    value = str(hostfile)
    if hasattr(client, "_patched_env"):
        client._patched_env["LIBGKFS_HOSTS_FILE"] = value
    if hasattr(client, "_env"):
        client._env["LIBGKFS_HOSTS_FILE"] = value


def test_expand(gkfwd_daemon_factory, gkfs_client, gkfs_shell):
    """
    Scenario: ADD (expand)
@@ -113,13 +136,16 @@ def test_expand(gkfwd_daemon_factory, gkfs_client, gkfs_shell):

    cmd = _run_cmd(mutate_hostfile, "mutate finalize", gkfs_shell)
    assert cmd.exit_code == 0
    clean_hostfile = hostfile.parent / "gkfs_hosts_expand_clean.txt"
    _write_clean_hostfile(mutate_hostfile, clean_hostfile)
    _set_client_hostfile(gkfs_client, clean_hostfile)

    for i in range(4):
        fpath = d00.mountdir / f"expand_file_{i}"
        ret = gkfs_client.stat(fpath)
        assert ret.retval == 0, f"stat failed for {fpath} after expand"

    with open(mutate_hostfile, "r") as hf:
    with open(clean_hostfile, "r") as hf:
        content = hf.read()
    for line in content.splitlines():
        stripped = line.strip()
@@ -154,7 +180,8 @@ def test_shrink(gkfwd_daemon_factory, gkfs_client, gkfs_shell):
    d01_port = d01.address.split(":")[-1]
    with open(old_hostfile, "r") as hf_in:
        original_lines = hf_in.readlines()
    with open(old_hostfile, "w") as hf_out:
    mutate_hostfile = old_hostfile.parent / "gkfs_hosts_shrink_mutate.txt"
    with open(mutate_hostfile, "w") as hf_out:
        for line in original_lines:
            stripped = line.strip()
            if not stripped or stripped.startswith("#"):
@@ -165,31 +192,34 @@ def test_shrink(gkfwd_daemon_factory, gkfs_client, gkfs_shell):
            else:
                hf_out.write(line)

    cmd = _run_cmd(old_hostfile, "mutate status", gkfs_shell)
    cmd = _run_cmd(mutate_hostfile, "mutate status", gkfs_shell)
    assert "No mutate running/finished." in cmd.stderr.decode()

    cmd = _run_cmd(old_hostfile, "mutate start", gkfs_shell, timeout=340
    cmd = _run_cmd(mutate_hostfile, "mutate start", gkfs_shell, timeout=340
    )
    assert "Mutate process" in cmd.stderr.decode()

    deadline = time.time() + 120
    while time.time() < deadline:
        cmd = _run_cmd(old_hostfile, "mutate status", gkfs_shell)
        cmd = _run_cmd(mutate_hostfile, "mutate status", gkfs_shell)
        if "No mutate running/finished." in cmd.stderr.decode():
            break
        time.sleep(2)
    else:
        pytest.fail("Mutate redistribution did not finish within 120 s")

    cmd = _run_cmd(old_hostfile, "mutate finalize", gkfs_shell)
    cmd = _run_cmd(mutate_hostfile, "mutate finalize", gkfs_shell)
    assert cmd.exit_code == 0
    clean_hostfile = old_hostfile.parent / "gkfs_hosts_shrink_clean.txt"
    _write_clean_hostfile(mutate_hostfile, clean_hostfile)
    _set_client_hostfile(gkfs_client, clean_hostfile)

    for i in range(8):
        fpath = d00.mountdir / f"shrink_file_{i}"
        ret = gkfs_client.stat(fpath)
        assert ret.retval == 0, f"stat failed for {fpath} after shrink"

    with open(old_hostfile, "r") as hf:
    with open(clean_hostfile, "r") as hf:
        content = hf.read()
    for line in content.splitlines():
        stripped = line.strip()
@@ -264,13 +294,16 @@ def test_mutate_swap(gkfwd_daemon_factory, gkfs_client, gkfs_shell):

    cmd = _run_cmd(mutate_hostfile, "mutate finalize", gkfs_shell)
    assert cmd.exit_code == 0
    clean_hostfile = old_hostfile.parent / "gkfs_hosts_mutate_swap_clean.txt"
    _write_clean_hostfile(mutate_hostfile, clean_hostfile)
    _set_client_hostfile(gkfs_client, clean_hostfile)

    for i in range(4):
        fpath = d00.mountdir / f"mutate_file_{i}"
        ret = gkfs_client.stat(fpath)
        assert ret.retval == 0, f"stat failed for {fpath} after mutate swap"

    with open(mutate_hostfile, "r") as hf:
    with open(clean_hostfile, "r") as hf:
        content = hf.read()
    for line in content.splitlines():
        stripped = line.strip()