Skip to content

Commit

Permalink
wip try os.Create
Browse files Browse the repository at this point in the history
  • Loading branch information
shoenig committed Mar 23, 2022
1 parent 71ccb89 commit c65cbf1
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions plugins/drivers/testutils/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strings"
"time"

"github.com/hashicorp/nomad/client/lib/cgutil"
"github.com/opencontainers/runc/libcontainer/cgroups/fs2"

hclog "github.com/hashicorp/go-hclog"
plugin "github.com/hashicorp/go-plugin"
"github.com/hashicorp/nomad/client/allocdir"
"github.com/hashicorp/nomad/client/config"
"github.com/hashicorp/nomad/client/lib/cgutil"
"github.com/hashicorp/nomad/client/logmon"
"github.com/hashicorp/nomad/client/taskenv"
"github.com/hashicorp/nomad/helper/testlog"
Expand Down Expand Up @@ -76,7 +75,11 @@ func NewDriverHarness(t testing.T, d drivers.DriverPlugin) *DriverHarness {
func (h *DriverHarness) setCgroup(allocID, task string) {
if cgutil.UseV2 {
h.cgroup = filepath.Join(cgutil.CgroupRoot, "testing.slice", cgutil.CgroupScope(allocID, task))
_ = fs2.CreateCgroupPath(h.cgroup, nil)
f, err := os.Create(h.cgroup)
if err != nil {
panic(err)
}
defer f.Close()
}
}

Expand All @@ -88,8 +91,10 @@ func (h *DriverHarness) Kill() {

func (h *DriverHarness) cleanupCgroup() {
if cgutil.UseV2 {
mgr, _ := fs2.NewManager(nil, h.cgroup, false)
_ = mgr.Destroy()
err := os.Remove(h.cgroup)
if err != nil {
panic(err)
}
}
}

Expand Down

0 comments on commit c65cbf1

Please sign in to comment.