skylab create-suite: Accept random priority.
BUG=chromium:951511
TEST=./skylab create-suite -dev -board nyan_blaze -image nyan_blaze-paladin/R75-12099.0.0-rc1 -pool suites -tag user:xixuan -timeout-mins 4320 -priority 66 sanity
Change-Id: Ia16115a4f7b64757f822bafa672475068447d6ee
Reviewed-on: https://chromium-review.googlesource.com/c/infra/infra/+/1575901
Commit-Queue: Xixuan Wu <xixuan@chromium.org>
Reviewed-by: Aviv Keshet <akeshet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#22525}
diff --git a/go/src/infra/cmd/skylab/internal/cmd/common.go b/go/src/infra/cmd/skylab/internal/cmd/common.go
index 7a9487f..94b749a 100644
--- a/go/src/infra/cmd/skylab/internal/cmd/common.go
+++ b/go/src/infra/cmd/skylab/internal/cmd/common.go
@@ -12,7 +12,6 @@
"io/ioutil"
"log"
"net/http"
- "sort"
"time"
"github.com/maruel/subcommands"
@@ -29,24 +28,7 @@
const progName = "skylab"
-type taskPriority struct {
- name string
- level int
-}
-
-var taskPriorityMap = map[string]int{
- "Weekly": 230,
- "CTS": 215,
- "Daily": 200,
- "PostBuild": 170,
- "Default": 140,
- "Build": 110,
- "PFQ": 80,
- "CQ": 50,
- "Super": 49,
-}
-var defaultTaskPriorityKey = "Default"
-var defaultTaskPriority = taskPriorityMap[defaultTaskPriorityKey]
+var defaultTaskPriority = 140
type commonFlags struct {
debug bool
@@ -200,27 +182,6 @@
return m, nil
}
-func sortedPriorities() []taskPriority {
- s := make([]taskPriority, 0, len(taskPriorityMap))
- for k, v := range taskPriorityMap {
- s = append(s, taskPriority{k, v})
- }
-
- sort.Slice(s, func(i, j int) bool {
- return s[i].level < s[j].level
- })
- return s
-}
-
-func sortedPriorityKeys() []string {
- sp := sortedPriorities()
- k := make([]string, 0, len(sp))
- for _, p := range sp {
- k = append(k, p.name)
- }
- return k
-}
-
var retryableCodes = map[int]bool{
http.StatusInternalServerError: true, // 500
http.StatusBadGateway: true, // 502
diff --git a/go/src/infra/cmd/skylab/internal/cmd/create-suite.go b/go/src/infra/cmd/skylab/internal/cmd/create-suite.go
index 0b614d9..089dcc9 100644
--- a/go/src/infra/cmd/skylab/internal/cmd/create-suite.go
+++ b/go/src/infra/cmd/skylab/internal/cmd/create-suite.go
@@ -9,7 +9,6 @@
"encoding/json"
"fmt"
"strconv"
- "strings"
"time"
"github.com/maruel/subcommands"
@@ -19,7 +18,6 @@
"go.chromium.org/luci/common/errors"
"go.chromium.org/luci/common/flag"
- "infra/cmd/skylab/internal/flagx"
"infra/cmd/skylab/internal/site"
)
@@ -41,10 +39,9 @@
c.Flags.StringVar(&c.model, "model", "", "Model to run suite on.")
c.Flags.StringVar(&c.pool, "pool", "", "Device pool to run suite on.")
c.Flags.StringVar(&c.image, "image", "", "Fully specified image name to run suite against, e.g. reef-canary/R73-11580.0.0")
- c.Flags.Var(flagx.NewChoice(&c.priority, sortedPriorityKeys()...), "priority",
+ c.Flags.IntVar(&c.priority, "priority", defaultTaskPriority,
`Specify the priority of the suite. A high value means this suite
-will be executed in a low priority. It should one of:
-`+strings.Join(sortedPriorityKeys(), ", "))
+will be executed in a low priority.`)
c.Flags.IntVar(&c.timeoutMins, "timeout-mins", 20,
`Time (counting from when the task starts) after which task will be
killed if it hasn't completed.`)
@@ -70,7 +67,7 @@
model string
pool string
image string
- priority string
+ priority int
timeoutMins int
maxRetries int
tags []string
@@ -98,15 +95,11 @@
suiteName := c.Flags.Arg(0)
dimensions := []string{"pool:ChromeOSSkylab-suite"}
- if c.priority == "" {
- c.priority = defaultTaskPriorityKey
- }
- priority := taskPriorityMap[c.priority]
keyvals, err := toKeyvalMap(c.keyvals)
if err != nil {
return err
}
- slices, err := getSuiteSlices(c.board, c.model, c.pool, c.image, suiteName, c.qsAccount, priority, c.timeoutMins, c.maxRetries, dimensions, keyvals, c.orphan)
+ slices, err := getSuiteSlices(c.board, c.model, c.pool, c.image, suiteName, c.qsAccount, c.priority, c.timeoutMins, c.maxRetries, dimensions, keyvals, c.orphan)
if err != nil {
return errors.Annotate(err, "create suite").Err()
}
@@ -119,7 +112,7 @@
"label-board:"+c.board,
"label-model:"+c.model,
"label-pool:"+c.pool,
- "priority:"+c.priority)
+ "priority:"+strconv.Itoa(c.priority))
s, err := newSwarmingService(ctx, c.authFlags, e)
if err != nil {
@@ -130,7 +123,7 @@
Name: c.image + "-" + suiteName,
}
- task.ID, err = createSuiteTask(ctx, s, task.Name, priority, slices, tags)
+ task.ID, err = createSuiteTask(ctx, s, task.Name, c.priority, slices, tags)
if err != nil {
return errors.Annotate(err, "create suite").Err()
}
@@ -161,6 +154,10 @@
return NewUsageError(c.Flags, "missing -image")
}
+ if c.priority < 50 || c.priority > 255 {
+ return NewUsageError(c.Flags, "priority should in [50,255]")
+ }
+
return nil
}