mirror of
https://github.com/containers/podman.git
synced 2025-06-28 14:29:04 +08:00
Use REGISTRIES_CONFIG_PATH for all tests
We should not be using the test systems registries.conf file for integration tests. We should always use a constructed file created specifically for the integration tests or we stand to have unpredictable results. The beforeTest function now sets an environment variable pointing to a registries.conf file in the test's tempdir. That file will container docker.io as a default. The afterTest function then clears the environment variable. Signed-off-by: baude <bbaude@redhat.com> Closes: #1197 Approved by: rhatdan
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -60,6 +61,12 @@ type PodmanTest struct {
|
|||||||
TempDir string
|
TempDir string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HostOS is a simple struct for the test os
|
||||||
|
type HostOS struct {
|
||||||
|
Distribution string
|
||||||
|
Version string
|
||||||
|
}
|
||||||
|
|
||||||
// TestLibpod ginkgo master function
|
// TestLibpod ginkgo master function
|
||||||
func TestLibpod(t *testing.T) {
|
func TestLibpod(t *testing.T) {
|
||||||
if reexec.Init() {
|
if reexec.Init() {
|
||||||
@ -91,7 +98,20 @@ var _ = BeforeSuite(func() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
host := GetHostDistributionInfo()
|
||||||
|
if host.Distribution == "rhel" && strings.HasPrefix(host.Version, "7") {
|
||||||
|
f, err := os.OpenFile("/proc/sys/user/max_user_namespaces", os.O_WRONLY, 0644)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Unable to enable userspace on RHEL 7")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
_, err = f.WriteString("15000")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Unable to enable userspace on RHEL 7")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
f.Close()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// CreateTempDirin
|
// CreateTempDirin
|
||||||
@ -101,6 +121,7 @@ func CreateTempDirInTempDir() (string, error) {
|
|||||||
|
|
||||||
// PodmanCreate creates a PodmanTest instance for the tests
|
// PodmanCreate creates a PodmanTest instance for the tests
|
||||||
func PodmanCreate(tempDir string) PodmanTest {
|
func PodmanCreate(tempDir string) PodmanTest {
|
||||||
|
|
||||||
cwd, _ := os.Getwd()
|
cwd, _ := os.Getwd()
|
||||||
|
|
||||||
podmanBinary := filepath.Join(cwd, "../../bin/podman")
|
podmanBinary := filepath.Join(cwd, "../../bin/podman")
|
||||||
@ -123,7 +144,7 @@ func PodmanCreate(tempDir string) PodmanTest {
|
|||||||
runCBinary := "/usr/bin/runc"
|
runCBinary := "/usr/bin/runc"
|
||||||
CNIConfigDir := "/etc/cni/net.d"
|
CNIConfigDir := "/etc/cni/net.d"
|
||||||
|
|
||||||
return PodmanTest{
|
p := PodmanTest{
|
||||||
PodmanBinary: podmanBinary,
|
PodmanBinary: podmanBinary,
|
||||||
ConmonBinary: conmonBinary,
|
ConmonBinary: conmonBinary,
|
||||||
CrioRoot: filepath.Join(tempDir, "crio"),
|
CrioRoot: filepath.Join(tempDir, "crio"),
|
||||||
@ -135,6 +156,10 @@ func PodmanCreate(tempDir string) PodmanTest {
|
|||||||
ArtifactPath: ARTIFACT_DIR,
|
ArtifactPath: ARTIFACT_DIR,
|
||||||
TempDir: tempDir,
|
TempDir: tempDir,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setup registries.conf ENV variable
|
||||||
|
p.setDefaultRegistriesConfigEnv()
|
||||||
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
//MakeOptions assembles all the podman main options
|
//MakeOptions assembles all the podman main options
|
||||||
@ -201,6 +226,9 @@ func (p *PodmanTest) Cleanup() {
|
|||||||
if err := os.RemoveAll(p.TempDir); err != nil {
|
if err := os.RemoveAll(p.TempDir); err != nil {
|
||||||
fmt.Printf("%q\n", err)
|
fmt.Printf("%q\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clean up the registries configuration file ENV variable set in Create
|
||||||
|
resetRegistriesConfigEnv()
|
||||||
}
|
}
|
||||||
|
|
||||||
// CleanupPod cleans up the temporary store
|
// CleanupPod cleans up the temporary store
|
||||||
@ -571,24 +599,40 @@ func (p *PodmanTest) BuildImage(dockerfile, imageName string, layers string) {
|
|||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
//GetHostDistribution returns the dist in string format. If the
|
//GetHostDistributionInfo returns a struct with its distribution name and version
|
||||||
//distribution cannot be determined, an empty string will be returned.
|
func GetHostDistributionInfo() HostOS {
|
||||||
func (p *PodmanTest) GetHostDistribution() string {
|
f, err := os.Open("/etc/os-release")
|
||||||
content, err := ioutil.ReadFile("/etc/os-release")
|
defer f.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return HostOS{}
|
||||||
}
|
}
|
||||||
for _, line := range content {
|
|
||||||
if strings.HasPrefix(fmt.Sprintf("%x", line), "ID") {
|
|
||||||
fields := strings.Split(fmt.Sprintf("%x", line), "=")
|
|
||||||
if len(fields) < 2 {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return strings.Trim(fields[1], "\"")
|
|
||||||
|
|
||||||
|
l := bufio.NewScanner(f)
|
||||||
|
host := HostOS{}
|
||||||
|
for l.Scan() {
|
||||||
|
if strings.HasPrefix(l.Text(), "ID=") {
|
||||||
|
host.Distribution = strings.Replace(strings.TrimSpace(strings.Join(strings.Split(l.Text(), "=")[1:], "")), "\"", "", -1)
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(l.Text(), "VERSION_ID=") {
|
||||||
|
host.Version = strings.Replace(strings.TrimSpace(strings.Join(strings.Split(l.Text(), "=")[1:], "")), "\"", "", -1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ""
|
return host
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PodmanTest) setDefaultRegistriesConfigEnv() {
|
||||||
|
defaultFile := filepath.Join(INTEGRATION_ROOT, "test/registries.conf")
|
||||||
|
os.Setenv("REGISTRIES_CONFIG_PATH", defaultFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PodmanTest) setRegistriesConfigEnv(b []byte) {
|
||||||
|
outfile := filepath.Join(p.TempDir, "registries.conf")
|
||||||
|
os.Setenv("REGISTRIES_CONFIG_PATH", outfile)
|
||||||
|
ioutil.WriteFile(outfile, b, 0644)
|
||||||
|
}
|
||||||
|
|
||||||
|
func resetRegistriesConfigEnv() {
|
||||||
|
os.Setenv("REGISTRIES_CONFIG_PATH", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsKernelNewThan compares the current kernel version to one provided. If
|
// IsKernelNewThan compares the current kernel version to one provided. If
|
||||||
|
@ -63,7 +63,7 @@ var _ = Describe("Podman run with --sig-proxy", func() {
|
|||||||
udsPath := filepath.Join(udsDir, "fifo")
|
udsPath := filepath.Join(udsDir, "fifo")
|
||||||
syscall.Mkfifo(udsPath, 0600)
|
syscall.Mkfifo(udsPath, 0600)
|
||||||
|
|
||||||
_, pid := podmanTest.PodmanPID([]string{"run", "-it", "-v", fmt.Sprintf("%s:/h", udsDir), fedoraMinimal, "bash", "-c", sigCatch})
|
_, pid := podmanTest.PodmanPID([]string{"run", "-it", "-v", fmt.Sprintf("%s:/h:Z", udsDir), fedoraMinimal, "bash", "-c", sigCatch})
|
||||||
|
|
||||||
uds, _ := os.OpenFile(udsPath, os.O_RDONLY, 0600)
|
uds, _ := os.OpenFile(udsPath, os.O_RDONLY, 0600)
|
||||||
defer uds.Close()
|
defer uds.Close()
|
||||||
|
@ -562,7 +562,7 @@ USER mail`
|
|||||||
err = os.MkdirAll(vol2, 0755)
|
err = os.MkdirAll(vol2, 0755)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
|
|
||||||
session := podmanTest.Podman([]string{"run", "--volume", vol1 + ":/myvol1:ro", "--volume", vol2 + ":/myvol2", ALPINE, "touch", "/myvol2/foo.txt"})
|
session := podmanTest.Podman([]string{"run", "--volume", vol1 + ":/myvol1:z", "--volume", vol2 + ":/myvol2:z", ALPINE, "touch", "/myvol2/foo.txt"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
})
|
})
|
||||||
|
@ -2,9 +2,7 @@ package integration
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
@ -177,10 +175,7 @@ var _ = Describe("Podman search", func() {
|
|||||||
Expect(push.ExitCode()).To(Equal(0))
|
Expect(push.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
// registries.conf set up
|
// registries.conf set up
|
||||||
regFileBytes := []byte(regFileContents)
|
podmanTest.setRegistriesConfigEnv([]byte(regFileContents))
|
||||||
outfile := filepath.Join(podmanTest.TempDir, "registries.conf")
|
|
||||||
os.Setenv("REGISTRIES_CONFIG_PATH", outfile)
|
|
||||||
ioutil.WriteFile(outfile, regFileBytes, 0644)
|
|
||||||
|
|
||||||
search := podmanTest.Podman([]string{"search", "localhost:5000/my-alpine"})
|
search := podmanTest.Podman([]string{"search", "localhost:5000/my-alpine"})
|
||||||
search.WaitWithDefaultTimeout()
|
search.WaitWithDefaultTimeout()
|
||||||
@ -191,7 +186,7 @@ var _ = Describe("Podman search", func() {
|
|||||||
Expect(search.ErrorToString()).Should(BeEmpty())
|
Expect(search.ErrorToString()).Should(BeEmpty())
|
||||||
|
|
||||||
// cleanup
|
// cleanup
|
||||||
os.Setenv("REGISTRIES_CONFIG_PATH", "")
|
resetRegistriesConfigEnv()
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman search doesn't attempt HTTP if force secure is true", func() {
|
It("podman search doesn't attempt HTTP if force secure is true", func() {
|
||||||
@ -208,10 +203,7 @@ var _ = Describe("Podman search", func() {
|
|||||||
Expect(push.ExitCode()).To(Equal(0))
|
Expect(push.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
// registries.conf set up
|
// registries.conf set up
|
||||||
regFileBytes := []byte(regFileContents)
|
podmanTest.setRegistriesConfigEnv([]byte(regFileContents))
|
||||||
outfile := filepath.Join(podmanTest.TempDir, "registries.conf")
|
|
||||||
os.Setenv("REGISTRIES_CONFIG_PATH", outfile)
|
|
||||||
ioutil.WriteFile(outfile, regFileBytes, 0644)
|
|
||||||
|
|
||||||
search := podmanTest.Podman([]string{"search", "localhost:5000/my-alpine", "--tls-verify=true"})
|
search := podmanTest.Podman([]string{"search", "localhost:5000/my-alpine", "--tls-verify=true"})
|
||||||
search.WaitWithDefaultTimeout()
|
search.WaitWithDefaultTimeout()
|
||||||
@ -222,7 +214,7 @@ var _ = Describe("Podman search", func() {
|
|||||||
Expect(match).Should(BeTrue())
|
Expect(match).Should(BeTrue())
|
||||||
|
|
||||||
// cleanup
|
// cleanup
|
||||||
os.Setenv("REGISTRIES_CONFIG_PATH", "")
|
resetRegistriesConfigEnv()
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman search doesn't attempt HTTP if registry is not listed as insecure", func() {
|
It("podman search doesn't attempt HTTP if registry is not listed as insecure", func() {
|
||||||
@ -239,10 +231,7 @@ var _ = Describe("Podman search", func() {
|
|||||||
Expect(push.ExitCode()).To(Equal(0))
|
Expect(push.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
// registries.conf set up
|
// registries.conf set up
|
||||||
regFileBytes := []byte(badRegFileContents)
|
podmanTest.setRegistriesConfigEnv([]byte(badRegFileContents))
|
||||||
outfile := filepath.Join(podmanTest.TempDir, "registries.conf")
|
|
||||||
os.Setenv("REGISTRIES_CONFIG_PATH", outfile)
|
|
||||||
ioutil.WriteFile(outfile, regFileBytes, 0644)
|
|
||||||
|
|
||||||
search := podmanTest.Podman([]string{"search", "localhost:5000/my-alpine"})
|
search := podmanTest.Podman([]string{"search", "localhost:5000/my-alpine"})
|
||||||
search.WaitWithDefaultTimeout()
|
search.WaitWithDefaultTimeout()
|
||||||
@ -253,7 +242,7 @@ var _ = Describe("Podman search", func() {
|
|||||||
Expect(match).Should(BeTrue())
|
Expect(match).Should(BeTrue())
|
||||||
|
|
||||||
// cleanup
|
// cleanup
|
||||||
os.Setenv("REGISTRIES_CONFIG_PATH", "")
|
resetRegistriesConfigEnv()
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman search doesn't attempt HTTP if one registry is not listed as insecure", func() {
|
It("podman search doesn't attempt HTTP if one registry is not listed as insecure", func() {
|
||||||
@ -278,10 +267,7 @@ var _ = Describe("Podman search", func() {
|
|||||||
Expect(push.ExitCode()).To(Equal(0))
|
Expect(push.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
// registries.conf set up
|
// registries.conf set up
|
||||||
regFileBytes := []byte(regFileContents2)
|
podmanTest.setRegistriesConfigEnv([]byte(regFileContents2))
|
||||||
outfile := filepath.Join(podmanTest.TempDir, "registries.conf")
|
|
||||||
os.Setenv("REGISTRIES_CONFIG_PATH", outfile)
|
|
||||||
ioutil.WriteFile(outfile, regFileBytes, 0644)
|
|
||||||
|
|
||||||
search := podmanTest.Podman([]string{"search", "my-alpine"})
|
search := podmanTest.Podman([]string{"search", "my-alpine"})
|
||||||
search.WaitWithDefaultTimeout()
|
search.WaitWithDefaultTimeout()
|
||||||
@ -292,6 +278,6 @@ var _ = Describe("Podman search", func() {
|
|||||||
Expect(match).Should(BeTrue())
|
Expect(match).Should(BeTrue())
|
||||||
|
|
||||||
// cleanup
|
// cleanup
|
||||||
os.Setenv("REGISTRIES_CONFIG_PATH", "")
|
resetRegistriesConfigEnv()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
[registries.search]
|
[registries.search]
|
||||||
registries = ['registry.access.redhat.com', 'registry.fedoraproject.org', 'docker.io']
|
registries = ['docker.io', 'quay.io']
|
||||||
|
|
||||||
[registries.insecure]
|
[registries.insecure]
|
||||||
registries = []
|
registries = []
|
||||||
|
Reference in New Issue
Block a user