Skip to content

EC2: no CreateFleet handler (partial-fulfillment semantics are the interesting part) #387

Closed

Description

@scttfrdmn

What's missing

emulator/ec2_plugin.go dispatches 80 EC2 actions, including the full instance lifecycle
(RunInstances, DescribeInstances, TerminateInstances, StopInstances, StartInstances,
DescribeInstanceStatus) and launch templates (CreateLaunchTemplate,
DescribeLaunchTemplates). CreateFleet is not one of them.

The only occurrences of "fleet" in the repo are in emulator/iam_managed.go — policy strings
for the unrelated Spot Fleet API (ec2:RequestSpotFleet, ec2:CancelSpotFleetRequests, the
spotfleet.amazonaws.com service principal, the spot-fleet service role ARN). No handler.

Why it's worth having

CreateFleet with Type: instant is the standard way to launch a mixed on-demand/spot,
multi-instance-type, multi-subnet group of instances in one call, and it is what
Slurm-on-AWS autoscaling plugins use for node resume. RunInstances cannot substitute: the
reason to call CreateFleet is the launch-template-override matrix and the partial
fulfillment
semantics.

Those semantics are the interesting part to emulate, and they are exactly what is hard to
exercise against real AWS:

  • Partial fulfillment. An instant fleet asking for 12 instances can return 8, with
    Errors[] explaining the shortfall (InsufficientInstanceCapacity,
    InsufficientFreeAddressesInSubnet) and Instances[] listing what it did create. Callers
    routinely get this wrong — the response looks successful, and TotalTargetCapacity is what
    you asked for, not what you got.
  • Overrides. LaunchTemplateConfigs[].Overrides[] across instance types and subnets, with
    AllocationStrategy choosing among them.
  • Placement.GroupName on the template or the override — a cluster placement group also
    constrains fulfillment, since it cannot span AZs.
  • Type: instant vs request/maintain, which differ in whether the call returns
    instance IDs synchronously at all.

Concrete response shape a caller depends on

From the resume.py path in
scttfrdmn/aws-plugin-for-slurm — the
fields actually read, which is a useful minimum bar for a handler:

response_fleet['Instances']            # list; each has ['InstanceIds'] (a list)
response_fleet.get('Errors', [])       # each has ['ErrorCode'], ['ErrorMessage'],
                                       #   ['LaunchTemplateAndOverrides']['Overrides']
                                       #   -> .get('InstanceType'), .get('SubnetId')
                                       # and .get('Lifecycle')

Note Instances[].InstanceIds is a list per entry, not one id — flattening it wrong is a
classic bug, and it only shows up when a fleet returns multiple entries.

Request side, the same caller sends LaunchTemplateConfigs (with Overrides appended per
subnet/instance type), TargetCapacitySpecification, Type: instant, and optionally
OnDemandOptions / SpotOptions (with InstanceInterruptionBehavior).

Suggested shape

A case "CreateFleet" handler that:

  1. Parses LaunchTemplateConfigs[] + Overrides[] and TargetCapacitySpecification.
  2. Creates instances through the same path as runInstances so they are visible to
    DescribeInstances — including Placement.GroupName and tag propagation from
    TagSpecifications. Tag propagation matters: callers find their own instances afterward
    with DescribeInstances(Filters=[{'Name': 'tag:Name', ...}]), which this emulator already
    supports and tests.
  3. Returns {FleetId, Instances[{InstanceIds, InstanceType, LaunchTemplateAndOverrides}], Errors[]}.
  4. Supports a configurable shortfall — "fulfil N of M and report error code X" — so the
    partial path is reachable in tests.

DescribeFleets / DeleteFleets would round it out, but CreateFleet with instant alone
covers the autoscaling use case.

Context, and what is not missing

Came up while building the test suite for a Slurm power-save plugin, whose resume path is a
single CreateFleet call. I checked the rest of that plugin's AWS surface against this
emulator, and CreateFleet is the only gap — its other two calls are covered, including the
exact filter forms it uses:

Plugin call Substrate
create_fleet missing
describe_instances with Filters=[{tag:Name}, {instance-state-name}] supported (ec2_plugin.go:512,522) and tested
terminate_instances supported

I am not blocked. That suite uses a small purpose-built boto3 fake, which I would keep
regardless — fault injection on the partial-fleet path is the entire point of those tests, and
a fake I control is the shortest path to it. Filing because the gap is worth recording, not
because I need it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions