From 742ca2d5209bb38238158889cfa4d2c6633e2d9e Mon Sep 17 00:00:00 2001 From: tpylak <tpylak> Date: Mon, 4 Jul 2011 13:07:26 +0000 Subject: [PATCH] LMS-2335, LMS-2346 bugfixes in InfectX dropboxes + tests SVN: 21963 --- integration-tests/common-screening.bash | 90 ++++++++++++ integration-tests/test-biozentrum.sh | 173 ++++++++++++++++++++++++ 2 files changed, 263 insertions(+) create mode 100644 integration-tests/common-screening.bash create mode 100755 integration-tests/test-biozentrum.sh diff --git a/integration-tests/common-screening.bash b/integration-tests/common-screening.bash new file mode 100644 index 00000000000..d33105fb92c --- /dev/null +++ b/integration-tests/common-screening.bash @@ -0,0 +1,90 @@ +# This code is ment to be common for all screening integration tests, +# but for now only biozentrum integration tests are using it. + +function install_and_run_openbis_server_screening { + local install_openbis=$1 + local local_template_dir=$2 + + local openbis_server_dir=$OPENBIS_SERVER_HCS + local openbis_server_name=`basename $openbis_server_dir` + + restore_database $OPENBIS_DATABASE_HCS $local_template_dir/$openbis_server_name/test_database.sql + if [ $install_openbis == "true" ]; then + rm -fr $openbis_server_dir + + unzip -q -d $openbis_server_dir $INSTALL/openBIS*.zip + mv $openbis_server_dir/openBIS-server/* $openbis_server_dir + rmdir $openbis_server_dir/openBIS-server + + cp -v $local_template_dir/$openbis_server_name/service.properties $openbis_server_dir/service.properties + $openbis_server_dir/install.sh $PWD/$openbis_server_dir + startup_openbis_server $openbis_server_dir + else + restart_openbis $openbis_server_dir + wait_for_server + fi +} + +function install_dss_screening { + local local_template_dir=$1 + + local dss_dest=$DSS_SERVER_HCS + local dss_template=$local_template_dir/$DSS_DIR_NAME + + rm -fr $dss_dest + unzip -q $INSTALL/datastore_server-screening*.zip -d $dss_dest + mv $dss_dest/datastore_server/* $dss_dest + rmdir $dss_dest/datastore_server + + # override default DSS configuration + cp -v $dss_template/etc/* $dss_dest/etc +} + +# installs AS and DSS and starts AS +function install_screening { + local local_template=$1 + + # FIXME uncomment !!!!!!!!!!!!!!!!!!!! + #rm -fr $INSTALL + #fetch_distributions datastore_server + #fetch_distributions screening + + echo Dropping imaging database: $IMAGING_DB + psql_cmd=`run_psql` + $psql_cmd -U postgres -c "drop database if exists $IMAGING_DB" + + rm -fr $WORK + mkdir -p $WORK + install_dss_screening $local_template + install_and_run_openbis_server_screening "true" $local_template +} + +function assertFeatureVectorDef { + local psql=`run_psql` + local result=`$psql -t -U postgres -d $IMAGING_DB \ + -c "select label from feature_defs where code = '$1'" \ + | awk '{gsub(/\|/,";");print}'` + echo "Checking feature $1" + assert_equals "Feature code and label" " $2" "$result" +} + +# returns 0 on success, 1 otherwise +function wait_for_file { + local file_name=$1 + + local timeout=40 + local total_time=0 + local check_interval=5 + echo -n Waiting for creation of $file_name + while [ ! -e $file_name ]; do + echo -n . + sleep $check_interval + total_time=$(( $total_time + $check_interval )) + if [ $total_time -gt $timeout ]; then + report_error "File $file_name has not been detected after $timeout sec [Error]" + return 1 + fi + done + echo " [OK]" + return 0 +} diff --git a/integration-tests/test-biozentrum.sh b/integration-tests/test-biozentrum.sh new file mode 100755 index 00000000000..377d8daa84f --- /dev/null +++ b/integration-tests/test-biozentrum.sh @@ -0,0 +1,173 @@ +#!/bin/sh +# +# The integration test scenario for Biozentrum screening workflow (iBrain2 integration). +# + +# --- include external sources ------------------------ + +source common.bash + +ERR_LOG=$WORK/all_err_log.txt +SVN_WEB_SRC_HCS=http://svncisd.ethz.ch/repos/cisd/screening/trunk + +WORK=$TARGETS/playground-screening-ibrain2 +OPENBIS_DATABASE_HCS=openbis_screening_biozentrum_integration_tests +IMAGING_DB=imaging_biozentrum_integration_tests + +# dir which contains AS and DSS configuration and AS core db dump +LOCAL_TEMPLATE=$TEMPLATE/data-biozentrum +DATA_TEMPLATE=$LOCAL_TEMPLATE/examples/ibrain2-dropboxes-test +OPENBIS_SERVER_HCS=$WORK/openBIS-server +DSS_DIR_NAME=datastore_server + +DSS_SERVER_HCS=$WORK/$DSS_DIR_NAME +DSS_INCOMING_PARENT_DIR=$DSS_SERVER_HCS/data + +source common-screening.bash + +# --- Specific part ----------------- + +TEST_ROOT_DIR=$DSS_INCOMING_PARENT_DIR/dropboxes +INCOMING_ROOT_DIR=$TEST_ROOT_DIR/incoming +CONFIRMATION_DIR=$TEST_ROOT_DIR/registration-status + +function copyDataset { + local dropbox_type=$1 + local name=$2 + + local dropbox=$INCOMING_ROOT_DIR/$dropbox_type + + echo Copy $name to $dropbox as $name + if [ -e $dropbox/$name ]; then + fatal_error Directory already exits in the dropbox! + fi + cp -r $DATA_TEMPLATE/$dropbox_type/$name $dropbox/$name + clean_svn $dropbox/$name +} + +function submitRawDataset { + + local dropbox=$INCOMING_ROOT_DIR/$1 + local name=$2 + + copyDataset $1 $name + touch $dropbox/.MARKER_is_finished_$name +} + +function submitDerivedDataset { + local dropbox=$INCOMING_ROOT_DIR/$1 + local name=$2 + local parent_dataset_code=$3 + + copyDataset $1 $name + + local key_pattern="storage_provider\.parent\.dataset\.id = " + find $dropbox/$name -name "metadata.properties" -exec sed -i "" "s/$key_pattern.*/${key_pattern}${parent_dataset_code}/g" {} \; + + touch $dropbox/.MARKER_is_finished_$name +} + +# returns 0 on success, 1 otherwise +function wait_for_confirmation_file { + local file_name=$1 + + wait_for_file $file_name + local ok=$? + + if [ $ok == 0 ]; then + local succeeded=`cat $file_name | grep STORAGE_SUCCESSFUL` + if [ "$succeeded" == "" ]; then + report_error `cat $file_name` + return 1 + else + return 0 + fi + else + return 1 + fi +} + +function submit_correct_datasets_and_wait { + echo Submit raw images dataset + submitRawDataset HCS_IMAGE_RAW ibrain2_dataset_id_32 + + CONF_FILE=$CONFIRMATION_DIR/ibrain2_dataset_id_32.properties + wait_for_confirmation_file $CONF_FILE + + # update parent dataset code in all files + PARENT_CODE_KEY="storage_provider.dataset.id = " + RAW_IMAGE_DATASET_CODE=`cat $CONF_FILE | grep "$PARENT_CODE_KEY" | tr -d "$PARENT_CODE_KEY"` + echo Update raw image dataset code: $RAW_IMAGE_DATASET_CODE + if [ "$RAW_IMAGE_DATASET_CODE" = "" ]; then + report_error Confirmation with code of raw image dataset has not been found + return + fi + + echo Submit all derived datasets + submitDerivedDataset HCS_IMAGE_OVERVIEW ibrain2_dataset_id_48 $RAW_IMAGE_DATASET_CODE + submitDerivedDataset HCS_IMAGE_SEGMENTATION ibrain2_dataset_id_99 $RAW_IMAGE_DATASET_CODE + submitDerivedDataset HCS_ANALYSIS_WELL_QUALITY_SUMMARY ibrain2_dataset_id_47 $RAW_IMAGE_DATASET_CODE + submitDerivedDataset HCS_ANALYSIS_WELL_RESULTS_SUMMARIES ibrain2_dataset_id_77 $RAW_IMAGE_DATASET_CODE + submitDerivedDataset HCS_ANALYSIS_CELL_FEATURES_CC_MAT ibrain2_dataset_id_58 $RAW_IMAGE_DATASET_CODE + + wait_for_confirmation_file $CONFIRMATION_DIR/ibrain2_dataset_id_48.properties + wait_for_confirmation_file $CONFIRMATION_DIR/ibrain2_dataset_id_99.properties + wait_for_confirmation_file $CONFIRMATION_DIR/ibrain2_dataset_id_47.properties + wait_for_confirmation_file $CONFIRMATION_DIR/ibrain2_dataset_id_77.properties + wait_for_confirmation_file $CONFIRMATION_DIR/ibrain2_dataset_id_58.properties +} + +function getDropboxNamesList { + echo "HCS_IMAGE_RAW HCS_IMAGE_OVERVIEW HCS_IMAGE_SEGMENTATION HCS_ANALYSIS_WELL_QUALITY_SUMMARY HCS_ANALYSIS_WELL_RESULTS_SUMMARIES HCS_ANALYSIS_CELL_FEATURES_CC_MAT" +} + +function createEmptyDropoxes { + rm -fr $TEST_ROOT_DIR + for name in `getDropboxNamesList`; do + mkdir -p $INCOMING_ROOT_DIR/$name + done + cp -r $LOCAL_TEMPLATE/dropboxes/scripts $TEST_ROOT_DIR + mkdir $TEST_ROOT_DIR/registration-status + mkdir $TEST_ROOT_DIR/tmp +} + +function assert_datasets_in_store_number { + local expected_number=$1 + + local datasets=`find $DSS_INCOMING_PARENT_DIR/store -name "original*" | wc -l | tr -d " "`; + assert_equals "Wrong number of registered datasets" $expected_number $datasets +} + +# FIXME: change to False !!!!!!!!!!!!!!!!!!!!!!!!!! +DEBUG=false + +function integration_tests_screening_biozentrum { + if [ "$DEBUG" == "false" ]; then + install_screening $LOCAL_TEMPLATE + fi + createEmptyDropoxes + if [ "$DEBUG" == "false" ]; then + switch_dss "on" $DSS_DIR_NAME + fi + submit_correct_datasets_and_wait + + for name in `getDropboxNamesList`; do + assert_dir_empty $INCOMING_ROOT_DIR/$name + done + + assert_datasets_in_store_number 6 + + # results_summaries dataset + assertFeatureVectorDef INTERPHASEINVASOMEINFECTION_INDEX InterphaseInvasomeInfection_Index + assertFeatureVectorDef COUNT_BACTERIA Count_Bacteria + # quality_summary dataset + assertFeatureVectorDef FOCUS_SCORE Focus_Score + + if [ "$DEBUG" == "false" ]; then + switch_dss "off" $DSS_DIR_NAME + shutdown_openbis_server $OPENBIS_SERVER_HCS + fi + exit_if_assertion_failed +} + +integration_tests_screening_biozentrum \ No newline at end of file -- GitLab