Skip to content

Commit

Permalink
Add functest for KVM hidden
Browse files Browse the repository at this point in the history
This follows the example of the tests that use `dmidecode`. We
use the `virt-what` RPM to get access to the
`/usr/libexec/virt-what-cpuid-helper` tool for parsing out the
KVM identifier string from VM CPUID, verify it is present for
a default config, and missing for a `<kvm><hidden state='on'/>`
config

Signed-off-by: Cole Robinson <[email protected]>
  • Loading branch information
crobinso committed Sep 17, 2020
1 parent 871c1b4 commit 338e7be
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 1 deletion.
8 changes: 8 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,14 @@ http_file(
],
)

http_file(
name = "virt-what",
sha256 = "a6972c67cf99537503d0517e99782ff6ed1ae7c93aea168da81dadbb836f9ae0",
urls = [
"https://dl.fedoraproject.org/pub/archive/fedora/linux/releases/30/Everything/x86_64/os/Packages/v/virt-what-1.19-2.fc30.x86_64.rpm",
],
)

# some repos which are not part of go_rules anymore
go_repository(
name = "com_github_golang_glog",
Expand Down
1 change: 1 addition & 0 deletions images/cdi-http-import-server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ rpm_image(
"@libaio//file",
"@e2fsprogs//file",
"@dmidecode//file",
"@virt-what//file",
"@which//file",
],
}),
Expand Down
2 changes: 1 addition & 1 deletion images/cdi-http-import-server/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ elif [ -n "$AS_EMPTY" ]; then
bash expose-as-iscsi.sh "${IMAGE_PATH}/disk.raw"
else
# Expose binaries via nginx server
for executable in qemu-ga stress dmidecode; do
for executable in qemu-ga stress dmidecode /usr/libexec/virt-what-cpuid-helper; do
cp $(which $executable) /usr/share/nginx/html/
done

Expand Down
14 changes: 14 additions & 0 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ const (
DmidecodeHttpUrl
DummyFileHttpUrl
CirrosHttpUrl
VirtWhatCpuidHelperHttpUrl
)

const (
Expand Down Expand Up @@ -2115,6 +2116,17 @@ func NewRandomFedoraVMIWithDmidecode() *v1.VirtualMachineInstance {
return vmi
}

func NewRandomFedoraVMIWithVirtWhatCpuidHelper() *v1.VirtualMachineInstance {
userData := fmt.Sprintf(`#!/bin/bash
echo "fedora" |passwd fedora --stdin
mkdir -p /usr/local/bin
curl %s > /usr/local/bin/virt-what-cpuid-helper
chmod +x /usr/local/bin/virt-what-cpuid-helper
`, GetUrl(VirtWhatCpuidHelperHttpUrl))
vmi := NewRandomVMIWithEphemeralDiskAndUserdataHighMemory(cd.ContainerDiskFor(cd.ContainerDiskFedora), userData)
return vmi
}

func GetGuestAgentUserData() string {
guestAgentUrl := GetUrl(GuestAgentHttpUrl)
return fmt.Sprintf(`#!/bin/bash
Expand Down Expand Up @@ -4298,6 +4310,8 @@ func GetUrl(urlIndex int) string {
str = fmt.Sprintf("http://cdi-http-import-server.%s/dummy.file", flags.KubeVirtInstallNamespace)
case CirrosHttpUrl:
str = fmt.Sprintf("http://cdi-http-import-server.%s/images/cirros.img", flags.KubeVirtInstallNamespace)
case VirtWhatCpuidHelperHttpUrl:
str = fmt.Sprintf("http://cdi-http-import-server.%s/virt-what-cpuid-helper", flags.KubeVirtInstallNamespace)
default:
str = ""
}
Expand Down
65 changes: 65 additions & 0 deletions tests/vmi_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2667,4 +2667,69 @@ var _ = Describe("Configurations", func() {
return nil
}, 30*time.Second, 1*time.Second).ShouldNot(HaveOccurred(), "VMI status IP should match VMI Pod IP")
})

Context("Check KVM CPUID advertisement", func() {
var vmi *v1.VirtualMachineInstance

BeforeEach(func() {
if tests.IsRunningOnKindInfra() {
Skip("Skip KVM MSR prescence test on kind")
}

vmi = tests.NewRandomFedoraVMIWithVirtWhatCpuidHelper()
})

It("test cpuid hidden", func() {
vmi.Spec.Domain.Features = &v1.Features{
KVM: &v1.FeatureKVM{Hidden: true},
}

By("Starting a VirtualMachineInstance")
vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).ToNot(HaveOccurred())
tests.WaitForSuccessfulVMIStart(vmi)

By("Check values in domain XML")
domXml, err := tests.GetRunningVirtualMachineInstanceDomainXML(virtClient, vmi)
Expect(err).ToNot(HaveOccurred())
Expect(domXml).To(ContainSubstring("<hidden state='on'/>"))

By("Expecting console")
expecter, err := tests.LoggedInFedoraExpecter(vmi)
Expect(err).ToNot(HaveOccurred())
defer expecter.Close()

By("Check virt-what-cpuid-helper does not match KVM")
res, err := expecter.ExpectBatch([]expect.Batcher{
&expect.BSnd{S: "virt-what-cpuid-helper > /dev/null 2>&1 && echo 'pass'\n"},
&expect.BExp{R: tests.RetValue("pass")},
&expect.BSnd{S: "$(sudo virt-what-cpuid-helper | grep -q KVMKVMKVM) || echo 'pass'\n"},
&expect.BExp{R: tests.RetValue("pass")},
}, 1*time.Second)
log.DefaultLogger().Object(vmi).Infof("%v", res)
Expect(err).ToNot(HaveOccurred())
})

It("test cpuid default", func() {
By("Starting a VirtualMachineInstance")
vmi, err = virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(vmi)
Expect(err).ToNot(HaveOccurred())
tests.WaitForSuccessfulVMIStart(vmi)

By("Expecting console")
expecter, err := tests.LoggedInFedoraExpecter(vmi)
Expect(err).ToNot(HaveOccurred())
defer expecter.Close()

By("Check virt-what-cpuid-helper matches KVM")
res, err := expecter.ExpectBatch([]expect.Batcher{
&expect.BSnd{S: "virt-what-cpuid-helper > /dev/null 2>&1 && echo 'pass'\n"},
&expect.BExp{R: tests.RetValue("pass")},
&expect.BSnd{S: "$(sudo virt-what-cpuid-helper | grep -q KVMKVMKVM) && echo 'pass'\n"},
&expect.BExp{R: tests.RetValue("pass")},
}, 1*time.Second)
log.DefaultLogger().Object(vmi).Infof("%v", res)
Expect(err).ToNot(HaveOccurred())
})
})
})

0 comments on commit 338e7be

Please sign in to comment.