ignore active-only tailscale peers in ip discovery
This commit is contained in:
parent
a7aabdff51
commit
e8ee085649
2 changed files with 50 additions and 1 deletions
|
|
@ -260,7 +260,7 @@ class EC2Runtime(RuntimeAdapter):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _peer_is_online(peer: dict[str, Any]) -> bool:
|
def _peer_is_online(peer: dict[str, Any]) -> bool:
|
||||||
return bool(peer.get("Online") or peer.get("Active"))
|
return bool(peer.get("Online"))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _peer_hostname(peer: dict[str, Any]) -> str | None:
|
def _peer_hostname(peer: dict[str, Any]) -> str | None:
|
||||||
|
|
|
||||||
|
|
@ -249,6 +249,55 @@ class TestDescribeInstance:
|
||||||
info = runtime.describe_instance("i-running1")
|
info = runtime.describe_instance("i-running1")
|
||||||
assert info["tailscale_ip"] is None
|
assert info["tailscale_ip"] is None
|
||||||
|
|
||||||
|
@patch.object(
|
||||||
|
EC2Runtime,
|
||||||
|
"_read_tailscale_status",
|
||||||
|
return_value={
|
||||||
|
"Peer": {
|
||||||
|
"stale": {
|
||||||
|
"HostName": "nix-builder-slot001",
|
||||||
|
"Online": False,
|
||||||
|
"Active": True,
|
||||||
|
"TailscaleIPs": ["100.64.0.10"],
|
||||||
|
},
|
||||||
|
"current": {
|
||||||
|
"HostName": "nix-builder-slot001",
|
||||||
|
"Online": True,
|
||||||
|
"Active": False,
|
||||||
|
"TailscaleIPs": ["100.64.0.11"],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
def test_ignores_active_but_offline_stale_peer(self, _mock_status):
|
||||||
|
ec2_client = boto3.client("ec2", region_name="us-east-1")
|
||||||
|
stubber = Stubber(ec2_client)
|
||||||
|
|
||||||
|
launch_time = datetime(2026, 1, 15, 12, 30, 0, tzinfo=UTC)
|
||||||
|
response = {
|
||||||
|
"Reservations": [
|
||||||
|
{
|
||||||
|
"Instances": [
|
||||||
|
{
|
||||||
|
"InstanceId": "i-running1",
|
||||||
|
"State": {"Code": 16, "Name": "running"},
|
||||||
|
"LaunchTime": launch_time,
|
||||||
|
"Tags": [{"Key": "AutoscalerSlot", "Value": "slot001"}],
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
|
stubber.add_response(
|
||||||
|
"describe_instances",
|
||||||
|
response,
|
||||||
|
{"InstanceIds": ["i-running1"]},
|
||||||
|
)
|
||||||
|
runtime = _make_runtime(stubber, ec2_client)
|
||||||
|
|
||||||
|
info = runtime.describe_instance("i-running1")
|
||||||
|
assert info["tailscale_ip"] == "100.64.0.11"
|
||||||
|
|
||||||
def test_localapi_permission_error_returns_none(self):
|
def test_localapi_permission_error_returns_none(self):
|
||||||
ec2_client = boto3.client("ec2", region_name="us-east-1")
|
ec2_client = boto3.client("ec2", region_name="us-east-1")
|
||||||
runtime = EC2Runtime(_make_config(), _client=ec2_client)
|
runtime = EC2Runtime(_make_config(), _client=ec2_client)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue