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

devfile push Integration test on kubernetes cluster #3041

3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ jobs:
# Run devfile integration test on Kubernetes cluster
- <<: *base-test
stage: test
name: "devfile catalog and watch command integration tests on kubernetes cluster"
name: "devfile catalog, watch and push command integration tests on kubernetes cluster"
before_script:
# Download kubectl, a cli tool for accessing Kubernetes cluster
- curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.16.0/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
Expand All @@ -192,3 +192,4 @@ jobs:
- export KUBERNETES=true
- travis_wait make test-cmd-devfile-catalog
- travis_wait make test-cmd-devfile-watch
- travis_wait make test-cmd-devfile-push
2 changes: 2 additions & 0 deletions tests/helper/helper_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ type CliRunner interface {
GetVolumeMountNamesandPathsFromContainer(deployName string, containerName, namespace string) string
WaitAndCheckForExistence(resourceType, namespace string, timeoutMinutes int) bool
GetServices(namespace string) string
CreateRandNamespaceProject() string
DeleteNamespaceProject(projectName string)
}
19 changes: 19 additions & 0 deletions tests/helper/helper_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"math/rand"
"os"
"os/exec"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -167,3 +168,21 @@ func GetUserHomeDir() string {
Expect(err).NotTo(HaveOccurred())
return homeDir
}

// LocalKubeconfigSet sets the KUBECONFIG to the temporary config file
func LocalKubeconfigSet(context string) {
originalKubeCfg := os.Getenv("KUBECONFIG")
if originalKubeCfg == "" {
homeDir := GetUserHomeDir()
originalKubeCfg = filepath.Join(homeDir, ".kube", "config")
}
copyKubeConfigFile(originalKubeCfg, filepath.Join(context, "config"))
}

// GetCliRunner gets the running cli against Kubernetes or OpenShift
func GetCliRunner() CliRunner {
if os.Getenv("KUBERNETES") == "true" {
return NewKubectlRunner("kubectl")
}
return NewOcRunner("oc")
}
17 changes: 17 additions & 0 deletions tests/helper/helper_kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,20 @@ func (kubectl KubectlRunner) GetServices(namespace string) string {
output := string(session.Wait().Out.Contents())
return output
}

// CreateRandNamespaceProject create new project with random name in kubernetes cluster (10 letters)
func (kubectl KubectlRunner) CreateRandNamespaceProject() string {
projectName := RandString(10)
fmt.Fprintf(GinkgoWriter, "Creating a new project: %s\n", projectName)
CmdShouldPass("kubectl", "create", "namespace", projectName)
CmdShouldPass("kubectl", "config", "set-context", "--current", "--namespace", projectName)
session := CmdShouldPass("kubectl", "get", "namespaces")
Expect(session).To(ContainSubstring(projectName))
return projectName
}

// DeleteNamespaceProject deletes a specified project in kubernetes cluster
func (kubectl KubectlRunner) DeleteNamespaceProject(projectName string) {
fmt.Fprintf(GinkgoWriter, "Deleting project: %s\n", projectName)
CmdShouldPass("kubectl", "delete", "namespaces", projectName)
}
17 changes: 17 additions & 0 deletions tests/helper/helper_oc.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,3 +505,20 @@ func (oc OcRunner) VerifyResourceDeleted(resourceType, resourceName, namespace s
output := string(session.Wait().Out.Contents())
Expect(output).NotTo(ContainSubstring(resourceName))
}

// CreateRandNamespaceProject create new project with random name in oc cluster (10 letters)
func (oc OcRunner) CreateRandNamespaceProject() string {
projectName := RandString(10)
fmt.Fprintf(GinkgoWriter, "Creating a new project: %s\n", projectName)
session := CmdShouldPass("odo", "project", "create", projectName, "-w", "-v4")
Expect(session).To(ContainSubstring("New project created"))
Expect(session).To(ContainSubstring(projectName))
return projectName
}

// DeleteNamespaceProject deletes a specified project in oc cluster
func (oc OcRunner) DeleteNamespaceProject(projectName string) {
fmt.Fprintf(GinkgoWriter, "Deleting project: %s\n", projectName)
session := CmdShouldPass("odo", "project", "delete", projectName, "-f")
Expect(session).To(ContainSubstring("Deleted project : " + projectName))
}
23 changes: 3 additions & 20 deletions tests/helper/kubernetes_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,12 @@ import (
. "github.com/onsi/gomega"
)

