From 5ab89ebafc604b010730380a0260796a5f3a69b7 Mon Sep 17 00:00:00 2001 From: Yunhong Jiang Date: Fri, 11 Dec 2015 14:38:49 -0500 Subject: Script to create the rt-tests rpm There is no rt-tests rpm on centos repo, also we need some special compile flag to enable the -a parameter. So we try to make the rpm ourselves. The version is specified as 0.96. But please notice that the Makefile in the rt-tests tree requires some key, we have to disable that requirement. So this rpm is only for OPNFV testing purpose. Change-Id: Ifdd52649bc14405dbe5ad375dc7fd32087139b18 Signed-off-by: Yunhong Jiang --- ci/envs/create-rt-tests-rpm.sh | 30 ++++++++++++++++++++++++++++++ ci/envs/rt-tests.patch | 26 ++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 ci/envs/create-rt-tests-rpm.sh create mode 100644 ci/envs/rt-tests.patch diff --git a/ci/envs/create-rt-tests-rpm.sh b/ci/envs/create-rt-tests-rpm.sh new file mode 100644 index 000000000..96fef2bcd --- /dev/null +++ b/ci/envs/create-rt-tests-rpm.sh @@ -0,0 +1,30 @@ +#!/bin/bash +############################################################################## +## Copyright (c) 2015 Intel Corp. +## +## All rights reserved. This program and the accompanying materials +## are made available under the terms of the Apache License, Version 2.0 +## which accompanies this distribution, and is available at +## http://www.apache.org/licenses/LICENSE-2.0 +############################################################################### + +usage () +{ + echo "$0 rpmdir" + exit 1 +} + +rpmdir=$1 +rm -rf ${rpmdir}/rt-tests-0.96-1.el7.centos.x86_64.rpm +gitdir=`mktemp -d` +ROOTDIR=$(cd $(dirname "$0")/../.. && pwd) +VERSION=v0.96 +cd $gitdir +git clone https://git.kernel.org/pub/scm/utils/rt-tests/rt-tests.git +cd rt-tests +git checkout -b ${VERSION} ${VERSION} +patch -p1 -i ${ROOTDIR}/ci/envs/rt-tests.patch +make HAVE_PARSE_CPUSTRING_ALL=1 rpm +cp ./RPMS/x86_64/rt-tests-0.96-1.el7.centos.x86_64.rpm $rpmdir +rm -rf $gitdir + diff --git a/ci/envs/rt-tests.patch b/ci/envs/rt-tests.patch new file mode 100644 index 000000000..b938e0768 --- /dev/null +++ b/ci/envs/rt-tests.patch @@ -0,0 +1,26 @@ +/******************************************************************************* + * * Copyright (c) 2015 Intel Corp. + * * + * * All rights reserved. This program and the accompanying materials + * * are made available under the terms of the Apache License, Version 2.0 + * * which accompanies this distribution, and is available at + * * http://www.apache.org/licenses/LICENSE-2.0 + * *******************************************************************************/ + +diff --git a/Makefile b/Makefile +index 1e4b7d1b0d3a..98968b94a57f 100644 +--- a/Makefile ++++ b/Makefile +@@ -198,10 +198,10 @@ release: distclean changelog + cp -r Makefile COPYING ChangeLog MAINTAINERS doc README.markdown src tmp/rt-tests + rm -f rt-tests-$(VERSION).tar rt-tests-$(VERSION).tar.asc + tar -C tmp -cf rt-tests-$(VERSION).tar rt-tests +- gpg2 --default-key clrkwllms@kernel.org --detach-sign --armor rt-tests-$(VERSION).tar ++ #gpg2 --default-key clrkwllms@kernel.org --detach-sign --armor rt-tests-$(VERSION).tar + gzip rt-tests-$(VERSION).tar + rm -f ChangeLog +- cp rt-tests-$(VERSION).tar.gz rt-tests-$(VERSION).tar.asc releases ++ cp rt-tests-$(VERSION).tar.gz releases + + .PHONY: tarball + tarball: -- cgit 1.2.3-korg From e5463c6781f5cf7ad4b353232be9ff3721fadf0b Mon Sep 17 00:00:00 2001 From: Yunhong Jiang Date: Wed, 9 Dec 2015 14:55:56 -0500 Subject: Script to create the guest image This script download the latest CentOS cloud image and modify it to meet the test requirement, including remove cloud related script, setup the ssh keys etc. It derives from yardstick project, which currently only provide support to Ubuntu image. If they support CentOS image, we can possibly switch to them. Change-Id: I9482936615a28da696ff8f51248a62b13e5677f4 Signed-off-by: Yunhong Jiang --- ci/envs/guest-cmd.sh | 10 ++++ ci/envs/guest-modify.sh | 142 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100755 ci/envs/guest-cmd.sh create mode 100755 ci/envs/guest-modify.sh diff --git a/ci/envs/guest-cmd.sh b/ci/envs/guest-cmd.sh new file mode 100755 index 000000000..abfa51a40 --- /dev/null +++ b/ci/envs/guest-cmd.sh @@ -0,0 +1,10 @@ +#!/bin/bash +############################################################################## +## Copyright (c) 2015 Intel Corp. +## +## All rights reserved. This program and the accompanying materials +## are made available under the terms of the Apache License, Version 2.0 +## which accompanies this distribution, and is available at +## http://www.apache.org/licenses/LICENSE-2.0 +############################################################################### + diff --git a/ci/envs/guest-modify.sh b/ci/envs/guest-modify.sh new file mode 100755 index 000000000..1208dd37e --- /dev/null +++ b/ci/envs/guest-modify.sh @@ -0,0 +1,142 @@ +#!/bin/bash + +############################################################################## +# Copyright (c) 2015 Ericsson AB and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +# This is copy from yardstick-img-modify on yardstick project. Currently +# yardstick script only ubuntu image, and this one is more for CentOS. +# Example invocation: +# yardstick-img-modify /home/yardstick/tools/ubuntu-server-cloudimg-modify.sh +# +# Warning: the script will create files by default in: +# /tmp/workspace/yardstick +# the files will be owned by root! +# +# TODO: image resize is needed if the base image is too small +# + +set -e +set -x + +die() { + echo "error: $1" >&2 + exit 1 +} + +usage () { + echo "$0 cmd workspace" + exit 1 +} + +test $# -eq 2 || usage +test $(id -u) -eq 0 || die "should invoke using sudo" + +ROOTDIR=$(cd $(dirname "$0")/../.. && pwd) +cmd=$1 +test -x $cmd +workspace=$2 +mountdir=`mktemp -d` + +image_url=${IMAGE_URL:-"http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-1510.qcow2"} +md5sums_url=${MD5SUMS_URL:-"http://cloud.centos.org/centos/7/images/sha256sum.txt"} + +imgfile="${workspace}/guest.img" +raw_imgfile="${workspace}/guest.raw" +filename=$(basename $image_url) +md5filename=$(basename $md5sums_url) + +# download and checksum base image, conditionally if local copy is outdated +download() { + test -d $workspace || mkdir -p $workspace + cd $workspace + rm -f $md5filename # always download the checksum file to a detect stale image + wget $md5sums_url + test -e $filename || wget -nc $image_url + grep "$filename\$" $md5filename |sha256sum -c + if [ $? -ne 0 ]; then + rm $filename + wget -nc $image_url + grep $filename $md5filename | md5sum -c + fi + rm -rf $raw_imgfile + qemu-img convert $filename $raw_imgfile + cd - +} + +# mount image +setup() { + mkdir -p $mountdir + + loopdevice=$(kpartx -l $raw_imgfile | head -1 | cut -f1 -d ' ') + + kpartx -a $raw_imgfile + # No idea why need this sleep + sleep 3 + mount /dev/mapper/$loopdevice $mountdir + + cp $cmd "$mountdir/" +} + +# modify image running a script using in a chrooted environment +modify() { + # Add the ssh key to the image + mkdir -p ${mountdir}/root/.ssh + cp ${ROOTDIR}/ci/envs/kvm4nfv_key.pub ${mountdir}/root/.ssh/authorized_keys + chmod 700 ${mountdir}/root/.ssh + chmod 600 ${mountdir}/root/.ssh/authorized_keys + + + umount $mountdir + + qemu-img convert -O qcow2 $raw_imgfile $imgfile +} + +# cleanup (umount) the image +cleanup() { + # designed to be idempotent + mount | grep $mountdir && umount $mountdir + kpartx -d $raw_imgfile || true + rm -f $raw_imgfile + rm -rf $mountdir +} + +exitcode="" +error_trap() +{ + local rc=$? + + set +e + + if [ -z "$exitcode" ]; then + exitcode=$rc + fi + + cleanup + + echo "Image build failed with $exitcode" + + exit $exitcode +} + +main() { + cleanup + + trap "error_trap" EXIT SIGTERM + + download + setup + modify + + trap - EXIT SIGTERM + cleanup + + echo "the modified image is found here: $imgfile" +} + +main -- cgit 1.2.3-korg From 0fcee09d0a19457df88a4cea607de08e52ee959e Mon Sep 17 00:00:00 2001 From: Yunhong Jiang Date: Fri, 4 Dec 2015 18:01:29 -0500 Subject: A script to launch real time guest Launch real time guest need special options like lock memory etc. A script is used to achieved this. We invoke the qemu utility directly instead of going through middle layer like libvirt, to get better controll. Change-Id: Ia6ad7313463e2f858516bddd4a4b58e95d8c943e Signed-off-by: David Su Signed-off-by: Yunhong Jiang --- ci/envs/host-run-qemu.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 ci/envs/host-run-qemu.sh diff --git a/ci/envs/host-run-qemu.sh b/ci/envs/host-run-qemu.sh new file mode 100755 index 000000000..c7a2fecc6 --- /dev/null +++ b/ci/envs/host-run-qemu.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +############################################################################## +## Copyright (c) 2015 Intel Corp. +## +## All rights reserved. This program and the accompanying materials +## are made available under the terms of the Apache License, Version 2.0 +## which accompanies this distribution, and is available at +## http://www.apache.org/licenses/LICENSE-2.0 +############################################################################### + +source host-config + +cpumask () { + m=$((1<<${1})) + printf 0x%x ${m} +} + +qmp_sock="/tmp/qmp-sock-$$" + +${qemu} -smp ${guest_cpus} -monitor unix:${qmp_sock},server,nowait -daemonize \ + -cpu host,migratable=off,+invtsc,+tsc-deadline,pmu=off \ + -realtime mlock=on -mem-prealloc -enable-kvm -m 1G \ + -mem-path /mnt/hugetlbfs-1g \ + -drive file=/root/workspace/image/guest.img,cache=none,aio=threads \ + -netdev user,id=guest0,hostfwd=tcp::5555-:22 \ + -device virtio-net-pci,netdev=guest0 \ + -nographic -serial /dev/null -parallel /dev/null + +i=0 +for c in `echo ${host_isolcpus} | sed 's/,/ /g'` ; do + cpu[$i]=${c} + i=`expr $i + 1` +done + +threads=`echo "info cpus" | nc -U ${qmp_sock} | grep thread_id | cut -d= -f3` + +# Bind QEMU processor threads to RT CPUs +i=0 +for tid in ${threads} ; do + tid=`printf %d ${tid}` # this is required to get rid of cr at end + mask=`cpumask ${cpu[$i]}` + taskset -p ${mask} ${tid} + i=`expr $i + 1` +done -- cgit 1.2.3-korg