Skip to content

Commit 6bd29c2

Browse files
author
jianghuaw
authored
Merge pull request #164 from citrix-openstack/add_node_script
Add node script
2 parents be2c625 + 7a73c19 commit 6bd29c2

File tree

1 file changed

+224
-0
lines changed

1 file changed

+224
-0
lines changed

test_vgpu.sh

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
#!/bin/bash
2+
3+
# This script is used to install an openstack environment to check vgpu
4+
# features. It should be called on a compute node which located on a xenserver
5+
# host with GPU cards.
6+
#
7+
# Example:
8+
# $0 $zuul_ref $zuul_changes $keep_env_flag
9+
#
10+
# zuul_ref: the commit ref from ZUUL
11+
# zuul_changes: related branch changes
12+
# keep_env_flag: if this flag set to "true", will don't clean the environment
13+
# after test finished.
14+
15+
set -ex
16+
refspec="$1"
17+
ZUUL_CHANGES="$2"
18+
keep_env=${3:-false}
19+
20+
if [ -z "$ZUUL_CHANGES" -o -z "$refspec" -o -z "$ZUUL_CHANGE" ]; then
21+
echo "ZUUL parameters needed"
22+
exit 1
23+
fi
24+
25+
FETCH_URL=${FETCH_URL:-"http://10.71.212.50/p/"}
26+
ROOT_DIR=/opt/stack/
27+
DEVSTACK_PATH=/opt/stack/devstack
28+
TEMPEST_DIR=/opt/stack/tempest
29+
TEST_BRANCH=$ZUUL_CHANGE
30+
DEST=${DEST:-"/opt/stack/openstack"}
31+
NOVA_CONF=/etc/nova/nova.conf
32+
IMAGE_NAME=${IMAGE_NAME:-"cirros-0.3.5-x86_64-disk"}
33+
VM_NAME=${VM_NAME:-"testVM"}
34+
JOURNAL_DIR=/var/log/journal
35+
VGPU_TEST_LOG_DIR=${VGPU_TEST_LOG_DIR:-"/opt/stack/workspace/test_vgpu/logs"}
36+
TMP_LOG_DIR=/tmp/openstack
37+
38+
39+
SLEEP_TIME_GAP=3
40+
SLEEP_MAX_TRIES=40
41+
42+
43+
echo "###################Test VGPU Begin#####################"
44+
45+
on_exit()
46+
{
47+
# Post proccess
48+
# Save logs
49+
set -x
50+
echo "###################Exit#####################"
51+
echo "###################Save logs#####################"
52+
rm -rf $TMP_LOG_DIR
53+
mkdir -p $TMP_LOG_DIR
54+
services=$(ls /etc/systemd/system | grep devstack@)
55+
for service in $services;
56+
do
57+
sudo journalctl --unit $service > $TMP_LOG_DIR/$service".log";
58+
done
59+
cp $TMP_LOG_DIR/* $VGPU_TEST_LOG_DIR/
60+
echo "###################Clean environment if requested#####################"
61+
if [ $keep_env != "true" ]; then
62+
pushd $DEVSTACK_PATH/
63+
nova delete $VM_NAME
64+
./clean.sh
65+
popd
66+
fi
67+
set +x
68+
}
69+
70+
trap on_exit EXIT
71+
72+
error_log="VGPU test failed with the following errors: "
73+
# Set up internal variables
74+
_SSH_OPTIONS="\
75+
-o BatchMode=yes \
76+
-o StrictHostKeyChecking=no \
77+
-o UserKnownHostsFile=/dev/null \
78+
-i /opt/stack/.ssh/id_rsa"
79+
80+
DOM0_IP=$(grep XENAPI_CONNECTION_URL ${DEVSTACK_PATH}/local.conf | cut -d'=' -f2 | sed 's/[^0-9,.]*//g')
81+
82+
echo "Dom0 IP is: $DOM0_IP"
83+
84+
function on_domzero() {
85+
ssh $_SSH_OPTIONS "root@$DOM0_IP" bash -s --
86+
}
87+
88+
pushd $DEVSTACK_PATH/
89+
90+
./clean.sh
91+
git checkout master
92+
git pull --ff origin master
93+
94+
popd
95+
96+
if grep "DEST=" ${DEVSTACK_PATH}/local.conf; then
97+
dest=$(grep "DEST=" ${DEVSTACK_PATH}/local.conf | cut -d= -f2)
98+
if [ $dest != ${DEVSTACK_PATH} ]; then
99+
sed -i '/DEST=*/d' ${DEVSTACK_PATH}/local.conf
100+
fi
101+
fi
102+
if ! grep "DEST=" ${DEVSTACK_PATH}/local.conf; then
103+
sed -i '/[[local|localrc]]/a DEST=/opt/stack/openstack' ${DEVSTACK_PATH}/local.conf
104+
fi
105+
106+
echo "###################Update openstack repositories#####################"
107+
PROJECT_LIST=$(echo $ZUUL_CHANGES | tr '^' '\n' | cut -d: -f1 | cut -d/ -f2 | sort | uniq)
108+
109+
pushd ${DEST}
110+
for dir in ${DEST}/*
111+
do
112+
if [ -d "${dir}" ] ; then
113+
echo "check ${dir}"
114+
pushd ${dir}
115+
if [ -d .git ]; then
116+
echo "update repository ${dir}"
117+
git checkout master
118+
if ! git diff-index --quiet HEAD --; then
119+
git checkout *
120+
fi
121+
git pull --ff origin master
122+
123+
pkg_flag=${dir##*/}
124+
echo $pkg_flag
125+
if [[ " ${PROJECT_LIST[@]} " =~ " ${pkg_flag} " ]]; then
126+
echo "Fetching change for repository ${dir}"
127+
if git branch | grep -w $TEST_BRANCH; then
128+
echo "delete the old temp branch"
129+
git branch -D $TEST_BRANCH
130+
fi
131+
git checkout master -B $TEST_BRANCH
132+
git fetch ${FETCH_URL}/openstack/${pkg_flag} $refspec
133+
git merge FETCH_HEAD -m "temp branch for vgpu patches merge"
134+
fi
135+
fi;
136+
popd
137+
fi
138+
done
139+
140+
popd
141+
142+
echo "###################Get VGPU type from the host#####################"
143+
first_vgpu_type=$(on_domzero << END_OF_REQ_VGPU_TYPE
144+
vgpu_type_list=\$(xe vgpu-type-list --minimal)
145+
vgpu_type_list=\${vgpu_type_list//,/ }
146+
for id in \$vgpu_type_list
147+
do
148+
name=\$(xe vgpu-type-param-get uuid=\$id param-name="model-name")
149+
if [ "\$name" != "passthrough" ]
150+
then
151+
echo \$name
152+
exit
153+
fi
154+
done
155+
END_OF_REQ_VGPU_TYPE
156+
)
157+
158+
echo "###################Devstack start stack#####################"
159+
pushd $DEVSTACK_PATH/
160+
if ! grep "enabled_vgpu_types=" ${DEVSTACK_PATH}/local.conf; then
161+
echo "[devices]" >> ${DEVSTACK_PATH}/local.conf
162+
echo "enabled_vgpu_types = $first_vgpu_type" >> ${DEVSTACK_PATH}/local.conf
163+
fi
164+
sudo find $JOURNAL_DIR -name "*.journal" -exec rm {} \;
165+
sudo systemctl restart systemd-journald
166+
./stack.sh
167+
popd
168+
169+
pushd $TEMPEST_DIR
170+
# TODO: run vgpu tempest
171+
172+
echo "###################Create test VM#####################"
173+
source $DEVSTACK_PATH/openrc admin demo
174+
# Add vgpu resource to falvor 1
175+
nova flavor-key 1 set resources:VGPU=1
176+
177+
# Change image type to hvm because vgpu only support hvm image
178+
image_id=$(glance image-list | grep "$IMAGE_NAME" | awk '{print $2}')
179+
glance image-update --property vm_mode=hvm $image_id
180+
181+
prv_net=$(openstack network list | grep "private" | awk '{print $2}')
182+
nova boot --image $IMAGE_NAME --flavor 1 --nic net-id=$prv_net $VM_NAME
183+
184+
nova_vm_id=$(nova show $VM_NAME | grep -w 'id' | awk '{print $4}')
185+
count=0
186+
while :
187+
do
188+
echo "Waitting to VM active"
189+
sleep $SLEEP_TIME_GAP
190+
count=$((count + 1))
191+
vm_state=$(nova show $VM_NAME | grep -w 'status' | awk '{print $4}')
192+
if [ $vm_state = "ERROR" ]; then
193+
error_log=$error_log"\n\tVM create failed"
194+
break
195+
elif [ $vm_state = "ACTIVE" ]; then
196+
break
197+
elif [ $count -gt $SLEEP_MAX_TRIES ]; then
198+
error_log=$error_log"\n\tVM can not reach active status"
199+
break
200+
fi
201+
done
202+
203+
echo "###################Check VGPU create status#####################"
204+
if [ $vm_state = "ACTIVE" ]; then
205+
result=$(on_domzero <<END_OF_VGPU_CONFIRM
206+
vgpu_list=\$(xe vgpu-list --minimal)
207+
vgpu_list=\${vgpu_list//,/ }
208+
for vgpu_id in \$vgpu_list
209+
do
210+
ret=\$(xe vgpu-param-list uuid=\$vgpu_id | grep $nova_vm_id)
211+
echo \$ret
212+
done
213+
END_OF_VGPU_CONFIRM
214+
)
215+
fi
216+
217+
if [ -n "$result" ]; then
218+
echo "VGPU create success"
219+
else
220+
error_log=$error_log"\n\tVGPU create failed"
221+
echo $error_log
222+
fi
223+
224+
set +ex

0 commit comments

Comments
 (0)