Skip to content

Commit de05a36

Browse files
test: add test for canonical pcie
Signed-off-by: Abhinandan Purkait <[email protected]>
1 parent 753de5f commit de05a36

File tree

6 files changed

+84
-56
lines changed

6 files changed

+84
-56
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

control-plane/agents/src/bin/core/tests/pool/mod.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use grpc::{
77
},
88
};
99
use itertools::Itertools;
10-
use regex::Regex;
1110
use std::{collections::HashMap, convert::TryFrom, thread::sleep, time::Duration};
1211
use stor_port::types::v0::store::pool::{Encryption, EncryptionSecret};
1312
use stor_port::types::v0::transport::{GetBlockDevices, NodeStatus};
@@ -1364,34 +1363,3 @@ async fn reject_devlink_reuse() {
13641363
}
13651364
}
13661365
}
1367-
1368-
#[tokio::test]
1369-
async fn persistent_devlink_regex() {
1370-
fn is_persistent_devlink(pattern: &str) -> bool {
1371-
let re = Regex::new(utils::DEVLINK_REGEX).expect("DEVLINK_REGEX should be valid");
1372-
re.is_match(pattern)
1373-
}
1374-
1375-
let test_suite = [
1376-
("/dev/some/path", false),
1377-
("/dev/mapper/some/path", false),
1378-
("/dev/disk/some/path", false),
1379-
("/dev/disk/by-something/path", false),
1380-
("/devil/disk/by-something/path", false),
1381-
("/dev/diskxyz/by-something/path", false),
1382-
("/dev/disk/something-by/path", false),
1383-
("/dev/disk/by-/path", false),
1384-
("something", false),
1385-
("/dev/somevg/lv0", false), // LVM Paths are to be used via the /dev/mapper or by /dev/disk/by-id
1386-
("/dev/disk/by-id/somepath", true),
1387-
("/dev/disk/by-path/somepath", true),
1388-
("/dev/disk/by-label/somepath", true),
1389-
("/dev/disk/by-partuuid/somepath", true),
1390-
("/dev/disk/by-partlabel/somepath", true),
1391-
("/dev/mapper/dm0", true),
1392-
];
1393-
1394-
for test in test_suite {
1395-
assert_eq!(is_persistent_devlink(test.0), test.1);
1396-
}
1397-
}

k8s/operators/src/pool/main.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -358,24 +358,3 @@ pub(crate) async fn migrate_and_clean_msps(k8s: &Client, namespace: &str) -> Res
358358
}
359359
Ok(())
360360
}
361-
362-
#[cfg(test)]
363-
mod test {
364-
365-
#[test]
366-
fn normalize_disk() {
367-
let disks = [
368-
"aio:///dev/null",
369-
"uring:///dev/null",
370-
"uring://dev/null", // this URL is invalid
371-
"pcie:///0000:01:00.0",
372-
"pcie:///00:01:00.0",
373-
];
374-
375-
assert_eq!(utils::disk::normalize_disk(disks[0]), "/dev/null");
376-
assert_eq!(utils::disk::normalize_disk(disks[1]), "/dev/null");
377-
assert_eq!(utils::disk::normalize_disk(disks[2]), "uring://dev/null");
378-
assert_eq!(utils::disk::normalize_disk(disks[3]), "/0000:01:00.0");
379-
assert_eq!(utils::disk::normalize_disk(disks[4]), "/0000:01:00.0");
380-
}
381-
}

tests/bdd/features/ana/validate/test_validate_nexus_swap.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
)
1111
import pytest
1212
import subprocess
13+
from retrying import retry
1314

1415
from common.deployer import Deployer
1516
from common.apiclient import ApiClient
@@ -179,6 +180,7 @@ def publish_to_node_2(background):
179180

180181

181182
@pytest.fixture
183+
@retry(wait_fixed=10, stop_max_attempt_number=200)
182184
def connect_to_node_2(publish_to_node_2):
183185
device = nvme_connect(publish_to_node_2)
184186
desc = nvme_list_subsystems(device)

utils/utils-lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ url = "2.5.4"
2323
strum = "0.26.3"
2424
strum_macros = "0.26.4"
2525
heck = "0.5.0"
26+
regex = "1.11.1"
2627

