forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
console_test.go
107 lines (89 loc) · 3.15 KB
/
console_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* 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 tests_test
import (
"flag"
"time"
"github.com/google/goexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"kubevirt.io/kubevirt/pkg/kubecli"
"kubevirt.io/kubevirt/tests"
)
var _ = Describe("Console", func() {
flag.Parse()
virtClient, err := kubecli.GetKubevirtClient()
tests.PanicOnError(err)
BeforeEach(func() {
tests.BeforeTestCleanup()
})
RunVMAndExpectConsoleOutput := func(image string, expected string) {
vm := tests.NewRandomVMWithEphemeralDiskHighMemory(image)
By("Creating a new VM")
Expect(virtClient.RestClient().Post().Resource("virtualmachines").Namespace(tests.NamespaceTestDefault).Body(vm).Do().Error()).To(Succeed())
tests.WaitForSuccessfulVMStart(vm)
By("Expecting the VM console")
expecter, _, err := tests.NewConsoleExpecter(virtClient, vm, "serial0", 10*time.Second)
defer expecter.Close()
Expect(err).ToNot(HaveOccurred())
By("Checking that the console output equals to expected one")
_, err = expecter.ExpectBatch([]expect.Batcher{
&expect.BExp{R: expected},
}, 120*time.Second)
Expect(err).ToNot(HaveOccurred())
}
Describe("A new VM", func() {
Context("with a serial console", func() {
Context("with a cirros image", func() {
It("should return that we are running cirros", func() {
RunVMAndExpectConsoleOutput(
"kubevirt/cirros-registry-disk-demo:devel",
"checking http://169.254.169.254/2009-04-04/instance-id",
)
}, 140)
})
Context("with a fedora image", func() {
It("should return that we are running fedora", func() {
RunVMAndExpectConsoleOutput(
"kubevirt/fedora-cloud-registry-disk-demo:devel",
"Welcome to",
)
}, 140)
})
It("should be able to reconnect to console multiple times", func() {
vm := tests.NewRandomVMWithEphemeralDisk("kubevirt/alpine-registry-disk-demo:devel")
By("Creating a new VM")
Expect(virtClient.RestClient().Post().Resource("virtualmachines").Namespace(tests.NamespaceTestDefault).Body(vm).Do().Error()).To(Succeed())
tests.WaitForSuccessfulVMStart(vm)
for i := 0; i < 5; i++ {
By("Expecting a VM console")
expecter, _, err := tests.NewConsoleExpecter(virtClient, vm, "serial0", 10*time.Second)
defer expecter.Close()
Expect(err).ToNot(HaveOccurred())
By("Checking that the console output equals to expected one")
_, err = expecter.ExpectBatch([]expect.Batcher{
&expect.BSnd{S: "\n"},
&expect.BExp{R: "login"},
}, 160*time.Second)
Expect(err).ToNot(HaveOccurred())
}
}, 220)
})
})
})