Skip to content

Commit 8b4cfaf

Browse files
mayastor-borsdsharma-dc
andcommitted
Merge #1861
1861: test(encryption): basic component test for encrypted pool r=dsharma-dc a=dsharma-dc Co-authored-by: Diwakar Sharma <[email protected]>
2 parents e5d0d18 + c5a9e1a commit 8b4cfaf

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

io-engine/tests/lvs_pool.rs

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use common::MayastorTest;
22
use io_engine::{
3+
bdev::crypto::{Cipher, EncryptionKey},
34
bdev_api::bdev_create,
45
core::{logical_volume::LogicalVolume, MayastorCliArgs, Protocol, Share, UntypedBdev},
56
lvs::{Lvs, LvsLvol, PropName, PropValue},
@@ -14,6 +15,9 @@ static TESTDIR: &str = "/tmp/io-engine-tests";
1415
static DISKNAME1: &str = "/tmp/io-engine-tests/disk1.img";
1516
static DISKNAME2: &str = "/tmp/io-engine-tests/disk2.img";
1617
static DISKNAME3: &str = "/tmp/io-engine-tests/disk3.img";
18+
static DISK_CRYPTO: &str = "/tmp/io-engine-tests/crypto_disk.img";
19+
static XTS_KEY: &str = "2b7e151628aed2a6abf7158809cf4f3c";
20+
static XTS_KEY2: &str = "2b7e151628aed2a6abf7158809cf4f3d";
1721

1822
#[tokio::test]
1923
async fn lvs_pool_test() {
@@ -25,10 +29,16 @@ async fn lvs_pool_test() {
2529
.output()
2630
.expect("failed to execute mkdir");
2731

28-
common::delete_file(&[DISKNAME1.into(), DISKNAME2.into(), DISKNAME3.into()]);
32+
common::delete_file(&[
33+
DISKNAME1.into(),
34+
DISKNAME2.into(),
35+
DISKNAME3.into(),
36+
DISK_CRYPTO.into(),
37+
]);
2938
common::truncate_file(DISKNAME1, 128 * 1024);
3039
common::truncate_file(DISKNAME2, 128 * 1024);
3140
common::truncate_file(DISKNAME3, 128 * 1024);
41+
common::truncate_file(DISK_CRYPTO, 128 * 1024);
3242

3343
//setup disk3 via loop device using a sector size of 4096.
3444
let ldev = common::setup_loopdev_file(DISKNAME3, Some(4096));
@@ -482,4 +492,51 @@ async fn lvs_pool_test() {
482492
common::delete_file(&[DISKNAME2.into()]);
483493
common::detach_loopdev(ldev.as_str());
484494
common::delete_file(&[DISKNAME3.into()]);
495+
496+
// Create an encrypted pool
497+
ms.spawn(async {
498+
let pool = Lvs::create_or_import(PoolArgs {
499+
name: "enc_pool".into(),
500+
disks: vec![format!("aio://{DISK_CRYPTO}")],
501+
uuid: None,
502+
cluster_size: None,
503+
md_args: None,
504+
backend: PoolBackend::Lvs,
505+
enc_key: Some(EncryptionKey {
506+
cipher: Cipher::AesXts,
507+
key_name: "test_key".into(),
508+
key: XTS_KEY.into(),
509+
key_len: 128,
510+
key2: Some(XTS_KEY2.into()),
511+
key2_len: Some(128),
512+
}),
513+
crypto_vbdev_name: Some("crypto_enc_pool".into()),
514+
})
515+
.await
516+
.unwrap();
517+
let pool_base_bdev = pool.base_bdev();
518+
assert_eq!(pool_base_bdev.driver(), "crypto");
519+
let underlying_bdev = pool_base_bdev.crypto_base_bdev().unwrap();
520+
// we internally use diskname as aio bdev name.
521+
assert_eq!(underlying_bdev.name(), DISK_CRYPTO);
522+
523+
// create some replicas on encrypted pool
524+
let pool = Lvs::lookup("enc_pool").unwrap();
525+
for i in 0..5 {
526+
pool.create_lvol(&format!("encvol-{i}"), 8 * 1024 * 1024, None, true, None)
527+
.await
528+
.unwrap();
529+
}
530+
assert_eq!(pool.lvols().unwrap().count(), 5);
531+
let dest = pool
532+
.lvols()
533+
.unwrap()
534+
.map(|r| r.destroy())
535+
.collect::<Vec<_>>();
536+
assert_eq!(dest.len(), 5);
537+
futures::future::join_all(dest).await;
538+
pool.destroy().await.unwrap();
539+
common::delete_file(&[DISK_CRYPTO.into()]);
540+
})
541+
.await;
485542
}

0 commit comments

Comments
 (0)