deps: Update ioutil deprecated library references to os and io respectively in the client package (#16318)
* Update ioutil deprecated library references to os and io respectively * Deal with the errors produced. Add error handling to filEntry info Add error handling to info
This commit is contained in:
parent
2332d694bb
commit
35c17b2e56
|
@ -3,7 +3,7 @@ package client_test
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
|
@ -102,7 +102,7 @@ func TestPrevAlloc_StreamAllocDir_TLS(t *testing.T) {
|
|||
// Save a file into alloc dir
|
||||
contents := []byte("123\n456")
|
||||
allocFn := filepath.Join(client1.DataDir, "alloc", origAlloc, "alloc", "data", "bar")
|
||||
require.NoError(ioutil.WriteFile(allocFn, contents, 0666))
|
||||
require.NoError(os.WriteFile(allocFn, contents, 0666))
|
||||
t.Logf("[TEST] Wrote initial file: %s", allocFn)
|
||||
|
||||
// Migrate alloc to other node
|
||||
|
@ -141,7 +141,7 @@ func TestPrevAlloc_StreamAllocDir_TLS(t *testing.T) {
|
|||
allocFn2 := filepath.Join(client2.DataDir, "alloc", newAlloc.ID, "alloc", "data", "bar")
|
||||
t.Logf("[TEST] Comparing against file: %s", allocFn2)
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
found, err := ioutil.ReadFile(allocFn2)
|
||||
found, err := os.ReadFile(allocFn2)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -357,12 +356,16 @@ func (d *AllocDir) List(path string) ([]*cstructs.AllocFileInfo, error) {
|
|||
}
|
||||
|
||||
p := filepath.Join(d.AllocDir, path)
|
||||
finfos, err := ioutil.ReadDir(p)
|
||||
finfos, err := os.ReadDir(p)
|
||||
if err != nil {
|
||||
return []*cstructs.AllocFileInfo{}, err
|
||||
}
|
||||
files := make([]*cstructs.AllocFileInfo, len(finfos))
|
||||
for idx, info := range finfos {
|
||||
for idx, file := range finfos {
|
||||
info, err := file.Info()
|
||||
if err != nil {
|
||||
return []*cstructs.AllocFileInfo{}, err
|
||||
}
|
||||
files[idx] = &cstructs.AllocFileInfo{
|
||||
Name: info.Name(),
|
||||
IsDir: info.IsDir(),
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"context"
|
||||
"io"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
@ -120,14 +119,14 @@ func TestAllocDir_MountSharedAlloc(t *testing.T) {
|
|||
// Write a file to the shared dir.
|
||||
contents := []byte("foo")
|
||||
const filename = "bar"
|
||||
if err := ioutil.WriteFile(filepath.Join(d.SharedDir, filename), contents, 0666); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(d.SharedDir, filename), contents, 0666); err != nil {
|
||||
t.Fatalf("Couldn't write file to shared directory: %v", err)
|
||||
}
|
||||
|
||||
// Check that the file exists in the task directories
|
||||
for _, td := range []*TaskDir{td1, td2} {
|
||||
taskFile := filepath.Join(td.SharedTaskDir, filename)
|
||||
act, err := ioutil.ReadFile(taskFile)
|
||||
act, err := os.ReadFile(taskFile)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to read shared alloc file from task dir: %v", err)
|
||||
continue
|
||||
|
@ -163,7 +162,7 @@ func TestAllocDir_Snapshot(t *testing.T) {
|
|||
// Write a file to the shared dir.
|
||||
exp := []byte{'f', 'o', 'o'}
|
||||
file := "bar"
|
||||
if err := ioutil.WriteFile(filepath.Join(d.SharedDir, "data", file), exp, 0666); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(d.SharedDir, "data", file), exp, 0666); err != nil {
|
||||
t.Fatalf("Couldn't write file to shared directory: %v", err)
|
||||
}
|
||||
|
||||
|
@ -176,7 +175,7 @@ func TestAllocDir_Snapshot(t *testing.T) {
|
|||
// Write a file to the task local
|
||||
exp = []byte{'b', 'a', 'r'}
|
||||
file1 := "lol"
|
||||
if err := ioutil.WriteFile(filepath.Join(td1.LocalDir, file1), exp, 0666); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(td1.LocalDir, file1), exp, 0666); err != nil {
|
||||
t.Fatalf("couldn't write file to task local directory: %v", err)
|
||||
}
|
||||
|
||||
|
@ -250,14 +249,14 @@ func TestAllocDir_Move(t *testing.T) {
|
|||
// Write a file to the shared dir.
|
||||
exp1 := []byte("foo")
|
||||
file1 := "bar"
|
||||
if err := ioutil.WriteFile(filepath.Join(dataDir, file1), exp1, 0666); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(dataDir, file1), exp1, 0666); err != nil {
|
||||
t.Fatalf("Couldn't write file to shared directory: %v", err)
|
||||
}
|
||||
|
||||
// Write a file to the task local
|
||||
exp2 := []byte("bar")
|
||||
file2 := "lol"
|
||||
if err := ioutil.WriteFile(filepath.Join(td1.LocalDir, file2), exp2, 0666); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(td1.LocalDir, file2), exp2, 0666); err != nil {
|
||||
t.Fatalf("couldn't write to task local directory: %v", err)
|
||||
}
|
||||
|
||||
|
@ -337,7 +336,7 @@ func TestAllocDir_ReadAt_SecretDir(t *testing.T) {
|
|||
|
||||
// create target file in the task secrets dir
|
||||
full := filepath.Join(d.AllocDir, target)
|
||||
err = ioutil.WriteFile(full, []byte("hi"), 0600)
|
||||
err = os.WriteFile(full, []byte("hi"), 0600)
|
||||
require.NoError(t, err)
|
||||
|
||||
// ReadAt of a file in the task secrets dir should fail
|
||||
|
|
|
@ -2,7 +2,6 @@ package allocdir
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
|
@ -184,12 +183,16 @@ func (t *TaskDir) embedDirs(entries map[string]string) error {
|
|||
}
|
||||
|
||||
// Enumerate the files in source.
|
||||
dirEntries, err := ioutil.ReadDir(source)
|
||||
dirEntries, err := os.ReadDir(source)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Couldn't read directory %v: %v", source, err)
|
||||
}
|
||||
|
||||
for _, entry := range dirEntries {
|
||||
for _, fileEntry := range dirEntries {
|
||||
entry, err := fileEntry.Info()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Couldn't read the file information %v: %v", entry, err)
|
||||
}
|
||||
hostEntry := filepath.Join(source, entry.Name())
|
||||
taskEntry := filepath.Join(destDir, filepath.Base(hostEntry))
|
||||
if entry.IsDir() {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package allocdir
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
@ -55,11 +54,11 @@ func TestTaskDir_EmbedDirs(t *testing.T) {
|
|||
|
||||
file := "foo"
|
||||
subFile := "bar"
|
||||
if err := ioutil.WriteFile(filepath.Join(host, file), []byte{'a'}, 0777); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(host, file), []byte{'a'}, 0777); err != nil {
|
||||
t.Fatalf("Couldn't create file in host dir %v: %v", host, err)
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(filepath.Join(subDir, subFile), []byte{'a'}, 0777); err != nil {
|
||||
if err := os.WriteFile(filepath.Join(subDir, subFile), []byte{'a'}, 0777); err != nil {
|
||||
t.Fatalf("Couldn't create file in host subdir %v: %v", subDir, err)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package allocdir
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
hclog "github.com/hashicorp/go-hclog"
|
||||
|
@ -11,7 +10,7 @@ import (
|
|||
// TestAllocDir returns a built alloc dir in a temporary directory and cleanup
|
||||
// func.
|
||||
func TestAllocDir(t testing.T, l hclog.Logger, prefix, id string) (*AllocDir, func()) {
|
||||
dir, err := ioutil.TempDir("", prefix)
|
||||
dir, err := os.MkdirTemp("", prefix)
|
||||
if err != nil {
|
||||
t.Fatalf("Couldn't create temp dir: %v", err)
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package allocrunner
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync/atomic"
|
||||
|
@ -1680,10 +1679,10 @@ func TestAllocRunner_MoveAllocDir(t *testing.T) {
|
|||
// Step 2. Modify its directory
|
||||
task := alloc.Job.TaskGroups[0].Tasks[0]
|
||||
dataFile := filepath.Join(ar.allocDir.SharedDir, "data", "data_file")
|
||||
ioutil.WriteFile(dataFile, []byte("hello world"), os.ModePerm)
|
||||
os.WriteFile(dataFile, []byte("hello world"), os.ModePerm)
|
||||
taskDir := ar.allocDir.TaskDirs[task.Name]
|
||||
taskLocalFile := filepath.Join(taskDir.LocalDir, "local_file")
|
||||
ioutil.WriteFile(taskLocalFile, []byte("good bye world"), os.ModePerm)
|
||||
os.WriteFile(taskLocalFile, []byte("good bye world"), os.ModePerm)
|
||||
|
||||
// Step 3. Start a new alloc
|
||||
alloc2 := mock.BatchAlloc()
|
||||
|
|
|
@ -3,7 +3,6 @@ package taskrunner
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
|
@ -83,7 +82,7 @@ func TestTaskRunner_ArtifactHook_PartialDone(t *testing.T) {
|
|||
|
||||
// Only create one of the 2 artifacts to cause an error on first run.
|
||||
file1 := filepath.Join(srcdir, "foo.txt")
|
||||
require.NoError(t, ioutil.WriteFile(file1, []byte{'1'}, 0644))
|
||||
require.NoError(t, os.WriteFile(file1, []byte{'1'}, 0644))
|
||||
|
||||
// Test server to serve the artifacts
|
||||
ts := httptest.NewServer(http.FileServer(http.Dir(srcdir)))
|
||||
|
@ -127,7 +126,7 @@ func TestTaskRunner_ArtifactHook_PartialDone(t *testing.T) {
|
|||
|
||||
// Write file2 so artifacts can download successfully
|
||||
file2 := filepath.Join(srcdir, "bar.txt")
|
||||
require.NoError(t, ioutil.WriteFile(file2, []byte{'1'}, 0644))
|
||||
require.NoError(t, os.WriteFile(file2, []byte{'1'}, 0644))
|
||||
|
||||
// Mock TaskRunner by copying state from resp to req and reset resp.
|
||||
req.PreviousState = maps.Clone(resp.State)
|
||||
|
@ -174,7 +173,7 @@ func TestTaskRunner_ArtifactHook_ConcurrentDownloadSuccess(t *testing.T) {
|
|||
numOfFiles := 7
|
||||
for i := 0; i < numOfFiles; i++ {
|
||||
file := filepath.Join(srcdir, fmt.Sprintf("file%d.txt", i))
|
||||
require.NoError(t, ioutil.WriteFile(file, []byte{byte(i)}, 0644))
|
||||
require.NoError(t, os.WriteFile(file, []byte{byte(i)}, 0644))
|
||||
}
|
||||
|
||||
// Test server to serve the artifacts
|
||||
|
@ -260,13 +259,13 @@ func TestTaskRunner_ArtifactHook_ConcurrentDownloadFailure(t *testing.T) {
|
|||
srcdir := t.TempDir()
|
||||
|
||||
file1 := filepath.Join(srcdir, "file1.txt")
|
||||
require.NoError(t, ioutil.WriteFile(file1, []byte{'1'}, 0644))
|
||||
require.NoError(t, os.WriteFile(file1, []byte{'1'}, 0644))
|
||||
|
||||
file2 := filepath.Join(srcdir, "file2.txt")
|
||||
require.NoError(t, ioutil.WriteFile(file2, []byte{'2'}, 0644))
|
||||
require.NoError(t, os.WriteFile(file2, []byte{'2'}, 0644))
|
||||
|
||||
file3 := filepath.Join(srcdir, "file3.txt")
|
||||
require.NoError(t, ioutil.WriteFile(file3, []byte{'3'}, 0644))
|
||||
require.NoError(t, os.WriteFile(file3, []byte{'3'}, 0644))
|
||||
|
||||
// Test server to serve the artifacts
|
||||
ts := httptest.NewServer(http.FileServer(http.Dir(srcdir)))
|
||||
|
@ -319,7 +318,7 @@ func TestTaskRunner_ArtifactHook_ConcurrentDownloadFailure(t *testing.T) {
|
|||
|
||||
// create the missing file
|
||||
file0 := filepath.Join(srcdir, "file0.txt")
|
||||
require.NoError(t, ioutil.WriteFile(file0, []byte{'0'}, 0644))
|
||||
require.NoError(t, os.WriteFile(file0, []byte{'0'}, 0644))
|
||||
|
||||
// Mock TaskRunner by copying state from resp to req and reset resp.
|
||||
req.PreviousState = maps.Clone(resp.State)
|
||||
|
@ -342,19 +341,19 @@ func TestTaskRunner_ArtifactHook_ConcurrentDownloadFailure(t *testing.T) {
|
|||
require.Contains(t, files[3], "file3.txt")
|
||||
|
||||
// verify the file contents too, since files will also be created for failed downloads
|
||||
data0, err := ioutil.ReadFile(files[0])
|
||||
data0, err := os.ReadFile(files[0])
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, data0, []byte{'0'})
|
||||
|
||||
data1, err := ioutil.ReadFile(files[1])
|
||||
data1, err := os.ReadFile(files[1])
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, data1, []byte{'1'})
|
||||
|
||||
data2, err := ioutil.ReadFile(files[2])
|
||||
data2, err := os.ReadFile(files[2])
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, data2, []byte{'2'})
|
||||
|
||||
data3, err := ioutil.ReadFile(files[3])
|
||||
data3, err := os.ReadFile(files[3])
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, data3, []byte{'3'})
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
|
@ -270,7 +269,7 @@ func (h *connectNativeHook) maybeSetSITokenEnv(dir, task string, env map[string]
|
|||
return nil
|
||||
}
|
||||
|
||||
token, err := ioutil.ReadFile(filepath.Join(dir, sidsTokenFile))
|
||||
token, err := os.ReadFile(filepath.Join(dir, sidsTokenFile))
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return fmt.Errorf("failed to load SI token for native task %s: %w", task, err)
|
||||
|
|
|
@ -2,7 +2,8 @@ package taskrunner
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
|
@ -27,8 +28,8 @@ func getTestConsul(t *testing.T) *consultest.TestServer {
|
|||
testConsul, err := consultest.NewTestServerConfigT(t, func(c *consultest.TestServerConfig) {
|
||||
c.Peering = nil // fix for older versions of Consul (<1.13.0) that don't support peering
|
||||
if !testing.Verbose() { // disable consul logging if -v not set
|
||||
c.Stdout = ioutil.Discard
|
||||
c.Stderr = ioutil.Discard
|
||||
c.Stdout = io.Discard
|
||||
c.Stderr = io.Discard
|
||||
}
|
||||
})
|
||||
require.NoError(t, err, "failed to start test consul server")
|
||||
|
@ -42,7 +43,7 @@ func TestConnectNativeHook_Name(t *testing.T) {
|
|||
}
|
||||
|
||||
func setupCertDirs(t *testing.T) (string, string) {
|
||||
fd, err := ioutil.TempFile(t.TempDir(), "connect_native_testcert")
|
||||
fd, err := os.CreateTemp(t.TempDir(), "connect_native_testcert")
|
||||
require.NoError(t, err)
|
||||
_, err = fd.WriteString("ABCDEF")
|
||||
require.NoError(t, err)
|
||||
|
@ -65,7 +66,7 @@ func TestConnectNativeHook_copyCertificate(t *testing.T) {
|
|||
t.Run("normal", func(t *testing.T) {
|
||||
err := new(connectNativeHook).copyCertificate(f, d, "out.pem")
|
||||
require.NoError(t, err)
|
||||
b, err := ioutil.ReadFile(filepath.Join(d, "out.pem"))
|
||||
b, err := os.ReadFile(filepath.Join(d, "out.pem"))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "ABCDEF", string(b))
|
||||
})
|
||||
|
@ -83,7 +84,7 @@ func TestConnectNativeHook_copyCertificates(t *testing.T) {
|
|||
KeyFile: f,
|
||||
}, d)
|
||||
require.NoError(t, err)
|
||||
ls, err := ioutil.ReadDir(d)
|
||||
ls, err := os.ReadDir(d)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 3, len(ls))
|
||||
})
|
||||
|
@ -411,7 +412,7 @@ func TestTaskRunner_ConnectNativeHook_with_SI_token(t *testing.T) {
|
|||
// Insert service identity token in the secrets directory
|
||||
token := uuid.Generate()
|
||||
siTokenFile := filepath.Join(request.TaskDir.SecretsDir, sidsTokenFile)
|
||||
err = ioutil.WriteFile(siTokenFile, []byte(token), 0440)
|
||||
err = os.WriteFile(siTokenFile, []byte(token), 0440)
|
||||
require.NoError(t, err)
|
||||
|
||||
response := new(interfaces.TaskPrestartResponse)
|
||||
|
@ -538,7 +539,7 @@ func TestTaskRunner_ConnectNativeHook_shareTLS(t *testing.T) {
|
|||
}
|
||||
|
||||
func checkFilesInDir(t *testing.T, dir string, includes, excludes []string) {
|
||||
ls, err := ioutil.ReadDir(dir)
|
||||
ls, err := os.ReadDir(dir)
|
||||
require.NoError(t, err)
|
||||
|
||||
var present []string
|
||||
|
|
|
@ -2,7 +2,6 @@ package taskrunner
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
|
@ -69,5 +68,5 @@ func writeDispatchPayload(base, filename string, payload []byte) error {
|
|||
return err
|
||||
}
|
||||
|
||||
return ioutil.WriteFile(renderTo, decoded, 0777)
|
||||
return os.WriteFile(renderTo, decoded, 0777)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package taskrunner
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
|
@ -50,7 +50,7 @@ func TestTaskRunner_DispatchHook_NoPayload(t *testing.T) {
|
|||
require.True(resp.Done)
|
||||
|
||||
// Assert payload directory is empty
|
||||
files, err := ioutil.ReadDir(req.TaskDir.LocalDir)
|
||||
files, err := os.ReadDir(req.TaskDir.LocalDir)
|
||||
require.NoError(err)
|
||||
require.Empty(files)
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ func TestTaskRunner_DispatchHook_Ok(t *testing.T) {
|
|||
require.True(resp.Done)
|
||||
|
||||
filename := filepath.Join(req.TaskDir.LocalDir, task.DispatchPayload.File)
|
||||
result, err := ioutil.ReadFile(filename)
|
||||
result, err := os.ReadFile(filename)
|
||||
require.NoError(err)
|
||||
require.Equal(expected, result)
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ func TestTaskRunner_DispatchHook_Error(t *testing.T) {
|
|||
require.False(resp.Done)
|
||||
|
||||
// Assert payload directory is empty
|
||||
files, err := ioutil.ReadDir(req.TaskDir.LocalDir)
|
||||
files, err := os.ReadDir(req.TaskDir.LocalDir)
|
||||
require.NoError(err)
|
||||
require.Empty(files)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
@ -448,7 +447,7 @@ func buildEnvoyBind(alloc *structs.Allocation, ifce, service, task string, taskE
|
|||
}
|
||||
|
||||
func (h *envoyBootstrapHook) writeConfig(filename, config string) error {
|
||||
if err := ioutil.WriteFile(filename, []byte(config), 0440); err != nil {
|
||||
if err := os.WriteFile(filename, []byte(config), 0440); err != nil {
|
||||
_ = os.Remove(filename)
|
||||
return err
|
||||
}
|
||||
|
@ -596,7 +595,7 @@ func (e envoyBootstrapArgs) env(env []string) []string {
|
|||
// Consul ACLs are enabled), it will be in place by the time we try to read it.
|
||||
func (h *envoyBootstrapHook) maybeLoadSIToken(task, dir string) (string, error) {
|
||||
tokenPath := filepath.Join(dir, sidsTokenFile)
|
||||
token, err := ioutil.ReadFile(tokenPath)
|
||||
token, err := os.ReadFile(tokenPath)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
h.logger.Error("failed to load SI token", "task", task, "error", err)
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
@ -46,7 +45,7 @@ func writeTmp(t *testing.T, s string, fm os.FileMode) string {
|
|||
dir := t.TempDir()
|
||||
|
||||
fPath := filepath.Join(dir, sidsTokenFile)
|
||||
err := ioutil.WriteFile(fPath, []byte(s), fm)
|
||||
err := os.WriteFile(fPath, []byte(s), fm)
|
||||
require.NoError(t, err)
|
||||
|
||||
return dir
|
||||
|
@ -358,7 +357,7 @@ func TestEnvoyBootstrapHook_with_SI_token(t *testing.T) {
|
|||
// Insert service identity token in the secrets directory
|
||||
token := uuid.Generate()
|
||||
siTokenFile := filepath.Join(req.TaskDir.SecretsDir, sidsTokenFile)
|
||||
err = ioutil.WriteFile(siTokenFile, []byte(token), 0440)
|
||||
err = os.WriteFile(siTokenFile, []byte(token), 0440)
|
||||
require.NoError(t, err)
|
||||
|
||||
resp := &interfaces.TaskPrestartResponse{}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
@ -147,7 +146,7 @@ func (h *sidsHook) earlyExit() bool {
|
|||
// writeToken writes token into the secrets directory for the task.
|
||||
func (h *sidsHook) writeToken(dir string, token string) error {
|
||||
tokenPath := filepath.Join(dir, sidsTokenFile)
|
||||
if err := ioutil.WriteFile(tokenPath, []byte(token), sidsTokenFilePerms); err != nil {
|
||||
if err := os.WriteFile(tokenPath, []byte(token), sidsTokenFilePerms); err != nil {
|
||||
return fmt.Errorf("failed to write SI token: %w", err)
|
||||
}
|
||||
return nil
|
||||
|
@ -158,7 +157,7 @@ func (h *sidsHook) writeToken(dir string, token string) error {
|
|||
// is returned only for some other (e.g. disk IO) error.
|
||||
func (h *sidsHook) recoverToken(dir string) (string, error) {
|
||||
tokenPath := filepath.Join(dir, sidsTokenFile)
|
||||
token, err := ioutil.ReadFile(tokenPath)
|
||||
token, err := os.ReadFile(tokenPath)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
h.logger.Error("failed to recover SI token", "error", err)
|
||||
|
|
|
@ -8,7 +8,6 @@ package taskrunner
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
@ -118,7 +117,7 @@ func TestSIDSHook_writeToken(t *testing.T) {
|
|||
err := h.writeToken(secrets, id)
|
||||
r.NoError(err)
|
||||
|
||||
content, err := ioutil.ReadFile(filepath.Join(secrets, sidsTokenFile))
|
||||
content, err := os.ReadFile(filepath.Join(secrets, sidsTokenFile))
|
||||
r.NoError(err)
|
||||
r.Equal(id, string(content))
|
||||
}
|
||||
|
@ -273,7 +272,7 @@ func TestTaskRunner_DeriveSIToken_UnWritableTokenFile(t *testing.T) {
|
|||
// successful token derivation
|
||||
secrets := t.TempDir()
|
||||
trConfig.TaskDir.SecretsDir = secrets
|
||||
err := ioutil.WriteFile(filepath.Join(secrets, sidsTokenFile), nil, 0400)
|
||||
err := os.WriteFile(filepath.Join(secrets, sidsTokenFile), nil, 0400)
|
||||
r.NoError(err)
|
||||
|
||||
// set a consul token for the nomad client, which is what triggers the
|
||||
|
@ -306,7 +305,7 @@ func TestTaskRunner_DeriveSIToken_UnWritableTokenFile(t *testing.T) {
|
|||
|
||||
// assert the token is *not* on disk, as secrets dir was un-writable
|
||||
tokenPath := filepath.Join(trConfig.TaskDir.SecretsDir, sidsTokenFile)
|
||||
token, err := ioutil.ReadFile(tokenPath)
|
||||
token, err := os.ReadFile(tokenPath)
|
||||
r.NoError(err)
|
||||
r.Empty(token)
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
|
@ -743,7 +742,7 @@ func TestTaskRunner_TaskEnv_None(t *testing.T) {
|
|||
|
||||
// Read stdout
|
||||
p := filepath.Join(conf.TaskDir.LogDir, task.Name+".stdout.0")
|
||||
stdout, err := ioutil.ReadFile(p)
|
||||
stdout, err := os.ReadFile(p)
|
||||
require.NoError(err)
|
||||
require.Equalf(exp, string(stdout), "expected: %s\n\nactual: %s\n", exp, stdout)
|
||||
}
|
||||
|
@ -1161,7 +1160,7 @@ func TestTaskRunner_Dispatch_Payload(t *testing.T) {
|
|||
|
||||
// Check that the file was written to disk properly
|
||||
payloadPath := filepath.Join(tr.taskDir.LocalDir, fileName)
|
||||
data, err := ioutil.ReadFile(payloadPath)
|
||||
data, err := os.ReadFile(payloadPath)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expected, data)
|
||||
}
|
||||
|
@ -1417,7 +1416,7 @@ func TestTaskRunner_BlockForSIDSToken(t *testing.T) {
|
|||
|
||||
// assert the token is on disk
|
||||
tokenPath := filepath.Join(trConfig.TaskDir.SecretsDir, sidsTokenFile)
|
||||
data, err := ioutil.ReadFile(tokenPath)
|
||||
data, err := os.ReadFile(tokenPath)
|
||||
r.NoError(err)
|
||||
r.Equal(token, string(data))
|
||||
}
|
||||
|
@ -1470,7 +1469,7 @@ func TestTaskRunner_DeriveSIToken_Retry(t *testing.T) {
|
|||
|
||||
// assert the token is on disk
|
||||
tokenPath := filepath.Join(trConfig.TaskDir.SecretsDir, sidsTokenFile)
|
||||
data, err := ioutil.ReadFile(tokenPath)
|
||||
data, err := os.ReadFile(tokenPath)
|
||||
r.NoError(err)
|
||||
r.Equal(token, string(data))
|
||||
}
|
||||
|
@ -1586,7 +1585,7 @@ func TestTaskRunner_BlockForVaultToken(t *testing.T) {
|
|||
|
||||
// Check that the token is on disk
|
||||
tokenPath := filepath.Join(conf.TaskDir.SecretsDir, vaultTokenFile)
|
||||
data, err := ioutil.ReadFile(tokenPath)
|
||||
data, err := os.ReadFile(tokenPath)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, token, string(data))
|
||||
|
||||
|
@ -1663,7 +1662,7 @@ func TestTaskRunner_DeriveToken_Retry(t *testing.T) {
|
|||
|
||||
// Check that the token is on disk
|
||||
tokenPath := filepath.Join(conf.TaskDir.SecretsDir, vaultTokenFile)
|
||||
data, err := ioutil.ReadFile(tokenPath)
|
||||
data, err := os.ReadFile(tokenPath)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, token, string(data))
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package taskrunner
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
@ -130,7 +129,7 @@ func (h *vaultHook) Prestart(ctx context.Context, req *interfaces.TaskPrestartRe
|
|||
// directory
|
||||
recoveredToken := ""
|
||||
h.tokenPath = filepath.Join(req.TaskDir.SecretsDir, vaultTokenFile)
|
||||
data, err := ioutil.ReadFile(h.tokenPath)
|
||||
data, err := os.ReadFile(h.tokenPath)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return fmt.Errorf("failed to recover vault token: %v", err)
|
||||
|
@ -343,7 +342,7 @@ func (h *vaultHook) deriveVaultToken() (token string, exit bool) {
|
|||
|
||||
// writeToken writes the given token to disk
|
||||
func (h *vaultHook) writeToken(token string) error {
|
||||
if err := ioutil.WriteFile(h.tokenPath, []byte(token), 0666); err != nil {
|
||||
if err := os.WriteFile(h.tokenPath, []byte(token), 0666); err != nil {
|
||||
return fmt.Errorf("failed to write vault token: %v", err)
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
@ -255,7 +255,7 @@ func TestPrevAlloc_StreamAllocDir_Error(t *testing.T) {
|
|||
}
|
||||
|
||||
// Assert streamAllocDir fails
|
||||
err = prevAlloc.streamAllocDir(context.Background(), ioutil.NopCloser(tarBuf), dest)
|
||||
err = prevAlloc.streamAllocDir(context.Background(), io.NopCloser(tarBuf), dest)
|
||||
if err == nil {
|
||||
t.Fatalf("expected an error from streamAllocDir")
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
|
@ -122,7 +121,7 @@ func TestPrevAlloc_StreamAllocDir_Ok(t *testing.T) {
|
|||
|
||||
dir1 := t.TempDir()
|
||||
|
||||
rc := ioutil.NopCloser(buf)
|
||||
rc := io.NopCloser(buf)
|
||||
prevAlloc := &remotePrevAlloc{logger: testlog.HCLogger(t)}
|
||||
if err := prevAlloc.streamAllocDir(context.Background(), rc, dir1); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
|
|
|
@ -3,7 +3,6 @@ package client
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/rpc"
|
||||
"os"
|
||||
|
@ -621,7 +620,7 @@ func (c *Client) init() error {
|
|||
|
||||
} else {
|
||||
// Otherwise make a temp directory to use.
|
||||
p, err := ioutil.TempDir("", "NomadClient")
|
||||
p, err := os.MkdirTemp("", "NomadClient")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed creating temporary directory for the StateDir: %v", err)
|
||||
}
|
||||
|
@ -662,7 +661,7 @@ func (c *Client) init() error {
|
|||
}
|
||||
} else {
|
||||
// Otherwise make a temp directory to use.
|
||||
p, err := ioutil.TempDir("", "NomadClient")
|
||||
p, err := os.MkdirTemp("", "NomadClient")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed creating temporary directory for the AllocDir: %v", err)
|
||||
}
|
||||
|
@ -1414,14 +1413,14 @@ func ensureNodeID(conf *config.Config) (id, secret string, err error) {
|
|||
|
||||
// Attempt to read existing ID
|
||||
idPath := filepath.Join(conf.StateDir, "client-id")
|
||||
idBuf, err := ioutil.ReadFile(idPath)
|
||||
idBuf, err := os.ReadFile(idPath)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
// Attempt to read existing secret ID
|
||||
secretPath := filepath.Join(conf.StateDir, "secret-id")
|
||||
secretBuf, err := ioutil.ReadFile(secretPath)
|
||||
secretBuf, err := os.ReadFile(secretPath)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return "", "", err
|
||||
}
|
||||
|
@ -1433,7 +1432,7 @@ func ensureNodeID(conf *config.Config) (id, secret string, err error) {
|
|||
id = hostID
|
||||
|
||||
// Persist the ID
|
||||
if err := ioutil.WriteFile(idPath, []byte(id), 0700); err != nil {
|
||||
if err := os.WriteFile(idPath, []byte(id), 0700); err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
}
|
||||
|
@ -1445,7 +1444,7 @@ func ensureNodeID(conf *config.Config) (id, secret string, err error) {
|
|||
secret = uuid.Generate()
|
||||
|
||||
// Persist the ID
|
||||
if err := ioutil.WriteFile(secretPath, []byte(secret), 0700); err != nil {
|
||||
if err := os.WriteFile(secretPath, []byte(secret), 0700); err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package config
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -33,7 +32,7 @@ func TestClientConfig(t testing.T) (*Config, func()) {
|
|||
tmpDir = filepath.Clean(tmpDir)
|
||||
|
||||
// Create a tempdir to hold state and alloc subdirs
|
||||
parent, err := ioutil.TempDir(tmpDir, "nomadtest")
|
||||
parent, err := os.MkdirTemp(tmpDir, "nomadtest")
|
||||
if err != nil {
|
||||
t.Fatalf("error creating client dir: %v", err)
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package fingerprint
|
|||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -25,7 +24,7 @@ func TestBridgeFingerprint_detect(t *testing.T) {
|
|||
}
|
||||
|
||||
func writeFile(t *testing.T, prefix, content string) string {
|
||||
f, err := ioutil.TempFile("", "bridge-fp-")
|
||||
f, err := os.CreateTemp("", "bridge-fp-")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = io.Copy(f, strings.NewReader(content))
|
||||
|
|
|
@ -2,9 +2,9 @@ package fingerprint
|
|||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
@ -38,7 +38,7 @@ func fakeConsul(payload string) (*httptest.Server, *config.Config) {
|
|||
}
|
||||
|
||||
func fakeConsulPayload(t *testing.T, filename string) string {
|
||||
b, err := ioutil.ReadFile(filename)
|
||||
b, err := os.ReadFile(filename)
|
||||
require.NoError(t, err)
|
||||
return string(b)
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package fingerprint
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
|
@ -96,7 +96,7 @@ func (f *EnvAzureFingerprint) Get(attribute string, format string) (string, erro
|
|||
return "", err
|
||||
}
|
||||
|
||||
resp, err := ioutil.ReadAll(res.Body)
|
||||
resp, err := io.ReadAll(res.Body)
|
||||
res.Body.Close()
|
||||
if err != nil {
|
||||
f.logger.Error("error reading response body for Azure attribute", "attribute", attribute, "error", err)
|
||||
|
|
|
@ -2,7 +2,7 @@ package fingerprint
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
|
@ -82,7 +82,7 @@ func (f *EnvDigitalOceanFingerprint) Get(attribute string, format string) (strin
|
|||
return "", err
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
body, err := io.ReadAll(res.Body)
|
||||
res.Body.Close()
|
||||
if err != nil {
|
||||
f.logger.Error("failed to read metadata", "attribute", attribute, "error", err, "resp_code", res.StatusCode)
|
||||
|
|
|
@ -3,7 +3,7 @@ package fingerprint
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
|
@ -111,7 +111,7 @@ func (f *EnvGCEFingerprint) Get(attribute string, recursive bool) (string, error
|
|||
return "", err
|
||||
}
|
||||
|
||||
resp, err := ioutil.ReadAll(res.Body)
|
||||
resp, err := io.ReadAll(res.Body)
|
||||
res.Body.Close()
|
||||
if err != nil {
|
||||
f.logger.Error("error reading response body for GCE attribute", "attribute", attribute, "error", err)
|
||||
|
|
|
@ -2,7 +2,7 @@ package fingerprint
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
@ -14,7 +14,7 @@ func (f *NetworkFingerprint) linkSpeedSys(device string) int {
|
|||
path := fmt.Sprintf("/sys/class/net/%s/speed", device)
|
||||
|
||||
// Read contents of the device/speed file
|
||||
content, err := ioutil.ReadFile(path)
|
||||
content, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
f.logger.Debug("unable to read link speed", "path", path, "device", device)
|
||||
return 0
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"net"
|
||||
"os"
|
||||
|
@ -1854,7 +1853,7 @@ func TestFS_logsImpl_NoFollow(t *testing.T) {
|
|||
for i := 0; i < 3; i++ {
|
||||
logFile := fmt.Sprintf("%s.%s.%d", task, logType, i)
|
||||
logFilePath := filepath.Join(logDir, logFile)
|
||||
err := ioutil.WriteFile(logFilePath, expected[i:i+1], 0777)
|
||||
err := os.WriteFile(logFilePath, expected[i:i+1], 0777)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create file: %v", err)
|
||||
}
|
||||
|
@ -1928,7 +1927,7 @@ func TestFS_logsImpl_Follow(t *testing.T) {
|
|||
}
|
||||
writeToFile := func(index int, data []byte) {
|
||||
logFilePath := filePath(index)
|
||||
err := ioutil.WriteFile(logFilePath, data, 0777)
|
||||
err := os.WriteFile(logFilePath, data, 0777)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create file: %v", err)
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ package cgutil
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
@ -224,7 +223,7 @@ func (c *cpusetManagerV1) reconcileCpusets() {
|
|||
}
|
||||
|
||||
// look for reserved cpusets which we don't know about and remove
|
||||
files, err := ioutil.ReadDir(c.reservedCpusetPath())
|
||||
files, err := os.ReadDir(c.reservedCpusetPath())
|
||||
if err != nil {
|
||||
c.logger.Error("failed to list files in reserved cgroup path during reconciliation", "path", c.reservedCpusetPath(), "error", err)
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
package cgutil
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
|
@ -41,7 +41,7 @@ func TestCpusetManager_V1_Init(t *testing.T) {
|
|||
|
||||
require.DirExists(t, filepath.Join(manager.cgroupParentPath, SharedCpusetCgroupName))
|
||||
require.FileExists(t, filepath.Join(manager.cgroupParentPath, SharedCpusetCgroupName, "cpuset.cpus"))
|
||||
sharedCpusRaw, err := ioutil.ReadFile(filepath.Join(manager.cgroupParentPath, SharedCpusetCgroupName, "cpuset.cpus"))
|
||||
sharedCpusRaw, err := os.ReadFile(filepath.Join(manager.cgroupParentPath, SharedCpusetCgroupName, "cpuset.cpus"))
|
||||
require.NoError(t, err)
|
||||
sharedCpus, err := cpuset.Parse(string(sharedCpusRaw))
|
||||
require.NoError(t, err)
|
||||
|
@ -68,7 +68,7 @@ func TestCpusetManager_V1_AddAlloc_single(t *testing.T) {
|
|||
// actual contents of shared group depends on machine core count
|
||||
require.DirExists(t, filepath.Join(manager.cgroupParentPath, SharedCpusetCgroupName))
|
||||
require.FileExists(t, filepath.Join(manager.cgroupParentPath, SharedCpusetCgroupName, "cpuset.cpus"))
|
||||
sharedCpusRaw, err := ioutil.ReadFile(filepath.Join(manager.cgroupParentPath, SharedCpusetCgroupName, "cpuset.cpus"))
|
||||
sharedCpusRaw, err := os.ReadFile(filepath.Join(manager.cgroupParentPath, SharedCpusetCgroupName, "cpuset.cpus"))
|
||||
require.NoError(t, err)
|
||||
sharedCpus, err := cpuset.Parse(string(sharedCpusRaw))
|
||||
require.NoError(t, err)
|
||||
|
@ -77,7 +77,7 @@ func TestCpusetManager_V1_AddAlloc_single(t *testing.T) {
|
|||
|
||||
// check that the 0th core is allocated to reserved cgroup
|
||||
require.DirExists(t, filepath.Join(manager.cgroupParentPath, ReservedCpusetCgroupName))
|
||||
reservedCpusRaw, err := ioutil.ReadFile(filepath.Join(manager.cgroupParentPath, ReservedCpusetCgroupName, "cpuset.cpus"))
|
||||
reservedCpusRaw, err := os.ReadFile(filepath.Join(manager.cgroupParentPath, ReservedCpusetCgroupName, "cpuset.cpus"))
|
||||
require.NoError(t, err)
|
||||
reservedCpus, err := cpuset.Parse(string(reservedCpusRaw))
|
||||
require.NoError(t, err)
|
||||
|
@ -91,7 +91,7 @@ func TestCpusetManager_V1_AddAlloc_single(t *testing.T) {
|
|||
require.True(t, ok)
|
||||
|
||||
require.DirExists(t, taskInfo.CgroupPath)
|
||||
taskCpusRaw, err := ioutil.ReadFile(filepath.Join(taskInfo.CgroupPath, "cpuset.cpus"))
|
||||
taskCpusRaw, err := os.ReadFile(filepath.Join(taskInfo.CgroupPath, "cpuset.cpus"))
|
||||
require.NoError(t, err)
|
||||
taskCpus, err := cpuset.Parse(string(taskCpusRaw))
|
||||
require.NoError(t, err)
|
||||
|
@ -125,14 +125,14 @@ func TestCpusetManager_V1_RemoveAlloc(t *testing.T) {
|
|||
manager.reconcileCpusets()
|
||||
|
||||
// shared cpuset should not include any expected cores
|
||||
sharedCpusRaw, err := ioutil.ReadFile(filepath.Join(manager.cgroupParentPath, SharedCpusetCgroupName, "cpuset.cpus"))
|
||||
sharedCpusRaw, err := os.ReadFile(filepath.Join(manager.cgroupParentPath, SharedCpusetCgroupName, "cpuset.cpus"))
|
||||
require.NoError(t, err)
|
||||
sharedCpus, err := cpuset.Parse(string(sharedCpusRaw))
|
||||
require.NoError(t, err)
|
||||
require.False(t, sharedCpus.ContainsAny(alloc1Cpuset.Union(alloc2Cpuset)))
|
||||
|
||||
// reserved cpuset should equal the expected cpus
|
||||
reservedCpusRaw, err := ioutil.ReadFile(filepath.Join(manager.cgroupParentPath, ReservedCpusetCgroupName, "cpuset.cpus"))
|
||||
reservedCpusRaw, err := os.ReadFile(filepath.Join(manager.cgroupParentPath, ReservedCpusetCgroupName, "cpuset.cpus"))
|
||||
require.NoError(t, err)
|
||||
reservedCpus, err := cpuset.Parse(string(reservedCpusRaw))
|
||||
require.NoError(t, err)
|
||||
|
@ -147,7 +147,7 @@ func TestCpusetManager_V1_RemoveAlloc(t *testing.T) {
|
|||
require.NoDirExists(t, alloc1TaskPath)
|
||||
|
||||
// shared cpuset should now include alloc1's cores
|
||||
sharedCpusRaw, err = ioutil.ReadFile(filepath.Join(manager.cgroupParentPath, SharedCpusetCgroupName, "cpuset.cpus"))
|
||||
sharedCpusRaw, err = os.ReadFile(filepath.Join(manager.cgroupParentPath, SharedCpusetCgroupName, "cpuset.cpus"))
|
||||
require.NoError(t, err)
|
||||
sharedCpus, err = cpuset.Parse(string(sharedCpusRaw))
|
||||
require.NoError(t, err)
|
||||
|
@ -155,7 +155,7 @@ func TestCpusetManager_V1_RemoveAlloc(t *testing.T) {
|
|||
require.True(t, sharedCpus.IsSupersetOf(alloc1Cpuset))
|
||||
|
||||
// reserved cpuset should only include alloc2's cores
|
||||
reservedCpusRaw, err = ioutil.ReadFile(filepath.Join(manager.cgroupParentPath, ReservedCpusetCgroupName, "cpuset.cpus"))
|
||||
reservedCpusRaw, err = os.ReadFile(filepath.Join(manager.cgroupParentPath, ReservedCpusetCgroupName, "cpuset.cpus"))
|
||||
require.NoError(t, err)
|
||||
reservedCpus, err = cpuset.Parse(string(reservedCpusRaw))
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
|
@ -189,7 +188,7 @@ func (f *FileRotator) nextFile() error {
|
|||
|
||||
// lastFile finds out the rotated file with the largest index in a path.
|
||||
func (f *FileRotator) lastFile() error {
|
||||
finfos, err := ioutil.ReadDir(f.path)
|
||||
finfos, err := os.ReadDir(f.path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -275,7 +274,7 @@ func (f *FileRotator) purgeOldFiles() {
|
|||
select {
|
||||
case <-f.purgeCh:
|
||||
var fIndexes []int
|
||||
files, err := ioutil.ReadDir(f.path)
|
||||
files, err := os.ReadDir(f.path)
|
||||
if err != nil {
|
||||
f.logger.Error("error getting directory listing", "error", err)
|
||||
return
|
||||
|
|
|
@ -2,7 +2,6 @@ package logging
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -189,7 +188,7 @@ func TestFileRotator_WriteRemaining(t *testing.T) {
|
|||
path := t.TempDir()
|
||||
|
||||
fname1 := filepath.Join(path, "redis.stdout.0")
|
||||
err := ioutil.WriteFile(fname1, []byte("abcd"), 0600)
|
||||
err := os.WriteFile(fname1, []byte("abcd"), 0600)
|
||||
require.NoError(t, err)
|
||||
|
||||
fr, err := NewFileRotator(path, baseFileName, 10, 5, testlog.HCLogger(t))
|
||||
|
@ -258,7 +257,7 @@ func TestFileRotator_PurgeOldFiles(t *testing.T) {
|
|||
require.Equal(t, len(str), nw)
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
f, err := ioutil.ReadDir(path)
|
||||
f, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to read dir %v: %w", path, err)
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package logmon
|
|||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
@ -122,7 +121,7 @@ func TestLogmon_Start_restart_flusheslogs(t *testing.T) {
|
|||
require.NoError(err)
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
raw, err := ioutil.ReadFile(filepath.Join(dir, "stdout.0"))
|
||||
raw, err := os.ReadFile(filepath.Join(dir, "stdout.0"))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -151,7 +150,7 @@ func TestLogmon_Start_restart_flusheslogs(t *testing.T) {
|
|||
require.NoError(err)
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
raw, err := ioutil.ReadFile(filepath.Join(dir, "stdout.0"))
|
||||
raw, err := os.ReadFile(filepath.Join(dir, "stdout.0"))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -171,7 +170,7 @@ func TestLogmon_Start_restart_flusheslogs(t *testing.T) {
|
|||
_, err = stdout.Write([]byte("st\n"))
|
||||
require.NoError(err)
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
raw, err := ioutil.ReadFile(filepath.Join(dir, "stdout.0"))
|
||||
raw, err := os.ReadFile(filepath.Join(dir, "stdout.0"))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -228,7 +227,7 @@ func TestLogmon_Start_restart(t *testing.T) {
|
|||
require.NoError(err)
|
||||
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
raw, err := ioutil.ReadFile(filepath.Join(dir, "stdout.0"))
|
||||
raw, err := os.ReadFile(filepath.Join(dir, "stdout.0"))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -266,7 +265,7 @@ func TestLogmon_Start_restart(t *testing.T) {
|
|||
_, err = stdout.Write([]byte("test\n"))
|
||||
require.NoError(err)
|
||||
testutil.WaitForResult(func() (bool, error) {
|
||||
raw, err := ioutil.ReadFile(filepath.Join(dir, "stdout.0"))
|
||||
raw, err := os.ReadFile(filepath.Join(dir, "stdout.0"))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue