From 3226561cf3960d76aa633daf134dbfc3ec9e7fa6 Mon Sep 17 00:00:00 2001 From: Ashley Cui Date: Thu, 21 Apr 2022 09:09:49 -0400 Subject: Allow changing of CPUs, Memory, and Disk Size Allow podman machine set to change CPUs, Memory and Disk size of a QEMU machine after its been created. Disk size can only be increased. If one setting fails to be changed, the other settings will still be applied. Signed-off-by: Ashley Cui --- pkg/machine/config.go | 7 +- pkg/machine/e2e/config_set.go | 43 ++++++++++++ pkg/machine/e2e/set_test.go | 139 +++++++++++++++++++++++++++++++++++++++ pkg/machine/qemu/machine.go | 138 +++++++++++++++++++++++++++----------- pkg/machine/qemu/machine_test.go | 17 +++++ pkg/machine/wsl/machine.go | 57 +++++++++++----- 6 files changed, 346 insertions(+), 55 deletions(-) create mode 100644 pkg/machine/e2e/config_set.go create mode 100644 pkg/machine/e2e/set_test.go create mode 100644 pkg/machine/qemu/machine_test.go (limited to 'pkg/machine') diff --git a/pkg/machine/config.go b/pkg/machine/config.go index 5bbaf8c51..833f9cba8 100644 --- a/pkg/machine/config.go +++ b/pkg/machine/config.go @@ -95,7 +95,10 @@ type ListResponse struct { } type SetOptions struct { - Rootful bool + CPUs *uint64 + DiskSize *uint64 + Memory *uint64 + Rootful *bool } type SSHOptions struct { @@ -118,7 +121,7 @@ type InspectOptions struct{} type VM interface { Init(opts InitOptions) (bool, error) Remove(name string, opts RemoveOptions) (string, func() error, error) - Set(name string, opts SetOptions) error + Set(name string, opts SetOptions) ([]error, error) SSH(name string, opts SSHOptions) error Start(name string, opts StartOptions) error State(bypass bool) (Status, error) diff --git a/pkg/machine/e2e/config_set.go b/pkg/machine/e2e/config_set.go new file mode 100644 index 000000000..b310ab1b9 --- /dev/null +++ b/pkg/machine/e2e/config_set.go @@ -0,0 +1,43 @@ +package e2e + +import ( + "strconv" +) + +type setMachine struct { + cpus *uint + diskSize *uint + memory *uint + + cmd []string +} + +func (i *setMachine) buildCmd(m *machineTestBuilder) []string { + cmd := []string{"machine", "set"} + if i.cpus != nil { + cmd = append(cmd, "--cpus", strconv.Itoa(int(*i.cpus))) + } + if i.diskSize != nil { + cmd = append(cmd, "--disk-size", strconv.Itoa(int(*i.diskSize))) + } + if i.memory != nil { + cmd = append(cmd, "--memory", strconv.Itoa(int(*i.memory))) + } + cmd = append(cmd, m.name) + i.cmd = cmd + return cmd +} + +func (i *setMachine) withCPUs(num uint) *setMachine { + i.cpus = &num + return i +} +func (i *setMachine) withDiskSize(size uint) *setMachine { + i.diskSize = &size + return i +} + +func (i *setMachine) withMemory(num uint) *setMachine { + i.memory = &num + return i +} diff --git a/pkg/machine/e2e/set_test.go b/pkg/machine/e2e/set_test.go new file mode 100644 index 000000000..4b95bde8e --- /dev/null +++ b/pkg/machine/e2e/set_test.go @@ -0,0 +1,139 @@ +package e2e + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +var _ = Describe("podman machine set", func() { + var ( + mb *machineTestBuilder + testDir string + ) + + BeforeEach(func() { + testDir, mb = setup() + }) + AfterEach(func() { + teardown(originalHomeDir, testDir, mb) + }) + + It("set machine cpus", func() { + name := randomString(12) + i := new(initMachine) + session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run() + Expect(err).To(BeNil()) + Expect(session.ExitCode()).To(Equal(0)) + + set := setMachine{} + setSession, err := mb.setName(name).setCmd(set.withCPUs(2)).run() + Expect(err).To(BeNil()) + Expect(setSession.ExitCode()).To(Equal(0)) + + s := new(startMachine) + startSession, err := mb.setCmd(s).run() + Expect(err).To(BeNil()) + Expect(startSession.ExitCode()).To(Equal(0)) + + ssh2 := sshMachine{} + sshSession2, err := mb.setName(name).setCmd(ssh2.withSSHComand([]string{"lscpu", "|", "grep", "\"CPU(s):\"", "|", "head", "-1"})).run() + Expect(err).To(BeNil()) + Expect(sshSession2.ExitCode()).To(Equal(0)) + Expect(sshSession2.outputToString()).To(ContainSubstring("2")) + + }) + + It("increase machine disk size", func() { + name := randomString(12) + i := new(initMachine) + session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run() + Expect(err).To(BeNil()) + Expect(session.ExitCode()).To(Equal(0)) + + set := setMachine{} + setSession, err := mb.setName(name).setCmd(set.withDiskSize(102)).run() + Expect(err).To(BeNil()) + Expect(setSession.ExitCode()).To(Equal(0)) + + s := new(startMachine) + startSession, err := mb.setCmd(s).run() + Expect(err).To(BeNil()) + Expect(startSession.ExitCode()).To(Equal(0)) + + ssh2 := sshMachine{} + sshSession2, err := mb.setName(name).setCmd(ssh2.withSSHComand([]string{"sudo", "fdisk", "-l", "|", "grep", "Disk"})).run() + Expect(err).To(BeNil()) + Expect(sshSession2.ExitCode()).To(Equal(0)) + Expect(sshSession2.outputToString()).To(ContainSubstring("102 GiB")) + }) + + It("decrease machine disk size should fail", func() { + name := randomString(12) + i := new(initMachine) + session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run() + Expect(err).To(BeNil()) + Expect(session.ExitCode()).To(Equal(0)) + + set := setMachine{} + setSession, _ := mb.setName(name).setCmd(set.withDiskSize(50)).run() + // TODO seems like stderr is not being returned; re-enabled when fixed + // Expect(err).To(BeNil()) + Expect(setSession.ExitCode()).To(Not(Equal(0))) + }) + + It("set machine ram", func() { + + name := randomString(12) + i := new(initMachine) + session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run() + Expect(err).To(BeNil()) + Expect(session.ExitCode()).To(Equal(0)) + + set := setMachine{} + setSession, err := mb.setName(name).setCmd(set.withMemory(4000)).run() + Expect(err).To(BeNil()) + Expect(setSession.ExitCode()).To(Equal(0)) + + s := new(startMachine) + startSession, err := mb.setCmd(s).run() + Expect(err).To(BeNil()) + Expect(startSession.ExitCode()).To(Equal(0)) + + ssh2 := sshMachine{} + sshSession2, err := mb.setName(name).setCmd(ssh2.withSSHComand([]string{"cat", "/proc/meminfo", "|", "numfmt", "--field", "2", "--from-unit=Ki", "--to-unit=Mi", "|", "sed", "'s/ kB/M/g'", "|", "grep", "MemTotal"})).run() + Expect(err).To(BeNil()) + Expect(sshSession2.ExitCode()).To(Equal(0)) + Expect(sshSession2.outputToString()).To(ContainSubstring("3824")) + }) + + It("no settings should change if no flags", func() { + name := randomString(12) + i := new(initMachine) + session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run() + Expect(err).To(BeNil()) + Expect(session.ExitCode()).To(Equal(0)) + + set := setMachine{} + setSession, err := mb.setName(name).setCmd(&set).run() + Expect(err).To(BeNil()) + Expect(setSession.ExitCode()).To(Equal(0)) + + s := new(startMachine) + startSession, err := mb.setCmd(s).run() + Expect(err).To(BeNil()) + Expect(startSession.ExitCode()).To(Equal(0)) + + ssh2 := sshMachine{} + sshSession2, err := mb.setName(name).setCmd(ssh2.withSSHComand([]string{"lscpu", "|", "grep", "\"CPU(s):\"", "|", "head", "-1"})).run() + Expect(err).To(BeNil()) + Expect(sshSession2.ExitCode()).To(Equal(0)) + Expect(sshSession2.outputToString()).To(ContainSubstring("1")) + + ssh3 := sshMachine{} + sshSession3, err := mb.setName(name).setCmd(ssh3.withSSHComand([]string{"sudo", "fdisk", "-l", "|", "grep", "Disk"})).run() + Expect(err).To(BeNil()) + Expect(sshSession3.ExitCode()).To(Equal(0)) + Expect(sshSession3.outputToString()).To(ContainSubstring("100 GiB")) + }) + +}) diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go index 5481bad29..091c9f8d1 100644 --- a/pkg/machine/qemu/machine.go +++ b/pkg/machine/qemu/machine.go @@ -390,25 +390,9 @@ func (v *MachineVM) Init(opts machine.InitOptions) (bool, error) { if err != nil { return false, err } - // Resize the disk image to input disk size - // only if the virtualdisk size is less than - // the given disk size - if opts.DiskSize<<(10*3) > originalDiskSize { - // Find the qemu executable - cfg, err := config.Default() - if err != nil { - return false, err - } - resizePath, err := cfg.FindHelperBinary("qemu-img", true) - if err != nil { - return false, err - } - resize := exec.Command(resizePath, []string{"resize", v.getImageFile(), strconv.Itoa(int(opts.DiskSize)) + "G"}...) - resize.Stdout = os.Stdout - resize.Stderr = os.Stderr - if err := resize.Run(); err != nil { - return false, errors.Errorf("resizing image: %q", err) - } + + if err := v.resizeDisk(opts.DiskSize, originalDiskSize>>(10*3)); err != nil { + return false, err } // If the user provides an ignition file, we need to // copy it into the conf dir @@ -432,14 +416,14 @@ func (v *MachineVM) Init(opts machine.InitOptions) (bool, error) { return err == nil, err } -func (v *MachineVM) Set(_ string, opts machine.SetOptions) error { - if v.Rootful == opts.Rootful { - return nil - } +func (v *MachineVM) Set(_ string, opts machine.SetOptions) ([]error, error) { + // If one setting fails to be applied, the others settings will not fail and still be applied. + // The setting(s) that failed to be applied will have its errors returned in setErrors + var setErrors []error state, err := v.State(false) if err != nil { - return err + return setErrors, err } if state == machine.Running { @@ -447,26 +431,45 @@ func (v *MachineVM) Set(_ string, opts machine.SetOptions) error { if v.Name != machine.DefaultMachineName { suffix = " " + v.Name } - return errors.Errorf("cannot change setting while the vm is running, run 'podman machine stop%s' first", suffix) + return setErrors, errors.Errorf("cannot change settings while the vm is running, run 'podman machine stop%s' first", suffix) } - changeCon, err := machine.AnyConnectionDefault(v.Name, v.Name+"-root") - if err != nil { - return err + if opts.Rootful != nil && v.Rootful != *opts.Rootful { + if err := v.setRootful(*opts.Rootful); err != nil { + setErrors = append(setErrors, errors.Wrapf(err, "failed to set rootful option")) + } else { + v.Rootful = *opts.Rootful + } } - if changeCon { - newDefault := v.Name - if opts.Rootful { - newDefault += "-root" - } - if err := machine.ChangeDefault(newDefault); err != nil { - return err + if opts.CPUs != nil && v.CPUs != *opts.CPUs { + v.CPUs = *opts.CPUs + v.editCmdLine("-smp", strconv.Itoa(int(v.CPUs))) + } + + if opts.Memory != nil && v.Memory != *opts.Memory { + v.Memory = *opts.Memory + v.editCmdLine("-m", strconv.Itoa(int(v.Memory))) + } + + if opts.DiskSize != nil && v.DiskSize != *opts.DiskSize { + if err := v.resizeDisk(*opts.DiskSize, v.DiskSize); err != nil { + setErrors = append(setErrors, errors.Wrapf(err, "failed to resize disk")) + } else { + v.DiskSize = *opts.DiskSize } } - v.Rootful = opts.Rootful - return v.writeConfig() + err = v.writeConfig() + if err != nil { + setErrors = append(setErrors, err) + } + + if len(setErrors) > 0 { + return setErrors, setErrors[0] + } + + return setErrors, nil } // Start executes the qemu command line and forks it @@ -1462,3 +1465,64 @@ func (v *MachineVM) getImageFile() string { func (v *MachineVM) getIgnitionFile() string { return v.IgnitionFilePath.GetPath() } + +//resizeDisk increases the size of the machine's disk in GB. +func (v *MachineVM) resizeDisk(diskSize uint64, oldSize uint64) error { + // Resize the disk image to input disk size + // only if the virtualdisk size is less than + // the given disk size + if diskSize < oldSize { + return errors.Errorf("new disk size must be larger than current disk size: %vGB", oldSize) + } + + // Find the qemu executable + cfg, err := config.Default() + if err != nil { + return err + } + resizePath, err := cfg.FindHelperBinary("qemu-img", true) + if err != nil { + return err + } + resize := exec.Command(resizePath, []string{"resize", v.getImageFile(), strconv.Itoa(int(diskSize)) + "G"}...) + resize.Stdout = os.Stdout + resize.Stderr = os.Stderr + if err := resize.Run(); err != nil { + return errors.Errorf("resizing image: %q", err) + } + + return nil +} + +func (v *MachineVM) setRootful(rootful bool) error { + changeCon, err := machine.AnyConnectionDefault(v.Name, v.Name+"-root") + if err != nil { + return err + } + + if changeCon { + newDefault := v.Name + if rootful { + newDefault += "-root" + } + err := machine.ChangeDefault(newDefault) + if err != nil { + return err + } + } + return nil +} + +func (v *MachineVM) editCmdLine(flag string, value string) { + found := false + for i, val := range v.CmdLine { + if val == flag { + found = true + v.CmdLine[i+1] = value + break + } + } + if !found { + v.CmdLine = append(v.CmdLine, []string{flag, value}...) + } +} diff --git a/pkg/machine/qemu/machine_test.go b/pkg/machine/qemu/machine_test.go new file mode 100644 index 000000000..62ca6068a --- /dev/null +++ b/pkg/machine/qemu/machine_test.go @@ -0,0 +1,17 @@ +package qemu + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestEditCmd(t *testing.T) { + vm := new(MachineVM) + vm.CmdLine = []string{"command", "-flag", "value"} + + vm.editCmdLine("-flag", "newvalue") + vm.editCmdLine("-anotherflag", "anothervalue") + + require.Equal(t, vm.CmdLine, []string{"command", "-flag", "newvalue", "-anotherflag", "anothervalue"}) +} diff --git a/pkg/machine/wsl/machine.go b/pkg/machine/wsl/machine.go index f57dbd299..1f1f2dcaf 100644 --- a/pkg/machine/wsl/machine.go +++ b/pkg/machine/wsl/machine.go @@ -736,28 +736,34 @@ func pipeCmdPassThrough(name string, input string, arg ...string) error { return cmd.Run() } -func (v *MachineVM) Set(name string, opts machine.SetOptions) error { - if v.Rootful == opts.Rootful { - return nil +func (v *MachineVM) Set(_ string, opts machine.SetOptions) ([]error, error) { + // If one setting fails to be applied, the others settings will not fail and still be applied. + // The setting(s) that failed to be applied will have its errors returned in setErrors + var setErrors []error + + if opts.Rootful != nil && v.Rootful != *opts.Rootful { + err := v.setRootful(*opts.Rootful) + if err != nil { + setErrors = append(setErrors, errors.Wrapf(err, "error setting rootful option")) + } else { + v.Rootful = *opts.Rootful + } } - changeCon, err := machine.AnyConnectionDefault(v.Name, v.Name+"-root") - if err != nil { - return err + if opts.CPUs != nil { + setErrors = append(setErrors, errors.Errorf("changing CPUs not suppored for WSL machines")) } - if changeCon { - newDefault := v.Name - if opts.Rootful { - newDefault += "-root" - } - if err := machine.ChangeDefault(newDefault); err != nil { - return err - } + if opts.Memory != nil { + setErrors = append(setErrors, errors.Errorf("changing memory not suppored for WSL machines")) + } - v.Rootful = opts.Rootful - return v.writeConfig() + if opts.DiskSize != nil { + setErrors = append(setErrors, errors.Errorf("changing Disk Size not suppored for WSL machines")) + } + + return setErrors, v.writeConfig() } func (v *MachineVM) Start(name string, _ machine.StartOptions) error { @@ -1362,3 +1368,22 @@ func (p *Provider) IsValidVMName(name string) (bool, error) { func (p *Provider) CheckExclusiveActiveVM() (bool, string, error) { return false, "", nil } + +func (v *MachineVM) setRootful(rootful bool) error { + changeCon, err := machine.AnyConnectionDefault(v.Name, v.Name+"-root") + if err != nil { + return err + } + + if changeCon { + newDefault := v.Name + if rootful { + newDefault += "-root" + } + err := machine.ChangeDefault(newDefault) + if err != nil { + return err + } + } + return nil +} -- cgit v1.2.3-54-g00ecf From b1089a23bc85759d1ac9319d1816c999980d8231 Mon Sep 17 00:00:00 2001 From: Brent Baude Date: Wed, 27 Apr 2022 15:16:25 -0500 Subject: Produce better test error messages As Ed has pointed out, the form of Expect(session).To(Exit(0)) provides much better error messages. Let's make Ed happy. Signed-off-by: Brent Baude --- pkg/machine/e2e/init_test.go | 6 ++--- pkg/machine/e2e/inspect_test.go | 9 ++++--- pkg/machine/e2e/rm_test.go | 11 ++++---- pkg/machine/e2e/set_test.go | 59 +++++++++++++++++++---------------------- pkg/machine/e2e/ssh_test.go | 11 ++++---- pkg/machine/e2e/start_test.go | 5 ++-- pkg/machine/e2e/stop_test.go | 9 ++++--- pkg/machine/qemu/machine.go | 2 +- 8 files changed, 56 insertions(+), 56 deletions(-) (limited to 'pkg/machine') diff --git a/pkg/machine/e2e/init_test.go b/pkg/machine/e2e/init_test.go index 309d460a9..304122738 100644 --- a/pkg/machine/e2e/init_test.go +++ b/pkg/machine/e2e/init_test.go @@ -28,13 +28,13 @@ var _ = Describe("podman machine init", func() { reallyLongName := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" session, err := mb.setName(reallyLongName).setCmd(&i).run() Expect(err).To(BeNil()) - Expect(session.ExitCode()).To(Equal(125)) + Expect(session).To(Exit(125)) }) It("simple init", func() { i := new(initMachine) session, err := mb.setCmd(i.withImagePath(mb.imagePath)).run() Expect(err).To(BeNil()) - Expect(session.ExitCode()).To(Equal(0)) + Expect(session).To(Exit(0)) inspectBefore, ec, err := mb.toQemuInspectInfo() Expect(err).To(BeNil()) @@ -52,7 +52,7 @@ var _ = Describe("podman machine init", func() { i := initMachine{} session, err := mb.setCmd(i.withImagePath(mb.imagePath)).run() Expect(err).To(BeNil()) - Expect(session.ExitCode()).To(Equal(0)) + Expect(session).To(Exit(0)) inspectBefore, ec, err := mb.toQemuInspectInfo() Expect(ec).To(BeZero()) diff --git a/pkg/machine/e2e/inspect_test.go b/pkg/machine/e2e/inspect_test.go index 30d810b8f..e282dd21d 100644 --- a/pkg/machine/e2e/inspect_test.go +++ b/pkg/machine/e2e/inspect_test.go @@ -7,6 +7,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + . "github.com/onsi/gomega/gexec" ) var _ = Describe("podman machine stop", func() { @@ -27,24 +28,24 @@ var _ = Describe("podman machine stop", func() { reallyLongName := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" session, err := mb.setName(reallyLongName).setCmd(&i).run() Expect(err).To(BeNil()) - Expect(session.ExitCode()).To(Equal(125)) + Expect(session).To(Exit(125)) }) It("inspect two machines", func() { i := new(initMachine) foo1, err := mb.setName("foo1").setCmd(i.withImagePath(mb.imagePath)).run() Expect(err).To(BeNil()) - Expect(foo1.ExitCode()).To(Equal(0)) + Expect(foo1).To(Exit(0)) ii := new(initMachine) foo2, err := mb.setName("foo2").setCmd(ii.withImagePath(mb.imagePath)).run() Expect(err).To(BeNil()) - Expect(foo2.ExitCode()).To(Equal(0)) + Expect(foo2).To(Exit(0)) inspect := new(inspectMachine) inspectSession, err := mb.setName("foo1").setCmd(inspect).run() Expect(err).To(BeNil()) - Expect(inspectSession.ExitCode()).To(Equal(0)) + Expect(inspectSession).To(Exit(0)) type fakeInfos struct { Status string diff --git a/pkg/machine/e2e/rm_test.go b/pkg/machine/e2e/rm_test.go index 011da5dde..43b8c594c 100644 --- a/pkg/machine/e2e/rm_test.go +++ b/pkg/machine/e2e/rm_test.go @@ -3,6 +3,7 @@ package e2e import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + . "github.com/onsi/gomega/gexec" ) var _ = Describe("podman machine rm", func() { @@ -23,14 +24,14 @@ var _ = Describe("podman machine rm", func() { reallyLongName := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" session, err := mb.setName(reallyLongName).setCmd(&i).run() Expect(err).To(BeNil()) - Expect(session.ExitCode()).To(Equal(125)) + Expect(session).To(Exit(125)) }) It("Remove machine", func() { i := new(initMachine) session, err := mb.setCmd(i.withImagePath(mb.imagePath)).run() Expect(err).To(BeNil()) - Expect(session.ExitCode()).To(Equal(0)) + Expect(session).To(Exit(0)) rm := rmMachine{} _, err = mb.setCmd(rm.withForce()).run() Expect(err).To(BeNil()) @@ -46,18 +47,18 @@ var _ = Describe("podman machine rm", func() { i := new(initMachine) session, err := mb.setCmd(i.withImagePath(mb.imagePath).withNow()).run() Expect(err).To(BeNil()) - Expect(session.ExitCode()).To(Equal(0)) + Expect(session).To(Exit(0)) rm := new(rmMachine) // Removing a running machine should fail stop, err := mb.setCmd(rm).run() Expect(err).To(BeNil()) - Expect(stop.ExitCode()).To(Equal(125)) + Expect(stop).To(Exit(125)) // Removing again with force stopAgain, err := mb.setCmd(rm.withForce()).run() Expect(err).To(BeNil()) - Expect(stopAgain.ExitCode()).To(BeZero()) + Expect(stopAgain).To(Exit(0)) // Inspect to be dead sure _, ec, err := mb.toQemuInspectInfo() diff --git a/pkg/machine/e2e/set_test.go b/pkg/machine/e2e/set_test.go index 4b95bde8e..9af29c560 100644 --- a/pkg/machine/e2e/set_test.go +++ b/pkg/machine/e2e/set_test.go @@ -3,6 +3,7 @@ package e2e import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + . "github.com/onsi/gomega/gexec" ) var _ = Describe("podman machine set", func() { @@ -23,24 +24,28 @@ var _ = Describe("podman machine set", func() { i := new(initMachine) session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run() Expect(err).To(BeNil()) - Expect(session.ExitCode()).To(Equal(0)) + Expect(session).To(Exit(0)) set := setMachine{} setSession, err := mb.setName(name).setCmd(set.withCPUs(2)).run() Expect(err).To(BeNil()) - Expect(setSession.ExitCode()).To(Equal(0)) + Expect(setSession).To(Exit(0)) s := new(startMachine) startSession, err := mb.setCmd(s).run() Expect(err).To(BeNil()) - Expect(startSession.ExitCode()).To(Equal(0)) + Expect(startSession).To(Exit(0)) ssh2 := sshMachine{} sshSession2, err := mb.setName(name).setCmd(ssh2.withSSHComand([]string{"lscpu", "|", "grep", "\"CPU(s):\"", "|", "head", "-1"})).run() Expect(err).To(BeNil()) - Expect(sshSession2.ExitCode()).To(Equal(0)) + Expect(sshSession2).To(Exit(0)) Expect(sshSession2.outputToString()).To(ContainSubstring("2")) + // Setting a running machine results in 125 + runner, err := mb.setName(name).setCmd(set.withCPUs(4)).run() + Expect(err).To(BeNil()) + Expect(runner).To(Exit(125)) }) It("increase machine disk size", func() { @@ -48,61 +53,51 @@ var _ = Describe("podman machine set", func() { i := new(initMachine) session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run() Expect(err).To(BeNil()) - Expect(session.ExitCode()).To(Equal(0)) + Expect(session).To(Exit(0)) set := setMachine{} setSession, err := mb.setName(name).setCmd(set.withDiskSize(102)).run() Expect(err).To(BeNil()) - Expect(setSession.ExitCode()).To(Equal(0)) + Expect(setSession).To(Exit(0)) + + // shrinking disk size iss verboten + shrink, err := mb.setName(name).setCmd(set.withDiskSize(5)).run() + Expect(err).To(BeNil()) + Expect(shrink).To(Exit(125)) s := new(startMachine) startSession, err := mb.setCmd(s).run() Expect(err).To(BeNil()) - Expect(startSession.ExitCode()).To(Equal(0)) + Expect(startSession).To(Exit(0)) ssh2 := sshMachine{} sshSession2, err := mb.setName(name).setCmd(ssh2.withSSHComand([]string{"sudo", "fdisk", "-l", "|", "grep", "Disk"})).run() Expect(err).To(BeNil()) - Expect(sshSession2.ExitCode()).To(Equal(0)) + Expect(sshSession2).To(Exit(0)) Expect(sshSession2.outputToString()).To(ContainSubstring("102 GiB")) }) - It("decrease machine disk size should fail", func() { - name := randomString(12) - i := new(initMachine) - session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run() - Expect(err).To(BeNil()) - Expect(session.ExitCode()).To(Equal(0)) - - set := setMachine{} - setSession, _ := mb.setName(name).setCmd(set.withDiskSize(50)).run() - // TODO seems like stderr is not being returned; re-enabled when fixed - // Expect(err).To(BeNil()) - Expect(setSession.ExitCode()).To(Not(Equal(0))) - }) - It("set machine ram", func() { - name := randomString(12) i := new(initMachine) session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run() Expect(err).To(BeNil()) - Expect(session.ExitCode()).To(Equal(0)) + Expect(session).To(Exit(0)) set := setMachine{} setSession, err := mb.setName(name).setCmd(set.withMemory(4000)).run() Expect(err).To(BeNil()) - Expect(setSession.ExitCode()).To(Equal(0)) + Expect(setSession).To(Exit(0)) s := new(startMachine) startSession, err := mb.setCmd(s).run() Expect(err).To(BeNil()) - Expect(startSession.ExitCode()).To(Equal(0)) + Expect(startSession).To(Exit(0)) ssh2 := sshMachine{} sshSession2, err := mb.setName(name).setCmd(ssh2.withSSHComand([]string{"cat", "/proc/meminfo", "|", "numfmt", "--field", "2", "--from-unit=Ki", "--to-unit=Mi", "|", "sed", "'s/ kB/M/g'", "|", "grep", "MemTotal"})).run() Expect(err).To(BeNil()) - Expect(sshSession2.ExitCode()).To(Equal(0)) + Expect(sshSession2).To(Exit(0)) Expect(sshSession2.outputToString()).To(ContainSubstring("3824")) }) @@ -111,28 +106,28 @@ var _ = Describe("podman machine set", func() { i := new(initMachine) session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run() Expect(err).To(BeNil()) - Expect(session.ExitCode()).To(Equal(0)) + Expect(session).To(Exit(0)) set := setMachine{} setSession, err := mb.setName(name).setCmd(&set).run() Expect(err).To(BeNil()) - Expect(setSession.ExitCode()).To(Equal(0)) + Expect(setSession).To(Exit(0)) s := new(startMachine) startSession, err := mb.setCmd(s).run() Expect(err).To(BeNil()) - Expect(startSession.ExitCode()).To(Equal(0)) + Expect(startSession).To(Exit(0)) ssh2 := sshMachine{} sshSession2, err := mb.setName(name).setCmd(ssh2.withSSHComand([]string{"lscpu", "|", "grep", "\"CPU(s):\"", "|", "head", "-1"})).run() Expect(err).To(BeNil()) - Expect(sshSession2.ExitCode()).To(Equal(0)) + Expect(sshSession2).To(Exit(0)) Expect(sshSession2.outputToString()).To(ContainSubstring("1")) ssh3 := sshMachine{} sshSession3, err := mb.setName(name).setCmd(ssh3.withSSHComand([]string{"sudo", "fdisk", "-l", "|", "grep", "Disk"})).run() Expect(err).To(BeNil()) - Expect(sshSession3.ExitCode()).To(Equal(0)) + Expect(sshSession3).To(Exit(0)) Expect(sshSession3.outputToString()).To(ContainSubstring("100 GiB")) }) diff --git a/pkg/machine/e2e/ssh_test.go b/pkg/machine/e2e/ssh_test.go index 90296fa10..155d39a64 100644 --- a/pkg/machine/e2e/ssh_test.go +++ b/pkg/machine/e2e/ssh_test.go @@ -3,6 +3,7 @@ package e2e import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + . "github.com/onsi/gomega/gexec" ) var _ = Describe("podman machine ssh", func() { @@ -23,7 +24,7 @@ var _ = Describe("podman machine ssh", func() { ssh := sshMachine{} session, err := mb.setName(name).setCmd(ssh).run() Expect(err).To(BeNil()) - Expect(session.ExitCode()).To(Equal(125)) + Expect(session).To(Exit(125)) // TODO seems like stderr is not being returned; re-enabled when fixed //Expect(session.outputToString()).To(ContainSubstring("not exist")) }) @@ -33,14 +34,14 @@ var _ = Describe("podman machine ssh", func() { i := new(initMachine) session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run() Expect(err).To(BeNil()) - Expect(session.ExitCode()).To(Equal(0)) + Expect(session).To(Exit(0)) ssh := sshMachine{} sshSession, err := mb.setName(name).setCmd(ssh).run() Expect(err).To(BeNil()) // TODO seems like stderr is not being returned; re-enabled when fixed //Expect(sshSession.outputToString()).To(ContainSubstring("is not running")) - Expect(sshSession.ExitCode()).To(Equal(125)) + Expect(sshSession).To(Exit(125)) }) It("ssh to running machine and check os-type", func() { @@ -48,12 +49,12 @@ var _ = Describe("podman machine ssh", func() { i := new(initMachine) session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath).withNow()).run() Expect(err).To(BeNil()) - Expect(session.ExitCode()).To(Equal(0)) + Expect(session).To(Exit(0)) ssh := sshMachine{} sshSession, err := mb.setName(name).setCmd(ssh.withSSHComand([]string{"cat", "/etc/os-release"})).run() Expect(err).To(BeNil()) - Expect(sshSession.ExitCode()).To(Equal(0)) + Expect(sshSession).To(Exit(0)) Expect(sshSession.outputToString()).To(ContainSubstring("Fedora CoreOS")) }) }) diff --git a/pkg/machine/e2e/start_test.go b/pkg/machine/e2e/start_test.go index 1cda0e8f1..1de66eb9a 100644 --- a/pkg/machine/e2e/start_test.go +++ b/pkg/machine/e2e/start_test.go @@ -4,6 +4,7 @@ import ( "github.com/containers/podman/v4/pkg/machine" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + . "github.com/onsi/gomega/gexec" ) var _ = Describe("podman machine start", func() { @@ -22,11 +23,11 @@ var _ = Describe("podman machine start", func() { i := new(initMachine) session, err := mb.setCmd(i.withImagePath(mb.imagePath)).run() Expect(err).To(BeNil()) - Expect(session.ExitCode()).To(Equal(0)) + Expect(session).To(Exit(0)) s := new(startMachine) startSession, err := mb.setCmd(s).run() Expect(err).To(BeNil()) - Expect(startSession.ExitCode()).To(Equal(0)) + Expect(startSession).To(Exit(0)) info, ec, err := mb.toQemuInspectInfo() Expect(err).To(BeNil()) diff --git a/pkg/machine/e2e/stop_test.go b/pkg/machine/e2e/stop_test.go index 5dee6a345..0c27045a6 100644 --- a/pkg/machine/e2e/stop_test.go +++ b/pkg/machine/e2e/stop_test.go @@ -3,6 +3,7 @@ package e2e import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + . "github.com/onsi/gomega/gexec" ) var _ = Describe("podman machine stop", func() { @@ -23,24 +24,24 @@ var _ = Describe("podman machine stop", func() { reallyLongName := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" session, err := mb.setName(reallyLongName).setCmd(&i).run() Expect(err).To(BeNil()) - Expect(session.ExitCode()).To(Equal(125)) + Expect(session).To(Exit(125)) }) It("Stop running machine", func() { i := new(initMachine) session, err := mb.setCmd(i.withImagePath(mb.imagePath).withNow()).run() Expect(err).To(BeNil()) - Expect(session.ExitCode()).To(Equal(0)) + Expect(session).To(Exit(0)) stop := new(stopMachine) // Removing a running machine should fail stopSession, err := mb.setCmd(stop).run() Expect(err).To(BeNil()) - Expect(stopSession.ExitCode()).To(Equal(0)) + Expect(stopSession).To(Exit(0)) // Stopping it again should not result in an error stopAgain, err := mb.setCmd(stop).run() Expect(err).To(BeNil()) - Expect(stopAgain.ExitCode()).To(BeZero()) + Expect(stopAgain).To(Exit((0))) }) }) diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go index 091c9f8d1..ccfad90f7 100644 --- a/pkg/machine/qemu/machine.go +++ b/pkg/machine/qemu/machine.go @@ -1466,7 +1466,7 @@ func (v *MachineVM) getIgnitionFile() string { return v.IgnitionFilePath.GetPath() } -//resizeDisk increases the size of the machine's disk in GB. +// resizeDisk increases the size of the machine's disk in GB. func (v *MachineVM) resizeDisk(diskSize uint64, oldSize uint64) error { // Resize the disk image to input disk size // only if the virtualdisk size is less than -- cgit v1.2.3-54-g00ecf From 07bc615b491836e88a331f8ab6e2ffdf34bc6905 Mon Sep 17 00:00:00 2001 From: cdoern Date: Tue, 12 Apr 2022 22:21:33 -0400 Subject: podman machine starting test add a test to make sure machines are not running while still starting in order to do this, I added a parameter to `run()` to delineate whether or not the command should block or not. The non blocking run allows for tests to get and use the `machineSession` pointer and check the exit code to see if it has finished. also fix a bug (created by #13996) that before started, the machines would always say "LastUp" and "Created" Less than one second ago Signed-off-by: cdoern --- pkg/machine/e2e/config.go | 16 +++++++++++----- pkg/machine/e2e/list_test.go | 27 +++++++++++++++++++++++++++ pkg/machine/qemu/machine.go | 6 +++--- 3 files changed, 41 insertions(+), 8 deletions(-) (limited to 'pkg/machine') diff --git a/pkg/machine/e2e/config.go b/pkg/machine/e2e/config.go index 7d75ca6bc..c17b840d3 100644 --- a/pkg/machine/e2e/config.go +++ b/pkg/machine/e2e/config.go @@ -131,7 +131,7 @@ func (m *machineTestBuilder) setTimeout(timeout time.Duration) *machineTestBuild func (mb *machineTestBuilder) toQemuInspectInfo() ([]qemuMachineInspectInfo, int, error) { args := []string{"machine", "inspect"} args = append(args, mb.names...) - session, err := runWrapper(mb.podmanBinary, args, defaultTimeout) + session, err := runWrapper(mb.podmanBinary, args, defaultTimeout, true) if err != nil { return nil, -1, err } @@ -140,11 +140,15 @@ func (mb *machineTestBuilder) toQemuInspectInfo() ([]qemuMachineInspectInfo, int return mii, session.ExitCode(), err } +func (m *machineTestBuilder) runWithoutWait() (*machineSession, error) { + return runWrapper(m.podmanBinary, m.cmd, m.timeout, false) +} + func (m *machineTestBuilder) run() (*machineSession, error) { - return runWrapper(m.podmanBinary, m.cmd, m.timeout) + return runWrapper(m.podmanBinary, m.cmd, m.timeout, true) } -func runWrapper(podmanBinary string, cmdArgs []string, timeout time.Duration) (*machineSession, error) { +func runWrapper(podmanBinary string, cmdArgs []string, timeout time.Duration, wait bool) (*machineSession, error) { if len(os.Getenv("DEBUG")) > 0 { cmdArgs = append([]string{"--log-level=debug"}, cmdArgs...) } @@ -156,8 +160,10 @@ func runWrapper(podmanBinary string, cmdArgs []string, timeout time.Duration) (* return nil, err } ms := machineSession{session} - ms.waitWithTimeout(timeout) - fmt.Println("output:", ms.outputToString()) + if wait { + ms.waitWithTimeout(timeout) + fmt.Println("output:", ms.outputToString()) + } return &ms, nil } diff --git a/pkg/machine/e2e/list_test.go b/pkg/machine/e2e/list_test.go index e7a439945..0ce9063f9 100644 --- a/pkg/machine/e2e/list_test.go +++ b/pkg/machine/e2e/list_test.go @@ -70,6 +70,33 @@ var _ = Describe("podman machine list", func() { Expect(util.StringInSlice(name1, listNames)).To(BeTrue()) Expect(util.StringInSlice(name2, listNames)).To(BeTrue()) }) + + It("list machine: check if running while starting", func() { + i := new(initMachine) + session, err := mb.setCmd(i.withImagePath(mb.imagePath)).run() + Expect(err).To(BeNil()) + Expect(session).To(Exit(0)) + s := new(startMachine) + startSession, err := mb.setCmd(s).runWithoutWait() + Expect(err).To(BeNil()) + l := new(listMachine) + for { // needs to be infinite because we need to check if running when inspect returns to avoid race conditions. + listSession, err := mb.setCmd(l).run() + Expect(listSession).To(Exit(0)) + Expect(err).To(BeNil()) + if startSession.ExitCode() == -1 { + Expect(listSession.outputToString()).NotTo(ContainSubstring("Currently running")) + } else { + break + } + } + Expect(startSession).To(Exit(0)) + listSession, err := mb.setCmd(l).run() + Expect(listSession).To(Exit(0)) + Expect(err).To(BeNil()) + Expect(listSession.outputToString()).To(ContainSubstring("Currently running")) + Expect(listSession.outputToString()).NotTo(ContainSubstring("Less than a second ago")) // check to make sure time created is accurate + }) }) func stripAsterisk(sl []string) { diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go index ccfad90f7..30e64e44e 100644 --- a/pkg/machine/qemu/machine.go +++ b/pkg/machine/qemu/machine.go @@ -1066,11 +1066,11 @@ func getVMInfos() ([]*machine.ListResponse, error) { return err } - if !vm.LastUp.IsZero() { + if !vm.LastUp.IsZero() { // this means we have already written a time to the config listEntry.LastUp = vm.LastUp - } else { + } else { // else we just created the machine AKA last up = created time listEntry.LastUp = vm.Created - vm.Created = time.Now() + vm.LastUp = listEntry.LastUp if err := vm.writeConfig(); err != nil { return err } -- cgit v1.2.3-54-g00ecf From a9a70a9491ffdaea40c9b521f6d2afe140226b9f Mon Sep 17 00:00:00 2001 From: Brent Baude Date: Tue, 26 Apr 2022 16:04:57 -0500 Subject: Refactor machine inspect I was asked to refactor machine inspect output to represent more common and basic information. machine inspect now has information that would be appropriate for different machines. [NO NEW TESTS NEEDED] Signed-off-by: Brent Baude --- cmd/podman/machine/inspect.go | 8 +-- pkg/machine/config.go | 134 ++++++++++++++++++++++++++++++++++++- pkg/machine/qemu/config.go | 142 ++++------------------------------------ pkg/machine/qemu/config_test.go | 15 +++-- pkg/machine/qemu/machine.go | 72 ++++++++++++-------- pkg/machine/wsl/machine.go | 6 +- 6 files changed, 203 insertions(+), 174 deletions(-) (limited to 'pkg/machine') diff --git a/cmd/podman/machine/inspect.go b/cmd/podman/machine/inspect.go index 147afe2b4..21e5074b7 100644 --- a/cmd/podman/machine/inspect.go +++ b/cmd/podman/machine/inspect.go @@ -59,16 +59,12 @@ func inspect(cmd *cobra.Command, args []string) error { errs = append(errs, err) continue } - state, err := vm.State(false) + ii, err := vm.Inspect() if err != nil { errs = append(errs, err) continue } - ii := machine.InspectInfo{ - State: state, - VM: vm, - } - vms = append(vms, ii) + vms = append(vms, *ii) } if len(inspectFlag.format) > 0 { // need jhonce to work his template magic diff --git a/pkg/machine/config.go b/pkg/machine/config.go index 833f9cba8..9a0ce757a 100644 --- a/pkg/machine/config.go +++ b/pkg/machine/config.go @@ -4,6 +4,8 @@ package machine import ( + errors2 "errors" + "io/ioutil" "net" "net/url" "os" @@ -12,6 +14,7 @@ import ( "github.com/containers/storage/pkg/homedir" "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) type InitOptions struct { @@ -68,7 +71,7 @@ type Download struct { Artifact string CompressionType string Format string - ImageName string `json:"image_name"` + ImageName string LocalPath string LocalUncompressedFile string Sha256sum string @@ -120,6 +123,7 @@ type InspectOptions struct{} type VM interface { Init(opts InitOptions) (bool, error) + Inspect() (*InspectInfo, error) Remove(name string, opts RemoveOptions) (string, func() error, error) Set(name string, opts SetOptions) ([]error, error) SSH(name string, opts SSHOptions) error @@ -133,8 +137,14 @@ type DistributionDownload interface { Get() *Download } type InspectInfo struct { - State Status - VM + ConfigPath VMFile + Created time.Time + Image ImageConfig + LastUp time.Time + Name string + Resources ResourceConfig + SSHConfig SSHConfig + State Status } func (rc RemoteConnectionType) MakeSSHURL(host, path, port, userName string) url.URL { @@ -186,3 +196,121 @@ func GetConfDir(vmType string) (string, error) { mkdirErr := os.MkdirAll(confDir, 0755) return confDir, mkdirErr } + +// ResourceConfig describes physical attributes of the machine +type ResourceConfig struct { + // CPUs to be assigned to the VM + CPUs uint64 + // Disk size in gigabytes assigned to the vm + DiskSize uint64 + // Memory in megabytes assigned to the vm + Memory uint64 +} + +const maxSocketPathLength int = 103 + +type VMFile struct { + // Path is the fully qualified path to a file + Path string + // Symlink is a shortened version of Path by using + // a symlink + Symlink *string `json:"symlink,omitempty"` +} + +// GetPath returns the working path for a machinefile. it returns +// the symlink unless one does not exist +func (m *VMFile) GetPath() string { + if m.Symlink == nil { + return m.Path + } + return *m.Symlink +} + +// Delete removes the machinefile symlink (if it exists) and +// the actual path +func (m *VMFile) Delete() error { + if m.Symlink != nil { + if err := os.Remove(*m.Symlink); err != nil && !errors2.Is(err, os.ErrNotExist) { + logrus.Errorf("unable to remove symlink %q", *m.Symlink) + } + } + if err := os.Remove(m.Path); err != nil && !errors2.Is(err, os.ErrNotExist) { + return err + } + return nil +} + +// Read the contents of a given file and return in []bytes +func (m *VMFile) Read() ([]byte, error) { + return ioutil.ReadFile(m.GetPath()) +} + +// NewMachineFile is a constructor for VMFile +func NewMachineFile(path string, symlink *string) (*VMFile, error) { + if len(path) < 1 { + return nil, errors2.New("invalid machine file path") + } + if symlink != nil && len(*symlink) < 1 { + return nil, errors2.New("invalid symlink path") + } + mf := VMFile{Path: path} + if symlink != nil && len(path) > maxSocketPathLength { + if err := mf.makeSymlink(symlink); err != nil && !errors2.Is(err, os.ErrExist) { + return nil, err + } + } + return &mf, nil +} + +// makeSymlink for macOS creates a symlink in $HOME/.podman/ +// for a machinefile like a socket +func (m *VMFile) makeSymlink(symlink *string) error { + homedir, err := os.UserHomeDir() + if err != nil { + return err + } + sl := filepath.Join(homedir, ".podman", *symlink) + // make the symlink dir and throw away if it already exists + if err := os.MkdirAll(filepath.Dir(sl), 0700); err != nil && !errors2.Is(err, os.ErrNotExist) { + return err + } + m.Symlink = &sl + return os.Symlink(m.Path, sl) +} + +type Mount struct { + ReadOnly bool + Source string + Tag string + Target string + Type string +} + +// ImageConfig describes the bootable image for the VM +type ImageConfig struct { + // IgnitionFile is the path to the filesystem where the + // ignition file was written (if needs one) + IgnitionFile VMFile `json:"IgnitionFilePath"` + // ImageStream is the update stream for the image + ImageStream string + // ImageFile is the fq path to + ImagePath VMFile `json:"ImagePath"` +} + +// HostUser describes the host user +type HostUser struct { + // Whether this machine should run in a rootful or rootless manner + Rootful bool + // UID is the numerical id of the user that called machine + UID int +} + +// SSHConfig contains remote access information for SSH +type SSHConfig struct { + // IdentityPath is the fq path to the ssh priv key + IdentityPath string + // SSH port for user networking + Port int + // RemoteUsername of the vm user + RemoteUsername string +} diff --git a/pkg/machine/qemu/config.go b/pkg/machine/qemu/config.go index 9473eef6f..56c95e3b3 100644 --- a/pkg/machine/qemu/config.go +++ b/pkg/machine/qemu/config.go @@ -4,13 +4,9 @@ package qemu import ( - "errors" - "io/ioutil" - "os" - "path/filepath" "time" - "github.com/sirupsen/logrus" + "github.com/containers/podman/v4/pkg/machine" ) const ( @@ -23,7 +19,7 @@ const ( Stable string = "stable" // Max length of fully qualified socket path - maxSocketPathLength int = 103 + ) type Provider struct{} @@ -36,7 +32,7 @@ type MachineVMV1 struct { // The command line representation of the qemu command CmdLine []string // Mounts is the list of remote filesystems to mount - Mounts []Mount + Mounts []machine.Mount // IdentityPath is the fq path to the ssh priv key IdentityPath string // IgnitionFilePath is the fq path to the .ign file @@ -65,27 +61,27 @@ type MachineVMV1 struct { type MachineVM struct { // ConfigPath is the path to the configuration file - ConfigPath MachineFile + ConfigPath machine.VMFile // The command line representation of the qemu command CmdLine []string // HostUser contains info about host user - HostUser + machine.HostUser // ImageConfig describes the bootable image - ImageConfig + machine.ImageConfig // Mounts is the list of remote filesystems to mount - Mounts []Mount + Mounts []machine.Mount // Name of VM Name string // PidFilePath is the where the PID file lives - PidFilePath MachineFile + PidFilePath machine.VMFile // QMPMonitor is the qemu monitor object for sending commands QMPMonitor Monitor // ReadySocket tells host when vm is booted - ReadySocket MachineFile + ReadySocket machine.VMFile // ResourceConfig is physical attrs of the VM - ResourceConfig + machine.ResourceConfig // SSHConfig for accessing the remote vm - SSHConfig + machine.SSHConfig // Starting tells us whether the machine is running or if we have just dialed it to start it Starting bool // Created contains the original created time instead of querying the file mod time @@ -94,59 +90,6 @@ type MachineVM struct { LastUp time.Time } -// ImageConfig describes the bootable image for the VM -type ImageConfig struct { - IgnitionFilePath MachineFile - // ImageStream is the update stream for the image - ImageStream string - // ImagePath is the fq path to - ImagePath MachineFile -} - -// HostUser describes the host user -type HostUser struct { - // Whether this machine should run in a rootful or rootless manner - Rootful bool - // UID is the numerical id of the user that called machine - UID int -} - -// SSHConfig contains remote access information for SSH -type SSHConfig struct { - // IdentityPath is the fq path to the ssh priv key - IdentityPath string - // SSH port for user networking - Port int - // RemoteUsername of the vm user - RemoteUsername string -} - -// ResourceConfig describes physical attributes of the machine -type ResourceConfig struct { - // CPUs to be assigned to the VM - CPUs uint64 - // Memory in megabytes assigned to the vm - Memory uint64 - // Disk size in gigabytes assigned to the vm - DiskSize uint64 -} - -type MachineFile struct { - // Path is the fully qualified path to a file - Path string - // Symlink is a shortened version of Path by using - // a symlink - Symlink *string -} - -type Mount struct { - Type string - Tag string - Source string - Target string - ReadOnly bool -} - type Monitorv1 struct { // Address portion of the qmp monitor (/tmp/tmp.sock) Address string @@ -158,7 +101,7 @@ type Monitorv1 struct { type Monitor struct { // Address portion of the qmp monitor (/tmp/tmp.sock) - Address MachineFile + Address machine.VMFile // Network portion of the qmp monitor (unix) Network string // Timeout in seconds for qmp monitor transactions @@ -170,64 +113,3 @@ var ( // qmp monitor interactions. defaultQMPTimeout = 2 * time.Second ) - -// GetPath returns the working path for a machinefile. it returns -// the symlink unless one does not exist -func (m *MachineFile) GetPath() string { - if m.Symlink == nil { - return m.Path - } - return *m.Symlink -} - -// Delete removes the machinefile symlink (if it exists) and -// the actual path -func (m *MachineFile) Delete() error { - if m.Symlink != nil { - if err := os.Remove(*m.Symlink); err != nil && !errors.Is(err, os.ErrNotExist) { - logrus.Errorf("unable to remove symlink %q", *m.Symlink) - } - } - if err := os.Remove(m.Path); err != nil && !errors.Is(err, os.ErrNotExist) { - return err - } - return nil -} - -// Read the contents of a given file and return in []bytes -func (m *MachineFile) Read() ([]byte, error) { - return ioutil.ReadFile(m.GetPath()) -} - -// NewMachineFile is a constructor for MachineFile -func NewMachineFile(path string, symlink *string) (*MachineFile, error) { - if len(path) < 1 { - return nil, errors.New("invalid machine file path") - } - if symlink != nil && len(*symlink) < 1 { - return nil, errors.New("invalid symlink path") - } - mf := MachineFile{Path: path} - if symlink != nil && len(path) > maxSocketPathLength { - if err := mf.makeSymlink(symlink); err != nil && !errors.Is(err, os.ErrExist) { - return nil, err - } - } - return &mf, nil -} - -// makeSymlink for macOS creates a symlink in $HOME/.podman/ -// for a machinefile like a socket -func (m *MachineFile) makeSymlink(symlink *string) error { - homedir, err := os.UserHomeDir() - if err != nil { - return err - } - sl := filepath.Join(homedir, ".podman", *symlink) - // make the symlink dir and throw away if it already exists - if err := os.MkdirAll(filepath.Dir(sl), 0700); err != nil && !errors.Is(err, os.ErrNotExist) { - return err - } - m.Symlink = &sl - return os.Symlink(m.Path, sl) -} diff --git a/pkg/machine/qemu/config_test.go b/pkg/machine/qemu/config_test.go index 264de9ae8..0fbb5b3bf 100644 --- a/pkg/machine/qemu/config_test.go +++ b/pkg/machine/qemu/config_test.go @@ -6,6 +6,7 @@ import ( "reflect" "testing" + "github.com/containers/podman/v4/pkg/machine" "github.com/containers/podman/v4/test/utils" ) @@ -37,7 +38,7 @@ func TestMachineFile_GetPath(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - m := &MachineFile{ + m := &machine.VMFile{ Path: tt.fields.Path, //nolint: scopelint Symlink: tt.fields.Symlink, //nolint: scopelint } @@ -73,7 +74,7 @@ func TestNewMachineFile(t *testing.T) { sym := "my.sock" longSym := filepath.Join(homedir, ".podman", sym) - m := MachineFile{ + m := machine.VMFile{ Path: p, Symlink: nil, } @@ -84,7 +85,7 @@ func TestNewMachineFile(t *testing.T) { tests := []struct { name string args args - want *MachineFile + want *machine.VMFile wantErr bool }{ { @@ -96,7 +97,7 @@ func TestNewMachineFile(t *testing.T) { { name: "Good with short symlink", args: args{p, &sym}, - want: &MachineFile{p, nil}, + want: &machine.VMFile{Path: p}, wantErr: false, }, { @@ -114,14 +115,14 @@ func TestNewMachineFile(t *testing.T) { { name: "Good with long symlink", args: args{longp, &sym}, - want: &MachineFile{longp, &longSym}, + want: &machine.VMFile{Path: longp, Symlink: &longSym}, wantErr: false, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := NewMachineFile(tt.args.path, tt.args.symlink) //nolint: scopelint - if (err != nil) != tt.wantErr { //nolint: scopelint + got, err := machine.NewMachineFile(tt.args.path, tt.args.symlink) //nolint: scopelint + if (err != nil) != tt.wantErr { //nolint: scopelint t.Errorf("NewMachineFile() error = %v, wantErr %v", err, tt.wantErr) //nolint: scopelint return } diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go index 30e64e44e..35eea5fb4 100644 --- a/pkg/machine/qemu/machine.go +++ b/pkg/machine/qemu/machine.go @@ -71,12 +71,12 @@ func (p *Provider) NewMachine(opts machine.InitOptions) (machine.VM, error) { if len(opts.Name) > 0 { vm.Name = opts.Name } - ignitionFile, err := NewMachineFile(filepath.Join(vmConfigDir, vm.Name+".ign"), nil) + ignitionFile, err := machine.NewMachineFile(filepath.Join(vmConfigDir, vm.Name+".ign"), nil) if err != nil { return nil, err } - vm.IgnitionFilePath = *ignitionFile - imagePath, err := NewMachineFile(opts.ImagePath, nil) + vm.IgnitionFile = *ignitionFile + imagePath, err := machine.NewMachineFile(opts.ImagePath, nil) if err != nil { return nil, err } @@ -105,14 +105,13 @@ func (p *Provider) NewMachine(opts machine.InitOptions) (machine.VM, error) { if err != nil { return nil, err } - cmd := []string{execPath} // Add memory cmd = append(cmd, []string{"-m", strconv.Itoa(int(vm.Memory))}...) // Add cpus cmd = append(cmd, []string{"-smp", strconv.Itoa(int(vm.CPUs))}...) // Add ignition file - cmd = append(cmd, []string{"-fw_cfg", "name=opt/com.coreos/config,file=" + vm.IgnitionFilePath.GetPath()}...) + cmd = append(cmd, []string{"-fw_cfg", "name=opt/com.coreos/config,file=" + vm.IgnitionFile.GetPath()}...) // Add qmp socket monitor, err := NewQMPMonitor("unix", vm.Name, defaultQMPTimeout) if err != nil { @@ -158,9 +157,9 @@ func migrateVM(configPath string, config []byte, vm *MachineVM) error { return err } - pidFilePath := MachineFile{Path: pidFile} + pidFilePath := machine.VMFile{Path: pidFile} qmpMonitor := Monitor{ - Address: MachineFile{Path: old.QMPMonitor.Address}, + Address: machine.VMFile{Path: old.QMPMonitor.Address}, Network: old.QMPMonitor.Network, Timeout: old.QMPMonitor.Timeout, } @@ -169,18 +168,18 @@ func migrateVM(configPath string, config []byte, vm *MachineVM) error { return err } virtualSocketPath := filepath.Join(socketPath, "podman", vm.Name+"_ready.sock") - readySocket := MachineFile{Path: virtualSocketPath} + readySocket := machine.VMFile{Path: virtualSocketPath} - vm.HostUser = HostUser{} - vm.ImageConfig = ImageConfig{} - vm.ResourceConfig = ResourceConfig{} - vm.SSHConfig = SSHConfig{} + vm.HostUser = machine.HostUser{} + vm.ImageConfig = machine.ImageConfig{} + vm.ResourceConfig = machine.ResourceConfig{} + vm.SSHConfig = machine.SSHConfig{} - ignitionFilePath, err := NewMachineFile(old.IgnitionFilePath, nil) + ignitionFilePath, err := machine.NewMachineFile(old.IgnitionFilePath, nil) if err != nil { return err } - imagePath, err := NewMachineFile(old.ImagePath, nil) + imagePath, err := machine.NewMachineFile(old.ImagePath, nil) if err != nil { return err } @@ -194,7 +193,7 @@ func migrateVM(configPath string, config []byte, vm *MachineVM) error { vm.CmdLine = old.CmdLine vm.DiskSize = old.DiskSize vm.IdentityPath = old.IdentityPath - vm.IgnitionFilePath = *ignitionFilePath + vm.IgnitionFile = *ignitionFilePath vm.ImagePath = *imagePath vm.ImageStream = old.ImageStream vm.Memory = old.Memory @@ -229,7 +228,7 @@ func migrateVM(configPath string, config []byte, vm *MachineVM) error { // and returns a vm instance func (p *Provider) LoadVMByName(name string) (machine.VM, error) { vm := &MachineVM{Name: name} - vm.HostUser = HostUser{UID: -1} // posix reserves -1, so use it to signify undefined + vm.HostUser = machine.HostUser{UID: -1} // posix reserves -1, so use it to signify undefined if err := vm.update(); err != nil { return nil, err } @@ -270,7 +269,7 @@ func (v *MachineVM) Init(opts machine.InitOptions) (bool, error) { if err != nil { return false, err } - uncompressedFile, err := NewMachineFile(dd.Get().LocalUncompressedFile, nil) + uncompressedFile, err := machine.NewMachineFile(dd.Get().LocalUncompressedFile, nil) if err != nil { return false, err } @@ -286,7 +285,7 @@ func (v *MachineVM) Init(opts machine.InitOptions) (bool, error) { if err != nil { return false, err } - imagePath, err := NewMachineFile(g.Get().LocalUncompressedFile, nil) + imagePath, err := machine.NewMachineFile(g.Get().LocalUncompressedFile, nil) if err != nil { return false, err } @@ -308,7 +307,7 @@ func (v *MachineVM) Init(opts machine.InitOptions) (bool, error) { return false, err } - mounts := []Mount{} + mounts := []machine.Mount{} for i, volume := range opts.Volumes { tag := fmt.Sprintf("vol%d", i) paths := strings.SplitN(volume, ":", 3) @@ -338,7 +337,7 @@ func (v *MachineVM) Init(opts machine.InitOptions) (bool, error) { virtfsOptions += ",readonly" } v.CmdLine = append(v.CmdLine, []string{"-virtfs", virtfsOptions}...) - mounts = append(mounts, Mount{Type: MountType9p, Tag: tag, Source: source, Target: target, ReadOnly: readonly}) + mounts = append(mounts, machine.Mount{Type: MountType9p, Tag: tag, Source: source, Target: target, ReadOnly: readonly}) } } v.Mounts = mounts @@ -809,7 +808,7 @@ func NewQMPMonitor(network, name string, timeout time.Duration) (Monitor, error) if timeout == 0 { timeout = defaultQMPTimeout } - address, err := NewMachineFile(filepath.Join(rtDir, "qmp_"+name+".sock"), nil) + address, err := machine.NewMachineFile(filepath.Join(rtDir, "qmp_"+name+".sock"), nil) if err != nil { return Monitor{}, err } @@ -1238,14 +1237,14 @@ func (v *MachineVM) userGlobalSocketLink() (string, error) { return filepath.Join(filepath.Dir(path), "podman.sock"), err } -func (v *MachineVM) forwardSocketPath() (*MachineFile, error) { +func (v *MachineVM) forwardSocketPath() (*machine.VMFile, error) { sockName := "podman.sock" path, err := machine.GetDataDir(v.Name) if err != nil { logrus.Errorf("Resolving data dir: %s", err.Error()) return nil, err } - return NewMachineFile(filepath.Join(path, sockName), &sockName) + return machine.NewMachineFile(filepath.Join(path, sockName), &sockName) } func (v *MachineVM) setConfigPath() error { @@ -1254,7 +1253,7 @@ func (v *MachineVM) setConfigPath() error { return err } - configPath, err := NewMachineFile(filepath.Join(vmConfigDir, v.Name)+".json", nil) + configPath, err := machine.NewMachineFile(filepath.Join(vmConfigDir, v.Name)+".json", nil) if err != nil { return err } @@ -1268,7 +1267,7 @@ func (v *MachineVM) setReadySocket() error { if err != nil { return err } - virtualSocketPath, err := NewMachineFile(filepath.Join(rtPath, "podman", readySocketName), &readySocketName) + virtualSocketPath, err := machine.NewMachineFile(filepath.Join(rtPath, "podman", readySocketName), &readySocketName) if err != nil { return err } @@ -1286,7 +1285,7 @@ func (v *MachineVM) setPIDSocket() error { } pidFileName := fmt.Sprintf("%s.pid", v.Name) socketDir := filepath.Join(rtPath, "podman") - pidFilePath, err := NewMachineFile(filepath.Join(socketDir, pidFileName), &pidFileName) + pidFilePath, err := machine.NewMachineFile(filepath.Join(socketDir, pidFileName), &pidFileName) if err != nil { return err } @@ -1463,7 +1462,26 @@ func (v *MachineVM) getImageFile() string { // getIgnitionFile wrapper returns the path to the ignition file func (v *MachineVM) getIgnitionFile() string { - return v.IgnitionFilePath.GetPath() + return v.IgnitionFile.GetPath() +} + +// Inspect returns verbose detail about the machine +func (v *MachineVM) Inspect() (*machine.InspectInfo, error) { + state, err := v.State(false) + if err != nil { + return nil, err + } + + return &machine.InspectInfo{ + ConfigPath: v.ConfigPath, + Created: v.Created, + Image: v.ImageConfig, + LastUp: v.LastUp, + Name: v.Name, + Resources: v.ResourceConfig, + SSHConfig: v.SSHConfig, + State: state, + }, nil } // resizeDisk increases the size of the machine's disk in GB. diff --git a/pkg/machine/wsl/machine.go b/pkg/machine/wsl/machine.go index 1f1f2dcaf..addcb7c8a 100644 --- a/pkg/machine/wsl/machine.go +++ b/pkg/machine/wsl/machine.go @@ -155,7 +155,7 @@ type Provider struct{} type MachineVM struct { // IdentityPath is the fq path to the ssh priv key IdentityPath string - // IgnitionFilePath is the fq path to the .ign file + // ImageStream is the version of fcos being used ImageStream string // ImagePath is the fq path to ImagePath string @@ -1387,3 +1387,7 @@ func (v *MachineVM) setRootful(rootful bool) error { } return nil } + +func (v *MachineVM) Inspect() (*machine.InspectInfo, error) { + return nil, define.ErrNotImplemented +} -- cgit v1.2.3-54-g00ecf From fb14171cba46f331fd9b25efed36c25b6b7ebcea Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Wed, 27 Apr 2022 14:28:38 +0200 Subject: enable errcheck linter The errcheck linter makes sure that errors are always check and not ignored by accident. It spotted a lot of unchecked errors, mostly in the tests but also some real problem in the code. Signed-off-by: Paul Holzinger --- .golangci.yml | 3 +-- cmd/podman/pods/create.go | 2 +- cmd/podman/root.go | 4 +++- cmd/podman/secrets/inspect.go | 4 +++- cmd/podman/system/reset.go | 5 +++- libpod/container_copy_linux.go | 12 ++++++++-- libpod/container_internal_linux.go | 16 ++++++++++--- libpod/kube.go | 6 ++++- libpod/networking_linux.go | 2 +- libpod/oci_attach_linux.go | 8 +++++-- libpod/runtime_ctr.go | 4 +++- libpod/util.go | 7 ++++-- pkg/domain/infra/abi/containers.go | 6 ++++- pkg/machine/qemu/config_test.go | 23 +++++++++++------- pkg/machine/qemu/machine.go | 5 ++-- test/e2e/attach_test.go | 2 -- test/e2e/benchmarks_test.go | 1 - test/e2e/build_test.go | 5 +++- test/e2e/checkpoint_image_test.go | 1 - test/e2e/checkpoint_test.go | 2 -- test/e2e/commit_test.go | 2 -- test/e2e/container_clone_test.go | 1 - test/e2e/container_create_volume_test.go | 1 - test/e2e/container_inspect_test.go | 1 - test/e2e/containers_conf_test.go | 1 - test/e2e/cp_test.go | 1 - test/e2e/create_staticip_test.go | 1 - test/e2e/create_staticmac_test.go | 1 - test/e2e/create_test.go | 8 +++---- test/e2e/diff_test.go | 1 - test/e2e/events_test.go | 1 - test/e2e/exec_test.go | 1 - test/e2e/export_test.go | 1 - test/e2e/generate_kube_test.go | 1 - test/e2e/generate_systemd_test.go | 2 +- test/e2e/healthcheck_run_test.go | 3 +-- test/e2e/history_test.go | 1 - test/e2e/image_sign_test.go | 2 -- test/e2e/images_test.go | 1 - test/e2e/import_test.go | 1 - test/e2e/init_test.go | 1 - test/e2e/inspect_test.go | 1 - test/e2e/libpod_suite_remote_test.go | 23 ++++++++++-------- test/e2e/libpod_suite_test.go | 12 ++++------ test/e2e/login_logout_test.go | 21 ++++++++++------ test/e2e/logs_test.go | 3 --- test/e2e/manifest_test.go | 1 - test/e2e/mount_rootless_test.go | 1 - test/e2e/namespace_test.go | 1 - test/e2e/network_create_test.go | 1 - test/e2e/pause_test.go | 1 - test/e2e/play_build_test.go | 1 - test/e2e/play_kube_test.go | 3 +-- test/e2e/pod_create_test.go | 1 - test/e2e/pod_infra_container_test.go | 1 - test/e2e/pod_initcontainers_test.go | 1 - test/e2e/pod_inspect_test.go | 1 - test/e2e/pod_kill_test.go | 1 - test/e2e/pod_pause_test.go | 1 - test/e2e/pod_pod_namespaces_test.go | 1 - test/e2e/pod_prune_test.go | 1 - test/e2e/pod_ps_test.go | 1 - test/e2e/pod_restart_test.go | 1 - test/e2e/pod_rm_test.go | 1 - test/e2e/pod_start_test.go | 1 - test/e2e/pod_stats_test.go | 1 - test/e2e/pod_stop_test.go | 1 - test/e2e/pod_top_test.go | 1 - test/e2e/port_test.go | 1 - test/e2e/prune_test.go | 1 - test/e2e/ps_test.go | 1 - test/e2e/pull_test.go | 15 ++++++++---- test/e2e/push_test.go | 18 +++++++++----- test/e2e/rename_test.go | 1 - test/e2e/restart_test.go | 1 - test/e2e/rm_test.go | 1 - test/e2e/run_aardvark_test.go | 1 - test/e2e/run_apparmor_test.go | 1 - test/e2e/run_cgroup_parent_test.go | 1 - test/e2e/run_cleanup_test.go | 3 ++- test/e2e/run_cpu_test.go | 1 - test/e2e/run_device_test.go | 1 - test/e2e/run_dns_test.go | 1 - test/e2e/run_entrypoint_test.go | 1 - test/e2e/run_env_test.go | 1 - test/e2e/run_exit_test.go | 1 - test/e2e/run_memory_test.go | 1 - test/e2e/run_networking_test.go | 6 ++--- test/e2e/run_ns_test.go | 1 - test/e2e/run_passwd_test.go | 1 - test/e2e/run_privileged_test.go | 1 - test/e2e/run_restart_test.go | 1 - test/e2e/run_seccomp_test.go | 1 - test/e2e/run_security_labels_test.go | 2 -- test/e2e/run_selinux_test.go | 1 - test/e2e/run_signal_test.go | 13 ++++++---- test/e2e/run_staticip_test.go | 1 - test/e2e/run_test.go | 7 +++--- test/e2e/run_userns_test.go | 1 - test/e2e/run_volume_test.go | 34 ++++++++++++++++---------- test/e2e/run_working_dir_test.go | 1 - test/e2e/runlabel_test.go | 1 - test/e2e/save_test.go | 3 ++- test/e2e/search_test.go | 41 ++++++++++++++++++++------------ test/e2e/secret_test.go | 1 - test/e2e/start_test.go | 1 - test/e2e/stats_test.go | 1 - test/e2e/stop_test.go | 1 - test/e2e/system_connection_test.go | 2 +- test/e2e/system_df_test.go | 3 +-- test/e2e/system_dial_stdio_test.go | 3 +-- test/e2e/system_reset_test.go | 3 +-- test/e2e/systemd_activate_test.go | 1 - test/e2e/systemd_test.go | 1 - test/e2e/toolbox_test.go | 1 - test/e2e/top_test.go | 1 - test/e2e/tree_test.go | 2 +- test/e2e/trust_test.go | 4 ++-- test/e2e/unshare_test.go | 1 - test/e2e/version_test.go | 2 +- test/e2e/volume_create_test.go | 1 - test/e2e/volume_exists_test.go | 1 - test/e2e/volume_inspect_test.go | 1 - test/e2e/volume_ls_test.go | 1 - test/e2e/volume_plugin_test.go | 16 ++++++++----- test/e2e/volume_prune_test.go | 1 - test/e2e/volume_rm_test.go | 1 - test/e2e/wait_test.go | 1 - test/utils/common_function_test.go | 6 +++-- test/utils/utils.go | 4 +++- 130 files changed, 234 insertions(+), 230 deletions(-) (limited to 'pkg/machine') diff --git a/.golangci.yml b/.golangci.yml index 1ce18c0c3..7eb6ea57e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -45,7 +45,6 @@ linters: - gocyclo - lll - unconvert - - errcheck - gosec - maligned - gomoddirectives @@ -65,4 +64,4 @@ linters: linters-settings: errcheck: check-blank: false - ignore: encoding/json:^Unmarshal,fmt:.* + ignore: fmt:.* diff --git a/cmd/podman/pods/create.go b/cmd/podman/pods/create.go index 891ff2e3c..4623ade63 100644 --- a/cmd/podman/pods/create.go +++ b/cmd/podman/pods/create.go @@ -214,7 +214,7 @@ func create(cmd *cobra.Command, args []string) error { ret, err := parsers.ParseUintList(copy) copy = "" if err != nil { - errors.Wrapf(err, "could not parse list") + return errors.Wrapf(err, "could not parse list") } var vals []int for ind, val := range ret { diff --git a/cmd/podman/root.go b/cmd/podman/root.go index 9b1aa778b..2bd4fa723 100644 --- a/cmd/podman/root.go +++ b/cmd/podman/root.go @@ -153,7 +153,9 @@ func persistentPreRunE(cmd *cobra.Command, args []string) error { *runtime, ) } - runtimeFlag.Value.Set(*runtime) + if err := runtimeFlag.Value.Set(*runtime); err != nil { + return err + } runtimeFlag.Changed = true logrus.Debugf("Checkpoint was created using '%s'. Restore will use the same runtime", *runtime) } else if cfg.RuntimePath != *runtime { diff --git a/cmd/podman/secrets/inspect.go b/cmd/podman/secrets/inspect.go index e8947e441..473d5620c 100644 --- a/cmd/podman/secrets/inspect.go +++ b/cmd/podman/secrets/inspect.go @@ -61,7 +61,9 @@ func inspect(cmd *cobra.Command, args []string) error { return err } defer w.Flush() - tmpl.Execute(w, inspected) + if err := tmpl.Execute(w, inspected); err != nil { + return err + } } else { buf, err := json.MarshalIndent(inspected, "", " ") if err != nil { diff --git a/cmd/podman/system/reset.go b/cmd/podman/system/reset.go index 03783170f..8f2e73375 100644 --- a/cmd/podman/system/reset.go +++ b/cmd/podman/system/reset.go @@ -81,7 +81,10 @@ func reset(cmd *cobra.Command, args []string) { } // Purge all the external containers with storage - registry.ContainerEngine().ContainerRm(registry.Context(), listCtnIds, entities.RmOptions{Force: true, All: true, Ignore: true, Volumes: true}) + _, err := registry.ContainerEngine().ContainerRm(registry.Context(), listCtnIds, entities.RmOptions{Force: true, All: true, Ignore: true, Volumes: true}) + if err != nil { + logrus.Error(err) + } // Shutdown all running engines, `reset` will hijack repository registry.ContainerEngine().Shutdown(registry.Context()) registry.ImageEngine().Shutdown(registry.Context()) diff --git a/libpod/container_copy_linux.go b/libpod/container_copy_linux.go index 91e712c74..7566fbb12 100644 --- a/libpod/container_copy_linux.go +++ b/libpod/container_copy_linux.go @@ -48,7 +48,11 @@ func (c *Container) copyFromArchive(path string, chown bool, rename map[string]s if err != nil { return nil, err } - unmount = func() { c.unmount(false) } + unmount = func() { + if err := c.unmount(false); err != nil { + logrus.Errorf("Failed to unmount container: %v", err) + } + } } if c.state.State == define.ContainerStateRunning { @@ -117,7 +121,11 @@ func (c *Container) copyToArchive(path string, writer io.Writer) (func() error, if err != nil { return nil, err } - unmount = func() { c.unmount(false) } + unmount = func() { + if err := c.unmount(false); err != nil { + logrus.Errorf("Failed to unmount container: %v", err) + } + } } statInfo, resolvedRoot, resolvedPath, err := c.stat(mountPoint, path) diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go index 31edff762..3c88cc75f 100644 --- a/libpod/container_internal_linux.go +++ b/libpod/container_internal_linux.go @@ -1180,7 +1180,11 @@ func (c *Container) createCheckpointImage(ctx context.Context, options Container return err } // Clean-up buildah working container - defer importBuilder.Delete() + defer func() { + if err := importBuilder.Delete(); err != nil { + logrus.Errorf("Image builder delete failed: %v", err) + } + }() if err := c.prepareCheckpointExport(); err != nil { return err @@ -1201,7 +1205,9 @@ func (c *Container) createCheckpointImage(ctx context.Context, options Container // Copy checkpoint from temporary tar file in the image addAndCopyOptions := buildah.AddAndCopyOptions{} - importBuilder.Add("", true, addAndCopyOptions, options.TargetFile) + if err := importBuilder.Add("", true, addAndCopyOptions, options.TargetFile); err != nil { + return err + } if err := c.addCheckpointImageMetadata(importBuilder); err != nil { return err @@ -1543,7 +1549,11 @@ func (c *Container) importCheckpointImage(ctx context.Context, imageID string) e } mountPoint, err := img.Mount(ctx, nil, "") - defer img.Unmount(true) + defer func() { + if err := c.unmount(true); err != nil { + logrus.Errorf("Failed to unmount container: %v", err) + } + }() if err != nil { return err } diff --git a/libpod/kube.go b/libpod/kube.go index 8b75a0c44..5a5fe9d35 100644 --- a/libpod/kube.go +++ b/libpod/kube.go @@ -1034,7 +1034,11 @@ func generateKubeSecurityContext(c *Container) (*v1.SecurityContext, error) { if err != nil { return nil, errors.Wrapf(err, "failed to mount %s mountpoint", c.ID()) } - defer c.unmount(false) + defer func() { + if err := c.unmount(false); err != nil { + logrus.Errorf("Failed to unmount container: %v", err) + } + }() } logrus.Debugf("Looking in container for user: %s", c.User()) diff --git a/libpod/networking_linux.go b/libpod/networking_linux.go index 2770b040e..0c124cf0b 100644 --- a/libpod/networking_linux.go +++ b/libpod/networking_linux.go @@ -488,7 +488,7 @@ func (r *Runtime) GetRootlessNetNs(new bool) (*RootlessNetNS, error) { pid := strconv.Itoa(cmd.Process.Pid) err = ioutil.WriteFile(filepath.Join(rootlessNetNsDir, rootlessNetNsSilrp4netnsPidFile), []byte(pid), 0700) if err != nil { - errors.Wrap(err, "unable to write rootless-netns slirp4netns pid file") + return nil, errors.Wrap(err, "unable to write rootless-netns slirp4netns pid file") } defer func() { diff --git a/libpod/oci_attach_linux.go b/libpod/oci_attach_linux.go index b5eabec1f..c6af294d5 100644 --- a/libpod/oci_attach_linux.go +++ b/libpod/oci_attach_linux.go @@ -274,11 +274,15 @@ func readStdio(conn *net.UnixConn, streams *define.AttachStreams, receiveStdoutE var err error select { case err = <-receiveStdoutError: - conn.CloseWrite() + if err := conn.CloseWrite(); err != nil { + logrus.Errorf("Failed to close stdin: %v", err) + } return err case err = <-stdinDone: if err == define.ErrDetach { - conn.CloseWrite() + if err := conn.CloseWrite(); err != nil { + logrus.Errorf("Failed to close stdin: %v", err) + } return err } if err == nil { diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index fd3ffd199..df7174ac6 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -513,7 +513,9 @@ func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (_ *Contai case define.NoLogging, define.PassthroughLogging: break case define.JournaldLogging: - ctr.initializeJournal(ctx) + if err := ctr.initializeJournal(ctx); err != nil { + return nil, fmt.Errorf("failed to initialize journal: %w", err) + } default: if ctr.config.LogPath == "" { ctr.config.LogPath = filepath.Join(ctr.config.StaticDir, "ctr.log") diff --git a/libpod/util.go b/libpod/util.go index 51fe60427..1753b4f34 100644 --- a/libpod/util.go +++ b/libpod/util.go @@ -55,8 +55,11 @@ func WaitForFile(path string, chWait chan error, timeout time.Duration) (bool, e if err := watcher.Add(filepath.Dir(path)); err == nil { inotifyEvents = watcher.Events } - defer watcher.Close() - defer watcher.Remove(filepath.Dir(path)) + defer func() { + if err := watcher.Close(); err != nil { + logrus.Errorf("Failed to close fsnotify watcher: %v", err) + } + }() } var timeoutChan <-chan time.Time diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go index b56c36015..89b09bb1d 100644 --- a/pkg/domain/infra/abi/containers.go +++ b/pkg/domain/infra/abi/containers.go @@ -641,7 +641,11 @@ func (ic *ContainerEngine) ContainerRestore(ctx context.Context, namesOrIds []st } restoreOptions.CheckpointImageID = img.ID() mountPoint, err := img.Mount(ctx, nil, "") - defer img.Unmount(true) + defer func() { + if err := img.Unmount(true); err != nil { + logrus.Errorf("Failed to unmount image: %v", err) + } + }() if err != nil { return nil, err } diff --git a/pkg/machine/qemu/config_test.go b/pkg/machine/qemu/config_test.go index 0fbb5b3bf..3f92881fa 100644 --- a/pkg/machine/qemu/config_test.go +++ b/pkg/machine/qemu/config_test.go @@ -68,9 +68,15 @@ func TestNewMachineFile(t *testing.T) { p := "/var/tmp/podman/my.sock" longp := filepath.Join(longTemp, utils.RandomString(100), "my.sock") - os.MkdirAll(filepath.Dir(longp), 0755) - f, _ := os.Create(longp) - f.Close() + err = os.MkdirAll(filepath.Dir(longp), 0755) + if err != nil { + panic(err) + } + f, err := os.Create(longp) + if err != nil { + panic(err) + } + _ = f.Close() sym := "my.sock" longSym := filepath.Join(homedir, ".podman", sym) @@ -120,14 +126,15 @@ func TestNewMachineFile(t *testing.T) { }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { - got, err := machine.NewMachineFile(tt.args.path, tt.args.symlink) //nolint: scopelint - if (err != nil) != tt.wantErr { //nolint: scopelint - t.Errorf("NewMachineFile() error = %v, wantErr %v", err, tt.wantErr) //nolint: scopelint + got, err := machine.NewMachineFile(tt.args.path, tt.args.symlink) + if (err != nil) != tt.wantErr { + t.Errorf("NewMachineFile() error = %v, wantErr %v", err, tt.wantErr) return } - if !reflect.DeepEqual(got, tt.want) { //nolint: scopelint - t.Errorf("NewMachineFile() got = %v, want %v", got, tt.want) //nolint: scopelint + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewMachineFile() got = %v, want %v", got, tt.want) } }) } diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go index 35eea5fb4..91e15c2af 100644 --- a/pkg/machine/qemu/machine.go +++ b/pkg/machine/qemu/machine.go @@ -484,12 +484,11 @@ func (v *MachineVM) Start(name string, _ machine.StartOptions) error { if err := v.writeConfig(); err != nil { return fmt.Errorf("writing JSON file: %w", err) } - defer func() error { + defer func() { v.Starting = false if err := v.writeConfig(); err != nil { - return fmt.Errorf("writing JSON file: %w", err) + logrus.Errorf("Writing JSON file: %v", err) } - return nil }() if v.isIncompatible() { logrus.Errorf("machine %q is incompatible with this release of podman and needs to be recreated, starting for recovery only", v.Name) diff --git a/test/e2e/attach_test.go b/test/e2e/attach_test.go index 74e3a619a..b110f7c5b 100644 --- a/test/e2e/attach_test.go +++ b/test/e2e/attach_test.go @@ -22,8 +22,6 @@ var _ = Describe("Podman attach", func() { Expect(err).To(BeNil()) podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - err = podmanTest.SeedImages() - Expect(err).To(BeNil()) }) AfterEach(func() { diff --git a/test/e2e/benchmarks_test.go b/test/e2e/benchmarks_test.go index 9653cee3b..746dec0a6 100644 --- a/test/e2e/benchmarks_test.go +++ b/test/e2e/benchmarks_test.go @@ -66,7 +66,6 @@ var _ = Describe("Podman Benchmark Suite", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - timedir, err = CreateTempDirInTempDir() if err != nil { os.Exit(1) diff --git a/test/e2e/build_test.go b/test/e2e/build_test.go index b8aad1084..b5cec5fff 100644 --- a/test/e2e/build_test.go +++ b/test/e2e/build_test.go @@ -533,7 +533,10 @@ subdir**` // make cwd as context root path Expect(os.Chdir(contextDir)).ToNot(HaveOccurred()) - defer os.Chdir(cwd) + defer func() { + err := os.Chdir(cwd) + Expect(err).ToNot(HaveOccurred()) + }() By("Test .containerignore filtering subdirectory") err = ioutil.WriteFile(filepath.Join(contextDir, ".containerignore"), []byte(`subdir/`), 0644) diff --git a/test/e2e/checkpoint_image_test.go b/test/e2e/checkpoint_image_test.go index 6c2a000e8..94320a70e 100644 --- a/test/e2e/checkpoint_image_test.go +++ b/test/e2e/checkpoint_image_test.go @@ -28,7 +28,6 @@ var _ = Describe("Podman checkpoint", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() // Check if the runtime implements checkpointing. Currently only // runc's checkpoint/restore implementation is supported. cmd := exec.Command(podmanTest.OCIRuntime, "checkpoint", "--help") diff --git a/test/e2e/checkpoint_test.go b/test/e2e/checkpoint_test.go index ac1677539..787178cd3 100644 --- a/test/e2e/checkpoint_test.go +++ b/test/e2e/checkpoint_test.go @@ -41,8 +41,6 @@ var _ = Describe("Podman checkpoint", func() { podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - err = podmanTest.SeedImages() - Expect(err).To(BeNil()) // Check if the runtime implements checkpointing. Currently only // runc's checkpoint/restore implementation is supported. cmd := exec.Command(podmanTest.OCIRuntime, "checkpoint", "--help") diff --git a/test/e2e/commit_test.go b/test/e2e/commit_test.go index 1de30e423..c82e5e471 100644 --- a/test/e2e/commit_test.go +++ b/test/e2e/commit_test.go @@ -24,8 +24,6 @@ var _ = Describe("Podman commit", func() { Expect(err).To(BeNil()) podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - err = podmanTest.SeedImages() - Expect(err).To(BeNil()) }) AfterEach(func() { diff --git a/test/e2e/container_clone_test.go b/test/e2e/container_clone_test.go index c47a89332..da9b511e0 100644 --- a/test/e2e/container_clone_test.go +++ b/test/e2e/container_clone_test.go @@ -24,7 +24,6 @@ var _ = Describe("Podman container clone", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/container_create_volume_test.go b/test/e2e/container_create_volume_test.go index 015b1742a..6d9f13694 100644 --- a/test/e2e/container_create_volume_test.go +++ b/test/e2e/container_create_volume_test.go @@ -83,7 +83,6 @@ var _ = Describe("Podman create data volume", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/container_inspect_test.go b/test/e2e/container_inspect_test.go index f58f2de29..5aed943da 100644 --- a/test/e2e/container_inspect_test.go +++ b/test/e2e/container_inspect_test.go @@ -25,7 +25,6 @@ var _ = Describe("Podman container inspect", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/containers_conf_test.go b/test/e2e/containers_conf_test.go index 09cd68042..b48e1ed62 100644 --- a/test/e2e/containers_conf_test.go +++ b/test/e2e/containers_conf_test.go @@ -29,7 +29,6 @@ var _ = Describe("Verify podman containers.conf usage", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() os.Setenv("CONTAINERS_CONF", "config/containers.conf") if IsRemote() { podmanTest.RestartRemoteService() diff --git a/test/e2e/cp_test.go b/test/e2e/cp_test.go index ede6036b9..8a65b85d3 100644 --- a/test/e2e/cp_test.go +++ b/test/e2e/cp_test.go @@ -31,7 +31,6 @@ var _ = Describe("Podman cp", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/create_staticip_test.go b/test/e2e/create_staticip_test.go index 4a1d926e0..6fd88753b 100644 --- a/test/e2e/create_staticip_test.go +++ b/test/e2e/create_staticip_test.go @@ -25,7 +25,6 @@ var _ = Describe("Podman create with --ip flag", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() // Cleanup the CNI networks used by the tests os.RemoveAll("/var/lib/cni/networks/podman") }) diff --git a/test/e2e/create_staticmac_test.go b/test/e2e/create_staticmac_test.go index 5fd8e3bd6..f02d9c88b 100644 --- a/test/e2e/create_staticmac_test.go +++ b/test/e2e/create_staticmac_test.go @@ -25,7 +25,6 @@ var _ = Describe("Podman run with --mac-address flag", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() // Cleanup the CNI networks used by the tests os.RemoveAll("/var/lib/cni/networks/podman") }) diff --git a/test/e2e/create_test.go b/test/e2e/create_test.go index d0813459d..63544d579 100644 --- a/test/e2e/create_test.go +++ b/test/e2e/create_test.go @@ -27,8 +27,6 @@ var _ = Describe("Podman create", func() { Expect(err).To(BeNil()) podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - err = podmanTest.SeedImages() - Expect(err).To(BeNil()) }) AfterEach(func() { @@ -176,7 +174,8 @@ var _ = Describe("Podman create", func() { // tests are passing inside a container. mountPath := filepath.Join(podmanTest.TempDir, "secrets") - os.Mkdir(mountPath, 0755) + err := os.Mkdir(mountPath, 0755) + Expect(err).ToNot(HaveOccurred()) session := podmanTest.Podman([]string{"create", "--log-driver", "k8s-file", "--name", "test", "--mount", fmt.Sprintf("type=bind,src=%s,target=/create/test", mountPath), ALPINE, "grep", "/create/test", "/proc/self/mountinfo"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) @@ -212,7 +211,8 @@ var _ = Describe("Podman create", func() { Expect(session.OutputToString()).To(ContainSubstring("shared")) mountPath = filepath.Join(podmanTest.TempDir, "scratchpad") - os.Mkdir(mountPath, 0755) + err = os.Mkdir(mountPath, 0755) + Expect(err).ToNot(HaveOccurred()) session = podmanTest.Podman([]string{"create", "--log-driver", "k8s-file", "--name", "test_tmpfs", "--mount", "type=tmpfs,target=/create/test", ALPINE, "grep", "/create/test", "/proc/self/mountinfo"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) diff --git a/test/e2e/diff_test.go b/test/e2e/diff_test.go index fb6df8f45..a1f57f41b 100644 --- a/test/e2e/diff_test.go +++ b/test/e2e/diff_test.go @@ -26,7 +26,6 @@ var _ = Describe("Podman diff", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/events_test.go b/test/e2e/events_test.go index 1d4560e8e..725118ab0 100644 --- a/test/e2e/events_test.go +++ b/test/e2e/events_test.go @@ -29,7 +29,6 @@ var _ = Describe("Podman events", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/exec_test.go b/test/e2e/exec_test.go index 3987746d0..f4ee688b7 100644 --- a/test/e2e/exec_test.go +++ b/test/e2e/exec_test.go @@ -27,7 +27,6 @@ var _ = Describe("Podman exec", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/export_test.go b/test/e2e/export_test.go index 78811f1b5..59cbe06ef 100644 --- a/test/e2e/export_test.go +++ b/test/e2e/export_test.go @@ -24,7 +24,6 @@ var _ = Describe("Podman export", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/generate_kube_test.go b/test/e2e/generate_kube_test.go index c92c1519f..2ca774a03 100644 --- a/test/e2e/generate_kube_test.go +++ b/test/e2e/generate_kube_test.go @@ -32,7 +32,6 @@ var _ = Describe("Podman generate kube", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/generate_systemd_test.go b/test/e2e/generate_systemd_test.go index e4b854332..08e8fbc8c 100644 --- a/test/e2e/generate_systemd_test.go +++ b/test/e2e/generate_systemd_test.go @@ -24,7 +24,6 @@ var _ = Describe("Podman generate systemd", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { @@ -581,6 +580,7 @@ var _ = Describe("Podman generate systemd", func() { }) It("podman generate systemd --new create command with double curly braces", func() { + SkipIfInContainer("journald inside a container doesn't work") // Regression test for #9034 session := podmanTest.Podman([]string{"create", "--name", "foo", "--log-driver=journald", "--log-opt=tag={{.Name}}", ALPINE}) session.WaitWithDefaultTimeout() diff --git a/test/e2e/healthcheck_run_test.go b/test/e2e/healthcheck_run_test.go index a41c10162..add739988 100644 --- a/test/e2e/healthcheck_run_test.go +++ b/test/e2e/healthcheck_run_test.go @@ -28,14 +28,13 @@ var _ = Describe("Podman healthcheck run", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { podmanTest.Cleanup() f := CurrentGinkgoTestDescription() timedResult := fmt.Sprintf("Test: %s completed in %f seconds", f.TestText, f.Duration.Seconds()) - GinkgoWriter.Write([]byte(timedResult)) + _, _ = GinkgoWriter.Write([]byte(timedResult)) }) diff --git a/test/e2e/history_test.go b/test/e2e/history_test.go index 92e0e1b08..d637fd9af 100644 --- a/test/e2e/history_test.go +++ b/test/e2e/history_test.go @@ -23,7 +23,6 @@ var _ = Describe("Podman history", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/image_sign_test.go b/test/e2e/image_sign_test.go index dbf697bb0..3c819a7d2 100644 --- a/test/e2e/image_sign_test.go +++ b/test/e2e/image_sign_test.go @@ -28,8 +28,6 @@ var _ = Describe("Podman image sign", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() - tempGNUPGHOME := filepath.Join(podmanTest.TempDir, "tmpGPG") err := os.Mkdir(tempGNUPGHOME, os.ModePerm) Expect(err).To(BeNil()) diff --git a/test/e2e/images_test.go b/test/e2e/images_test.go index fc1c48c15..2473ec59e 100644 --- a/test/e2e/images_test.go +++ b/test/e2e/images_test.go @@ -27,7 +27,6 @@ var _ = Describe("Podman images", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/import_test.go b/test/e2e/import_test.go index f62df23d9..e6995f0e6 100644 --- a/test/e2e/import_test.go +++ b/test/e2e/import_test.go @@ -24,7 +24,6 @@ var _ = Describe("Podman import", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/init_test.go b/test/e2e/init_test.go index fdb2b41a1..ccc102fa3 100644 --- a/test/e2e/init_test.go +++ b/test/e2e/init_test.go @@ -23,7 +23,6 @@ var _ = Describe("Podman init", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/inspect_test.go b/test/e2e/inspect_test.go index 25b938d07..6fe850f0b 100644 --- a/test/e2e/inspect_test.go +++ b/test/e2e/inspect_test.go @@ -24,7 +24,6 @@ var _ = Describe("Podman inspect", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/libpod_suite_remote_test.go b/test/e2e/libpod_suite_remote_test.go index 9ad2bf7b9..8357246a5 100644 --- a/test/e2e/libpod_suite_remote_test.go +++ b/test/e2e/libpod_suite_remote_test.go @@ -16,6 +16,7 @@ import ( "time" "github.com/containers/podman/v4/pkg/rootless" + . "github.com/onsi/gomega" ) func IsRemote() bool { @@ -57,7 +58,8 @@ func (p *PodmanTestIntegration) setDefaultRegistriesConfigEnv() { func (p *PodmanTestIntegration) setRegistriesConfigEnv(b []byte) { outfile := filepath.Join(p.TempDir, "registries.conf") os.Setenv("CONTAINERS_REGISTRIES_CONF", outfile) - ioutil.WriteFile(outfile, b, 0644) + err := ioutil.WriteFile(outfile, b, 0644) + Expect(err).ToNot(HaveOccurred()) } func resetRegistriesConfigEnv() { @@ -71,7 +73,8 @@ func PodmanTestCreate(tempDir string) *PodmanTestIntegration { func (p *PodmanTestIntegration) StartRemoteService() { if os.Geteuid() == 0 { - os.MkdirAll("/run/podman", 0755) + err := os.MkdirAll("/run/podman", 0755) + Expect(err).ToNot(HaveOccurred()) } args := []string{} @@ -88,7 +91,8 @@ func (p *PodmanTestIntegration) StartRemoteService() { command.Stdout = os.Stdout command.Stderr = os.Stderr fmt.Printf("Running: %s %s\n", p.PodmanBinary, strings.Join(podmanOptions, " ")) - command.Start() + err := command.Start() + Expect(err).ToNot(HaveOccurred()) command.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} p.RemoteCommand = command p.RemoteSession = command.Process @@ -145,11 +149,6 @@ func getRemoteOptions(p *PodmanTestIntegration, args []string) []string { return podmanOptions } -// SeedImages restores all the artifacts into the main store for remote tests -func (p *PodmanTestIntegration) SeedImages() error { - return nil -} - // RestoreArtifact puts the cached image into our test store func (p *PodmanTestIntegration) RestoreArtifact(image string) error { tarball := imageTarPath(image) @@ -159,8 +158,12 @@ func (p *PodmanTestIntegration) RestoreArtifact(image string) error { podmanOptions := getRemoteOptions(p, args) command := exec.Command(p.PodmanBinary, podmanOptions...) fmt.Printf("Running: %s %s\n", p.PodmanBinary, strings.Join(podmanOptions, " ")) - command.Start() - command.Wait() + if err := command.Start(); err != nil { + return err + } + if err := command.Wait(); err != nil { + return err + } } return nil } diff --git a/test/e2e/libpod_suite_test.go b/test/e2e/libpod_suite_test.go index cf81a0348..a633bd3d7 100644 --- a/test/e2e/libpod_suite_test.go +++ b/test/e2e/libpod_suite_test.go @@ -10,6 +10,7 @@ import ( "path/filepath" "github.com/containers/podman/v4/pkg/rootless" + . "github.com/onsi/gomega" ) func IsRemote() bool { @@ -40,13 +41,15 @@ func (p *PodmanTestIntegration) PodmanExtraFiles(args []string, extraFiles []*os func (p *PodmanTestIntegration) setDefaultRegistriesConfigEnv() { defaultFile := filepath.Join(INTEGRATION_ROOT, "test/registries.conf") - os.Setenv("CONTAINERS_REGISTRIES_CONF", defaultFile) + err := os.Setenv("CONTAINERS_REGISTRIES_CONF", defaultFile) + Expect(err).ToNot(HaveOccurred()) } func (p *PodmanTestIntegration) setRegistriesConfigEnv(b []byte) { outfile := filepath.Join(p.TempDir, "registries.conf") os.Setenv("CONTAINERS_REGISTRIES_CONF", outfile) - ioutil.WriteFile(outfile, b, 0644) + err := ioutil.WriteFile(outfile, b, 0644) + Expect(err).ToNot(HaveOccurred()) } func resetRegistriesConfigEnv() { @@ -70,11 +73,6 @@ func (p *PodmanTestIntegration) RestoreArtifact(image string) error { func (p *PodmanTestIntegration) StopRemoteService() {} -// SeedImages is a no-op for localized testing -func (p *PodmanTestIntegration) SeedImages() error { - return nil -} - // We don't support running API service when local func (p *PodmanTestIntegration) StartRemoteService() { } diff --git a/test/e2e/login_logout_test.go b/test/e2e/login_logout_test.go index 001779cdf..bce8b78c6 100644 --- a/test/e2e/login_logout_test.go +++ b/test/e2e/login_logout_test.go @@ -36,7 +36,8 @@ var _ = Describe("Podman login and logout", func() { podmanTest = PodmanTestCreate(tempdir) authPath = filepath.Join(podmanTest.TempDir, "auth") - os.Mkdir(authPath, os.ModePerm) + err := os.Mkdir(authPath, os.ModePerm) + Expect(err).ToNot(HaveOccurred()) if IsCommandAvailable("getenforce") { ge := SystemExec("getenforce", []string{}) @@ -55,11 +56,14 @@ var _ = Describe("Podman login and logout", func() { session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - f, _ := os.Create(filepath.Join(authPath, "htpasswd")) + f, err := os.Create(filepath.Join(authPath, "htpasswd")) + Expect(err).ToNot(HaveOccurred()) defer f.Close() - f.WriteString(session.OutputToString()) - f.Sync() + _, err = f.WriteString(session.OutputToString()) + Expect(err).ToNot(HaveOccurred()) + err = f.Sync() + Expect(err).ToNot(HaveOccurred()) port := GetPort() server = strings.Join([]string{"localhost", strconv.Itoa(port)}, ":") @@ -68,7 +72,8 @@ var _ = Describe("Podman login and logout", func() { testImg = strings.Join([]string{server, "test-alpine"}, "/") certDirPath = filepath.Join(os.Getenv("HOME"), ".config/containers/certs.d", server) - os.MkdirAll(certDirPath, os.ModePerm) + err = os.MkdirAll(certDirPath, os.ModePerm) + Expect(err).ToNot(HaveOccurred()) cwd, _ := os.Getwd() certPath = filepath.Join(cwd, "../", "certs") @@ -207,7 +212,8 @@ var _ = Describe("Podman login and logout", func() { }) It("podman login and logout with --cert-dir", func() { certDir := filepath.Join(podmanTest.TempDir, "certs") - os.MkdirAll(certDir, os.ModePerm) + err := os.MkdirAll(certDir, os.ModePerm) + Expect(err).ToNot(HaveOccurred()) setup := SystemExec("cp", []string{filepath.Join(certPath, "domain.crt"), filepath.Join(certDir, "ca.crt")}) setup.WaitWithDefaultTimeout() @@ -226,7 +232,8 @@ var _ = Describe("Podman login and logout", func() { }) It("podman login and logout with multi registry", func() { certDir := filepath.Join(os.Getenv("HOME"), ".config/containers/certs.d", "localhost:9001") - os.MkdirAll(certDir, os.ModePerm) + err = os.MkdirAll(certDir, os.ModePerm) + Expect(err).ToNot(HaveOccurred()) cwd, _ := os.Getwd() certPath = filepath.Join(cwd, "../", "certs") diff --git a/test/e2e/logs_test.go b/test/e2e/logs_test.go index 934a306ce..4e6dcb8af 100644 --- a/test/e2e/logs_test.go +++ b/test/e2e/logs_test.go @@ -37,9 +37,6 @@ var _ = Describe("Podman logs", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - if err := podmanTest.SeedImages(); err != nil { - os.Exit(1) - } }) AfterEach(func() { diff --git a/test/e2e/manifest_test.go b/test/e2e/manifest_test.go index 230864891..92b8bc2e1 100644 --- a/test/e2e/manifest_test.go +++ b/test/e2e/manifest_test.go @@ -36,7 +36,6 @@ var _ = Describe("Podman manifest", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/mount_rootless_test.go b/test/e2e/mount_rootless_test.go index 30d7ce8a9..994a5899b 100644 --- a/test/e2e/mount_rootless_test.go +++ b/test/e2e/mount_rootless_test.go @@ -25,7 +25,6 @@ var _ = Describe("Podman mount", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/namespace_test.go b/test/e2e/namespace_test.go index bc9db4cd9..0000a2327 100644 --- a/test/e2e/namespace_test.go +++ b/test/e2e/namespace_test.go @@ -23,7 +23,6 @@ var _ = Describe("Podman namespaces", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/network_create_test.go b/test/e2e/network_create_test.go index a6e927ca2..69966b07e 100644 --- a/test/e2e/network_create_test.go +++ b/test/e2e/network_create_test.go @@ -32,7 +32,6 @@ var _ = Describe("Podman network create", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/pause_test.go b/test/e2e/pause_test.go index 66638d71c..402719de2 100644 --- a/test/e2e/pause_test.go +++ b/test/e2e/pause_test.go @@ -45,7 +45,6 @@ var _ = Describe("Podman pause", func() { podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/play_build_test.go b/test/e2e/play_build_test.go index 96785c569..914144ae6 100644 --- a/test/e2e/play_build_test.go +++ b/test/e2e/play_build_test.go @@ -29,7 +29,6 @@ var _ = Describe("Podman play kube with build", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go index aaefa4625..0e91db04c 100644 --- a/test/e2e/play_kube_test.go +++ b/test/e2e/play_kube_test.go @@ -1206,8 +1206,6 @@ var _ = Describe("Podman play kube", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() - kubeYaml = filepath.Join(podmanTest.TempDir, "kube.yaml") }) @@ -2744,6 +2742,7 @@ MemoryReservation: {{ .HostConfig.MemoryReservation }}`}) }) It("podman play kube applies log driver to containers", func() { + SkipIfInContainer("journald inside a container doesn't work") pod := getPod() err := generateKubeYaml("pod", pod, kubeYaml) Expect(err).To(BeNil()) diff --git a/test/e2e/pod_create_test.go b/test/e2e/pod_create_test.go index 0c7886a93..dedb1caeb 100644 --- a/test/e2e/pod_create_test.go +++ b/test/e2e/pod_create_test.go @@ -35,7 +35,6 @@ var _ = Describe("Podman pod create", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/pod_infra_container_test.go b/test/e2e/pod_infra_container_test.go index 2b56502b0..ab204992c 100644 --- a/test/e2e/pod_infra_container_test.go +++ b/test/e2e/pod_infra_container_test.go @@ -24,7 +24,6 @@ var _ = Describe("Podman pod create", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/pod_initcontainers_test.go b/test/e2e/pod_initcontainers_test.go index 3c660c5bf..ec429f568 100644 --- a/test/e2e/pod_initcontainers_test.go +++ b/test/e2e/pod_initcontainers_test.go @@ -26,7 +26,6 @@ var _ = Describe("Podman init containers", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/pod_inspect_test.go b/test/e2e/pod_inspect_test.go index dcc70e4a5..351317cc5 100644 --- a/test/e2e/pod_inspect_test.go +++ b/test/e2e/pod_inspect_test.go @@ -25,7 +25,6 @@ var _ = Describe("Podman pod inspect", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/pod_kill_test.go b/test/e2e/pod_kill_test.go index 18f9769a1..0612200d4 100644 --- a/test/e2e/pod_kill_test.go +++ b/test/e2e/pod_kill_test.go @@ -24,7 +24,6 @@ var _ = Describe("Podman pod kill", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/pod_pause_test.go b/test/e2e/pod_pause_test.go index 57ae75926..d78890347 100644 --- a/test/e2e/pod_pause_test.go +++ b/test/e2e/pod_pause_test.go @@ -26,7 +26,6 @@ var _ = Describe("Podman pod pause", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/pod_pod_namespaces_test.go b/test/e2e/pod_pod_namespaces_test.go index 667a54861..5b288898f 100644 --- a/test/e2e/pod_pod_namespaces_test.go +++ b/test/e2e/pod_pod_namespaces_test.go @@ -24,7 +24,6 @@ var _ = Describe("Podman pod create", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/pod_prune_test.go b/test/e2e/pod_prune_test.go index 55ecc1593..dce3e34e4 100644 --- a/test/e2e/pod_prune_test.go +++ b/test/e2e/pod_prune_test.go @@ -23,7 +23,6 @@ var _ = Describe("Podman pod prune", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/pod_ps_test.go b/test/e2e/pod_ps_test.go index a0a1e1438..97ca5ff94 100644 --- a/test/e2e/pod_ps_test.go +++ b/test/e2e/pod_ps_test.go @@ -26,7 +26,6 @@ var _ = Describe("Podman ps", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/pod_restart_test.go b/test/e2e/pod_restart_test.go index 1897104cc..fab448f92 100644 --- a/test/e2e/pod_restart_test.go +++ b/test/e2e/pod_restart_test.go @@ -23,7 +23,6 @@ var _ = Describe("Podman pod restart", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/pod_rm_test.go b/test/e2e/pod_rm_test.go index dbb2d6d13..a5eab7eed 100644 --- a/test/e2e/pod_rm_test.go +++ b/test/e2e/pod_rm_test.go @@ -28,7 +28,6 @@ var _ = Describe("Podman pod rm", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/pod_start_test.go b/test/e2e/pod_start_test.go index 2f3ef3a11..084a48636 100644 --- a/test/e2e/pod_start_test.go +++ b/test/e2e/pod_start_test.go @@ -27,7 +27,6 @@ var _ = Describe("Podman pod start", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/pod_stats_test.go b/test/e2e/pod_stats_test.go index 0e94406f8..8f76e6e5a 100644 --- a/test/e2e/pod_stats_test.go +++ b/test/e2e/pod_stats_test.go @@ -28,7 +28,6 @@ var _ = Describe("Podman pod stats", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/pod_stop_test.go b/test/e2e/pod_stop_test.go index fc78f9ed6..2fe0aa486 100644 --- a/test/e2e/pod_stop_test.go +++ b/test/e2e/pod_stop_test.go @@ -24,7 +24,6 @@ var _ = Describe("Podman pod stop", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/pod_top_test.go b/test/e2e/pod_top_test.go index 564170412..07028da45 100644 --- a/test/e2e/pod_top_test.go +++ b/test/e2e/pod_top_test.go @@ -25,7 +25,6 @@ var _ = Describe("Podman top", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/port_test.go b/test/e2e/port_test.go index d81c03e5b..03263a198 100644 --- a/test/e2e/port_test.go +++ b/test/e2e/port_test.go @@ -25,7 +25,6 @@ var _ = Describe("Podman port", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/prune_test.go b/test/e2e/prune_test.go index 01f987b92..75adf1724 100644 --- a/test/e2e/prune_test.go +++ b/test/e2e/prune_test.go @@ -35,7 +35,6 @@ var _ = Describe("Podman prune", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/ps_test.go b/test/e2e/ps_test.go index 021ebc30b..1100a5d90 100644 --- a/test/e2e/ps_test.go +++ b/test/e2e/ps_test.go @@ -29,7 +29,6 @@ var _ = Describe("Podman ps", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/pull_test.go b/test/e2e/pull_test.go index d13334651..41eb8b449 100644 --- a/test/e2e/pull_test.go +++ b/test/e2e/pull_test.go @@ -345,7 +345,8 @@ var _ = Describe("Podman pull", func() { podmanTest.AddImageToRWStore(cirros) dirpath := filepath.Join(podmanTest.TempDir, "cirros") - os.MkdirAll(dirpath, os.ModePerm) + err = os.MkdirAll(dirpath, os.ModePerm) + Expect(err).ToNot(HaveOccurred()) imgPath := fmt.Sprintf("dir:%s", dirpath) session := podmanTest.Podman([]string{"push", "cirros", imgPath}) @@ -368,7 +369,8 @@ var _ = Describe("Podman pull", func() { podmanTest.AddImageToRWStore(cirros) dirpath := filepath.Join(podmanTest.TempDir, "cirros") - os.MkdirAll(dirpath, os.ModePerm) + err = os.MkdirAll(dirpath, os.ModePerm) + Expect(err).ToNot(HaveOccurred()) imgPath := fmt.Sprintf("oci:%s", dirpath) session := podmanTest.Podman([]string{"push", "cirros", imgPath}) @@ -387,7 +389,8 @@ var _ = Describe("Podman pull", func() { }) It("podman pull check quiet", func() { - podmanTest.RestoreArtifact(ALPINE) + err := podmanTest.RestoreArtifact(ALPINE) + Expect(err).ToNot(HaveOccurred()) setup := podmanTest.Podman([]string{"images", ALPINE, "-q", "--no-trunc"}) setup.WaitWithDefaultTimeout() Expect(setup).Should(Exit(0)) @@ -428,8 +431,10 @@ var _ = Describe("Podman pull", func() { // We already tested pulling, so we can save some energy and // just restore local artifacts and tag them. - podmanTest.RestoreArtifact(ALPINE) - podmanTest.RestoreArtifact(BB) + err := podmanTest.RestoreArtifact(ALPINE) + Expect(err).ToNot(HaveOccurred()) + err = podmanTest.RestoreArtifact(BB) + Expect(err).ToNot(HaveOccurred()) // What we want is at least two images which have the same name // and are prefixed with two different unqualified-search diff --git a/test/e2e/push_test.go b/test/e2e/push_test.go index 3b571ab20..0288bf915 100644 --- a/test/e2e/push_test.go +++ b/test/e2e/push_test.go @@ -101,7 +101,8 @@ var _ = Describe("Podman push", func() { Skip("No registry image for ppc64le") } if rootless.IsRootless() { - podmanTest.RestoreArtifact(registry) + err := podmanTest.RestoreArtifact(registry) + Expect(err).ToNot(HaveOccurred()) } lock := GetPortLock("5000") defer lock.Unlock() @@ -132,8 +133,10 @@ var _ = Describe("Podman push", func() { Skip("No registry image for ppc64le") } authPath := filepath.Join(podmanTest.TempDir, "auth") - os.Mkdir(authPath, os.ModePerm) - os.MkdirAll("/etc/containers/certs.d/localhost:5000", os.ModePerm) + err = os.Mkdir(authPath, os.ModePerm) + Expect(err).ToNot(HaveOccurred()) + err = os.MkdirAll("/etc/containers/certs.d/localhost:5000", os.ModePerm) + Expect(err).ToNot(HaveOccurred()) defer os.RemoveAll("/etc/containers/certs.d/localhost:5000") cwd, _ := os.Getwd() @@ -157,11 +160,14 @@ var _ = Describe("Podman push", func() { session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - f, _ := os.Create(filepath.Join(authPath, "htpasswd")) + f, err := os.Create(filepath.Join(authPath, "htpasswd")) + Expect(err).ToNot(HaveOccurred()) defer f.Close() - f.WriteString(session.OutputToString()) - f.Sync() + _, err = f.WriteString(session.OutputToString()) + Expect(err).ToNot(HaveOccurred()) + err = f.Sync() + Expect(err).ToNot(HaveOccurred()) session = podmanTest.Podman([]string{"run", "-d", "-p", "5000:5000", "--name", "registry", "-v", strings.Join([]string{authPath, "/auth"}, ":"), "-e", "REGISTRY_AUTH=htpasswd", "-e", diff --git a/test/e2e/rename_test.go b/test/e2e/rename_test.go index ef90c3f22..341490d9c 100644 --- a/test/e2e/rename_test.go +++ b/test/e2e/rename_test.go @@ -24,7 +24,6 @@ var _ = Describe("podman rename", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/restart_test.go b/test/e2e/restart_test.go index b8c74d395..b3052623b 100644 --- a/test/e2e/restart_test.go +++ b/test/e2e/restart_test.go @@ -24,7 +24,6 @@ var _ = Describe("Podman restart", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/rm_test.go b/test/e2e/rm_test.go index f836540b4..7dbe5fed8 100644 --- a/test/e2e/rm_test.go +++ b/test/e2e/rm_test.go @@ -24,7 +24,6 @@ var _ = Describe("Podman rm", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/run_aardvark_test.go b/test/e2e/run_aardvark_test.go index 7b4598423..25eb8b538 100644 --- a/test/e2e/run_aardvark_test.go +++ b/test/e2e/run_aardvark_test.go @@ -25,7 +25,6 @@ var _ = Describe("Podman run networking", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() SkipIfCNI(podmanTest) }) diff --git a/test/e2e/run_apparmor_test.go b/test/e2e/run_apparmor_test.go index ed88ab7a0..18d011e6d 100644 --- a/test/e2e/run_apparmor_test.go +++ b/test/e2e/run_apparmor_test.go @@ -42,7 +42,6 @@ var _ = Describe("Podman run", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/run_cgroup_parent_test.go b/test/e2e/run_cgroup_parent_test.go index 34715be22..24cae43b1 100644 --- a/test/e2e/run_cgroup_parent_test.go +++ b/test/e2e/run_cgroup_parent_test.go @@ -30,7 +30,6 @@ var _ = Describe("Podman run with --cgroup-parent", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/run_cleanup_test.go b/test/e2e/run_cleanup_test.go index 2282ef913..ea2caf907 100644 --- a/test/e2e/run_cleanup_test.go +++ b/test/e2e/run_cleanup_test.go @@ -23,7 +23,8 @@ var _ = Describe("Podman run exit", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.RestoreArtifact(ALPINE) + err = podmanTest.RestoreArtifact(ALPINE) + Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { diff --git a/test/e2e/run_cpu_test.go b/test/e2e/run_cpu_test.go index fda0a7c24..b21be5729 100644 --- a/test/e2e/run_cpu_test.go +++ b/test/e2e/run_cpu_test.go @@ -33,7 +33,6 @@ var _ = Describe("Podman run cpu", func() { podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/run_device_test.go b/test/e2e/run_device_test.go index 479837dda..c46afdaca 100644 --- a/test/e2e/run_device_test.go +++ b/test/e2e/run_device_test.go @@ -24,7 +24,6 @@ var _ = Describe("Podman run device", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/run_dns_test.go b/test/e2e/run_dns_test.go index 7561a2e85..61177b4c7 100644 --- a/test/e2e/run_dns_test.go +++ b/test/e2e/run_dns_test.go @@ -23,7 +23,6 @@ var _ = Describe("Podman run dns", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/run_entrypoint_test.go b/test/e2e/run_entrypoint_test.go index fde43dfec..9f35b9e7e 100644 --- a/test/e2e/run_entrypoint_test.go +++ b/test/e2e/run_entrypoint_test.go @@ -23,7 +23,6 @@ var _ = Describe("Podman run entrypoint", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/run_env_test.go b/test/e2e/run_env_test.go index f4c44c23b..bab52efc5 100644 --- a/test/e2e/run_env_test.go +++ b/test/e2e/run_env_test.go @@ -23,7 +23,6 @@ var _ = Describe("Podman run", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/run_exit_test.go b/test/e2e/run_exit_test.go index aa9a4295c..0663e4d9a 100644 --- a/test/e2e/run_exit_test.go +++ b/test/e2e/run_exit_test.go @@ -25,7 +25,6 @@ var _ = Describe("Podman run exit", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/run_memory_test.go b/test/e2e/run_memory_test.go index d6a67da57..083020f08 100644 --- a/test/e2e/run_memory_test.go +++ b/test/e2e/run_memory_test.go @@ -26,7 +26,6 @@ var _ = Describe("Podman run memory", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/run_networking_test.go b/test/e2e/run_networking_test.go index 7527682cb..39c26ec4a 100644 --- a/test/e2e/run_networking_test.go +++ b/test/e2e/run_networking_test.go @@ -32,7 +32,6 @@ var _ = Describe("Podman run networking", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { @@ -747,11 +746,12 @@ EXPOSE 2004-2005/tcp`, ALPINE) routeAdd := func(gateway string) { gw := net.ParseIP(gateway) route := &netlink.Route{Dst: nil, Gw: gw} - netlink.RouteAdd(route) + err = netlink.RouteAdd(route) + Expect(err).ToNot(HaveOccurred()) } setupNetworkNs := func(networkNSName string) { - ns.WithNetNSPath("/run/netns/"+networkNSName, func(_ ns.NetNS) error { + _ = ns.WithNetNSPath("/run/netns/"+networkNSName, func(_ ns.NetNS) error { loopbackup() linkup("eth0", "46:7f:45:6e:4f:c8", []string{"10.25.40.0/24", "fd04:3e42:4a4e:3381::/64"}) linkup("eth1", "56:6e:35:5d:3e:a8", []string{"10.88.0.0/16"}) diff --git a/test/e2e/run_ns_test.go b/test/e2e/run_ns_test.go index 23fd298d7..f99d6cf3f 100644 --- a/test/e2e/run_ns_test.go +++ b/test/e2e/run_ns_test.go @@ -25,7 +25,6 @@ var _ = Describe("Podman run ns", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/run_passwd_test.go b/test/e2e/run_passwd_test.go index ce6c6ffda..411e12218 100644 --- a/test/e2e/run_passwd_test.go +++ b/test/e2e/run_passwd_test.go @@ -24,7 +24,6 @@ var _ = Describe("Podman run passwd", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/run_privileged_test.go b/test/e2e/run_privileged_test.go index 59223c589..4f0b512c6 100644 --- a/test/e2e/run_privileged_test.go +++ b/test/e2e/run_privileged_test.go @@ -49,7 +49,6 @@ var _ = Describe("Podman privileged container tests", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/run_restart_test.go b/test/e2e/run_restart_test.go index ec8fbfe98..b1002ece4 100644 --- a/test/e2e/run_restart_test.go +++ b/test/e2e/run_restart_test.go @@ -23,7 +23,6 @@ var _ = Describe("Podman run restart containers", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/run_seccomp_test.go b/test/e2e/run_seccomp_test.go index 03212b6dc..bd44a3ef1 100644 --- a/test/e2e/run_seccomp_test.go +++ b/test/e2e/run_seccomp_test.go @@ -23,7 +23,6 @@ var _ = Describe("Podman run", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/run_security_labels_test.go b/test/e2e/run_security_labels_test.go index 8aebeaebb..915566a2c 100644 --- a/test/e2e/run_security_labels_test.go +++ b/test/e2e/run_security_labels_test.go @@ -25,8 +25,6 @@ var _ = Describe("Podman generate kube", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() - }) AfterEach(func() { diff --git a/test/e2e/run_selinux_test.go b/test/e2e/run_selinux_test.go index b71c68baf..4a433f308 100644 --- a/test/e2e/run_selinux_test.go +++ b/test/e2e/run_selinux_test.go @@ -25,7 +25,6 @@ var _ = Describe("Podman run", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() if !selinux.GetEnabled() { Skip("SELinux not enabled") } diff --git a/test/e2e/run_signal_test.go b/test/e2e/run_signal_test.go index d40a5a1b4..e5d9b6c7b 100644 --- a/test/e2e/run_signal_test.go +++ b/test/e2e/run_signal_test.go @@ -34,7 +34,6 @@ var _ = Describe("Podman run with --sig-proxy", func() { } podmanTest = PodmanTestCreate(tmpdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { @@ -51,11 +50,14 @@ var _ = Describe("Podman run with --sig-proxy", func() { signal := syscall.SIGFPE // Set up a socket for communication udsDir := filepath.Join(tmpdir, "socket") - os.Mkdir(udsDir, 0700) + err := os.Mkdir(udsDir, 0700) + Expect(err).ToNot(HaveOccurred()) udsPath := filepath.Join(udsDir, "fifo") - syscall.Mkfifo(udsPath, 0600) + err = syscall.Mkfifo(udsPath, 0600) + Expect(err).ToNot(HaveOccurred()) if rootless.IsRootless() { - podmanTest.RestoreArtifact(fedoraMinimal) + err = podmanTest.RestoreArtifact(fedoraMinimal) + Expect(err).ToNot(HaveOccurred()) } _, pid := podmanTest.PodmanPID([]string{"run", "-it", "-v", fmt.Sprintf("%s:/h:Z", udsDir), fedoraMinimal, "bash", "-c", sigCatch}) @@ -112,7 +114,8 @@ var _ = Describe("Podman run with --sig-proxy", func() { Specify("signals are not forwarded to container with sig-proxy false", func() { signal := syscall.SIGFPE if rootless.IsRootless() { - podmanTest.RestoreArtifact(fedoraMinimal) + err = podmanTest.RestoreArtifact(fedoraMinimal) + Expect(err).ToNot(HaveOccurred()) } session, pid := podmanTest.PodmanPID([]string{"run", "--name", "test2", "--sig-proxy=false", fedoraMinimal, "bash", "-c", sigCatch2}) diff --git a/test/e2e/run_staticip_test.go b/test/e2e/run_staticip_test.go index 7e61e7c5e..af3f98d4b 100644 --- a/test/e2e/run_staticip_test.go +++ b/test/e2e/run_staticip_test.go @@ -28,7 +28,6 @@ var _ = Describe("Podman run with --ip flag", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() // Cleanup the CNI networks used by the tests os.RemoveAll("/var/lib/cni/networks/podman") }) diff --git a/test/e2e/run_test.go b/test/e2e/run_test.go index 386a27a2f..afcca6ff0 100644 --- a/test/e2e/run_test.go +++ b/test/e2e/run_test.go @@ -36,7 +36,6 @@ var _ = Describe("Podman run", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { @@ -814,8 +813,10 @@ USER bin`, BB) It("podman test hooks", func() { hcheck := "/run/hookscheck" hooksDir := tempdir + "/hooks" - os.Mkdir(hooksDir, 0755) - fileutils.CopyFile("hooks/hooks.json", hooksDir) + err := os.Mkdir(hooksDir, 0755) + Expect(err).ToNot(HaveOccurred()) + err = fileutils.CopyFile("hooks/hooks.json", hooksDir) + Expect(err).ToNot(HaveOccurred()) os.Setenv("HOOK_OPTION", fmt.Sprintf("--hooks-dir=%s", hooksDir)) os.Remove(hcheck) session := podmanTest.Podman([]string{"run", ALPINE, "ls"}) diff --git a/test/e2e/run_userns_test.go b/test/e2e/run_userns_test.go index 092621c27..613727118 100644 --- a/test/e2e/run_userns_test.go +++ b/test/e2e/run_userns_test.go @@ -33,7 +33,6 @@ var _ = Describe("Podman UserNS support", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/run_volume_test.go b/test/e2e/run_volume_test.go index 4f1013f8d..3bef889b7 100644 --- a/test/e2e/run_volume_test.go +++ b/test/e2e/run_volume_test.go @@ -34,7 +34,6 @@ var _ = Describe("Podman run with volumes", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { @@ -55,7 +54,8 @@ var _ = Describe("Podman run with volumes", func() { It("podman run with volume flag", func() { mountPath := filepath.Join(podmanTest.TempDir, "secrets") - os.Mkdir(mountPath, 0755) + err = os.Mkdir(mountPath, 0755) + Expect(err).ToNot(HaveOccurred()) vol := mountPath + ":" + dest // [5] is flags @@ -82,7 +82,8 @@ var _ = Describe("Podman run with volumes", func() { Skip("skip failing test on ppc64le") } mountPath := filepath.Join(podmanTest.TempDir, "secrets") - os.Mkdir(mountPath, 0755) + err = os.Mkdir(mountPath, 0755) + Expect(err).ToNot(HaveOccurred()) mount := "type=bind,src=" + mountPath + ",target=" + dest session := podmanTest.Podman([]string{"run", "--rm", "--mount", mount, ALPINE, "grep", dest, "/proc/self/mountinfo"}) @@ -141,14 +142,16 @@ var _ = Describe("Podman run with volumes", func() { It("podman run with conflicting volumes errors", func() { mountPath := filepath.Join(podmanTest.TmpDir, "secrets") - os.Mkdir(mountPath, 0755) + err := os.Mkdir(mountPath, 0755) + Expect(err).ToNot(HaveOccurred()) session := podmanTest.Podman([]string{"run", "-v", mountPath + ":" + dest, "-v", "/tmp" + ":" + dest, ALPINE, "ls"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(125)) }) It("podman run with conflict between image volume and user mount succeeds", func() { - podmanTest.RestoreArtifact(redis) + err = podmanTest.RestoreArtifact(redis) + Expect(err).ToNot(HaveOccurred()) mountPath := filepath.Join(podmanTest.TempDir, "secrets") err := os.Mkdir(mountPath, 0755) Expect(err).To(BeNil()) @@ -164,7 +167,8 @@ var _ = Describe("Podman run with volumes", func() { It("podman run with mount flag and boolean options", func() { mountPath := filepath.Join(podmanTest.TempDir, "secrets") - os.Mkdir(mountPath, 0755) + err := os.Mkdir(mountPath, 0755) + Expect(err).ToNot(HaveOccurred()) mount := "type=bind,src=" + mountPath + ",target=" + dest session := podmanTest.Podman([]string{"run", "--rm", "--mount", mount + ",ro=false", ALPINE, "grep", dest, "/proc/self/mountinfo"}) @@ -193,7 +197,8 @@ var _ = Describe("Podman run with volumes", func() { It("podman run with volumes and suid/dev/exec options", func() { SkipIfRemote("podman-remote does not support --volumes") mountPath := filepath.Join(podmanTest.TempDir, "secrets") - os.Mkdir(mountPath, 0755) + err := os.Mkdir(mountPath, 0755) + Expect(err).ToNot(HaveOccurred()) session := podmanTest.Podman([]string{"run", "--rm", "-v", mountPath + ":" + dest + ":suid,dev,exec", ALPINE, "grep", dest, "/proc/self/mountinfo"}) session.WaitWithDefaultTimeout() @@ -224,7 +229,8 @@ var _ = Describe("Podman run with volumes", func() { } } mountPath := filepath.Join(podmanTest.TempDir, "secrets") - os.Mkdir(mountPath, 0755) + err := os.Mkdir(mountPath, 0755) + Expect(err).ToNot(HaveOccurred()) // Container should be able to start with custom overlay volume session := podmanTest.Podman([]string{"run", "--rm", "-v", mountPath + ":/data:O", "--workdir=/data", ALPINE, "echo", "hello"}) @@ -603,7 +609,8 @@ VOLUME /test/`, ALPINE) } } mountPath := filepath.Join(podmanTest.TempDir, "secrets") - os.Mkdir(mountPath, 0755) + err := os.Mkdir(mountPath, 0755) + Expect(err).ToNot(HaveOccurred()) testFile := filepath.Join(mountPath, "test1") f, err := os.Create(testFile) Expect(err).To(BeNil(), "os.Create "+testFile) @@ -651,7 +658,8 @@ VOLUME /test/`, ALPINE) It("overlay volume conflicts with named volume and mounts", func() { mountPath := filepath.Join(podmanTest.TempDir, "secrets") - os.Mkdir(mountPath, 0755) + err := os.Mkdir(mountPath, 0755) + Expect(err).ToNot(HaveOccurred()) testFile := filepath.Join(mountPath, "test1") f, err := os.Create(testFile) Expect(err).To(BeNil()) @@ -716,7 +724,8 @@ VOLUME /test/`, ALPINE) } mountPath := filepath.Join(podmanTest.TempDir, "secrets") - os.Mkdir(mountPath, 0755) + err = os.Mkdir(mountPath, 0755) + Expect(err).ToNot(HaveOccurred()) vol := mountPath + ":" + dest + ":U" session := podmanTest.Podman([]string{"run", "--rm", "--user", "888:888", "-v", vol, ALPINE, "stat", "-c", "%u:%g", dest}) @@ -754,7 +763,8 @@ VOLUME /test/`, ALPINE) } mountPath := filepath.Join(podmanTest.TempDir, "foo") - os.Mkdir(mountPath, 0755) + err = os.Mkdir(mountPath, 0755) + Expect(err).ToNot(HaveOccurred()) // false bind mount vol := "type=bind,src=" + mountPath + ",dst=" + dest + ",U=false" diff --git a/test/e2e/run_working_dir_test.go b/test/e2e/run_working_dir_test.go index 50d0a2194..ff91a420f 100644 --- a/test/e2e/run_working_dir_test.go +++ b/test/e2e/run_working_dir_test.go @@ -24,7 +24,6 @@ var _ = Describe("Podman run", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/runlabel_test.go b/test/e2e/runlabel_test.go index d1e11dd9a..018ed37c2 100644 --- a/test/e2e/runlabel_test.go +++ b/test/e2e/runlabel_test.go @@ -37,7 +37,6 @@ var _ = Describe("podman container runlabel", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/save_test.go b/test/e2e/save_test.go index 39295608e..536eefda7 100644 --- a/test/e2e/save_test.go +++ b/test/e2e/save_test.go @@ -170,7 +170,8 @@ var _ = Describe("Podman save", func() { } defer func() { cmd = exec.Command("cp", "default.yaml", "/etc/containers/registries.d/default.yaml") - cmd.Run() + err := cmd.Run() + Expect(err).ToNot(HaveOccurred()) }() cmd = exec.Command("cp", "sign/key.gpg", "/tmp/key.gpg") diff --git a/test/e2e/search_test.go b/test/e2e/search_test.go index 07198d799..8237f6433 100644 --- a/test/e2e/search_test.go +++ b/test/e2e/search_test.go @@ -64,8 +64,6 @@ registries = ['{{.Host}}:{{.Port}}']` podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() - }) AfterEach(func() { @@ -242,7 +240,8 @@ registries = ['{{.Host}}:{{.Port}}']` Fail("Cannot start docker registry on port %s", port) } ep := endpoint{Port: fmt.Sprintf("%d", port), Host: "localhost"} - podmanTest.RestoreArtifact(ALPINE) + err = podmanTest.RestoreArtifact(ALPINE) + Expect(err).ToNot(HaveOccurred()) image := fmt.Sprintf("%s/my-alpine", ep.Address()) push := podmanTest.Podman([]string{"push", "--tls-verify=false", "--remove-signatures", ALPINE, image}) push.WaitWithDefaultTimeout() @@ -277,7 +276,8 @@ registries = ['{{.Host}}:{{.Port}}']` Fail("unable to start registry on port %s", port) } - podmanTest.RestoreArtifact(ALPINE) + err = podmanTest.RestoreArtifact(ALPINE) + Expect(err).ToNot(HaveOccurred()) image := fmt.Sprintf("%s/my-alpine", ep.Address()) push := podmanTest.Podman([]string{"push", "--tls-verify=false", "--remove-signatures", ALPINE, image}) push.WaitWithDefaultTimeout() @@ -285,9 +285,11 @@ registries = ['{{.Host}}:{{.Port}}']` // registries.conf set up var buffer bytes.Buffer - registryFileTmpl.Execute(&buffer, ep) + err = registryFileTmpl.Execute(&buffer, ep) + Expect(err).ToNot(HaveOccurred()) podmanTest.setRegistriesConfigEnv(buffer.Bytes()) - ioutil.WriteFile(fmt.Sprintf("%s/registry4.conf", tempdir), buffer.Bytes(), 0644) + err = ioutil.WriteFile(fmt.Sprintf("%s/registry4.conf", tempdir), buffer.Bytes(), 0644) + Expect(err).ToNot(HaveOccurred()) if IsRemote() { podmanTest.RestartRemoteService() defer podmanTest.RestartRemoteService() @@ -319,16 +321,19 @@ registries = ['{{.Host}}:{{.Port}}']` Fail("Cannot start docker registry on port %s", port) } - podmanTest.RestoreArtifact(ALPINE) + err = podmanTest.RestoreArtifact(ALPINE) + Expect(err).ToNot(HaveOccurred()) image := fmt.Sprintf("%s/my-alpine", ep.Address()) push := podmanTest.Podman([]string{"push", "--tls-verify=false", "--remove-signatures", ALPINE, image}) push.WaitWithDefaultTimeout() Expect(push).Should(Exit(0)) var buffer bytes.Buffer - registryFileTmpl.Execute(&buffer, ep) + err = registryFileTmpl.Execute(&buffer, ep) + Expect(err).ToNot(HaveOccurred()) podmanTest.setRegistriesConfigEnv(buffer.Bytes()) - ioutil.WriteFile(fmt.Sprintf("%s/registry5.conf", tempdir), buffer.Bytes(), 0644) + err = ioutil.WriteFile(fmt.Sprintf("%s/registry5.conf", tempdir), buffer.Bytes(), 0644) + Expect(err).ToNot(HaveOccurred()) search := podmanTest.Podman([]string{"search", image, "--tls-verify=true"}) search.WaitWithDefaultTimeout() @@ -356,16 +361,19 @@ registries = ['{{.Host}}:{{.Port}}']` Fail("Cannot start docker registry on port %s", port) } - podmanTest.RestoreArtifact(ALPINE) + err = podmanTest.RestoreArtifact(ALPINE) + Expect(err).ToNot(HaveOccurred()) image := fmt.Sprintf("%s/my-alpine", ep.Address()) push := podmanTest.Podman([]string{"push", "--tls-verify=false", "--remove-signatures", ALPINE, image}) push.WaitWithDefaultTimeout() Expect(push).Should(Exit(0)) var buffer bytes.Buffer - registryFileBadTmpl.Execute(&buffer, ep) + err = registryFileBadTmpl.Execute(&buffer, ep) + Expect(err).ToNot(HaveOccurred()) podmanTest.setRegistriesConfigEnv(buffer.Bytes()) - ioutil.WriteFile(fmt.Sprintf("%s/registry6.conf", tempdir), buffer.Bytes(), 0644) + err = ioutil.WriteFile(fmt.Sprintf("%s/registry6.conf", tempdir), buffer.Bytes(), 0644) + Expect(err).ToNot(HaveOccurred()) if IsRemote() { podmanTest.RestartRemoteService() @@ -409,16 +417,19 @@ registries = ['{{.Host}}:{{.Port}}']` Fail("Cannot start docker registry on port %s", port2) } - podmanTest.RestoreArtifact(ALPINE) + err = podmanTest.RestoreArtifact(ALPINE) + Expect(err).ToNot(HaveOccurred()) push := podmanTest.Podman([]string{"push", "--tls-verify=false", "--remove-signatures", ALPINE, fmt.Sprintf("localhost:%d/my-alpine", port2)}) push.WaitWithDefaultTimeout() Expect(push).Should(Exit(0)) // registries.conf set up var buffer bytes.Buffer - registryFileTwoTmpl.Execute(&buffer, ep3) + err = registryFileTwoTmpl.Execute(&buffer, ep3) + Expect(err).ToNot(HaveOccurred()) podmanTest.setRegistriesConfigEnv(buffer.Bytes()) - ioutil.WriteFile(fmt.Sprintf("%s/registry8.conf", tempdir), buffer.Bytes(), 0644) + err = ioutil.WriteFile(fmt.Sprintf("%s/registry8.conf", tempdir), buffer.Bytes(), 0644) + Expect(err).ToNot(HaveOccurred()) if IsRemote() { podmanTest.RestartRemoteService() diff --git a/test/e2e/secret_test.go b/test/e2e/secret_test.go index 90d760c81..ed328d84a 100644 --- a/test/e2e/secret_test.go +++ b/test/e2e/secret_test.go @@ -26,7 +26,6 @@ var _ = Describe("Podman secret", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/start_test.go b/test/e2e/start_test.go index 98943c6fc..73af9d12c 100644 --- a/test/e2e/start_test.go +++ b/test/e2e/start_test.go @@ -26,7 +26,6 @@ var _ = Describe("Podman start", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/stats_test.go b/test/e2e/stats_test.go index 7435a0e3b..b43a81cd3 100644 --- a/test/e2e/stats_test.go +++ b/test/e2e/stats_test.go @@ -32,7 +32,6 @@ var _ = Describe("Podman stats", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/stop_test.go b/test/e2e/stop_test.go index 99d7f278c..8864ba5fd 100644 --- a/test/e2e/stop_test.go +++ b/test/e2e/stop_test.go @@ -25,7 +25,6 @@ var _ = Describe("Podman stop", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/system_connection_test.go b/test/e2e/system_connection_test.go index ac4c5e5ea..95920136e 100644 --- a/test/e2e/system_connection_test.go +++ b/test/e2e/system_connection_test.go @@ -47,7 +47,7 @@ var _ = Describe("podman system connection", func() { } f := CurrentGinkgoTestDescription() - GinkgoWriter.Write( + _, _ = GinkgoWriter.Write( []byte( fmt.Sprintf("Test: %s completed in %f seconds", f.TestText, f.Duration.Seconds()))) }) diff --git a/test/e2e/system_df_test.go b/test/e2e/system_df_test.go index a9fa5f4ac..ba4a40ab4 100644 --- a/test/e2e/system_df_test.go +++ b/test/e2e/system_df_test.go @@ -26,14 +26,13 @@ var _ = Describe("podman system df", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { podmanTest.Cleanup() f := CurrentGinkgoTestDescription() timedResult := fmt.Sprintf("Test: %s completed in %f seconds", f.TestText, f.Duration.Seconds()) - GinkgoWriter.Write([]byte(timedResult)) + _, _ = GinkgoWriter.Write([]byte(timedResult)) }) It("podman system df", func() { diff --git a/test/e2e/system_dial_stdio_test.go b/test/e2e/system_dial_stdio_test.go index 5fcb20cb8..4e4c99bfe 100644 --- a/test/e2e/system_dial_stdio_test.go +++ b/test/e2e/system_dial_stdio_test.go @@ -24,14 +24,13 @@ var _ = Describe("podman system dial-stdio", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { podmanTest.Cleanup() f := CurrentGinkgoTestDescription() timedResult := fmt.Sprintf("Test: %s completed in %f seconds", f.TestText, f.Duration.Seconds()) - GinkgoWriter.Write([]byte(timedResult)) + _, _ = GinkgoWriter.Write([]byte(timedResult)) }) It("podman system dial-stdio help", func() { diff --git a/test/e2e/system_reset_test.go b/test/e2e/system_reset_test.go index f413ce147..ec94bb819 100644 --- a/test/e2e/system_reset_test.go +++ b/test/e2e/system_reset_test.go @@ -24,14 +24,13 @@ var _ = Describe("podman system reset", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { podmanTest.Cleanup() f := CurrentGinkgoTestDescription() timedResult := fmt.Sprintf("Test: %s completed in %f seconds", f.TestText, f.Duration.Seconds()) - GinkgoWriter.Write([]byte(timedResult)) + _, _ = GinkgoWriter.Write([]byte(timedResult)) }) It("podman system reset", func() { diff --git a/test/e2e/systemd_activate_test.go b/test/e2e/systemd_activate_test.go index 04acafe1b..aeea4f932 100644 --- a/test/e2e/systemd_activate_test.go +++ b/test/e2e/systemd_activate_test.go @@ -31,7 +31,6 @@ var _ = Describe("Systemd activate", func() { podmanTest = PodmanTestCreate(tempDir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/systemd_test.go b/test/e2e/systemd_test.go index 57fc323ce..a1a080904 100644 --- a/test/e2e/systemd_test.go +++ b/test/e2e/systemd_test.go @@ -28,7 +28,6 @@ var _ = Describe("Podman systemd", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() systemdUnitFile = `[Unit] Description=redis container [Service] diff --git a/test/e2e/toolbox_test.go b/test/e2e/toolbox_test.go index 1fc28a06d..1e9a6da1f 100644 --- a/test/e2e/toolbox_test.go +++ b/test/e2e/toolbox_test.go @@ -56,7 +56,6 @@ var _ = Describe("Toolbox-specific testing", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/top_test.go b/test/e2e/top_test.go index 344568da5..66bb887dc 100644 --- a/test/e2e/top_test.go +++ b/test/e2e/top_test.go @@ -23,7 +23,6 @@ var _ = Describe("Podman top", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/tree_test.go b/test/e2e/tree_test.go index ab6e49e88..e1282d2b4 100644 --- a/test/e2e/tree_test.go +++ b/test/e2e/tree_test.go @@ -31,7 +31,7 @@ var _ = Describe("Podman image tree", func() { podmanTest.Cleanup() f := CurrentGinkgoTestDescription() timedResult := fmt.Sprintf("Test: %s completed in %f seconds", f.TestText, f.Duration.Seconds()) - GinkgoWriter.Write([]byte(timedResult)) + _, _ = GinkgoWriter.Write([]byte(timedResult)) }) It("podman image tree", func() { diff --git a/test/e2e/trust_test.go b/test/e2e/trust_test.go index d17e34e9c..eee802e43 100644 --- a/test/e2e/trust_test.go +++ b/test/e2e/trust_test.go @@ -28,7 +28,6 @@ var _ = Describe("Podman trust", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { @@ -75,7 +74,8 @@ var _ = Describe("Podman trust", func() { Expect(session).Should(Exit(0)) Expect(session.OutputToString()).To(BeValidJSON()) var teststruct []map[string]string - json.Unmarshal(session.Out.Contents(), &teststruct) + err = json.Unmarshal(session.Out.Contents(), &teststruct) + Expect(err).ToNot(HaveOccurred()) Expect(teststruct).To(HaveLen(3)) // To ease comparison, group the unordered array of repos by repo (and we expect only one entry by repo, so order within groups doesn’t matter) repoMap := map[string][]map[string]string{} diff --git a/test/e2e/unshare_test.go b/test/e2e/unshare_test.go index 8b06dd4f5..520a2f884 100644 --- a/test/e2e/unshare_test.go +++ b/test/e2e/unshare_test.go @@ -32,7 +32,6 @@ var _ = Describe("Podman unshare", func() { podmanTest.CgroupManager = "cgroupfs" podmanTest.StorageOptions = ROOTLESS_STORAGE_OPTIONS podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/version_test.go b/test/e2e/version_test.go index a30db80eb..052b9aa39 100644 --- a/test/e2e/version_test.go +++ b/test/e2e/version_test.go @@ -30,7 +30,7 @@ var _ = Describe("Podman version", func() { podmanTest.Cleanup() f := CurrentGinkgoTestDescription() processTestResult(f) - podmanTest.SeedImages() + }) It("podman version", func() { diff --git a/test/e2e/volume_create_test.go b/test/e2e/volume_create_test.go index 0ac91abd3..09e5da8a0 100644 --- a/test/e2e/volume_create_test.go +++ b/test/e2e/volume_create_test.go @@ -24,7 +24,6 @@ var _ = Describe("Podman volume create", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/volume_exists_test.go b/test/e2e/volume_exists_test.go index fdadbda27..0de574968 100644 --- a/test/e2e/volume_exists_test.go +++ b/test/e2e/volume_exists_test.go @@ -24,7 +24,6 @@ var _ = Describe("Podman volume exists", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/volume_inspect_test.go b/test/e2e/volume_inspect_test.go index 5e3edfe24..344fe8b05 100644 --- a/test/e2e/volume_inspect_test.go +++ b/test/e2e/volume_inspect_test.go @@ -23,7 +23,6 @@ var _ = Describe("Podman volume inspect", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/volume_ls_test.go b/test/e2e/volume_ls_test.go index ce4cfc77d..19f87fb8a 100644 --- a/test/e2e/volume_ls_test.go +++ b/test/e2e/volume_ls_test.go @@ -24,7 +24,6 @@ var _ = Describe("Podman volume ls", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/volume_plugin_test.go b/test/e2e/volume_plugin_test.go index fd205805d..4700afdb5 100644 --- a/test/e2e/volume_plugin_test.go +++ b/test/e2e/volume_plugin_test.go @@ -25,11 +25,11 @@ var _ = Describe("Podman volume plugins", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() os.Setenv("CONTAINERS_CONF", "config/containers.conf") SkipIfRemote("Volume plugins only supported as local") SkipIfRootless("Root is required for volume plugin testing") - os.MkdirAll("/run/docker/plugins", 0755) + err = os.MkdirAll("/run/docker/plugins", 0755) + Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { @@ -55,7 +55,8 @@ var _ = Describe("Podman volume plugins", func() { podmanTest.AddImageToRWStore(volumeTest) pluginStatePath := filepath.Join(podmanTest.TempDir, "volumes") - os.Mkdir(pluginStatePath, 0755) + err := os.Mkdir(pluginStatePath, 0755) + Expect(err).ToNot(HaveOccurred()) // Keep this distinct within tests to avoid multiple tests using the same plugin. pluginName := "testvol1" @@ -89,7 +90,8 @@ var _ = Describe("Podman volume plugins", func() { podmanTest.AddImageToRWStore(volumeTest) pluginStatePath := filepath.Join(podmanTest.TempDir, "volumes") - os.Mkdir(pluginStatePath, 0755) + err := os.Mkdir(pluginStatePath, 0755) + Expect(err).ToNot(HaveOccurred()) // Keep this distinct within tests to avoid multiple tests using the same plugin. pluginName := "testvol2" @@ -112,7 +114,8 @@ var _ = Describe("Podman volume plugins", func() { podmanTest.AddImageToRWStore(volumeTest) pluginStatePath := filepath.Join(podmanTest.TempDir, "volumes") - os.Mkdir(pluginStatePath, 0755) + err := os.Mkdir(pluginStatePath, 0755) + Expect(err).ToNot(HaveOccurred()) // Keep this distinct within tests to avoid multiple tests using the same plugin. pluginName := "testvol3" @@ -153,7 +156,8 @@ var _ = Describe("Podman volume plugins", func() { podmanTest.AddImageToRWStore(volumeTest) pluginStatePath := filepath.Join(podmanTest.TempDir, "volumes") - os.Mkdir(pluginStatePath, 0755) + err := os.Mkdir(pluginStatePath, 0755) + Expect(err).ToNot(HaveOccurred()) // Keep this distinct within tests to avoid multiple tests using the same plugin. pluginName := "testvol4" diff --git a/test/e2e/volume_prune_test.go b/test/e2e/volume_prune_test.go index 0b4c30a48..600f1b887 100644 --- a/test/e2e/volume_prune_test.go +++ b/test/e2e/volume_prune_test.go @@ -23,7 +23,6 @@ var _ = Describe("Podman volume prune", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/volume_rm_test.go b/test/e2e/volume_rm_test.go index 2a2de0920..0180b7a46 100644 --- a/test/e2e/volume_rm_test.go +++ b/test/e2e/volume_rm_test.go @@ -23,7 +23,6 @@ var _ = Describe("Podman volume rm", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/e2e/wait_test.go b/test/e2e/wait_test.go index 098780c70..16e876af9 100644 --- a/test/e2e/wait_test.go +++ b/test/e2e/wait_test.go @@ -23,7 +23,6 @@ var _ = Describe("Podman wait", func() { } podmanTest = PodmanTestCreate(tempdir) podmanTest.Setup() - podmanTest.SeedImages() }) AfterEach(func() { diff --git a/test/utils/common_function_test.go b/test/utils/common_function_test.go index a73d75490..7092e40a1 100644 --- a/test/utils/common_function_test.go +++ b/test/utils/common_function_test.go @@ -113,8 +113,10 @@ var _ = Describe("Common functions test", func() { Expect(err).To(BeNil(), "Can not find the JSON file after we write it.") defer read.Close() - bytes, _ := ioutil.ReadAll(read) - json.Unmarshal(bytes, compareData) + bytes, err := ioutil.ReadAll(read) + Expect(err).ToNot(HaveOccurred()) + err = json.Unmarshal(bytes, compareData) + Expect(err).ToNot(HaveOccurred()) Expect(reflect.DeepEqual(testData, compareData)).To(BeTrue(), "Data changed after we store it to file.") }) diff --git a/test/utils/utils.go b/test/utils/utils.go index f3e14c784..36f5a9414 100644 --- a/test/utils/utils.go +++ b/test/utils/utils.go @@ -489,7 +489,9 @@ func IsCommandAvailable(command string) bool { // WriteJSONFile write json format data to a json file func WriteJSONFile(data []byte, filePath string) error { var jsonData map[string]interface{} - json.Unmarshal(data, &jsonData) + if err := json.Unmarshal(data, &jsonData); err != nil { + return err + } formatJSON, err := json.MarshalIndent(jsonData, "", " ") if err != nil { return err -- cgit v1.2.3-54-g00ecf From 9d5158e94af310fbacc13821bb55f591e89288d8 Mon Sep 17 00:00:00 2001 From: "Jason T. Greene" Date: Sat, 30 Apr 2022 20:21:51 -0500 Subject: Implement machine inspect for WSL Signed-off-by: Jason T. Greene --- pkg/machine/wsl/machine.go | 197 ++++++++++++++++++++++++++++----------------- 1 file changed, 124 insertions(+), 73 deletions(-) (limited to 'pkg/machine') diff --git a/pkg/machine/wsl/machine.go b/pkg/machine/wsl/machine.go index addcb7c8a..bc2ac7864 100644 --- a/pkg/machine/wsl/machine.go +++ b/pkg/machine/wsl/machine.go @@ -18,7 +18,6 @@ import ( "strings" "time" - "github.com/containers/podman/v4/libpod/define" "github.com/containers/podman/v4/pkg/machine" "github.com/containers/podman/v4/utils" "github.com/containers/storage/pkg/homedir" @@ -153,20 +152,22 @@ const ( type Provider struct{} type MachineVM struct { - // IdentityPath is the fq path to the ssh priv key - IdentityPath string + // ConfigPath is the path to the configuration file + ConfigPath string + // Created contains the original created time instead of querying the file mod time + Created time.Time // ImageStream is the version of fcos being used ImageStream string // ImagePath is the fq path to ImagePath string + // LastUp contains the last recorded uptime + LastUp time.Time // Name of the vm Name string - // SSH port for user networking - Port int - // RemoteUsername of the vm user - RemoteUsername string // Whether this machine should run in a rootful or rootless manner Rootful bool + // SSH identity, username, etc + machine.SSHConfig } type ExitCodeError struct { @@ -181,16 +182,22 @@ func GetWSLProvider() machine.Provider { return wslProvider } -// NewMachine initializes an instance of a virtual machine based on the qemu -// virtualization. +// NewMachine initializes an instance of a wsl machine func (p *Provider) NewMachine(opts machine.InitOptions) (machine.VM, error) { vm := new(MachineVM) if len(opts.Name) > 0 { vm.Name = opts.Name } + configPath, err := getConfigPath(opts.Name) + if err != nil { + return vm, err + } + vm.ConfigPath = configPath vm.ImagePath = opts.ImagePath vm.RemoteUsername = opts.Username + vm.Created = time.Now() + vm.LastUp = vm.Created // Add a random port for ssh port, err := utils.GetRandomPort() @@ -202,25 +209,69 @@ func (p *Provider) NewMachine(opts machine.InitOptions) (machine.VM, error) { return vm, nil } +func getConfigPath(name string) (string, error) { + vmConfigDir, err := machine.GetConfDir(vmtype) + if err != nil { + return "", err + } + return filepath.Join(vmConfigDir, name+".json"), nil +} + // LoadByName reads a json file that describes a known qemu vm // and returns a vm instance func (p *Provider) LoadVMByName(name string) (machine.VM, error) { - vm := new(MachineVM) - vmConfigDir, err := machine.GetConfDir(vmtype) + configPath, err := getConfigPath(name) if err != nil { return nil, err } - b, err := ioutil.ReadFile(filepath.Join(vmConfigDir, name+".json")) - if os.IsNotExist(err) { - return nil, errors.Wrap(machine.ErrNoSuchVM, name) - } + + vm, err := readAndMigrate(configPath, name) + return vm, err +} + +// readAndMigrate returns the content of the VM's +// configuration file in json +func readAndMigrate(configPath string, name string) (*MachineVM, error) { + vm := new(MachineVM) + b, err := os.ReadFile(configPath) if err != nil { - return nil, err + if errors.Is(err, os.ErrNotExist) { + return nil, errors.Wrap(machine.ErrNoSuchVM, name) + } + return vm, err } err = json.Unmarshal(b, vm) + if err == nil && vm.Created.IsZero() { + err = vm.migrate40(configPath) + } return vm, err } +func (v *MachineVM) migrate40(configPath string) error { + v.ConfigPath = configPath + fi, err := os.Stat(configPath) + if err != nil { + return err + } + v.Created = fi.ModTime() + v.LastUp = getLegacyLastStart(v) + return v.writeConfig() +} + +func getLegacyLastStart(vm *MachineVM) time.Time { + vmDataDir, err := machine.GetDataDir(vmtype) + if err != nil { + return vm.Created + } + distDir := filepath.Join(vmDataDir, "wsldist") + start := filepath.Join(distDir, vm.Name, "laststart") + info, err := os.Stat(start) + if err != nil { + return vm.Created + } + return info.ModTime() +} + // Init writes the json configuration file to the filesystem for // other verbs (start, stop) func (v *MachineVM) Init(opts machine.InitOptions) (bool, error) { @@ -289,12 +340,7 @@ func downloadDistro(v *MachineVM, opts machine.InitOptions) error { } func (v *MachineVM) writeConfig() error { - vmConfigDir, err := machine.GetConfDir(vmtype) - if err != nil { - return err - } - - jsonFile := filepath.Join(vmConfigDir, v.Name) + ".json" + jsonFile := v.ConfigPath b, err := json.MarshalIndent(v, "", " ") if err != nil { @@ -810,7 +856,8 @@ func (v *MachineVM) Start(name string, _ machine.StartOptions) error { } } - return markStart(name) + _, _, err = v.updateTimeStamps(true) + return err } func launchWinProxy(v *MachineVM) (bool, string, error) { @@ -1005,6 +1052,8 @@ func (v *MachineVM) Stop(name string, _ machine.StopOptions) error { return errors.Errorf("%q is not running", v.Name) } + _, _, _ = v.updateTimeStamps(true) + if err := stopWinProxy(v); err != nil { fmt.Fprintf(os.Stderr, "Could not stop API forwarding service (win-sshproxy.exe): %s\n", err.Error()) } @@ -1032,10 +1081,12 @@ func (v *MachineVM) Stop(name string, _ machine.StopOptions) error { return nil } -// TODO: We need to rename isRunning to State(); I do not have a -// windows system to test this on. func (v *MachineVM) State(bypass bool) (machine.Status, error) { - return "", define.ErrNotImplemented + if v.isRunning() { + return machine.Running, nil + } + + return machine.Stopped, nil } func stopWinProxy(v *MachineVM) error { @@ -1210,14 +1261,9 @@ func GetVMInfos() ([]*machine.ListResponse, error) { var listed []*machine.ListResponse if err = filepath.WalkDir(vmConfigDir, func(path string, d fs.DirEntry, err error) error { - vm := new(MachineVM) if strings.HasSuffix(d.Name(), ".json") { - fullPath := filepath.Join(vmConfigDir, d.Name()) - b, err := ioutil.ReadFile(fullPath) - if err != nil { - return err - } - err = json.Unmarshal(b, vm) + path := filepath.Join(vmConfigDir, d.Name()) + vm, err := readAndMigrate(path, strings.TrimSuffix(d.Name(), ".json")) if err != nil { return err } @@ -1229,15 +1275,13 @@ func GetVMInfos() ([]*machine.ListResponse, error) { listEntry.CPUs, _ = getCPUs(vm) listEntry.Memory, _ = getMem(vm) listEntry.DiskSize = getDiskSize(vm) - fi, err := os.Stat(fullPath) - if err != nil { - return err - } - listEntry.CreatedAt = fi.ModTime() - listEntry.LastUp = getLastStart(vm, fi.ModTime()) - if vm.isRunning() { - listEntry.Running = true - } + listEntry.RemoteUsername = vm.RemoteUsername + listEntry.Port = vm.Port + listEntry.IdentityPath = vm.IdentityPath + + running := vm.isRunning() + listEntry.CreatedAt, listEntry.LastUp, _ = vm.updateTimeStamps(running) + listEntry.Running = running listed = append(listed, listEntry) } @@ -1248,6 +1292,16 @@ func GetVMInfos() ([]*machine.ListResponse, error) { return listed, err } +func (vm *MachineVM) updateTimeStamps(updateLast bool) (time.Time, time.Time, error) { + var err error + if updateLast { + vm.LastUp = time.Now() + err = vm.writeConfig() + } + + return vm.Created, vm.LastUp, err +} + func getDiskSize(vm *MachineVM) uint64 { vmDataDir, err := machine.GetDataDir(vmtype) if err != nil { @@ -1262,36 +1316,6 @@ func getDiskSize(vm *MachineVM) uint64 { return uint64(info.Size()) } -func markStart(name string) error { - vmDataDir, err := machine.GetDataDir(vmtype) - if err != nil { - return err - } - distDir := filepath.Join(vmDataDir, "wsldist") - start := filepath.Join(distDir, name, "laststart") - file, err := os.Create(start) - if err != nil { - return err - } - file.Close() - - return nil -} - -func getLastStart(vm *MachineVM, created time.Time) time.Time { - vmDataDir, err := machine.GetDataDir(vmtype) - if err != nil { - return created - } - distDir := filepath.Join(vmDataDir, "wsldist") - start := filepath.Join(distDir, vm.Name, "laststart") - info, err := os.Stat(start) - if err != nil { - return created - } - return info.ModTime() -} - func getCPUs(vm *MachineVM) (uint64, error) { dist := toDist(vm.Name) if run, _ := isWSLRunning(dist); !run { @@ -1388,6 +1412,33 @@ func (v *MachineVM) setRootful(rootful bool) error { return nil } +// Inspect returns verbose detail about the machine func (v *MachineVM) Inspect() (*machine.InspectInfo, error) { - return nil, define.ErrNotImplemented + state, err := v.State(false) + if err != nil { + return nil, err + } + + created, lastUp, _ := v.updateTimeStamps(state == machine.Running) + + return &machine.InspectInfo{ + ConfigPath: machine.VMFile{Path: v.ConfigPath}, + Created: created, + Image: machine.ImageConfig{ + ImagePath: machine.VMFile{Path: v.ImagePath}, + ImageStream: v.ImageStream, + }, + LastUp: lastUp, + Name: v.Name, + Resources: v.getResources(), + SSHConfig: v.SSHConfig, + State: state, + }, nil +} + +func (v *MachineVM) getResources() (resources machine.ResourceConfig) { + resources.CPUs, _ = getCPUs(v) + resources.Memory, _ = getMem(v) + resources.DiskSize = getDiskSize(v) + return } -- cgit v1.2.3-54-g00ecf