From 199dcdbcaa84a39c60f0f95bbcf687b537e7056a Mon Sep 17 00:00:00 2001 From: "wu.zhihui" Date: Thu, 4 Aug 2016 10:11:16 +0800 Subject: [Yardstick-233]DPDK image for TC042 These file is based on Akos's code. (https://gerrit.opnfv.org/gerrit/#/c/16095/) The different places: 1. create flavor and import yardstick_key.pub with heat template. 2. remove handle code about eth0 in user_data. 3. update heat cli and delete step "nova stop" which is not necessary. 4. clean the stack in final. 5. add eth2 for vm. JIRA: YARDSTICK-233 Change-Id: I04f2051fb4bcfeed2df4868d758fd92011c62233 Signed-off-by: wu.zhihui --- tools/dpdk_install.yml | 124 +++++++++++++++++++++ tools/ubuntu-server-cloudimg-dpdk-modify.sh | 98 +++++++++++++++++ tools/yardstick-img-dpdk-finalize.sh | 39 +++++++ tools/yardstick-img-dpdk-modify | 162 ++++++++++++++++++++++++++++ 4 files changed, 423 insertions(+) create mode 100644 tools/dpdk_install.yml create mode 100755 tools/ubuntu-server-cloudimg-dpdk-modify.sh create mode 100644 tools/yardstick-img-dpdk-finalize.sh create mode 100644 tools/yardstick-img-dpdk-modify diff --git a/tools/dpdk_install.yml b/tools/dpdk_install.yml new file mode 100644 index 000000000..12c83e144 --- /dev/null +++ b/tools/dpdk_install.yml @@ -0,0 +1,124 @@ +heat_template_version: 2015-04-30 + +description: > + Used to run VMs with DPDK pktgen + +parameters: + image: + type: string + description: Name of the image + default: yardstick-wily-server + + timeout: + type: number + description: Timeout in seconds for WaitCondition, depends on your image and environment + default: 900 + + external_net_name: + type: string + description: Name of the external network which management network will connect to + default: admin_floating_net + +resources: + flavor: + type: OS::Nova::Flavor + properties: + ram: 4096 + vcpus: 4 + disk: 4 + + network: + type: OS::Neutron::Net + properties: + name: dpdk_net + + subnet: + type: OS::Neutron::Subnet + properties: + name: dpdk_subnet + ip_version: 4 + cidr: 192.168.0.0/24 + network: { get_resource: network } + + management_router: + type: OS::Neutron::Router + properties: + name: management_router + external_gateway_info: + network: { get_param: external_net_name } + + management_router_interface: + type: OS::Neutron::RouterInterface + properties: + router: { get_resource: management_router } + subnet: { get_resource: subnet } + + floating_ip: + type: OS::Neutron::FloatingIP + properties: + floating_network: { get_param: external_net_name } + + floating_ip_association: + type: OS::Nova::FloatingIPAssociation + properties: + floating_ip: { get_resource: floating_ip } + server_id: {get_resource: dpdk_vm} + + keypair: + type: OS::Nova::KeyPair + properties: + name: yardstick-key + public_key: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD0RkXfW6pksd1cZmXuvXZF/Mlqqq3ahIGcGoULOC97XMpu0vdxMpcUwdjwGqMwEXTVyfHidu0l99bLqOCpSUKCmbWx3ONJ+1kqFx4HwsKEWLiyDYqsuMrDeZT1eFjC5avCoTcrIw2wq5NaBb00lDGagNZOeopaL5YIa4+PizEY23+cir24D67NU21Fg3JE92AIeGlNa4j66L3a+lL0hZq74Dilmp42wm4GsbplRO6KJfyaraowHb1X+TmhCjBgHk6M/OJ9yPAroZyJNcwjMAuuxhAYWRuT3SdbnoUR0RG2VhfDh0qNid7vOqLbhKPeaLLFmzkN+9w3WdCp6LbSYt87 yardstick@yardstick.opnfv.org + + wait_handle: + type: OS::Heat::WaitConditionHandle + + wait_condition: + type: OS::Heat::WaitCondition + properties: + handle: { get_resource: wait_handle } + count: 1 + timeout: { get_param: timeout } + + dpdk_vm: + type: OS::Nova::Server + depends_on: [subnet, keypair, flavor] + properties: + name: { get_param: "OS::stack_name" } + image: { get_param: image } + flavor: { get_resource: flavor } + key_name: {get_resource: keypair} + networks: + - network: { get_resource: network } + config_drive: True + user_data_format : RAW + user_data: + str_replace: + template: | + #!/bin/sh + cat <<'CEOF' > /tmp/dpdk_post_build.sh + export RTE_SDK=/dpdk + export RTE_TARGET=x86_64-native-linuxapp-gcc + cd /dpdk + make install T=x86_64-native-linuxapp-gcc DESTDIR=destdir + modprobe uio + insmod /dpdk/x86_64-native-linuxapp-gcc/kmod/igb_uio.ko + insmod /dpdk/x86_64-native-linuxapp-gcc/kmod/rte_kni.ko + cd /pktgen-dpdk + make RTE_SDK=/dpdk + echo "PCKTGEN BUILT" + rm -rf /var/lib/cloud/instances + echo "rm succesfull" + ls /dpdk/x86_64-native-linuxapp-gcc/kmod/ + $NOTIFY --data-binary '{"status": "SUCCESS"}' + CEOF + chmod +x /tmp/dpdk_post_build.sh + echo "chmod" + nohup /tmp/dpdk_post_build.sh & + params: + $NOTIFY: { get_attr: ['wait_handle', 'curl_cli'] } + +outputs: + vm_uuid: + description: uuid of the VM + value: { get_attr: [ dpdk_vm, show,id ] } diff --git a/tools/ubuntu-server-cloudimg-dpdk-modify.sh b/tools/ubuntu-server-cloudimg-dpdk-modify.sh new file mode 100755 index 000000000..edcbeb61a --- /dev/null +++ b/tools/ubuntu-server-cloudimg-dpdk-modify.sh @@ -0,0 +1,98 @@ +#!/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 +############################################################################## + +# installs required packages +# must be run from inside the image (either chrooted or running) + +set -ex + +if [ $# -eq 1 ]; then + nameserver_ip=$1 + + # /etc/resolv.conf is a symbolic link to /run, restore at end + rm /etc/resolv.conf + echo "nameserver $nameserver_ip" > /etc/resolv.conf + echo "nameserver 8.8.8.8" >> /etc/resolv.conf + echo "nameserver 8.8.4.4" >> /etc/resolv.conf +fi + +# iperf3 only available for wily in backports +grep wily /etc/apt/sources.list && \ + echo "deb http://archive.ubuntu.com/ubuntu/ wily-backports main restricted universe multiverse" >> /etc/apt/sources.list + +# Workaround for building on CentOS (apt-get is not working with http sources) +# sed -i 's/http/ftp/' /etc/apt/sources.list + +# Force apt to use ipv4 due to build problems on LF POD. +echo 'Acquire::ForceIPv4 "true";' > /etc/apt/apt.conf.d/99force-ipv4 + +echo 'GRUB_CMDLINE_LINUX="resume=/dev/sda1 default_hugepagesz=1G hugepagesz=1G hugepages=1 iommu=on iommu=pt intel_iommu=on"' >> /etc/default/grub +echo 'vm.nr_hugepages=512' >> /etc/sysctl.conf +echo 'huge /mnt/huge hugetlbfs defaults 0 0' >> vi /etc/fstab + +mkdir /mnt/huge +chmod 777 /mnt/huge + +for i in {1..2} +do + touch /etc/network/interfaces.d/eth$i.cfg + chmod 777 /etc/network/interfaces.d/eth$i.cfg + echo "auto eth$i" >> /etc/network/interfaces.d/eth$i.cfg + echo "iface eth$i inet dhcp" >> /etc/network/interfaces.d/eth$i.cfg +done + +# this needs for checking dpdk status, adding interfaces to dpdk, bind, unbind etc.. + +# Add hostname to /etc/hosts. +# Allow console access via pwd +cat </etc/cloud/cloud.cfg.d/10_etc_hosts.cfg +manage_etc_hosts: True +password: RANDOM +chpasswd: { expire: False } +ssh_pwauth: True +EOF + +linuxheadersversion=`echo ls boot/vmlinuz* | cut -d- -f2-` + +apt-get update +apt-get install -y \ + fio \ + gcc \ + git \ + iperf3 \ + linux-tools-common \ + linux-tools-generic \ + lmbench \ + make \ + netperf \ + patch \ + perl \ + rt-tests \ + stress \ + sysstat \ + linux-headers-$linuxheadersversion \ + libpcap-dev \ + lua5.2 + +git clone http://dpdk.org/git/dpdk +git clone http://dpdk.org/git/apps/pktgen-dpdk + +git clone https://github.com/kdlucas/byte-unixbench.git /opt/tempT +make --directory /opt/tempT/UnixBench/ + +git clone https://github.com/beefyamoeba5/ramspeed.git /opt/tempT/RAMspeed +cd /opt/tempT/RAMspeed/ramspeed-2.6.0 +mkdir temp +bash build.sh + +git clone https://github.com/beefyamoeba5/cachestat.git /opt/tempT/Cachestat + +# restore symlink +ln -sf /run/resolvconf/resolv.conf /etc/resolv.conf diff --git a/tools/yardstick-img-dpdk-finalize.sh b/tools/yardstick-img-dpdk-finalize.sh new file mode 100644 index 000000000..b9ea83e11 --- /dev/null +++ b/tools/yardstick-img-dpdk-finalize.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# installs dpdk and pktgen packages on modified image + +# PREREQUISITES +# modified image (yardstick-wily-server) must be uploaded to OpenStack +# heat must be installed: apt-get install python-heatclient, python-glanceclient, python-nova +# must have a public yardstick-key uploaded in openstack +# must have a proper flavor for the image (i.e. m1.small) + + +stackname="yardstick-modify-stack" +template=dpdk_install.yml +new_image_name="yardstick-image-pktgen-ready" + +openstack stack create $stackname -f yaml -t $template +progress="WARMING_UP" + +while [ "$progress" != "CREATE_COMPLETE" ] +do + sleep 10 + echo "check stack status......." + show_output=$(openstack stack show $stackname) + progress=$(echo $show_output | sed 's/^.*stack_status . \([^ ]*\).*$/\1/') + echo "$progress" + if [ "$progress" == "CREATE_FAILED" ];then + echo "create $stackname failed" + exit 1 + fi +done + +status=$(nova image-create --poll $stackname $new_image_name) +if [[ "$status" =~ "Finished" ]];then + echo "$new_image_name finished" +fi + +nova delete $stackname +sleep 10 +openstack stack delete --yes $stackname diff --git a/tools/yardstick-img-dpdk-modify b/tools/yardstick-img-dpdk-modify new file mode 100644 index 000000000..ec2672d27 --- /dev/null +++ b/tools/yardstick-img-dpdk-modify @@ -0,0 +1,162 @@ +#!/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 +############################################################################## + +# yardstick-img-dpdk-modify - download and modify a Ubuntu cloud image +# +# The actual customization is done by a script passed with an absolute path as +# the only single argument. The command needs to be invoked as sudo +# +# Example invocation: +# yardstick-img-dpdk-modify /home/yardstick/tools/ubuntu-server-cloudimg-dpdk-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 +} + +test $# -eq 1 || die "no image specific script as argument" +test $(id -u) -eq 0 || die "should invoke using sudo" + +cmd=$1 +test -x $cmd +mountdir="/mnt/yardstick" + +workspace=${WORKSPACE:-"/tmp/workspace/yardstick"} +host=${HOST:-"cloud-images.ubuntu.com"} +release=${RELEASE:-"wily"} +image_path="${release}/current/${release}-server-cloudimg-amd64-disk1.img" +image_url=${IMAGE_URL:-"https://${host}/${image_path}"} +md5sums_path="${release}/current/MD5SUMS" +md5sums_url=${MD5SUMS_URL:-"https://${host}/${md5sums_path}"} + +imgfile="${workspace}/yardstick-${release}-server" +raw_imgfile="${workspace}/yardstick-${release}-server.raw" +filename=$(basename $image_url) + +# download and checksum base image, conditionally if local copy is outdated +download() { + test -d $workspace || mkdir -p $workspace + cd $workspace + rm -f MD5SUMS # always download the checksum file to a detect stale image + wget $md5sums_url + test -e $filename || wget -nc $image_url + grep $filename MD5SUMS | md5sum -c || + if [ $? -ne 0 ]; then + rm $filename + wget -nc $image_url + grep $filename MD5SUMS | md5sum -c + fi + qemu-img convert $filename $raw_imgfile + cd - +} + +# mount image +setup() { + mkdir -p $mountdir + + for i in $(seq 0 9); do + [ -a /dev/loop$i ] || mknod -m 660 /dev/loop$i b 7 $i + done + + loopdevice=$(kpartx -l $raw_imgfile | head -1 | cut -f1 -d ' ') + + kpartx -a $raw_imgfile + + mount /dev/mapper/$loopdevice $mountdir + mount -t proc none $mountdir/proc + + echo $loopdevice + + sudo resize2fs /dev/mapper/$loopdevice + + cp $cmd $mountdir/$(basename $cmd) +} + +# modify image running a script using in a chrooted environment +modify() { + # resolv.conf does not exist in base image, pass nameserver value from host + nameserver_ip=$(grep -m 1 '^nameserver' \ + /etc/resolv.conf | awk '{ print $2 '}) + + # prevent init scripts from running during install + echo $'#!/bin/sh\nexit 101' >$mountdir/usr/sbin/policy-rc.d + chmod a+x $mountdir/usr/sbin/policy-rc.d + + chroot $mountdir /$(basename $cmd) $nameserver_ip + + rm -rf $mountdir/usr/sbin/policy-rc.d + + umount -f $mountdir/proc + umount $mountdir + + qemu-img convert -c -o compat=0.10 -O qcow2 $raw_imgfile $imgfile +# qemu-img convert -O vmdk $raw_imgfile $imgfile + + if dmsetup table | grep $loopdevice; then + dmsetup clear $loopdevice || true + fi +} + +# cleanup (umount) the image +cleanup() { + # designed to be idempotent + mount | grep $mountdir/proc && umount $mountdir/proc + mount | grep $mountdir && umount $mountdir + if [ -f $raw_imgfile ]; then + kpartx -dv $raw_imgfile || true + fi + 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