github.com/AbhinandanKurakure/podman/v3@v3.4.10/test/e2e/info_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"fmt"
     5  	"io/ioutil"
     6  	"os"
     7  	"os/exec"
     8  	"os/user"
     9  	"path/filepath"
    10  
    11  	. "github.com/containers/podman/v3/test/utils"
    12  	. "github.com/onsi/ginkgo"
    13  	. "github.com/onsi/gomega"
    14  	. "github.com/onsi/gomega/gexec"
    15  )
    16  
    17  var _ = Describe("Podman Info", func() {
    18  	var (
    19  		tempdir    string
    20  		err        error
    21  		podmanTest *PodmanTestIntegration
    22  	)
    23  
    24  	BeforeEach(func() {
    25  		tempdir, err = CreateTempDirInTempDir()
    26  		if err != nil {
    27  			os.Exit(1)
    28  		}
    29  		podmanTest = PodmanTestCreate(tempdir)
    30  		podmanTest.Setup()
    31  	})
    32  
    33  	AfterEach(func() {
    34  		podmanTest.Cleanup()
    35  		f := CurrentGinkgoTestDescription()
    36  		processTestResult(f)
    37  	})
    38  
    39  	It("podman info --format json", func() {
    40  		tests := []struct {
    41  			input    string
    42  			success  bool
    43  			exitCode int
    44  		}{
    45  			{"json", true, 0},
    46  			{" json", true, 0},
    47  			{"json ", true, 0},
    48  			{"  json   ", true, 0},
    49  			{"{{json .}}", true, 0},
    50  			{"{{ json .}}", true, 0},
    51  			{"{{json .   }}", true, 0},
    52  			{"  {{  json .    }}   ", true, 0},
    53  			{"{{json }}", true, 0},
    54  			{"{{json .", false, 125},
    55  			{"json . }}", false, 0}, // without opening {{ template seen as string literal
    56  		}
    57  		for _, tt := range tests {
    58  			session := podmanTest.Podman([]string{"info", "--format", tt.input})
    59  			session.WaitWithDefaultTimeout()
    60  
    61  			desc := fmt.Sprintf("JSON test(%q)", tt.input)
    62  			Expect(session).Should(Exit(tt.exitCode), desc)
    63  			Expect(session.IsJSONOutputValid()).To(Equal(tt.success), desc)
    64  		}
    65  	})
    66  
    67  	It("podman info --format GO template", func() {
    68  		session := podmanTest.Podman([]string{"info", "--format", "{{.Store.GraphRoot}}"})
    69  		session.WaitWithDefaultTimeout()
    70  		Expect(session).Should(Exit(0))
    71  	})
    72  
    73  	It("podman info --format GO template", func() {
    74  		session := podmanTest.Podman([]string{"info", "--format", "{{.Registries}}"})
    75  		session.WaitWithDefaultTimeout()
    76  		Expect(session).Should(Exit(0))
    77  		Expect(session.OutputToString()).To(ContainSubstring("registry"))
    78  	})
    79  
    80  	It("podman info --format GO template plugins", func() {
    81  		session := podmanTest.Podman([]string{"info", "--format", "{{.Plugins}}"})
    82  		session.WaitWithDefaultTimeout()
    83  		Expect(session).Should(Exit(0))
    84  		Expect(session.OutputToString()).To(ContainSubstring("local"))
    85  		Expect(session.OutputToString()).To(ContainSubstring("journald"))
    86  		Expect(session.OutputToString()).To(ContainSubstring("bridge"))
    87  	})
    88  
    89  	It("podman info rootless storage path", func() {
    90  		SkipIfNotRootless("test of rootless_storage_path is only meaningful as rootless")
    91  		SkipIfRemote("Only tests storage on local client")
    92  		configPath := filepath.Join(podmanTest.TempDir, ".config", "containers", "storage.conf")
    93  		os.Setenv("CONTAINERS_STORAGE_CONF", configPath)
    94  		defer func() {
    95  			os.Unsetenv("CONTAINERS_STORAGE_CONF")
    96  		}()
    97  		err := os.RemoveAll(filepath.Dir(configPath))
    98  		Expect(err).To(BeNil())
    99  
   100  		err = os.MkdirAll(filepath.Dir(configPath), os.ModePerm)
   101  		Expect(err).To(BeNil())
   102  
   103  		rootlessStoragePath := `"/tmp/$HOME/$USER/$UID/storage"`
   104  		driver := `"overlay"`
   105  		storageOpt := `"/usr/bin/fuse-overlayfs"`
   106  		storageConf := []byte(fmt.Sprintf("[storage]\ndriver=%s\nrootless_storage_path=%s\n[storage.options]\nmount_program=%s", driver, rootlessStoragePath, storageOpt))
   107  		err = ioutil.WriteFile(configPath, storageConf, os.ModePerm)
   108  		Expect(err).To(BeNil())
   109  
   110  		u, err := user.Current()
   111  		Expect(err).To(BeNil())
   112  
   113  		// Cannot use podmanTest.Podman() and test for storage path
   114  		expect := filepath.Join("/tmp", os.Getenv("HOME"), u.Username, u.Uid, "storage")
   115  		podmanPath := podmanTest.PodmanTest.PodmanBinary
   116  		cmd := exec.Command(podmanPath, "info", "--format", "{{.Store.GraphRoot -}}")
   117  		out, err := cmd.CombinedOutput()
   118  		Expect(err).To(BeNil())
   119  		Expect(string(out)).To(Equal(expect))
   120  	})
   121  
   122  	It("podman info check RemoteSocket", func() {
   123  		session := podmanTest.Podman([]string{"info", "--format", "{{.Host.RemoteSocket.Path}}"})
   124  		session.WaitWithDefaultTimeout()
   125  		Expect(session).Should(Exit(0))
   126  		Expect(session.OutputToString()).To(MatchRegexp("/run/.*podman.*sock"))
   127  
   128  		if IsRemote() {
   129  			session = podmanTest.Podman([]string{"info", "--format", "{{.Host.RemoteSocket.Exists}}"})
   130  			session.WaitWithDefaultTimeout()
   131  			Expect(session).Should(Exit(0))
   132  			Expect(session.OutputToString()).To(ContainSubstring("true"))
   133  		}
   134  	})
   135  
   136  	It("verify ServiceIsRemote", func() {
   137  		session := podmanTest.Podman([]string{"info", "--format", "{{.Host.ServiceIsRemote}}"})
   138  		session.WaitWithDefaultTimeout()
   139  		Expect(session).To(Exit(0))
   140  
   141  		if podmanTest.RemoteTest {
   142  			Expect(session.OutputToString()).To(ContainSubstring("true"))
   143  		} else {
   144  			Expect(session.OutputToString()).To(ContainSubstring("false"))
   145  		}
   146  	})
   147  
   148  	It("Podman info must contain cgroupControllers with ReleventControllers", func() {
   149  		SkipIfRootless("Hard to tell which controllers are going to be enabled for rootless")
   150  		SkipIfRootlessCgroupsV1("Disable cgroups not supported on cgroupv1 for rootless users")
   151  		session := podmanTest.Podman([]string{"info", "--format", "{{.Host.CgroupControllers}}"})
   152  		session.WaitWithDefaultTimeout()
   153  		Expect(session).To(Exit(0))
   154  		Expect(session.OutputToString()).To(ContainSubstring("memory"))
   155  		Expect(session.OutputToString()).To(ContainSubstring("pids"))
   156  	})
   157  })