Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vm/vm-under-test: Move first boot to new service #56

Merged
merged 6 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pkg/internal/checkup/executor/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions pkg/internal/checkup/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion vms/vm-under-test/scripts/build-vm-image
Original file line number Diff line number Diff line change
Expand Up @@ -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
100 changes: 93 additions & 7 deletions vms/vm-under-test/scripts/customize-vm
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF > "$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
28 changes: 0 additions & 28 deletions vms/vm-under-test/scripts/first-boot

This file was deleted.