Skip to content

Commit 7fbb857

Browse files
[CI] clean up the qemu workflow and scripts a little
- rename 'qemu_config.py' to 'parse_config.py' (it's already in qemu dir); - minor changes, removal of redundant code, extra comments, etc.
1 parent fe6a82c commit 7fbb857

File tree

5 files changed

+41
-30
lines changed

5 files changed

+41
-30
lines changed

.github/workflows/qemu.yml

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-22.04
1616

1717
steps:
18-
- name: Checkout
18+
- name: Checkout UMF
1919
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
2020
with:
2121
fetch-depth: 0
@@ -25,16 +25,20 @@ jobs:
2525
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
2626
sudo udevadm control --reload-rules
2727
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
28+
29+
- name: Install dependencies
3230
run: |
33-
sudo apt-get install -y libvirt-clients libvirt-daemon-system libvirt-daemon virtinst bridge-utils
31+
sudo apt-get update
32+
sudo apt-get install -y qemu-system genisoimage qemu-utils \
33+
libvirt-clients libvirt-daemon-system libvirt-daemon virtinst bridge-utils
3434
pip install -r scripts/qemu/requirements.txt
35-
sudo usermod -a -G kvm,libvirt $USER
35+
36+
- name: Add user to kvm group
37+
run: sudo usermod -a -G kvm,libvirt $USER
38+
3639
- name: Run ssh-keygen
3740
run: ssh-keygen -b 4096 -N '' -f ~/.ssh/id_rsa
41+
3842
- name: Generate iso with user info
3943
run: |
4044
pub_key=$(cat ~/.ssh/id_rsa.pub)
@@ -69,11 +73,14 @@ jobs:
6973
EOF
7074
7175
sudo -Sk genisoimage -output ubuntu-cloud-init.iso -volid cidata -joliet -rock ./user-data ./meta-data
76+
7277
- name: Download ubuntu image
7378
run: wget https://cloud-images.ubuntu.com/releases/lunar/release/ubuntu-23.04-server-cloudimg-amd64.img
79+
7480
- name: Resize image
7581
run: qemu-img resize ./ubuntu-23.04-server-cloudimg-amd64.img +4G
76-
- name: Build
82+
83+
- name: Build UMF in QEMU
7784
run: |
7885
scripts/qemu/start_qemu.sh scripts/qemu/configs/default.xml
7986
@@ -85,27 +92,22 @@ jobs:
8592
8693
scp -P 2222 ${{github.workspace}}/scripts/qemu/run-build.sh [email protected]:/home/cxltest
8794
scp -P 2222 ${{github.workspace}}/scripts/qemu/run-tests.sh [email protected]:/home/cxltest
88-
ssh [email protected] -p 2222 -t "bash /home/cxltest/run-build.sh https://github.com/$CI_REPO ${{env.CI_BRANCH}}"
8995
96+
ssh [email protected] -p 2222 -t "bash /home/cxltest/run-build.sh https://github.com/$CI_REPO ${{env.CI_BRANCH}}"
9097
ssh [email protected] -p 2222 -t "sudo shutdown -h now"
9198
92-
- name: Run tests
99+
- name: Run tests in QEMU
93100
run: |
94101
for config_file in scripts/qemu/configs/*.xml; do
95102
config_name=$(basename $config_file .xml)
96103
97-
echo testing $config_name
98104
while ps -aux | grep qemu-system-x86_64 | grep -q -v grep; do
99105
echo "Waiting for QEMU to shut down..."
100106
sleep 5
101107
done
108+
109+
echo "\n ### Testing ${config_name} ###"
102110
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
109111
110112
ssh [email protected] -p 2222 -t "bash /home/cxltest/run-tests.sh"
111113
ssh [email protected] -p 2222 -t "sudo shutdown -h now"

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313
import psutil
1414
import shutil
1515

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

2124
TopologyCfg = collections.namedtuple(
2225
"TopologyCfg", ["name", "hmat", "cpu_model", "cpu_options", "mem_options"]
@@ -27,7 +30,7 @@
2730

2831
def enable_verbose():
2932
"""
30-
Parse command line arguments
33+
Check if env var ENABLE_VERBOSE is set and enable verbose mode
3134
"""
3235
global verbose_mode
3336
verbose_mode = os.getenv("ENABLE_VERBOSE", False)
@@ -50,6 +53,9 @@ def parse_topology_xml(tpg_file_name: str) -> TopologyCfg:
5053
result.check_returncode()
5154
libvirt_args = result.stdout.decode("utf-8").strip()
5255

56+
if verbose_mode != False:
57+
print(f"\nFull libvirt_args: {libvirt_args}\n")
58+
5359
tpg_cfg = {
5460
"name": re.search(r"guest=(\w+)", libvirt_args).group(1),
5561
"hmat": "hmat=on" in libvirt_args,
@@ -74,7 +80,7 @@ def parse_topology_xml(tpg_file_name: str) -> TopologyCfg:
7480
except subprocess.CalledProcessError:
7581
sys.exit(f"\n XML file: {tpg_file_name} error in virsh parsing")
7682
except Exception:
77-
sys.exit(f"\n Provided file is missing or missing virsh.")
83+
sys.exit(f"\n Provided file ({tpg_file_name}) is missing or missing virsh.")
7884
return tpg
7985

8086

@@ -89,7 +95,7 @@ def get_qemu_args(tpg_file_name: str) -> str:
8995

9096
def calculate_memory(tpg: TopologyCfg) -> str:
9197
"""
92-
Memory used by QEMU
98+
Total memory required by given QEMU config
9399
"""
94100
if tpg.mem_options:
95101
mem_needed = 0
@@ -112,4 +118,6 @@ def calculate_memory(tpg: TopologyCfg) -> str:
112118
tpg_file_name = sys.argv[1]
113119
else:
114120
sys.exit(f"\n Usage: {sys.argv[0]} <tpg_file_name>")
121+
122+
# Print QEMU arguments as a result of this script
115123
print(get_qemu_args(tpg_file_name))

scripts/qemu/run-build.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ set -e
88
repo=$1
99
branch=$2
1010

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
11+
echo password | sudo -Sk apt-get update
12+
echo password | sudo -Sk apt-get install -y git cmake gcc g++ pkg-config \
13+
numactl libnuma-dev hwloc libhwloc-dev libjemalloc-dev libtbb-dev valgrind
1314

1415
git clone $repo umf
1516
cd umf

scripts/qemu/run-tests.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
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

98
config_file=$1
109

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

1313
if grep -q '<interconnects>' "$config_file"; then
1414
hmat="on"
@@ -19,12 +19,13 @@ fi
1919
sudo qemu-system-x86_64 \
2020
-drive file=./ubuntu-23.04-server-cloudimg-amd64.img,format=qcow2,index=0,media=disk,id=hd \
2121
-cdrom ./ubuntu-cloud-init.iso \
22-
-machine q35,usb=off,hmat=$hmat \
22+
-machine q35,usb=off,hmat=${hmat} \
2323
-enable-kvm \
2424
-net nic -net user,hostfwd=tcp::2222-:22 \
25-
$(python3 scripts/qemu/qemu_config.py $config_file | sed s/''\''/'/g) \
25+
${parsed_config} \
2626
-daemonize -display none
2727

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

0 commit comments

Comments
 (0)