diff --git a/pkg/internal/checkup/executor/console/console.go b/pkg/internal/checkup/executor/console/console.go index d6bf7bc7..4bc23514 100644 --- a/pkg/internal/checkup/executor/console/console.go +++ b/pkg/internal/checkup/executor/console/console.go @@ -101,6 +101,17 @@ func RetValue(retcode string) string { return "\n" + retcode + CRLF + ".*" + PromptExpression } +func (e Expecter) GetGuestKernelArgs() (string, error) { + const cmdLineCmd = "cat /proc/cmdline\n" + batch := []expect.Batcher{ + &expect.BSnd{S: cmdLineCmd}, + &expect.BExp{R: PromptExpression}, + } + const printKernelArgsTimeout = 30 * time.Second + resp, err := e.SafeExpectBatchWithResponse(batch, printKernelArgsTimeout) + return resp[0].Output, err +} + // SafeExpectBatchWithResponse runs the batch from `expected`, connecting to a VMI's console and // waiting for the batch to return with a response until timeout. // It validates that the commands arrive to the console. diff --git a/pkg/internal/checkup/executor/executor.go b/pkg/internal/checkup/executor/executor.go index 1ec75daf..564f9b8c 100644 --- a/pkg/internal/checkup/executor/executor.go +++ b/pkg/internal/checkup/executor/executor.go @@ -62,6 +62,9 @@ func (e Executor) Execute(ctx context.Context, vmiUnderTestName string) (status. return status.Results{}, fmt.Errorf("failed to login to VMI \"%s/%s\": %w", e.namespace, vmiUnderTestName, err) } + kernelArgs, _ := vmiUnderTestConsoleExpecter.GetGuestKernelArgs() + log.Printf("VMI under test guest kernel Args: %s", kernelArgs) + oslatClient := oslat.NewClient(vmiUnderTestConsoleExpecter, e.OslatDuration) log.Printf("Running Oslat test on VMI under test for %s...", e.OslatDuration.String()) maxLatency, err := oslatClient.Run(ctx) diff --git a/vms/vm-under-test/scripts/build-vm-image b/vms/vm-under-test/scripts/build-vm-image index c1cdced6..1ee56fc8 100755 --- a/vms/vm-under-test/scripts/build-vm-image +++ b/vms/vm-under-test/scripts/build-vm-image @@ -24,6 +24,5 @@ virt-builder centosstream-8 \ --root-password password:redhat \ --install cloud-init,kernel-rt,tuned,rt-tests \ --run /root/scripts/customize-vm \ - --firstboot /root/scripts/first-boot \ --selinux-relabel \ --output /output/kubevirt-realtime-checkup-vm.qcow2 diff --git a/vms/vm-under-test/scripts/customize-vm b/vms/vm-under-test/scripts/customize-vm index 9b0cd557..546679d2 100755 --- a/vms/vm-under-test/scripts/customize-vm +++ b/vms/vm-under-test/scripts/customize-vm @@ -19,12 +19,98 @@ set -e -systemctl disable NetworkManager-wait-online -systemctl disable sshd -systemctl disable irqbalance +# Disable unnecessary services +disable_services() { + local service_list=("NetworkManager-wait-online" "sshd" "irqbalance") + for service in "${service_list[@]}"; do + systemctl disable "$service" + done +} -dnf --enablerepo=rt install -y tuned-profiles-realtime -dnf --enablerepo=nfv install -y tuned-profiles-nfv-guest +# Install required packages +install_packages() { + dnf --enablerepo=rt install -y tuned-profiles-realtime + dnf --enablerepo=nfv install -y tuned-profiles-nfv-guest +} -swapoff -a -sed -i '/swap/s/^/#/' /etc/fstab +# Disable swap +disable_swap() { + swapoff -a + sed -i '/swap/s/^/#/' /etc/fstab +} + +# Create and enable the boot checkup service +setup_boot_service() { + local service_name="realtime-checkup-boot.service" + local checkup_boot_script_full_path="/usr/bin/realtime-checkup-boot.sh" + local checkup_boot_service_full_path="/usr/lib/systemd/system/$service_name" + local checkup_boot_ready_marker_full_path="/var/realtime-checkup-image-ready-marker" + + setup_checkup_boot_script "$checkup_boot_script_full_path" + + cat < "$checkup_boot_service_full_path" +[Unit] +Description=Checkup Boot Script +Before=qemu-guest-agent.service +ConditionPathExists=!$checkup_boot_ready_marker_full_path +[Service] +Type=oneshot +ExecStart=$checkup_boot_script_full_path $checkup_boot_ready_marker_full_path +Restart=no +User=root +Group=root +[Install] +WantedBy=multi-user.target +Wants=first-boot-complete.target +EOF + + systemctl enable "$checkup_boot_service_full_path" + systemctl start "$checkup_boot_service_full_path" +} + +setup_checkup_boot_script() { + local checkup_boot_script_full_path=$1 +cat <<'EOF' > "$checkup_boot_script_full_path" +#!/usr/bin/env bash +# +# This file is part of the kiagnose 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 2024 Red Hat, Inc. +# + +set -e + +checkup_boot_ready_marker_full_path=$1 + +if systemctl --type swap list-units | grep -q '.swap'; then + systemctl mask "$(systemctl --type swap list-units | grep '.swap' | awk '{print $1}')" +fi + +tuned_conf="/etc/tuned/realtime-virtual-guest-variables.conf" +echo "isolated_cores=2-3" > "$tuned_conf" +echo "isolate_managed_irq=Y" >> "$tuned_conf" +tuned-adm profile realtime-virtual-guest + +touch $checkup_boot_ready_marker_full_path +reboot +EOF + + chmod +x "$checkup_boot_script_full_path" +} + +disable_services +install_packages +disable_swap +setup_boot_service diff --git a/vms/vm-under-test/scripts/first-boot b/vms/vm-under-test/scripts/first-boot deleted file mode 100755 index 5facd899..00000000 --- a/vms/vm-under-test/scripts/first-boot +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash -# -# This file is part of the kiagnose 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 2023 Red Hat, Inc. -# - -set -e - -systemctl mask "$(systemctl --type swap | grep '.swap' | awk '{print $1}')" - -echo isolated_cores=2-3 >> /etc/tuned/realtime-virtual-guest-variables.conf -echo isolate_managed_irq=Y >> /etc/tuned/realtime-virtual-guest-variables.conf -tuned-adm profile realtime-virtual-guest - -reboot