diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2024-01-12 11:47:40 +0100 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2024-01-12 12:33:22 +0000 |
| commit | f6fa7c2845ca01940da7571219da2203c579068d (patch) | |
| tree | 4eb1473f8eee8c473bfe1b6031868b0e944b6a4d /syz-ci | |
| parent | c9aa7b7def60823283a7fd261940c0a05d3ce850 (diff) | |
syz-ci: refactor loadManagerConfig()
The linters are complaining about a too high cyclomatic complexity.
Split out a ManagerConfig.validate() method.
Diffstat (limited to 'syz-ci')
| -rw-r--r-- | syz-ci/manager.go | 19 | ||||
| -rw-r--r-- | syz-ci/syz-ci.go | 19 |
2 files changed, 22 insertions, 16 deletions
diff --git a/syz-ci/manager.go b/syz-ci/manager.go index f125e2e1a..d21a2a67f 100644 --- a/syz-ci/manager.go +++ b/syz-ci/manager.go @@ -14,6 +14,7 @@ import ( "os" "path" "path/filepath" + "regexp" "strings" "time" @@ -917,3 +918,21 @@ func (mgr *Manager) Errorf(msg string, args ...interface{}) { mgr.dash.LogError(mgr.name, msg, args...) } } + +func (mgr *ManagerConfig) validate(cfg *Config) error { + // Manager name must not contain dots because it is used as GCE image name prefix. + managerNameRe := regexp.MustCompile("^[a-zA-Z0-9-_]{3,64}$") + if !managerNameRe.MatchString(mgr.Name) { + return fmt.Errorf("param 'managers.name' has bad value: %q", mgr.Name) + } + if mgr.Jobs.AnyEnabled() && (cfg.DashboardAddr == "" || cfg.DashboardClient == "") { + return fmt.Errorf("manager %v: has jobs but no dashboard info", mgr.Name) + } + if mgr.Jobs.PollCommits && (cfg.DashboardAddr == "" || mgr.DashboardClient == "") { + return fmt.Errorf("manager %v: commit_poll is set but no dashboard info", mgr.Name) + } + if (mgr.Jobs.BisectCause || mgr.Jobs.BisectFix) && cfg.BisectBinDir == "" { + return fmt.Errorf("manager %v: enabled bisection but no bisect_bin_dir", mgr.Name) + } + return nil +} diff --git a/syz-ci/syz-ci.go b/syz-ci/syz-ci.go index 6eb62bba4..138bf2104 100644 --- a/syz-ci/syz-ci.go +++ b/syz-ci/syz-ci.go @@ -60,7 +60,6 @@ import ( _ "net/http/pprof" "os" "path/filepath" - "regexp" "strings" "sync" "time" @@ -419,26 +418,12 @@ func loadManagerConfig(cfg *Config, mgr *ManagerConfig) error { } else { managercfg.Name = cfg.Name + "-" + mgr.Name } - // Manager name must not contain dots because it is used as GCE image name prefix. - managerNameRe := regexp.MustCompile("^[a-zA-Z0-9-_]{3,64}$") - if !managerNameRe.MatchString(mgr.Name) { - return fmt.Errorf("param 'managers.name' has bad value: %q", mgr.Name) - } if mgr.CompilerType == "" { mgr.CompilerType = "gcc" } if mgr.Branch == "" { mgr.Branch = "master" } - if mgr.Jobs.AnyEnabled() && (cfg.DashboardAddr == "" || cfg.DashboardClient == "") { - return fmt.Errorf("manager %v: has jobs but no dashboard info", mgr.Name) - } - if mgr.Jobs.PollCommits && (cfg.DashboardAddr == "" || mgr.DashboardClient == "") { - return fmt.Errorf("manager %v: commit_poll is set but no dashboard info", mgr.Name) - } - if (mgr.Jobs.BisectCause || mgr.Jobs.BisectFix) && cfg.BisectBinDir == "" { - return fmt.Errorf("manager %v: enabled bisection but no bisect_bin_dir", mgr.Name) - } mgr.managercfg = managercfg managercfg.Syzkaller = filepath.FromSlash("syzkaller/current") if managercfg.HTTP == "" { @@ -456,10 +441,12 @@ func loadManagerConfig(cfg *Config, mgr *ManagerConfig) error { mgr.KernelBaselineConfig = osutil.Abs(mgr.KernelBaselineConfig) mgr.KernelCmdline = osutil.Abs(mgr.KernelCmdline) mgr.KernelSysctl = osutil.Abs(mgr.KernelSysctl) - if mgr.KernelConfig != "" && mgr.KernelBaselineConfig == "" { mgr.KernelBaselineConfig = inferBaselineConfig(mgr.KernelConfig) } + if err := mgr.validate(cfg); err != nil { + return err + } if cfg.PatchVMConfigs[managercfg.Type] != nil { managercfg.VM, err = config.MergeJSONs(managercfg.VM, cfg.PatchVMConfigs[managercfg.Type]) |
