Skip to content

Commit 9c8d119

Browse files
Merge pull request #673 from lukaszstolarczuk/qemu-ci
Minor cleanup in QEMU CI
2 parents e67c4e1 + c221579 commit 9c8d119

File tree

5 files changed

+76
-72
lines changed

5 files changed

+76
-72
lines changed

.github/workflows/qemu.yml

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ name: Qemu
33

44
on: workflow_call
55

6-
env:
7-
CI_BRANCH: "${{ github.head_ref || github.ref_name }}"
8-
96
permissions:
107
contents: read
118

@@ -15,38 +12,43 @@ jobs:
1512
runs-on: ubuntu-22.04
1613

1714
steps:
18-
- name: Checkout
15+
- name: Checkout UMF
1916
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
2017
with:
2118
fetch-depth: 0
19+
path: umf
2220

2321
- name: Enable KVM
2422
run: |
2523
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
2624
sudo udevadm control --reload-rules
2725
sudo udevadm trigger --name-match=kvm
28-
- name: Install qemu
29-
run: |
30-
sudo apt update && sudo apt install -y qemu-system genisoimage qemu-utils
31-
- name: Install libvirt and script dependencies
26+
27+
- name: Install dependencies
3228
run: |
33-
sudo apt-get install -y libvirt-clients libvirt-daemon-system libvirt-daemon virtinst bridge-utils
34-
pip install -r scripts/qemu/requirements.txt
35-
sudo usermod -a -G kvm,libvirt $USER
29+
sudo apt-get update
30+
sudo apt-get install -y qemu-system genisoimage qemu-utils \
31+
libvirt-clients libvirt-daemon-system libvirt-daemon virtinst bridge-utils
32+
pip install -r umf/scripts/qemu/requirements.txt
33+
34+
- name: Add user to kvm group
35+
run: sudo usermod -a -G kvm,libvirt $USER
36+
3637
- name: Run ssh-keygen
3738
run: ssh-keygen -b 4096 -N '' -f ~/.ssh/id_rsa
39+
3840
- name: Generate iso with user info
3941
run: |
4042
pub_key=$(cat ~/.ssh/id_rsa.pub)
4143
4244
cat > user-data << EOF
4345
#cloud-config
4446
45-
# Add a 'cxltest' user to the system with a password
47+
# Add a 'testuser' user to the system with a password
4648
users:
4749
- default
48-
- name: cxltest
49-
gecos: CXL Test User
50+
- name: testuser
51+
gecos: Test User
5052
primary_group: wheel
5153
groups: users
5254
sudo: ALL=(ALL) NOPASSWD:ALL
@@ -59,54 +61,47 @@ jobs:
5961
chpasswd:
6062
list: |
6163
root:password
62-
cxltest:password
64+
testuser:password
6365
expire: False
6466
EOF
6567
6668
cat > meta-data << EOF
67-
instance-id: cxl-test
68-
local-hostname: cxl-test
69+
instance-id: qemu-test
70+
local-hostname: qemu-test
6971
EOF
7072
7173
sudo -Sk genisoimage -output ubuntu-cloud-init.iso -volid cidata -joliet -rock ./user-data ./meta-data
74+
7275
- name: Download ubuntu image
7376
run: wget https://cloud-images.ubuntu.com/releases/lunar/release/ubuntu-23.04-server-cloudimg-amd64.img
77+
7478
- name: Resize image
7579
run: qemu-img resize ./ubuntu-23.04-server-cloudimg-amd64.img +4G
76-
- name: Build
77-
run: |
78-
scripts/qemu/start_qemu.sh scripts/qemu/configs/default.xml
7980

