|
| 1 | +package chaos |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "github.com/docker/docker/api/types/container" |
| 7 | + "github.com/docker/docker/api/types/mount" |
| 8 | + "github.com/google/uuid" |
| 9 | + "github.com/smartcontractkit/chainlink-testing-framework/framework" |
| 10 | + "github.com/testcontainers/testcontainers-go" |
| 11 | + "strings" |
| 12 | +) |
| 13 | + |
| 14 | +func ExecPumba(command string) (func(), error) { |
| 15 | + ctx := context.Background() |
| 16 | + cmd := strings.Split(command, " ") |
| 17 | + pumbaReq := testcontainers.ContainerRequest{ |
| 18 | + Name: fmt.Sprintf("chaos-%s", uuid.NewString()[0:5]), |
| 19 | + Image: "gaiaadm/pumba", |
| 20 | + Labels: framework.DefaultTCLabels(), |
| 21 | + Privileged: true, |
| 22 | + Cmd: cmd, |
| 23 | + HostConfigModifier: func(h *container.HostConfig) { |
| 24 | + h.Mounts = []mount.Mount{ |
| 25 | + { |
| 26 | + Type: "bind", |
| 27 | + Source: "/var/run/docker.sock", |
| 28 | + Target: "/var/run/docker.sock", |
| 29 | + ReadOnly: true, |
| 30 | + }, |
| 31 | + } |
| 32 | + }, |
| 33 | + } |
| 34 | + pumbaContainer, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ |
| 35 | + ContainerRequest: pumbaReq, |
| 36 | + Started: true, |
| 37 | + }) |
| 38 | + if err != nil { |
| 39 | + return nil, fmt.Errorf("failed to start pumba chaos container: %w", err) |
| 40 | + } |
| 41 | + framework.L.Info().Msg("Pumba chaos started") |
| 42 | + return func() { |
| 43 | + _ = pumbaContainer.Terminate(ctx) |
| 44 | + }, nil |
| 45 | +} |
0 commit comments