Skip to content

Commit

Permalink
Fix sudo appearing in touchSentinel command (#91)
Browse files Browse the repository at this point in the history
Add tests for sudo being true or false in multi partial commands

Change test scheduler to include wrstat executable name and sudo.

Co-authored-by: Rosie Kern <[email protected]>
  • Loading branch information
rk1274 and rk1274 authored Sep 6, 2024
1 parent 0e9a806 commit 8c498e2
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 135 deletions.
2 changes: 1 addition & 1 deletion cmd/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ invocations of cron, do 'sudo wrstsat cron --kill'.

taskr := tasker.New(tasker.Option{})
taskr.Task(crontab, func(ctx context.Context) (int, error) {
err := doMultiScheduling(args)
err := doMultiScheduling(args, sudo)

if runJobs != "" {
os.Exit(0)
Expand Down
9 changes: 4 additions & 5 deletions cmd/multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ exists, and you have a wrstat server using the database files inside, the server
will automatically start using the new data and delete the old.`,
Run: func(cmd *cobra.Command, args []string) {
checkMultiArgs(args)
err := doMultiScheduling(args)
err := doMultiScheduling(args, sudo)
if err != nil {
die("%s", err)
}
Expand Down Expand Up @@ -203,8 +203,8 @@ func checkStandardFlags() {
}

// doMultiScheduling does the main work of the multi sub-command.
func doMultiScheduling(args []string) error {
s, d := newScheduler(workDir, forcedQueue)
func doMultiScheduling(args []string, sudo bool) error {
s, d := newScheduler(workDir, forcedQueue, sudo)
defer d()

unique := scheduler.UniqueString()
Expand All @@ -218,12 +218,11 @@ func doMultiScheduling(args []string) error {
scheduleWalkJobs(outputRoot, args, unique, multiStatJobs, multiInodes, multiCh, forcedQueue, s)

if partialDirMerge != "" {
s.DisableSudo()

unique = scheduleStaticCopy(outputRoot, unique, partialDirMerge, partialDirClean, s)
}

if createPartial {
s.DisableSudo()
schedulePartialSentinel(outputRoot, unique, s)

return nil
Expand Down
19 changes: 14 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,20 @@ func die(msg string, a ...interface{}) {
// function you should defer.
//
// If you provide a non-blank queue, that queue will be used when scheduling.
func newScheduler(cwd, queue string) (*scheduler.Scheduler, func()) {
func newScheduler(cwd, queue string, sudo bool) (*scheduler.Scheduler, func()) {
if runJobs != "" {
return testScheduler()
return testScheduler(sudo)
}

s, err := scheduler.New(deployment, cwd, queue, connectTimeout, appLogger, sudo)
s, err := scheduler.New(deployment, cwd, queue, connectTimeout, appLogger)
if err != nil {
die("%s", err)
}

if sudo {
s.EnableSudo()
}

return s, func() {
err = s.Disconnect()
if err != nil {
Expand Down Expand Up @@ -199,6 +203,11 @@ func testPrint(jobs []*jobqueue.Job) {
json.NewEncoder(w).Encode(jobs) //nolint:errcheck,errchkjson
}

func testScheduler() (*scheduler.Scheduler, func()) {
return &scheduler.Scheduler{}, func() {}
func testScheduler(sudo bool) (*scheduler.Scheduler, func()) {
s := &scheduler.Scheduler{}
if sudo {
s.EnableSudo()
}

return s, func() {}
}
2 changes: 1 addition & 1 deletion cmd/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ your own job that depends on that group, such as a 'wrstat combine' call).`,
Run: func(cmd *cobra.Command, args []string) {

Check warning on line 89 in cmd/walk.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'cmd' seems to be unused, consider removing or renaming it as _ (revive)
desiredDir := checkArgs(outputDir, depGroup, args)

s, d := newScheduler("", forcedQueue)
s, d := newScheduler("", forcedQueue, sudo)
defer d()

if walkID == "" {
Expand Down
Loading

0 comments on commit 8c498e2

Please sign in to comment.