Initial commit

This commit is contained in:
Dmitry Vlasov
2023-11-17 03:49:01 +03:00
commit 26512eedae
3 changed files with 625 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
* eol=lf
+149
View File
@@ -0,0 +1,149 @@
# RBD Test
### Links
1. [Linux NFS-HOWTO - Optimizing NFS Performance](https://nfs.sourceforge.net/nfs-howto/ar01s05.html)
### Example of use
```
git clone https://gitlab.resds.ru/vlasov.dv/nfs-test.git
cd nfs-test
chmod +x create-vm.sh
./create-vm.sh --bootstrap-env env
vi env
sudo ./create-vm.sh -e ./env
sudo less -R /tmp/create-vm/Ubuntu22.04/serial.log # For observing the test
```
As a result you will get something like that:
```
Using uid:0, gid:0.
Writing a byte at a time...done
Writing intelligently...done
Rewriting...done
Reading a byte at a time...done
Reading intelligently...done
start 'em...done...done...done...done...done...
Create files in sequential order...done.
Stat files in sequential order...done.
Delete files in sequential order...done.
Create files in random order...done.
Stat files in random order...done.
Delete files in random order...done.
Version 2.00 ------Sequential Output------ --Sequential Input- --Random-
-Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--
Name:Size etc /sec %CP /sec %CP /sec %CP /sec %CP /sec %CP /sec %CP
Ubuntu22 4G 751k 97 155m 33 35.4m 12 974k 96 41.8m 8 227.2 11
Latency 15686us 203ms 367ms 358ms 282ms 396ms
Version 2.00 ------Sequential Create------ --------Random Create--------
Ubuntu22 -Create-- --Read--- -Delete-- -Create-- --Read--- -Delete--
files /sec %CP /sec %CP /sec %CP /sec %CP /sec %CP /sec %CP
16 1 2 +++++ +++ 724249376 2 1 1 +++++ +++ 724249376 1
Latency 1858ms 46383us 1105ms 2012ms 2620us 2165ms
1.98,2.00,Ubuntu22,1,1700182713,4G,,8192,5,751,97,159132,33,36287,12,974,96,42847,8,227.2,11,16,,,,,49,2,+++++,+++,95,2,45,1,+++++,+++,78,1,15686us,203ms,367ms,358ms,282ms,396ms,1858ms,46383us,1105ms,2012ms,2620us,2165ms
```
### Usage of `./create-vm.sh`:
```
usage:
./create-vm.sh required_args [optional_args] OR
./create-vm.sh misc_args
Create a new virtual machine from a specified yaml config
misc_args:
--bootstrap-env ENV_PATH create template env file and exit
required_args:
-n, --name NAME name of a virtual machine
-o, --os-variant OS_VARIANT operating system
-m, --memory MEMORY RAM size
-c, --vcpus VCPUS Amount of of cores
-i, --image IMAGE URL or path to an ISO image
-s, --size SIZE Size of an OS drive (example: 8G)
-b, --bridge BRIDGE bridge name (LinuxBridge only)
-a, --ip-address IP ip address of eth0
-p, --prefix PREFIX network prefix
-g, --gateway GATEWAY ip address of network gateway
-d, --dns DNS ip address of dns server
-N, --nfs NFS_IP:NFS_DIR ip address and dir of NFS share
default: 172.17.5.99:/var/nfs/general
-A, --nfs-args NFS_ARGS mount arguments of nfs
default: auto,nofail,noatime,nolock,intr,tcp,actimeo=1800
-t, --test-suite TEST_UTIL what should be used for the test
(bonnie++ and iozone are available)
default: bonnie++
-T, --testargs TEST_UTIL_ARGS arguments that shoud be passed to
testing program
(-d for bonnie++ or -f for iozone
being set automatically)
default: -u 0
optional_args:
-h, --help show this help message and exit
-e, --env export args from env file
-r, --rm-if-exist if vm exist, remove it first
default: false
-P, --pubkey PUBKEY place public key into autorized_keys of
all defined in config.yaml users
default: /home/$USER/.ssh/id_rsa.pub
-v, --vnc-password VNC_PASSWORD vnc console password
default: PASSWD1!
-C, --cloud-init CLOUD_INIT Path to a cloud-init config - will be
created if not provided
env example:
NAME=Ubuntu22.04
OS_VARIANT=ubuntu22.04
MEMORY=2048
VCPUS=2
IMAGE=https://cloud-images.ubuntu.com/jammy/20231010/jammy-server-cloudimg-amd64.img
SIZE=8G
BRIDGE=virbr0
IP=192.168.122.2
PREFIX=24
GATEWAY=192.168.122.1
DNS=8.8.8.8
NFS_IP=172.17.5.99
NFS_DIR=/var/nfs/general
NFS_ARGS=auto,nofail,noatime,nolock,intr,tcp,actimeo=1800
TEST_UTIL=bonnie++
TEST_UTIL_ARGS="-u 0"
RM=true
PUBKEY=/home/cloudadmin/.ssh/id_rsa.pub
VNC_PASSWORD=PASSWD1!
cloud-init example:
#cloud-config
package_upgrade: false
runcmd:
- touch /test.txt
packages:
- vim
- htop
- nfs-common
- bonnie++
- iozone3
users:
- name: ubuntu
ssh-authorized-keys:
- {{PUBKEY}}
sudo: ['ALL=(ALL) NOPASSWD:ALL']
ssh_pwauth: true
lock-passwd: false
chpasswd: {expire: False}
groups: sudo
shell: /bin/bash
- name: adminuser
ssh-authorized-keys:
- {{PUBKEY}}
sudo: ['ALL=(ALL) NOPASSWD:ALL']
ssh_pwauth: true
lock-passwd: false
chpasswd: {expire: False}
groups: sudo
shell: /bin/bash
runcmd:
- mkdir -p {{NFS_MOUNTPOINT}}
- echo '{{NFS_IP}}:{{NFS_DIR}} {{NFS_MOUNTPOINT}} nfs {{NFS_ARGS}} 0 0' >> /etc/fstab
- mount -a
- {{TEST_UTIL}} {{TEST_UTIL_ARGS}}
```
+475
View File
@@ -0,0 +1,475 @@
#!/usr/bin/env bash
# Creating a new virtual (another virt-viewer wrapper, yes)
#
# == Defaults =================================================================
DEFAULT_BASE_PATH=/tmp/create-vm
DEFAULT_NFS_MOUNTPOINT="/nfs/general"
DEFAULT_USER_INIT="#cloud-config
package_upgrade: false
runcmd:
- touch /test.txt
packages:
- vim
- htop
- nfs-common
- bonnie++
- iozone3
users:
- name: ubuntu
ssh-authorized-keys:
- {{PUBKEY}}
sudo: ['ALL=(ALL) NOPASSWD:ALL']
ssh_pwauth: true
lock-passwd: false
chpasswd: {expire: False}
groups: sudo
shell: /bin/bash
- name: adminuser
ssh-authorized-keys:
- {{PUBKEY}}
sudo: ['ALL=(ALL) NOPASSWD:ALL']
ssh_pwauth: true
lock-passwd: false
chpasswd: {expire: False}
groups: sudo
shell: /bin/bash
runcmd:
- mkdir -p {{NFS_MOUNTPOINT}}
- echo '{{NFS_IP}}:{{NFS_DIR}} {{NFS_MOUNTPOINT}} nfs {{NFS_ARGS}} 0 0' >> /etc/fstab
- mount -a
- {{TEST_UTIL}} {{TEST_UTIL_ARGS}}
"
DEFAULT_NETPLAN="network:
version: 2
renderer: networkd
ethernets:
enp1s0:
dhcp4: false
addresses:
- {{IP}}/{{PREFIX}}
routes:
- to: default
via: {{GATEWAY}}
nameservers:
addresses:
- {{DNS}}
"
DEFAULT_ENV="NAME=Ubuntu22.04
OS_VARIANT=ubuntu22.04
MEMORY=2048
VCPUS=2
IMAGE=https://cloud-images.ubuntu.com/jammy/20231010/jammy-server-cloudimg-amd64.img
SIZE=8G
BRIDGE=virbr0
IP=192.168.122.2
PREFIX=24
GATEWAY=192.168.122.1
DNS=8.8.8.8
NFS_IP=172.17.5.99
NFS_DIR=/var/nfs/general
NFS_ARGS=auto,nofail,noatime,nolock,intr,tcp,actimeo=1800
TEST_UTIL=bonnie++
TEST_UTIL_ARGS=\"-u 0\"
RM=true
PUBKEY=/home/cloudadmin/.ssh/id_rsa.pub
VNC_PASSWORD=PASSWD1!
"
# == Help =====================================================================
HELP="
usage:
$0 required_args [optional_args] OR
$0 misc_args
Create a new virtual machine from a specified yaml config
misc_args:
--bootstrap-env ENV_PATH create template env file and exit
required_args:
-n, --name NAME name of a virtual machine
-o, --os-variant OS_VARIANT operating system
-m, --memory MEMORY RAM size
-c, --vcpus VCPUS Amount of of cores
-i, --image IMAGE URL or path to an ISO image
-s, --size SIZE Size of an OS drive (example: 8G)
-b, --bridge BRIDGE bridge name (LinuxBridge only)
-a, --ip-address IP ip address of eth0
-p, --prefix PREFIX network prefix
-g, --gateway GATEWAY ip address of network gateway
-d, --dns DNS ip address of dns server
-N, --nfs NFS_IP:NFS_DIR ip address and dir of NFS share
default: 172.17.5.99:/var/nfs/general
-A, --nfs-args NFS_ARGS mount arguments of nfs
default: auto,nofail,noatime,nolock,intr,tcp,actimeo=1800
-t, --test-suite TEST_UTIL what should be used for the test
(bonnie++ and iozone are available)
default: bonnie++
-T, --testargs TEST_UTIL_ARGS arguments that shoud be passed to
testing program
(-d for bonnie++ or -f for iozone
being set automatically)
default: -u 0
optional_args:
-h, --help show this help message and exit
-e, --env export args from env file
-r, --rm-if-exist if vm exist, remove it first
default: false
-P, --pubkey PUBKEY place public key into autorized_keys of
all defined in config.yaml users
default: /home/\$USER/.ssh/id_rsa.pub
-v, --vnc-password VNC_PASSWORD vnc console password
default: PASSWD1!
-C, --cloud-init CLOUD_INIT Path to a cloud-init config - will be
created if not provided
env example:
$(echo -e "$DEFAULT_ENV"|paste /dev/null -|expand -4)
cloud-init example:
$(echo -e "$DEFAULT_USER_INIT"|paste /dev/null -|expand -4)
"
# == Functions ================================================================
function help() {
echo -ne "${HELP/[$'\n']}"
echo
}
function required() {
[[ -n "$1" ]] || {
echo "Incorrect options provided"
help
exit 1
}
}
function bootstrap_env() {
required $1
echo -e "$DEFAULT_ENV" > $1
}
function rm_domain() {
virsh undefine --nvram $2
virsh destroy $2
rm -f $1/backing.img
rm -f $1/cidata.iso
rm -f $1/meta-data
rm -f $1/network-config
rm -f $1/Ubuntu22.04.img
rm -f $1/Ubuntu22.04.qcow2
rm -f $1/user-data
}
function cleanup_known_host() {
ssh-keygen -f "/home/$(id -nu 1000)/.ssh/known_hosts" -R "$1"
ssh-keygen -f "/root/.ssh/known_hosts" -R "$1"
}
# == Args parse ===============================================================
options=$(getopt -n $0 -o n:o:m:c:i:s:b:a:p:g:d:N:A:t:T:he:rP:v:C: \
--long bootstrap-env: \
--long name: \
--long os-variant: \
--long memory: \
--long vcpus: \
--long image: \
--long size: \
--long bridge: \
--long ip-address: \
--long prefix: \
--long gateway: \
--long dns: \
--long nfs: \
--long nfsargs: \
--long test-suite: \
--long test-args: \
--long help \
--long env: \
--long rm-if-exist \
--long pubkey: \
--long vnc-password: \
--long cloud-init: \
-- "$@")
[ $? -eq 0 ] || {
echo "Incorrect options provided"
help
exit 1
}
eval set -- "$options"
while true; do
case $1 in
--bootstrap-env)
shift
bootstrap_env $1
exit 0
;;
-n | --name)
shift
NAME=$1
shift
;;
-o | --os-variant)
shift
OS_VARIANT=$1
shift
;;
-m | --memory)
shift
MEMORY=$1
shift
;;
-c | --vcpus)
shift
VCPUS=$1
shift
;;
-i | --image)
shift
IMAGE=$1
shift
;;
-s | --size)
shift
SIZE=${1:-"8G"}
shift
;;
-b | --bridge)
shift
BRIDGE=$1
shift
;;
-p | --prefix)
shift
PREFIX=$1
shift
;;
-a | --ip-address)
shift
IP=$1
shift
;;
-g | --gateway)
shift
GATEWAY=$1
shift
;;
-d | --dns)
shift
DNS=$1
shift
;;
-N | --nfs)
shift
NFS=(${1//:/ })
NFS_IP=${NFS[0]:-172.17.5.99}
NFS_DIR=${NFS[1]:-/var/nfs/general}
shift
;;
-A | --nfsargs)
shift
NFS_ARGS=$1
shift
;;
-t | --test-suite)
shift
TEST_UTIL=$1
shift
;;
-T | --test-args)
shift
TEST_UTIL_ARGS=${1:-"-u 0"}
shift
;;
-h | --help)
help
exit 0
;;
-e | --env)
shift
ENV=$1
shift
;;
-r | --rm-if-exist)
shift
RM=${1:-false}
shift
;;
-p | --pubkey)
shift
PUBKEY=${1:-"/home/$USER/.ssh/id_rsa.pub"}
shift
;;
-v | --vnc-password)
shift
VNC_PASSWORD=${1:-"PASSWD1!"}
shift
;;
-C | --cloud-init)
shift
CLOUD_INIT=$1
shift
;;
--)
shift
break
esac
done
# Required args
if [[ -z "$ENV" ]]; then
required $NAME
required $OS_VARIANT
required $MEMORY
required $VCPUS
required $IMAGE
required $BRIDGE
required $IP
required $PREFIX
required $GATEWAY
required $DNS
fi
if [[ -n "$ENV" ]]; then
if [[ $ENV != /* ]] || [[ $ENV != ./* ]] || [[ $ENV != ./* ]]; then
ENV="./$ENV"
fi
if [[ -e "$ENV" ]]; then
set -a
source $ENV
set +a
else
echo Env file $ENV does not exist
exit 1
fi
fi
IMAGE_IS_URL=false
if [[ "$IMAGE" == https://* ]] || [[ "$IMAGE" == http://* ]]; then
IMAGE_IS_URL=true
fi
CP_CLOUD_INIT=false
if [[ -n "$CLOUD_INIT" ]] && [[ -e "$CLOUD_INIT" ]]; then
CP_CLOUD_INIT=true
fi
ENV=$(readlink -f "$ENV")
PUBKEY=$(readlink -f "$PUBKEY")
CLOUD_INIT=$(readlink -f "$CLOUD_INIT")
BASE_PATH=$DEFAULT_BASE_PATH/$NAME
# == Dependencies =============================================================
DEBIAN_FRONTEND=noninteractive apt-get install -y genisoimage \
qemu-kvm libvirt-daemon-system virtinst
# == Asserts ==================================================================
printf "virsh "
if ! virsh --version; then
echo "Please install libvirt packages first"
exit 1
fi
printf "virt-install "
if ! virt-install --version; then
echo "Please install virt-install package first"
exit 1
fi
if ! genisoimage --version; then
echo "Please install genisoimage package first"
exit 1
fi
if ! getopt --version; then
echo "Please install getopt package first"
exit 1
fi
if [[ ! -e $PUBKEY ]]; then
ssh-keygen -t rsa -f ${PUBKEY//".pub"/""} -q -P ""
fi
# == Main =====================================================================
# Remove if exist
if [ "$RM" = true ]; then
rm_domain $BASE_PATH $NAME 2>/dev/null
fi
mkdir -p $BASE_PATH
# Preparing user-data
if [[ "$CP_CLOUD_INIT" == true ]]; then
cp -f $CLOUD_INIT $BASE_PATH/user-data
else
# Append -d or -f depend on util
case "$TEST_UTIL" in
bonnie++)
test_util_args_parsed="-d $DEFAULT_NFS_MOUNTPOINT $TEST_UTIL_ARGS"
;;
iozone)
test_util_args_parsed="-f $DEFAULT_NFS_MOUNTPOINT/testfile $TEST_UTIL_ARGS"
;;
esac
user_init=${DEFAULT_USER_INIT//"{{PUBKEY}}"/"$(cat $PUBKEY 2>/dev/null)"}
user_init=${user_init//"{{NFS_IP}}"/"$NFS_IP"}
user_init=${user_init//"{{NFS_DIR}}"/"$NFS_DIR"}
user_init=${user_init//"{{NFS_MOUNTPOINT}}"/"$DEFAULT_NFS_MOUNTPOINT"}
user_init=${user_init//"{{NFS_ARGS}}"/"$NFS_ARGS"}
user_init=${user_init//"{{TEST_UTIL}}"/"$TEST_UTIL"}
user_init=${user_init//"{{TEST_UTIL_ARGS}}"/"$test_util_args_parsed"}
echo -e "$user_init" > $BASE_PATH/user-data
fi
# Preparing meta-data
echo -e "local-hostname: $NAME" > $BASE_PATH/meta-data
# Preparing network-config
netplan=${DEFAULT_NETPLAN//"{{IP}}"/"$IP"}
netplan=${netplan//"{{PREFIX}}"/"$PREFIX"}
netplan=${netplan//"{{GATEWAY}}"/"$GATEWAY"}
netplan=${netplan//"{{DNS}}"/"$DNS"}
echo -e "$netplan" > $BASE_PATH/network-config
# Preparing image
if [ "$IMAGE_IS_URL" == true ]; then
curl -o $BASE_PATH/backing.img -L $IMAGE
fi
qemu-img create -f qcow2 -F qcow2 \
-o backing_file=$BASE_PATH/backing.img \
$BASE_PATH/$NAME.qcow2
qemu-img convert -f qcow2 -O raw $BASE_PATH/$NAME.qcow2 \
$BASE_PATH/$NAME.img
qemu-img resize -f raw $BASE_PATH/$NAME.img $SIZE
# Preparing cidata
genisoimage -output $BASE_PATH/cidata.iso -volid cidata -joliet \
-rock $BASE_PATH/user-data $BASE_PATH/meta-data \
$BASE_PATH/network-config
# virt-install
virt-install --name $NAME \
--os-variant $OS_VARIANT \
--memory $MEMORY \
--vcpus $VCPUS \
--cpu host \
--virt-type kvm \
--disk path=$BASE_PATH/$NAME.img,format=raw,device=disk \
--network bridge:$BRIDGE \
--graphics vnc,listen=0.0.0.0,password=$VNC_PASSWORD \
--import \
--serial file,path=$BASE_PATH/serial.log \
--boot uefi \
--disk $BASE_PATH/cidata.iso,device=cdrom \
--noautoconsole \
--noreboot
# Starting vm
virsh start $NAME
# Cleaning up existing known_hosts
cleanup_known_host $IP 2>/dev/null