Skip to content

Commit

Permalink
packet: a more detailed timeline message
Browse files Browse the repository at this point in the history
  • Loading branch information
Bubblemelon committed Jun 27, 2018
1 parent 40b6996 commit ed97ed5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 32 deletions.
12 changes: 6 additions & 6 deletions internal/exec/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ type Engine struct {

// Run executes the stage of the given name. It returns true if the stage
// successfully ran and false if there were any errors.
func (e Engine) Run(stageName string) bool {
func (e Engine) Run(stageName string) (bool, string) {
if e.Fetcher == nil || e.Logger == nil {
fmt.Fprintf(os.Stderr, "engine incorrectly configured\n")
return false
return false, "engine incorrectly configured"
}
baseConfig := types.Config{
Ignition: types.Ignition{Version: types.MaxVersion.String()},
Expand All @@ -72,7 +72,7 @@ func (e Engine) Run(stageName string) bool {
e.logReport(r)
if err != nil && err != providers.ErrNoProvider {
e.Logger.Crit("failed to acquire system base config: %v", err)
return false
return false, "failed to acquire system base config: " + err.Error()
}

cfg, err := e.acquireConfig()
Expand All @@ -84,17 +84,17 @@ func (e Engine) Run(stageName string) bool {
e.logReport(r)
if err != nil && err != providers.ErrNoProvider {
e.Logger.Crit("failed to acquire default config: %v", err)
return false
return false, "failed to acquire default config: " + err.Error()
}
default:
e.Logger.Crit("failed to acquire config: %v", err)
return false
return false, "failed to acquire config: " + err.Error()
}

e.Logger.PushPrefix(stageName)
defer e.Logger.PopPrefix()

return stages.Get(stageName).Create(e.Logger, e.Root, *e.Fetcher).Run(config.Append(baseConfig, config.Append(systemBaseConfig, cfg)))
return stages.Get(stageName).Create(e.Logger, e.Root, *e.Fetcher).Run(config.Append(baseConfig, config.Append(systemBaseConfig, cfg))), "Valid Ignition Config"
}

// acquireConfig returns the configuration, first checking a local cache
Expand Down
7 changes: 4 additions & 3 deletions internal/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ func main() {
OEMConfig: oemConfig,
Fetcher: &fetcher,
}
ignSuccess, message := engine.Run(flags.stage.String())

if !engine.Run(flags.stage.String()) {
if !ignSuccess {
// ignition fails
logger.Info("Ignition Fails")
oemConfig.Status("fail")
oemConfig.Status(ignSuccess, message)
os.Exit(1)
} else {
logger.Info("Ignition Passes")
oemConfig.Status("")
oemConfig.Status(ignSuccess, message)
}
}
25 changes: 6 additions & 19 deletions internal/oem/oem.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,16 @@ func (c Config) NewFetcherFunc() providers.FuncNewFetcher {
}
}

func (c Config) Status(s string) providers.FuncStatusFetcher {
// Status takes b as whether ignition passes (true) or fails
// msg is the error or success message
func (c Config) Status(b bool, msg string) providers.FuncStatusFetcher {
rf := resource.Fetcher{}
if s == "fail" {
packet.FetchStatus(rf, s)
// r := report.Report{
// Entries: []Entry{
// {
// Message: "Ignition Failed",
// },
// },
// }
if !b {
packet.FetchStatus(rf, msg)

return c.status
}
// r := report.Report{
// Entries: []Entry{
// {
// Message: "Ignition Passed",
// },
// },
// }

packet.FetchStatus(rf, s)
packet.FetchStatus(rf, msg)

return c.status

Expand Down
7 changes: 3 additions & 4 deletions internal/providers/packet/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ func FetchStatus(f resource.Fetcher, s string) error {
postMessageURL := phonehomeURL + "/events"

// Place message into report struct
if s == "fail" {
if s != "Valid Ignition Config" {
m := Message{
Message: "Ignition Config Invalid",
Message: s,
}
// Marshall Message
messageJSON, err := json.Marshal(m)
Expand All @@ -119,11 +119,10 @@ func FetchStatus(f resource.Fetcher, s string) error {

} else {

// any string other than "fail" in vairable s:
fmt.Println("IGNTION STATUS PASS")

m := Message{
Message: "Ignition Config valid",
Message: s,
}

// Marshall Message
Expand Down

0 comments on commit ed97ed5

Please sign in to comment.