Skip to content

Commit

Permalink
Unauthorized test, tweak DiskTest to supply custom UUIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
smklein committed Mar 27, 2024
1 parent 80931b6 commit 65ac86b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 20 deletions.
40 changes: 31 additions & 9 deletions nexus/test-utils/src/resource_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,17 @@ pub struct DiskTest {

impl DiskTest {
pub const DEFAULT_ZPOOL_SIZE_GIB: u32 = 10;
pub const DEFAULT_ZPOOL_COUNT: u32 = 3;

/// Creates a new "DiskTest", but does not actually add any zpools.
pub async fn empty<N: NexusServer>(
cptestctx: &ControlPlaneTestContext<N>,
) -> Self {
let sled_agent = cptestctx.sled_agent.sled_agent.clone();

Self { sled_agent, zpools: vec![] }
}

// Creates fake physical storage, an organization, and a project.
pub async fn new<N: NexusServer>(
cptestctx: &ControlPlaneTestContext<N>,
) -> Self {
Expand All @@ -718,10 +727,8 @@ impl DiskTest {
let mut disk_test = Self { sled_agent, zpools: vec![] };

// Create three Zpools, each 10 GiB, each with one Crucible dataset.
for _ in 0..3 {
disk_test
.add_zpool_with_dataset(cptestctx, Self::DEFAULT_ZPOOL_SIZE_GIB)
.await;
for _ in 0..Self::DEFAULT_ZPOOL_COUNT {
disk_test.add_zpool_with_dataset(cptestctx).await;
}

disk_test
Expand All @@ -730,18 +737,33 @@ impl DiskTest {
pub async fn add_zpool_with_dataset<N: NexusServer>(
&mut self,
cptestctx: &ControlPlaneTestContext<N>,
) {
self.add_zpool_with_dataset_ext(
cptestctx,
Uuid::new_v4(),
Uuid::new_v4(),
Uuid::new_v4(),
Self::DEFAULT_ZPOOL_SIZE_GIB,
)
.await
}

pub async fn add_zpool_with_dataset_ext<N: NexusServer>(
&mut self,
cptestctx: &ControlPlaneTestContext<N>,
physical_disk_id: Uuid,
zpool_id: Uuid,
dataset_id: Uuid,
gibibytes: u32,
) {
// To get a dataset, we actually need to create a new simulated physical
// disk, zpool, and dataset, all contained within one another.
let zpool = TestZpool {
id: Uuid::new_v4(),
id: zpool_id,
size: ByteCount::from_gibibytes_u32(gibibytes),
datasets: vec![TestDataset { id: Uuid::new_v4() }],
datasets: vec![TestDataset { id: dataset_id }],
};

let physical_disk_id = Uuid::new_v4();

let disk_identity = DiskIdentity {
vendor: "test-vendor".into(),
serial: format!("totally-unique-serial: {}", physical_disk_id),
Expand Down
12 changes: 6 additions & 6 deletions nexus/tests/integration_tests/disks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -967,9 +967,9 @@ async fn test_disk_backed_by_multiple_region_sets(
assert_eq!(10, DiskTest::DEFAULT_ZPOOL_SIZE_GIB);

// Create another three zpools, all 10 gibibytes, each with one dataset
test.add_zpool_with_dataset(cptestctx, 10).await;
test.add_zpool_with_dataset(cptestctx, 10).await;
test.add_zpool_with_dataset(cptestctx, 10).await;
test.add_zpool_with_dataset(cptestctx).await;
test.add_zpool_with_dataset(cptestctx).await;
test.add_zpool_with_dataset(cptestctx).await;

create_project_and_pool(client).await;

Expand Down Expand Up @@ -1682,9 +1682,9 @@ async fn test_multiple_disks_multiple_zpools(
// Assert default is still 10 GiB
assert_eq!(10, DiskTest::DEFAULT_ZPOOL_SIZE_GIB);

test.add_zpool_with_dataset(cptestctx, 10).await;
test.add_zpool_with_dataset(cptestctx, 10).await;
test.add_zpool_with_dataset(cptestctx, 10).await;
test.add_zpool_with_dataset(cptestctx).await;
test.add_zpool_with_dataset(cptestctx).await;
test.add_zpool_with_dataset(cptestctx).await;

create_project_and_pool(client).await;

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 @@ -1967,7 +1967,7 @@ pub static VERIFY_ENDPOINTS: Lazy<Vec<VerifyEndpoint>> = Lazy::new(|| {

VerifyEndpoint {
url: &HARDWARE_DISK_URL,
visibility: Visibility::Public,
visibility: Visibility::Protected,
unprivileged_access: UnprivilegedAccess::None,
allowed_methods: vec![AllowedMethod::Get],
},
Expand Down
12 changes: 11 additions & 1 deletion nexus/tests/integration_tests/unauthorized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,17 @@ type ControlPlaneTestContext =
// 403).
#[nexus_test]
async fn test_unauthorized(cptestctx: &ControlPlaneTestContext) {
DiskTest::new(cptestctx).await;
let mut disk_test = DiskTest::new(cptestctx).await;
disk_test
.add_zpool_with_dataset_ext(
cptestctx,
nexus_test_utils::PHYSICAL_DISK_UUID.parse().unwrap(),
uuid::Uuid::new_v4(),
uuid::Uuid::new_v4(),
DiskTest::DEFAULT_ZPOOL_SIZE_GIB,
)
.await;

let client = &cptestctx.external_client;
let log = &cptestctx.logctx.log;
let mut setup_results = std::collections::BTreeMap::new();
Expand Down
4 changes: 1 addition & 3 deletions nexus/tests/integration_tests/volume_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2052,9 +2052,7 @@ async fn test_keep_your_targets_straight(cptestctx: &ControlPlaneTestContext) {

// Four zpools, one dataset each
let mut disk_test = DiskTest::new(&cptestctx).await;
disk_test
.add_zpool_with_dataset(&cptestctx, DiskTest::DEFAULT_ZPOOL_SIZE_GIB)
.await;
disk_test.add_zpool_with_dataset(&cptestctx).await;

// This bug occurs when region_snapshot records share a snapshot_addr, so
// insert those here manually.
Expand Down

0 comments on commit 65ac86b

Please sign in to comment.