Skip to content

Commit a646e77

Browse files
committed
tests: don't enforce NS management support for local testing
The tests framework added supported and dependency on NS management for clean setups. Though this prevents to run part of the tests suites on devices which do no support NS management. Add feature detection and skip the setup/tear down code for the NS setup if the device doesn't support this. Signed-off-by: Daniel Wagner <[email protected]>
1 parent 013f3a9 commit a646e77

1 file changed

Lines changed: 35 additions & 3 deletions

File tree

tests/nvme_test.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ def to_decimal(value):
4343
- Returns:
4444
- Decimal integer
4545
"""
46-
return int(str(value), 0)
46+
val = 0
47+
try:
48+
val = int(str(value), 0)
49+
except (TypeError, ValueError):
50+
raise ValueError(f"Invalid value: {value!r}")
51+
return val
4752

4853

4954
class TestNVMe(unittest.TestCase):
@@ -77,14 +82,17 @@ def setUp(self):
7782
self.load_config()
7883
if self.do_validate_pci_device:
7984
self.validate_pci_device()
80-
self.create_and_attach_default_ns()
85+
self.ns_mgmt_supported = self.get_ns_mgmt_support()
86+
if self.ns_mgmt_supported:
87+
self.create_and_attach_default_ns()
8188
print(f"\nsetup: ctrl: {self.ctrl}, ns1: {self.ns1}, default_nsid: {self.default_nsid}, flbas: {self.flbas}\n")
8289

8390
def tearDown(self):
8491
""" Post Section for TestNVMe. """
8592
if self.clear_log_dir is True:
8693
shutil.rmtree(self.log_dir, ignore_errors=True)
87-
self.create_and_attach_default_ns()
94+
if self.ns_mgmt_supported:
95+
self.create_and_attach_default_ns()
8896
print(f"\nteardown: ctrl: {self.ctrl}, ns1: {self.ns1}, default_nsid: {self.default_nsid}, flbas: {self.flbas}\n")
8997

9098
@classmethod
@@ -209,6 +217,30 @@ def get_ctrl_id(self):
209217
"ERROR : nvme list-ctrl could not find ctrl")
210218
return str(json_output['ctrl_list'][0]['ctrl_id'])
211219

220+
def get_ns_mgmt_support(self):
221+
"""
222+
Determine whether Namespace Management and Namespace Attachment
223+
operations are supported by the controller.
224+
225+
This method reads the Optional Admin Command Support (OACS) field
226+
from the Identify Controller data structure and evaluates specific
227+
bits that indicate support for:
228+
- Namespace Management (bit 3)
229+
- Namespace Attachment (bit 4)
230+
231+
Both features must be supported for this function to return True.
232+
233+
Returns:
234+
bool: True if both Namespace Management and Namespace Attachment
235+
are supported, False otherwise.
236+
"""
237+
oacs = to_decimal(self.get_id_ctrl_field_value("oacs"))
238+
239+
ns_mgmt_supported = bool(oacs & (1 << 3))
240+
ns_attach_supported = bool(oacs & (1 << 4))
241+
242+
return ns_mgmt_supported and ns_attach_supported
243+
212244
def get_nsid_list(self):
213245
""" Wrapper for extracting the namespace list.
214246
- Args:

0 commit comments

Comments
 (0)