Skip to content

Commit 0e978f0

Browse files
milan-zededaeriknordmark
authored andcommitted
Do not suspend DPC testing when clocks are not synchronized
If DPC is failing connectivity tests (due to some transient network issue) and device is powered off for long enough that clocks loose time (or there is no battery to keep them running), device will not be able to establish connectivity after power on for a very long time. This is because we demand that failed DPC is tried again only after some time elapses (5 minutes) since the last failed connectivity test. However, when device starts with clocks reset at time "zero" (i.e. start of the epoch), it will take many decades until the current time (as reported by clocks) is past the last failure timestamp. The solution is to detect unsync clocks and allow to test and use DPC immediately. Signed-off-by: Milan Lenco <[email protected]> (cherry picked from commit b3bdbc6)
1 parent 28f38e7 commit 0e978f0

File tree

2 files changed

+43
-16
lines changed

2 files changed

+43
-16
lines changed

pkg/pillar/types/zedroutertypes.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,14 @@ func (config DevicePortConfig) IsDPCTestable(minTimeSinceFailure time.Duration)
861861
if config.LastSucceeded.After(config.LastFailed) {
862862
return true
863863
}
864+
if config.LastFailed.After(time.Now()) {
865+
// Clocks are not in sync - most likely they are still around
866+
// the start of the epoch.
867+
// Network is likely needed to synchronize the clocks using NTP,
868+
// and we should attempt to establish network connectivity using
869+
// any DPC available.
870+
return true
871+
}
864872
return time.Since(config.LastFailed) >= minTimeSinceFailure
865873
}
866874

pkg/pillar/types/zedroutertypes_test.go

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -183,56 +183,75 @@ func TestIsDPCUsable(t *testing.T) {
183183
}
184184

185185
func TestIsDPCTestable(t *testing.T) {
186-
n := time.Now()
187186
testMatrix := map[string]struct {
188187
devicePortConfig DevicePortConfig
189188
expectedValue bool
190189
}{
191-
"Difference is exactly 60 seconds": {
190+
"DPC always failed test and not enough time passed since the last test": {
192191
devicePortConfig: DevicePortConfig{
193192
TestResults: TestResults{
194-
LastFailed: n.Add(time.Second * 60),
195-
LastSucceeded: n,
193+
LastFailed: time.Now().Add(-2 * time.Minute),
194+
LastSucceeded: time.Time{},
196195
},
197196
Ports: usablePorts,
198197
},
199198
expectedValue: false,
200199
},
201-
"Difference is 61 seconds": {
200+
"DPC succeeded, then failed and not enough time passed since then": {
202201
devicePortConfig: DevicePortConfig{
203202
TestResults: TestResults{
204-
LastFailed: n.Add(time.Second * 61),
205-
LastSucceeded: n,
203+
LastFailed: time.Now().Add(-2 * time.Minute),
204+
LastSucceeded: time.Now().Add(-4 * time.Minute),
206205
},
207206
Ports: usablePorts,
208207
},
209208
expectedValue: false,
210209
},
211-
"Difference is 59 seconds": {
210+
"DPC always failed test but enough time passed since the last test": {
212211
devicePortConfig: DevicePortConfig{
213212
TestResults: TestResults{
214-
LastFailed: n.Add(time.Second * 59),
215-
LastSucceeded: n,
213+
LastFailed: time.Now().Add(-6 * time.Minute),
214+
LastSucceeded: time.Time{},
216215
},
217216
Ports: usablePorts,
218217
},
219-
expectedValue: false,
218+
expectedValue: true,
220219
},
221-
"LastFailed is 0": {
220+
"DPC succeeded, then failed but enough time passed since then": {
221+
devicePortConfig: DevicePortConfig{
222+
TestResults: TestResults{
223+
LastFailed: time.Now().Add(-6 * time.Minute),
224+
LastSucceeded: time.Now().Add(-8 * time.Minute),
225+
},
226+
Ports: usablePorts,
227+
},
228+
expectedValue: true,
229+
},
230+
"DPC always succeeded test": {
222231
devicePortConfig: DevicePortConfig{
223232
TestResults: TestResults{
224233
LastFailed: time.Time{},
225-
LastSucceeded: n,
234+
LastSucceeded: time.Now().Add(-2 * time.Minute),
226235
},
227236
Ports: usablePorts,
228237
},
229238
expectedValue: true,
230239
},
231-
"Last Succeeded is after Last Failed": {
240+
"DPC failed but later succeeded test": {
232241
devicePortConfig: DevicePortConfig{
233242
TestResults: TestResults{
234-
LastFailed: n,
235-
LastSucceeded: n.Add(time.Second * 61),
243+
LastFailed: time.Now().Add(-4 * time.Minute),
244+
LastSucceeded: time.Now().Add(-2 * time.Minute),
245+
},
246+
Ports: usablePorts,
247+
},
248+
expectedValue: true,
249+
},
250+
"Clocks are not synchronized": {
251+
devicePortConfig: DevicePortConfig{
252+
TestResults: TestResults{
253+
LastFailed: time.Now().Add(time.Hour),
254+
LastSucceeded: time.Time{},
236255
},
237256
Ports: usablePorts,
238257
},

0 commit comments

Comments
 (0)