Commit da33cf4
[minigraph/device_info] Parse device type from device_desc.xml; fix is_voq/packet_chassis to read Config DB directly (Azure#2451)
## Problem
After running `config load_mgmt` + `config save`, two failures occur on
Supervisor/Linecard devices:
### 1. `bgp_neighbor` script fails on Supervisor
**Root cause:** `type` is not populated in `DEVICE_METADATA.localhost`
after `config load_mgmt`, so the script fails when checking device type.
### 2. `load_minigraph` fails on Supervisor and Linecard
**Root cause:** DB connection to `CHASSIS*DB` fails because `calcmgrd`
does not have the iptable rule to allow midplane traffic — this rule is
only added when `is_chassis()` returns `True`.
### Why `is_chassis()` returns `False`
- **Supervisor:** The current implementation calls a platform API which
internally tries to connect to `CHASSIS*DB` — and since that connection
is not yet available, it fails.
- **Linecard:** `switch_type` is not defined in Config DB at this point,
so `is_chassis()` returns `False`.
---
## Fix
### 1. `src/sonic-config-engine/minigraph.py` —
`parse_device_desc_xml()`
Populate `DEVICE_METADATA.localhost.type` from `<ElementType>` when
parsing `device_desc.xml`. Map `Linecard` and `Supervisor` to
`SpineRouter`.
This fixes the `bgp_neighbor` failure on Supervisor.
```python
if d_type:
if d_type in ('Linecard', 'Supervisor'):
results['DEVICE_METADATA']['localhost']['type'] = 'SpineRouter'
else:
results['DEVICE_METADATA']['localhost']['type'] = d_type
```
### 2. `src/sonic-py-common/sonic_py_common/device_info.py` —
`is_chassis()`
- Remove dependency on `CHASSIS*DB` connection by reading `switch_type`
directly from Config DB via `get_localhost_info()` instead of
`get_platform_info()` (which uses a cached global and internally may
attempt a `CHASSIS*DB` connection).
- Add an early check: if `DEVICE_METADATA.localhost.type ==
'SpineRouter'`, return `True` immediately — removing the dependency on
`switch_type` being defined.
```python
def is_chassis():
if get_localhost_info('type') == 'SpineRouter':
return True
return is_voq_chassis() or is_packet_chassis()
```
---
## Files Changed
| File | Change |
|---|---|
| `src/sonic-config-engine/minigraph.py` | Populate `type` in
`DEVICE_METADATA` from `<ElementType>`; map Linecard/Supervisor →
SpineRouter |
| `src/sonic-py-common/sonic_py_common/device_info.py` | `is_chassis()`
checks `type == SpineRouter` first; `is_voq/packet_chassis()` read
Config DB directly |
| `src/sonic-py-common/tests/device_info_test.py` | Update mocks and add
SpineRouter test case |
| `src/sonic-config-engine/tests/test_minigraph_case.py` | Add UTs for
device type parsing and Linecard/Supervisor mapping |
|
`src/sonic-config-engine/tests/simple-sample-device-desc-supervisor.xml`
| New test fixture |
| `src/sonic-config-engine/tests/simple-sample-device-desc-linecard.xml`
| New test fixture |
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 9504bbf commit da33cf4
6 files changed
Lines changed: 59 additions & 10 deletions
File tree
- src
- sonic-config-engine
- tests
- sonic-py-common
- sonic_py_common
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2856 | 2856 | | |
2857 | 2857 | | |
2858 | 2858 | | |
| 2859 | + | |
| 2860 | + | |
| 2861 | + | |
| 2862 | + | |
| 2863 | + | |
2859 | 2864 | | |
2860 | 2865 | | |
2861 | 2866 | | |
| |||
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| |||
557 | 559 | | |
558 | 560 | | |
559 | 561 | | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
560 | 575 | | |
561 | 576 | | |
562 | 577 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
563 | 563 | | |
564 | 564 | | |
565 | 565 | | |
566 | | - | |
567 | | - | |
| 566 | + | |
| 567 | + | |
568 | 568 | | |
569 | 569 | | |
570 | 570 | | |
571 | | - | |
572 | | - | |
| 571 | + | |
| 572 | + | |
573 | 573 | | |
574 | 574 | | |
575 | 575 | | |
| 576 | + | |
| 577 | + | |
576 | 578 | | |
577 | 579 | | |
578 | 580 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
123 | | - | |
124 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
| 129 | + | |
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
134 | | - | |
| 134 | + | |
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
139 | | - | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
140 | 143 | | |
141 | 144 | | |
142 | 145 | | |
| |||
0 commit comments