summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcontrib/cirrus/setup_environment.sh4
-rw-r--r--libpod/boltdb_state_internal.go30
-rw-r--r--libpod/container_internal_linux.go28
-rw-r--r--libpod/runtime.go19
-rw-r--r--libpod/runtime_ctr.go5
-rw-r--r--libpod/shutdown/handler.go131
-rw-r--r--pkg/api/handlers/compat/containers_create.go2
-rw-r--r--pkg/api/server/server.go24
-rw-r--r--pkg/domain/infra/abi/play.go2
-rw-r--r--pkg/domain/infra/abi/terminal/sigproxy_linux.go5
-rw-r--r--pkg/specgen/generate/namespaces.go2
-rw-r--r--pkg/specgen/generate/ports.go46
-rw-r--r--test/e2e/common_test.go9
-rw-r--r--test/e2e/play_kube_test.go19
-rw-r--r--test/e2e/run_networking_test.go15
-rw-r--r--test/endpoint/setup.go9
-rw-r--r--test/system/030-run.bats23
-rw-r--r--test/system/055-rm.bats9
-rw-r--r--test/system/140-diff.bats6
-rw-r--r--test/system/helpers.bash18
20 files changed, 330 insertions, 76 deletions
diff --git a/contrib/cirrus/setup_environment.sh b/contrib/cirrus/setup_environment.sh
index 1b992711f..3135a5e65 100755
--- a/contrib/cirrus/setup_environment.sh
+++ b/contrib/cirrus/setup_environment.sh
@@ -52,7 +52,7 @@ case "$CG_FS_TYPE" in
if [[ "$OS_RELEASE_ID" == "ubuntu" ]]; then
echo "export OCI_RUNTIME=/usr/lib/cri-o-runc/sbin/runc" >> /etc/environment
else
- echo "export OCI_RUNTIME=/usr/bin/runc" >> /etc/environment
+ echo "export OCI_RUNTIME=runc" >> /etc/environment
fi
fi
;;
@@ -61,7 +61,7 @@ case "$CG_FS_TYPE" in
# This is necessary since we've built/installed from source,
# which uses runc as the default.
warn "Forcing testing with crun instead of runc"
- echo "export OCI_RUNTIME=/usr/bin/crun" >> /etc/environment
+ echo "export OCI_RUNTIME=crun" >> /etc/environment
fi
;;
*) die_unknown CG_FS_TYPE
diff --git a/libpod/boltdb_state_internal.go b/libpod/boltdb_state_internal.go
index 9be753d26..e195ca314 100644
--- a/libpod/boltdb_state_internal.go
+++ b/libpod/boltdb_state_internal.go
@@ -2,7 +2,7 @@ package libpod
import (
"bytes"
- "path/filepath"
+ "os"
"runtime"
"strings"
@@ -400,14 +400,30 @@ func (s *BoltState) getContainerFromDB(id []byte, ctr *Container, ctrsBkt *bolt.
// Handle legacy containers which might use a literal path for
// their OCI runtime name.
runtimeName := ctr.config.OCIRuntime
- if strings.HasPrefix(runtimeName, "/") {
- runtimeName = filepath.Base(runtimeName)
- }
-
ociRuntime, ok := s.runtime.ociRuntimes[runtimeName]
if !ok {
- // Use a MissingRuntime implementation
- ociRuntime = getMissingRuntime(runtimeName, s.runtime)
+ runtimeSet := false
+
+ // If the path starts with a / and exists, make a new
+ // OCI runtime for it using the full path.
+ if strings.HasPrefix(runtimeName, "/") {
+ if stat, err := os.Stat(runtimeName); err == nil && !stat.IsDir() {
+ newOCIRuntime, err := newConmonOCIRuntime(runtimeName, []string{runtimeName}, s.runtime.conmonPath, s.runtime.runtimeFlags, s.runtime.config)
+ if err == nil {
+ // The runtime lock should
+ // protect against concurrent
+ // modification of the map.
+ ociRuntime = newOCIRuntime
+ s.runtime.ociRuntimes[runtimeName] = ociRuntime
+ runtimeSet = true
+ }
+ }
+ }
+
+ if !runtimeSet {
+ // Use a MissingRuntime implementation
+ ociRuntime = getMissingRuntime(runtimeName, s.runtime)
+ }
}
ctr.ociRuntime = ociRuntime
}
diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go
index eff390e46..ffb2f5b73 100644
--- a/libpod/container_internal_linux.go
+++ b/libpod/container_internal_linux.go
@@ -1541,11 +1541,31 @@ func (c *Container) getHosts() string {
}
}
- if c.config.NetMode.IsSlirp4netns() {
- // When using slirp4netns, the interface gets a static IP
- hosts += fmt.Sprintf("# used by slirp4netns\n%s\t%s %s\n", "10.0.2.100", c.Hostname(), c.Config().Name)
- }
hosts += c.cniHosts()
+
+ // If not making a network namespace, add our own hostname.
+ if c.Hostname() != "" {
+ if c.config.NetMode.IsSlirp4netns() {
+ // When using slirp4netns, the interface gets a static IP
+ hosts += fmt.Sprintf("# used by slirp4netns\n%s\t%s %s\n", "10.0.2.100", c.Hostname(), c.config.Name)
+ } else {
+ hasNetNS := false
+ for _, ns := range c.config.Spec.Linux.Namespaces {
+ if ns.Type == spec.NetworkNamespace {
+ hasNetNS = true
+ break
+ }
+ }
+ if !hasNetNS {
+ // 127.0.1.1 and host's hostname to match Docker
+ osHostname, err := os.Hostname()
+ if err != nil {
+ osHostname = c.Hostname()
+ }
+ hosts += fmt.Sprintf("127.0.1.1 %s\n", osHostname)
+ }
+ }
+ }
return hosts
}
diff --git a/libpod/runtime.go b/libpod/runtime.go
index 7da8b181f..792492db6 100644
--- a/libpod/runtime.go
+++ b/libpod/runtime.go
@@ -17,6 +17,7 @@ import (
"github.com/containers/podman/v2/libpod/events"
"github.com/containers/podman/v2/libpod/image"
"github.com/containers/podman/v2/libpod/lock"
+ "github.com/containers/podman/v2/libpod/shutdown"
"github.com/containers/podman/v2/pkg/cgroups"
"github.com/containers/podman/v2/pkg/registries"
"github.com/containers/podman/v2/pkg/rootless"
@@ -174,9 +175,21 @@ func newRuntimeFromConfig(ctx context.Context, conf *config.Config, options ...R
}
}
+ if err := shutdown.Start(); err != nil {
+ return nil, errors.Wrapf(err, "error starting shutdown signal handler")
+ }
+
if err := makeRuntime(ctx, runtime); err != nil {
return nil, err
}
+
+ if err := shutdown.Register("libpod", func(sig os.Signal) error {
+ os.Exit(1)
+ return nil
+ }); err != nil {
+ logrus.Errorf("Error registering shutdown handler for libpod: %v", err)
+ }
+
return runtime, nil
}
@@ -383,14 +396,12 @@ func makeRuntime(ctx context.Context, runtime *Runtime) (retErr error) {
// If the string starts with / it's a path to a runtime
// executable.
if strings.HasPrefix(runtime.config.Engine.OCIRuntime, "/") {
- name := filepath.Base(runtime.config.Engine.OCIRuntime)
-
- ociRuntime, err := newConmonOCIRuntime(name, []string{runtime.config.Engine.OCIRuntime}, runtime.conmonPath, runtime.runtimeFlags, runtime.config)
+ ociRuntime, err := newConmonOCIRuntime(runtime.config.Engine.OCIRuntime, []string{runtime.config.Engine.OCIRuntime}, runtime.conmonPath, runtime.runtimeFlags, runtime.config)
if err != nil {
return err
}
- runtime.ociRuntimes[name] = ociRuntime
+ runtime.ociRuntimes[runtime.config.Engine.OCIRuntime] = ociRuntime
runtime.defaultOCIRuntime = ociRuntime
} else {
ociRuntime, ok := runtime.ociRuntimes[runtime.config.Engine.OCIRuntime]
diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go
index 51b4c5f03..de73a9ff3 100644
--- a/libpod/runtime_ctr.go
+++ b/libpod/runtime_ctr.go
@@ -12,6 +12,7 @@ import (
"github.com/containers/common/pkg/config"
"github.com/containers/podman/v2/libpod/define"
"github.com/containers/podman/v2/libpod/events"
+ "github.com/containers/podman/v2/libpod/shutdown"
"github.com/containers/podman/v2/pkg/cgroups"
"github.com/containers/podman/v2/pkg/rootless"
"github.com/containers/storage"
@@ -149,6 +150,10 @@ func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (_ *Contai
return nil, err
}
+ // Inhibit shutdown until creation succeeds
+ shutdown.Inhibit()
+ defer shutdown.Uninhibit()
+
// Allocate a lock for the container
lock, err := r.lockManager.AllocateLock()
if err != nil {
diff --git a/libpod/shutdown/handler.go b/libpod/shutdown/handler.go
new file mode 100644
index 000000000..87538dec9
--- /dev/null
+++ b/libpod/shutdown/handler.go
@@ -0,0 +1,131 @@
+package shutdown
+
+import (
+ "os"
+ "os/signal"
+ "sync"
+ "syscall"
+
+ "github.com/pkg/errors"
+ "github.com/sirupsen/logrus"
+)
+
+var (
+ stopped bool
+ sigChan chan os.Signal
+ cancelChan chan bool
+ // Definitions of all on-shutdown handlers
+ handlers map[string]func(os.Signal) error
+ // Ordering that on-shutdown handlers will be invoked.
+ handlerOrder []string
+ shutdownInhibit sync.RWMutex
+)
+
+// Start begins handling SIGTERM and SIGINT and will run the given on-signal
+// handlers when one is called. This can be cancelled by calling Stop().
+func Start() error {
+ if sigChan != nil {
+ // Already running, do nothing.
+ return nil
+ }
+
+ sigChan = make(chan os.Signal, 1)
+ cancelChan = make(chan bool, 1)
+ stopped = false
+
+ signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
+
+ go func() {
+ select {
+ case <-cancelChan:
+ signal.Stop(sigChan)
+ close(sigChan)
+ close(cancelChan)
+ stopped = true
+ return
+ case sig := <-sigChan:
+ logrus.Infof("Received shutdown signal %v, terminating!", sig)
+ shutdownInhibit.Lock()
+ for _, name := range handlerOrder {
+ handler, ok := handlers[name]
+ if !ok {
+ logrus.Errorf("Shutdown handler %s definition not found!", name)
+ continue
+ }
+ logrus.Infof("Invoking shutdown handler %s", name)
+ if err := handler(sig); err != nil {
+ logrus.Errorf("Error running shutdown handler %s: %v", name, err)
+ }
+ }
+ shutdownInhibit.Unlock()
+ return
+ }
+ }()
+
+ return nil
+}
+
+// Stop the shutdown signal handler.
+func Stop() error {
+ if cancelChan == nil {
+ return errors.New("shutdown signal handler has not yet been started")
+ }
+ if stopped {
+ return nil
+ }
+
+ cancelChan <- true
+
+ return nil
+}
+
+// Temporarily inhibit signals from shutting down Libpod.
+func Inhibit() {
+ shutdownInhibit.RLock()
+}
+
+// Stop inhibiting signals from shutting down Libpod.
+func Uninhibit() {
+ shutdownInhibit.RUnlock()
+}
+
+// Register registers a function that will be executed when Podman is terminated
+// by a signal. Handlers are invoked LIFO - the last handler registered is the
+// first run.
+func Register(name string, handler func(os.Signal) error) error {
+ if handlers == nil {
+ handlers = make(map[string]func(os.Signal) error)
+ }
+
+ if _, ok := handlers[name]; ok {
+ return errors.Errorf("handler with name %s already exists", name)
+ }
+
+ handlers[name] = handler
+ handlerOrder = append([]string{name}, handlerOrder...)
+
+ return nil
+}
+
+// Unregister un-registers a given shutdown handler.
+func Unregister(name string) error {
+ if handlers == nil {
+ return nil
+ }
+
+ if _, ok := handlers[name]; !ok {
+ return nil
+ }
+
+ delete(handlers, name)
+
+ newOrder := []string{}
+ for _, checkName := range handlerOrder {
+ if checkName != name {
+ newOrder = append(newOrder, checkName)
+ }
+ }
+ handlerOrder = newOrder
+
+ return nil
+}
diff --git a/pkg/api/handlers/compat/containers_create.go b/pkg/api/handlers/compat/containers_create.go
index 4ce31cc83..8a0b3c922 100644
--- a/pkg/api/handlers/compat/containers_create.go
+++ b/pkg/api/handlers/compat/containers_create.go
@@ -238,7 +238,7 @@ func makeCreateConfig(ctx context.Context, containerConfig *config.Config, input
Pod: "", // podman
PodmanPath: "", // podman
Quiet: false, // front-end only
- Resources: createconfig.CreateResourceConfig{},
+ Resources: createconfig.CreateResourceConfig{MemorySwappiness: -1},
RestartPolicy: input.HostConfig.RestartPolicy.Name,
Rm: input.HostConfig.AutoRemove,
StopSignal: stopSignal,
diff --git a/pkg/api/server/server.go b/pkg/api/server/server.go
index 355a46fb7..64008767b 100644
--- a/pkg/api/server/server.go
+++ b/pkg/api/server/server.go
@@ -7,7 +7,6 @@ import (
"net"
"net/http"
"os"
- "os/signal"
goRuntime "runtime"
"strings"
"sync"
@@ -15,6 +14,7 @@ import (
"time"
"github.com/containers/podman/v2/libpod"
+ "github.com/containers/podman/v2/libpod/shutdown"
"github.com/containers/podman/v2/pkg/api/handlers"
"github.com/containers/podman/v2/pkg/api/server/idle"
"github.com/coreos/go-systemd/v22/activation"
@@ -180,8 +180,17 @@ func setupSystemd() {
// Serve starts responding to HTTP requests.
func (s *APIServer) Serve() error {
setupSystemd()
- sigChan := make(chan os.Signal, 1)
- signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
+
+ // Start the shutdown signal handler.
+ if err := shutdown.Start(); err != nil {
+ return err
+ }
+ if err := shutdown.Register("server", func(sig os.Signal) error {
+ return s.Shutdown()
+ }); err != nil {
+ return err
+ }
+
errChan := make(chan error, 1)
go func() {
@@ -217,14 +226,7 @@ func (s *APIServer) Serve() error {
errChan <- nil
}()
- select {
- case err := <-errChan:
- return err
- case sig := <-sigChan:
- logrus.Infof("APIServer terminated by signal %v", sig)
- }
-
- return nil
+ return <-errChan
}
// Shutdown is a clean shutdown waiting on existing clients
diff --git a/pkg/domain/infra/abi/play.go b/pkg/domain/infra/abi/play.go
index a7c66bae6..348570a20 100644
--- a/pkg/domain/infra/abi/play.go
+++ b/pkg/domain/infra/abi/play.go
@@ -341,7 +341,7 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY
}
named, err := reference.ParseNormalizedNamed(container.Image)
if err != nil {
- return nil, err
+ return nil, errors.Wrapf(err, "Failed to parse image %q", container.Image)
}
// In kube, if the image is tagged with latest, it should always pull
if tagged, isTagged := named.(reference.NamedTagged); isTagged {
diff --git a/pkg/domain/infra/abi/terminal/sigproxy_linux.go b/pkg/domain/infra/abi/terminal/sigproxy_linux.go
index f484e926c..0c586cf5c 100644
--- a/pkg/domain/infra/abi/terminal/sigproxy_linux.go
+++ b/pkg/domain/infra/abi/terminal/sigproxy_linux.go
@@ -5,12 +5,17 @@ import (
"syscall"
"github.com/containers/podman/v2/libpod"
+ "github.com/containers/podman/v2/libpod/shutdown"
"github.com/containers/podman/v2/pkg/signal"
"github.com/sirupsen/logrus"
)
// ProxySignals ...
func ProxySignals(ctr *libpod.Container) {
+ // Stop catching the shutdown signals (SIGINT, SIGTERM) - they're going
+ // to the container now.
+ shutdown.Stop()
+
sigBuffer := make(chan os.Signal, 128)
signal.CatchAll(sigBuffer)
diff --git a/pkg/specgen/generate/namespaces.go b/pkg/specgen/generate/namespaces.go
index 7adb8be6a..7e4f09dc4 100644
--- a/pkg/specgen/generate/namespaces.go
+++ b/pkg/specgen/generate/namespaces.go
@@ -342,7 +342,7 @@ func specConfigureNamespaces(s *specgen.SpecGenerator, g *generate.Generator, rt
return errors.Wrapf(err, "error looking up container to share uts namespace with")
}
hostname = utsCtr.Hostname()
- case s.NetNS.NSMode == specgen.Host || s.UtsNS.NSMode == specgen.Host:
+ case (s.NetNS.NSMode == specgen.Host && hostname == "") || s.UtsNS.NSMode == specgen.Host:
tmpHostname, err := os.Hostname()
if err != nil {
return errors.Wrap(err, "unable to retrieve hostname of the host")
diff --git a/pkg/specgen/generate/ports.go b/pkg/specgen/generate/ports.go
index 7dd50ac0d..5c13c95b2 100644
--- a/pkg/specgen/generate/ports.go
+++ b/pkg/specgen/generate/ports.go
@@ -25,7 +25,12 @@ const (
func parsePortMapping(portMappings []specgen.PortMapping) ([]ocicni.PortMapping, map[string]map[string]map[uint16]uint16, map[string]map[string]map[uint16]uint16, error) {
// First, we need to validate the ports passed in the specgen, and then
// convert them into CNI port mappings.
- finalMappings := []ocicni.PortMapping{}
+ type tempMapping struct {
+ mapping ocicni.PortMapping
+ startOfRange bool
+ isInRange bool
+ }
+ tempMappings := []tempMapping{}
// To validate, we need two maps: one for host ports, one for container
// ports.
@@ -153,18 +158,32 @@ func parsePortMapping(portMappings []specgen.PortMapping) ([]ocicni.PortMapping,
Protocol: p,
HostIP: port.HostIP,
}
- finalMappings = append(finalMappings, cniPort)
+ tempMappings = append(
+ tempMappings,
+ tempMapping{
+ mapping: cniPort,
+ startOfRange: port.Range > 0 && index == 0,
+ isInRange: port.Range > 0,
+ },
+ )
}
}
}
// Handle any 0 host ports now by setting random container ports.
if postAssignHostPort {
- remadeMappings := make([]ocicni.PortMapping, 0, len(finalMappings))
+ remadeMappings := make([]ocicni.PortMapping, 0, len(tempMappings))
+
+ var (
+ candidate int
+ err error
+ )
// Iterate over all
- for _, p := range finalMappings {
- if p.HostPort != 0 {
+ for _, tmp := range tempMappings {
+ p := tmp.mapping
+
+ if p.HostPort != 0 && !tmp.isInRange {
remadeMappings = append(remadeMappings, p)
continue
}
@@ -192,9 +211,15 @@ func parsePortMapping(portMappings []specgen.PortMapping) ([]ocicni.PortMapping,
// Max retries to ensure we don't loop forever.
for i := 0; i < 15; i++ {
- candidate, err := getRandomPort()
- if err != nil {
- return nil, nil, nil, errors.Wrapf(err, "error getting candidate host port for container port %d", p.ContainerPort)
+ // Only get a random candidate for single entries or the start
+ // of a range. Otherwise we just increment the candidate.
+ if !tmp.isInRange || tmp.startOfRange {
+ candidate, err = getRandomPort()
+ if err != nil {
+ return nil, nil, nil, errors.Wrapf(err, "error getting candidate host port for container port %d", p.ContainerPort)
+ }
+ } else {
+ candidate++
}
if hostPortMap[uint16(candidate)] == 0 {
@@ -213,6 +238,11 @@ func parsePortMapping(portMappings []specgen.PortMapping) ([]ocicni.PortMapping,
return remadeMappings, containerPortValidate, hostPortValidate, nil
}
+ finalMappings := []ocicni.PortMapping{}
+ for _, m := range tempMappings {
+ finalMappings = append(finalMappings, m.mapping)
+ }
+
return finalMappings, containerPortValidate, hostPortValidate, nil
}
diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go
index 1f9b65f16..206c66f9f 100644
--- a/test/e2e/common_test.go
+++ b/test/e2e/common_test.go
@@ -235,14 +235,7 @@ func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration {
ociRuntime := os.Getenv("OCI_RUNTIME")
if ociRuntime == "" {
- var err error
- ociRuntime, err = exec.LookPath("crun")
- // If we cannot find the crun binary, setting to something static as we have no way
- // to return an error. The tests will fail and point out that the runc binary could
- // not be found nicely.
- if err != nil {
- ociRuntime = "/usr/bin/runc"
- }
+ ociRuntime = "crun"
}
os.Setenv("DISABLE_HC_SYSTEMD", "true")
CNIConfigDir := "/etc/cni/net.d"
diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go
index 3906fa49d..7ab8dc6f8 100644
--- a/test/e2e/play_kube_test.go
+++ b/test/e2e/play_kube_test.go
@@ -1447,4 +1447,23 @@ MemoryReservation: {{ .HostConfig.MemoryReservation }}`})
Expect(inspect.OutputToString()).To(ContainSubstring("Memory: " + expectedMemoryLimit))
}
})
+
+ It("podman play kube reports invalid image name", func() {
+ invalidImageName := "./myimage"
+
+ pod := getPod(
+ withCtr(
+ getCtr(
+ withImage(invalidImageName),
+ ),
+ ),
+ )
+ err := generateKubeYaml("pod", pod, kubeYaml)
+ Expect(err).To(BeNil())
+
+ kube := podmanTest.Podman([]string{"play", "kube", kubeYaml})
+ kube.WaitWithDefaultTimeout()
+ Expect(kube.ExitCode()).To(Equal(125))
+ Expect(kube.ErrorToString()).To(ContainSubstring(invalidImageName))
+ })
})
diff --git a/test/e2e/run_networking_test.go b/test/e2e/run_networking_test.go
index e14482db7..540ac5409 100644
--- a/test/e2e/run_networking_test.go
+++ b/test/e2e/run_networking_test.go
@@ -571,4 +571,19 @@ var _ = Describe("Podman run networking", func() {
podrm.WaitWithDefaultTimeout()
Expect(podrm.ExitCode()).To(BeZero())
})
+
+ It("podman run net=host adds entry to /etc/hosts", func() {
+ run := podmanTest.Podman([]string{"run", "--net=host", ALPINE, "cat", "/etc/hosts"})
+ run.WaitWithDefaultTimeout()
+ Expect(run.ExitCode()).To(BeZero())
+ Expect(strings.Contains(run.OutputToString(), "127.0.1.1")).To(BeTrue())
+ })
+
+ It("podman run with --net=host and --hostname sets correct hostname", func() {
+ hostname := "testctr"
+ run := podmanTest.Podman([]string{"run", "--net=host", "--hostname", hostname, ALPINE, "hostname"})
+ run.WaitWithDefaultTimeout()
+ Expect(run.ExitCode()).To(BeZero())
+ Expect(strings.Contains(run.OutputToString(), "testctr")).To(BeTrue())
+ })
})
diff --git a/test/endpoint/setup.go b/test/endpoint/setup.go
index 56cab06b0..6bbc8d2bc 100644
--- a/test/endpoint/setup.go
+++ b/test/endpoint/setup.go
@@ -51,14 +51,7 @@ func Setup(tempDir string) *EndpointTestIntegration {
ociRuntime := os.Getenv("OCI_RUNTIME")
if ociRuntime == "" {
- var err error
- ociRuntime, err = exec.LookPath("runc")
- // If we cannot find the runc binary, setting to something static as we have no way
- // to return an error. The tests will fail and point out that the runc binary could
- // not be found nicely.
- if err != nil {
- ociRuntime = "/usr/bin/runc"
- }
+ ociRuntime = "runc"
}
os.Setenv("DISABLE_HC_SYSTEMD", "true")
CNIConfigDir := "/etc/cni/net.d"
diff --git a/test/system/030-run.bats b/test/system/030-run.bats
index f7c48da8d..9f4037730 100644
--- a/test/system/030-run.bats
+++ b/test/system/030-run.bats
@@ -460,24 +460,17 @@ json-file | f
is "$output" "$expect" "podman run with --tz=local, matches host"
}
-@test "podman container exists" {
- rand=$(random_string 30)
- run_podman 1 container exists myctr
-
- run_podman create --name myctr $IMAGE /bin/true
- run_podman container exists myctr
-
- # Create a container that podman does not know about
- run buildah from $IMAGE
+# run with --runtime should preserve the named runtime
+@test "podman run : full path to --runtime is preserved" {
+ skip_if_cgroupsv1
+ skip_if_remote
+ run_podman run -d --runtime '/usr/bin/crun' $IMAGE sleep 60
cid="$output"
- # exists should fail
- run_podman 1 container exists $cid
-
- # exists should succeed
- run_podman container exists --external $cid
+ run_podman inspect --format '{{.OCIRuntime}}' $cid
+ is "$output" "/usr/bin/crun"
- run buildah rm $cid
+ run_podman kill $cid
}
# vim: filetype=sh
diff --git a/test/system/055-rm.bats b/test/system/055-rm.bats
index 7176ae4b8..0107114b5 100644
--- a/test/system/055-rm.bats
+++ b/test/system/055-rm.bats
@@ -41,11 +41,14 @@ load helpers
run_podman create --name $rand $IMAGE /bin/true
# Create a container that podman does not know about
- run buildah from $IMAGE
- cid="$output"
+ external_cid=$(buildah from $IMAGE)
+
+ # Plain 'exists' should fail, but should succeed with --external
+ run_podman 1 container exists $external_cid
+ run_podman container exists --external $external_cid
# rm should succeed
- run_podman rm $rand $cid
+ run_podman rm $rand $external_cid
}
# I'm sorry! This test takes 13 seconds. There's not much I can do about it,
diff --git a/test/system/140-diff.bats b/test/system/140-diff.bats
index d0f33e438..1277f9bbe 100644
--- a/test/system/140-diff.bats
+++ b/test/system/140-diff.bats
@@ -34,8 +34,8 @@ load helpers
@test "podman diff with buildah container " {
rand_file=$(random_string 10)
- run buildah from --name buildahctr $IMAGE
- run buildah run buildahctr sh -c "touch /$rand_file;rm /etc/services"
+ buildah from --name buildahctr $IMAGE
+ buildah run buildahctr sh -c "touch /$rand_file;rm /etc/services"
run_podman diff --format json buildahctr
@@ -51,7 +51,7 @@ load helpers
is "$result" "${expect[$field]}" "$field"
done
- run buildah rm buildahctr
+ buildah rm buildahctr
}
# vim: filetype=sh
diff --git a/test/system/helpers.bash b/test/system/helpers.bash
index 4591c9015..2cced10c2 100644
--- a/test/system/helpers.bash
+++ b/test/system/helpers.bash
@@ -34,6 +34,14 @@ function basic_setup() {
# Clean up all containers
run_podman rm --all --force
+ # ...including external (buildah) ones
+ run_podman ps --all --external --format '{{.ID}} {{.Names}}'
+ for line in "${lines[@]}"; do
+ set $line
+ echo "# setup(): removing stray external container $1 ($2)" >&3
+ run_podman rm $1
+ done
+
# Clean up all images except those desired
found_needed_image=
run_podman images --all --format '{{.Repository}}:{{.Tag}} {{.ID}}'
@@ -245,6 +253,7 @@ function is_cgroupsv1() {
! is_cgroupsv2
}
+# True if cgroups v2 are enabled
function is_cgroupsv2() {
cgroup_type=$(stat -f -c %T /sys/fs/cgroup)
test "$cgroup_type" = "cgroup2fs"
@@ -297,6 +306,15 @@ function skip_if_no_selinux() {
fi
}
+#######################
+# skip_if_cgroupsv1 # ...with an optional message
+#######################
+function skip_if_cgroupsv1() {
+ if ! is_cgroupsv2; then
+ skip "${1:-test requires cgroupsv2}"
+ fi
+}
+
#########
# die # Abort with helpful message
#########