Skip to content

Commit

Permalink
Merge pull request #1571 from FIWARE/context/deletionOfCoreContext
Browse files Browse the repository at this point in the history
Fixed a bug about deleting/reloading the core context
  • Loading branch information
kzangeli authored Feb 29, 2024
2 parents 3b58294 + e1704b9 commit c7484b1
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 25 deletions.
9 changes: 8 additions & 1 deletion src/lib/orionld/mhd/mhdConnectionInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,8 +907,15 @@ MHD_Result orionldUriArgumentGet(void* cbDataP, MHD_ValueKind kind, const char*
}
else if (strcmp(key, "reload") == 0)
{
orionldState.uriParams.reload = true;
orionldState.uriParams.mask |= ORIONLD_URIPARAM_RELOAD;

if (strcmp(value, "true") == 0)
orionldState.uriParams.reload = true;
else if (strcmp(value, "false") != 0)
{
orionldError(OrionldBadRequestData, "Invalid value for uri parameter /reload/ (not true nor false)", value, 400);
return MHD_YES;
}
}
else if (strcmp(key, "exist") == 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ orionldStart CB
# 01. Create an entity with a context, only to put the context in the context cache
# 02. DELETE the context from the cache with the URL
# 03. Attempt to GET the context - see 404 Not Found
# 04. Attempt to DELETE the Core Context
# 04. Attempt to DELETE the Core Context without ?reload - see error
# 05. Attempt to DELETE the Core Context, with ?reload=false - see error
# 06. DELETE the Core Context, with ?reload=true - OK
#

echo "01. Create an entity with a context, only to put the context in the context cache"
Expand Down Expand Up @@ -66,13 +68,26 @@ echo
echo


echo "04. Attempt to DELETE the Core Context"
echo "======================================"
echo "04. Attempt to DELETE the Core Context without ?reload - see error"
echo "=================================================================="
orionCurl --url '/ngsi-ld/v1/jsonldContexts/https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.6.jsonld' -X DELETE
echo
echo


echo "05. Attempt to DELETE the Core Context, with ?reload=false - see error"
echo "======================================================================"
orionCurl --url '/ngsi-ld/v1/jsonldContexts/https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.6.jsonld?reload=false' -X DELETE
echo
echo

echo "06. DELETE the Core Context, with ?reload=true - OK"
echo "==================================================="
orionCurl --url '/ngsi-ld/v1/jsonldContexts/https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.6.jsonld?reload=true' -X DELETE
echo
echo


--REGEXPECT--
01. Create an entity with a context, only to put the context in the context cache
=================================================================================
Expand Down Expand Up @@ -104,8 +119,22 @@ Date: REGEX(.*)
}


04. Attempt to DELETE the Core Context
======================================
04. Attempt to DELETE the Core Context without ?reload - see error
==================================================================
HTTP/1.1 400 Bad Request
Content-Length: 208
Content-Type: application/json
Date: REGEX(.*)

{
"detail": "The Core Context can be reloaded, please use the URI param '?reload=true' for that",
"title": "The NGSI-LD Core Context cannot be deleted",
"type": "https://uri.etsi.org/ngsi-ld/errors/BadRequestData"
}


05. Attempt to DELETE the Core Context, with ?reload=false - see error
======================================================================
HTTP/1.1 400 Bad Request
Content-Length: 208
Content-Type: application/json
Expand All @@ -118,6 +147,13 @@ Date: REGEX(.*)
}


06. DELETE the Core Context, with ?reload=true - OK
===================================================
HTTP/1.1 204 No Content
Date: REGEX(.*)



