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() {
|
func init() {
|
||||||
cmd := root.Command("run", "Run a test group or OONI Run link")
|
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()
|
noCollector := cmd.Flag("no-collector", "Disable uploading measurements to a collector").Bool()
|
||||||
|
|
||||||
|
var probe *ooni.Probe
|
||||||
cmd.Action(func(_ *kingpin.ParseContext) error {
|
cmd.Action(func(_ *kingpin.ParseContext) error {
|
||||||
var err error
|
var err error
|
||||||
probe, err = root.Init()
|
probe, err = root.Init()
|
||||||
|
@ -29,22 +22,43 @@ func init() {
|
||||||
log.Errorf("%s", err)
|
log.Errorf("%s", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = onboard.MaybeOnboarding(probe); err != nil {
|
if err = onboard.MaybeOnboarding(probe); err != nil {
|
||||||
log.WithError(err).Error("failed to perform onboarding")
|
log.WithError(err).Error("failed to perform onboarding")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if *noCollector == true {
|
if *noCollector == true {
|
||||||
probe.Config().Sharing.UploadResults = false
|
probe.Config().Sharing.UploadResults = false
|
||||||
}
|
}
|
||||||
return nil
|
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", "")
|
websitesCmd := cmd.Command("websites", "")
|
||||||
inputFile := websitesCmd.Flag("input-file", "File containing input URLs").Strings()
|
inputFile := websitesCmd.Flag("input-file", "File containing input URLs").Strings()
|
||||||
input := websitesCmd.Flag("input", "Test the specified URL").Strings()
|
input := websitesCmd.Flag("input", "Test the specified URL").Strings()
|
||||||
websitesCmd.Action(func(_ *kingpin.ParseContext) error {
|
websitesCmd.Action(func(_ *kingpin.ParseContext) error {
|
||||||
|
log.Infof("Running %s tests", color.BlueString("websites"))
|
||||||
return nettests.RunGroup(nettests.RunGroupConfig{
|
return nettests.RunGroup(nettests.RunGroupConfig{
|
||||||
GroupName: "websites",
|
GroupName: "websites",
|
||||||
Probe: probe,
|
Probe: probe,
|
||||||
|
@ -52,43 +66,23 @@ func init() {
|
||||||
Inputs: *input,
|
Inputs: *input,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
imCmd := cmd.Command("im", "")
|
|
||||||
imCmd.Action(func(_ *kingpin.ParseContext) error {
|
easyRuns := []string{"im", "performance", "circumvention", "middlebox"}
|
||||||
return nettests.RunGroup(nettests.RunGroupConfig{
|
for _, name := range easyRuns {
|
||||||
GroupName: "im",
|
cmd.Command(name, "").Action(genRunWithGroupName(name))
|
||||||
Probe: probe,
|
}
|
||||||
})
|
|
||||||
})
|
unattendedCmd := cmd.Command("unattended", "")
|
||||||
performanceCmd := cmd.Command("performance", "")
|
unattendedCmd.Action(func(_ *kingpin.ParseContext) error {
|
||||||
performanceCmd.Action(func(_ *kingpin.ParseContext) error {
|
return functionalRun(func(name string, gr nettests.Group) bool {
|
||||||
return nettests.RunGroup(nettests.RunGroupConfig{
|
return gr.UnattendedOK == true
|
||||||
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,
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
allCmd := cmd.Command("all", "").Default()
|
allCmd := cmd.Command("all", "").Default()
|
||||||
allCmd.Action(func(_ *kingpin.ParseContext) error {
|
allCmd.Action(func(_ *kingpin.ParseContext) error {
|
||||||
log.Infof("Running %s tests", color.BlueString("all"))
|
return functionalRun(func(name string, gr nettests.Group) bool {
|
||||||
for tg := range nettests.NettestGroups {
|
return true
|
||||||
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
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,20 @@
|
||||||
package nettests
|
package nettests
|
||||||
|
|
||||||
// NettestGroup base structure
|
// Group is a group of nettests
|
||||||
type NettestGroup struct {
|
type Group struct {
|
||||||
Label string
|
Label string
|
||||||
Nettests []Nettest
|
Nettests []Nettest
|
||||||
|
UnattendedOK bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NettestGroups that can be run by the user
|
// All contains all the nettests that can be run by the user
|
||||||
var NettestGroups = map[string]NettestGroup{
|
var All = map[string]Group{
|
||||||
"websites": {
|
"websites": {
|
||||||
Label: "Websites",
|
Label: "Websites",
|
||||||
Nettests: []Nettest{
|
Nettests: []Nettest{
|
||||||
WebConnectivity{},
|
WebConnectivity{},
|
||||||
},
|
},
|
||||||
|
UnattendedOK: true,
|
||||||
},
|
},
|
||||||
"performance": {
|
"performance": {
|
||||||
Label: "Performance",
|
Label: "Performance",
|
||||||
|
@ -27,6 +29,7 @@ var NettestGroups = map[string]NettestGroup{
|
||||||
HTTPInvalidRequestLine{},
|
HTTPInvalidRequestLine{},
|
||||||
HTTPHeaderFieldManipulation{},
|
HTTPHeaderFieldManipulation{},
|
||||||
},
|
},
|
||||||
|
UnattendedOK: true,
|
||||||
},
|
},
|
||||||
"im": {
|
"im": {
|
||||||
Label: "Instant Messaging",
|
Label: "Instant Messaging",
|
||||||
|
@ -35,6 +38,7 @@ var NettestGroups = map[string]NettestGroup{
|
||||||
Telegram{},
|
Telegram{},
|
||||||
WhatsApp{},
|
WhatsApp{},
|
||||||
},
|
},
|
||||||
|
UnattendedOK: true,
|
||||||
},
|
},
|
||||||
"circumvention": {
|
"circumvention": {
|
||||||
Label: "Circumvention Tools",
|
Label: "Circumvention Tools",
|
||||||
|
@ -42,5 +46,6 @@ var NettestGroups = map[string]NettestGroup{
|
||||||
Psiphon{},
|
Psiphon{},
|
||||||
Tor{},
|
Tor{},
|
||||||
},
|
},
|
||||||
|
UnattendedOK: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ func RunGroup(config RunGroupConfig) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
group, ok := NettestGroups[config.GroupName]
|
group, ok := All[config.GroupName]
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Errorf("No test group named %s", config.GroupName)
|
log.Errorf("No test group named %s", config.GroupName)
|
||||||
return errors.New("invalid test group name")
|
return errors.New("invalid test group name")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user