Skip to content

Commit 5f93056

Browse files
authored
Merge pull request #4882 from wlemkows/ndctl-align-63
test: add support for ndctl list v63
2 parents cd31d7e + 1e01b0a commit 5f93056

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

src/test/unittest/tools.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Ndctl:
5858
"""ndctl CLI handle"""
5959
def __init__(self):
6060
self.version = self._get_ndctl_version()
61-
self.ndctl_list_output = self._get_ndctl_list_output()
61+
self.ndctl_list_output = self._get_ndctl_list_output('list')
6262

6363
def _get_ndctl_version(self):
6464
proc = sp.run(['ndctl', '--version'], stdout=sp.PIPE, stderr=sp.STDOUT)
@@ -69,8 +69,8 @@ def _get_ndctl_version(self):
6969
version = proc.stdout.strip()
7070
return version
7171

72-
def _get_ndctl_list_output(self):
73-
proc = sp.run(['ndctl', 'list'], stdout=sp.PIPE, stderr=sp.STDOUT)
72+
def _get_ndctl_list_output(self, *args):
73+
proc = sp.run(['ndctl', *args], stdout=sp.PIPE, stderr=sp.STDOUT)
7474
if proc.returncode != 0:
7575
raise futils.Fail('ndctl list failed:{}{}'.format(os.linesep,
7676
proc.stdout))
@@ -85,7 +85,7 @@ def _get_dev_info(self, dev_path):
8585
dev = None
8686
devtypes = ('blockdev', 'chardev')
8787

88-
for d in self.ndctl_list_output:
88+
for d in self._get_ndctl_list_output('list'):
8989
for dt in devtypes:
9090
if dt in d and os.path.join('/dev', d[dt]) == dev_path:
9191
dev = d
@@ -95,9 +95,39 @@ def _get_dev_info(self, dev_path):
9595
.format(dev_path))
9696
return dev
9797

98+
# for ndctl v63 we need to parse ndctl list in a different way than for v64
99+
def _get_dev_info_63(self, dev_path):
100+
dev = None
101+
devtype = 'chardev'
102+
daxreg = 'daxregion'
103+
104+
for d in self._get_ndctl_list_output('list', '-v'):
105+
if daxreg in d:
106+
devices = d[daxreg]['devices']
107+
for device in devices:
108+
if devtype in device and \
109+
os.path.join('/dev', device[devtype]) == dev_path:
110+
# only params from daxreg are intrested at this point,
111+
# other values are read by _get_dev_info() earlier
112+
dev = d[daxreg]
113+
114+
if not dev:
115+
raise futils.Fail('ndctl does not recognize the device: "{}"'
116+
.format(dev_path))
117+
118+
return dev
119+
98120
def _get_dev_param(self, dev_path, param):
121+
p = None
99122
dev = self._get_dev_info(dev_path)
100-
return dev[param]
123+
124+
try:
125+
p = dev[param]
126+
except KeyError:
127+
dev = self._get_dev_info_63(dev_path)
128+
p = dev[param]
129+
130+
return p
101131

102132
def get_dev_size(self, dev_path):
103133
return int(self._get_dev_param(dev_path, 'size'))

0 commit comments

Comments
 (0)