mirror of
https://github.com/containers/podman.git
synced 2025-10-19 04:03:23 +08:00
Use file-based eventer for integration tests
This adds several top-level Podman flags for specifying different events backend types, which are then used in CI. It resolves a number of serious issues with events-based testing. Signed-off-by: Matthew Heon <matthew.heon@pm.me>
This commit is contained in:
@ -16,6 +16,7 @@ type MainFlags struct {
|
|||||||
CniConfigDir string
|
CniConfigDir string
|
||||||
ConmonPath string
|
ConmonPath string
|
||||||
DefaultMountsFile string
|
DefaultMountsFile string
|
||||||
|
EventsBackend string
|
||||||
HooksDir []string
|
HooksDir []string
|
||||||
MaxWorks int
|
MaxWorks int
|
||||||
Namespace string
|
Namespace string
|
||||||
|
@ -109,6 +109,10 @@ func getRuntime(ctx context.Context, c *cliconfig.PodmanCommand, renumber bool,
|
|||||||
options = append(options, libpod.WithNetworkCmdPath(c.GlobalFlags.NetworkCmdPath))
|
options = append(options, libpod.WithNetworkCmdPath(c.GlobalFlags.NetworkCmdPath))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.Flags().Changed("events-backend") {
|
||||||
|
options = append(options, libpod.WithEventsLogger(c.GlobalFlags.EventsBackend))
|
||||||
|
}
|
||||||
|
|
||||||
if c.Flags().Changed("cgroup-manager") {
|
if c.Flags().Changed("cgroup-manager") {
|
||||||
options = append(options, libpod.WithCgroupManager(c.GlobalFlags.CGroupManager))
|
options = append(options, libpod.WithCgroupManager(c.GlobalFlags.CGroupManager))
|
||||||
} else {
|
} else {
|
||||||
|
@ -35,6 +35,7 @@ func init() {
|
|||||||
rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.CniConfigDir, "cni-config-dir", "", "Path of the configuration directory for CNI networks")
|
rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.CniConfigDir, "cni-config-dir", "", "Path of the configuration directory for CNI networks")
|
||||||
rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.DefaultMountsFile, "default-mounts-file", "", "Path to default mounts file")
|
rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.DefaultMountsFile, "default-mounts-file", "", "Path to default mounts file")
|
||||||
rootCmd.PersistentFlags().MarkHidden("defaults-mount-file")
|
rootCmd.PersistentFlags().MarkHidden("defaults-mount-file")
|
||||||
|
rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.EventsBackend, "events-backend", "", "Events backend to use")
|
||||||
// Override default --help information of `--help` global flag
|
// Override default --help information of `--help` global flag
|
||||||
var dummyHelp bool
|
var dummyHelp bool
|
||||||
rootCmd.PersistentFlags().BoolVar(&dummyHelp, "help", false, "Help for podman")
|
rootCmd.PersistentFlags().BoolVar(&dummyHelp, "help", false, "Help for podman")
|
||||||
|
@ -96,7 +96,7 @@ libpod to manage containers.
|
|||||||
a slirp4netns network. If "" is used then the binary is looked up using the $PATH environment variable.
|
a slirp4netns network. If "" is used then the binary is looked up using the $PATH environment variable.
|
||||||
|
|
||||||
**events_logger**=""
|
**events_logger**=""
|
||||||
Default method to use when logging events. Valid values are "journald" and "file".
|
Default method to use when logging events. Valid values are "file", "journald", and "none".
|
||||||
|
|
||||||
## FILES
|
## FILES
|
||||||
`/usr/share/containers/libpod.conf`, default libpod configuration path
|
`/usr/share/containers/libpod.conf`, default libpod configuration path
|
||||||
|
@ -33,6 +33,10 @@ CGroup manager to use for container cgroups. Supported values are cgroupfs or sy
|
|||||||
|
|
||||||
Path to where the cpu performance results should be written
|
Path to where the cpu performance results should be written
|
||||||
|
|
||||||
|
**--events-logger**=*type*
|
||||||
|
|
||||||
|
Backend to use for storing events. Allowed values are **file**, **journald**, and **none**.
|
||||||
|
|
||||||
**--hooks-dir**=*path*
|
**--hooks-dir**=*path*
|
||||||
|
|
||||||
Each `*.json` file in the path configures a hook for Podman containers. For more details on the syntax of the JSON files and the semantics of hook injection, see `oci-hooks(5)`. Podman and libpod currently support both the 1.0.0 and 0.1.0 hook schemas, although the 0.1.0 schema is deprecated.
|
Each `*.json` file in the path configures a hook for Podman containers. For more details on the syntax of the JSON files and the semantics of hook injection, see `oci-hooks(5)`. Podman and libpod currently support both the 1.0.0 and 0.1.0 hook schemas, although the 0.1.0 schema is deprecated.
|
||||||
|
@ -187,7 +187,7 @@ func (c *Container) StopWithTimeout(timeout uint) error {
|
|||||||
c.state.State == ContainerStateExited {
|
c.state.State == ContainerStateExited {
|
||||||
return ErrCtrStopped
|
return ErrCtrStopped
|
||||||
}
|
}
|
||||||
defer c.newContainerEvent(events.Stop)
|
|
||||||
return c.stop(timeout)
|
return c.stop(timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1044,7 +1044,13 @@ func (c *Container) stop(timeout uint) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Wait until we have an exit file, and sync once we do
|
// Wait until we have an exit file, and sync once we do
|
||||||
return c.waitForExitFileAndSync()
|
if err := c.waitForExitFileAndSync(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
c.newContainerEvent(events.Stop)
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Internal, non-locking function to pause a container
|
// Internal, non-locking function to pause a container
|
||||||
|
@ -14,6 +14,8 @@ const (
|
|||||||
LogFile EventerType = iota
|
LogFile EventerType = iota
|
||||||
// Journald indicates journald should be used to log events
|
// Journald indicates journald should be used to log events
|
||||||
Journald EventerType = iota
|
Journald EventerType = iota
|
||||||
|
// Null is a no-op events logger. It does not read or write events.
|
||||||
|
Null EventerType = iota
|
||||||
)
|
)
|
||||||
|
|
||||||
// Event describes the attributes of a libpod event
|
// Event describes the attributes of a libpod event
|
||||||
|
@ -16,11 +16,30 @@ var ErrNoJournaldLogging = errors.New("No support for journald logging")
|
|||||||
|
|
||||||
// String returns a string representation of EventerType
|
// String returns a string representation of EventerType
|
||||||
func (et EventerType) String() string {
|
func (et EventerType) String() string {
|
||||||
if et == LogFile {
|
switch et {
|
||||||
|
case LogFile:
|
||||||
return "file"
|
return "file"
|
||||||
|
case Journald:
|
||||||
}
|
|
||||||
return "journald"
|
return "journald"
|
||||||
|
case Null:
|
||||||
|
return "none"
|
||||||
|
default:
|
||||||
|
return "invalid"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsValidEventer checks if the given string is a valid eventer type.
|
||||||
|
func IsValidEventer(eventer string) bool {
|
||||||
|
switch eventer {
|
||||||
|
case LogFile.String():
|
||||||
|
return true
|
||||||
|
case Journald.String():
|
||||||
|
return true
|
||||||
|
case Null.String():
|
||||||
|
return true
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewEvent creates a event struct and populates with
|
// NewEvent creates a event struct and populates with
|
||||||
|
@ -18,8 +18,10 @@ func NewEventer(options EventerOptions) (eventer Eventer, err error) {
|
|||||||
}
|
}
|
||||||
case strings.ToUpper(LogFile.String()):
|
case strings.ToUpper(LogFile.String()):
|
||||||
eventer = EventLogFile{options}
|
eventer = EventLogFile{options}
|
||||||
|
case strings.ToUpper(Null.String()):
|
||||||
|
eventer = NewNullEventer()
|
||||||
default:
|
default:
|
||||||
return eventer, errors.Errorf("unknown event logger type: %s", strings.ToUpper(options.EventerType))
|
return nil, errors.Errorf("unknown event logger type: %s", strings.ToUpper(options.EventerType))
|
||||||
}
|
}
|
||||||
return eventer, nil
|
return eventer, nil
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ func (e EventLogFile) Read(options ReadOptions) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
switch event.Type {
|
switch event.Type {
|
||||||
case Image, Volume, Pod, Container:
|
case Image, Volume, Pod, System, Container:
|
||||||
// no-op
|
// no-op
|
||||||
default:
|
default:
|
||||||
return errors.Errorf("event type %s is not valid in %s", event.Type.String(), e.options.LogFilePath)
|
return errors.Errorf("event type %s is not valid in %s", event.Type.String(), e.options.LogFilePath)
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/containers/image/manifest"
|
"github.com/containers/image/manifest"
|
||||||
|
"github.com/containers/libpod/libpod/events"
|
||||||
"github.com/containers/libpod/pkg/namespaces"
|
"github.com/containers/libpod/pkg/namespaces"
|
||||||
"github.com/containers/libpod/pkg/rootless"
|
"github.com/containers/libpod/pkg/rootless"
|
||||||
"github.com/containers/libpod/pkg/util"
|
"github.com/containers/libpod/pkg/util"
|
||||||
@ -421,6 +422,25 @@ func WithDefaultInfraCommand(cmd string) RuntimeOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithEventsLogger sets the events backend to use.
|
||||||
|
// Currently supported values are "file" for file backend and "journald" for
|
||||||
|
// journald backend.
|
||||||
|
func WithEventsLogger(logger string) RuntimeOption {
|
||||||
|
return func(rt *Runtime) error {
|
||||||
|
if rt.valid {
|
||||||
|
return ErrRuntimeFinalized
|
||||||
|
}
|
||||||
|
|
||||||
|
if !events.IsValidEventer(logger) {
|
||||||
|
return errors.Wrapf(ErrInvalidArg, "%q is not a valid events backend", logger)
|
||||||
|
}
|
||||||
|
|
||||||
|
rt.config.EventsLogger = logger
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WithRenumber instructs libpod to perform a lock renumbering while
|
// WithRenumber instructs libpod to perform a lock renumbering while
|
||||||
// initializing. This will handle migrations from early versions of libpod with
|
// initializing. This will handle migrations from early versions of libpod with
|
||||||
// file locks to newer versions with SHM locking, as well as changes in the
|
// file locks to newer versions with SHM locking, as well as changes in the
|
||||||
|
@ -376,14 +376,9 @@ func (r *Runtime) removeContainer(ctx context.Context, c *Container, force bool,
|
|||||||
|
|
||||||
// Check that the container's in a good state to be removed
|
// Check that the container's in a good state to be removed
|
||||||
if c.state.State == ContainerStateRunning {
|
if c.state.State == ContainerStateRunning {
|
||||||
if err := r.ociRuntime.stopContainer(c, c.StopTimeout()); err != nil {
|
if err := c.stop(c.StopTimeout()); err != nil {
|
||||||
return errors.Wrapf(err, "cannot remove container %s as it could not be stopped", c.ID())
|
return errors.Wrapf(err, "cannot remove container %s as it could not be stopped", c.ID())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to update container state to make sure we know it's stopped
|
|
||||||
if err := c.waitForExitFileAndSync(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that all of our exec sessions have finished
|
// Check that all of our exec sessions have finished
|
||||||
|
@ -165,6 +165,9 @@ func (c *CreateConfig) createExitCommand(runtime *libpod.Runtime) ([]string, err
|
|||||||
for _, opt := range config.StorageConfig.GraphDriverOptions {
|
for _, opt := range config.StorageConfig.GraphDriverOptions {
|
||||||
command = append(command, []string{"--storage-opt", opt}...)
|
command = append(command, []string{"--storage-opt", opt}...)
|
||||||
}
|
}
|
||||||
|
if config.EventsLogger != "" {
|
||||||
|
command = append(command, []string{"--events-backend", config.EventsLogger}...)
|
||||||
|
}
|
||||||
|
|
||||||
if c.Syslog {
|
if c.Syslog {
|
||||||
command = append(command, "--syslog", "true")
|
command = append(command, "--syslog", "true")
|
||||||
|
@ -405,7 +405,7 @@ func (p *PodmanTestIntegration) BuildImage(dockerfile, imageName string, layers
|
|||||||
|
|
||||||
// PodmanPID execs podman and returns its PID
|
// PodmanPID execs podman and returns its PID
|
||||||
func (p *PodmanTestIntegration) PodmanPID(args []string) (*PodmanSessionIntegration, int) {
|
func (p *PodmanTestIntegration) PodmanPID(args []string) (*PodmanSessionIntegration, int) {
|
||||||
podmanOptions := p.MakeOptions(args)
|
podmanOptions := p.MakeOptions(args, false)
|
||||||
fmt.Printf("Running: %s %s\n", p.PodmanBinary, strings.Join(podmanOptions, " "))
|
fmt.Printf("Running: %s %s\n", p.PodmanBinary, strings.Join(podmanOptions, " "))
|
||||||
command := exec.Command(p.PodmanBinary, podmanOptions...)
|
command := exec.Command(p.PodmanBinary, podmanOptions...)
|
||||||
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
|
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
|
||||||
|
@ -30,13 +30,20 @@ func SkipIfRootless() {
|
|||||||
|
|
||||||
// Podman is the exec call to podman on the filesystem
|
// Podman is the exec call to podman on the filesystem
|
||||||
func (p *PodmanTestIntegration) Podman(args []string) *PodmanSessionIntegration {
|
func (p *PodmanTestIntegration) Podman(args []string) *PodmanSessionIntegration {
|
||||||
podmanSession := p.PodmanBase(args, false)
|
podmanSession := p.PodmanBase(args, false, false)
|
||||||
return &PodmanSessionIntegration{podmanSession}
|
return &PodmanSessionIntegration{podmanSession}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PodmanNoCache calls podman with out adding the imagecache
|
// PodmanNoCache calls podman with out adding the imagecache
|
||||||
func (p *PodmanTestIntegration) PodmanNoCache(args []string) *PodmanSessionIntegration {
|
func (p *PodmanTestIntegration) PodmanNoCache(args []string) *PodmanSessionIntegration {
|
||||||
podmanSession := p.PodmanBase(args, true)
|
podmanSession := p.PodmanBase(args, true, false)
|
||||||
|
return &PodmanSessionIntegration{podmanSession}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PodmanNoEvents calls the Podman command without an imagecache and without an
|
||||||
|
// events backend. It is used mostly for caching and uncaching images.
|
||||||
|
func (p *PodmanTestIntegration) PodmanNoEvents(args []string) *PodmanSessionIntegration {
|
||||||
|
podmanSession := p.PodmanBase(args, true, true)
|
||||||
return &PodmanSessionIntegration{podmanSession}
|
return &PodmanSessionIntegration{podmanSession}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +142,7 @@ func (p *PodmanTestIntegration) StopVarlink() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//MakeOptions assembles all the podman main options
|
//MakeOptions assembles all the podman main options
|
||||||
func (p *PodmanTestIntegration) makeOptions(args []string) []string {
|
func (p *PodmanTestIntegration) makeOptions(args []string, noEvents bool) []string {
|
||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +163,7 @@ func (p *PodmanTestIntegration) RestoreArtifactToCache(image string) error {
|
|||||||
dest := strings.Split(image, "/")
|
dest := strings.Split(image, "/")
|
||||||
destName := fmt.Sprintf("/tmp/%s.tar", strings.Replace(strings.Join(strings.Split(dest[len(dest)-1], "/"), ""), ":", "-", -1))
|
destName := fmt.Sprintf("/tmp/%s.tar", strings.Replace(strings.Join(strings.Split(dest[len(dest)-1], "/"), ""), ":", "-", -1))
|
||||||
p.CrioRoot = p.ImageCacheDir
|
p.CrioRoot = p.ImageCacheDir
|
||||||
restore := p.PodmanNoCache([]string{"load", "-q", "-i", destName})
|
restore := p.PodmanNoEvents([]string{"load", "-q", "-i", destName})
|
||||||
restore.WaitWithDefaultTimeout()
|
restore.WaitWithDefaultTimeout()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -23,19 +23,26 @@ func SkipIfRootless() {
|
|||||||
|
|
||||||
// Podman is the exec call to podman on the filesystem
|
// Podman is the exec call to podman on the filesystem
|
||||||
func (p *PodmanTestIntegration) Podman(args []string) *PodmanSessionIntegration {
|
func (p *PodmanTestIntegration) Podman(args []string) *PodmanSessionIntegration {
|
||||||
podmanSession := p.PodmanBase(args, false)
|
podmanSession := p.PodmanBase(args, false, false)
|
||||||
return &PodmanSessionIntegration{podmanSession}
|
return &PodmanSessionIntegration{podmanSession}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PodmanNoCache calls the podman command with no configured imagecache
|
// PodmanNoCache calls the podman command with no configured imagecache
|
||||||
func (p *PodmanTestIntegration) PodmanNoCache(args []string) *PodmanSessionIntegration {
|
func (p *PodmanTestIntegration) PodmanNoCache(args []string) *PodmanSessionIntegration {
|
||||||
podmanSession := p.PodmanBase(args, true)
|
podmanSession := p.PodmanBase(args, true, false)
|
||||||
|
return &PodmanSessionIntegration{podmanSession}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PodmanNoEvents calls the Podman command without an imagecache and without an
|
||||||
|
// events backend. It is used mostly for caching and uncaching images.
|
||||||
|
func (p *PodmanTestIntegration) PodmanNoEvents(args []string) *PodmanSessionIntegration {
|
||||||
|
podmanSession := p.PodmanBase(args, true, true)
|
||||||
return &PodmanSessionIntegration{podmanSession}
|
return &PodmanSessionIntegration{podmanSession}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PodmanAsUser is the exec call to podman on the filesystem with the specified uid/gid and environment
|
// PodmanAsUser is the exec call to podman on the filesystem with the specified uid/gid and environment
|
||||||
func (p *PodmanTestIntegration) PodmanAsUser(args []string, uid, gid uint32, cwd string, env []string) *PodmanSessionIntegration {
|
func (p *PodmanTestIntegration) PodmanAsUser(args []string, uid, gid uint32, cwd string, env []string) *PodmanSessionIntegration {
|
||||||
podmanSession := p.PodmanAsUserBase(args, uid, gid, cwd, env, false)
|
podmanSession := p.PodmanAsUserBase(args, uid, gid, cwd, env, false, false)
|
||||||
return &PodmanSessionIntegration{podmanSession}
|
return &PodmanSessionIntegration{podmanSession}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,14 +66,19 @@ func PodmanTestCreate(tempDir string) *PodmanTestIntegration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MakeOptions assembles all the podman main options
|
// MakeOptions assembles all the podman main options
|
||||||
func (p *PodmanTestIntegration) makeOptions(args []string) []string {
|
func (p *PodmanTestIntegration) makeOptions(args []string, noEvents bool) []string {
|
||||||
var debug string
|
var debug string
|
||||||
if _, ok := os.LookupEnv("DEBUG"); ok {
|
if _, ok := os.LookupEnv("DEBUG"); ok {
|
||||||
debug = "--log-level=debug --syslog=true "
|
debug = "--log-level=debug --syslog=true "
|
||||||
}
|
}
|
||||||
|
|
||||||
podmanOptions := strings.Split(fmt.Sprintf("%s--root %s --runroot %s --runtime %s --conmon %s --cni-config-dir %s --cgroup-manager %s --tmpdir %s",
|
eventsType := "file"
|
||||||
debug, p.CrioRoot, p.RunRoot, p.OCIRuntime, p.ConmonBinary, p.CNIConfigDir, p.CgroupManager, p.TmpDir), " ")
|
if noEvents {
|
||||||
|
eventsType = "none"
|
||||||
|
}
|
||||||
|
|
||||||
|
podmanOptions := strings.Split(fmt.Sprintf("%s--root %s --runroot %s --runtime %s --conmon %s --cni-config-dir %s --cgroup-manager %s --tmpdir %s --events-backend %s",
|
||||||
|
debug, p.CrioRoot, p.RunRoot, p.OCIRuntime, p.ConmonBinary, p.CNIConfigDir, p.CgroupManager, p.TmpDir, eventsType), " ")
|
||||||
if os.Getenv("HOOK_OPTION") != "" {
|
if os.Getenv("HOOK_OPTION") != "" {
|
||||||
podmanOptions = append(podmanOptions, os.Getenv("HOOK_OPTION"))
|
podmanOptions = append(podmanOptions, os.Getenv("HOOK_OPTION"))
|
||||||
}
|
}
|
||||||
@ -81,7 +93,7 @@ func (p *PodmanTestIntegration) RestoreArtifact(image string) error {
|
|||||||
fmt.Printf("Restoring %s...\n", image)
|
fmt.Printf("Restoring %s...\n", image)
|
||||||
dest := strings.Split(image, "/")
|
dest := strings.Split(image, "/")
|
||||||
destName := fmt.Sprintf("/tmp/%s.tar", strings.Replace(strings.Join(strings.Split(dest[len(dest)-1], "/"), ""), ":", "-", -1))
|
destName := fmt.Sprintf("/tmp/%s.tar", strings.Replace(strings.Join(strings.Split(dest[len(dest)-1], "/"), ""), ":", "-", -1))
|
||||||
restore := p.PodmanNoCache([]string{"load", "-q", "-i", destName})
|
restore := p.PodmanNoEvents([]string{"load", "-q", "-i", destName})
|
||||||
restore.Wait(90)
|
restore.Wait(90)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -93,7 +105,7 @@ func (p *PodmanTestIntegration) RestoreArtifactToCache(image string) error {
|
|||||||
destName := fmt.Sprintf("/tmp/%s.tar", strings.Replace(strings.Join(strings.Split(dest[len(dest)-1], "/"), ""), ":", "-", -1))
|
destName := fmt.Sprintf("/tmp/%s.tar", strings.Replace(strings.Join(strings.Split(dest[len(dest)-1], "/"), ""), ":", "-", -1))
|
||||||
|
|
||||||
p.CrioRoot = p.ImageCacheDir
|
p.CrioRoot = p.ImageCacheDir
|
||||||
restore := p.PodmanNoCache([]string{"load", "-q", "-i", destName})
|
restore := p.PodmanNoEvents([]string{"load", "-q", "-i", destName})
|
||||||
restore.WaitWithDefaultTimeout()
|
restore.WaitWithDefaultTimeout()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -750,9 +750,10 @@ USER mail`
|
|||||||
match, _ := session.GrepString("1.2.3.4")
|
match, _ := session.GrepString("1.2.3.4")
|
||||||
Expect(match).Should(BeTrue())
|
Expect(match).Should(BeTrue())
|
||||||
|
|
||||||
session = podmanTest.Podman([]string{"run", "--rm", "--http-proxy=false", ALPINE, "printenv", "http_proxy"})
|
session = podmanTest.Podman([]string{"run", "--http-proxy=false", ALPINE, "printenv", "http_proxy"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session.ExitCode()).To(Equal(1))
|
Expect(session.ExitCode()).To(Equal(1))
|
||||||
|
Expect(session.OutputToString()).To(Equal(""))
|
||||||
os.Unsetenv("http_proxy")
|
os.Unsetenv("http_proxy")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ var _ = Describe("PodmanTest test", func() {
|
|||||||
FakeOutputs["check"] = []string{"check"}
|
FakeOutputs["check"] = []string{"check"}
|
||||||
os.Setenv("HOOK_OPTION", "hook_option")
|
os.Setenv("HOOK_OPTION", "hook_option")
|
||||||
env := os.Environ()
|
env := os.Environ()
|
||||||
session := podmanTest.PodmanAsUserBase([]string{"check"}, 1000, 1000, "", env, true)
|
session := podmanTest.PodmanAsUserBase([]string{"check"}, 1000, 1000, "", env, true, false)
|
||||||
os.Unsetenv("HOOK_OPTION")
|
os.Unsetenv("HOOK_OPTION")
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session.Command.Process).ShouldNot(BeNil())
|
Expect(session.Command.Process).ShouldNot(BeNil())
|
||||||
|
@ -26,14 +26,14 @@ var (
|
|||||||
// PodmanTestCommon contains common functions will be updated later in
|
// PodmanTestCommon contains common functions will be updated later in
|
||||||
// the inheritance structs
|
// the inheritance structs
|
||||||
type PodmanTestCommon interface {
|
type PodmanTestCommon interface {
|
||||||
MakeOptions(args []string) []string
|
MakeOptions(args []string, noEvents bool) []string
|
||||||
WaitForContainer() bool
|
WaitForContainer() bool
|
||||||
WaitContainerReady(id string, expStr string, timeout int, step int) bool
|
WaitContainerReady(id string, expStr string, timeout int, step int) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// PodmanTest struct for command line options
|
// PodmanTest struct for command line options
|
||||||
type PodmanTest struct {
|
type PodmanTest struct {
|
||||||
PodmanMakeOptions func(args []string) []string
|
PodmanMakeOptions func(args []string, noEvents bool) []string
|
||||||
PodmanBinary string
|
PodmanBinary string
|
||||||
ArtifactPath string
|
ArtifactPath string
|
||||||
TempDir string
|
TempDir string
|
||||||
@ -59,15 +59,15 @@ type HostOS struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MakeOptions assembles all podman options
|
// MakeOptions assembles all podman options
|
||||||
func (p *PodmanTest) MakeOptions(args []string) []string {
|
func (p *PodmanTest) MakeOptions(args []string, noEvents bool) []string {
|
||||||
return p.PodmanMakeOptions(args)
|
return p.PodmanMakeOptions(args, noEvents)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PodmanAsUserBase exec podman as user. uid and gid is set for credentials usage. env is used
|
// PodmanAsUserBase exec podman as user. uid and gid is set for credentials usage. env is used
|
||||||
// to record the env for debugging
|
// to record the env for debugging
|
||||||
func (p *PodmanTest) PodmanAsUserBase(args []string, uid, gid uint32, cwd string, env []string, nocache bool) *PodmanSession {
|
func (p *PodmanTest) PodmanAsUserBase(args []string, uid, gid uint32, cwd string, env []string, nocache, noEvents bool) *PodmanSession {
|
||||||
var command *exec.Cmd
|
var command *exec.Cmd
|
||||||
podmanOptions := p.MakeOptions(args)
|
podmanOptions := p.MakeOptions(args, noEvents)
|
||||||
podmanBinary := p.PodmanBinary
|
podmanBinary := p.PodmanBinary
|
||||||
if p.RemoteTest {
|
if p.RemoteTest {
|
||||||
podmanBinary = p.RemotePodmanBinary
|
podmanBinary = p.RemotePodmanBinary
|
||||||
@ -105,8 +105,8 @@ func (p *PodmanTest) PodmanAsUserBase(args []string, uid, gid uint32, cwd string
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PodmanBase exec podman with default env.
|
// PodmanBase exec podman with default env.
|
||||||
func (p *PodmanTest) PodmanBase(args []string, nocache bool) *PodmanSession {
|
func (p *PodmanTest) PodmanBase(args []string, nocache, noEvents bool) *PodmanSession {
|
||||||
return p.PodmanAsUserBase(args, 0, 0, "", nil, nocache)
|
return p.PodmanAsUserBase(args, 0, 0, "", nil, nocache, noEvents)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WaitForContainer waits on a started container
|
// WaitForContainer waits on a started container
|
||||||
@ -124,7 +124,7 @@ func (p *PodmanTest) WaitForContainer() bool {
|
|||||||
// containers are currently running.
|
// containers are currently running.
|
||||||
func (p *PodmanTest) NumberOfContainersRunning() int {
|
func (p *PodmanTest) NumberOfContainersRunning() int {
|
||||||
var containers []string
|
var containers []string
|
||||||
ps := p.PodmanBase([]string{"ps", "-q"}, true)
|
ps := p.PodmanBase([]string{"ps", "-q"}, true, false)
|
||||||
ps.WaitWithDefaultTimeout()
|
ps.WaitWithDefaultTimeout()
|
||||||
Expect(ps.ExitCode()).To(Equal(0))
|
Expect(ps.ExitCode()).To(Equal(0))
|
||||||
for _, i := range ps.OutputToStringArray() {
|
for _, i := range ps.OutputToStringArray() {
|
||||||
@ -139,7 +139,7 @@ func (p *PodmanTest) NumberOfContainersRunning() int {
|
|||||||
// containers are currently defined.
|
// containers are currently defined.
|
||||||
func (p *PodmanTest) NumberOfContainers() int {
|
func (p *PodmanTest) NumberOfContainers() int {
|
||||||
var containers []string
|
var containers []string
|
||||||
ps := p.PodmanBase([]string{"ps", "-aq"}, true)
|
ps := p.PodmanBase([]string{"ps", "-aq"}, true, false)
|
||||||
ps.WaitWithDefaultTimeout()
|
ps.WaitWithDefaultTimeout()
|
||||||
Expect(ps.ExitCode()).To(Equal(0))
|
Expect(ps.ExitCode()).To(Equal(0))
|
||||||
for _, i := range ps.OutputToStringArray() {
|
for _, i := range ps.OutputToStringArray() {
|
||||||
@ -154,7 +154,7 @@ func (p *PodmanTest) NumberOfContainers() int {
|
|||||||
// pods are currently defined.
|
// pods are currently defined.
|
||||||
func (p *PodmanTest) NumberOfPods() int {
|
func (p *PodmanTest) NumberOfPods() int {
|
||||||
var pods []string
|
var pods []string
|
||||||
ps := p.PodmanBase([]string{"pod", "ps", "-q"}, true)
|
ps := p.PodmanBase([]string{"pod", "ps", "-q"}, true, false)
|
||||||
ps.WaitWithDefaultTimeout()
|
ps.WaitWithDefaultTimeout()
|
||||||
Expect(ps.ExitCode()).To(Equal(0))
|
Expect(ps.ExitCode()).To(Equal(0))
|
||||||
for _, i := range ps.OutputToStringArray() {
|
for _, i := range ps.OutputToStringArray() {
|
||||||
@ -170,7 +170,7 @@ func (p *PodmanTest) NumberOfPods() int {
|
|||||||
func (p *PodmanTest) GetContainerStatus() string {
|
func (p *PodmanTest) GetContainerStatus() string {
|
||||||
var podmanArgs = []string{"ps"}
|
var podmanArgs = []string{"ps"}
|
||||||
podmanArgs = append(podmanArgs, "--all", "--format={{.Status}}")
|
podmanArgs = append(podmanArgs, "--all", "--format={{.Status}}")
|
||||||
session := p.PodmanBase(podmanArgs, true)
|
session := p.PodmanBase(podmanArgs, true, false)
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
return session.OutputToString()
|
return session.OutputToString()
|
||||||
}
|
}
|
||||||
@ -178,7 +178,7 @@ func (p *PodmanTest) GetContainerStatus() string {
|
|||||||
// WaitContainerReady waits process or service inside container start, and ready to be used.
|
// WaitContainerReady waits process or service inside container start, and ready to be used.
|
||||||
func (p *PodmanTest) WaitContainerReady(id string, expStr string, timeout int, step int) bool {
|
func (p *PodmanTest) WaitContainerReady(id string, expStr string, timeout int, step int) bool {
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
s := p.PodmanBase([]string{"logs", id}, true)
|
s := p.PodmanBase([]string{"logs", id}, true, false)
|
||||||
s.WaitWithDefaultTimeout()
|
s.WaitWithDefaultTimeout()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
@ -191,7 +191,7 @@ func (p *PodmanTest) WaitContainerReady(id string, expStr string, timeout int, s
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
time.Sleep(time.Duration(step) * time.Second)
|
time.Sleep(time.Duration(step) * time.Second)
|
||||||
s = p.PodmanBase([]string{"logs", id}, true)
|
s = p.PodmanBase([]string{"logs", id}, true, false)
|
||||||
s.WaitWithDefaultTimeout()
|
s.WaitWithDefaultTimeout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ func FakePodmanTestCreate() *FakePodmanTest {
|
|||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *FakePodmanTest) makeOptions(args []string) []string {
|
func (p *FakePodmanTest) makeOptions(args []string, noEvents bool) []string {
|
||||||
return FakeOutputs[strings.Join(args, " ")]
|
return FakeOutputs[strings.Join(args, " ")]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user