Spdk/scripts/perf/nvmf/common.py
Karol Latecki db43b387ba test: do not use iter_pci_class_code in tests
Do not use iter_pci_class_code function in tests to
iterate over NVMe drives. This function can return
drives which at the moment of execution can not be
whitelisted for use.

This can result in test errors (such as simply
bdev_nvme_attach_controller RPC command failing) or
even using and deleting data from NVMe drive which
was not meant to be used in tests.

Fixes #1235

Change-Id: I82b9935fc88605b636c2096be6c71d4880a567c8
Signed-off-by: Karol Latecki <karol.latecki@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1309
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
2020-03-18 08:03:21 +00:00

43 lines
1.3 KiB
Python

import os
import re
import json
from itertools import product, chain
from subprocess import check_output, Popen
def get_used_numa_nodes():
used_numa_nodes = set()
for bdf in get_nvme_devices_bdf():
with open("/sys/bus/pci/devices/%s/numa_node" % bdf, "r") as numa_file:
output = numa_file.read()
used_numa_nodes.add(int(output))
return used_numa_nodes
def get_nvme_devices_count():
output = get_nvme_devices_bdf()
return len(output)
def get_nvme_devices_bdf():
print("Getting BDFs for NVMe section")
output = check_output("rootdir=$PWD; \
source test/common/autotest_common.sh; \
get_nvme_bdfs 01 08 02",
executable="/bin/bash", shell=True)
output = [str(x, encoding="utf-8") for x in output.split()]
print("Done getting BDFs")
return output
def get_nvme_devices():
print("Getting kernel NVMe names")
output = check_output("lsblk -o NAME -nlp", shell=True).decode(encoding="utf-8")
output = [x for x in output.split("\n") if "nvme" in x]
print("Done getting kernel NVMe names")
return output
def nvmet_command(nvmet_bin, command):
return check_output("%s %s" % (nvmet_bin, command), shell=True).decode(encoding="utf-8")