Skip to content

Commit

Permalink
manifest_test: safer registry setup and teardown
Browse files Browse the repository at this point in the history
manifest_test:authenticated_push() is the final test left to
fix before merging containers#14397. The reason it's failing _seems_ to be
that podman is running with a mix of netavark and CNI, and
that _seems_ to be because this test invokes hack/podman-registry
which invokes plain podman without whatever options used in e2e.

Starting a registry directly from the test is insane: there is
no reusable code for doing that (see login_logout_test.go and
push_test.go. Yeesh.)

Solution: set $PODMAN, by inspecting the podmanTest object
which includes both a path and a list of options. podman-registry
will invoke that. (It will also override --root and --runroot.
This is the desired behavior).

Also: add cleanup. If auth-push test fails, stop the registry.

Also: add a sanity check to podman-registry script, have it
wait for the registry port to activate. Die if it doesn't.
That could've saved us a nice bit of debugging time.

Signed-off-by: Ed Santiago <[email protected]>
  • Loading branch information
edsantiago committed Jul 7, 2022
1 parent 700f1fa commit 1161e8b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
24 changes: 23 additions & 1 deletion hack/podman-registry
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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})\""
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/libpod_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
20 changes: 18 additions & 2 deletions test/e2e/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var _ = Describe("Podman manifest", func() {
tempdir string
err error
podmanTest *PodmanTestIntegration
registry *podmanRegistry.Registry
)

const (
Expand All @@ -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"})
Expand Down Expand Up @@ -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"})
Expand Down Expand Up @@ -330,6 +345,7 @@ var _ = Describe("Podman manifest", func() {

err = registry.Stop()
Expect(err).To(BeNil())
registry = nil
})

It("push with error", func() {
Expand Down

0 comments on commit 1161e8b

Please sign in to comment.