Skip to content

Commit

Permalink
Added dmidecode tests for SMBios and Chassis
Browse files Browse the repository at this point in the history
Signed-off-by: Vatsal Parekh <[email protected]>
  • Loading branch information
vatsalparekh authored and Vatsal Parekh committed Sep 23, 2019
1 parent e63c240 commit 9755424
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 6 deletions.
8 changes: 8 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,11 @@ http_file(
"https://archives.fedoraproject.org/pub/archive/fedora/linux/updates/28/Everything/x86_64/Packages/e/e2fsprogs-1.44.2-0.fc28.x86_64.rpm",
],
)

http_file(
name = "dmidecode",
sha256 = "5694c041bcebc273cbf9a67f7210b2dd93c517aba55d93d20980b5bdf4be3751",
urls = [
"https://dl.fedoraproject.org/pub/archive/fedora/linux/releases/28/Everything/x86_64/os/Packages/d/dmidecode-3.1-5.fc28.x86_64.rpm",
],
)
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 @@ -16,6 +16,7 @@ rpm_image(
"@capstone//file",
"@libaio//file",
"@e2fsprogs//file",
"@dmidecode//file",
],
)

Expand Down
1 change: 1 addition & 0 deletions images/cdi-http-import-server/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ else
# Expose qemu-guest-agent via nginx server
cp /usr/bin/qemu-ga /usr/share/nginx/html/
cp /usr/bin/stress /usr/share/nginx/html/
cp /usr/bin/dmidecode /usr/share/nginx/html/
/usr/sbin/nginx
fi
12 changes: 12 additions & 0 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ const (
FedoraHttpUrl = "http://cdi-http-import-server.kubevirt/images/fedora.img"
GuestAgentHttpUrl = "http://cdi-http-import-server.kubevirt/qemu-ga"
StressHttpUrl = "http://cdi-http-import-server.kubevirt/stress"
DmidecodeHttpUrl = "http://cdi-http-import-server.kubevirt/dmidecode"
)

