This repository has been archived by the owner on Jun 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathvirtio_rng_test.go
83 lines (70 loc) · 2.38 KB
/
virtio_rng_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
package tests_test
import (
"flag"
"fmt"
"time"
"github.com/google/goexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"kubevirt.io/kubevirt/pkg/api/v1"
"kubevirt.io/kubevirt/pkg/kubecli"
ktests "kubevirt.io/kubevirt/tests"
)
const (
ddCommand = "dd count=10 bs=1024 if=/dev/%s of=/tmp/%s.txt\n"
checkRNGDevice = "cat /sys/devices/virtual/misc/hw_random/%s\n"
checkFileSize = "ls /tmp/%s.txt | wc -l'\n"
outputDevice = "virtio_rng.0"
)
var rngAvailable string
var rngCurrent string
var ddWithRandom string
var ddWithHWRandom string
var checkFileRandom string
var checkFileHWRng string
var _ = Describe("[rfe_id:609][crit:medium][vendor:[email protected]][level:component]VIRT RNG test", func() {
flag.Parse()
virtClient, err := kubecli.GetKubevirtClient()
ktests.PanicOnError(err)
setCommands()
ktests.BeforeAll(func() {
ktests.BeforeTestCleanup()
})
Context("With VirtIO RNG device", func() {
var withRngVmi *v1.VirtualMachineInstance
withRngVmi = ktests.NewRandomVMIWithEphemeralDisk(ktests.ContainerDiskFor(ktests.ContainerDiskAlpine))
It("[test_id:791]Virtio rng device should be present", func() {
withRngVmi.Spec.Domain.Devices.Rng = &v1.Rng{}
By("Starting a VMI")
withRngVmi, err = virtClient.VirtualMachineInstance(ktests.NamespaceTestDefault).Create(withRngVmi)
Expect(err).ToNot(HaveOccurred())
ktests.WaitForSuccessfulVMIStart(withRngVmi)
By("Expecting console")
expecter, err := ktests.LoggedInAlpineExpecter(withRngVmi)
Expect(err).ToNot(HaveOccurred())
defer expecter.Close()
By("Checking the virtio RNG")
_, err = expecter.ExpectBatch([]expect.Batcher{
&expect.BSnd{S: rngAvailable},
&expect.BExp{R: outputDevice},
&expect.BSnd{S: rngCurrent},
&expect.BExp{R: outputDevice},
&expect.BSnd{S: ddWithRandom},
&expect.BSnd{S: ddWithHWRandom},
&expect.BSnd{S: checkFileRandom},
&expect.BExp{R: "1"},
&expect.BSnd{S: checkFileHWRng},
&expect.BExp{R: "1"},
}, 60*time.Second)
Expect(err).ToNot(HaveOccurred())
})
})
})
func setCommands() {
rngAvailable = fmt.Sprintf(checkRNGDevice, "rng_available")
rngCurrent = fmt.Sprintf(checkRNGDevice, "rng_current")
ddWithRandom = fmt.Sprintf(ddCommand, "random", "random")
ddWithHWRandom = fmt.Sprintf(ddCommand, "hwrng", "hwrng")
checkFileRandom = fmt.Sprintf(checkFileSize, "random")
checkFileHWRng = fmt.Sprintf(checkFileSize, "hwrng")
}