-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "feat(troubleshoot): add filesystem latency check"" (#…
…1030) * Revert "Revert "feat(troubleshoot): add filesystem latency check" (#1024)" This reverts commit 760c3be. * fix preflight * Update pkg/preflights/host-preflight.yaml Co-authored-by: Alex Parker <[email protected]> * feedback * Update pkg/preflights/host-preflight.yaml Co-authored-by: Alex Parker <[email protected]> --------- Co-authored-by: Alex Parker <[email protected]>
- Loading branch information
Showing
14 changed files
with
548 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package docker | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
type Docker struct { | ||
client string | ||
t *testing.T | ||
} | ||
|
||
func NewCLI(t *testing.T) *Docker { | ||
client, err := exec.LookPath("docker") | ||
if err != nil { | ||
t.Fatalf("failed to find docker in path: %v", err) | ||
} | ||
return &Docker{ | ||
client: client, | ||
t: t, | ||
} | ||
} | ||
|
||
type Container struct { | ||
Image string | ||
Volumes []string | ||
|
||
id string | ||
t *testing.T | ||
} | ||
|
||
func NewContainer(t *testing.T) *Container { | ||
return &Container{ | ||
id: generateID(), | ||
t: t, | ||
} | ||
} | ||
|
||
func (c *Container) WithImage(image string) *Container { | ||
c.Image = image | ||
return c | ||
} | ||
|
||
func (c *Container) WithECBinary() *Container { | ||
path, err := filepath.Abs("../output/bin/embedded-cluster") | ||
if err != nil { | ||
c.t.Fatalf("failed to get absolute path to embedded-cluster binary: %v", err) | ||
} | ||
_, err = os.Stat(path) | ||
if err != nil { | ||
c.t.Fatalf("failed to find embedded-cluster binary: %v", err) | ||
} | ||
err = os.Chmod(path, 0755) | ||
if err != nil { | ||
c.t.Fatalf("failed to chmod embedded-cluster binary: %v", err) | ||
} | ||
return c.WithVolume(fmt.Sprintf("%s:%s", path, c.GetECBinaryPath())) | ||
} | ||
|
||
func (c *Container) GetECBinaryPath() string { | ||
return "/ec/bin/embedded-cluster" | ||
} | ||
|
||
func (c *Container) WithLicense(path string) *Container { | ||
path, err := filepath.Abs(path) | ||
if err != nil { | ||
c.t.Fatalf("failed to get absolute path to license file: %v", err) | ||
} | ||
_, err = os.Stat(path) | ||
if err != nil { | ||
c.t.Fatalf("failed to find embedded-cluster binary: %v", err) | ||
} | ||
return c.WithVolume(fmt.Sprintf("%s:%s", path, c.GetLicensePath())) | ||
} | ||
|
||
func (c *Container) GetLicensePath() string { | ||
return "/ec/license.yaml" | ||
} | ||
|
||
func (c *Container) WithVolume(volume string) *Container { | ||
c.Volumes = append(c.Volumes, volume) | ||
return c | ||
} | ||
|
||
func (c *Container) Start(cli *Docker) { | ||
execCmd := exec.Command( | ||
cli.client, "run", "--rm", "-d", "-w", "/ec", "--platform=linux/amd64", "--privileged", | ||
"--name", c.id, | ||
) | ||
for _, volume := range c.Volumes { | ||
execCmd.Args = append(execCmd.Args, "-v", volume) | ||
} | ||
execCmd.Args = append(execCmd.Args, c.Image) | ||
execCmd.Args = append(execCmd.Args, "sh", "-c", "while true; do sleep 1; done") | ||
c.t.Logf("starting container: docker %s", strings.Join(execCmd.Args, " ")) | ||
err := execCmd.Run() | ||
if err != nil { | ||
c.t.Fatalf("failed to start container: %v", err) | ||
} | ||
} | ||
|
||
func (c *Container) Destroy(cli *Docker) { | ||
execCmd := exec.Command(cli.client, "rm", "-f", c.id) | ||
err := execCmd.Run() | ||
if err != nil { | ||
c.t.Fatalf("failed to destroy container: %v", err) | ||
} | ||
} | ||
|
||
func (c *Container) Exec(cli *Docker, cmd string) (string, string, error) { | ||
args := []string{"exec", c.id, "sh", "-c", cmd} | ||
execCmd := exec.Command(cli.client, args...) | ||
c.t.Logf("executing command: docker %s", strings.Join(execCmd.Args, " ")) | ||
var stdout, stderr bytes.Buffer | ||
execCmd.Stdout = &stdout | ||
execCmd.Stderr = &stderr | ||
err := execCmd.Run() | ||
return stdout.String(), stderr.String(), err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package docker | ||
|
||
import "math/rand" | ||
|
||
var alphabet = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") | ||
|
||
func generateID() string { | ||
b := make([]rune, 32) | ||
for i := range b { | ||
b[i] = alphabet[rand.Intn(len(alphabet))] | ||
} | ||
return "ece2e-" + string(b) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package e2e | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/replicatedhq/embedded-cluster/e2e/docker" | ||
"github.com/replicatedhq/embedded-cluster/pkg/preflights" | ||
) | ||
|
||
func TestPreflights(t *testing.T) { | ||
t.Parallel() | ||
|
||
cli := docker.NewCLI(t) | ||
|
||
container := docker.NewContainer(t). | ||
WithImage("debian:bookworm-slim"). | ||
WithECBinary() | ||
if licensePath := os.Getenv("LICENSE_PATH"); licensePath != "" { | ||
t.Logf("using license %s", licensePath) | ||
container = container.WithLicense(licensePath) | ||
} | ||
container.Start(cli) | ||
|
||
t.Cleanup(func() { | ||
container.Destroy(cli) | ||
}) | ||
|
||
_, stderr, err := container.Exec(cli, | ||
"apt-get update && apt-get install -y apt-utils kmod", | ||
) | ||
if err != nil { | ||
t.Fatalf("failed to install deps: err=%v, stderr=%s", err, stderr) | ||
} | ||
|
||
runCmd := fmt.Sprintf("%s install run-preflights --no-prompt", container.GetECBinaryPath()) | ||
if os.Getenv("LICENSE_PATH") != "" { | ||
runCmd = fmt.Sprintf("%s --license %s", runCmd, container.GetLicensePath()) | ||
} | ||
|
||
// we are more interested in the results | ||
runStdout, runStderr, runErr := container.Exec(cli, runCmd) | ||
|
||
stdout, stderr, err := container.Exec(cli, | ||
"cat /var/lib/embedded-cluster/support/host-preflight-results.json", | ||
) | ||
if err != nil { | ||
t.Logf("run-preflights: err=%v, stdout=%s, stderr=%s", runErr, runStdout, runStderr) | ||
t.Fatalf("failed to get preflight results: err=%v, stderr=%s", err, stderr) | ||
} | ||
|
||
results, err := preflights.OutputFromReader(strings.NewReader(stdout)) | ||
if err != nil { | ||
t.Fatalf("failed to parse preflight results: %v", err) | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
assert func(t *testing.T, results *preflights.Output) | ||
}{ | ||
{ | ||
name: "Should contain fio results", | ||
assert: func(t *testing.T, results *preflights.Output) { | ||
for _, res := range results.Pass { | ||
if res.Title == "Filesystem Write Latency" { | ||
t.Logf("fio test passed: %s", res.Message) | ||
return | ||
} | ||
} | ||
for _, res := range results.Fail { | ||
if !strings.Contains(res.Message, "Write latency is high") { | ||
t.Errorf("fio test failed: %s", res.Message) | ||
} | ||
// as long as fio ran successfully, we're good | ||
t.Logf("fio test failed: %s", res.Message) | ||
} | ||
|
||
t.Errorf("fio test not found") | ||
}, | ||
}, | ||
{ | ||
name: "Should not contain unexpected failures", | ||
assert: func(t *testing.T, results *preflights.Output) { | ||
expected := map[string]bool{ | ||
// TODO: work to remove these | ||
"System Clock": true, | ||
"'devices' Cgroup Controller": true, | ||
"Default Route": true, | ||
"API Access": true, | ||
"Proxy Registry Access": true, | ||
// as long as fio ran successfully, we're good | ||
"Filesystem Write Latency": true, | ||
} | ||
for _, res := range results.Fail { | ||
if !expected[res.Title] { | ||
t.Errorf("unexpected failure: %q, %q", res.Title, res.Message) | ||
} else { | ||
t.Logf("found expected failure: %q, %q", res.Title, res.Message) | ||
} | ||
} | ||
}, | ||
}, | ||
{ | ||
name: "Should not contain unexpected warnings", | ||
assert: func(t *testing.T, results *preflights.Output) { | ||
expected := map[string]bool{} | ||
for _, res := range results.Warn { | ||
if !expected[res.Title] { | ||
t.Errorf("unexpected warning: %q, %q", res.Title, res.Message) | ||
} else { | ||
t.Logf("found expected warning: %q, %q", res.Title, res.Message) | ||
} | ||
} | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tt.assert(t, results) | ||
}) | ||
} | ||
} |
Oops, something went wrong.