From 014969f3374a1d4293b0d257b766cbf2a8b54c4b Mon Sep 17 00:00:00 2001 From: Rodric Rabbah <rabbah@us.ibm.com> Date: Wed, 21 Sep 2016 14:02:40 -0400 Subject: [PATCH] Fixes two errors in invoke path: 1. if docker pull fails for black box container, do not attempt to run container 2. if action is a black box, set appropriate bits correctly Added test for running docker action with bogus name. --- .../core/cli/test/WskBasicUsageTests.scala | 19 +++++++++++++++++++ .../dispatcher/test/DispatcherTests.scala | 18 ++++++++++-------- .../whisk/core/entity/test/SchemaTests.scala | 17 +++++++++++++++++ 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/tests/src/whisk/core/cli/test/WskBasicUsageTests.scala b/tests/src/whisk/core/cli/test/WskBasicUsageTests.scala index 6e890305..b0b2e049 100644 --- a/tests/src/whisk/core/cli/test/WskBasicUsageTests.scala +++ b/tests/src/whisk/core/cli/test/WskBasicUsageTests.scala @@ -22,6 +22,7 @@ import java.time.Instant import scala.language.postfixOps import scala.concurrent.duration.Duration import scala.concurrent.duration.DurationInt +import scala.util.Random import org.apache.commons.io.FileUtils import org.junit.runner.RunWith @@ -401,6 +402,24 @@ class WskBasicUsageTests } } + it should "create, and invoke an action that utilizes an invalid docker container with appropriate error" in withAssetCleaner(wskprops) { + val name = "invalid dockerContainer" + val containerName = s"bogus${Random.alphanumeric.take(16).mkString.toLowerCase}" + + (wp, assetHelper) => + assetHelper.withCleaner(wsk.action, name) { + // docker name is a randomly generate string + (action, _) => action.create(name, Some(containerName), kind = Some("docker")) + } + + val run = wsk.action.invoke(name) + withActivation(wsk.activation, run) { + activation => + activation.response.status shouldBe ActivationResponse.messageForCode(ActivationResponse.ApplicationError) + activation.response.result.get.fields("error") shouldBe s"Failed to pull container image '$containerName'.".toJson + } + } + behavior of "Wsk packages" it should "create, and get a package to verify annotation parsing" in withAssetCleaner(wskprops) { diff --git a/tests/src/whisk/core/dispatcher/test/DispatcherTests.scala b/tests/src/whisk/core/dispatcher/test/DispatcherTests.scala index 7c96f3e8..0948d42f 100644 --- a/tests/src/whisk/core/dispatcher/test/DispatcherTests.scala +++ b/tests/src/whisk/core/dispatcher/test/DispatcherTests.scala @@ -33,19 +33,21 @@ import akka.event.Logging.{ InfoLevel, DebugLevel } import common.WskActorSystem import spray.json.JsNumber import spray.json.JsObject +import whisk.common.Logging import whisk.common.TransactionId import whisk.core.connector.{ ActivationMessage => Message } import whisk.core.dispatcher.ActivationFeed -import whisk.core.dispatcher.MessageHandler import whisk.core.dispatcher.Dispatcher +import whisk.core.dispatcher.MessageHandler import whisk.core.entity.ActivationId -import whisk.core.entity.Subject -import whisk.utils.retry +import whisk.core.entity.AuthKey +import whisk.core.entity.DocRevision import whisk.core.entity.EntityName import whisk.core.entity.EntityPath import whisk.core.entity.FullyQualifiedEntityName -import whisk.common.Logging -import whisk.core.entity.AuthKey +import whisk.core.entity.SemVer +import whisk.core.entity.Subject +import whisk.utils.retry @RunWith(classOf[JUnitRunner]) class DispatcherTests extends FlatSpec with Matchers with WskActorSystem { @@ -66,8 +68,8 @@ class DispatcherTests extends FlatSpec with Matchers with WskActorSystem { val content = JsObject("payload" -> JsNumber(count)) val subject = Subject() val authkey = AuthKey() - val path = FullyQualifiedEntityName(EntityPath("test"), EntityName(s"count-$count"), None) - val msg = Message(TransactionId.testing, path, subject, authkey, ActivationId(), EntityPath(subject()), Some(content)) + val path = FullyQualifiedEntityName(EntityPath("test"), EntityName(s"count-$count"), SemVer()) + val msg = Message(TransactionId.testing, path, DocRevision(), subject, authkey, ActivationId(), EntityPath(subject()), Some(content)) connector.send(msg) } @@ -100,7 +102,7 @@ class DispatcherTests extends FlatSpec with Matchers with WskActorSystem { Console.withErr(stream) { retry({ val logs = stream.toString() - logs should include regex (s"exception while pulling new records: commit failed") + logs should include regex (s"exception while pulling new records *.* commit failed") }, 10, Some(100 milliseconds)) connector.throwCommitException = false diff --git a/tests/src/whisk/core/entity/test/SchemaTests.scala b/tests/src/whisk/core/entity/test/SchemaTests.scala index 2a0f2d31..ae655937 100644 --- a/tests/src/whisk/core/entity/test/SchemaTests.scala +++ b/tests/src/whisk/core/entity/test/SchemaTests.scala @@ -45,6 +45,7 @@ import whisk.core.entity.ActivationId import whisk.core.entity.AuthKey import whisk.core.entity.DocId import whisk.core.entity.DocInfo +import whisk.core.entity.DocRevision import whisk.core.entity.EntityName import whisk.core.entity.Exec import whisk.core.entity.LogLimit @@ -89,6 +90,22 @@ class SchemaTests extends FlatSpec with BeforeAndAfter with Matchers { } } + it should "accept any string as doc revision" in { + Seq("a", " a", "a ", "", null).foreach { i => + val d = DocRevision(i) + assert(d.rev == (if (i != null) i.trim else null)) + } + + DocRevision.serdes.read(JsNull) shouldBe DocRevision() + DocRevision.serdes.read(JsString("")) shouldBe DocRevision("") + DocRevision.serdes.read(JsString("a")) shouldBe DocRevision("a") + DocRevision.serdes.read(JsString(" a")) shouldBe DocRevision("a") + DocRevision.serdes.read(JsString("a ")) shouldBe DocRevision("a") + intercept[DeserializationException] { + DocRevision.serdes.read(JsNumber(1)) + } + } + it should "reject malformed doc info" in { Seq(null, "", " ").foreach { i => intercept[IllegalArgumentException] { -- GitLab