Skip to content

Make test instance setup less repetitive - #11858

Merged
iximeow merged 13 commits into
mainfrom
ixi/instance-create-test-params
Nov 20, 2026
Merged

iximeow merged 13 commits into
mainfrom
ixi/instance-create-test-params

Conversation

@iximeow

@iximeow iximeow commented Nov 19, 2026

Copy link
Copy Markdown
Member

when I added cpu_platforms a while ago it was kind of sad how many InstanceCreate I had to go touch, but I did because I wasn't sure how to spell it better at the time. as I'm going to be adding a new field imminently, I was looking at this again and got sad again because we've added a few more fields and clearly other folks were kind of sad about this same situation.

so, hopefully this gets people away from having to ask, when reading a test: "did the test author pick a value they thought was a good default, did the author pick a value they needed for a test, or is this just copied from somewhere else?"

this will conflict with #11565, which also adds a field to InstanceCreate and demonstrates my sadness. if #11565 goes first though, the resolution is probably straightforward: in all the places except where we're specifically testing the shutdown policy, take the default that this change introduces instead.

@iximeow

iximeow commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

after putting up the draft I noticed another fifty places we instance::InstanceCreate instead of instance_create_with, so I'll push another commit or two here before marking this ready for review.

@david-crespo

Copy link
Copy Markdown
Contributor

Love it. Big fan of leaning on the helpers. The verbosity of our tests makes it so hard to understand which choices matter.

instances.rs did different stuff with ssh key defaults than everything else..
client,
PROJECT_NAME,
INSTANCE_NAME,
&Default::default(),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was probably a bug in the test setup (which I think did not matter). an instance that is created in Stopped would get the default DefaultDualStack interface, rather than the DefaultIpv4 that create_instance() just above would use. I assume we should probably test with dual-stack subnets at this point but the tests but create_default_subnet_pool only sets up V4 test subnets. this is the case for all the create_instance_stopped() here.

Comment on lines -377 to -378
"instance {:?}",
instance.identity.name

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the most part I have tried to keep instance settings matching whatever they were before the refactor, but some of these were so funky I had a hard time convincing myself to care about a weird interim point. since name is a Name, the {:?} here would make the instance's description instance Name("just-rainsticks"). InstanceCreateBuilder's default description also formats with {:?}, but does so on the &str for the instance name, so this is "only" instance "just-rainsticks" now.

@@ -3158,33 +3019,9 @@ async fn test_instances_create_stopped_start(
create_project_and_pool(&client).await;

// Create an instance in a stopped state.
let instance: Instance = object_create(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create_instance_stopped is such an appropriate helper here I struggle to convince myself that it's wroth spelling out the old defaults, and this test obviously does not care about user data, SSH keys, etc.

let interim_body = instance::InstanceCreate {
identity: IdentityMetadataCreateParams {
name: instance_name.parse().unwrap(),
description: format!("instance {:?}", instance_name),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of wish this was instance {}, but that gets beyond what I was willing to tolerate in "largely refactoring".

anti_affinity_groups: Vec::new(),
enable_jumbo_frames: false,
};
.with_ssh_public_keys(None)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is where we actually care about None vs Some(vec![...]). other uses of .with_ssh_public_keys(None) are just to match a prior ssh_public_keys: None which itself was probably a copy-paste default.

anywhere outside this test I kind of think we should discard a ssh_public_keys setting (as well as with_user_data(&[])..) because really the test just wanted some kind of reasonable value to make the builder compile.

@iximeow
iximeow marked this pull request as ready for review November 19, 2026 19:37

@jmpesp jmpesp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ship it ship it ship it ship it ship it

pool: DEMO_IP_POOL_NAME.clone().into(),
},
}])
.with_start(true)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was true before too, but: should this be creating a stopped instance instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yes, this was the other "I think our tests do the wrong thing" that I had wanted to comment on. thank you for noticing. I think it should, but it I think it doesn't matter because we don't use these demo instances in ways that would care. I definitely didn't want to change it without more reading than I wanted to do in this diff.

Comment on lines -381 to -382
ncpus: instance.ncpus,
memory: instance.memory,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would help to have a InstanceCreateBuilder::from(&instance)? Maybe as follow up work, not to delay this PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's actually pretty rare that we want a carbon-copy of a specific instance's settings. here, I think this is because "we had an instance up there, this is shorter to type than the InstanceCpuCount and ByteCount::from_gibibytes invocations, end of". this test does care about the instance name matching, and that's about it really...

@iximeow

iximeow commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

since you've both taken a look already (thanks!) I've fixed the conflict and will merge this as-is. there'll be a followup PR to move the integration_tests/multicast stuff over too.

@iximeow
iximeow merged commit 7ed8343 into main Nov 20, 2026
19 checks passed
@iximeow
iximeow deleted the ixi/instance-create-test-params branch November 20, 2026 04:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants