ooni-probe-cli/internal/cli/run/run.go

55 lines
1.4 KiB
Go
Raw Normal View History

package run
import (
2018-02-13 17:11:22 +01:00
"time"
"github.com/alecthomas/kingpin"
2018-02-12 16:45:13 +01:00
"github.com/apex/log"
"github.com/openobservatory/gooni/internal/cli/root"
2018-02-13 17:11:22 +01:00
"github.com/openobservatory/gooni/internal/database"
"github.com/openobservatory/gooni/nettests"
2018-02-13 16:16:23 +01:00
"github.com/openobservatory/gooni/nettests/groups"
)
func init() {
cmd := root.Command("run", "Run a test group or OONI Run link")
nettestGroup := cmd.Arg("name", "the nettest group to run").Required().String()
cmd.Action(func(_ *kingpin.ParseContext) error {
log.Infof("Starting %s", *nettestGroup)
2018-02-13 17:11:22 +01:00
_, ctx, err := root.Init()
2018-02-12 16:45:13 +01:00
if err != nil {
log.Errorf("%s", err)
return err
}
2018-02-13 17:11:22 +01:00
group := groups.NettestGroups[*nettestGroup]
log.Debugf("Running test group %s", group.Label)
2018-02-13 16:16:23 +01:00
2018-02-13 17:11:22 +01:00
result, err := database.CreateResult(ctx.DB, database.Result{
Name: *nettestGroup,
2018-03-08 13:46:21 +01:00
StartTime: time.Now().UTC(),
2018-02-13 17:11:22 +01:00
})
if err != nil {
2018-03-08 11:53:04 +01:00
log.Errorf("DB result error: %s", err)
2018-02-13 17:11:22 +01:00
return err
}
for _, nt := range group.Nettests {
2018-03-14 14:44:37 +01:00
log.Debugf("Running test %T", nt)
ctl := nettests.NewController(ctx, result)
2018-03-08 13:46:21 +01:00
if err := nt.Run(ctl); err != nil {
log.WithError(err).Errorf("Failed to run %s", group.Label)
return err
}
2018-02-13 17:11:22 +01:00
// XXX
// 1. Generate the summary
// 2. Link the measurement to the Result (this should probably happen in
// the nettest class)
// 3. Update the summary of the result and the other metadata in the db
}
2018-03-08 13:46:21 +01:00
// result.Update(ctx.DB)
return nil
})
}