Skip to content

Commit

Permalink
stages/files: add previousReport to result report
Browse files Browse the repository at this point in the history
This change notices if a report already exists and accordingly
nest the report in previousReport.
related to #1214
  • Loading branch information
sohankunkerkar committed Aug 4, 2021
1 parent 25d6d05 commit 2ea3db2
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions internal/exec/stages/files/filesystemEntries.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,48 @@ func (s *stage) createResultFile() error {
s.Logger.PushPrefix("createResultFile")
defer s.Logger.PopPrefix()

var prevReport interface{}
prevPath, err := s.JoinPath(distro.ResultFilePath())
if err != nil {
return fmt.Errorf("building previous result file path: %w", err)
}
prevData, err := ioutil.ReadFile(prevPath)
if err != nil && !os.IsNotExist(err) {
return fmt.Errorf("reading previous report: %w", err)
}
if err == nil {
// To check if it's a live system
cmd := exec.Command("is-lve-image")
err := cmd.Run()
if err != nil {
s.Logger.Notice("failed to run is-live-image hook")
}
if exitErr, ok := err.(*exec.ExitError); ok {
if exitErr.ExitCode() != 0 {
s.Logger.Warning("couldn't run is-live-image: %w", string(exitErr.Stderr))
}
}
s.Logger.Warning("Unexpected behavior may occur. Ignition is not designed to run more than once per system")
err = json.Unmarshal(prevData, &prevReport)
if err != nil {
return fmt.Errorf("couldn't unmarshal previous report output: %v", err)
}
}

bootIDBytes, err := ioutil.ReadFile(distro.BootIDPath())
if err != nil {
return fmt.Errorf("reading boot ID: %w", err)
}

result := struct {
ProvisioningBootID string `json:"provisioningBootID"`
ProvisioningDate string `json:"provisioningDate"`
UserConfigProvided bool `json:"userConfigProvided"`
ProvisioningBootID string `json:"provisioningBootID"`
ProvisioningDate string `json:"provisioningDate"`
UserConfigProvided bool `json:"userConfigProvided"`
PreviousReport interface{} `json:"previousReport,omitempty"`
}{
ProvisioningBootID: strings.TrimSpace(string(bootIDBytes)),
ProvisioningDate: time.Now().Format(time.RFC3339),
PreviousReport: prevReport,
}
for _, config := range s.State.FetchedConfigs {
if config.Kind == "user" {
Expand Down

0 comments on commit 2ea3db2

Please sign in to comment.