mirror of https://github.com/containers/podman.git
				
				
				
			Implement --format for machine inspect
* Fix issue of nil pointer derefence Signed-off-by: Jhon Honce <jhonce@redhat.com>
This commit is contained in:
		
							parent
							
								
									1e0c50df38
								
							
						
					
					
						commit
						88015cf0d8
					
				| 
						 | 
				
			
			@ -7,10 +7,10 @@ import (
 | 
			
		|||
	"encoding/json"
 | 
			
		||||
	"os"
 | 
			
		||||
 | 
			
		||||
	"github.com/containers/common/pkg/report"
 | 
			
		||||
	"github.com/containers/podman/v4/cmd/podman/common"
 | 
			
		||||
	"github.com/containers/podman/v4/cmd/podman/registry"
 | 
			
		||||
	"github.com/containers/podman/v4/cmd/podman/utils"
 | 
			
		||||
	"github.com/containers/podman/v4/libpod/define"
 | 
			
		||||
	"github.com/containers/podman/v4/pkg/machine"
 | 
			
		||||
	"github.com/sirupsen/logrus"
 | 
			
		||||
	"github.com/spf13/cobra"
 | 
			
		||||
| 
						 | 
				
			
			@ -66,12 +66,29 @@ func inspect(cmd *cobra.Command, args []string) error {
 | 
			
		|||
		}
 | 
			
		||||
		vms = append(vms, *ii)
 | 
			
		||||
	}
 | 
			
		||||
	if len(inspectFlag.format) > 0 {
 | 
			
		||||
		// need jhonce to work his template magic
 | 
			
		||||
		return define.ErrNotImplemented
 | 
			
		||||
	}
 | 
			
		||||
	if err := printJSON(vms); err != nil {
 | 
			
		||||
		logrus.Error(err)
 | 
			
		||||
	switch {
 | 
			
		||||
	case cmd.Flag("format").Changed:
 | 
			
		||||
		row := report.NormalizeFormat(inspectFlag.format)
 | 
			
		||||
		row = report.EnforceRange(row)
 | 
			
		||||
 | 
			
		||||
		tmpl, err := report.NewTemplate("Machine inspect").Parse(row)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		w, err := report.NewWriterDefault(os.Stdout)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if err := tmpl.Execute(w, vms); err != nil {
 | 
			
		||||
			logrus.Error(err)
 | 
			
		||||
		}
 | 
			
		||||
		w.Flush()
 | 
			
		||||
	default:
 | 
			
		||||
		if err := printJSON(vms); err != nil {
 | 
			
		||||
			logrus.Error(err)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return errs.PrintErrors()
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -43,9 +43,11 @@ var _ = Describe("podman machine stop", func() {
 | 
			
		|||
		Expect(foo2).To(Exit(0))
 | 
			
		||||
 | 
			
		||||
		inspect := new(inspectMachine)
 | 
			
		||||
		inspect = inspect.withFormat("{{.Name}}")
 | 
			
		||||
		inspectSession, err := mb.setName("foo1").setCmd(inspect).run()
 | 
			
		||||
		Expect(err).To(BeNil())
 | 
			
		||||
		Expect(inspectSession).To(Exit(0))
 | 
			
		||||
		Expect(inspectSession.Bytes()).To(ContainSubstring("foo1"))
 | 
			
		||||
 | 
			
		||||
		type fakeInfos struct {
 | 
			
		||||
			Status string
 | 
			
		||||
| 
						 | 
				
			
			@ -56,13 +58,13 @@ var _ = Describe("podman machine stop", func() {
 | 
			
		|||
		Expect(err).ToNot(HaveOccurred())
 | 
			
		||||
		Expect(len(infos)).To(Equal(2))
 | 
			
		||||
 | 
			
		||||
		//rm := new(rmMachine)
 | 
			
		||||
		////	Must manually clean up due to multiple names
 | 
			
		||||
		//for _, name := range []string{"foo1", "foo2"} {
 | 
			
		||||
		// rm := new(rmMachine)
 | 
			
		||||
		// //	Must manually clean up due to multiple names
 | 
			
		||||
		// for _, name := range []string{"foo1", "foo2"} {
 | 
			
		||||
		//	mb.setName(name).setCmd(rm.withForce()).run()
 | 
			
		||||
		//	mb.names = []string{}
 | 
			
		||||
		//}
 | 
			
		||||
		//mb.names = []string{}
 | 
			
		||||
		// }
 | 
			
		||||
		// mb.names = []string{}
 | 
			
		||||
 | 
			
		||||
	})
 | 
			
		||||
})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,14 +23,20 @@ func TestMain(m *testing.M) {
 | 
			
		|||
 | 
			
		||||
const (
 | 
			
		||||
	defaultStream string = "podman-testing"
 | 
			
		||||
	tmpDir        string = "/var/tmp"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	tmpDir         = "/var/tmp"
 | 
			
		||||
	fqImageName    string
 | 
			
		||||
	suiteImageName string
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	if value, ok := os.LookupEnv("TMPDIR"); ok {
 | 
			
		||||
		tmpDir = value
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// TestLibpod ginkgo master function
 | 
			
		||||
func TestMachine(t *testing.T) {
 | 
			
		||||
	RegisterFailHandler(Fail)
 | 
			
		||||
| 
						 | 
				
			
			@ -70,7 +76,8 @@ var _ = SynchronizedAfterSuite(func() {},
 | 
			
		|||
	})
 | 
			
		||||
 | 
			
		||||
func setup() (string, *machineTestBuilder) {
 | 
			
		||||
	homeDir, err := ioutil.TempDir("/var/tmp", "podman_test")
 | 
			
		||||
	// Set TMPDIR if this needs a new directory
 | 
			
		||||
	homeDir, err := ioutil.TempDir("", "podman_test")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		Fail(fmt.Sprintf("failed to create home directory: %q", err))
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -525,10 +525,11 @@ func (v *MachineVM) Start(name string, _ machine.StartOptions) error {
 | 
			
		|||
		time.Sleep(wait)
 | 
			
		||||
		wait++
 | 
			
		||||
	}
 | 
			
		||||
	defer qemuSocketConn.Close()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	defer qemuSocketConn.Close()
 | 
			
		||||
 | 
			
		||||
	fd, err := qemuSocketConn.(*net.UnixConn).File()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue