Skip to content

Commit debc9a2

Browse files
committed
tests: validate create-ns command nsid json output
Also the command output-format is changed to json. Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
1 parent 34a40cf commit debc9a2

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

tests/nvme_test.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,13 @@ def create_ns(self, nsze, ncap, flbas, dps):
354354
- flbas : new namespace format.
355355
- dps : new namespace data protection information.
356356
- Returns:
357-
- return code of the nvme create namespace command.
357+
- Popen object of the nvme create namespace command.
358358
"""
359359
create_ns_cmd = f"{self.nvme_bin} create-ns {self.ctrl} " + \
360360
f"--nsze={str(nsze)} --ncap={str(ncap)} --flbas={str(flbas)} " + \
361-
f"--dps={str(dps)} --verbose"
362-
return self.exec_cmd(create_ns_cmd)
361+
f"--dps={str(dps)} --verbose --output-format=json"
362+
return subprocess.Popen(create_ns_cmd, shell=True,
363+
stdout=subprocess.PIPE, encoding='utf-8')
363364

364365
def create_and_validate_ns(self, nsid, nsze, ncap, flbas, dps):
365366
""" Wrapper for creating and validating a namespace.
@@ -372,8 +373,12 @@ def create_and_validate_ns(self, nsid, nsze, ncap, flbas, dps):
372373
- Returns:
373374
- return 0 on success, error code on failure.
374375
"""
375-
err = self.create_ns(nsze, ncap, flbas, dps)
376+
proc = self.create_ns(nsze, ncap, flbas, dps)
377+
err = proc.wait()
376378
if err == 0:
379+
json_output = json.loads(proc.stdout.read())
380+
self.assertEqual(int(json_output['nsid']), nsid,
381+
"ERROR : create namespace failed")
377382
id_ns_cmd = f"{self.nvme_bin} id-ns {self.ctrl} " + \
378383
f"--namespace-id={str(nsid)}"
379384
err = subprocess.call(id_ns_cmd,

0 commit comments

Comments
 (0)