summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoropenshift-ci[bot] <75433959+openshift-ci[bot]@users.noreply.github.com>2022-07-08 08:32:16 +0000
committerGitHub <noreply@github.com>2022-07-08 08:32:16 +0000
commita2bcf833c98cb38eb28dc65a8768963d0b7344fc (patch)
tree738e826bce6a0aef0454f44dfb4cc1f3e8f06efc
parent720b3217fd02c635d4f3fd5a2ba0464ae1d8c8b2 (diff)
parent1161e8bd548d23ea9b8cf5ba12d89ded3f86a425 (diff)
downloadpodman-a2bcf833c98cb38eb28dc65a8768963d0b7344fc.tar.gz
podman-a2bcf833c98cb38eb28dc65a8768963d0b7344fc.tar.bz2
podman-a2bcf833c98cb38eb28dc65a8768963d0b7344fc.zip
Merge pull request #14845 from edsantiago/registry_sanitize
manifest_test: safer registry setup and teardown
-rwxr-xr-xhack/podman-registry24
-rw-r--r--test/e2e/libpod_suite_test.go5
-rw-r--r--test/e2e/manifest_test.go20
3 files changed, 46 insertions, 3 deletions
diff --git a/hack/podman-registry b/hack/podman-registry
index 3f0aa2aea..f6a266883 100755
--- a/hack/podman-registry
+++ b/hack/podman-registry
@@ -122,6 +122,25 @@ function must_pass() {
fi
}
+###################
+# wait_for_port # Returns once port is available on localhost
+###################
+function wait_for_port() {
+ local port=$1 # Numeric port
+
+ local host=127.0.0.1
+ local _timeout=5
+
+ # Wait
+ while [ $_timeout -gt 0 ]; do
+ { exec {unused_fd}<> /dev/tcp/$host/$port; } &>/dev/null && return
+ sleep 1
+ _timeout=$(( $_timeout - 1 ))
+ done
+
+ die "Timed out waiting for port $port"
+}
+
# END helper functions
###############################################################################
# BEGIN action processing
@@ -130,7 +149,7 @@ function do_start() {
# If called without a port, assign a random one in the 5xxx range
if [ -z "${PODMAN_REGISTRY_PORT}" ]; then
for port in $(shuf -i 5000-5999);do
- if ! { exec 3<> /dev/tcp/127.0.0.1/$port; } &>/dev/null; then
+ if ! { exec {unused_fd}<> /dev/tcp/127.0.0.1/$port; } &>/dev/null; then
PODMAN_REGISTRY_PORT=$port
break
fi
@@ -203,6 +222,9 @@ function do_start() {
-e "REGISTRY_HTTP_TLS_KEY=/auth/domain.key" \
registry:2.6
+ # Confirm that registry started and port is active
+ wait_for_port $PODMAN_REGISTRY_PORT
+
# Dump settings. Our caller will use these to access the registry.
for v in IMAGE PORT USER PASS; do
echo "PODMAN_REGISTRY_${v}=\"$(eval echo \$PODMAN_REGISTRY_${v})\""
diff --git a/test/e2e/libpod_suite_test.go b/test/e2e/libpod_suite_test.go
index a633bd3d7..ecb7a2278 100644
--- a/test/e2e/libpod_suite_test.go
+++ b/test/e2e/libpod_suite_test.go
@@ -76,3 +76,8 @@ func (p *PodmanTestIntegration) StopRemoteService() {}
// We don't support running API service when local
func (p *PodmanTestIntegration) StartRemoteService() {
}
+
+// Just a stub for compiling with `!remote`.
+func getRemoteOptions(p *PodmanTestIntegration, args []string) []string {
+ return nil
+}
diff --git a/test/e2e/manifest_test.go b/test/e2e/manifest_test.go
index 2f8b47e25..280276973 100644
--- a/test/e2e/manifest_test.go
+++ b/test/e2e/manifest_test.go
@@ -17,6 +17,7 @@ var _ = Describe("Podman manifest", func() {
tempdir string
err error
podmanTest *PodmanTestIntegration
+ registry *podmanRegistry.Registry
)
const (
@@ -39,10 +40,16 @@ var _ = Describe("Podman manifest", func() {
})
AfterEach(func() {
+ // if auth test fails, it will leave a registry running
+ if registry != nil {
+ _ = registry.Stop()
+ }
+ // Also from auth test; don't propagate it to other tests
+ os.Unsetenv("PODMAN")
+
podmanTest.Cleanup()
f := CurrentGinkgoTestDescription()
processTestResult(f)
-
})
It("create w/o image", func() {
session := podmanTest.Podman([]string{"manifest", "create", "foo"})
@@ -297,7 +304,15 @@ var _ = Describe("Podman manifest", func() {
registryOptions := &podmanRegistry.Options{
Image: "docker-archive:" + imageTarPath(REGISTRY_IMAGE),
}
- registry, err := podmanRegistry.StartWithOptions(registryOptions)
+
+ // registry script invokes $PODMAN; make sure we define that
+ // so it can use our same networking options.
+ opts := strings.Join(podmanTest.MakeOptions(nil, false, false), " ")
+ if IsRemote() {
+ opts = strings.Join(getRemoteOptions(podmanTest, nil), " ")
+ }
+ os.Setenv("PODMAN", podmanTest.PodmanBinary+" "+opts)
+ registry, err = podmanRegistry.StartWithOptions(registryOptions)
Expect(err).To(BeNil())
session := podmanTest.Podman([]string{"manifest", "create", "foo"})
@@ -330,6 +345,7 @@ var _ = Describe("Podman manifest", func() {
err = registry.Stop()
Expect(err).To(BeNil())
+ registry = nil
})
It("push with error", func() {