agent: complete plan05 closeout
This commit is contained in:
parent
33ba248c49
commit
2f0fffa905
12 changed files with 1347 additions and 313 deletions
|
|
@ -130,6 +130,135 @@ class TestDescribeInstance:
|
|||
assert info["tailscale_ip"] is None
|
||||
assert info["launch_time"] == launch_time.isoformat()
|
||||
|
||||
@patch.object(
|
||||
EC2Runtime,
|
||||
"_read_tailscale_status",
|
||||
return_value={
|
||||
"Peer": {
|
||||
"peer1": {
|
||||
"HostName": "nix-builder-slot001-i-running1",
|
||||
"Online": True,
|
||||
"TailscaleIPs": ["100.64.0.10"],
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
def test_discovers_tailscale_ip_from_localapi(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.10"
|
||||
|
||||
@patch.object(EC2Runtime, "_read_tailscale_status", return_value={"Peer": {}})
|
||||
def test_discovery_unavailable_returns_none(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"] is None
|
||||
|
||||
@patch.object(
|
||||
EC2Runtime,
|
||||
"_read_tailscale_status",
|
||||
return_value={
|
||||
"Peer": {
|
||||
"peer1": {
|
||||
"HostName": "nix-builder-slot001-old",
|
||||
"Online": True,
|
||||
"TailscaleIPs": ["100.64.0.10"],
|
||||
},
|
||||
"peer2": {
|
||||
"HostName": "nix-builder-slot001-new",
|
||||
"Online": True,
|
||||
"TailscaleIPs": ["100.64.0.11"],
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
def test_ambiguous_slot_match_returns_none(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"] is None
|
||||
|
||||
def test_localapi_permission_error_returns_none(self):
|
||||
ec2_client = boto3.client("ec2", region_name="us-east-1")
|
||||
runtime = EC2Runtime(_make_config(), _client=ec2_client)
|
||||
|
||||
with patch(
|
||||
"nix_builder_autoscaler.runtime.ec2._UnixSocketHTTPConnection.connect",
|
||||
side_effect=PermissionError,
|
||||
):
|
||||
assert runtime._read_tailscale_status() is None
|
||||
|
||||
def test_missing_instance_returns_terminated(self):
|
||||
ec2_client = boto3.client("ec2", region_name="us-east-1")
|
||||
stubber = Stubber(ec2_client)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue