Skip to content

Commit ce48761

Browse files
committed
qa/tasks/nvme_loop: update task to work with new nvme list format
Specifically on some centos 9 tests, we've seen that a newer version of some nvme related package is causing this task to fail with "KeyError: 'DevicePath'" due to the format of the output of the nvme list command changing. This patch adds handling for the new format we've seen while also still supporting the old format (necessary for the tests running on ubuntu). Fixes: https://tracker.ceph.com/issues/69067 Signed-off-by: Adam King <[email protected]>
1 parent 914c6de commit ce48761

File tree

1 file changed

+105
-6
lines changed

1 file changed

+105
-6
lines changed

qa/tasks/nvme_loop.py

Lines changed: 105 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def task(ctx, config):
7070
remote.run(args=['lsblk'], stdout=StringIO())
7171
p = remote.run(args=['sudo', 'nvme', 'list', '-o', 'json'], stdout=StringIO())
7272
new_devs = []
73-
# `nvme list -o json` will return the following output:
73+
# `nvme list -o json` will return one of the following output:
7474
'''{
7575
"Devices" : [
7676
{
@@ -91,13 +91,112 @@ def task(ctx, config):
9191
}
9292
]
9393
}'''
94+
'''{
95+
"Devices":[
96+
{
97+
"HostNQN":"nqn.2014-08.org.nvmexpress:uuid:00000000-0000-0000-0000-0cc47ada6ba4",
98+
"HostID":"898a0e10-da2d-4a42-8017-d9c445089d0c",
99+
"Subsystems":[
100+
{
101+
"Subsystem":"nvme-subsys0",
102+
"SubsystemNQN":"nqn.2014.08.org.nvmexpress:80868086CVFT623300LN400BGN INTEL SSDPEDMD400G4",
103+
"Controllers":[
104+
{
105+
"Controller":"nvme0",
106+
"Cntlid":"0",
107+
"SerialNumber":"CVFT623300LN400BGN",
108+
"ModelNumber":"INTEL SSDPEDMD400G4",
109+
"Firmware":"8DV101H0",
110+
"Transport":"pcie",
111+
"Address":"0000:02:00.0",
112+
"Slot":"2",
113+
"Namespaces":[
114+
{
115+
"NameSpace":"nvme0n1",
116+
"Generic":"ng0n1",
117+
"NSID":1,
118+
"UsedBytes":400088457216,
119+
"MaximumLBA":781422768,
120+
"PhysicalSize":400088457216,
121+
"SectorSize":512
122+
}
123+
],
124+
"Paths":[
125+
]
126+
}
127+
],
128+
"Namespaces":[
129+
]
130+
}
131+
]
132+
}
133+
]
134+
}
135+
'''
136+
'''{
137+
"Devices":[
138+
{
139+
"HostNQN":"nqn.2014-08.org.nvmexpress:uuid:00000000-0000-0000-0000-0cc47ada6ba4",
140+
"HostID":"898a0e10-da2d-4a42-8017-d9c445089d0c",
141+
"Subsystems":[
142+
{
143+
"Subsystem":"nvme-subsys0",
144+
"SubsystemNQN":"nqn.2014.08.org.nvmexpress:80868086CVFT534400C2400BGN INTEL SSDPEDMD400G4",
145+
"Controllers":[
146+
{
147+
"Controller":"nvme0",
148+
"Cntlid":"0",
149+
"SerialNumber":"CVFT534400C2400BGN",
150+
"ModelNumber":"INTEL SSDPEDMD400G4",
151+
"Firmware":"8DV101H0",
152+
"Transport":"pcie",
153+
"Address":"0000:02:00.0",
154+
"Slot":"2",
155+
"Namespaces":[
156+
{
157+
"NameSpace":"nvme0n1",
158+
"Generic":"ng0n1",
159+
"NSID":1,
160+
"UsedBytes":400088457216,
161+
"MaximumLBA":781422768,
162+
"PhysicalSize":400088457216,
163+
"SectorSize":512
164+
}
165+
],
166+
"Paths":[
167+
]
168+
}
169+
],
170+
"Namespaces":[
171+
]
172+
}
173+
]
174+
}
175+
]
176+
}
177+
'''
94178
nvme_list = json.loads(p.stdout.getvalue())
95179
for device in nvme_list['Devices']:
96-
dev = device['DevicePath']
97-
vendor = device['ModelNumber']
98-
if dev.startswith('/dev/') and vendor == 'Linux':
99-
new_devs.append(dev)
100-
bluestore_zap(remote, dev)
180+
try:
181+
# first try format 1 / older format
182+
dev = device['DevicePath']
183+
vendor = device['ModelNumber']
184+
if dev.startswith('/dev/') and vendor == 'Linux':
185+
new_devs.append(dev)
186+
bluestore_zap(remote, dev)
187+
except KeyError:
188+
for subsystem in device['Subsystems']:
189+
# format 2
190+
if 'Namespaces' in subsystem and subsystem['Namespaces']:
191+
dev = '/dev/' + subsystem['Namespaces'][0]['NameSpace']
192+
# try format 3 last
193+
else:
194+
dev = '/dev/' + subsystem['Controllers'][0]['Namespaces'][0]['NameSpace']
195+
# vendor is the same for format 2 and 3
196+
vendor = subsystem['Controllers'][0]['ModelNumber']
197+
if vendor == 'Linux':
198+
new_devs.append(dev)
199+
bluestore_zap(remote, dev)
101200
log.info(f'new_devs {new_devs}')
102201
assert len(new_devs) <= len(devs)
103202
if len(new_devs) == len(devs):

0 commit comments

Comments
 (0)