const (
Expand Down Expand Up @@ -1762,6 +1763,17 @@ func NewRandomFedoraVMIWitGuestAgent() *v1.VirtualMachineInstance {
return agentVMI
}

func NewRandomFedoraVMIWithDmidecode() *v1.VirtualMachineInstance {
dmidecodeUserData := fmt.Sprintf(`#!/bin/bash
echo "fedora" |passwd fedora --stdin
mkdir -p /usr/local/bin
curl %s > /usr/local/bin/dmidecode
chmod +x /usr/local/bin/dmidecode
`, DmidecodeHttpUrl)
vmi := NewRandomVMIWithEphemeralDiskAndUserdataHighMemory(ContainerDiskFor(ContainerDiskFedora), dmidecodeUserData)
return vmi
}

func GetGuestAgentUserData() string {
return fmt.Sprintf(`#!/bin/bash
echo "fedora" |passwd fedora --stdin
Expand Down
66 changes: 60 additions & 6 deletions tests/vmi_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ import (
"kubevirt.io/kubevirt/tests"
)

const (
dmidecodePackageUrl = "http://download-ib01.fedoraproject.org/pub/fedora/linux/releases/29/Everything/x86_64/os/Packages/d/dmidecode-3.2-1.fc29.x86_64.rpm"
)

var _ = Describe("Configurations", func() {

tests.FlagParse()
Expand Down Expand Up @@ -1861,13 +1865,9 @@ var _ = Describe("Configurations", func() {
})

Context("Check Chassis value", func() {
var vmi *v1.VirtualMachineInstance

BeforeEach(func() {
vmi = tests.NewRandomVMI()
})

It("[test_id:2927]Test Chassis value in a newly created VM", func() {
vmi := tests.NewRandomFedoraVMIWithDmidecode()
vmi.Spec.Domain.Chassis = &v1.Chassis{
Asset: "Test-123",
}
Expand All @@ -1877,9 +1877,24 @@ var _ = Describe("Configurations", func() {
Expect(err).ToNot(HaveOccurred())
tests.WaitForSuccessfulVMIStart(vmi)

By("Check values on domain XML")
domXml, err := tests.GetRunningVirtualMachineInstanceDomainXML(virtClient, vmi)
Expect(err).ToNot(HaveOccurred())
Expect(domXml).To(ContainSubstring("<entry name='asset'>Test-123</entry>"))

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

By("Check value in VM with dmidecode")
// Check on the VM, if expected values are there with dmidecode
res, err := expecter.ExpectBatch([]expect.Batcher{
&expect.BSnd{S: "[ $(sudo dmidecode -s chassis-asset-tag | tr -s ' ') -eq Test-123 ] && echo 'pass' || echo 'fail'\n"},
&expect.BExp{R: "pass"},
}, 1*time.Second)
log.DefaultLogger().Object(vmi).Infof("%v", res)
Expect(err).ToNot(HaveOccurred())
})
})

Expand All @@ -1888,24 +1903,44 @@ var _ = Describe("Configurations", func() {
var vmi *v1.VirtualMachineInstance

BeforeEach(func() {
vmi = tests.NewRandomVMIWithEphemeralDisk(tests.ContainerDiskFor(tests.ContainerDiskAlpine))
vmi = tests.NewRandomFedoraVMIWithDmidecode()
})

It("[test_id:2751]test default SMBios", func() {

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("<entry name='family'>KubeVirt</entry>"))
Expect(domXml).To(ContainSubstring("<entry name='product'>None</entry>"))
Expect(domXml).To(ContainSubstring("<entry name='manufacturer'>KubeVirt</entry>"))

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

By("Check values in dmidecode")
// Check on the VM, if expected values are there with dmidecode
res, err := expecter.ExpectBatch([]expect.Batcher{
&expect.BSnd{S: "[ $(sudo dmidecode -s system-family | tr -s ' ') -eq KubeVirt ] && echo 'pass' || echo 'fail'\n"},
&expect.BExp{R: "pass"},
&expect.BSnd{S: "[ $(sudo dmidecode -s system-product-name | tr -s ' ') -eq None ] && echo 'pass' || echo 'fail'\n"},
&expect.BExp{R: "pass"},
&expect.BSnd{S: "[ $(sudo dmidecode -s system-manufacturer | tr -s ' ') -eq KubeVirt ] && echo 'pass' || echo 'fail'\n"},
&expect.BExp{R: "pass"},
}, 1*time.Second)
log.DefaultLogger().Object(vmi).Infof("%v", res)
Expect(err).ToNot(HaveOccurred())
})

It("[test_id:2752]test custom SMBios values", func() {

// Set a custom test SMBios
test_smbios := &cmdv1.SMBios{Family: "test", Product: "test", Manufacturer: "None", Sku: "1.0", Version: "1.0"}
smbiosJson, err := json.Marshal(test_smbios)
Expand All @@ -1924,6 +1959,25 @@ var _ = Describe("Configurations", func() {
Expect(domXml).To(ContainSubstring("<entry name='manufacturer'>None</entry>"))
Expect(domXml).To(ContainSubstring("<entry name='sku'>1.0</entry>"))
Expect(domXml).To(ContainSubstring("<entry name='version'>1.0</entry>"))

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

By("Check values in dmidecode")

// Check on the VM, if expected values are there with dmidecode
res, err := expecter.ExpectBatch([]expect.Batcher{
&expect.BSnd{S: "[ $(sudo dmidecode -s system-family | tr -s ' ') -eq test ] && echo 'pass' || echo 'fail'\n"},
&expect.BExp{R: "pass"},
&expect.BSnd{S: "[ $(sudo dmidecode -s system-product-name | tr -s ' ') -eq test ] && echo 'pass' || echo 'fail'\n"},
&expect.BExp{R: "pass"},
&expect.BSnd{S: "[ $(sudo dmidecode -s system-manufacturer | tr -s ' ') -eq None ] && echo 'pass' || echo 'fail'\n"},
&expect.BExp{R: "pass"},
}, 1*time.Second)
log.DefaultLogger().Object(vmi).Infof("%v", res)
Expect(err).ToNot(HaveOccurred())
})
})
})

0 comments on commit 9755424

Please sign in to comment.