Skip to content

Commit c815255

Browse files
committed
nim: Ignore bootstrap and /config/GlobalConfig if onboarded
If we have a /persist/checkpoint/lastconfig we ignore re-reading those files. They will have been taken into account in forming /persist/status/nim/DevicePortConfigList/ Signed-off-by: eriknordmark <erik@zededa.com>
1 parent a05ded7 commit c815255

File tree

3 files changed

+39
-12
lines changed

3 files changed

+39
-12
lines changed

pkg/pillar/cmd/nim/nim.go

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/lf-edge/eve/pkg/pillar/pubsub"
2626
"github.com/lf-edge/eve/pkg/pillar/types"
2727
fileutils "github.com/lf-edge/eve/pkg/pillar/utils/file"
28+
"github.com/lf-edge/eve/pkg/pillar/utils/persist"
2829
"github.com/sirupsen/logrus"
2930
)
3031

@@ -186,9 +187,14 @@ func (n *nim) init() (err error) {
186187
func (n *nim) run(ctx context.Context) (err error) {
187188
n.Log.Noticef("Starting %s", agentName)
188189

190+
// This will re-ingest network configuration from the bootstrap config
191+
// (priority) or ImportGlobalConfigFile (fallback) on each boot until
192+
// the device is onboarded and has a /persist/checkpoint/lastconfig.
193+
ignoreBootstraps := n.hasPersistLastconfig()
194+
189195
// Check if we have a /config/DevicePortConfig/*.json which we need to
190196
// take into account by copying it to /run/global/DevicePortConfig/
191-
n.ingestDevicePortConfig()
197+
n.ingestDevicePortConfig(ignoreBootstraps)
192198

193199
// Start DPC Manager.
194200
if err = n.dpcManager.Init(ctx); err != nil {
@@ -197,6 +203,12 @@ func (n *nim) run(ctx context.Context) (err error) {
197203
installerDPCs := n.listPublishedDPCs(runDevicePortConfigDir)
198204
haveBootstrapConf := fileutils.FileExists(n.Log, types.BootstrapConfFileName)
199205
expectBootstrapDPCs := len(installerDPCs) > 0 || haveBootstrapConf
206+
if expectBootstrapDPCs && ignoreBootstraps {
207+
n.Log.Noticef("Not ingesting bootstrap config from config partition: " +
208+
"/persist/checkpoint/lastconfig is present")
209+
expectBootstrapDPCs = false
210+
}
211+
200212
if err = n.dpcManager.Run(ctx, expectBootstrapDPCs); err != nil {
201213
return err
202214
}
@@ -313,6 +325,21 @@ func (n *nim) run(ctx context.Context) (err error) {
313325
}
314326
}
315327

328+
// Check if we have /persist/checkpoint/lastconfig
329+
// Does not verify they will be used since we do not do the protobuf decode
330+
// nor check the signature.
331+
func (n *nim) hasPersistLastconfig() bool {
332+
contents, _, err := persist.ReadSavedConfig(n.Log, "lastconfig")
333+
if err == nil && len(contents) != 0 {
334+
return true
335+
}
336+
contents, _, err = persist.ReadSavedConfig(n.Log, "lastconfig.bak")
337+
if err == nil && len(contents) != 0 {
338+
return true
339+
}
340+
return false
341+
}
342+
316343
func (n *nim) initPublications() (err error) {
317344
n.pubDeviceNetworkStatus, err = n.PubSub.NewPublication(
318345
pubsub.PublicationOptions{
@@ -856,13 +883,19 @@ func (n *nim) listPublishedDPCs(directory string) (dpcFilePaths []string) {
856883

857884
// ingestPortConfig reads all json files in configDevicePortConfigDir, ensures
858885
// they have a TimePriority, and then writes to runDevicePortConfigDir.
859-
// XXX do we need something to avoid re-application of the same file?
860-
// Or is it sufficient to depend on the fact that we only do this until we have
861-
// a /persist/checkpoint/lastconfig from the controller? Do we check that in nim?
862-
func (n *nim) ingestDevicePortConfig() {
886+
func (n *nim) ingestDevicePortConfig(ignoreBootstraps bool) {
863887
dpcFiles := n.listPublishedDPCs(configDevicePortConfigDir)
888+
if len(dpcFiles) == 0 {
889+
return
890+
}
891+
if ignoreBootstraps {
892+
n.Log.Noticef("Not ingesting DPC jsons (%v) from config partition: "+
893+
"/persist/checkpoint/lastconfig is present",
894+
strings.Join(dpcFiles, ", "))
895+
return
896+
}
864897
// Skip these legacy DPC json files if there is bootstrap config.
865-
if fileutils.FileExists(n.Log, types.BootstrapConfFileName) && len(dpcFiles) > 0 {
898+
if fileutils.FileExists(n.Log, types.BootstrapConfFileName) {
866899
n.Log.Noticef("Not ingesting DPC jsons (%v) from config partition: "+
867900
"bootstrap config is present", strings.Join(dpcFiles, ", "))
868901
return

pkg/pillar/cmd/zedagent/handleconfig.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,6 @@ func maybeLoadBootstrapConfig(getconfigCtx *getconfigContext) {
315315
case obsoleteConfig:
316316
log.Error("Bootstrap config is obsolete")
317317
}
318-
// XXX should we save it as /persist/checkpoint/lastconfig if we
319-
// have no such file?
320318
}
321319

322320
func indicateInvalidBootstrapConfig(getconfigCtx *getconfigContext) {
@@ -786,7 +784,6 @@ func requestConfigByURL(getconfigCtx *getconfigContext, url string,
786784
// can be used to enable the local keyboard etc for
787785
// debugging purposes.
788786
confName := "lastconfig"
789-
// XXX do we know bootreason?
790787
if !ctx.bootReason.StartWithSavedConfig() {
791788
log.Warnf("Use backup config due to boot reason %s",
792789
ctx.bootReason.String())

pkg/pillar/cmd/zedagent/zedagent.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,6 @@ func Run(ps *pubsub.PubSub, loggerArg *logrus.Logger, logArg *base.LogObject, ar
426426
// Does NOT publish yet since we want to get any bootstrap or
427427
foundCheckpoint := initializeConfigItemValueMap(zedagentCtx)
428428

429-
// XXX should a bootstrap or /config/GlobalConfig file be able
430-
// to override a checkpoint? Do we need to handle such after the first
431-
// boot? Here we only look if no /persist/checkpoint/lastconfig.
432429
if !foundCheckpoint {
433430
// Load bootstrap configuration if present.
434431
maybeLoadBootstrapConfig(getconfigCtx)

0 commit comments

Comments
 (0)