Skip to content

Commit

Permalink
Refactor baseOS activation logic in parseconfig.go
Browse files Browse the repository at this point in the history
It is safer to get the activation status of the baseOS from zboot
instead of the pubsub, since pubsub only gets populated after a config
is read.

Signed-off-by: Paul Gaiduk <paulg@zededa.com>
  • Loading branch information
europaul authored and eriknordmark committed Mar 15, 2024
1 parent 81ec19e commit dd571b5
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions pkg/pillar/cmd/zedagent/parseconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,28 +303,23 @@ func parseBaseOS(getconfigCtx *getconfigContext,
Activate: baseOS.Activate,
}

// Check if the BaseOsConfig already exists
prevBaseOsConfig, _ := getconfigCtx.pubBaseOsConfig.Get(cfg.Key())
if prevBaseOsConfig == nil {
// If we don't have a BaseOsConfig with the same key already published, it's a new one
// Check for activation flag
if cfg.Activate {
activateNewBaseOSFlag = true
}
// Check if baseOS version has changed and the new baseOS is set to be activated
partName := getZbootCurrentPartition(getconfigCtx.zedagentCtx)
status := getZbootPartitionStatus(getconfigCtx.zedagentCtx, partName)
if status.ShortVersion != cfg.BaseOsVersion && cfg.Activate {
activateNewBaseOSFlag = true
log.Functionf("BaseOS version has changed. Previous version: %s, New version: %s", status.ShortVersion, cfg.BaseOsVersion)
log.Functionf("Activate flag is set to true. BaseOS will be activated.")
} else {
log.Functionf("BaseOS version has not changed or Activate flag is not set to true.")
}

// Go through all published BaseOsConfig's and delete the ones which are not in the config
// and detect if we have a BaseOsConfig which has changed from Activate=false to Activate=true
items := getconfigCtx.pubBaseOsConfig.GetAll()
for idStr := range items {
if idStr != cfg.Key() {
log.Functionf("parseBaseOS: deleting %s\n", idStr)
unpublishBaseOsConfig(getconfigCtx, idStr)
} else {
if !items[idStr].(types.BaseOsConfig).Activate && cfg.Activate {
log.Functionf("parseBaseOS: Activate set for %s", idStr)
activateNewBaseOSFlag = true
}
}
}
// publish new one
Expand Down

0 comments on commit dd571b5

Please sign in to comment.