Skip to content

Commit

Permalink
chore: rework test script
Browse files Browse the repository at this point in the history
  • Loading branch information
nixpig committed Oct 29, 2024
1 parent 71704c1 commit ac55284
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 34 deletions.
6 changes: 4 additions & 2 deletions internal/commands/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ func Delete(opts *DeleteOpts, log *zerolog.Logger, db *sql.DB) error {
return fmt.Errorf("container cannot be deleted in current state: %s", cntr.State.Status)
}

process, _ := os.FindProcess(cntr.State.PID)
process, err := os.FindProcess(cntr.State.PID)
if err != nil {
return fmt.Errorf("find container process: %w", err)
}
if process != nil {
process.Signal(syscall.Signal(9))
}
Expand All @@ -41,7 +44,6 @@ func Delete(opts *DeleteOpts, log *zerolog.Logger, db *sql.DB) error {
return errors.New("didn't delete container for whatever reason")
}

log.Info().Msg("execing poststop hooks")
if err := cntr.ExecHooks("poststop"); err != nil {
fmt.Println("failed to execute poststop hooks")
log.Warn().Err(err).Msg("failed to execute poststop hooks")
Expand Down
6 changes: 5 additions & 1 deletion internal/commands/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func Start(opts *StartOpts, log *zerolog.Logger, db *sql.DB) error {

// TODO: run DELETE tasks here, then...

log.Info().Msg("execing poststop hooks")
if err := cntr.ExecHooks("poststop"); err != nil {
fmt.Println("WARNING: failed to execute poststop hooks")
log.Warn().Err(err).Msg("failed to execute poststop hooks")
Expand All @@ -74,6 +73,11 @@ func Start(opts *StartOpts, log *zerolog.Logger, db *sql.DB) error {
}
defer conn.Close()

if err := cntr.ExecHooks("poststart"); err != nil {
log.Warn().Err(err).Msg("failed to execute poststart hooks")
// TODO: how to handle this (log a warning) from start command??
}

// FIXME: ?? when process starts, the PID in state should be updated to the process IN the container??

// cntr.State.Status = specs.StateStopped
Expand Down
9 changes: 2 additions & 7 deletions internal/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,6 @@ func (c *Container) Fork(opts *ForkOpts, log *zerolog.Logger, db *sql.DB) error
}
log.Info().Msg("UPDATED STATE FILE")

// if err := c.ExecHooks("poststart"); err != nil {
// log.Warn().Err(err).Msg("failed to execute poststart hooks")
// // TODO: how to handle this (log a warning) from start command??
// }

return nil
})

Expand Down Expand Up @@ -575,13 +570,13 @@ func (c *Container) Clean() error {
return os.RemoveAll(c.State.Bundle)
}

func (c *Container) ExecHooks(hook string) error {
func (c *Container) ExecHooks(lifecycleHook string) error {
if c.Spec.Hooks == nil {
return nil
}

var specHooks []specs.Hook
switch hook {
switch lifecycleHook {
case "prestart":
//lint:ignore SA1019 marked as deprecated, but still required by OCI Runtime integration tests
specHooks = c.Spec.Hooks.Prestart
Expand Down
5 changes: 3 additions & 2 deletions internal/container/lifecycle/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (

func ExecHooks(hooks []specs.Hook) error {
for _, h := range hooks {

ctx := context.Background()
var cancel context.CancelFunc
if h.Timeout != nil {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(
ctx,
time.Duration(*h.Timeout)*time.Second,
Expand All @@ -24,7 +25,7 @@ func ExecHooks(hooks []specs.Hook) error {
cmd.Env = h.Env

if err := cmd.Run(); err != nil {
return fmt.Errorf("exec hook: %w", err)
return fmt.Errorf("exec hook: %s %+v: %w", h.Path, h.Args, err)
}
}

Expand Down
68 changes: 46 additions & 22 deletions oci.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,48 @@
#!/bin/sh
echo "" > results.tap

RUNTIME=${RUNTIME:-./brownie}
./validation/default/default.t 2>&1 | tee -a results.tap
./validation/config_updates_without_affect/config_updates_without_affect.t 2>&1 | tee -a results.tap
./validation/create/create.t 2>&1 | tee -a results.tap
./validation/delete/delete.t 2>&1 | tee -a results.tap
./validation/hostname/hostname.t 2>&1 | tee -a results.tap
./validation/kill/kill.t 2>&1 | tee -a results.tap
./validation/kill_no_effect/kill_no_effect.t 2>&1 | tee -a results.tap
./validation/linux_devices/linux_devices.t 2>&1 | tee -a results.tap
./validation/linux_mount_label/linux_mount_label.t 2>&1 | tee -a results.tap
./validation/linux_rootfs_propagation/linux_rootfs_propagation.t 2>&1 | tee -a results.tap
./validation/linux_sysctl/linux_sysctl.t 2>&1 | tee -a results.tap
./validation/mounts/mounts.t 2>&1 | tee -a results.tap
# ./validation/pidfile/pidfile.t 2>&1 | tee -a results.tap
./validation/prestart/prestart.t 2>&1 | tee -a results.tap
./validation/prestart_fail/prestart_fail.t 2>&1 | tee -a results.tap
./validation/process/process.t 2>&1 | tee -a results.tap
./validation/process_capabilities/process_capabilities.t 2>&1 | tee -a results.tap
./validation/process_oom_score_adj/process_oom_score_adj.t 2>&1 | tee -a results.tap
./validation/start/start.t 2>&1 | tee -a results.tap
./validation/state/state.t 2>&1 | tee -a results.tap
(! grep -F "not ok" results.tap)
LOGDIR=$(dirname)/logs

tests=(
"default"
"config_updates_without_affect"
"create"
"delete"
"hostname"
"kill"
"kill_no_effect"
"linux_devices"
"linux_mount_label"
"linux_rootfs_propagation"
"linux_sysctl"
"mounts"
"prestart"
"prestart_fail"
"process"
"process_capabilities"
"process_oom_score_adj"
"start"
"state"
)

mkdir -p $LOGDIR

# run tests
for test in "${tests[@]}"; do
./validation/${test}/${test}.t 2>&1 | tee ${LOGDIR}/${test}.log
done

# check for failures
total_failures=0
for test in "${tests[@]}"; do
failures=$(grep -F "not ok" ${LOGDIR}/${test}.log | wc -l)

if [0 -ne $failures]; then
total_failures=$(($total_failures + $failures))
fi
done

if [0 -ne $total_failures]; then
exit 1
fi

0 comments on commit ac55284

Please sign in to comment.