Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nexus] instance create: make hostname param optional #6824

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions common/src/api/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3173,6 +3173,9 @@ mod test {
for name in valid_names {
eprintln!("check name \"{}\" (should be valid)", name);
assert_eq!(name, name.parse::<Name>().unwrap().as_str());
// make sure valid names are also valid hostnames so we can use names as
// fallback hostnames, e.g., in instance create
assert_eq!(name, name.parse::<Hostname>().unwrap().as_str());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There aren't that many examples in the list. It would be cool to do a proptest type thing here but I didn't see any tests like that in omicron.

}
}

Expand Down
2 changes: 1 addition & 1 deletion end-to-end-tests/src/instance_launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async fn instance_launch() -> Result<()> {
.body(InstanceCreate {
name: generate_name("instance")?,
description: String::new(),
hostname: "localshark".parse().unwrap(), // 🦈
hostname: Some("localshark".parse().unwrap()), // 🦈
memory: ByteCount(1024 * 1024 * 1024),
ncpus: InstanceCpuCount(2),
boot_disk: Some(InstanceDiskAttachment::Attach {
Expand Down
5 changes: 4 additions & 1 deletion nexus/db-model/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ impl Instance {
user_data: params.user_data.clone(),
ncpus: params.ncpus.into(),
memory: params.memory.into(),
hostname: params.hostname.to_string(),
hostname: match &params.hostname {
Some(hostname) => hostname.to_string(),
None => params.identity.name.to_string(),
},
auto_restart,
// Intentionally ignore `params.boot_disk_id` here: we can't set
// `boot_disk_id` until the referenced disk is attached.
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2006,7 +2006,7 @@ mod tests {
},
ncpus: 2i64.try_into().unwrap(),
memory: ByteCount::from_gibibytes_u32(16),
hostname: "myhostname".try_into().unwrap(),
hostname: Some("myhostname".try_into().unwrap()),
user_data: Vec::new(),
network_interfaces:
params::InstanceNetworkInterfaceAttachment::None,
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ mod tests {
},
ncpus: 2i64.try_into().unwrap(),
memory: ByteCount::from_gibibytes_u32(16),
hostname: "myhostname".try_into().unwrap(),
hostname: Some("myhostname".try_into().unwrap()),
user_data: Vec::new(),
network_interfaces:
params::InstanceNetworkInterfaceAttachment::None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ mod test {
},
ncpus: cpus.try_into().unwrap(),
memory: memory.try_into().unwrap(),
hostname: "myhostname".try_into().unwrap(),
hostname: Some("myhostname".try_into().unwrap()),
user_data: Vec::new(),
network_interfaces:
params::InstanceNetworkInterfaceAttachment::None,
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/vpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3708,7 +3708,7 @@ mod tests {
},
ncpus: external::InstanceCpuCount(1),
memory: 10.into(),
hostname: "insty".parse().unwrap(),
hostname: Some("insty".parse().unwrap()),
user_data: vec![],
network_interfaces:
params::InstanceNetworkInterfaceAttachment::None,
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/queries/external_ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ mod tests {
identity: IdentityMetadataCreateParams { name: String::from(name).parse().unwrap(), description: format!("instance {}", name) },
ncpus: InstanceCpuCount(omicron_common::api::external::InstanceCpuCount(1)).into(),
memory: ByteCount(omicron_common::api::external::ByteCount::from_gibibytes_u32(1)).into(),
hostname: "test".parse().unwrap(),
hostname: Some("test".parse().unwrap()),
ssh_public_keys: None,
user_data: vec![],
network_interfaces: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/queries/network_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1853,7 +1853,7 @@ mod tests {
},
ncpus: InstanceCpuCount(4),
memory: ByteCount::from_gibibytes_u32(4),
hostname: "inst".parse().unwrap(),
hostname: Some("inst".parse().unwrap()),
user_data: vec![],
ssh_public_keys: Some(Vec::new()),
network_interfaces: InstanceNetworkInterfaceAttachment::None,
Expand Down
2 changes: 1 addition & 1 deletion nexus/src/app/background/tasks/instance_reincarnation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ mod test {
// resource requests as small as possible.
ncpus: 1i64.try_into().unwrap(),
memory: ByteCount::from_gibibytes_u32(2),
hostname: "myhostname".try_into().unwrap(),
hostname: Some("myhostname".try_into().unwrap()),
user_data: Vec::new(),
network_interfaces:
params::InstanceNetworkInterfaceAttachment::None,
Expand Down
2 changes: 1 addition & 1 deletion nexus/src/app/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2413,7 +2413,7 @@ mod tests {
},
ncpus: InstanceCpuCount(1),
memory: ByteCount::from_gibibytes_u32(1),
hostname: Hostname::try_from("elysium").unwrap(),
hostname: Some(Hostname::try_from("elysium").unwrap()),
user_data: vec![],
network_interfaces: InstanceNetworkInterfaceAttachment::None,
external_ips: vec![],
Expand Down
2 changes: 1 addition & 1 deletion nexus/src/app/sagas/instance_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,7 @@ pub mod test {
},
ncpus: InstanceCpuCount::try_from(2).unwrap(),
memory: ByteCount::from_gibibytes_u32(4),
hostname: "inst".parse().unwrap(),
hostname: Some("inst".parse().unwrap()),
user_data: vec![],
ssh_public_keys: None,
network_interfaces:
Expand Down
2 changes: 1 addition & 1 deletion nexus/src/app/sagas/instance_delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ mod test {
},
ncpus: InstanceCpuCount::try_from(2).unwrap(),
memory: ByteCount::from_gibibytes_u32(4),
hostname: "inst".parse().unwrap(),
hostname: Some("inst".parse().unwrap()),
user_data: vec![],
ssh_public_keys: Some(Vec::new()),
network_interfaces:
Expand Down
2 changes: 1 addition & 1 deletion nexus/src/app/sagas/instance_migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ mod tests {
},
ncpus: InstanceCpuCount(2),
memory: ByteCount::from_gibibytes_u32(2),
hostname: INSTANCE_NAME.parse().unwrap(),
hostname: Some(INSTANCE_NAME.parse().unwrap()),
user_data: b"#cloud-config".to_vec(),
ssh_public_keys: Some(Vec::new()),
network_interfaces:
Expand Down
2 changes: 1 addition & 1 deletion nexus/src/app/sagas/instance_start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ mod test {
},
ncpus: InstanceCpuCount(2),
memory: ByteCount::from_gibibytes_u32(2),
hostname: INSTANCE_NAME.parse().unwrap(),
hostname: Some(INSTANCE_NAME.parse().unwrap()),
user_data: b"#cloud-config".to_vec(),
ssh_public_keys: Some(Vec::new()),
network_interfaces:
Expand Down
2 changes: 1 addition & 1 deletion nexus/src/app/sagas/instance_update/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,7 @@ mod test {
},
ncpus: InstanceCpuCount(1),
memory: ByteCount::from_gibibytes_u32(1),
hostname: INSTANCE_NAME.parse().unwrap(),
hostname: Some(INSTANCE_NAME.parse().unwrap()),
user_data: b"#cloud-config".to_vec(),
ssh_public_keys: Some(Vec::new()),
network_interfaces:
Expand Down
2 changes: 1 addition & 1 deletion nexus/src/app/sagas/snapshot_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2124,7 +2124,7 @@ mod test {
},
ncpus: InstanceCpuCount(2),
memory: ByteCount::from_gibibytes_u32(1),
hostname: "base-instance".parse().unwrap(),
hostname: Some("base-instance".parse().unwrap()),
user_data:
b"#cloud-config\nsystem_info:\n default_user:\n name: oxide"
.to_vec(),
Expand Down
2 changes: 1 addition & 1 deletion nexus/test-utils/src/resource_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ pub async fn create_instance_with(
},
ncpus: InstanceCpuCount(4),
memory: ByteCount::from_gibibytes_u32(1),
hostname: "the-host".parse().unwrap(),
hostname: Some("the-host".parse().unwrap()),
user_data:
b"#cloud-config\nsystem_info:\n default_user:\n name: oxide"
.to_vec(),
Expand Down
2 changes: 1 addition & 1 deletion nexus/tests/integration_tests/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ pub static DEMO_INSTANCE_CREATE: Lazy<params::InstanceCreate> =
},
ncpus: InstanceCpuCount(1),
memory: ByteCount::from_gibibytes_u32(16),
hostname: "demo-instance".parse().unwrap(),
hostname: Some("demo-instance".parse().unwrap()),
user_data: vec![],
ssh_public_keys: Some(Vec::new()),
network_interfaces: params::InstanceNetworkInterfaceAttachment::Default,
Expand Down
2 changes: 1 addition & 1 deletion nexus/tests/integration_tests/external_ips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ async fn test_floating_ip_attach_fail_between_projects(
},
ncpus: InstanceCpuCount(4),
memory: ByteCount::from_gibibytes_u32(1),
hostname: "the-host".parse().unwrap(),
hostname: Some("the-host".parse().unwrap()),
user_data:
b"#cloud-config\nsystem_info:\n default_user:\n name: oxide"
.to_vec(),
Expand Down
Loading
Loading