forked from lf-edge/eve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zboottypes.go
139 lines (119 loc) · 4.47 KB
/
zboottypes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Copyright (c) 2017 Zededa, Inc.
// SPDX-License-Identifier: Apache-2.0
package types
import (
"github.com/google/go-cmp/cmp"
"github.com/lf-edge/eve/pkg/pillar/base"
)
// ZbootConfig contains information fed from zedagent to baseosmgr.
// Only used to indicate that the testing of the image/partition is complete.
type ZbootConfig struct {
PartitionLabel string
TestComplete bool
}
// Key returns the key used in pubsub for ZbootConfig
func (config ZbootConfig) Key() string {
return config.PartitionLabel
}
// LogCreate :
func (config ZbootConfig) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.ZbootConfigLogType, "",
nilUUID, config.LogKey())
if logObject == nil {
return
}
logObject.CloneAndAddField("test-complete-bool", config.TestComplete).
Noticef("Zboot config create")
}
// LogModify :
func (config ZbootConfig) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.ZbootConfigLogType, "",
nilUUID, config.LogKey())
oldConfig, ok := old.(ZbootConfig)
if !ok {
logObject.Clone().Fatalf("LogModify: Old object interface passed is not of ZbootConfig type")
}
if oldConfig.TestComplete != config.TestComplete {
logObject.CloneAndAddField("test-complete-bool", config.TestComplete).
AddField("old-test-complete-bool", oldConfig.TestComplete).
Noticef("Zboot config modify")
} else {
// XXX remove?
logObject.CloneAndAddField("diff", cmp.Diff(oldConfig, config)).
Noticef("Zboot config modify other change")
}
}
// LogDelete :
func (config ZbootConfig) LogDelete(logBase *base.LogObject) {
logObject := base.EnsureLogObject(logBase, base.ZbootConfigLogType, "",
nilUUID, config.LogKey())
logObject.CloneAndAddField("test-complete-bool", config.TestComplete).
Noticef("Zboot config delete")
base.DeleteLogObject(logBase, config.LogKey())
}
// LogKey : XXX note that this only the IMGx, while Status includes ShortVersion for logs
func (config ZbootConfig) LogKey() string {
return string(base.ZbootConfigLogType) + "-" + config.PartitionLabel
}
type ZbootStatus struct {
PartitionLabel string
PartitionDevname string
PartitionState string
ShortVersion string
LongVersion string
CurrentPartition bool
TestComplete bool
}
func (status ZbootStatus) Key() string {
return status.PartitionLabel
}
// LogCreate :
func (status ZbootStatus) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.ZbootStatusLogType, "",
nilUUID, status.LogKey())
if logObject == nil {
return
}
logObject.CloneAndAddField("partition-state", status.PartitionState).
AddField("current-partition-bool", status.CurrentPartition).
AddField("test-complete-bool", status.TestComplete).
Noticef("Zboot status create")
}
// LogModify :
func (status ZbootStatus) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.ZbootStatusLogType, "",
nilUUID, status.LogKey())
oldStatus, ok := old.(ZbootStatus)
if !ok {
logObject.Clone().Fatalf("LogModify: Old object interface passed is not of ZbootStatus type")
}
if oldStatus.PartitionState != status.PartitionState ||
oldStatus.CurrentPartition != status.CurrentPartition ||
oldStatus.TestComplete != status.TestComplete {
logObject.CloneAndAddField("partition-state", status.PartitionState).
AddField("old-partition-state", oldStatus.PartitionState).
AddField("current-partition-bool", status.CurrentPartition).
AddField("old-current-partition-bool", oldStatus.CurrentPartition).
AddField("test-complete-bool", status.TestComplete).
AddField("old-test-complete-bool", oldStatus.TestComplete).
Noticef("Zboot status modify")
} else {
// XXX remove?
logObject.CloneAndAddField("diff", cmp.Diff(oldStatus, status)).
Noticef("Zboot status modify other change")
}
}
// LogDelete :
func (status ZbootStatus) LogDelete(logBase *base.LogObject) {
logObject := base.EnsureLogObject(logBase, base.ZbootStatusLogType, "",
nilUUID, status.LogKey())
logObject.CloneAndAddField("partition-state", status.PartitionState).
AddField("current-partition-bool", status.CurrentPartition).
AddField("test-complete-bool", status.TestComplete).
Noticef("Zboot status delete")
base.DeleteLogObject(logBase, status.LogKey())
}
// LogKey : XXX note that this includes the ShortVersion, while Status only the PartitionLabel
func (status ZbootStatus) LogKey() string {
return string(base.ZbootStatusLogType) + "-" + status.PartitionLabel + "-" + status.ShortVersion
}