Commit 2d228c1
committed
[SmartSwitch] add graceful shutdown/startup utilities and visibility
<!--
Please make sure you've read and understood our contributing guidelines:
https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md
** Make sure all your commits include a signature generated with `git commit -s` **
If this is a bug fix, make sure your description includes "closes #xxxx",
"fixes #xxxx" or "resolves #xxxx" so that GitHub automatically closes the related
issue when the PR is merged.
If you are adding/modifying/removing any command or utility script, please also
make sure to add/modify/remove any unit tests from the tests
directory as appropriate.
If you are modifying or removing an existing 'show', 'config' or 'sonic-clear'
subcommand, or you are adding a new subcommand, please make sure you also
update the Command Line Reference Guide (doc/Command-Reference.md) to reflect
your changes.
Please provide the following information:
-->
HLD: https://github.com/sonic-net/SONiC/blob/master/doc/smart-switch/graceful-shutdown/graceful-shutdown.md
These changes build upon enhancements in sonic-net#4031
This PR adds CLI support and visibility for module-level graceful transitions (startup/shutdown/reboot) to align with the SmartSwitch/DPU lifecycle work.
#### What I did
- Added support to view module transition states (startup, shutdown, reboot) through CLI.
- Integrated with STATE_DB CHASSIS_MODULE_TABLE to display transition status, type, and elapsed time.
- Enhanced user experience with readable durations and exit codes for automation.
- Implemented comprehensive unit tests for transition visibility, parsing, and error handling.
#### How I did it
- Added a helper class to read STATE_DB entries:
- state_transition_in_progress
- transition_type
- transition_start_time
- Implemented robust error handling for missing or malformed DB entries.
- Added pytest-based unit tests using mocked state_db_connector.
#### How to verify it
- Build and install the updated sonic-utilities package on DUT
- Check Redis entries: `redis-cli -n 6 hgetall "CHASSIS_MODULE_TABLE|DPU0"`
- Run the module startup/shutdown commands
- Run unit tests
#### Sample outputs when "state_transition_in_progress"
Errors thrown when the same module transition is already in progress.
$ sudo config chassis modules shutdown DPU2;redis-cli -n 6 hgetall 'CHASSIS_MODULE_TABLE|DPU2';sudo reboot -d DPU2;redis-cli -n 6 hgetall 'CHASSIS_MODULE_TABLE|DPU2'
Shutting down chassis module DPU2
1) "desc"
2) "NVIDIA XXXXXX DPU"
3) "slot"
4) "N/A"
5) "oper_status"
6) "Online"
7) "serial"
8) "XXXXXXXXXX"
9) "transition_in_progress"
10) "True"
11) "transition_type"
12) "shutdown"
13) "transition_start_time"
14) "1763059401"
True
2025-11-13 18:43:22 - User requested rebooting device dpu2 ...
2025-11-13 18:43:23 - INFO: DPU dpu2 is in 'Online' state before reboot.
2025-11-13 18:43:23 - ERROR: state_transition_in_progress flag is already set for dpu2
#### Previous command output (if the output of a command-line utility has changed)
#### New command output (if the output of a command-line utility has changed)
$ reboot -d DPU1
True
2025-11-17 17:56:10 - User requested rebooting device dpu1 ...
2025-11-17 17:56:11 - INFO: DPU dpu1 is in 'Online' state before reboot.
2025-11-17 17:56:12 - INFO: Rebooting dpu1, ip:1X9.XXX.X00.2 gnmi_port:50XXX
2025-11-17 17:56:53 - INFO: dpu1 halted the services successfully
2025-11-17 17:58:50 - INFO: Rebooting dpu1 with reboot_type:DPU...1 parent b056ba1 commit 2d228c1
5 files changed
Lines changed: 345 additions & 187 deletions
File tree
- config
- scripts
- tests
- utilities_common
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | 68 | | |
112 | 69 | | |
113 | 70 | | |
| |||
196 | 153 | | |
197 | 154 | | |
198 | 155 | | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
208 | 160 | | |
209 | 161 | | |
210 | 162 | | |
| |||
243 | 195 | | |
244 | 196 | | |
245 | 197 | | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
255 | 202 | | |
256 | 203 | | |
257 | 204 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
75 | 74 | | |
76 | 75 | | |
77 | 76 | | |
| |||
82 | 81 | | |
83 | 82 | | |
84 | 83 | | |
85 | | - | |
86 | 84 | | |
87 | 85 | | |
88 | 86 | | |
89 | 87 | | |
90 | 88 | | |
91 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
92 | 124 | | |
93 | 125 | | |
94 | 126 | | |
| |||
119 | 151 | | |
120 | 152 | | |
121 | 153 | | |
| 154 | + | |
| 155 | + | |
122 | 156 | | |
123 | 157 | | |
124 | 158 | | |
| |||
127 | 161 | | |
128 | 162 | | |
129 | 163 | | |
130 | | - | |
131 | 164 | | |
132 | 165 | | |
133 | 166 | | |
| |||
171 | 204 | | |
172 | 205 | | |
173 | 206 | | |
174 | | - | |
| 207 | + | |
175 | 208 | | |
176 | 209 | | |
177 | 210 | | |
| |||
187 | 220 | | |
188 | 221 | | |
189 | 222 | | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
190 | 233 | | |
191 | 234 | | |
192 | 235 | | |
| |||
199 | 242 | | |
200 | 243 | | |
201 | 244 | | |
202 | | - | |
| 245 | + | |
203 | 246 | | |
204 | | - | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
205 | 251 | | |
206 | 252 | | |
207 | 253 | | |
208 | | - | |
| 254 | + | |
209 | 255 | | |
210 | | - | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
211 | 260 | | |
212 | 261 | | |
213 | 262 | | |
214 | 263 | | |
215 | | - | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
216 | 271 | | |
217 | 272 | | |
218 | 273 | | |
| |||
0 commit comments