Skip to content

Commit

Permalink
Merge pull request #221 from RamLavi/add_guest_agent_ping_wait
Browse files Browse the repository at this point in the history
checkup: Add guest agent ping wait
  • Loading branch information
RamLavi authored Jan 28, 2024
2 parents 5c88d2c + ee2b433 commit ccc6f64
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 13 deletions.
15 changes: 7 additions & 8 deletions pkg/internal/checkup/checkup.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,14 @@ func (c *Checkup) Setup(ctx context.Context) (setupErr error) {
}()

var updatedVMIUnderTest *kvcorev1.VirtualMachineInstance
updatedVMIUnderTest, err = c.waitForVMIToBoot(setupCtx, c.vmiUnderTest.Name)
updatedVMIUnderTest, err = c.waitForVMIToBeReady(setupCtx, c.vmiUnderTest.Name)
if err != nil {
return err
}

c.vmiUnderTest = updatedVMIUnderTest

var updatedTrafficGen *kvcorev1.VirtualMachineInstance
updatedTrafficGen, err = c.waitForVMIToBoot(setupCtx, c.trafficGen.Name)
updatedTrafficGen, err = c.waitForVMIToBeReady(setupCtx, c.trafficGen.Name)
if err != nil {
return err
}
Expand Down Expand Up @@ -233,9 +232,9 @@ func (c *Checkup) createVMI(ctx context.Context, vmiToCreate *kvcorev1.VirtualMa
return err
}

