@@ -44,18 +44,20 @@ var (
4444
4545// RebootParams specify the reboot parameters used by the Reboot API.
4646type RebootParams struct {
47- request any
48- waitTime time.Duration
49- checkInterval time.Duration
50- lmTTkrID string // latency measurement testtracker UUID
51- lmTitle string // latency measurement title
47+ request any
48+ waitTime time.Duration
49+ checkInterval time.Duration
50+ requestTimeout time.Duration
51+ lmTTkrID string // latency measurement testtracker UUID
52+ lmTitle string // latency measurement title
5253}
5354
5455// NewRebootParams returns RebootParams structure with default values.
5556func NewRebootParams () * RebootParams {
5657 return & RebootParams {
57- waitTime : 4 * time .Minute ,
58- checkInterval : 20 * time .Second ,
58+ waitTime : 4 * time .Minute ,
59+ checkInterval : 20 * time .Second ,
60+ requestTimeout : 2 * time .Minute ,
5961 }
6062}
6163
@@ -82,6 +84,14 @@ func (p *RebootParams) WithRequest(r any) *RebootParams {
8284 return p
8385}
8486
87+ // WithRequestTimeout adds the timeout for the reboot request.
88+ // The function will wait for the gNOI server to be down within this duration.
89+ // Default value is 2 minutes.
90+ func (p * RebootParams ) WithRequestTimeout (timeout time.Duration ) * RebootParams {
91+ p .requestTimeout = timeout
92+ return p
93+ }
94+
8595// WithLatencyMeasurement adds testtracker uuid and title for latency measurement.
8696func (p * RebootParams ) WithLatencyMeasurement (testTrackerID , title string ) * RebootParams {
8797 p .lmTTkrID = testTrackerID
@@ -132,28 +142,47 @@ func Reboot(t *testing.T, d *ondatra.DUTDevice, params *RebootParams) error {
132142 return nil
133143 }
134144
135- log .Infof ("Polling gNOI server reachability in %v intervals for max duration of %v" , params .checkInterval , params .waitTime )
145+ rebootRequestTimeout := params .requestTimeout
146+ ctx , cancel := context .WithTimeout (context .Background (), rebootRequestTimeout )
147+ defer cancel ()
148+
149+ // The switch backend might not have processed the request or might take
150+ // sometime to execute the request. So poll for the gNOI server to be down,
151+ // or context to expire.
152+ pollErr := poll (ctx , 10 * time .Second /*(pollInterval)*/ , func () pollStatus {
153+ err := GNOIAble (t , d )
154+ timeElapsed := (time .Now ().UnixNano () - timeBeforeReboot ) / int64 (time .Second )
155+ if err == nil {
156+ log .Infof ("gNOI server is still up after %v seconds" , timeElapsed )
157+ return continuePoll
158+ }
159+ log .Infof ("gNOI server is down after %v seconds, got error while checking gNOI server reachability: %v as expected" , timeElapsed , err )
160+ return exitPoll
161+ })
162+ if pollErr != nil {
163+ log .WarningContextf (ctx , "Polling gNOI server to be down within time: %v failed: %v" , rebootRequestTimeout , pollErr )
164+ log .InfoContextf (ctx , "Continue to check if the switch has rebooted" )
165+ }
166+
167+ log .InfoContextf (ctx , "Polling gNOI server reachability in %v intervals for max duration of %v" , params .checkInterval , params .waitTime )
136168 for timeout := time .Now ().Add (params .waitTime ); time .Now ().Before (timeout ); {
137- // The switch backend might not have processed the request or might take
138- // sometime to execute the request. So wait for check interval time and
139- // later verify that the switch rebooted within the specified wait time.
140169 time .Sleep (params .checkInterval )
141170 doneTime := time .Now ()
142171 timeElapsed := (doneTime .UnixNano () - timeBeforeReboot ) / int64 (time .Second )
143172
144173 if err := GNOIAble (t , d ); err != nil {
145- log .Infof ( "gNOI server not up after %v seconds" , timeElapsed )
174+ log .InfoContextf ( ctx , "gNOI server not up after %v seconds" , timeElapsed )
146175 continue
147176 }
148- log .Infof ( "gNOI server up after %v seconds" , timeElapsed )
177+ log .InfoContextf ( ctx , "gNOI server up after %v seconds" , timeElapsed )
149178
150179 // An extra check to ensure that the system has rebooted.
151180 if bootTime := gnmiSystemBootTimeGet (t , d ); bootTime < uint64 (timeBeforeReboot ) {
152- log .Infof ( "Switch has not rebooted after %v seconds" , timeElapsed )
181+ log .InfoContextf ( ctx , "Switch has not rebooted after %v seconds" , timeElapsed )
153182 continue
154183 }
155184
156- log .Infof ( "Switch rebooted after %v seconds" , timeElapsed )
185+ log .InfoContextf ( ctx , "Switch rebooted after %v seconds" , timeElapsed )
157186 return nil
158187 }
159188
0 commit comments