From c367b7b0749ae26ac428919fd7310d220e2a6b54 Mon Sep 17 00:00:00 2001 From: Priti Kumari Date: Wed, 15 Apr 2020 13:14:25 +0530 Subject: [PATCH 1/2] Run devfile create Interation test on kubernetes cluster --- .travis.yml | 3 ++- pkg/odo/cli/component/create.go | 8 ------ .../devfile/cmd_devfile_create_test.go | 26 +++++++++++++++---- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index a19aeaeb895..4e9c134ea67 100644 --- a/.travis.yml +++ b/.travis.yml @@ -168,7 +168,7 @@ jobs: # Run devfile integration test on Kubernetes cluster - <<: *base-test stage: test - name: "devfile catalog, watch, push and delete command integration tests on kubernetes cluster" + name: "devfile catalog, watch, push, delete and create command integration tests on kubernetes cluster" env: - MINIKUBE_WANTUPDATENOTIFICATION=false - MINIKUBE_WANTREPORTERRORPROMPT=false @@ -193,3 +193,4 @@ jobs: - travis_wait make test-cmd-devfile-watch - travis_wait make test-cmd-devfile-push - travis_wait make test-cmd-devfile-delete + - travis_wait make test-cmd-devfile-create diff --git a/pkg/odo/cli/component/create.go b/pkg/odo/cli/component/create.go index ebeae5a5d8b..fe82dae9795 100644 --- a/pkg/odo/cli/component/create.go +++ b/pkg/odo/cli/component/create.go @@ -101,11 +101,8 @@ var EnvFilePath = filepath.Join(LocalDirectoryDefaultLocation, envFile) var ConfigFilePath = filepath.Join(LocalDirectoryDefaultLocation, configFile) var createLongDesc = ktemplates.LongDesc(`Create a configuration describing a component. - If a component name is not provided, it'll be auto-generated. - A full list of component types that can be deployed is available using: 'odo catalog list' - By default, builder images (component type) will be used from the current namespace. You can explicitly supply a namespace by using: odo create namespace/name:version If version is not specified by default, latest will be chosen as the version.`) @@ -119,19 +116,14 @@ Note: When you use odo with experimental mode enabled and create devfile compone # Create new Node.js component %[1]s nodejs - # Create new Node.js component named 'frontend' with the source in './frontend' directory %[1]s nodejs frontend --context ./frontend - # Create new Java component with binary named sample.jar in './target' directory %[1]s java:8 --binary target/sample.jar - # Create new Node.js component with source from remote git repository %[1]s nodejs --git https://github.com/openshift/nodejs-ex.git - # Create new Node.js component with custom ports, additional environment variables and memory and cpu limits %[1]s nodejs --port 8080,8100/tcp,9100/udp --env key=value,key1=value1 --memory 4Gi --cpu 2 - # Create new Node.js component and download the sample project named nodejs-web-app %[1]s nodejs --downloadSource=nodejs-web-app`) diff --git a/tests/integration/devfile/cmd_devfile_create_test.go b/tests/integration/devfile/cmd_devfile_create_test.go index 23b471cdaad..4d76928d50b 100644 --- a/tests/integration/devfile/cmd_devfile_create_test.go +++ b/tests/integration/devfile/cmd_devfile_create_test.go @@ -23,17 +23,28 @@ var _ = Describe("odo devfile create command tests", func() { // This is run after every Spec (It) var _ = BeforeEach(func() { SetDefaultEventuallyTimeout(10 * time.Minute) - namespace = helper.CreateRandProject() context = helper.CreateNewContext() - currentWorkingDirectory = helper.Getwd() - helper.Chdir(context) 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")) + namespace = helper.CreateRandNamespace(kubeConfigFile) + } else { + namespace = helper.CreateRandProject() + } + currentWorkingDirectory = helper.Getwd() + helper.Chdir(context) }) // This is run after every Spec (It) var _ = AfterEach(func() { - helper.DeleteProject(namespace) + if os.Getenv("KUBERNETES") == "true" { + helper.DeleteNamespace(namespace) + os.Unsetenv("KUBECONFIG") + } else { + helper.DeleteProject(namespace) + } helper.Chdir(currentWorkingDirectory) helper.DeleteDir(context) os.Unsetenv("GLOBALODOCONFIG") @@ -67,7 +78,12 @@ var _ = Describe("odo devfile create command tests", func() { It("should fail to create the devfile componet with invalid component type", func() { fakeComponentName := "fake-component" output := helper.CmdShouldFail("odo", "create", fakeComponentName) - expectedString := "component type \"" + fakeComponentName + "\" not found" + var expectedString string + if os.Getenv("KUBERNETES") == "true" { + expectedString = "component not found" + } else { + expectedString := "component type \"" + fakeComponentName + "\" not found" + } helper.MatchAllInOutput(output, []string{expectedString}) }) }) From 48d8dfc13bb83123ec268b39d2ba7896179db3b0 Mon Sep 17 00:00:00 2001 From: Priti Kumari Date: Fri, 15 May 2020 18:05:47 +0530 Subject: [PATCH 2/2] Skipping s2i image related test on kubernetes cluster --- pkg/odo/cli/component/create.go | 8 ++++ .../devfile/cmd_devfile_create_test.go | 38 +++++++++---------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/pkg/odo/cli/component/create.go b/pkg/odo/cli/component/create.go index fe82dae9795..ebeae5a5d8b 100644 --- a/pkg/odo/cli/component/create.go +++ b/pkg/odo/cli/component/create.go @@ -101,8 +101,11 @@ var EnvFilePath = filepath.Join(LocalDirectoryDefaultLocation, envFile) var ConfigFilePath = filepath.Join(LocalDirectoryDefaultLocation, configFile) var createLongDesc = ktemplates.LongDesc(`Create a configuration describing a component. + If a component name is not provided, it'll be auto-generated. + A full list of component types that can be deployed is available using: 'odo catalog list' + By default, builder images (component type) will be used from the current namespace. You can explicitly supply a namespace by using: odo create namespace/name:version If version is not specified by default, latest will be chosen as the version.`) @@ -116,14 +119,19 @@ Note: When you use odo with experimental mode enabled and create devfile compone # Create new Node.js component %[1]s nodejs + # Create new Node.js component named 'frontend' with the source in './frontend' directory %[1]s nodejs frontend --context ./frontend + # Create new Java component with binary named sample.jar in './target' directory %[1]s java:8 --binary target/sample.jar + # Create new Node.js component with source from remote git repository %[1]s nodejs --git https://github.com/openshift/nodejs-ex.git + # Create new Node.js component with custom ports, additional environment variables and memory and cpu limits %[1]s nodejs --port 8080,8100/tcp,9100/udp --env key=value,key1=value1 --memory 4Gi --cpu 2 + # Create new Node.js component and download the sample project named nodejs-web-app %[1]s nodejs --downloadSource=nodejs-web-app`) diff --git a/tests/integration/devfile/cmd_devfile_create_test.go b/tests/integration/devfile/cmd_devfile_create_test.go index 4d76928d50b..6e8b14d6bc7 100644 --- a/tests/integration/devfile/cmd_devfile_create_test.go +++ b/tests/integration/devfile/cmd_devfile_create_test.go @@ -15,10 +15,10 @@ import ( var _ = Describe("odo devfile create command tests", func() { const devfile = "devfile.yaml" const envFile = ".odo/env/env.yaml" - var namespace string - var context string - var currentWorkingDirectory string - var devfilePath string + var namespace, context, currentWorkingDirectory, devfilePath, originalKubeconfig string + + // Using program commmand according to cliRunner in devfile + cliRunner := helper.GetCliRunner() // This is run after every Spec (It) var _ = BeforeEach(func() { @@ -26,26 +26,19 @@ var _ = Describe("odo devfile create command tests", func() { 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")) - namespace = helper.CreateRandNamespace(kubeConfigFile) - } else { - namespace = helper.CreateRandProject() - } + originalKubeconfig = os.Getenv("KUBECONFIG") + helper.LocalKubeconfigSet(context) + namespace = 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(namespace) - os.Unsetenv("KUBECONFIG") - } else { - helper.DeleteProject(namespace) - } + cliRunner.DeleteNamespaceProject(namespace) helper.Chdir(currentWorkingDirectory) + err := os.Setenv("KUBECONFIG", originalKubeconfig) + Expect(err).NotTo(HaveOccurred()) helper.DeleteDir(context) os.Unsetenv("GLOBALODOCONFIG") }) @@ -59,7 +52,14 @@ var _ = Describe("odo devfile create command tests", func() { Expect(helper.CmdShouldPass("odo", "create", "nodejs")).To(ContainSubstring(experimentalOutputMsg)) }) + }) + Context("Disabling experimental preference should show a disclaimer", func() { + JustBeforeEach(func() { + if os.Getenv("KUBERNETES") == "true" { + Skip("Skipping test because s2i image is not supported on Kubernetes cluster") + } + }) It("checks that the experimental warning does *not* appear when Experimental is set to false for create", func() { helper.CmdShouldPass("odo", "preference", "set", "Experimental", "false", "-f") helper.CopyExample(filepath.Join("source", "nodejs"), context) @@ -80,9 +80,9 @@ var _ = Describe("odo devfile create command tests", func() { output := helper.CmdShouldFail("odo", "create", fakeComponentName) var expectedString string if os.Getenv("KUBERNETES") == "true" { - expectedString = "component not found" + expectedString = "component type not found" } else { - expectedString := "component type \"" + fakeComponentName + "\" not found" + expectedString = "component type \"" + fakeComponentName + "\" not found" } helper.MatchAllInOutput(output, []string{expectedString}) })