--TEARDOWN--
brokerStop CB
dbDrop CB
2 changes: 1 addition & 1 deletion test/functionalTest/cases/0000_ngsild/ngsild_version.test
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ echo
echo "02. Make sure the branch output from Step 01 is the same as current branch"
echo "=========================================================================="
branchAccordingToBroker=$(echo $_response | awk -F\"branch\" '{ print $2 }' | awk -F\" '{ print $2 }')
branchAccordingToGit=$(git branch | grep ^\* | awk '{ print $2 }')
branchAccordingToGit=$(git branch 2> /dev/null | grep ^\* | awk '{ print $2 }')
if [ "$branchAccordingToBroker" != "$branchAccordingToGit" ]
then
echo "Branch According To Git: $branchAccordingToGit"
Expand Down
42 changes: 24 additions & 18 deletions test/functionalTest/testHarness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,10 @@ function exitFunction()
echo
echo "Error $exitCode: $errorText"
echo
echo "$stderrFile:"
echo "-------------------------------------------------"
echo "stderrFile: $stderrFile:"
echo "================================================="
cat $stderrFile
echo "-------------------------------------------------"
echo "================================================="
echo
echo

Expand Down Expand Up @@ -772,7 +772,7 @@ then
cd $dirOrFile
elif [ ! -d "$dir" ]
then
exitFunction 1 "$dir is not a directory" "HARNESS" "$dir" "" "" DIE
exitFunction 1 "$dir is not a directory" "HARNESS" "$dir" " " " " DIE " "
else
cd $dir
fi
Expand Down Expand Up @@ -887,7 +887,7 @@ function fileCreation()
NAME=$(sed -n '/--NAME--/,/^--/p' $path | grep -v "^--")
if [ "$NAME" == "" ]
then
exitFunction 2 "--NAME-- part is missing" "$path" "($path)" "" "" DIE
exitFunction 2 "--NAME-- part is missing" "$path" "($path)" "diffFile" "stdoutFile" DIE "stderrFile"
exit 2 # Just in case
fi

Expand All @@ -900,7 +900,7 @@ function fileCreation()
logMsg "Creating $TEST_SHELL_INIT at $PWD"
sed -n '/--SHELL-INIT--/,/^--/p' $path | grep -v "^--" > $TEST_SHELL_INIT
else
exitFunction 3 "--SHELL-INIT-- part is missing" $path "($path)" "" "" DIE
exitFunction 3 "--SHELL-INIT-- part is missing" $path "($path)" "diffFile" "stdoutFile" DIE "stderrFile"
fi

#
Expand All @@ -912,7 +912,7 @@ function fileCreation()
logMsg "Creating $TEST_SHELL at $PWD"
sed -n '/--SHELL--/,/^--/p' $path | grep -v "^--" > $TEST_SHELL
else
exitFunction 4 "--SHELL-- part is missing" $path "($path)" "" "" DIE
exitFunction 4 "--SHELL-- part is missing" $path "($path)" "diffFile" "stdoutFile" DIE "stderrFile"
fi

#
Expand All @@ -924,7 +924,7 @@ function fileCreation()
logMsg "Creating $TEST_REGEXPECT at $PWD"
sed -n '/--REGEXPECT--/,/^--/p' $path | grep -v "^--" > $TEST_REGEXPECT
else
exitFunction 5 "--REGEXPECT-- part is missing" $path "($path)" "" "" DIE
exitFunction 5 "--REGEXPECT-- part is missing" $path "($path)" "diffFile" "stdoutFile" DIE "stderrFile"
fi

#
Expand All @@ -936,7 +936,7 @@ function fileCreation()
logMsg "Creating $TEST_TEARDOWN at $PWD"
sed -n '/--TEARDOWN--/,/^--/p' $path | grep -v "^--" > $TEST_TEARDOWN
else
exitFunction 6 "--TEARDOWN-- part is missing" $path "($path)" "" "" DIE
exitFunction 6 "--TEARDOWN-- part is missing" $path "($path)" "diffFile" "stdoutFile" DIE "stderrFile"
fi
}

Expand Down Expand Up @@ -996,18 +996,24 @@ function partExecute()
#
# Check that stderr is empty
#
logMsg "=============================================="
logMsg "wc -l $dirname/$filename.$what.stderr:"
wc -l $dirname/$filename.$what.stderr >> $LOG_FILE
logMsg "=============================================="

