-
Notifications
You must be signed in to change notification settings - Fork 40
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
Fix ip pool policy for instance allocation #2113
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -11,6 +11,9 @@ use nexus_test_utils::http_testing::NexusRequest; | |||
use nexus_test_utils::http_testing::RequestBuilder; | ||||
use nexus_test_utils::resource_helpers::create_disk; | ||||
use nexus_test_utils::resource_helpers::create_ip_pool; | ||||
use nexus_test_utils::resource_helpers::create_local_user; | ||||
use nexus_test_utils::resource_helpers::create_silo; | ||||
use nexus_test_utils::resource_helpers::grant_iam; | ||||
use nexus_test_utils::resource_helpers::object_create; | ||||
use nexus_test_utils::resource_helpers::objects_list_page_authz; | ||||
use nexus_test_utils::resource_helpers::populate_ip_pool; | ||||
|
@@ -26,9 +29,11 @@ use omicron_common::api::external::InstanceState; | |||
use omicron_common::api::external::Ipv4Net; | ||||
use omicron_common::api::external::Name; | ||||
use omicron_common::api::external::NetworkInterface; | ||||
use omicron_nexus::authz::SiloRole; | ||||
use omicron_nexus::external_api::shared::IpKind; | ||||
use omicron_nexus::external_api::shared::IpRange; | ||||
use omicron_nexus::external_api::shared::Ipv4Range; | ||||
use omicron_nexus::external_api::shared::SiloIdentityMode; | ||||
use omicron_nexus::external_api::views; | ||||
use omicron_nexus::TestInterfaces as _; | ||||
use omicron_nexus::{external_api::params, Nexus}; | ||||
|
@@ -2889,6 +2894,98 @@ async fn test_instance_ephemeral_ip_from_correct_pool( | |||
); | ||||
} | ||||
|
||||
#[nexus_test] | ||||
async fn test_instance_create_in_silo(cptestctx: &ControlPlaneTestContext) { | ||||
let client = &cptestctx.external_client; | ||||
|
||||
// Create a silo with a Collaborator User | ||||
let silo = | ||||
create_silo(&client, "authz", true, SiloIdentityMode::LocalOnly).await; | ||||
let user_id = create_local_user( | ||||
client, | ||||
&silo, | ||||
&"unpriv".parse().unwrap(), | ||||
params::UserPassword::InvalidPassword, | ||||
) | ||||
.await | ||||
.id; | ||||
grant_iam( | ||||
client, | ||||
"/system/silos/authz", | ||||
SiloRole::Collaborator, | ||||
user_id, | ||||
AuthnMode::PrivilegedUser, | ||||
) | ||||
.await; | ||||
|
||||
// Populate IP Pool | ||||
populate_ip_pool(&client, "default", None).await; | ||||
|
||||
// Create test organization and projects. | ||||
NexusRequest::objects_post( | ||||
client, | ||||
"/organizations", | ||||
¶ms::OrganizationCreate { | ||||
identity: IdentityMetadataCreateParams { | ||||
name: ORGANIZATION_NAME.parse().unwrap(), | ||||
description: String::new(), | ||||
}, | ||||
}, | ||||
) | ||||
.authn_as(AuthnMode::SiloUser(user_id)) | ||||
.execute() | ||||
.await | ||||
.expect("failed to create Organization") | ||||
.parsed_body::<views::Organization>() | ||||
.expect("failed to parse new Organization"); | ||||
NexusRequest::objects_post( | ||||
client, | ||||
&format!("/organizations/{ORGANIZATION_NAME}/projects"), | ||||
¶ms::ProjectCreate { | ||||
identity: IdentityMetadataCreateParams { | ||||
name: PROJECT_NAME.parse().unwrap(), | ||||
description: String::new(), | ||||
}, | ||||
}, | ||||
) | ||||
.authn_as(AuthnMode::SiloUser(user_id)) | ||||
.execute() | ||||
.await | ||||
.expect("failed to create Project") | ||||
.parsed_body::<views::Project>() | ||||
.expect("failed to parse new Project"); | ||||
|
||||
// Create an instance using the authorization granted to the collaborator | ||||
// Silo User. | ||||
let instance_params = params::InstanceCreate { | ||||
identity: IdentityMetadataCreateParams { | ||||
name: Name::try_from(String::from("ip-pool-test")).unwrap(), | ||||
description: String::from("instance to test IP Pool authz"), | ||||
}, | ||||
ncpus: InstanceCpuCount::try_from(2).unwrap(), | ||||
memory: ByteCount::from_gibibytes_u32(4), | ||||
hostname: String::from("inst"), | ||||
user_data: vec![], | ||||
network_interfaces: params::InstanceNetworkInterfaceAttachment::Default, | ||||
external_ips: vec![params::ExternalIpCreate::Ephemeral { | ||||
pool_name: Some(Name::try_from(String::from("default")).unwrap()), | ||||
}], | ||||
disks: vec![], | ||||
start: true, | ||||
}; | ||||
let url_instances = format!( | ||||
"/organizations/{}/projects/{}/instances", | ||||
ORGANIZATION_NAME, PROJECT_NAME | ||||
); | ||||
NexusRequest::objects_post(client, &url_instances, &instance_params) | ||||
.authn_as(AuthnMode::SiloUser(user_id)) | ||||
.execute() | ||||
.await | ||||
.expect("Failed to create instance") | ||||
.parsed_body::<Instance>() | ||||
.expect("Failed to parse instance"); | ||||
Comment on lines
+2980
to
+2986
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before updating the polar policy, this failed. The instance creation pathway checks for For example:
|
||||
} | ||||
|
||||
async fn instance_get( | ||||
client: &ClientTestContext, | ||||
instance_url: &str, | ||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really part of this PR, but it would be neat if the
resource_helpers
used a builder pattern to make these calls a little easier to customize. They currently hard-code "privileged user", which means I need to do the request myself.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's open a bug for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2114