Skip to content

Address CMX flakiness on reboot #2341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 78 additions & 13 deletions e2e/cluster/cmx/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Node struct {
ID string `json:"id"`
Name string `json:"name"`
NetworkID string `json:"network_id"`
Status string `json:"status"`

privateIP string `json:"-"`
sshEndpoint string `json:"-"`
Expand Down Expand Up @@ -271,30 +272,94 @@ func (c *Cluster) waitUntilAirgapped(node int) error {
}

func (c *Cluster) WaitForReboot() {
time.Sleep(30 * time.Second)
for i := range c.Nodes {
c.waitForSSH(i)
c.waitForClockSync(i)
c.waitForRunning()
c.waitForSSH()
c.waitForClockSync()
}

func (c *Cluster) waitForRunning() {
timeout := time.After(5 * time.Minute)
tick := time.Tick(10 * time.Second)

for {
select {
case <-timeout:
c.t.Fatalf("timed out waiting for nodes to be running after 5 minutes")

case <-tick:
if err := c.refreshNodes(); err != nil {
c.t.Logf("failed to refresh nodes: %v", err)
continue
}

for i, node := range c.Nodes {
if node.Status != "running" {
c.t.Logf("waiting for node %d (%s) to be running (status: %s)", i, node.ID, node.Status)
continue
}
}

c.t.Logf("all nodes are running")
return
}
}
}

func (c *Cluster) waitForSSH(node int) {
if err := waitForSSH(c.Nodes[node], c.t); err != nil {
c.t.Fatalf("failed to wait for ssh to be available on node %d: %v", node, err)
func (c *Cluster) refreshNodes() error {
output, err := exec.Command("replicated", "vm", "ls", "-ojson").Output()
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
return fmt.Errorf("list nodes: %w: stderr: %s: stdout: %s", err, string(exitErr.Stderr), string(output))
}
return fmt.Errorf("list nodes: %w: stdout: %s", err, string(output))
}

var allNodes []Node
if err := json.Unmarshal(output, &allNodes); err != nil {
return fmt.Errorf("unmarshal nodes: %v: %s", err, string(output))
}

allNodesMap := make(map[string]Node)
for _, node := range allNodes {
allNodesMap[node.ID] = node
}

for i, node := range c.Nodes {
if updated, ok := allNodesMap[node.ID]; ok {
c.Nodes[i] = updated
}
}

return nil
}

func (c *Cluster) waitForClockSync(node int) {
func (c *Cluster) waitForSSH() {
for i, node := range c.Nodes {
if err := waitForSSH(node, c.t); err != nil {
c.t.Fatalf("failed to wait for SSH to be available on node %d: %v", i, err)
}
}
}

func (c *Cluster) waitForClockSync() {
timeout := time.After(5 * time.Minute)
tick := time.Tick(time.Second)
tick := time.Tick(5 * time.Second)

for {
select {
case <-timeout:
stdout, stderr, err := c.RunCommandOnNode(node, []string{"timedatectl show -p NTP -p NTPSynchronized"})
c.t.Fatalf("timeout waiting for clock sync on node %d: %v: %s: %s", node, err, stdout, stderr)
c.t.Fatalf("timeout waiting for clock sync on all nodes")

case <-tick:
status, _, _ := c.RunCommandOnNode(node, []string{"timedatectl show -p NTP -p NTPSynchronized"})
if strings.Contains(status, "NTP=yes") && strings.Contains(status, "NTPSynchronized=yes") {
for i := range c.Nodes {
status, _, _ := c.RunCommandOnNode(i, []string{"timedatectl show -p NTP -p NTPSynchronized"})

if !strings.Contains(status, "NTP=yes") || !strings.Contains(status, "NTPSynchronized=yes") {
c.t.Logf("waiting for NTP=yes and NTPSynchronized=yes on node %d (status: %s)", i, status)
continue
}

c.t.Logf("clock synced on node %d (status: %s)", i, status)
return
}
}
Expand Down
Loading