@@ -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) {
186187func (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+
316343func (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
0 commit comments