github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/test/e2e/load_test.go (about)

     1  // +build !remoteclient
     2  
     3  package integration
     4  
     5  import (
     6  	"fmt"
     7  	"os"
     8  	"path/filepath"
     9  
    10  	. "github.com/containers/libpod/test/utils"
    11  	. "github.com/onsi/ginkgo"
    12  	. "github.com/onsi/gomega"
    13  )
    14  
    15  var _ = Describe("Podman load", func() {
    16  	var (
    17  		tempdir    string
    18  		err        error
    19  		podmanTest *PodmanTestIntegration
    20  	)
    21  
    22  	BeforeEach(func() {
    23  		tempdir, err = CreateTempDirInTempDir()
    24  		if err != nil {
    25  			os.Exit(1)
    26  		}
    27  		podmanTest = PodmanTestCreate(tempdir)
    28  		podmanTest.Setup()
    29  		podmanTest.RestoreAllArtifacts()
    30  	})
    31  
    32  	AfterEach(func() {
    33  		podmanTest.Cleanup()
    34  		f := CurrentGinkgoTestDescription()
    35  		processTestResult(f)
    36  
    37  	})
    38  
    39  	It("podman load input flag", func() {
    40  		outfile := filepath.Join(podmanTest.TempDir, "alpine.tar")
    41  
    42  		images := podmanTest.PodmanNoCache([]string{"images"})
    43  		images.WaitWithDefaultTimeout()
    44  		fmt.Println(images.OutputToStringArray())
    45  
    46  		save := podmanTest.PodmanNoCache([]string{"save", "-o", outfile, ALPINE})
    47  		save.WaitWithDefaultTimeout()
    48  		Expect(save.ExitCode()).To(Equal(0))
    49  
    50  		rmi := podmanTest.Podman([]string{"rmi", ALPINE})
    51  		rmi.WaitWithDefaultTimeout()
    52  		Expect(rmi.ExitCode()).To(Equal(0))
    53  
    54  		result := podmanTest.PodmanNoCache([]string{"load", "-i", outfile})
    55  		result.WaitWithDefaultTimeout()
    56  		Expect(result.ExitCode()).To(Equal(0))
    57  	})
    58  
    59  	It("podman load compressed tar file", func() {
    60  		outfile := filepath.Join(podmanTest.TempDir, "alpine.tar")
    61  
    62  		save := podmanTest.PodmanNoCache([]string{"save", "-o", outfile, ALPINE})
    63  		save.WaitWithDefaultTimeout()
    64  		Expect(save.ExitCode()).To(Equal(0))
    65  
    66  		compress := SystemExec("gzip", []string{outfile})
    67  		Expect(compress.ExitCode()).To(Equal(0))
    68  		outfile = outfile + ".gz"
    69  
    70  		rmi := podmanTest.PodmanNoCache([]string{"rmi", ALPINE})
    71  		rmi.WaitWithDefaultTimeout()
    72  		Expect(rmi.ExitCode()).To(Equal(0))
    73  
    74  		result := podmanTest.PodmanNoCache([]string{"load", "-i", outfile})
    75  		result.WaitWithDefaultTimeout()
    76  		Expect(result.ExitCode()).To(Equal(0))
    77  	})
    78  
    79  	It("podman load oci-archive image", func() {
    80  		outfile := filepath.Join(podmanTest.TempDir, "alpine.tar")
    81  
    82  		save := podmanTest.PodmanNoCache([]string{"save", "-o", outfile, "--format", "oci-archive", ALPINE})
    83  		save.WaitWithDefaultTimeout()
    84  		Expect(save.ExitCode()).To(Equal(0))
    85  
    86  		rmi := podmanTest.PodmanNoCache([]string{"rmi", ALPINE})
    87  		rmi.WaitWithDefaultTimeout()
    88  		Expect(rmi.ExitCode()).To(Equal(0))
    89  
    90  		result := podmanTest.PodmanNoCache([]string{"load", "-i", outfile})
    91  		result.WaitWithDefaultTimeout()
    92  		Expect(result.ExitCode()).To(Equal(0))
    93  	})
    94  
    95  	It("podman load oci-archive with signature", func() {
    96  		outfile := filepath.Join(podmanTest.TempDir, "alpine.tar")
    97  
    98  		save := podmanTest.PodmanNoCache([]string{"save", "-o", outfile, "--format", "oci-archive", ALPINE})
    99  		save.WaitWithDefaultTimeout()
   100  		Expect(save.ExitCode()).To(Equal(0))
   101  
   102  		rmi := podmanTest.PodmanNoCache([]string{"rmi", ALPINE})
   103  		rmi.WaitWithDefaultTimeout()
   104  		Expect(rmi.ExitCode()).To(Equal(0))
   105  
   106  		result := podmanTest.PodmanNoCache([]string{"load", "--signature-policy", "/etc/containers/policy.json", "-i", outfile})
   107  		result.WaitWithDefaultTimeout()
   108  		Expect(result.ExitCode()).To(Equal(0))
   109  	})
   110  
   111  	It("podman load with quiet flag", func() {
   112  		outfile := filepath.Join(podmanTest.TempDir, "alpine.tar")
   113  
   114  		save := podmanTest.PodmanNoCache([]string{"save", "-o", outfile, ALPINE})
   115  		save.WaitWithDefaultTimeout()
   116  		Expect(save.ExitCode()).To(Equal(0))
   117  
   118  		rmi := podmanTest.PodmanNoCache([]string{"rmi", ALPINE})
   119  		rmi.WaitWithDefaultTimeout()
   120  		Expect(rmi.ExitCode()).To(Equal(0))
   121  
   122  		result := podmanTest.PodmanNoCache([]string{"load", "-q", "-i", outfile})
   123  		result.WaitWithDefaultTimeout()
   124  		Expect(result.ExitCode()).To(Equal(0))
   125  	})
   126  
   127  	It("podman load directory", func() {
   128  		outdir := filepath.Join(podmanTest.TempDir, "alpine")
   129  
   130  		save := podmanTest.PodmanNoCache([]string{"save", "--format", "oci-dir", "-o", outdir, ALPINE})
   131  		save.WaitWithDefaultTimeout()
   132  		Expect(save.ExitCode()).To(Equal(0))
   133  
   134  		rmi := podmanTest.Podman([]string{"rmi", ALPINE})
   135  		rmi.WaitWithDefaultTimeout()
   136  		Expect(rmi.ExitCode()).To(Equal(0))
   137  
   138  		result := podmanTest.Podman([]string{"load", "-i", outdir})
   139  		result.WaitWithDefaultTimeout()
   140  		Expect(result.ExitCode()).To(Equal(0))
   141  	})
   142  
   143  	It("podman load bogus file", func() {
   144  		save := podmanTest.PodmanNoCache([]string{"load", "-i", "foobar.tar"})
   145  		save.WaitWithDefaultTimeout()
   146  		Expect(save).To(ExitWithError())
   147  	})
   148  
   149  	It("podman load multiple tags", func() {
   150  		if podmanTest.Host.Arch == "ppc64le" {
   151  			Skip("skip on ppc64le")
   152  		}
   153  		outfile := filepath.Join(podmanTest.TempDir, "alpine.tar")
   154  		alpVersion := "docker.io/library/alpine:3.2"
   155  
   156  		pull := podmanTest.PodmanNoCache([]string{"pull", alpVersion})
   157  		pull.WaitWithDefaultTimeout()
   158  		Expect(pull.ExitCode()).To(Equal(0))
   159  
   160  		save := podmanTest.PodmanNoCache([]string{"save", "-o", outfile, ALPINE, alpVersion})
   161  		save.WaitWithDefaultTimeout()
   162  		Expect(save.ExitCode()).To(Equal(0))
   163  
   164  		rmi := podmanTest.PodmanNoCache([]string{"rmi", ALPINE, alpVersion})
   165  		rmi.WaitWithDefaultTimeout()
   166  		Expect(rmi.ExitCode()).To(Equal(0))
   167  
   168  		result := podmanTest.PodmanNoCache([]string{"load", "-i", outfile})
   169  		result.WaitWithDefaultTimeout()
   170  		Expect(result.ExitCode()).To(Equal(0))
   171  
   172  		inspect := podmanTest.PodmanNoCache([]string{"inspect", ALPINE})
   173  		inspect.WaitWithDefaultTimeout()
   174  		Expect(result.ExitCode()).To(Equal(0))
   175  		inspect = podmanTest.PodmanNoCache([]string{"inspect", alpVersion})
   176  		inspect.WaitWithDefaultTimeout()
   177  		Expect(result.ExitCode()).To(Equal(0))
   178  	})
   179  
   180  	It("podman load localhost registry from scratch", func() {
   181  		outfile := filepath.Join(podmanTest.TempDir, "load_test.tar.gz")
   182  		setup := podmanTest.PodmanNoCache([]string{"tag", ALPINE, "hello:world"})
   183  		setup.WaitWithDefaultTimeout()
   184  		Expect(setup.ExitCode()).To(Equal(0))
   185  
   186  		setup = podmanTest.PodmanNoCache([]string{"save", "-o", outfile, "--format", "oci-archive", "hello:world"})
   187  		setup.WaitWithDefaultTimeout()
   188  		Expect(setup.ExitCode()).To(Equal(0))
   189  
   190  		setup = podmanTest.PodmanNoCache([]string{"rmi", "hello:world"})
   191  		setup.WaitWithDefaultTimeout()
   192  		Expect(setup.ExitCode()).To(Equal(0))
   193  
   194  		load := podmanTest.PodmanNoCache([]string{"load", "-i", outfile})
   195  		load.WaitWithDefaultTimeout()
   196  		Expect(load.ExitCode()).To(Equal(0))
   197  
   198  		result := podmanTest.PodmanNoCache([]string{"images", "hello:world"})
   199  		result.WaitWithDefaultTimeout()
   200  		Expect(result.LineInOutputContains("docker")).To(Not(BeTrue()))
   201  		Expect(result.LineInOutputContains("localhost")).To(BeTrue())
   202  	})
   203  
   204  	It("podman load localhost registry from scratch and :latest", func() {
   205  		podmanTest.RestoreArtifact(fedoraMinimal)
   206  		outfile := filepath.Join(podmanTest.TempDir, "load_test.tar.gz")
   207  
   208  		setup := podmanTest.PodmanNoCache([]string{"tag", fedoraMinimal, "hello"})
   209  		setup.WaitWithDefaultTimeout()
   210  		Expect(setup.ExitCode()).To(Equal(0))
   211  
   212  		setup = podmanTest.PodmanNoCache([]string{"save", "-o", outfile, "--format", "oci-archive", "hello"})
   213  		setup.WaitWithDefaultTimeout()
   214  		Expect(setup.ExitCode()).To(Equal(0))
   215  
   216  		setup = podmanTest.PodmanNoCache([]string{"rmi", "hello"})
   217  		setup.WaitWithDefaultTimeout()
   218  		Expect(setup.ExitCode()).To(Equal(0))
   219  
   220  		load := podmanTest.PodmanNoCache([]string{"load", "-i", outfile})
   221  		load.WaitWithDefaultTimeout()
   222  		Expect(load.ExitCode()).To(Equal(0))
   223  
   224  		result := podmanTest.PodmanNoCache([]string{"images", "hello:latest"})
   225  		result.WaitWithDefaultTimeout()
   226  		Expect(result.LineInOutputContains("docker")).To(Not(BeTrue()))
   227  		Expect(result.LineInOutputContains("localhost")).To(BeTrue())
   228  	})
   229  
   230  	It("podman load localhost registry from dir", func() {
   231  		outfile := filepath.Join(podmanTest.TempDir, "load")
   232  
   233  		setup := podmanTest.PodmanNoCache([]string{"tag", BB, "hello:world"})
   234  		setup.WaitWithDefaultTimeout()
   235  		Expect(setup.ExitCode()).To(Equal(0))
   236  
   237  		setup = podmanTest.PodmanNoCache([]string{"save", "-o", outfile, "--format", "oci-dir", "hello:world"})
   238  		setup.WaitWithDefaultTimeout()
   239  		Expect(setup.ExitCode()).To(Equal(0))
   240  
   241  		setup = podmanTest.PodmanNoCache([]string{"rmi", "hello:world"})
   242  		setup.WaitWithDefaultTimeout()
   243  		Expect(setup.ExitCode()).To(Equal(0))
   244  
   245  		load := podmanTest.PodmanNoCache([]string{"load", "-i", outfile})
   246  		load.WaitWithDefaultTimeout()
   247  		Expect(load.ExitCode()).To(Equal(0))
   248  
   249  		result := podmanTest.PodmanNoCache([]string{"images", "load:latest"})
   250  		result.WaitWithDefaultTimeout()
   251  		Expect(result.LineInOutputContains("docker")).To(Not(BeTrue()))
   252  		Expect(result.LineInOutputContains("localhost")).To(BeTrue())
   253  	})
   254  
   255  	It("podman load xz compressed image", func() {
   256  		outfile := filepath.Join(podmanTest.TempDir, "bb.tar")
   257  
   258  		save := podmanTest.PodmanNoCache([]string{"save", "-o", outfile, BB})
   259  		save.WaitWithDefaultTimeout()
   260  		Expect(save.ExitCode()).To(Equal(0))
   261  		session := SystemExec("xz", []string{outfile})
   262  		Expect(session.ExitCode()).To(Equal(0))
   263  
   264  		rmi := podmanTest.PodmanNoCache([]string{"rmi", BB})
   265  		rmi.WaitWithDefaultTimeout()
   266  		Expect(rmi.ExitCode()).To(Equal(0))
   267  
   268  		result := podmanTest.PodmanNoCache([]string{"load", "-i", outfile + ".xz"})
   269  		result.WaitWithDefaultTimeout()
   270  		Expect(result.ExitCode()).To(Equal(0))
   271  	})
   272  })