Skip to content

Commit

Permalink
test: add test to validate replica listing scenarios on query
Browse files Browse the repository at this point in the history
Signed-off-by: Abhinandan Purkait <[email protected]>
  • Loading branch information
Abhinandan-Purkait committed Aug 24, 2023
1 parent 357a9fd commit f9f9d82
Show file tree
Hide file tree
Showing 3 changed files with 216 additions and 16 deletions.
8 changes: 4 additions & 4 deletions io-engine/src/grpc/v1/replica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,16 @@ fn filter_replicas_by_replica_type(
let query = &query;

let query_fields = vec![
(query.replica, (!replica.is_snapshot && !replica.is_clone)),
(query.snapshot, replica.is_snapshot),
(query.clone, replica.is_clone),
// ... add other fields here as needed
];

query_fields.iter().all(|(query_field, replica_field)| {
query_fields.iter().any(|(query_field, replica_field)| {
match query_field {
Some(true) => *replica_field,
Some(false) => !(*replica_field),
None => true,
true => *replica_field,
false => false,
}
})
})
Expand Down
222 changes: 211 additions & 11 deletions io-engine/tests/snapshot_nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ use io_engine::{
use io_engine_tests::file_io::{test_write_to_file, DataSize};
use nix::errno::Errno;

use mayastor_api::v1::snapshot::{
destroy_snapshot_request::Pool,
list_snapshots_request::Query,
CreateReplicaSnapshotRequest,
CreateSnapshotCloneRequest,
DestroySnapshotRequest,
use mayastor_api::v1::{
replica::list_replica_options,
snapshot::{
destroy_snapshot_request::Pool,
list_snapshots_request,
CreateReplicaSnapshotRequest,
CreateSnapshotCloneRequest,
DestroySnapshotRequest,
},
};
use std::{pin::Pin, str};
use uuid::Uuid;
Expand Down Expand Up @@ -965,7 +968,7 @@ async fn test_replica_snapshot_listing_with_query() {
.list_snapshot(ListSnapshotsRequest {
source_uuid: None,
snapshot_uuid: None,
query: Some(Query {
query: Some(list_snapshots_request::Query {
invalid: None,
discarded: Some(false),
}),
Expand Down Expand Up @@ -993,7 +996,7 @@ async fn test_replica_snapshot_listing_with_query() {
.list_snapshot(ListSnapshotsRequest {
source_uuid: None,
snapshot_uuid: None,
query: Some(Query {
query: Some(list_snapshots_request::Query {
invalid: None,
discarded: Some(false),
}),
Expand All @@ -1020,7 +1023,7 @@ async fn test_replica_snapshot_listing_with_query() {
.list_snapshot(ListSnapshotsRequest {
source_uuid: None,
snapshot_uuid: None,
query: Some(Query {
query: Some(list_snapshots_request::Query {
invalid: None,
discarded: Some(false),
}),
Expand All @@ -1038,7 +1041,7 @@ async fn test_replica_snapshot_listing_with_query() {
.list_snapshot(ListSnapshotsRequest {
source_uuid: None,
snapshot_uuid: None,
query: Some(Query {
query: Some(list_snapshots_request::Query {
invalid: None,
discarded: Some(true),
}),
Expand All @@ -1056,7 +1059,7 @@ async fn test_replica_snapshot_listing_with_query() {
.list_snapshot(ListSnapshotsRequest {
source_uuid: None,
snapshot_uuid: None,
query: Some(Query {
query: Some(list_snapshots_request::Query {
invalid: None,
discarded: None,
}),
Expand All @@ -1081,3 +1084,200 @@ async fn test_replica_snapshot_listing_with_query() {
.snapshots;
assert_eq!(snaps.len(), 2);
}

/// This tests creates 2 replicas --> 2 snapshots --> 1 restore --> Validates
/// listing.
#[tokio::test]
async fn test_replica_listing_with_query() {
let _ = get_ms();
let (test, _urls) = launch_instance(true).await;
let conn = GrpcConnect::new(&test);
let snap1 = Uuid::new_v4();

let mut ms1 = conn
.grpc_handle("ms1")
.await
.expect("Can't connect to remote I/O agent");

ms1.snapshot
.create_replica_snapshot(CreateReplicaSnapshotRequest {
replica_uuid: replica1_uuid(),
snapshot_uuid: snap1.to_string(),
snapshot_name: "snap1rep1/2".to_string(),
entity_id: "snap1rep1".to_string(),
txn_id: "1".to_string(),
})
.await
.expect("Should create replica snapshot");

ms1.snapshot
.create_replica_snapshot(CreateReplicaSnapshotRequest {
replica_uuid: replica2_uuid(),
snapshot_uuid: Uuid::new_v4().to_string(),
snapshot_name: "snap2rep2/1".to_string(),
entity_id: "snap2rep2".to_string(),
txn_id: "1".to_string(),
})
.await
.expect("Should create replica snapshot");

ms1.snapshot
.create_snapshot_clone(CreateSnapshotCloneRequest {
snapshot_uuid: snap1.to_string(),
clone_name: "snaprep1clone".to_string(),
clone_uuid: Uuid::new_v4().to_string(),
})
.await
.expect("Should create snapshot clone");

// List all with query None, all replicas including snapshots and clones.
let replicas = ms1
.replica
.list_replicas(ListReplicaOptions {
name: None,
poolname: None,
uuid: None,
pooluuid: None,
query: None,
})
.await
.expect("List should not fail")
.into_inner()
.replicas;
assert_eq!(replicas.len(), 5);

// List all replicas except snapshots.
let replicas = ms1
.replica
.list_replicas(ListReplicaOptions {
name: None,
poolname: None,
uuid: None,
pooluuid: None,
query: Some(list_replica_options::Query {
replica: true,
snapshot: false,
clone: true,
}),
})
.await
.expect("List should not fail")
.into_inner()
.replicas;
assert_eq!(replicas.len(), 3);
assert!(!replicas[0].is_snapshot);
assert!(!replicas[1].is_snapshot);
assert!(!replicas[2].is_snapshot);

// List all replicas except clones.
let replicas = ms1
.replica
.list_replicas(ListReplicaOptions {
name: None,
poolname: None,
uuid: None,
pooluuid: None,
query: Some(list_replica_options::Query {
replica: true,
snapshot: true,
clone: false,
}),
})
.await
.expect("List should not fail")
.into_inner()
.replicas;
assert_eq!(replicas.len(), 4);
assert!(!replicas[0].is_clone);
assert!(!replicas[1].is_clone);
assert!(!replicas[2].is_clone);
assert!(!replicas[3].is_clone);

// List only clones and snapshots.
let replicas = ms1
.replica
.list_replicas(ListReplicaOptions {
name: None,
poolname: None,
uuid: None,
pooluuid: None,
query: Some(list_replica_options::Query {
replica: false,
snapshot: true,
clone: true,
}),
})
.await
.expect("List should not fail")
.into_inner()
.replicas;
assert_eq!(replicas.len(), 3);
assert!(replicas[0].is_clone || replicas[0].is_snapshot);
assert!(replicas[1].is_clone || replicas[1].is_snapshot);
assert!(replicas[2].is_clone || replicas[2].is_snapshot);

// List only snapshots.
let replicas = ms1
.replica
.list_replicas(ListReplicaOptions {
name: None,
poolname: None,
uuid: None,
pooluuid: None,
query: Some(list_replica_options::Query {
replica: false,
snapshot: true,
clone: false,
}),
})
.await
.expect("List should not fail")
.into_inner()
.replicas;
assert_eq!(replicas.len(), 2);
assert!(replicas[0].is_snapshot);
assert!(replicas[1].is_snapshot);

// List only clones.
let replicas = ms1
.replica
.list_replicas(ListReplicaOptions {
name: None,
poolname: None,
uuid: None,
pooluuid: None,
query: Some(list_replica_options::Query {
replica: false,
snapshot: false,
clone: true,
}),
})
.await
.expect("List should not fail")
.into_inner()
.replicas;
assert_eq!(replicas.len(), 1);
assert!(replicas[0].is_clone);

// List all only replicas.
let replicas = ms1
.replica
.list_replicas(ListReplicaOptions {
name: None,
poolname: None,
uuid: None,
pooluuid: None,
query: Some(list_replica_options::Query {
replica: true,
snapshot: false,
clone: false,
}),
})
.await
.expect("List should not fail")
.into_inner()
.replicas;
assert_eq!(replicas.len(), 2);
assert!(!replicas[0].is_clone && !replicas[0].is_snapshot);
assert!(!replicas[1].is_clone && !replicas[1].is_snapshot);
}
2 changes: 1 addition & 1 deletion rpc/mayastor-api

0 comments on commit f9f9d82

Please sign in to comment.