Skip to content

Commit

Permalink
login: Change LoginToCentOS to LoginToCentOSAsRoot
Browse files Browse the repository at this point in the history
Since we only log in as `root` - simply `LoginToCentOS`
and rename it to match its abilities.

Signed-off-by: Orel Misan <[email protected]>
  • Loading branch information
orelmisan committed Feb 19, 2024
1 parent 33dbcf7 commit 4dfe5e3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
8 changes: 3 additions & 5 deletions pkg/internal/checkup/executor/console/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"google.golang.org/grpc/codes"
)

func (e Expecter) LoginToCentOS(username, password string) error {
func (e Expecter) LoginToCentOSAsRoot(password string) error {
const (
connectionTimeout = 10 * time.Second
promptTimeout = 5 * time.Second
Expand All @@ -47,9 +47,7 @@ func (e Expecter) LoginToCentOS(username, password string) error {
}

// Do not login, if we already logged in
loggedInPromptRegex := fmt.Sprintf(
`(\[%s@(localhost|centos|%s) ~\]\$ |\[root@(localhost|centos|%s) ~\]\# )`, username, e.vmiName, e.vmiName,
)
loggedInPromptRegex := fmt.Sprintf(`(\[root@(localhost|centos|%s) ~\]\# )`, e.vmiName)
b := []expect.Batcher{
&expect.BSnd{S: "\n"},
&expect.BExp{R: loggedInPromptRegex},
Expand All @@ -67,7 +65,7 @@ func (e Expecter) LoginToCentOS(username, password string) error {
// Using only "login: " would match things like "Last failed login: Tue Jun 9 22:25:30 UTC 2020 on ttyS0"
// and in case the VM's did not get hostname form DHCP server try the default hostname
R: regexp.MustCompile(fmt.Sprintf(`(localhost|centos|%s) login: `, e.vmiName)),
S: fmt.Sprintf("%s\n", username),
S: "root\n",
T: expect.Next(),
Rt: 10,
},
Expand Down
4 changes: 1 addition & 3 deletions pkg/internal/checkup/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ type vmiSerialConsoleClient interface {
type Executor struct {
vmiSerialClient vmiSerialConsoleClient
namespace string
vmiUsername string
vmiPassword string
OslatDuration time.Duration
}
Expand All @@ -49,7 +48,6 @@ func New(client vmiSerialConsoleClient, namespace string, cfg config.Config) Exe
return Executor{
vmiSerialClient: client,
namespace: namespace,
vmiUsername: config.VMIUsername,
vmiPassword: config.VMIPassword,
OslatDuration: cfg.OslatDuration,
}
Expand All @@ -58,7 +56,7 @@ func New(client vmiSerialConsoleClient, namespace string, cfg config.Config) Exe
func (e Executor) Execute(ctx context.Context, vmiUnderTestName string) (status.Results, error) {
log.Printf("Login to VMI under test...")
vmiUnderTestConsoleExpecter := console.NewExpecter(e.vmiSerialClient, e.namespace, vmiUnderTestName)
if err := vmiUnderTestConsoleExpecter.LoginToCentOS(e.vmiUsername, e.vmiPassword); err != nil {
if err := vmiUnderTestConsoleExpecter.LoginToCentOSAsRoot(e.vmiPassword); err != nil {
return status.Results{}, fmt.Errorf("failed to login to VMI \"%s/%s\": %w", e.namespace, vmiUnderTestName, err)
}

Expand Down
1 change: 0 additions & 1 deletion pkg/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const (
)

const (
VMIUsername = "root"
VMIPassword = "redhat" // #nosec

VMUnderTestDefaultContainerDiskImage = "quay.io/kiagnose/kubevirt-realtime-checkup-vm:main"
Expand Down

0 comments on commit 4dfe5e3

Please sign in to comment.