Merge "Use job API to check job status in smoke test"
This commit is contained in:
commit
35983b6d83
|
@ -102,51 +102,22 @@ source $DEVSTACK_DIR/functions-common
|
|||
source $DEVSTACK_DIR/lib/database
|
||||
initialize_database_backends
|
||||
|
||||
if [ "$DATABASE_TYPE" == "mysql" ]; then
|
||||
token=$(openstack token issue -c id -f value)
|
||||
for i in $(seq 1 11); do
|
||||
if [ $i == 11 ]; then
|
||||
# we check fail job at the end to give fail job a chance to redo
|
||||
fail_result=$(mysql -u$DATABASE_USER -p$DATABASE_PASSWORD -h$DATABASE_HOST -Dtricircle -e 'SELECT COUNT(*) FROM async_jobs WHERE status = "0_Fail"')
|
||||
fail_count=$(echo $fail_result | grep -o "[0-9]\{1,\}")
|
||||
if [ $fail_count -ne 0 ]; then
|
||||
echo "Listing fail job"
|
||||
mysql -u$DATABASE_USER -p$DATABASE_PASSWORD -h$DATABASE_HOST -Dtricircle -e 'SELECT * FROM async_jobs WHERE status = "0_Fail";'
|
||||
die $LINENO "Smoke test fails, $fail_count job fail"
|
||||
fi
|
||||
echo "List fail jobs"
|
||||
curl -X GET http://127.0.0.1:19999/v1.0/jobs?status=fail -H "Content-Type: application/json" -H "X-Auth-Token: $token"
|
||||
die $LINENO "Smoke test fails, exceed max wait time for job"
|
||||
fi
|
||||
full_result=$(mysql -u$DATABASE_USER -p$DATABASE_PASSWORD -h$DATABASE_HOST -Dtricircle -e 'SELECT COUNT(*) FROM async_jobs;')
|
||||
full_count=$(echo $full_result | grep -o "[0-9]\{1,\}")
|
||||
if [ $full_count -ne 0 ]; then
|
||||
full_result=$(curl -X GET http://127.0.0.1:19999/v1.0/jobs -H "Content-Type: application/json" -H "X-Auth-Token: $token")
|
||||
echo $full_result | python smoke_test_validation.py job 0
|
||||
if [ $? != 0 ]; then
|
||||
echo "Wait for job to finish"
|
||||
sleep 10
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
else
|
||||
for i in $(seq 1 11); do
|
||||
if [ $i == 11 ]; then
|
||||
# we check fail job at the end to give fail job a chance to redo
|
||||
fail_result=$(psql -h$DATABASE_HOST -U$DATABASE_USER -dtricircle -c 'SELECT COUNT(*) FROM async_jobs WHERE status = "0_Fail"')
|
||||
fail_count=$(echo $fail_result | grep -o "[0-9]\{1,\}")
|
||||
if [ $fail_count -ne 0 ]; then
|
||||
echo "Listing fail job"
|
||||
psql -h$DATABASE_HOST -U$DATABASE_USER -dtricircle -c 'SELECT * FROM async_jobs WHERE status = "0_Fail";'
|
||||
die $LINENO "Smoke test fails, $fail_count job fail"
|
||||
fi
|
||||
die $LINENO "Smoke test fails, exceed max wait time for job"
|
||||
fi
|
||||
full_result=$(psql -h$DATABASE_HOST -U$DATABASE_USER -dtricircle -c 'SELECT COUNT(*) FROM async_jobs;')
|
||||
full_count=$(echo $full_result | grep -o "[0-9]\{1,\}")
|
||||
if [ $full_count -ne 0 ]; then
|
||||
echo "Wait for job to finish"
|
||||
sleep 10
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
$openstackpod1 server list -f json | python smoke_test_validation.py server 1
|
||||
if [ $? != 0 ]; then
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# Copyright 2017 Huawei Technologies Co., Ltd.
|
||||
# All Rights Reserved
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
|
@ -29,7 +28,11 @@ class ContainedString(object):
|
|||
return other.find(self.content) == -1
|
||||
|
||||
|
||||
CONDITIONS = {
|
||||
ALL_CONDITIONS = {
|
||||
'0': {'job': [{'status': 'SUCCESS'}]}
|
||||
}
|
||||
|
||||
ANY_CONDITIONS = {
|
||||
'1': {'server': [{'Name': 'vm1', 'Status': 'ACTIVE'},
|
||||
{'Name': 'vm3', 'Status': 'ACTIVE'}],
|
||||
'subnet': [{'Subnet': '100.0.0.0/24'}, {'Subnet': '10.0.1.0/24'},
|
||||
|
@ -54,18 +57,43 @@ CONDITIONS = {
|
|||
}
|
||||
|
||||
|
||||
def validate_condition(result, condition):
|
||||
if not isinstance(result, list):
|
||||
result = [result]
|
||||
for res in result:
|
||||
def get_result_list(result):
|
||||
if isinstance(result, list):
|
||||
return result
|
||||
# not list, so result should be a dict
|
||||
if len(result) != 1:
|
||||
# dict for single resource
|
||||
return [result]
|
||||
value = list(result.values())[0]
|
||||
if isinstance(value, list):
|
||||
# dict for resource list
|
||||
return value
|
||||
else:
|
||||
return [result]
|
||||
|
||||
|
||||
def validate_any_condition(result, condition):
|
||||
for res in get_result_list(result):
|
||||
if all(res[key] == value for (key, value) in condition.items()):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def validate_all_condition(result, condition):
|
||||
for res in get_result_list(result):
|
||||
if not all(res[key] == value for (key, value) in condition.items()):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def validate_result(result, region, res_type):
|
||||
for condition in CONDITIONS[region][res_type]:
|
||||
if not validate_condition(result, condition):
|
||||
if res_type in ANY_CONDITIONS.get(region, {}):
|
||||
for condition in ANY_CONDITIONS[region][res_type]:
|
||||
if not validate_any_condition(result, condition):
|
||||
return False
|
||||
if res_type in ALL_CONDITIONS.get(region, {}):
|
||||
for condition in ALL_CONDITIONS[region][res_type]:
|
||||
if not validate_all_condition(result, condition):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
Loading…
Reference in New Issue