2728
version-info = { path = "../dependencies/version-info", default-features = false }
2829
git-version-macro = { path = "../dependencies/git-version-macro" }

utils/utils-lib/src/disk.rs

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use url::Url;
22

3-
/// Normalize the disks if they have a schema, we dont want to change anything
4-
/// or do any error checking -- the loop will converge to the error state eventually
3+
/// Normalize the disks if they have a schema, we don't want to change anything
4+
/// or do any error checking.
55
pub fn normalize_disk(disk: &str) -> String {
66
let disk = if disk.starts_with("pcie://") {
77
canonical_pcie_address(disk).unwrap_or_else(|| disk.to_string())
@@ -19,7 +19,7 @@ pub fn normalize_disk(disk: &str) -> String {
1919
}
2020

2121
fn canonical_pcie_address(addr: &str) -> Option<String> {
22-
let stripped = addr.strip_prefix("pcie://")?;
22+
let stripped = addr.strip_prefix("pcie:///")?;
2323

2424
let parts: Vec<&str> = stripped.split([':', '.']).collect();
2525
if parts.len() != 4 {
@@ -33,3 +33,80 @@ fn canonical_pcie_address(addr: &str) -> Option<String> {
3333

3434
Some(format!("pcie:///{domain}:{bus}:{device}.{function}"))
3535
}
36+
37+
#[cfg(test)]
38+
mod tests {
39+
use crate::disk::{canonical_pcie_address, normalize_disk};
40+
use regex::Regex;
41+
42+
#[test]
43+
fn persistent_devlink_regex() {
44+
fn is_persistent_devlink(pattern: &str) -> bool {
45+
let re = Regex::new(crate::DEVLINK_REGEX).expect("DEVLINK_REGEX should be valid");
46+
re.is_match(pattern)
47+
}
48+
49+
let test_suite = [
50+
("/dev/some/path", false),
51+
("/dev/mapper/some/path", false),
52+
("/dev/disk/some/path", false),
53+
("/dev/disk/by-something/path", false),
54+
("/devil/disk/by-something/path", false),
55+
("/dev/diskxyz/by-something/path", false),
56+
("/dev/disk/something-by/path", false),
57+
("/dev/disk/by-/path", false),
58+
("something", false),
59+
("/dev/somevg/lv0", false),
60+
("/dev/disk/by-id/somepath", true),
61+
("/dev/disk/by-path/somepath", true),
62+
("/dev/disk/by-label/somepath", true),
63+
("/dev/disk/by-partuuid/somepath", true),
64+
("/dev/disk/by-partlabel/somepath", true),
65+
("/dev/mapper/dm0", true),
66+
];
67+
68+
for test in test_suite {
69+
assert_eq!(is_persistent_devlink(test.0), test.1);
70+
}
71+
}
72+
73+
#[test]
74+
fn normalize_disk_test() {
75+
let test_suite = [
76+
("aio:///dev/null", "/dev/null"),
77+
("uring:///dev/null", "/dev/null"),
78+
("uring://dev/null", "uring://dev/null"),
79+
("pcie:///0000:01:00.0", "/0000:01:00.0"),
80+
("pcie:///00:01:00.0", "/0000:01:00.0"),
81+
("pcie:///12454:01:00.0", "/12454:01:00.0"),
82+
];
83+
for test in test_suite {
84+
assert_eq!(normalize_disk(test.0), test.1);
85+
}
86+
}
87+
88+
#[test]
89+
fn canonical_pcie_address_test() {
90+
let test_suite = [
91+
(
92+
"pcie:///0000:01:00.0",
93+
Some("pcie:///0000:01:00.0".to_string()),
94+
),
95+
(
96+
"pcie:///00:01:00.0",
97+
Some("pcie:///0000:01:00.0".to_string()),
98+
),
99+
(
100+
"pcie:///12454:01:00.0", // Invalid address
101+
None,
102+
),
103+
(
104+
"pcie:///0011:0111:00.0", // Invalid address
105+
None,
106+
),
107+
];
108+
for test in test_suite {
109+
assert_eq!(canonical_pcie_address(test.0), test.1);
110+
}
111+
}
112+
}

0 commit comments

Comments
 (0)