Refactor error logging
It is hard to grep errors in current log. so in this patch,
I'm updating die function which also writes log for
screen_log_dir/error.log.
In future, we may categolize negative fault by using
this error.log.
Change-Id: I70a8cfe67ed408284f5c88c762c6bb8acb8ecdb2
diff --git a/exercises/euca.sh b/exercises/euca.sh
index 8b15da8..50d4744 100755
--- a/exercises/euca.sh
+++ b/exercises/euca.sh
@@ -56,68 +56,62 @@
# Find a machine image to boot
IMAGE=`euca-describe-images | grep machine | grep ${DEFAULT_IMAGE_NAME} | cut -f2 | head -n1`
-die_if_not_set IMAGE "Failure getting image $DEFAULT_IMAGE_NAME"
+die_if_not_set $LINENO IMAGE "Failure getting image $DEFAULT_IMAGE_NAME"
# Add a secgroup
if ! euca-describe-groups | grep -q $SECGROUP; then
euca-add-group -d "$SECGROUP description" $SECGROUP
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while ! euca-describe-groups | grep -q $SECGROUP; do sleep 1; done"; then
- echo "Security group not created"
- exit 1
+ die $LINENO "Security group not created"
fi
fi
# Launch it
INSTANCE=`euca-run-instances -g $SECGROUP -t $DEFAULT_INSTANCE_TYPE $IMAGE | grep INSTANCE | cut -f2`
-die_if_not_set INSTANCE "Failure launching instance"
+die_if_not_set $LINENO INSTANCE "Failure launching instance"
# Assure it has booted within a reasonable time
if ! timeout $RUNNING_TIMEOUT sh -c "while ! euca-describe-instances $INSTANCE | grep -q running; do sleep 1; done"; then
- echo "server didn't become active within $RUNNING_TIMEOUT seconds"
- exit 1
+ die $LINENO "server didn't become active within $RUNNING_TIMEOUT seconds"
fi
# Volumes
# -------
if [[ "$ENABLED_SERVICES" =~ "c-vol" ]]; then
VOLUME_ZONE=`euca-describe-availability-zones | head -n1 | cut -f2`
- die_if_not_set VOLUME_ZONE "Failure to find zone for volume"
+ die_if_not_set $LINENO VOLUME_ZONE "Failure to find zone for volume"
VOLUME=`euca-create-volume -s 1 -z $VOLUME_ZONE | cut -f2`
- die_if_not_set VOLUME "Failure to create volume"
+ die_if_not_set $LINENO VOLUME "Failure to create volume"
# Test that volume has been created
VOLUME=`euca-describe-volumes | cut -f2`
- die_if_not_set VOLUME "Failure to get volume"
+ die_if_not_set $LINENO VOLUME "Failure to get volume"
# Test volume has become available
if ! timeout $RUNNING_TIMEOUT sh -c "while ! euca-describe-volumes $VOLUME | grep -q available; do sleep 1; done"; then
- echo "volume didnt become available within $RUNNING_TIMEOUT seconds"
- exit 1
+ die $LINENO "volume didnt become available within $RUNNING_TIMEOUT seconds"
fi
# Attach volume to an instance
euca-attach-volume -i $INSTANCE -d $ATTACH_DEVICE $VOLUME || \
- die "Failure attaching volume $VOLUME to $INSTANCE"
+ die $LINENO "Failure attaching volume $VOLUME to $INSTANCE"
if ! timeout $ACTIVE_TIMEOUT sh -c "while ! euca-describe-volumes $VOLUME | grep -q in-use; do sleep 1; done"; then
- echo "Could not attach $VOLUME to $INSTANCE"
- exit 1
+ die $LINENO "Could not attach $VOLUME to $INSTANCE"
fi
# Detach volume from an instance
euca-detach-volume $VOLUME || \
- die "Failure detaching volume $VOLUME to $INSTANCE"
+ die $LINENO "Failure detaching volume $VOLUME to $INSTANCE"
if ! timeout $ACTIVE_TIMEOUT sh -c "while ! euca-describe-volumes $VOLUME | grep -q available; do sleep 1; done"; then
- echo "Could not detach $VOLUME to $INSTANCE"
- exit 1
+ die $LINENO "Could not detach $VOLUME to $INSTANCE"
fi
# Remove volume
euca-delete-volume $VOLUME || \
- die "Failure to delete volume"
+ die $LINENO "Failure to delete volume"
if ! timeout $ACTIVE_TIMEOUT sh -c "while euca-describe-volumes | grep $VOLUME; do sleep 1; done"; then
- echo "Could not delete $VOLUME"
- exit 1
+ die $LINENO "Could not delete $VOLUME"
fi
else
echo "Volume Tests Skipped"
@@ -125,58 +119,55 @@
# Allocate floating address
FLOATING_IP=`euca-allocate-address | cut -f2`
-die_if_not_set FLOATING_IP "Failure allocating floating IP"
+die_if_not_set $LINENO FLOATING_IP "Failure allocating floating IP"
# Associate floating address
euca-associate-address -i $INSTANCE $FLOATING_IP || \
- die "Failure associating address $FLOATING_IP to $INSTANCE"
+ die $LINENO "Failure associating address $FLOATING_IP to $INSTANCE"
# Authorize pinging
euca-authorize -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
- die "Failure authorizing rule in $SECGROUP"
+ die $LINENO "Failure authorizing rule in $SECGROUP"
# Test we can ping our floating ip within ASSOCIATE_TIMEOUT seconds
ping_check "$PUBLIC_NETWORK_NAME" $FLOATING_IP $ASSOCIATE_TIMEOUT
# Revoke pinging
euca-revoke -P icmp -s 0.0.0.0/0 -t -1:-1 $SECGROUP || \
- die "Failure revoking rule in $SECGROUP"
+ die $LINENO "Failure revoking rule in $SECGROUP"
# Release floating address
euca-disassociate-address $FLOATING_IP || \
- die "Failure disassociating address $FLOATING_IP"
+ die $LINENO "Failure disassociating address $FLOATING_IP"
# Wait just a tick for everything above to complete so release doesn't fail
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep $INSTANCE | grep -q $FLOATING_IP; do sleep 1; done"; then
- echo "Floating ip $FLOATING_IP not disassociated within $ASSOCIATE_TIMEOUT seconds"
- exit 1
+ die $LINENO "Floating ip $FLOATING_IP not disassociated within $ASSOCIATE_TIMEOUT seconds"
fi
# Release floating address
euca-release-address $FLOATING_IP || \
- die "Failure releasing address $FLOATING_IP"
+ die $LINENO "Failure releasing address $FLOATING_IP"
# Wait just a tick for everything above to complete so terminate doesn't fail
if ! timeout $ASSOCIATE_TIMEOUT sh -c "while euca-describe-addresses | grep -q $FLOATING_IP; do sleep 1; done"; then
- echo "Floating ip $FLOATING_IP not released within $ASSOCIATE_TIMEOUT seconds"
- exit 1
+ die $LINENO "Floating ip $FLOATING_IP not released within $ASSOCIATE_TIMEOUT seconds"
fi
# Terminate instance
euca-terminate-instances $INSTANCE || \
- die "Failure terminating instance $INSTANCE"
+ die $LINENO "Failure terminating instance $INSTANCE"
# Assure it has terminated within a reasonable time. The behaviour of this
# case changed with bug/836978. Requesting the status of an invalid instance
# will now return an error message including the instance id, so we need to
# filter that out.
if ! timeout $TERMINATE_TIMEOUT sh -c "while euca-describe-instances $INSTANCE | grep -ve \"\\\(InstanceNotFound\\\|InvalidInstanceID\[.\]NotFound\\\)\" | grep -q $INSTANCE; do sleep 1; done"; then
- echo "server didn't terminate within $TERMINATE_TIMEOUT seconds"
- exit 1
+ die $LINENO "server didn't terminate within $TERMINATE_TIMEOUT seconds"
fi
# Delete secgroup
-euca-delete-group $SECGROUP || die "Failure deleting security group $SECGROUP"
+euca-delete-group $SECGROUP || die $LINENO "Failure deleting security group $SECGROUP"
set +o xtrace
echo "*********************************************************************"