80-
if [ ${{ github.event_name }} = 'pull_request' ]; then
81-
CI_REPO="${{ github.event.pull_request.head.repo.full_name }}"
82-
else
83-
CI_REPO="$GITHUB_REPOSITORY"
84-
fi
81+
- name: Build UMF in QEMU
82+
run: |
83+
umf/scripts/qemu/start_qemu.sh default.xml
8584
86-
scp -P 2222 ${{github.workspace}}/scripts/qemu/run-build.sh [email protected]:/home/cxltest
87-
scp -P 2222 ${{github.workspace}}/scripts/qemu/run-tests.sh cxltest@127.0.0.1:/home/cxltest
88-
ssh cxltest@127.0.0.1 -p 2222 -t "bash /home/cxltest/run-build.sh https://github.com/$CI_REPO ${{env.CI_BRANCH}}"
85+
# Copy UMF repository's content into the home dir in QEMU
86+
rsync -az -e "ssh -p 2222" ${{github.workspace}}/umf/ testuser@127.0.0.1:/home/testuser/
87+
ssh testuser@127.0.0.1 -p 2222 -t "sudo chown -R testuser:users /home/testuser"
8988
90-
ssh [email protected] -p 2222 -t "sudo shutdown -h now"
89+
ssh [email protected] -p 2222 -t "bash /home/testuser/scripts/qemu/run-build.sh"
90+
ssh [email protected] -p 2222 -t "sudo shutdown -h now"
9191
92-
- name: Run tests
92+
- name: Run tests in QEMU
9393
run: |
94-
for config_file in scripts/qemu/configs/*.xml; do
95-
config_name=$(basename $config_file .xml)
94+
for config_file in umf/scripts/qemu/configs/*.xml; do
95+
config_name=$(basename $config_file)
9696
97-
echo testing $config_name
9897
while ps -aux | grep qemu-system-x86_64 | grep -q -v grep; do
9998
echo "Waiting for QEMU to shut down..."
10099
sleep 5
101100
done
102-
scripts/qemu/start_qemu.sh $config_file
103-
104-
if [ ${{ github.event_name }} = 'pull_request' ]; then
105-
CI_REPO="${{ github.event.pull_request.head.repo.full_name }}"
106-
else
107-
CI_REPO="$GITHUB_REPOSITORY"
108-
fi
109-
110-
ssh [email protected] -p 2222 -t "bash /home/cxltest/run-tests.sh"
111-
ssh [email protected] -p 2222 -t "sudo shutdown -h now"
101+
102+
echo "\n ### Testing ${config_name} ###"
103+
umf/scripts/qemu/start_qemu.sh ${config_name}
104+
105+
ssh [email protected] -p 2222 -t "bash /home/testuser/scripts/qemu/run-tests.sh"
106+
ssh [email protected] -p 2222 -t "sudo shutdown -h now"
112107
done

scripts/qemu/qemu_config.py renamed to scripts/qemu/parse_config.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
"""
2+
Copyright (C) 2023-2024 Intel Corporation
3+
4+
Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
5+
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
"""
7+
18
import re
29
import subprocess # nosec
310
import sys
@@ -6,10 +13,13 @@
613
import psutil
714
import shutil
815

9-
# If you want to manually run this script please install deps by: pip install -r requirements.txt
10-
# To get virsh please install libvirt-clients
16+
# This script parses the topology xml file and returns QEMU arguments.
17+
#
18+
# Before running this script:
19+
# - install python deps for this script: pip install -r requirements.txt
20+
# - install 'libvirt-clients' package (for virsh)
1121
#
12-
# Enable verbose mode by using environment variable ENABLE_VERBOSE=1
22+
# Enable verbose mode by setting environment variable: ENABLE_VERBOSE=1
1323

1424
TopologyCfg = collections.namedtuple(
1525
"TopologyCfg", ["name", "hmat", "cpu_model", "cpu_options", "mem_options"]
@@ -20,7 +30,7 @@
2030

2131
def enable_verbose():
2232
"""
23-
Parse command line arguments
33+
Check if env var ENABLE_VERBOSE is set and enable verbose mode
2434
"""
2535
global verbose_mode
2636
verbose_mode = os.getenv("ENABLE_VERBOSE", False)
@@ -43,9 +53,13 @@ def parse_topology_xml(tpg_file_name: str) -> TopologyCfg:
4353
result.check_returncode()
4454
libvirt_args = result.stdout.decode("utf-8").strip()
4555

56+
if verbose_mode != False:
57+
print(f"\nFull libvirt_args: {libvirt_args}\n")
58+
59+
hmat_search = re.search(r"hmat=(\w+)", libvirt_args)
4660
tpg_cfg = {
4761
"name": re.search(r"guest=(\w+)", libvirt_args).group(1),
48-
"hmat": "hmat=on" in libvirt_args,
62+
"hmat": hmat_search.group(0) if hmat_search else "hmat=off",
4963
"cpu_model": re.search(r"cpu (\S+)", libvirt_args).group(1),
5064
"cpu_options": re.search("(?=-smp)(.*)threads=[0-9]+", libvirt_args).group(
5165
0
@@ -67,7 +81,7 @@ def parse_topology_xml(tpg_file_name: str) -> TopologyCfg:
6781
except subprocess.CalledProcessError:
6882
sys.exit(f"\n XML file: {tpg_file_name} error in virsh parsing")
6983
except Exception:
70-
sys.exit(f"\n Provided file is missing or missing virsh.")
84+
sys.exit(f"\n Provided file ({tpg_file_name}) is missing or missing virsh.")
7185
return tpg
7286

7387

@@ -76,13 +90,16 @@ def get_qemu_args(tpg_file_name: str) -> str:
7690
Get QEMU arguments from topology xml file
7791
"""
7892
tpg = parse_topology_xml(tpg_file_name)
79-
qemu_args = f"-name {tpg.name} {calculate_memory(tpg)} -cpu {tpg.cpu_model} {tpg.cpu_options} {tpg.mem_options}"
93+
qemu_args = (
94+
f"-machine q35,usb=off,{tpg.hmat} -name {tpg.name} "
95+
f"{calculate_memory(tpg)} -cpu {tpg.cpu_model} {tpg.cpu_options} {tpg.mem_options}"
96+
)
8097
return qemu_args
8198

8299

83100
def calculate_memory(tpg: TopologyCfg) -> str:
84101
"""
85-
Memory used by QEMU
102+
Total memory required by given QEMU config
86103
"""
87104
if tpg.mem_options:
88105
mem_needed = 0
@@ -105,4 +122,6 @@ def calculate_memory(tpg: TopologyCfg) -> str:
105122
tpg_file_name = sys.argv[1]
106123
else:
107124
sys.exit(f"\n Usage: {sys.argv[0]} <tpg_file_name>")
125+
126+
# Print QEMU arguments as a result of this script
108127
print(get_qemu_args(tpg_file_name))

scripts/qemu/run-build.sh

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,9 @@
55

66
set -e
77

8-
repo=$1
9-
branch=$2
10-
11-
echo password | sudo -Sk apt update
12-
echo password | sudo -Sk apt install -y git cmake gcc g++ numactl libnuma-dev libhwloc-dev libjemalloc-dev libtbb-dev pkg-config valgrind hwloc
13-
14-
git clone $repo umf
15-
cd umf
16-
git checkout $branch
8+
echo password | sudo -Sk apt-get update
9+
echo password | sudo -Sk apt-get install -y git cmake gcc g++ pkg-config \
10+
numactl libnuma-dev hwloc libhwloc-dev libjemalloc-dev libtbb-dev valgrind
1711

1812
mkdir build
1913
cd build

scripts/qemu/run-tests.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ echo password | sudo bash -c "echo 0 > /proc/sys/kernel/yama/ptrace_scope"
1313

1414
numactl -H
1515

16-
cd umf/build
16+
cd build
1717
ctest --verbose
1818

1919
# run tests bound to a numa node
@@ -23,4 +23,3 @@ numactl -N 1 ctest --output-on-failure
2323
# run tests under valgrind
2424
echo "Running tests under valgrind memcheck ..."
2525
../test/test_valgrind.sh .. . memcheck
26-

scripts/qemu/start_qemu.sh

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,25 @@
33
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
44
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55

6-
set -x
76
set -e
87

9-
config_file=$1
8+
# The config file name (should be located in ./configs/ sub-dir)
9+
config_name=$1
1010

11-
python3 scripts/qemu/qemu_config.py $config_file
11+
# Parse the config file to get topology info and fix escaped single quotes
12+
parsed_config=$(python3 "$(dirname $0)/parse_config.py" "$(dirname $0)/configs/${config_name}" | sed s/''\''/'/g)
1213

13-
if grep -q '<interconnects>' "$config_file"; then
14-
hmat="on"
15-
else
16-
hmat="off"
17-
fi
14+
set -x
1815

1916
sudo qemu-system-x86_64 \
2017
-drive file=./ubuntu-23.04-server-cloudimg-amd64.img,format=qcow2,index=0,media=disk,id=hd \
2118
-cdrom ./ubuntu-cloud-init.iso \
22-
-machine q35,usb=off,hmat=$hmat \
2319
-enable-kvm \
2420
-net nic -net user,hostfwd=tcp::2222-:22 \
25-
$(python3 scripts/qemu/qemu_config.py $config_file | sed s/''\''/'/g) \
21+
${parsed_config} \
2622
-daemonize -display none
2723

24+
# Enable ssh connection to the VM
2825
until ssh-keyscan -p 2222 -H 127.0.0.1 >> ~/.ssh/known_hosts 2>/dev/null; do
2926
echo "Waiting for SSH..."
3027
sleep 1

0 commit comments

Comments
 (0)