81 lines
3.3 KiB
Python
81 lines
3.3 KiB
Python
"""Both-SIM permission is not a promise of priority or automatic failover."""
|
|
|
|
import json
|
|
|
|
import pytest
|
|
from test_equipment_network import context, full_core_context # noqa: F401
|
|
|
|
from k1link.device_plugins.arnavi_b2 import profiles
|
|
from k1link.device_plugins.arnavi_b2.usb_protocol import Configuration, Setting
|
|
from k1link.fleet import equipment_network as network
|
|
from k1link.fleet.independent_equipment import EquipmentError
|
|
|
|
|
|
@pytest.mark.parametrize("flags", [0, 1 << 10, 1 << 20, (1 << 10) | (1 << 20)])
|
|
def test_both_permission_preserves_apns_passwords_and_other_flags(flags):
|
|
before = Configuration(
|
|
(
|
|
Setting(72, (flags | 2072).to_bytes(4, "big")),
|
|
Setting(67, b"private.one"),
|
|
Setting(89, b"private.two"),
|
|
Setting(90, b"user"),
|
|
Setting(91, b"synthetic"),
|
|
)
|
|
)
|
|
after = profiles.prepare(before, {"connectivity": {"strategy": "both"}})
|
|
assert after.integer(72, 4) == 2072
|
|
assert after.records[1:] == before.records[1:]
|
|
with pytest.raises(ValueError):
|
|
profiles.Policy(connectivity={"strategy": "both", "apn": "conflict"})
|
|
|
|
|
|
@pytest.mark.parametrize("slot", [1, 2])
|
|
def test_core_both_receipt_accepts_either_real_slot_and_no_configuration_only_success(
|
|
full_core_context, # noqa: F811
|
|
monkeypatch,
|
|
slot,
|
|
):
|
|
equipment, hosts, row, config = full_core_context
|
|
row["settings"]["connectivity"] = {"strategy": "both"}
|
|
with equipment.db() as db:
|
|
db.execute("UPDATE instances SET body=? WHERE id=?", (json.dumps(row), row["id"]))
|
|
for host in hosts.rows():
|
|
host["status"]["version"] = "0.1.37"
|
|
hosts.save(host)
|
|
sent = []
|
|
|
|
def send(host, method, path, body=None):
|
|
sent.append(body)
|
|
return {"id": body["id"], "kind": body["kind"], "state": "queued", "durable": True}
|
|
|
|
monkeypatch.setattr(network, "request", send)
|
|
op = network.start(hosts, row["id"], 1, select_sim=True)["network_operation"]
|
|
assert op["sim_policy"] == sent[0]["sim_policy"] == "both"
|
|
assert "sim_slot" not in sent[0]
|
|
receipt = {"id": op["id"], "kind": "select-sim", "state": "verified"}
|
|
with pytest.raises(ValueError, match="not SIM selection"):
|
|
network.record(hosts, row["id"], op["id"], receipt)
|
|
for invalid in (0, 3, True):
|
|
with pytest.raises(ValueError, match="mismatch"):
|
|
network.record(
|
|
hosts,
|
|
row["id"],
|
|
op["id"],
|
|
{**receipt, "state": "sim_selected", "active_sim": invalid},
|
|
)
|
|
network.record(
|
|
hosts, row["id"], op["id"], {**receipt, "state": "sim_selected", "active_sim": slot}
|
|
)
|
|
assert equipment.listing()[0]["network_operation"]["active_sim"] == slot
|
|
|
|
|
|
def test_core_both_is_explicit_and_requires_compatible_vps(full_core_context): # noqa: F811
|
|
equipment, hosts, row, _ = full_core_context
|
|
row["settings"]["connectivity"] = {"strategy": "both"}
|
|
assert network.plan(equipment, row, full=True)["kind"] == "configure-all"
|
|
assert network.plan(equipment, row, full=True, select_sim=True)["kind"] == "select-sim"
|
|
with equipment.db() as db:
|
|
db.execute("UPDATE instances SET body=? WHERE id=?", (json.dumps(row), row["id"]))
|
|
with pytest.raises(EquipmentError, match="обеих SIM"):
|
|
network.start(hosts, row["id"], 1, select_sim=True)
|