linesInStderr=$(wc -l $dirname/$filename.$what.stderr | awk '{ print $1}' 2> /dev/null)
if [ "$linesInStderr" != "" ] && [ "$linesInStderr" != "0" ]
then
if [ $__tryNo == $MAX_TRIES ]
then
exitFunction 7 "$what: output on stderr" $path "($path): $what produced output on stderr" $dirname/$filename.$what.stderr $dirname/$filename.$what.stdout "$forcedDie"
exitFunction 7 "$what: output on stderr" $path "($path): $what produced output on stderr" "no diff" "$dirname/$filename.$what.stdout" "$forcedDie" "$dirname/$filename.$what.stderr"
else
logMsg "$what: output on stderr"
logMsg "------------------------------------------------------"
logMsg "******************************************************"
cat $dirname/$filename.$what.stderr >> $LOG_FILE
logMsg "------------------------------------------------------"
echo -n "(ERROR 7 - $what: output on stderr) "
logMsg "******************************************************"
echo -n "(lines in stderr: $linesInStderr) "
echo "(ERROR 7 - $what: output on stderr) "
fi

partExecuteResult=7
Expand All @@ -1023,7 +1029,7 @@ function partExecute()
logMsg "$what: exit code is $eCode - retry? (try: $__tryNo, MAX_TRIES: $MAX_TRIES)"
if [ $__tryNo == $MAX_TRIES ]
then
exitFunction 8 $path "$what exited with code $eCode" "($path)" $dirname/$filename.$what.stderr $dirname/$filename.$what.stdout "$forcedDie"
exitFunction 8 "$what exited with code $eCode" "$path" "non-zero exit code" "no diff" "$dirname/$filename.$what.stdout" "$forcedDie" "$dirname/$filename.$what.stderr"
else
echo -n "(ERROR 8 - $what: exited with code $eCode) "
fi
Expand Down Expand Up @@ -1075,7 +1081,7 @@ function partExecute()
logMsg "$what $dirname/$filename: eCode=$eCode"
if [ $__tryNo == $MAX_TRIES ]
then
exitFunction 9 "output not as expected" $path "($path) output not as expected" $dirname/$filename.diff $dirname/$filename.out "Survive" "$dirname/$filename.$what.stderr"
exitFunction 9 "output not as expected" $path "($path) output not as expected" "$dirname/$filename.diff" "$dirname/$filename.out" "Survive" "$dirname/$filename.$what.stderr"
else
echo -n "(ERROR 9 - .out and .regexpect differ) "
fi
Expand Down Expand Up @@ -1178,7 +1184,7 @@ function runTest()
linesInStderr=$(wc -l $dirname/$filename.shellInit.stderr | awk '{ print $1}' 2> /dev/null)
if [ "$linesInStderr" != "" ] && [ "$linesInStderr" != "0" ]
then
exitFunction 10 "SHELL-INIT produced output on stderr" $path "($path)" $dirname/$filename.shellInit.stderr $dirname/$filename.shellInit.stdout "Continue"
exitFunction 10 "SHELL-INIT produced output on stderr" $path "stderr not empty" "$dirname/$filename.shellInit.stdout" "Continue" "$dirname/$filename.shellInit.stderr"
runTestStatus="shell-init-error"
return
fi
Expand Down Expand Up @@ -1216,14 +1222,14 @@ function runTest()

if [ "$linesInStderr" != "" ] && [ "$linesInStderr" != "0" ]
then
exitFunction 20 "SHELL-INIT II produced output on stderr" $path "($path)" $dirname/$filename.shellInit.stderr $dirname/$filename.shellInit.stdout "Continue"
exitFunction 20 "SHELL-INIT II produced output on stderr" $path "output on stderr" "$dirname/$filename.shellInit.stdout" "Continue" "$dirname/$filename.shellInit.stderr"
runTestStatus="shell-init-output-on-stderr"
return
fi

if [ "$eCode" != "0" ]
then
exitFunction 11 "SHELL-INIT exited with code $eCode" $path "($path)" $dirname/$filename.shellInit.stderr $dirname/$filename.shellInit.stdout "Continue"
exitFunction 11 "SHELL-INIT exited with code $eCode" $path "output on stderr" "$dirname/$filename.shellInit.stdout" "Continue" "$dirname/$filename.shellInit.stderr"
runTestStatus="shell-init-exited-with-"$eCode
return
fi
Expand Down

0 comments on commit c7484b1

Please sign in to comment.