You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by pd...@apache.org on 2019/04/30 21:57:27 UTC
[incubator-openwhisk-wskdeploy] branch master updated: Fixes export
project with feed bug (#1052)
This is an automated email from the ASF dual-hosted git repository.
pdesai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-wskdeploy.git
The following commit(s) were added to refs/heads/master by this push:
new f310a24 Fixes export project with feed bug (#1052)
f310a24 is described below
commit f310a2400875174b3de2d5cbd0b40176def2feb1
Author: Pavel Kravchenko <kp...@il.ibm.com>
AuthorDate: Wed May 1 00:57:22 2019 +0300
Fixes export project with feed bug (#1052)
Added test validating export trigger with feed action
---
cmd/export.go | 23 ++++++---
tests/src/integration/common/wskdeploy.go | 10 ++++
tests/src/integration/export/export_test.go | 62 +++++++++++++++++++++----
tests/src/integration/export/manifest_feed.yaml | 15 ++++++
4 files changed, 94 insertions(+), 16 deletions(-)
diff --git a/cmd/export.go b/cmd/export.go
index 5e5db05..a91d77d 100644
--- a/cmd/export.go
+++ b/cmd/export.go
@@ -216,12 +216,19 @@ func exportProject(projectName string, targetManifest string) error {
// export trigger to manifest
if feedname, isFeed := utils.IsFeedAction(&trg); isFeed {
- // export feed input parameters
- feedAction, _, _ := client.Actions.Get(feedname, true)
- if err != nil {
- return err
+ // check if feed name starts with namespace and workaround it
+ // the current problem is that client has user namespace and when feed specified with different namespace it will fail to invoke the feed action
+ // we need to transform the path from e.g.
+ // /api/v1/namespaces/kpavel@il.ibm.com_uspace/actions//whisk.system/alarms/interval?blocking=true
+ // in to
+ // /api/v1/namespaces/kpavel@il.ibm.com_uspace/actions/../../whisk.system/actions/alarms/interval?blocking=true
+ if strings.HasPrefix(feedname, "/") {
+ // /whisk.system/alarms/interval -> ../../whisk.system/actions/alarms/interval
+ prts := strings.SplitN(feedname, "/", 3)
+ feedname = "../../" + prts[1] + "/actions/" + prts[2]
}
+ // export feed input parameters
params := make(map[string]interface{})
params["authKey"] = client.Config.AuthToken
params["lifecycleEvent"] = "READ"
@@ -231,10 +238,12 @@ func exportProject(projectName string, targetManifest string) error {
return err
}
feedConfig := res["config"]
- for key, val := range feedConfig.(map[string]interface{}) {
- if i := feedAction.Parameters.FindKeyValue(key); i >= 0 {
- trg.Parameters = trg.Parameters.AddOrReplace(&whisk.KeyValue{Key: key, Value: val})
+ if feedConfig != nil {
+ for key, val := range feedConfig.(map[string]interface{}) {
+ if key != "startDate" {
+ trg.Parameters = trg.Parameters.AddOrReplace(&whisk.KeyValue{Key: key, Value: val})
+ }
}
}
}
diff --git a/tests/src/integration/common/wskdeploy.go b/tests/src/integration/common/wskdeploy.go
index 5dddf56..b072a52 100644
--- a/tests/src/integration/common/wskdeploy.go
+++ b/tests/src/integration/common/wskdeploy.go
@@ -177,6 +177,11 @@ func (Wskdeploy *Wskdeploy) ManagedDeploymentManifestAndProject(manifestPath str
return Wskdeploy.RunCommand("sync", "-m", manifestPath, "--projectname", projectName)
}
+func (Wskdeploy *Wskdeploy) ManagedDeploymentManifestAndProjectWithCredentials(manifestPath string, projectName string, wskprops *whisk.Wskprops) (string, error) {
+ return Wskdeploy.RunCommand("sync", "-m", manifestPath, "--projectname", projectName, "--auth", wskprops.AuthKey,
+ "--namespace", wskprops.Namespace, "--apihost", wskprops.APIHost, "--apiversion", wskprops.Apiversion)
+}
+
func (Wskdeploy *Wskdeploy) ManagedDeployment(manifestPath string, deploymentPath string) (string, error) {
return Wskdeploy.RunCommand("sync", "-m", manifestPath, "-d", deploymentPath)
}
@@ -189,6 +194,11 @@ func (wskdeploy *Wskdeploy) ExportProject(projectName string, targetManifestPath
return wskdeploy.RunCommand("export", "-m", targetManifestPath, "--projectname", projectName)
}
+func (wskdeploy *Wskdeploy) ExportProjectWithCredentials(projectName string, targetManifestPath string, wskprops *whisk.Wskprops) (string, error) {
+ return wskdeploy.RunCommand("export", "-m", targetManifestPath, "--projectname", projectName, "--auth", wskprops.AuthKey,
+ "--namespace", wskprops.Namespace, "--apihost", wskprops.APIHost, "--apiversion", wskprops.Apiversion)
+}
+
// This method is only for testing
// This method will mock a construction of deployment plan, creating all the memory objects
// This method CANNOT be used for real deployment!
diff --git a/tests/src/integration/export/export_test.go b/tests/src/integration/export/export_test.go
index 7bc2ccc..650ee81 100644
--- a/tests/src/integration/export/export_test.go
+++ b/tests/src/integration/export/export_test.go
@@ -25,6 +25,7 @@ import (
"os"
"strconv"
"testing"
+ "time"
"github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/common"
"github.com/stretchr/testify/assert"
@@ -44,8 +45,6 @@ func TestExport(t *testing.T) {
wskdeploy := common.NewWskdeploy()
- defer os.RemoveAll(targetManifestFolder)
-
_, err := wskdeploy.ManagedDeploymentOnlyManifest(manifestLib1Path)
assert.Equal(t, nil, err, "Failed to deploy the lib1 manifest file.")
@@ -55,6 +54,8 @@ func TestExport(t *testing.T) {
_, err = wskdeploy.ManagedDeploymentOnlyManifest(manifestExtPath)
assert.Equal(t, nil, err, "Failed to deploy the ext manifest file.")
+ time.Sleep(2 * time.Second) // should it sleep for few seconds before export?!
+
_, err = wskdeploy.ExportProject(projectName, targetManifestPath)
assert.Equal(t, nil, err, "Failed to export project.")
@@ -75,6 +76,7 @@ func TestExport(t *testing.T) {
_, err = wskdeploy.UndeployManifestPathOnly(manifestLib1Path)
assert.Equal(t, nil, err, "Failed to undeploy the lib2.")
+ os.RemoveAll(targetManifestFolder)
}
func SkipTestExportHelloWorld(t *testing.T) {
@@ -83,8 +85,6 @@ func SkipTestExportHelloWorld(t *testing.T) {
targetManifestFolder := os.Getenv("GOPATH") + EXPORT_TEST_PATH + "tmp-" + strconv.Itoa(rand.Intn(1000)) + "/"
targetManifestHelloWorldPath := targetManifestFolder + "manifest-" + projectName + ".yaml"
- defer os.RemoveAll(targetManifestFolder)
-
wskdeploy := common.NewWskdeploy()
_, err := wskdeploy.ManagedDeploymentManifestAndProject(manifestHelloWorldPath, projectName)
@@ -112,6 +112,8 @@ func SkipTestExportHelloWorld(t *testing.T) {
_, err = wskdeploy.UndeployManifestPathOnly(targetManifestHelloWorldPath)
assert.Equal(t, nil, err, "Failed to undeploy exported project")
}
+
+ os.RemoveAll(targetManifestFolder)
}
func TestExport2Pack(t *testing.T) {
@@ -119,14 +121,13 @@ func TestExport2Pack(t *testing.T) {
targetManifestFolder := os.Getenv("GOPATH") + EXPORT_TEST_PATH + "tmp-" + strconv.Itoa(rand.Intn(1000)) + "/"
target2PackManifestPath := targetManifestFolder + "exported2packmanifest.yaml"
- defer os.RemoveAll(targetManifestFolder)
-
projectName := "2pack"
wskdeploy := common.NewWskdeploy()
_, err := wskdeploy.ManagedDeploymentOnlyManifest(manifest2PackPath)
assert.Equal(t, nil, err, "Failed to deploy the 2pack manifest file.")
+ time.Sleep(2 * time.Second) // should it sleep for few seconds before export?!
_, err = wskdeploy.ExportProject(projectName, target2PackManifestPath)
assert.Equal(t, nil, err, "Failed to export project.")
@@ -141,21 +142,22 @@ func TestExport2Pack(t *testing.T) {
_, err = wskdeploy.UndeployManifestPathOnly(manifest2PackPath)
assert.Equal(t, nil, err, "Failed to undeploy")
+
+ os.RemoveAll(targetManifestFolder)
}
func TestExportApi(t *testing.T) {
projectName := "ApiExp"
wskdeploy := common.NewWskdeploy()
- defer os.RemoveAll(targetManifestFolder)
-
_, err := wskdeploy.ManagedDeploymentManifestAndProject(manifestApiExpPath, projectName)
assert.Equal(t, nil, err, "Failed to deploy the ApiExp manifest file.")
+ time.Sleep(2 * time.Second) // should it sleep for few seconds before export?!
_, err = wskdeploy.ExportProject(projectName, targetApiExpManifestPath)
assert.Equal(t, nil, err, "Failed to export project.")
- _, err = os.Stat(manifestApiExpPath)
+ _, err = os.Stat(targetApiExpManifestPath)
assert.Equal(t, nil, err, "Missing exported manifest file")
_, err = os.Stat(targetManifestFolder + "api-gateway-test/greeting.js")
@@ -169,6 +171,45 @@ func TestExportApi(t *testing.T) {
_, err = wskdeploy.UndeployManifestPathOnly(targetApiExpManifestPath)
assert.Equal(t, nil, err, "Failed to undeploy the exported manifest file")
+
+ os.RemoveAll(targetManifestFolder)
+}
+
+func TestExportTriggerFeed(t *testing.T) {
+ projectName := "FeedExp"
+
+ wskprops := common.GetWskpropsFromEnvVars(common.BLUEMIX_APIHOST, common.BLUEMIX_NAMESPACE, common.BLUEMIX_AUTH)
+ err := common.ValidateWskprops(wskprops)
+ if err != nil {
+ fmt.Println(err.Error())
+ fmt.Println("Wsk properties are not properly configured, so tests are skipped.")
+ } else {
+ wskdeploy := common.NewWskdeploy()
+
+ _, err = wskdeploy.ManagedDeploymentManifestAndProjectWithCredentials(manifestFeedExpPath, projectName, wskprops)
+ assert.Equal(t, nil, err, "Failed to deploy the FeedExp manifest file.")
+
+ time.Sleep(2 * time.Second) // should it sleep for few seconds before export?!
+ _, err = wskdeploy.ExportProjectWithCredentials(projectName, targetFeedExpManifestPath, wskprops)
+ assert.Equal(t, nil, err, "Failed to export project with trigger feed.")
+
+ _, err = os.Stat(targetFeedExpManifestPath)
+ assert.Equal(t, nil, err, "Missing exported manifest file")
+
+ _, err = os.Stat(targetManifestFolder + "trigger-feed-test/greeting.js")
+ assert.Equal(t, nil, err, "Missing exported trigger-feed-test/greeting.js")
+
+ _, err = wskdeploy.UndeployWithCredentials(targetFeedExpManifestPath, manifestFeedExpPath, wskprops)
+ assert.Equal(t, nil, err, "Failed to undeploy manifest feed")
+
+ _, err = wskdeploy.ManagedDeploymentManifestAndProjectWithCredentials(manifestFeedExpPath, projectName, wskprops)
+ assert.Equal(t, nil, err, "Failed to redeploy the exported manifest file.")
+
+ _, err = wskdeploy.UndeployWithCredentials(targetFeedExpManifestPath, manifestFeedExpPath, wskprops)
+ assert.Equal(t, nil, err, "Failed to undeploy the exported manifest file")
+ }
+
+ os.RemoveAll(targetManifestFolder)
}
var (
@@ -184,4 +225,7 @@ var (
manifestApiExpPath = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/export/manifest_apiexp.yaml"
targetApiExpManifestPath = targetManifestFolder + "exportedapimanifest.yaml"
+
+ manifestFeedExpPath = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/export/manifest_feed.yaml"
+ targetFeedExpManifestPath = targetManifestFolder + "exportedfeedmanifest.yaml"
)
diff --git a/tests/src/integration/export/manifest_feed.yaml b/tests/src/integration/export/manifest_feed.yaml
new file mode 100644
index 0000000..6519166
--- /dev/null
+++ b/tests/src/integration/export/manifest_feed.yaml
@@ -0,0 +1,15 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more contributor
+# license agreements; and to You under the Apache License, Version 2.0.
+packages:
+ trigger-feed-test:
+ version: 1.0
+ license: Apache-2.0
+ actions:
+ greeting:
+ function: src/greeting.js
+ runtime: nodejs:6
+ triggers:
+ test_alarm_trigger:
+ feed: /whisk.system/alarms/interval
+ inputs:
+ minutes: 1