Commit 86b1a802 authored by Ramon Nou's avatar Ramon Nou
Browse files

test(malleability): isolate mutate hostfiles in tests

Use separate mutate hostfiles for expand workflows instead of rewriting the
active hostfile, and remove redundant marker rewrites from error-handling
tests. This keeps daemon discovery state intact while still exercising
malleability commands with the intended hostfile mutations.
parent 6d690721
Loading
Loading
Loading
Loading
+0 −31
Original line number Diff line number Diff line
@@ -67,17 +67,6 @@ def test_expand_start_with_same_node_count(gkfwd_daemon_factory, gkfs_shell):
            if not line.startswith("#"):
                hf_out.write(line)

    # Use marker-based approach: no --new-hosts-file needed
    # Mark all entries with '+' to simulate adding same nodes (will fail gracefully)
    with open(hostfile, 'r') as hf_in:
        original_lines = hf_in.readlines()
    with open(hostfile, 'w') as hf_out:
        for line in original_lines:
            if not line.startswith('#') and line.strip():
                hf_out.write('+' + line)
            else:
                hf_out.write(line)

    cmd_str = f"LIBGKFS_HOSTS_FILE={hostfile} gkfs_malleability mutate start"
    cmd = gkfs_shell.script(cmd_str, intercept_shell=False, timeout=340)
    time.sleep(3)
@@ -105,16 +94,6 @@ def test_shrink_status_after_failed_expand(gkfwd_daemon_factory, gkfs_shell):
            if not line.startswith("#"):
                hf_out.write(line)

    # Try mutate with markers (may fail due to same node count)
    with open(hostfile, 'r') as hf_in:
        original_lines = hf_in.readlines()
    with open(hostfile, 'w') as hf_out:
        for line in original_lines:
            if not line.startswith('#') and line.strip():
                hf_out.write('+' + line)
            else:
                hf_out.write(line)

    cmd_str = f"LIBGKFS_HOSTS_FILE={hostfile} gkfs_malleability mutate start"
    cmd = gkfs_shell.script(cmd_str, intercept_shell=False, timeout=340)
    time.sleep(3)
@@ -154,16 +133,6 @@ def test_malleability_expand_with_data(gkfwd_daemon_factory, gkfs_client, gkfs_s
    cmd = gkfs_shell.script(cmd_str, intercept_shell=False)
    assert cmd.exit_code == 0

    # Start mutation with markers (fails due to same node count, which is expected)
    with open(hostfile, 'r') as hf_in:
        original_lines = hf_in.readlines()
    with open(hostfile, 'w') as hf_out:
        for line in original_lines:
            if not line.startswith('#') and line.strip():
                hf_out.write('+' + line)
            else:
                hf_out.write(line)

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

+14 −12
Original line number Diff line number Diff line
@@ -81,9 +81,10 @@ def test_expand(gkfwd_daemon_factory, gkfs_client, gkfs_shell):
    d01 = gkfwd_daemon_factory.create(expand_mode=True)
    time.sleep(2)
    d01_port = d01.address.split(":")[-1]
    mutate_hostfile = hostfile.parent / "gkfs_hosts_expand_mutate.txt"
    with open(hostfile, "r") as hf_in:
        original_lines = hf_in.readlines()
    with open(hostfile, "w") as hf_out:
    with open(mutate_hostfile, "w") as hf_out:
        for line in original_lines:
            stripped = line.strip()
            if not stripped or stripped.startswith("#"):
@@ -94,23 +95,23 @@ def test_expand(gkfwd_daemon_factory, gkfs_client, gkfs_shell):
            else:
                hf_out.write(line)

    cmd = _run_cmd(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(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(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(hostfile, "mutate finalize", gkfs_shell)
    cmd = _run_cmd(mutate_hostfile, "mutate finalize", gkfs_shell)
    assert cmd.exit_code == 0

    for i in range(4):
@@ -118,7 +119,7 @@ def test_expand(gkfwd_daemon_factory, gkfs_client, gkfs_shell):
        ret = gkfs_client.stat(fpath)
        assert ret.retval == 0, f"stat failed for {fpath} after expand"

    with open(hostfile, "r") as hf:
    with open(mutate_hostfile, "r") as hf:
        content = hf.read()
    for line in content.splitlines():
        stripped = line.strip()
@@ -229,9 +230,10 @@ def test_mutate_swap(gkfwd_daemon_factory, gkfs_client, gkfs_shell):

    d01_port = d01.address.split(":")[-1]
    d02_port = d02.address.split(":")[-1]
    mutate_hostfile = old_hostfile.parent / "gkfs_hosts_mutate_swap.txt"
    with open(old_hostfile, "r") as hf_in:
        original_lines = hf_in.readlines()
    with open(old_hostfile, "w") as hf_out:
    with open(mutate_hostfile, "w") as hf_out:
        for line in original_lines:
            stripped = line.strip()
            if not stripped or stripped.startswith("#"):
@@ -244,23 +246,23 @@ def test_mutate_swap(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

    for i in range(4):
@@ -268,7 +270,7 @@ def test_mutate_swap(gkfwd_daemon_factory, gkfs_client, gkfs_shell):
        ret = gkfs_client.stat(fpath)
        assert ret.retval == 0, f"stat failed for {fpath} after mutate swap"

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