func (c *Checkup) waitForVMIToBoot(ctx context.Context, name string) (*kvcorev1.VirtualMachineInstance, error) {
func (c *Checkup) waitForVMIToBeReady(ctx context.Context, name string) (*kvcorev1.VirtualMachineInstance, error) {
vmiFullName := ObjectFullName(c.namespace, name)
log.Printf("Waiting for VMI %q to boot...", vmiFullName)
log.Printf("Waiting for VMI %q to be ready...", vmiFullName)
var updatedVMI *kvcorev1.VirtualMachineInstance

conditionFn := func(ctx context.Context) (bool, error) {
Expand All @@ -246,7 +245,7 @@ func (c *Checkup) waitForVMIToBoot(ctx context.Context, name string) (*kvcorev1.
}

for _, condition := range updatedVMI.Status.Conditions {
if condition.Type == kvcorev1.VirtualMachineInstanceAgentConnected && condition.Status == k8scorev1.ConditionTrue {
if condition.Type == kvcorev1.VirtualMachineInstanceReady && condition.Status == k8scorev1.ConditionTrue {
return true, nil
}
}
Expand All @@ -255,10 +254,10 @@ func (c *Checkup) waitForVMIToBoot(ctx context.Context, name string) (*kvcorev1.
}
const pollInterval = 5 * time.Second
if err := wait.PollImmediateUntilWithContext(ctx, pollInterval, conditionFn); err != nil {
return nil, fmt.Errorf("failed to wait for VMI %q to boot: %v", vmiFullName, err)
return nil, fmt.Errorf("failed to wait for VMI %q to be ready: %v", vmiFullName, err)
}

log.Printf("VMI %q had successfully booted", vmiFullName)
log.Printf("VMI %q has successfully reached ready condition", vmiFullName)

return updatedVMI, nil
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/internal/checkup/checkup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,11 @@ func (cs *clientStub) GetVirtualMachineInstance(_ context.Context, namespace, na
return nil, k8serrors.NewNotFound(schema.GroupResource{Group: "kubevirt.io", Resource: "virtualmachineinstances"}, name)
}

vmi.Status.Conditions = append(vmi.Status.Conditions, kvcorev1.VirtualMachineInstanceCondition{
Type: kvcorev1.VirtualMachineInstanceAgentConnected,
Status: k8scorev1.ConditionTrue,
})
vmi.Status.Conditions = append(vmi.Status.Conditions,
kvcorev1.VirtualMachineInstanceCondition{
Type: kvcorev1.VirtualMachineInstanceReady,
Status: k8scorev1.ConditionTrue,
})

return vmi, nil
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/internal/checkup/vmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func newVMIUnderTest(name string, checkupConfig config.Config, configMapName str
vmi.WithCloudInitNoCloudVolume(cloudInitDiskName, CloudInit(vmiUnderTestBootCommands(configDiskSerial))),
vmi.WithConfigMapVolume(configVolumeName, configMapName),
vmi.WithConfigMapDisk(configVolumeName, configDiskSerial),
vmi.WithReadinessFileProbe(config.BootScriptReadinessMarkerFileFullPath),
)

return vmi.New(name, optionsToApply...)
Expand All @@ -88,6 +89,7 @@ func newTrafficGen(name string, checkupConfig config.Config, configMapName strin
vmi.WithCloudInitNoCloudVolume(cloudInitDiskName, CloudInit(trafficGenBootCommands(configDiskSerial))),
vmi.WithConfigMapVolume(configVolumeName, configMapName),
vmi.WithConfigMapDisk(configVolumeName, configDiskSerial),
vmi.WithReadinessFileProbe(config.BootScriptReadinessMarkerFileFullPath),
)

return vmi.New(name, optionsToApply...)
Expand Down Expand Up @@ -132,7 +134,7 @@ func generateBootScript() string {
sb := strings.Builder{}

sb.WriteString("#!/bin/bash\n")
sb.WriteString("set -e\n")
sb.WriteString("set -x\n")
sb.WriteString("\n")
sb.WriteString("checkup_tuned_adm_set_marker_full_path=" + config.BootScriptTunedAdmSetMarkerFileFullPath + "\n")
sb.WriteString("\n")
Expand All @@ -141,10 +143,13 @@ func generateBootScript() string {
sb.WriteString(" tuned-adm profile cpu-partitioning\n\n")
sb.WriteString(" touch $checkup_tuned_adm_set_marker_full_path\n")
sb.WriteString(" reboot\n")
sb.WriteString(" exit 0\n")
sb.WriteString("fi\n")
sb.WriteString("\n")
sb.WriteString("driverctl set-override " + config.VMIEastNICPCIAddress + " vfio-pci\n")
sb.WriteString("driverctl set-override " + config.VMIWestNICPCIAddress + " vfio-pci\n")
sb.WriteString("touch " + config.BootScriptReadinessMarkerFileFullPath + "\n")
sb.WriteString("chcon -t virt_qemu_ga_exec_t " + config.BootScriptReadinessMarkerFileFullPath + "\n")

return sb.String()
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/internal/checkup/vmi/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,23 @@ func WithAffinity(affinity *corev1.Affinity) Option {
}
}

func WithReadinessFileProbe(fileName string) Option {
return func(vmi *kvcorev1.VirtualMachineInstance) {
var readinessProbeCommand = []string{"cat", fileName}
vmi.Spec.ReadinessProbe = &kvcorev1.Probe{
Handler: kvcorev1.Handler{
Exec: &corev1.ExecAction{
Command: readinessProbeCommand,
},
},
FailureThreshold: 30,
InitialDelaySeconds: 90,
PeriodSeconds: 10,
TimeoutSeconds: 10,
}
}
}

func Pointer[T any](v T) *T {
return &v
}
1 change: 1 addition & 0 deletions pkg/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const (
BootScriptName = "dpdk-checkup-boot.sh"
BootScriptBinDirectory = "/usr/bin/"
BootScriptTunedAdmSetMarkerFileFullPath = "/var/dpdk-checkup-tuned-adm-set-marker"
BootScriptReadinessMarkerFileFullPath = "/tmp/dpdk-checkup-ready-marker"
)

var (
Expand Down
7 changes: 7 additions & 0 deletions vms/traffic-gen/scripts/customize-vm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ set_unsafe_no_io_mmu_mode() {
echo "options vfio enable_unsafe_noiommu_mode=1" > /etc/modprobe.d/vfio-noiommu.conf
}

# Enable guest-exec on the qemu-guest-agent configuration
enable_guest_exec() {
sed -i '/^BLACKLIST_RPC=/ { s/guest-exec-status//; s/guest-exec//g }' /etc/sysconfig/qemu-ga
sed -i '/^BLACKLIST_RPC=/ { s/,\+/,/g; s/^,\|,$//g }' /etc/sysconfig/qemu-ga
}

# Install trex package
install_trex() {
local TREX_URL=https://trex-tgn.cisco.com/trex/release
Expand All @@ -60,4 +66,5 @@ install_trex() {
disable_services
setup_hugepages
set_unsafe_no_io_mmu_mode
enable_guest_exec
install_trex
7 changes: 7 additions & 0 deletions vms/vm-under-test/scripts/customize-vm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ set_unsafe_no_io_mmu_mode() {
echo "options vfio enable_unsafe_noiommu_mode=1" > /etc/modprobe.d/vfio-noiommu.conf
}

# Enable guest-exec on the qemu-guest-agent configuration
enable_guest_exec() {
sed -i '/^BLACKLIST_RPC=/ { s/guest-exec-status//; s/guest-exec//g }' /etc/sysconfig/qemu-ga
sed -i '/^BLACKLIST_RPC=/ { s/,\+/,/g; s/^,\|,$//g }' /etc/sysconfig/qemu-ga
}

disable_services
setup_hugepages
set_unsafe_no_io_mmu_mode
enable_guest_exec

0 comments on commit ccc6f64

Please sign in to comment.