diff --git a/.travis.yml b/.travis.yml index be400f5..9a1fdfa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ notifications: secure: Yc9ZlTaxhcZT3GWkYyiKpREEORBDLNoTHRqBJNOKvIF1oOCZPH0E9KqaJewwcoSno9G8yhd239kzYtv34moAxYdyKe89SomiH+9wFFpjlS7Ge28+VTWv8yr1EL6pUMW7rJDDODeKxwEHMkdCMARFLrYlQ8xM9quWrc98zqULwusIZpGyVwT3K/4PpWL1OH7D9d0Ain3jods1t7hEzlt8XykLhxpu20bKtxo/0rBJre7f6oCCjEARsHJkvx31VuuZAp5cCLOXPc22Fsd7kqOzzGpsLQICURwUqf7DR8qWyFyXT3QnfJwc2uYXE1yj6SOGxHV1jXOSIymiUFD+8afHlm4SBnqo0UhAIf1z3AJ7r+MSsCTLK7w7kY1WjfOXCK74hiNzS8WmzZJ7C3cVCKYEaxYDDbpUqx9b1+gRaf+acJEuvkMLlkJo5Rze+njdeR9RZbR7i0KR3OCLjXDlu87P2orq6iMNCTDs1FtXlOFeeL42o1YcL1CCKnVXr9feGDSmpZ7Y1ypih+yoeFRYrdG/rPEcgppPXCZBbCWqlzAoRMDrFck+weHTCyMzm16moz2dAxCulm8TrUlb5z4ClbasD6sfdaSFskQtpnW6JtG9gIQt6pfJGkHzMV3Js06sUTNhRWtiLXyUJAftN2xq1skFoMR5beg2a1H9+OKeS03a45E= before_install: - - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then openssl aes-256-cbc -K $encrypted_10110adb91b4_key -iv $encrypted_10110adb91b4_iv -in tests/credentials.json.enc -out tests/credentials.json -d; fi' + - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then openssl aes-256-cbc -K "$encrypted_8D2E480FC532_key" -iv "$encrypted_8D2E480FC532_iv" -in tests/credentials.json.enc -out tests/credentials.json -d; fi' - "./tools/travis/setup.sh" install: true script: diff --git a/tests/build.gradle b/tests/build.gradle index ff6e0fc..537fc62 100644 --- a/tests/build.gradle +++ b/tests/build.gradle @@ -38,3 +38,14 @@ dependencies { tasks.withType(ScalaCompile) { scalaCompileOptions.additionalParameters = gradle.scala.compileFlags } + +task buildArtifacts(type:Exec) { + workingDir 'src/test/resources' + commandLine './build.sh' +} + +tasks.withType(Test) { + dependsOn buildArtifacts +} + +testClasses.dependsOn(buildArtifacts) diff --git a/tests/credentials.json.enc b/tests/credentials.json.enc index 82f3eb9..d0c5ac1 100644 Binary files a/tests/credentials.json.enc and b/tests/credentials.json.enc differ diff --git a/tests/dat/db2/testDB2Service.py b/tests/dat/db2/testDB2Service.py index fe3550b..d168a5b 100644 --- a/tests/dat/db2/testDB2Service.py +++ b/tests/dat/db2/testDB2Service.py @@ -11,8 +11,18 @@ def main(args): print ("Connection failed.") return {"error":"Error connecting to db2"} - # Select from TestTable (the row just inserted) - cmd = "SELECT HISP_DESC FROM SAMPLES.HISPANIC_ORIGIN WHERE HISP_CODE='03'" + # Select from TestTable (the row just inserted). + # + # Due to the db2 lite plan we use, the schema name is fixed to be + # the same as the username. We cut the value of the UID field + # in the ssldsn to get it and insert it in the select statement. + # The ssldsn looks like this: + # ssldsn="DATABASE=BLUDB;HOSTNAME=dashdb-xxxx.services.dal.bluemix.net;PORT=50001;PROTOCOL=TCPIP;UID=yyyyyyy;PWD=;" + # + ssldsndict = dict(x.split("=") for x in ssldsn.rstrip(";").split(";")) + print("user={}".format(ssldsndict["UID"])) + + cmd = "SELECT HISP_DESC FROM {}.HISPANIC_ORIGIN WHERE HISP_CODE='03'".format(ssldsndict["UID"]) result = ibm_db.exec_immediate(conn, cmd) if not result: @@ -27,4 +37,4 @@ def main(args): if __name__ == "__main__": # execute only if run as a script input = {"__bx_creds":{"dashDB":{"ssldsn":""}}} - print(main(input)) \ No newline at end of file + print(main(input)) diff --git a/tests/dat/watson/testWatsonService.py b/tests/dat/watson/testWatsonService.py index 2edb64d..164a07d 100644 --- a/tests/dat/watson/testWatsonService.py +++ b/tests/dat/watson/testWatsonService.py @@ -8,8 +8,8 @@ def main(args): language_translator = LanguageTranslatorV3( version="2018-05-01", url=args.get("url"), - username=args.get("username"), - password=args.get("password")) + username="APIKey", + password=args.get("apikey")) translation = language_translator.translate(text='Hello', model_id='en-es') if LooseVersion(sdk_version) < LooseVersion('2.0.0'): @@ -20,6 +20,5 @@ def main(args): if __name__ == "__main__": # execute only if run as a script input = {"url":"", - "username":"", - "password":""} + "apikey":""} print(main(input)) diff --git a/tests/src/test/resources/build.sh b/tests/src/test/resources/build.sh new file mode 100755 index 0000000..035a9d9 --- /dev/null +++ b/tests/src/test/resources/build.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set -e + +# build the necessary resources for the testcases +# this is not implemented, yet +# it will look like this: +# (cd python-zip && zip ../python.zip -r .) diff --git a/tests/src/test/resources/python2_virtualenv.zip b/tests/src/test/resources/python2_virtualenv.zip new file mode 100644 index 0000000..4808c8a Binary files /dev/null and b/tests/src/test/resources/python2_virtualenv.zip differ diff --git a/tests/src/test/resources/python3_virtualenv.zip b/tests/src/test/resources/python3_virtualenv.zip new file mode 100644 index 0000000..3f40a15 Binary files /dev/null and b/tests/src/test/resources/python3_virtualenv.zip differ diff --git a/tests/src/test/resources/python_virtualenv_dir.zip b/tests/src/test/resources/python_virtualenv_dir.zip new file mode 100644 index 0000000..f308fa1 Binary files /dev/null and b/tests/src/test/resources/python_virtualenv_dir.zip differ diff --git a/tests/src/test/resources/python_virtualenv_name.zip b/tests/src/test/resources/python_virtualenv_name.zip new file mode 100644 index 0000000..4c6c68a Binary files /dev/null and b/tests/src/test/resources/python_virtualenv_name.zip differ diff --git a/tests/src/test/scala/actionContainers/IBMPythonActionContainerTests.scala b/tests/src/test/scala/actionContainers/IBMPythonActionContainerTests.scala index a889202..73d886d 100644 --- a/tests/src/test/scala/actionContainers/IBMPythonActionContainerTests.scala +++ b/tests/src/test/scala/actionContainers/IBMPythonActionContainerTests.scala @@ -16,6 +16,7 @@ package runtime.actionContainers +import java.io.File import org.junit.runner.RunWith import org.scalatest.junit.JUnitRunner import spray.json.DefaultJsonProtocol._ @@ -24,7 +25,6 @@ import common.WskActorSystem import actionContainers.{ActionContainer, BasicActionRunnerTests} import actionContainers.ActionContainer.withContainer import actionContainers.ResourceHelpers.{readAsBase64, ZipBuilder} -import common.TestUtils import java.nio.file.Paths @RunWith(classOf[JUnitRunner]) @@ -105,6 +105,7 @@ class IBMPythonActionContainerTests extends BasicActionRunnerTests with WskActor | "api_key": os.environ['__OW_API_KEY'], | "namespace": os.environ['__OW_NAMESPACE'], | "action_name": os.environ['__OW_ACTION_NAME'], + | "action_version": os.environ['__OW_ACTION_VERSION'], | "activation_id": os.environ['__OW_ACTIVATION_ID'], | "deadline": os.environ['__OW_DEADLINE'] | } @@ -213,9 +214,17 @@ class IBMPythonActionContainerTests extends BasicActionRunnerTests with WskActor }) } + // + // return the full path/filename of a file from the classpath + // + def testArtifact(name: String): String = { + new File(this.getClass.getClassLoader.getResource(name).toURI).toString() + } + it should "report error if zipped Python action containing a virtual environment for wrong python version" in { val zippedPythonAction = "python2_virtualenv.zip" - val zippedPythonActionName = TestUtils.getTestActionFilename(zippedPythonAction) + val zippedPythonActionName = testArtifact(zippedPythonAction) + val code = readAsBase64(Paths.get(zippedPythonActionName)) val (out, err) = withActionContainer() { c => @@ -242,7 +251,7 @@ class IBMPythonActionContainerTests extends BasicActionRunnerTests with WskActor } it should "report error if zipped Python action has wrong main module name" in { - val zippedPythonActionWrongName = TestUtils.getTestActionFilename("python_virtualenv_name.zip") + val zippedPythonActionWrongName = testArtifact("python_virtualenv_name.zip") val code = readAsBase64(Paths.get(zippedPythonActionWrongName)) @@ -260,7 +269,7 @@ class IBMPythonActionContainerTests extends BasicActionRunnerTests with WskActor } it should "report error if zipped Python action has invalid virtualenv directory" in { - val zippedPythonActionWrongDir = TestUtils.getTestActionFilename("python_virtualenv_dir.zip") + val zippedPythonActionWrongDir = testArtifact("python_virtualenv_dir.zip") val code = readAsBase64(Paths.get(zippedPythonActionWrongDir)) val (out, err) = withActionContainer() { c => diff --git a/tests/src/test/scala/integration/CredentialsIBMPythonWatsonTests.scala b/tests/src/test/scala/integration/CredentialsIBMPythonWatsonTests.scala index 98237fd..93aa697 100644 --- a/tests/src/test/scala/integration/CredentialsIBMPythonWatsonTests.scala +++ b/tests/src/test/scala/integration/CredentialsIBMPythonWatsonTests.scala @@ -41,8 +41,7 @@ class CredentialsIBMPythonWatsonTests extends TestHelpers with WskTestHelpers wi JsonParser(ParserInput(vcapString)).asJsObject.fields("language_translator").asInstanceOf[JsArray].elements(0) val creds = vcapInfo.asJsObject.fields("credentials").asJsObject val url = creds.fields("url").asInstanceOf[JsString] - val username = creds.fields("username").asInstanceOf[JsString] - val password = creds.fields("password").asInstanceOf[JsString] + val apikey = creds.fields("apikey").asInstanceOf[JsString] /* Uses Watson Translation Service to translate the word "Hello" in English, to "Hola" in Spanish. @@ -55,7 +54,7 @@ class CredentialsIBMPythonWatsonTests extends TestHelpers with WskTestHelpers wi file, main = Some("main"), kind = defaultKind, - parameters = Map("url" -> url, "username" -> username, "password" -> password)) + parameters = Map("url" -> url, "apikey" -> apikey)) } withActivation(wsk.activation, wsk.action.invoke(actionName)) { activation => diff --git a/tools/travis/build.sh b/tools/travis/build.sh index d8f39d8..666c6fa 100755 --- a/tools/travis/build.sh +++ b/tools/travis/build.sh @@ -25,6 +25,6 @@ docker tag openwhisk/python2action python2action TERM=dumb ./gradlew install -# Build IBM nodejs runtime +# Build IBM Python runtime images cd $ROOTDIR TERM=dumb ./gradlew distDocker -PdockerImagePrefix=${IMAGE_PREFIX} diff --git a/tools/travis/setup.sh b/tools/travis/setup.sh index 3b90022..46a555b 100755 --- a/tools/travis/setup.sh +++ b/tools/travis/setup.sh @@ -7,9 +7,13 @@ SCRIPTDIR=$(cd $(dirname "$0") && pwd) ROOTDIR="$SCRIPTDIR/../.." HOMEDIR="$SCRIPTDIR/../../../" -# OpenWhisk stuff +# clone openWhisk cd $HOMEDIR git clone --depth=1 https://github.com/apache/openwhisk.git openwhisk + +# setup the openwhisk environment cd openwhisk ./tools/travis/setup.sh +# Also build required test artifacts +./gradlew :tests:buildArtifacts