// CopyKubeConfigFile copies default kubeconfig file into current context config file
func CopyKubeConfigFile(kubeConfigFile, tempConfigFile string) string {
// copyKubeConfigFile copies default kubeconfig file into current temporary context config file
func copyKubeConfigFile(kubeConfigFile, tempConfigFile string) {
info, err := os.Stat(kubeConfigFile)
Expect(err).NotTo(HaveOccurred())
err = copyFile(kubeConfigFile, tempConfigFile, info)
Expect(err).NotTo(HaveOccurred())
os.Setenv("KUBECONFIG", tempConfigFile)
return tempConfigFile
}

// CreateRandNamespace create new project with random name in kubernetes cluster (10 letters)
func CreateRandNamespace(context string) string {
projectName := RandString(10)
fmt.Fprintf(GinkgoWriter, "Creating a new project: %s\n", projectName)
CmdShouldPass("kubectl", "create", "namespace", projectName)
CmdShouldPass("kubectl", "config", "set-context", context, "--namespace", projectName)
session := CmdShouldPass("kubectl", "get", "namespaces")
Expect(session).To(ContainSubstring(projectName))
return projectName
}

// DeleteNamespace deletes a specified project in kubernetes cluster
func DeleteNamespace(projectName string) {
fmt.Fprintf(GinkgoWriter, "Deleting project: %s\n", projectName)
CmdShouldPass("kubectl", "delete", "namespaces", projectName)
fmt.Fprintf(GinkgoWriter, "Setting KUBECONFIG=%s\n", tempConfigFile)
}
27 changes: 11 additions & 16 deletions tests/integration/devfile/cmd_devfile_catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,31 @@ import (
)

var _ = Describe("odo devfile catalog command tests", func() {
var project string
var context string
var currentWorkingDirectory string
var project, context, currentWorkingDirectory, originalKubeconfig string

// Using program commmand according to cliRunner in devfile
cliRunner := helper.GetCliRunner()

// This is run after every Spec (It)
var _ = BeforeEach(func() {
SetDefaultEventuallyTimeout(10 * time.Minute)
context = helper.CreateNewContext()
os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml"))
helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true")
if os.Getenv("KUBERNETES") == "true" {
homeDir := helper.GetUserHomeDir()
kubeConfigFile := helper.CopyKubeConfigFile(filepath.Join(homeDir, ".kube", "config"), filepath.Join(context, "config"))
project = helper.CreateRandNamespace(kubeConfigFile)
} else {
project = helper.CreateRandProject()
}

originalKubeconfig = os.Getenv("KUBECONFIG")
helper.LocalKubeconfigSet(context)
project = cliRunner.CreateRandNamespaceProject()
currentWorkingDirectory = helper.Getwd()
helper.Chdir(context)
})

// This is run after every Spec (It)
var _ = AfterEach(func() {
if os.Getenv("KUBERNETES") == "true" {
helper.DeleteNamespace(project)
os.Unsetenv("KUBECONFIG")
} else {
helper.DeleteProject(project)
}
cliRunner.DeleteNamespaceProject(project)
helper.Chdir(currentWorkingDirectory)
err := os.Setenv("KUBECONFIG", originalKubeconfig)
Expect(err).NotTo(HaveOccurred())
helper.DeleteDir(context)
os.Unsetenv("GLOBALODOCONFIG")
})
Expand Down
54 changes: 28 additions & 26 deletions tests/integration/devfile/cmd_devfile_push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,36 @@ import (
)

var _ = Describe("odo devfile push command tests", func() {
var namespace, context, cmpName, currentWorkingDirectory string
var namespace, context, cmpName, currentWorkingDirectory, originalKubeconfig string
var sourcePath = "/projects/nodejs-web-app"

// TODO: all oc commands in all devfile related test should get replaced by kubectl
// TODO: to goal is not to use "oc"
oc := helper.NewOcRunner("oc")
// Using program commmand according to cliRunner in devfile
cliRunner := helper.GetCliRunner()

// This is run after every Spec (It)
var _ = BeforeEach(func() {
SetDefaultEventuallyTimeout(10 * time.Minute)
namespace = helper.CreateRandProject()
context = helper.CreateNewContext()
currentWorkingDirectory = helper.Getwd()
cmpName = helper.RandString(6)

helper.Chdir(context)

os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml"))

// Devfile push requires experimental mode to be set
helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true")

originalKubeconfig = os.Getenv("KUBECONFIG")
helper.LocalKubeconfigSet(context)
namespace = cliRunner.CreateRandNamespaceProject()
currentWorkingDirectory = helper.Getwd()
cmpName = helper.RandString(6)
helper.Chdir(context)
})

// Clean up after the test
// This is run after every Spec (It)
var _ = AfterEach(func() {
helper.DeleteProject(namespace)
cliRunner.DeleteNamespaceProject(namespace)
helper.Chdir(currentWorkingDirectory)
err := os.Setenv("KUBECONFIG", originalKubeconfig)
Expect(err).NotTo(HaveOccurred())
helper.DeleteDir(context)
os.Unsetenv("GLOBALODOCONFIG")
})
Expand All @@ -56,14 +58,14 @@ var _ = Describe("odo devfile push command tests", func() {
helper.CopyExampleDevFile(filepath.Join("source", "devfiles", "nodejs", "devfile-no-endpoints.yaml"), filepath.Join(context, "devfile.yaml"))

helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--project", namespace)
output := oc.GetServices(namespace)
output := cliRunner.GetServices(namespace)
Expect(output).NotTo(ContainSubstring(cmpName))

helper.RenameFile("devfile-old.yaml", "devfile.yaml")
output = helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--project", namespace)

Expect(output).To(ContainSubstring("Changes successfully pushed to component"))
output = oc.GetServices(namespace)
output = cliRunner.GetServices(namespace)
Expect(output).To(ContainSubstring(cmpName))
})

Expand Down Expand Up @@ -103,9 +105,9 @@ var _ = Describe("odo devfile push command tests", func() {
utils.ExecPushWithNewFileAndDir(context, cmpName, namespace, newFilePath, newDirPath)

// Check to see if it's been pushed (foobar.txt abd directory testdir)
podName := oc.GetRunningPodNameByComponent(cmpName, namespace)
podName := cliRunner.GetRunningPodNameByComponent(cmpName, namespace)

stdOut := oc.ExecListDir(podName, namespace, sourcePath)
stdOut := cliRunner.ExecListDir(podName, namespace, sourcePath)
helper.MatchAllInOutput(stdOut, []string{"foobar.txt", "testdir"})

// Now we delete the file and dir and push
Expand All @@ -114,7 +116,7 @@ var _ = Describe("odo devfile push command tests", func() {
helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--project", namespace, "-v4")

// Then check to see if it's truly been deleted
stdOut = oc.ExecListDir(podName, namespace, sourcePath)
stdOut = cliRunner.ExecListDir(podName, namespace, sourcePath)
helper.DontMatchAllInOutput(stdOut, []string{"foobar.txt", "testdir"})
})

Expand All @@ -127,10 +129,10 @@ var _ = Describe("odo devfile push command tests", func() {
helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--project", namespace)

// Check to see if it's been pushed (foobar.txt abd directory testdir)
podName := oc.GetRunningPodNameByComponent(cmpName, namespace)
podName := cliRunner.GetRunningPodNameByComponent(cmpName, namespace)

var statErr error
oc.CheckCmdOpInRemoteDevfilePod(
cliRunner.CheckCmdOpInRemoteDevfilePod(
podName,
"",
namespace,
Expand All @@ -144,7 +146,7 @@ var _ = Describe("odo devfile push command tests", func() {
Expect(os.Remove(filepath.Join(context, "app", "app.js"))).NotTo(HaveOccurred())
helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--project", namespace)

oc.CheckCmdOpInRemoteDevfilePod(
cliRunner.CheckCmdOpInRemoteDevfilePod(
podName,
"",
namespace,
Expand All @@ -166,11 +168,11 @@ var _ = Describe("odo devfile push command tests", func() {
utils.ExecDefaultDevfileCommands(context, cmpName, namespace)

// Check to see if it's been pushed (foobar.txt abd directory testdir)
podName := oc.GetRunningPodNameByComponent(cmpName, namespace)
podName := cliRunner.GetRunningPodNameByComponent(cmpName, namespace)

var statErr error
var cmdOutput string
oc.CheckCmdOpInRemoteDevfilePod(
cliRunner.CheckCmdOpInRemoteDevfilePod(
podName,
"runtime",
namespace,
Expand Down Expand Up @@ -282,11 +284,11 @@ var _ = Describe("odo devfile push command tests", func() {
})

// Check to see if it's been pushed (foobar.txt abd directory testdir)
podName := oc.GetRunningPodNameByComponent(cmpName, namespace)
podName := cliRunner.GetRunningPodNameByComponent(cmpName, namespace)

var statErr error
var cmdOutput string
oc.CheckCmdOpInRemoteDevfilePod(
cliRunner.CheckCmdOpInRemoteDevfilePod(
podName,
"runtime",
namespace,
Expand All @@ -300,7 +302,7 @@ var _ = Describe("odo devfile push command tests", func() {
Expect(statErr).ToNot(HaveOccurred())
Expect(cmdOutput).To(ContainSubstring("init"))

oc.CheckCmdOpInRemoteDevfilePod(
cliRunner.CheckCmdOpInRemoteDevfilePod(
podName,
"runtime2",
namespace,
Expand All @@ -314,7 +316,7 @@ var _ = Describe("odo devfile push command tests", func() {
Expect(statErr).ToNot(HaveOccurred())
Expect(cmdOutput).To(ContainSubstring("hello"))

oc.CheckCmdOpInRemoteDevfilePod(
cliRunner.CheckCmdOpInRemoteDevfilePod(
podName,
"runtime2",
namespace,
Expand All @@ -329,7 +331,7 @@ var _ = Describe("odo devfile push command tests", func() {
volumesMatched := false

// check the volume name and mount paths for the containers
volNamesAndPaths := oc.GetVolumeMountNamesandPathsFromContainer(cmpName, "runtime", namespace)
volNamesAndPaths := cliRunner.GetVolumeMountNamesandPathsFromContainer(cmpName, "runtime", namespace)
volNamesAndPathsArr := strings.Fields(volNamesAndPaths)
for _, volNamesAndPath := range volNamesAndPathsArr {
volNamesAndPathArr := strings.Split(volNamesAndPath, ":")
Expand Down
24 changes: 11 additions & 13 deletions tests/integration/devfile/cmd_devfile_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,34 @@ import (
)

var _ = Describe("odo devfile registry command tests", func() {
var project string
var context string
var currentWorkingDirectory string
var project, context, currentWorkingDirectory, originalKubeconfig string
const registryName string = "RegistryName"
const addRegistryURL string = "https://raw.githubusercontent.com/GeekArthur/registry/master"
const updateRegistryURL string = "http://www.example.com/update"

// Using program commmand according to cliRunner in devfile
cliRunner := helper.GetCliRunner()

// This is run after every Spec (It)
var _ = BeforeEach(func() {
SetDefaultEventuallyTimeout(10 * time.Minute)
context = helper.CreateNewContext()
os.Setenv("GLOBALODOCONFIG", filepath.Join(context, "config.yaml"))
helper.CmdShouldPass("odo", "preference", "set", "Experimental", "true")
if os.Getenv("KUBERNETES") == "true" {
project = helper.CreateRandNamespace(context)
} else {
project = helper.CreateRandProject()
}

originalKubeconfig = os.Getenv("KUBECONFIG")
helper.LocalKubeconfigSet(context)
project = cliRunner.CreateRandNamespaceProject()
currentWorkingDirectory = helper.Getwd()
helper.Chdir(context)
})

// This is run after every Spec (It)
var _ = AfterEach(func() {
if os.Getenv("KUBERNETES") == "true" {
helper.DeleteNamespace(project)
} else {
helper.DeleteProject(project)
}
cliRunner.DeleteNamespaceProject(project)
helper.Chdir(currentWorkingDirectory)
err := os.Setenv("KUBECONFIG", originalKubeconfig)
Expect(err).NotTo(HaveOccurred())
helper.DeleteDir(context)
})

Expand Down
Loading