Skip to content

Commit

Permalink
feat: implement the unattended group
Browse files Browse the repository at this point in the history
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 ooni/probe#1289.
  • Loading branch information
bassosimone committed Dec 1, 2020
1 parent 60d08ee commit bc86a85
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 51 deletions.
82 changes: 38 additions & 44 deletions internal/cli/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,83 +12,77 @@ 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()
if err != nil {
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,
InputFiles: *inputFile,
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
})
})
}
17 changes: 11 additions & 6 deletions internal/nettests/groups.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package nettests

// NettestGroup base structure
type NettestGroup struct {
Label string
Nettests []Nettest
// 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",
Expand All @@ -27,6 +29,7 @@ var NettestGroups = map[string]NettestGroup{
HTTPInvalidRequestLine{},
HTTPHeaderFieldManipulation{},
},
UnattendedOK: true,
},
"im": {
Label: "Instant Messaging",
Expand All @@ -35,12 +38,14 @@ var NettestGroups = map[string]NettestGroup{
Telegram{},
WhatsApp{},
},
UnattendedOK: true,
},
"circumvention": {
Label: "Circumvention Tools",
Nettests: []Nettest{
Psiphon{},
Tor{},
},
UnattendedOK: true,
},
}
2 changes: 1 addition & 1 deletion internal/nettests/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit bc86a85

Please sign in to comment.