Skip to content

Commit fa41b9c

Browse files
authored
[Smartswitch][pcied] Fix pcied handling for smartswitch during DPU detach #5 (sonic-net#633)
1 parent 700ccd4 commit fa41b9c

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

sonic-pcied/scripts/pcied

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,6 @@ class DaemonPcied(daemon_base.DaemonBase):
115115
stable_keys = self.status_table.getKeys()
116116
for stk in stable_keys:
117117
self.status_table._del(stk)
118-
if self.detach_info:
119-
detach_info_keys = self.detach_info.getKeys()
120-
for dk in detach_info_keys:
121-
self.detach_info._del(dk)
122118
except Exception as e:
123119
log.log_warning("Exception during cleanup: {}".format(str(e)), True)
124120

@@ -185,8 +181,10 @@ class DaemonPcied(daemon_base.DaemonBase):
185181
for key in detach_info_keys:
186182
dpu_info = self.detach_info.get(key)
187183
if dpu_info:
188-
bus_info = dpu_info.get(PCIE_DETACH_BUS_INFO_FIELD)
189-
dpu_state = dpu_info.get(PCIE_DETACH_DPU_STATE_FIELD)
184+
# Convert tuple of field-value pairs to dictionary for easier access
185+
dpu_dict = dict(dpu_info[1])
186+
bus_info = dpu_dict.get(PCIE_DETACH_BUS_INFO_FIELD)
187+
dpu_state = dpu_dict.get(PCIE_DETACH_DPU_STATE_FIELD)
190188
if bus_info == pcie_dev and dpu_state == "detaching":
191189
return True
192190

sonic-pcied/tests/test_DaemonPcied.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ def test_del(self):
170170

171171
daemon_pcied.device_table.getKeys.return_value = ['device1', 'device2']
172172
daemon_pcied.status_table.getKeys.return_value = ['status1']
173-
daemon_pcied.detach_info.getKeys.return_value = ['detach1', 'detach2', 'detach3']
174173

175174
daemon_pcied.__del__()
176175

@@ -181,10 +180,6 @@ def test_del(self):
181180
assert daemon_pcied.status_table._del.call_count == 1
182181
daemon_pcied.status_table._del.assert_called_with('status1')
183182

184-
assert daemon_pcied.detach_info._del.call_count == 3
185-
daemon_pcied.detach_info._del.assert_any_call('detach1')
186-
daemon_pcied.detach_info._del.assert_any_call('detach2')
187-
daemon_pcied.detach_info._del.assert_any_call('detach3')
188183

189184
@mock.patch('pcied.load_platform_pcieutil', mock.MagicMock())
190185
@mock.patch('pcied.log.log_warning')
@@ -202,11 +197,12 @@ def test_is_dpu_in_detaching_mode(self):
202197
daemon_pcied = pcied.DaemonPcied(SYSLOG_IDENTIFIER)
203198
daemon_pcied.detach_info = mock.MagicMock()
204199
daemon_pcied.detach_info.getKeys = mock.MagicMock(return_value=['DPU_0', 'DPU_1'])
200+
# Mock the get() method to return tuple of (exists, field_value_pairs)
205201
daemon_pcied.detach_info.get = mock.MagicMock(
206202
side_effect=lambda key: {
207-
'DPU_0': {'bus_info': '0000:03:00.1', 'dpu_state': 'detaching'},
208-
'DPU_1': {'bus_info': '0000:03:00.2', 'dpu_state': 'attached'}
209-
}.get(key, None)
203+
'DPU_0': (True, [('bus_info', '0000:03:00.1'), ('dpu_state', 'detaching')]),
204+
'DPU_1': (True, [('bus_info', '0000:03:00.2'), ('dpu_state', 'attached')])
205+
}.get(key, (False, []))
210206
)
211207

212208
# Test when the device is in detaching mode

0 commit comments

Comments
 (0)