diff --git a/nova/tests/live_migration/hooks/ceph.sh b/nova/tests/live_migration/hooks/ceph.sh new file mode 100755 index 000000000000..2ee752812e33 --- /dev/null +++ b/nova/tests/live_migration/hooks/ceph.sh @@ -0,0 +1,317 @@ +#!/bin/bash + +CEPH_REPLICAS=2 + +function setup_ceph_cluster { + install_ceph_full + configure_ceph_local + + echo "copy ceph.conf and admin keyring to compute only nodes" + ls -la /etc/ceph + sudo cp /etc/ceph/ceph.conf /tmp/ceph.conf + sudo chown ${STACK_USER}:${STACK_USER} /tmp/ceph.conf + $ANSIBLE subnodes --sudo -f 5 -i "$WORKSPACE/inventory" -m copy -a "src=/tmp/ceph.conf dest=/etc/ceph/ceph.conf owner=root group=root" + sudo rm -f /tmp/ceph.conf + sudo cp /etc/ceph/ceph.client.admin.keyring /tmp/ceph.client.admin.keyring + sudo chown ${STACK_USER}:${STACK_USER} /tmp/ceph.client.admin.keyring + sudo chmod 644 /tmp/ceph.client.admin.keyring + ls -la /tmp + $ANSIBLE subnodes --sudo -f 5 -i "$WORKSPACE/inventory" -m copy -a "src=/tmp/ceph.client.admin.keyring dest=/etc/ceph/ceph.client.admin.keyring owner=root group=root" + sudo rm -f /tmp/ceph.client.admin.keyring + echo "check result of copying files" + $ANSIBLE subnodes --sudo -f 5 -i "$WORKSPACE/inventory" -m shell -a "ls -la /etc/ceph" + + + echo "start ceph-mon" + sudo initctl emit ceph-mon id=$(hostname) + echo "start ceph-osd" + sudo start ceph-osd id=${OSD_ID} + echo "check ceph-osd before second node addition" + wait_for_ceph_up + + configure_ceph_remote + + echo "check ceph-osd tree" + wait_for_ceph_up +} + +function install_ceph_full { + if uses_debs; then + $ANSIBLE all --sudo -f 5 -i "$WORKSPACE/inventory" -m apt \ + -a "name=ceph state=present" + elif is_fedora; then + $ANSIBLE all --sudo -f 5 -i "$WORKSPACE/inventory" -m yum \ + -a "name=ceph state=present" + fi +} + +function configure_ceph_local { + sudo mkdir -p ${CEPH_DATA_DIR}/{bootstrap-mds,bootstrap-osd,mds,mon,osd,tmp} + + # create ceph monitor initial key and directory + sudo ceph-authtool /var/lib/ceph/tmp/keyring.mon.$(hostname) \ + --create-keyring --name=mon. --add-key=$(ceph-authtool --gen-print-key) \ + --cap mon 'allow *' + sudo mkdir /var/lib/ceph/mon/ceph-$(hostname) + + # create a default ceph configuration file + sudo tee ${CEPH_CONF_FILE} > /dev/null < /dev/null + sudo chown ${STACK_USER}:$(id -g -n $whoami) ${CEPH_CONF_DIR}/ceph.client.${CINDER_CEPH_USER}.keyring + + #copy cinder keyring to compute only node + sudo cp /etc/ceph/ceph.client.cinder.keyring /tmp/ceph.client.cinder.keyring + sudo chown stack:stack /tmp/ceph.client.cinder.keyring + $ANSIBLE subnodes --sudo -f 5 -i "$WORKSPACE/inventory" -m copy -a "src=/tmp/ceph.client.cinder.keyring dest=/etc/ceph/ceph.client.cinder.keyring" + sudo rm -f /tmp/ceph.client.cinder.keyring + + sudo ceph -c ${CEPH_CONF_FILE} osd pool set ${NOVA_CEPH_POOL} size ${CEPH_REPLICAS} + if [[ $CEPH_REPLICAS -ne 1 ]]; then + sudo ceph -c ${CEPH_CONF_FILE} osd pool set ${NOVA_CEPH_POOL} crush_ruleset ${RULE_ID} + fi +} + +function configure_and_start_nova { + _ceph_configure_nova + #import secret to libvirt + _populate_libvirt_secret + echo 'check compute processes before restart' + $ANSIBLE all --sudo -f 5 -i "$WORKSPACE/inventory" -m shell -a "ps aux | grep compute" + + #stop nova-compute + stop 'all' 'n-cpu' + + echo 'check processes after compute stop' + $ANSIBLE all --sudo -f 5 -i "$WORKSPACE/inventory" -m shell -a "ps aux | grep compute" + + # restart local nova-compute + sudo -H -u $STACK_USER bash -c "/tmp/start_process.sh n-cpu '/usr/local/bin/nova-compute --config-file /etc/nova/nova.conf' libvirtd" + + # restart remote nova-compute + for SUBNODE in $SUBNODES ; do + ssh $SUBNODE "sudo -H -u $STACK_USER bash -c '/tmp/start_process.sh n-cpu \"/usr/local/bin/nova-compute --config-file /etc/nova/nova.conf\" libvirtd'" + done + $ANSIBLE all --sudo -f 5 -i "$WORKSPACE/inventory" -m shell -a "ps aux | grep compute" + +} + +function _ceph_configure_cinder { + sudo ceph -c ${CEPH_CONF_FILE} osd pool create ${CINDER_CEPH_POOL} ${CINDER_CEPH_POOL_PG} ${CINDER_CEPH_POOL_PGP} + sudo ceph -c ${CEPH_CONF_FILE} osd pool set ${CINDER_CEPH_POOL} size ${CEPH_REPLICAS} + if [[ $CEPH_REPLICAS -ne 1 ]]; then + sudo ceph -c ${CEPH_CONF_FILE} osd pool set ${CINDER_CEPH_POOL} crush_ruleset ${RULE_ID} + fi + + CINDER_CONF=${CINDER_CONF:-/etc/cinder/cinder.conf} + $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m ini_file -a "dest=$CINDER_CONF section=ceph option=volume_backend_name value=ceph" + $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m ini_file -a "dest=$CINDER_CONF section=ceph option=volume_driver value=cinder.volume.drivers.rbd.RBDDriver" + $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m ini_file -a "dest=$CINDER_CONF section=ceph option=rbd_ceph_conf value=$CEPH_CONF_FILE" + $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m ini_file -a "dest=$CINDER_CONF section=ceph option=rbd_pool value=$CINDER_CEPH_POOL" + $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m ini_file -a "dest=$CINDER_CONF section=ceph option=rbd_user value=$CINDER_CEPH_USER" + $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m ini_file -a "dest=$CINDER_CONF section=ceph option=rbd_uuid value=$CINDER_CEPH_UUID" + $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m ini_file -a "dest=$CINDER_CONF section=ceph option=rbd_flatten_volume_from_snapshot value=False" + $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m ini_file -a "dest=$CINDER_CONF section=ceph option=rbd_max_clone_depth value=5" + $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m ini_file -a "dest=$CINDER_CONF section=DEFAULT option=glance_api_version value=2" + $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m ini_file -a "dest=$CINDER_CONF section=DEFAULT option=default_volume_type value=ceph" + $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m ini_file -a "dest=$CINDER_CONF section=DEFAULT option=enabled_backends value=ceph" + +} + +function configure_and_start_cinder { + _ceph_configure_cinder + stop 'primary' 'c-vol' + + sudo -H -u $STACK_USER bash -c "/tmp/start_process.sh c-vol '/usr/local/bin/cinder-volume --config-file /etc/cinder/cinder.conf'" + source $BASE/new/devstack/openrc + + export OS_USERNAME=admin + export OS_PROJECT_NAME=admin + lvm_type=$(cinder type-list | awk -F "|" 'NR==4{ print $2}') + cinder type-delete $lvm_type + openstack volume type create --os-volume-api-version 1 --property volume_backend_name="ceph" ceph +} + +function _populate_libvirt_secret { + cat > /tmp/secret.xml < + ${CINDER_CEPH_UUID} + + client.${CINDER_CEPH_USER} secret + + +EOF + + $ANSIBLE subnodes --sudo -f 5 -i "$WORKSPACE/inventory" -m copy -a "src=/tmp/secret.xml dest=/tmp/secret.xml" + $ANSIBLE all --sudo -f 5 -i "$WORKSPACE/inventory" -m shell -a "virsh secret-define --file /tmp/secret.xml" + local secret=$(sudo ceph -c ${CEPH_CONF_FILE} auth get-key client.${CINDER_CEPH_USER}) + # TODO(tdurakov): remove this escaping as https://github.com/ansible/ansible/issues/13862 fixed + secret=${secret//=/'\='} + $ANSIBLE all --sudo -f 5 -i "$WORKSPACE/inventory" -m shell -a "virsh secret-set-value --secret ${CINDER_CEPH_UUID} --base64 $secret" + $ANSIBLE all --sudo -f 5 -i "$WORKSPACE/inventory" -m file -a "path=/tmp/secret.xml state=absent" + +} diff --git a/nova/tests/live_migration/hooks/nfs.sh b/nova/tests/live_migration/hooks/nfs.sh new file mode 100755 index 000000000000..d6f177894a50 --- /dev/null +++ b/nova/tests/live_migration/hooks/nfs.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +function nfs_setup { + if uses_debs; then + module=apt + elif is_fedora; then + module=yum + fi + $ANSIBLE all --sudo -f 5 -i "$WORKSPACE/inventory" -m $module \ + -a "name=nfs-common state=present" + $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m $module \ + -a "name=nfs-kernel-server state=present" + + $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m ini_file -a "dest=/etc/idmapd.conf section=Mapping option=Nobody-User value=nova" + + $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m ini_file -a "dest=/etc/idmapd.conf section=Mapping option=Nobody-Group value=nova" + + for SUBNODE in $SUBNODES ; do + $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m lineinfile -a "dest=/etc/exports line='/opt/stack/data/nova/instances $SUBNODE(rw,fsid=0,insecure,no_subtree_check,async,no_root_squash)'" + done + + $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m shell -a "exportfs -a" + $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m service -a "name=nfs-kernel-server state=restarted" + $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m service -a "name=idmapd state=restarted" + $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m shell -a "iptables -A INPUT -p tcp --dport 111 -j ACCEPT" + $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m shell -a "iptables -A INPUT -p udp --dport 111 -j ACCEPT" + $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m shell -a "iptables -A INPUT -p tcp --dport 2049 -j ACCEPT" + $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m shell -a "iptables -A INPUT -p udp --dport 2049 -j ACCEPT" + $ANSIBLE subnodes --sudo -f 5 -i "$WORKSPACE/inventory" -m shell -a "mount -t nfs4 -o proto\=tcp,port\=2049 $primary_node:/ /opt/stack/data/nova/instances/" +} + +function nfs_configure_tempest { + $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m ini_file -a "dest=$BASE/new/tempest/etc/tempest.conf section=compute-feature-enabled option=block_migration_for_live_migration value=False" +} + +function nfs_verify_setup { + $ANSIBLE subnodes --sudo -f 5 -i "$WORKSPACE/inventory" -m file -a "path=/opt/stack/data/nova/instances/test_file state=touch" + if [ ! -e '/opt/stack/data/nova/instances/test_file' ]; then + die $LINENO "NFS configuration failure" + fi +} + +function nfs_teardown { + #teardown nfs shared storage + $ANSIBLE subnodes --sudo -f 5 -i "$WORKSPACE/inventory" -m shell -a "umount -t nfs4 /opt/stack/data/nova/instances/" + $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m service -a "name=nfs-kernel-server state=stopped" +} \ No newline at end of file diff --git a/nova/tests/live_migration/hooks/run_tests.sh b/nova/tests/live_migration/hooks/run_tests.sh index f8da55944445..e5918ca67401 100755 --- a/nova/tests/live_migration/hooks/run_tests.sh +++ b/nova/tests/live_migration/hooks/run_tests.sh @@ -3,60 +3,53 @@ # environments based on underlying storage, used for ephemerals. # This hook allows to inject logic of environment reconfiguration in ci job. # Base scenario for this would be: -# - run live-migration on env without shared storage -# - set up ceph for ephemerals, and reconfigure nova, tempest for that -# - run live-migration tests -# - remove ceph and set up nfs for ephemerals, make appropriate change in nova -# and tempest config -# - run live-migration tests +# +# 1. test with all local storage (use default for volumes) +# 2. test with NFS for root + ephemeral disks +# 3. test with Ceph for root + ephemeral disks +# 4. test with Ceph for volumes and root + ephemeral disk -set -x +set -xe cd $BASE/new/tempest -sudo -H -u tempest tox -eall -- --concurrency=$TEMPEST_CONCURRENCY live_migration -#nfs preparation -echo "subnode info:" -cat /etc/nodepool/sub_nodes_private -echo "inventory:" -cat $WORKSPACE/inventory -echo "process info:" -ps aux | grep nova-compute +source $BASE/new/devstack/functions +source $BASE/new/devstack/functions-common source $WORKSPACE/devstack-gate/functions.sh - -if uses_debs; then - $ANSIBLE all --sudo -f 5 -i "$WORKSPACE/inventory" -m apt \ - -a "name=nfs-common state=present" - $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m apt \ - -a "name=nfs-kernel-server state=present" -elif is_fedora; then - $ANSIBLE all --sudo -f 5 -i "$WORKSPACE/inventory" -m yum \ - -a "name=nfs-common state=present" - $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m yum \ - -a "name=nfs-kernel-server state=present" -fi - -$ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m ini_file -a "dest=/etc/idmapd.conf section=Mapping option=Nobody-User value=nova" - -$ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m ini_file -a "dest=/etc/idmapd.conf section=Mapping option=Nobody-Group value=nova" - -SUBNODES=$(cat /etc/nodepool/sub_nodes_private) -for SUBNODE in $SUBNODES ; do - $ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m lineinfile -a "dest=/etc/exports line='/opt/stack/data/nova/instances $SUBNODE(rw,fsid=0,insecure,no_subtree_check,async,no_root_squash)'" -done - -$ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m shell -a "exportfs -a" -$ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m service -a "name=nfs-kernel-server state=restarted" -$ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m service -a "name=idmapd state=restarted" -$ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m shell -a "iptables -A INPUT -p tcp --dport 111 -j ACCEPT" -$ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m shell -a "iptables -A INPUT -p udp --dport 111 -j ACCEPT" -$ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m shell -a "iptables -A INPUT -p tcp --dport 2049 -j ACCEPT" -$ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m shell -a "iptables -A INPUT -p udp --dport 2049 -j ACCEPT" +source $BASE/new/nova/nova/tests/live_migration/hooks/utils.sh +source $BASE/new/nova/nova/tests/live_migration/hooks/nfs.sh +source $BASE/new/nova/nova/tests/live_migration/hooks/ceph.sh primary_node=$(cat /etc/nodepool/primary_node_private) -$ANSIBLE subnodes --sudo -f 5 -i "$WORKSPACE/inventory" -m shell -a "mount -t nfs4 -o proto\=tcp,port\=2049 $primary_node:/ /opt/stack/data/nova/instances/" -$ANSIBLE subnodes --sudo -f 5 -i "$WORKSPACE/inventory" -m file -a "path=/opt/stack/data/nova/instances/test_file state=touch" -echo "check whether NFS shared storage works or not:" -ls -la /opt/stack/data/nova/instances -SCREEN_NAME=${SCREEN_NAME:-stack} -$ANSIBLE primary --sudo -f 5 -i "$WORKSPACE/inventory" -m ini_file -a "dest=$BASE/new/tempest/etc/tempest.conf section=compute-feature-enabled option=block_migration_for_live_migration value=False" +SUBNODES=$(cat /etc/nodepool/sub_nodes_private) +SERVICE_HOST=$primary_node +STACK_USER=${STACK_USER:-stack} -sudo -H -u tempest tox -eall -- --concurrency=$TEMPEST_CONCURRENCY live_migration +populate_start_script + +echo '1. test with all local storage (use default for volumes)' + +run_tempest "block migration test" + +echo '2. test with NFS for root + ephemeral disks' + +nfs_setup +nfs_configure_tempest +nfs_verify_setup +run_tempest "NFS shared storage test" +nfs_teardown + +echo '3. test with Ceph for root + ephemeral disks' + +source $BASE/new/devstack/lib/ceph + +#reset output +set -xe + +setup_ceph_cluster +configure_and_start_glance +configure_and_start_nova +run_tempest "Ceph nova&glance test" + +echo '4. test with Ceph for volumes and root + ephemeral disk' + +configure_and_start_cinder +run_tempest "Ceph nova&glance&cinder test" \ No newline at end of file diff --git a/nova/tests/live_migration/hooks/utils.sh b/nova/tests/live_migration/hooks/utils.sh new file mode 100755 index 000000000000..591a1feb1cb3 --- /dev/null +++ b/nova/tests/live_migration/hooks/utils.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +function run_tempest { + local message=$1 + sudo -H -u tempest tox -eall -- --concurrency=$TEMPEST_CONCURRENCY live_migration + exitcode=$? + if [[ $exitcode -ne 0 ]]; then + die $LINENO "$message failure" + fi +} + +function populate_start_script { + SCREEN_NAME=${SCREEN_NAME:-stack} + DEST=${DEST:-/opt/stack} + SERVICE_DIR=${SERVICE_DIR:-${DEST}/status} + ENABLED_SERVICES=${ENABLED_SERVICES:-n-cpu,g-api,c-vol} + LIBVIRT_GROUP=${LIBVIRT_GROUP:-libvirtd} + TIMESTAMP_FORMAT=${TIMESTAMP_FORMAT:-"%F-%H%M%S"} + LOGDAYS=${LOGDAYS:-7} + CURRENT_LOG_TIME=$(date "+$TIMESTAMP_FORMAT") + + #creates script for starting process without screen and copies it to all + # nodes + # + # args: + # $1 - service name to start + # $2 - command to execute + # $3 - group to run under + cat > /tmp/start_process.sh <&"\$REAL_LOG_FILE" 2>&1 + ln -sf "\$REAL_LOG_FILE" \$LOGDIR/\$service.log + export PYTHONUNBUFFERED=1 +fi +if [[ -n "\$sg" ]]; then + setsid sg \$sg -c "\$command" & echo \$! >\$SERVICE_DIR/\$SCREEN_NAME/\$service.pid +else + setsid \$command & echo \$! >\$SERVICE_DIR/\$SCREEN_NAME/\$service.pid +fi +exit 0 +EOF + chmod +x /tmp/start_process.sh + $ANSIBLE subnodes --sudo -f 5 -i "$WORKSPACE/inventory" -m copy -a "src=/tmp/start_process.sh dest=/tmp/start_process.sh owner=$STACK_USER group=$STACK_USER mode=0777" + $ANSIBLE subnodes --sudo -f 5 -i "$WORKSPACE/inventory" -m shell -a "ls -la /tmp/start_process.sh" +} + +function stop { + local target=$1 + local service=$2 + $ANSIBLE $target --sudo -f 5 -i "$WORKSPACE/inventory" -m shell -a " +executable=/bin/bash +BASE\=$BASE +source $BASE/new/devstack/functions-common +ENABLED_SERVICES\=$ENABLED_SERVICES +SCREEN_NAME\=$SCREEN_NAME +SERVICE_DIR\=$SERVICE_DIR +stop_process $service +" +}