Skip to content

This is to make sure activations for a shared action run in an invocation namespace. #5296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions tests/src/test/scala/common/WskTestHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ object ActivationResponse extends DefaultJsonProtocol {
* @param annotations a list of JSON objects to save the annotations of the activation
*/
case class ActivationResult(activationId: String,
namespace: String,
logs: Option[List[String]],
response: ActivationResponse,
start: Instant,
Expand Down Expand Up @@ -123,14 +124,14 @@ object ActivationResult extends DefaultJsonProtocol {
}

implicit val serdes = new RootJsonFormat[ActivationResult] {
private val format = jsonFormat8(ActivationResult.apply)
private val format = jsonFormat9(ActivationResult.apply)

def write(result: ActivationResult) = format.write(result)

def read(value: JsValue) = {
val obj = value.asJsObject
obj.getFields("activationId", "response", "start") match {
case Seq(JsString(activationId), response, start) =>
obj.getFields("activationId", "namespace", "response", "start") match {
case Seq(JsString(activationId), JsString(namespace), response, start) =>
Try {
val logs = obj.fields.get("logs").map(_.convertTo[List[String]])
val end = obj.fields.get("end").map(_.convertTo[Instant]).getOrElse(Instant.EPOCH)
Expand All @@ -139,6 +140,7 @@ object ActivationResult extends DefaultJsonProtocol {
val annotations = obj.fields.get("annotations").map(_.convertTo[List[JsObject]])
new ActivationResult(
activationId,
namespace,
logs,
response.convertTo[ActivationResponse],
start.convertTo[Instant],
Expand Down
28 changes: 28 additions & 0 deletions tests/src/test/scala/system/basic/WskActivationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,32 @@ class WskActivationTests extends TestHelpers with WskTestHelpers with WskActorSy
resultWithoutSize shouldBe expectedResult
}
}

it should "invoke a shared action under a different invocation namespace" in withAssetCleaner(wskprops) {
(wp, assetHelper) =>
val packageName = "shared-package"
val actionName = "echo"
var invocationNamesapce = if (wskprops.namespace == "_") "guest" else wskprops.namespace
val packageActionName = s"/${invocationNamesapce}/${packageName}/${actionName}"

assetHelper.withCleaner(wsk.pkg, packageName) { (pkg, _) =>
pkg.create(packageName, shared = Some(true))(wp)
}

assetHelper.withCleaner(wsk.action, packageActionName) { (action, _) =>
action.create(packageActionName, Some(TestUtils.getTestActionFilename("echo.js")))(wp)
}

withActivation(wsk.activation, wsk.action.invoke(packageActionName)(wp)) { activation =>
activation.namespace shouldBe invocationNamesapce
}(wp)

val systemId = "whisk.system"
val wskprops2 = WskProps(authKey = WskAdmin.listKeys(systemId)(0)._1, namespace = systemId)
invocationNamesapce = if (wskprops2.namespace == "_") "guest" else wskprops2.namespace

withActivation(wsk.activation, wsk.action.invoke(packageActionName)(wskprops2)) { activation =>
activation.namespace shouldBe invocationNamesapce
}(wskprops2)
}
}