Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: address io/ioutil depreciation #361

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions builder/vsphere/clone/step_customize.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ package clone
import (
"context"
"fmt"
"io/ioutil"
"net"
"os"

"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
Expand Down Expand Up @@ -193,7 +193,7 @@ func (s *StepCustomize) identitySettings() (types.BaseCustomizationIdentitySetti
}

if s.Config.WindowsSysPrepFile != "" {
sysPrep, err := ioutil.ReadFile(s.Config.WindowsSysPrepFile)
sysPrep, err := os.ReadFile(s.Config.WindowsSysPrepFile)
if err != nil {
return nil, fmt.Errorf("error on reading %s: %s", s.Config.WindowsSysPrepFile, err)
}
Expand Down
3 changes: 1 addition & 2 deletions builder/vsphere/common/step_ssh_key_pair.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package common
import (
"context"
"fmt"
"io/ioutil"
"os"

"github.com/hashicorp/packer-plugin-sdk/communicator"
Expand Down Expand Up @@ -98,7 +97,7 @@ func (s *StepSshKeyPair) Run(ctx context.Context, state multistep.StateBag) mult
if s.Debug {
ui.Message(fmt.Sprintf("Saving communicator private key for debug purposes: %s", s.DebugKeyPath))
// Write the key out
if err := ioutil.WriteFile(s.DebugKeyPath, kp.PrivateKeyPemBlock, 0600); err != nil {
if err := os.WriteFile(s.DebugKeyPath, kp.PrivateKeyPemBlock, 0600); err != nil {
state.Put("error", fmt.Errorf("Error saving debug key: %s", err))
return multistep.ActionHalt
}
Expand Down
6 changes: 3 additions & 3 deletions builder/vsphere/driver/datastore_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package driver

import (
"fmt"
"io/ioutil"
"os"
"testing"
"time"
)
Expand All @@ -32,7 +32,7 @@ func TestFileUpload(t *testing.T) {
hostName := "esxi-1.vsphere65.test"

fileName := fmt.Sprintf("test-%v", time.Now().Unix())
tmpFile, err := ioutil.TempFile("", fileName)
tmpFile, err := os.CreateTemp("", fileName)
if err != nil {
t.Fatalf("Error creating temp file")
}
Expand Down Expand Up @@ -68,7 +68,7 @@ func TestFileUploadDRS(t *testing.T) {
hostName := ""

fileName := fmt.Sprintf("test-%v", time.Now().Unix())
tmpFile, err := ioutil.TempFile("", fileName)
tmpFile, err := os.CreateTemp("", fileName)
if err != nil {
t.Fatalf("Error creating temp file")
}
Expand Down
3 changes: 1 addition & 2 deletions builder/vsphere/iso/builder_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package iso

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"testing"
Expand Down Expand Up @@ -484,7 +483,7 @@ func checkNetworkCard(name string) error {
}

func TestAccISOBuilderAcc_createFloppy(t *testing.T) {
tmpFile, err := ioutil.TempFile("", "packer-vsphere-iso-test")
tmpFile, err := os.CreateTemp("", "packer-vsphere-iso-test")
if err != nil {
t.Fatalf("Error creating temp file: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions builder/vsphere/iso/step_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package iso
import (
"context"
"errors"
"io/ioutil"
"io"
"path"
"strings"
"testing"
Expand Down Expand Up @@ -312,7 +312,7 @@ func TestStepCreateVM_Cleanup(t *testing.T) {
errorBuffer := &strings.Builder{}
ui := &packersdk.BasicUi{
Reader: strings.NewReader(""),
Writer: ioutil.Discard,
Writer: io.Discard,
ErrorWriter: errorBuffer,
}
state.Put("ui", ui)
Expand Down
4 changes: 2 additions & 2 deletions builder/vsphere/supervisor/step_create_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package supervisor
import (
"context"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/hashicorp/packer-plugin-sdk/communicator"
Expand Down Expand Up @@ -247,7 +247,7 @@ func (s *StepCreateSource) createVMMetadataSecret(ctx context.Context, logger *P
func (s *StepCreateSource) getBootstrapStringData(ctx context.Context, logger *PackerLogger) (map[string]string, error) {
if s.Config.BootstrapDataFile != "" {
logger.Info("Loading bootstrap data from file: %s", s.Config.BootstrapDataFile)
content, err := ioutil.ReadFile(s.Config.BootstrapDataFile)
content, err := os.ReadFile(s.Config.BootstrapDataFile)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions builder/vsphere/supervisor/step_create_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"os"
"reflect"
"strings"
Expand Down Expand Up @@ -249,7 +248,7 @@ func TestCreateSource_RunCustomBootstrap(t *testing.T) {
defer os.Remove(testDataFile.Name())
defer testDataFile.Close()
testBootstrapData := []byte("unattend: test-unattend-config")
if err := ioutil.WriteFile(testDataFile.Name(), testBootstrapData, 0666); err != nil {
if err := os.WriteFile(testDataFile.Name(), testBootstrapData, 0666); err != nil {
t.Fatalf("Failed to write content to temp file: %v", err)
}
step.Config.BootstrapDataFile = testDataFile.Name()
Expand Down
Loading