Skip to content

Commit 7605115

Browse files
committed
Simplify project_deletion_with_instance; start instance 'stopped'
1 parent 6400f95 commit 7605115

File tree

2 files changed

+27
-44
lines changed

2 files changed

+27
-44
lines changed

end-to-end-tests/src/helpers/ctx.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ use crate::helpers::generate_name;
22
use anyhow::{Context as _, Result};
33
use omicron_sled_agent::rack_setup::config::SetupServiceConfig;
44
use oxide_client::types::{Name, OrganizationCreate, ProjectCreate};
5-
use oxide_client::{Client, ClientOrganizationsExt, ClientProjectsExt, ClientVpcsExt};
5+
use oxide_client::{
6+
Client, ClientOrganizationsExt, ClientProjectsExt, ClientVpcsExt,
7+
};
68
use reqwest::header::{HeaderMap, HeaderValue, AUTHORIZATION};
79
use reqwest::Url;
810
use std::net::SocketAddr;

nexus/tests/integration_tests/projects.rs

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,17 @@ use nexus_test_utils::http_testing::AuthnMode;
1010
use nexus_test_utils::http_testing::NexusRequest;
1111
use nexus_test_utils::http_testing::RequestBuilder;
1212
use nexus_test_utils::resource_helpers::{
13-
create_disk, create_instance_with, create_ip_pool, create_organization,
14-
create_project, create_vpc, object_create, project_get, DiskTest,
13+
create_disk, create_ip_pool, create_organization, create_project,
14+
create_vpc, object_create, project_get, DiskTest,
1515
};
1616
use nexus_test_utils_macros::nexus_test;
17+
use omicron_common::api::external::ByteCount;
1718
use omicron_common::api::external::IdentityMetadataCreateParams;
1819
use omicron_common::api::external::Instance;
20+
use omicron_common::api::external::InstanceCpuCount;
1921
use omicron_nexus::external_api::params;
2022
use omicron_nexus::external_api::views;
2123
use omicron_nexus::external_api::views::Project;
22-
use omicron_nexus::Nexus;
23-
use omicron_nexus::TestInterfaces as _;
24-
use sled_agent_client::TestInterfaces as _;
25-
use std::sync::Arc;
26-
use uuid::Uuid;
2724

2825
type ControlPlaneTestContext =
2926
nexus_test_utils::ControlPlaneTestContext<omicron_nexus::Server>;
@@ -135,11 +132,6 @@ async fn delete_project_expect_fail(
135132
error.message
136133
}
137134

138-
pub async fn instance_simulate(nexus: &Arc<Nexus>, id: &Uuid) {
139-
let sa = nexus.instance_sled_by_id(id).await.unwrap();
140-
sa.instance_finish_transition(id.clone()).await;
141-
}
142-
143135
#[nexus_test]
144136
async fn test_project_deletion(cptestctx: &ControlPlaneTestContext) {
145137
let client = &cptestctx.external_client;
@@ -171,7 +163,6 @@ async fn test_project_deletion_with_instance(
171163
cptestctx: &ControlPlaneTestContext,
172164
) {
173165
let client = &cptestctx.external_client;
174-
let apictx = &cptestctx.server.apictx;
175166

176167
let org_name = "test-org";
177168
create_ip_pool(&client, "p0", None, None).await;
@@ -184,43 +175,33 @@ async fn test_project_deletion_with_instance(
184175
create_project(&client, &org_name, &name).await;
185176
delete_project_default_subnet(&url, &client).await;
186177
delete_project_default_vpc(&url, &client).await;
187-
let instance = create_instance_with(
188-
&client,
189-
&org_name,
190-
&name,
191-
"my-instance",
192-
&params::InstanceNetworkInterfaceAttachment::None,
193-
vec![],
178+
179+
let _: Instance = object_create(
180+
client,
181+
&format!("{url}/instances"),
182+
&params::InstanceCreate {
183+
identity: IdentityMetadataCreateParams {
184+
name: "my-instance".parse().unwrap(),
185+
description: format!("description"),
186+
},
187+
ncpus: InstanceCpuCount(4),
188+
memory: ByteCount::from_gibibytes_u32(1),
189+
hostname: String::from("the_host"),
190+
user_data: b"none".to_vec(),
191+
network_interfaces:
192+
params::InstanceNetworkInterfaceAttachment::None,
193+
external_ips: vec![],
194+
disks: vec![],
195+
start: false,
196+
},
194197
)
195198
.await;
199+
196200
assert_eq!(
197201
"project to be deleted contains an instance",
198202
delete_project_expect_fail(&url, &client).await,
199203
);
200-
let nexus = &apictx.nexus;
201-
202-
// TODO: Can we start the instance as stopped...
203204

204-
// Let the instance start running
205-
instance_simulate(nexus, &instance.identity.id).await;
206-
// Ask the instance to stop
207-
NexusRequest::new(
208-
RequestBuilder::new(
209-
client,
210-
Method::POST,
211-
&format!("{url}/instances/my-instance/stop"),
212-
)
213-
.body(None as Option<&serde_json::Value>)
214-
.expect_status(Some(StatusCode::ACCEPTED)),
215-
)
216-
.authn_as(AuthnMode::PrivilegedUser)
217-
.execute()
218-
.await
219-
.unwrap()
220-
.parsed_body::<Instance>()
221-
.unwrap();
222-
// Let the instance stop
223-
instance_simulate(nexus, &instance.identity.id).await;
224205
NexusRequest::object_delete(
225206
client,
226207
&format!("{url}/instances/my-instance"),

0 commit comments

Comments
 (0)