feat: implement the unattended group (#183)
We don't want to run performance in the background because this causes too much traffic towards m-lab servers. When we'll have the check-in API, this will be the entry point we'll use to contact such an API and get things to do. Part of https://github.com/ooni/probe/issues/1289.
This commit is contained in:
parent
60d08eef3b
commit
d402cd9090
|
@ -12,16 +12,9 @@ import (
|
|||
|
||||
func init() {
|
||||
cmd := root.Command("run", "Run a test group or OONI Run link")
|
||||
|
||||
var nettestGroupNamesBlue []string
|
||||
var probe *ooni.Probe
|
||||
|
||||
for name := range nettests.NettestGroups {
|
||||
nettestGroupNamesBlue = append(nettestGroupNamesBlue, color.BlueString(name))
|
||||
}
|
||||
|
||||
noCollector := cmd.Flag("no-collector", "Disable uploading measurements to a collector").Bool()
|
||||
|
||||
var probe *ooni.Probe
|
||||
cmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
var err error
|
||||
probe, err = root.Init()
|
||||
|
@ -29,22 +22,43 @@ func init() {
|
|||
log.Errorf("%s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if err = onboard.MaybeOnboarding(probe); err != nil {
|
||||
log.WithError(err).Error("failed to perform onboarding")
|
||||
return err
|
||||
}
|
||||
|
||||
if *noCollector == true {
|
||||
probe.Config().Sharing.UploadResults = false
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
functionalRun := func(pred func(name string, gr nettests.Group) bool) error {
|
||||
for name, group := range nettests.All {
|
||||
if pred(name, group) != true {
|
||||
continue
|
||||
}
|
||||
log.Infof("Running %s tests", color.BlueString(name))
|
||||
conf := nettests.RunGroupConfig{GroupName: name, Probe: probe}
|
||||
if err := nettests.RunGroup(conf); err != nil {
|
||||
log.WithError(err).Errorf("failed to run %s", name)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
genRunWithGroupName := func(targetName string) func(*kingpin.ParseContext) error {
|
||||
return func(*kingpin.ParseContext) error {
|
||||
return functionalRun(func(groupName string, gr nettests.Group) bool {
|
||||
return groupName == targetName
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
websitesCmd := cmd.Command("websites", "")
|
||||
inputFile := websitesCmd.Flag("input-file", "File containing input URLs").Strings()
|
||||
input := websitesCmd.Flag("input", "Test the specified URL").Strings()
|
||||
websitesCmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
log.Infof("Running %s tests", color.BlueString("websites"))
|
||||
return nettests.RunGroup(nettests.RunGroupConfig{
|
||||
GroupName: "websites",
|
||||
Probe: probe,
|
||||
|
@ -52,43 +66,23 @@ func init() {
|
|||
Inputs: *input,
|
||||
})
|
||||
})
|
||||
imCmd := cmd.Command("im", "")
|
||||
imCmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
return nettests.RunGroup(nettests.RunGroupConfig{
|
||||
GroupName: "im",
|
||||
Probe: probe,
|
||||
})
|
||||
})
|
||||
performanceCmd := cmd.Command("performance", "")
|
||||
performanceCmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
return nettests.RunGroup(nettests.RunGroupConfig{
|
||||
GroupName: "performance",
|
||||
Probe: probe,
|
||||
})
|
||||
})
|
||||
middleboxCmd := cmd.Command("middlebox", "")
|
||||
middleboxCmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
return nettests.RunGroup(nettests.RunGroupConfig{
|
||||
GroupName: "middlebox",
|
||||
Probe: probe,
|
||||
})
|
||||
})
|
||||
circumventionCmd := cmd.Command("circumvention", "")
|
||||
circumventionCmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
return nettests.RunGroup(nettests.RunGroupConfig{
|
||||
GroupName: "circumvention",
|
||||
Probe: probe,
|
||||
|
||||
easyRuns := []string{"im", "performance", "circumvention", "middlebox"}
|
||||
for _, name := range easyRuns {
|
||||
cmd.Command(name, "").Action(genRunWithGroupName(name))
|
||||
}
|
||||
|
||||
unattendedCmd := cmd.Command("unattended", "")
|
||||
unattendedCmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
return functionalRun(func(name string, gr nettests.Group) bool {
|
||||
return gr.UnattendedOK == true
|
||||
})
|
||||
})
|
||||
|
||||
allCmd := cmd.Command("all", "").Default()
|
||||
allCmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
log.Infof("Running %s tests", color.BlueString("all"))
|
||||
for tg := range nettests.NettestGroups {
|
||||
group := nettests.RunGroupConfig{GroupName: tg, Probe: probe}
|
||||
if err := nettests.RunGroup(group); err != nil {
|
||||
log.WithError(err).Errorf("failed to run %s", tg)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return functionalRun(func(name string, gr nettests.Group) bool {
|
||||
return true
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
package nettests
|
||||
|
||||
// NettestGroup base structure
|
||||
type NettestGroup struct {
|
||||
// Group is a group of nettests
|
||||
type Group struct {
|
||||
Label string
|
||||
Nettests []Nettest
|
||||
UnattendedOK bool
|
||||
}
|
||||
|
||||
// NettestGroups that can be run by the user
|
||||
var NettestGroups = map[string]NettestGroup{
|
||||
// All contains all the nettests that can be run by the user
|
||||
var All = map[string]Group{
|
||||
"websites": {
|
||||
Label: "Websites",
|
||||
Nettests: []Nettest{
|
||||
WebConnectivity{},
|
||||
},
|
||||
UnattendedOK: true,
|
||||
},
|
||||
"performance": {
|
||||
Label: "Performance",
|
||||
|
@ -27,6 +29,7 @@ var NettestGroups = map[string]NettestGroup{
|
|||
HTTPInvalidRequestLine{},
|
||||
HTTPHeaderFieldManipulation{},
|
||||
},
|
||||
UnattendedOK: true,
|
||||
},
|
||||
"im": {
|
||||
Label: "Instant Messaging",
|
||||
|
@ -35,6 +38,7 @@ var NettestGroups = map[string]NettestGroup{
|
|||
Telegram{},
|
||||
WhatsApp{},
|
||||
},
|
||||
UnattendedOK: true,
|
||||
},
|
||||
"circumvention": {
|
||||
Label: "Circumvention Tools",
|
||||
|
@ -42,5 +46,6 @@ var NettestGroups = map[string]NettestGroup{
|
|||
Psiphon{},
|
||||
Tor{},
|
||||
},
|
||||
UnattendedOK: true,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ func RunGroup(config RunGroupConfig) error {
|
|||
return err
|
||||
}
|
||||
|
||||
group, ok := NettestGroups[config.GroupName]
|
||||
group, ok := All[config.GroupName]
|
||||
if !ok {
|
||||
log.Errorf("No test group named %s", config.GroupName)
|
||||
return errors.New("invalid test group name")
|
||||
|
|
Loading…
Reference in New Issue
Block a user