Skip to content

Commit

Permalink
test: Configure console on login
Browse files Browse the repository at this point in the history
`stty columns 200` to avoid console wraps.
`dmesg -n 1` to avoid dmesg from trashing tty1.

Signed-off-by: Alona Kaplan <[email protected]>
  • Loading branch information
AlonaKaplan committed Aug 5, 2020
1 parent 98765ff commit 6dea670
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2852,6 +2852,27 @@ func CheckForTextExpecter(vmi *v1.VirtualMachineInstance, expected []expect.Batc
return err
}

func configureConsole(expecter expect.Expecter, prompt string, shouldSudo bool) error {
sudoString := ""
if shouldSudo {
sudoString = "sudo "
}
batch := append([]expect.Batcher{
&expect.BSnd{S: "stty columns 500\n"},
&expect.BExp{R: prompt},
&expect.BSnd{S: "echo $?\n"},
&expect.BExp{R: retcode("0")},
&expect.BSnd{S: fmt.Sprintf("%sdmesg -n 1\n", sudoString)},
&expect.BExp{R: prompt},
&expect.BSnd{S: "echo $?\n"},
&expect.BExp{R: retcode("0")}})
resp, err := expecter.ExpectBatch(batch, 30*time.Second)
if err != nil {
log.DefaultLogger().Infof("%v", resp)
}
return err
}

func configureIPv6OnVMI(vmi *v1.VirtualMachineInstance, expecter expect.Expecter, virtClient kubecli.KubevirtClient, prompt string) error {
hasEth0Iface := func(vmi *v1.VirtualMachineInstance) bool {
hasNetEth0Batch := append([]expect.Batcher{
Expand Down Expand Up @@ -2953,6 +2974,12 @@ func LoggedInCirrosExpecter(vmi *v1.VirtualMachineInstance) (expect.Expecter, er
return nil, err
}

err = configureConsole(expecter, "\\$ ", true)
if err != nil {
expecter.Close()
return nil, err
}

return expecter, configureIPv6OnVMI(vmi, expecter, virtClient, "\\$ ")
}

Expand All @@ -2976,6 +3003,12 @@ func LoggedInAlpineExpecter(vmi *v1.VirtualMachineInstance) (expect.Expecter, er
expecter.Close()
return nil, err
}

err = configureConsole(expecter, "localhost:~\\#", false)
if err != nil {
expecter.Close()
return nil, err
}
return expecter, err
}

Expand Down Expand Up @@ -3025,6 +3058,12 @@ func LoggedInFedoraExpecter(vmi *v1.VirtualMachineInstance) (expect.Expecter, er
return expecter, err
}

err = configureConsole(expecter, "\\#", false)
if err != nil {
expecter.Close()
return nil, err
}

return expecter, configureIPv6OnVMI(vmi, expecter, virtClient, "\\#")
}

Expand Down

0 comments on commit 6dea670

Please sign in to comment.