Skip to content
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

Fixes export project with feed bug #1052

Merged
merged 1 commit into from Apr 30, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 16 additions & 7 deletions cmd/export.go
Expand Up @@ -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"
Expand All @@ -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})
}
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions tests/src/integration/common/wskdeploy.go
Expand Up @@ -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)
}
Expand All @@ -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!
Expand Down
62 changes: 53 additions & 9 deletions tests/src/integration/export/export_test.go
Expand Up @@ -25,6 +25,7 @@ import (
"os"
"strconv"
"testing"
"time"

"github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/common"
"github.com/stretchr/testify/assert"
Expand All @@ -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.")

Expand All @@ -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.")

Expand All @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -112,21 +112,22 @@ 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) {
manifest2PackPath := os.Getenv("GOPATH") + EXPORT_TEST_PATH + "manifest_2pack.yaml"
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.")

Expand All @@ -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")
Expand All @@ -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 (
Expand All @@ -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"
)
15 changes: 15 additions & 0 deletions 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