Skip to content

Commit

Permalink
Merge pull request kubevirt#10434 from xpivarc/tests-drop-console-tests
Browse files Browse the repository at this point in the history
Drop similiar console tests
  • Loading branch information
kubevirt-bot authored Jan 11, 2024
2 parents a403b7c + 4f7cda3 commit fdce65d
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 208 deletions.
1 change: 0 additions & 1 deletion tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ go_test(
"canary_upgrade_test.go",
"clone_test.go",
"config_test.go",
"console_test.go",
"container_disk_test.go",
"dryrun_test.go",
"hyperv_test.go",
Expand Down
7 changes: 6 additions & 1 deletion tests/compute/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@ go_library(

go_test(
name = "go_default_test",
srcs = ["credentials_test.go"],
srcs = [
"console_test.go",
"credentials_test.go",
],
embed = [":go_default_library"],
deps = [
"//staging/src/kubevirt.io/api/core/v1:go_default_library",
"//staging/src/kubevirt.io/client-go/kubecli:go_default_library",
"//tests:go_default_library",
"//tests/console:go_default_library",
"//tests/framework/kubevirt:go_default_library",
"//tests/framework/matcher:go_default_library",
"//tests/libvmi:go_default_library",
"//tests/testsuite:go_default_library",
"//tests/util:go_default_library",
"//vendor/github.com/google/goexpect:go_default_library",
"//vendor/github.com/onsi/ginkgo/v2:go_default_library",
Expand Down
150 changes: 150 additions & 0 deletions tests/compute/console_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
* This file is part of the KubeVirt project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2017 Red Hat, Inc.
*
*/

package compute

import (
"context"
"io"
"time"

"kubevirt.io/kubevirt/tests/framework/kubevirt"

expect "github.com/google/goexpect"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
k8sv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"kubevirt.io/kubevirt/tests/testsuite"

v1 "kubevirt.io/api/core/v1"
"kubevirt.io/client-go/kubecli"

"kubevirt.io/kubevirt/tests"
"kubevirt.io/kubevirt/tests/console"
"kubevirt.io/kubevirt/tests/libvmi"
)

const startupTimeout = 30

var _ = SIGDescribe("[rfe_id:127][posneg:negative][crit:medium][vendor:[email protected]][level:component]Console", func() {

var virtClient kubecli.KubevirtClient

BeforeEach(func() {
virtClient = kubevirt.Client()
})

expectConsoleOutput := func(vmi *v1.VirtualMachineInstance, expected string) {
By("Checking that the console output equals to expected one")
ExpectWithOffset(1, console.SafeExpectBatch(vmi, []expect.Batcher{
&expect.BSnd{S: "\n"},
&expect.BExp{R: expected},
}, 120)).To(Succeed())
}

Describe("[rfe_id:127][posneg:negative][crit:medium][vendor:[email protected]][level:component]A new VirtualMachineInstance", func() {
Context("with a serial console", func() {
It("[test_id:1588]should return OS login", func() {
vmi := libvmi.NewCirros()
vmi = tests.RunVMIAndExpectLaunch(vmi, startupTimeout)
expectConsoleOutput(
vmi,
"login as 'cirros' user",
)
})
It("[test_id:1590]should be able to reconnect to console multiple times", func() {
vmi := libvmi.NewAlpine()
vmi = tests.RunVMIAndExpectLaunch(vmi, startupTimeout)

for i := 0; i < 5; i++ {
expectConsoleOutput(vmi, "login")
}
})

It("[test_id:1591]should close console connection when new console connection is opened", func() {
vmi := tests.RunVMIAndExpectLaunch(libvmi.NewAlpine(), startupTimeout)

By("opening 1st console connection")
stream, err := virtClient.VirtualMachineInstance(vmi.Namespace).SerialConsole(vmi.Name, &kubecli.SerialConsoleOptions{})
Expect(err).ToNot(HaveOccurred())
defer stream.AsConn().Close()

firstConsoleErrChan := make(chan error, 1)
outReader, outWriter := io.Pipe()
inReader, _ := io.Pipe()
go func() {
io.Copy(io.Discard, outReader)
}()
go func() {
firstConsoleErrChan <- stream.Stream(kubecli.StreamOptions{
In: inReader,
Out: outWriter,
})
}()

By("opening 2nd console connection")
expectConsoleOutput(vmi, "login")

By("expecting error on 1st console connection")
Eventually(firstConsoleErrChan, 1*time.Minute, 1*time.Second).Should(Receive(MatchError(ContainSubstring("EOF"))))
})

It("[test_id:1592]should wait until the virtual machine is in running state and return a stream interface", func() {
vmi := libvmi.NewAlpine()
By("Creating a new VirtualMachineInstance")
vmi, err := virtClient.VirtualMachineInstance(testsuite.GetTestNamespace(vmi)).Create(context.Background(), vmi)
Expect(err).ToNot(HaveOccurred())

By("and connecting to it very quickly. Hopefully the VM is not yet up")
_, err = virtClient.VirtualMachineInstance(vmi.Namespace).SerialConsole(vmi.Name, &kubecli.SerialConsoleOptions{ConnectionTimeout: 30 * time.Second})
Expect(err).ToNot(HaveOccurred())
})

It("[test_id:1593]should not be connected if scheduled to non-existing host", func() {
vmi := libvmi.NewAlpine(
libvmi.WithNodeAffinityFor(&k8sv1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "nonexistent",
},
}),
)

By("Creating a new VirtualMachineInstance")
vmi, err := virtClient.VirtualMachineInstance(testsuite.GetTestNamespace(vmi)).Create(context.Background(), vmi)
Expect(err).ToNot(HaveOccurred())

_, err = virtClient.VirtualMachineInstance(vmi.Namespace).SerialConsole(vmi.Name, &kubecli.SerialConsoleOptions{ConnectionTimeout: 30 * time.Second})
Expect(err).To(MatchError("Timeout trying to connect to the virtual machine instance"))
})
})

Context("without a serial console", func() {
It("[test_id:4118]should run but not be connectable via the serial console", func() {
vmi := libvmi.NewAlpine(libvmi.WithoutSerialConsole())
vmi = tests.RunVMIAndExpectLaunch(vmi, startupTimeout)

By("failing to connect to serial console")
_, err := virtClient.VirtualMachineInstance(vmi.ObjectMeta.Namespace).SerialConsole(vmi.ObjectMeta.Name, &kubecli.SerialConsoleOptions{})
Expect(err).To(MatchError("No serial consoles are present."), "serial console should not connect if there are no serial consoles present")
})
})
})
})
206 changes: 0 additions & 206 deletions tests/console_test.go

This file was deleted.

Loading

0 comments on commit fdce65d

Please sign in to comment.