-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25638 from soltysh/test_cmd2
Move debug.sh & timeout.sh to a proper e2e
- Loading branch information
Showing
9 changed files
with
323 additions
and
402 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,188 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
|
||
g "github.com/onsi/ginkgo" | ||
o "github.com/onsi/gomega" | ||
|
||
"k8s.io/apimachinery/pkg/util/wait" | ||
|
||
exutil "github.com/openshift/origin/test/extended/util" | ||
) | ||
|
||
var _ = g.Describe("[sig-cli][Slow] oc debug", func() { | ||
var _ = g.Describe("[sig-cli] oc debug", func() { | ||
oc := exutil.NewCLI("oc-debug") | ||
templatePath := exutil.FixturePath("testdata", "test-cli-debug.yaml") | ||
testCLIDebug := exutil.FixturePath("testdata", "test-cli-debug.yaml") | ||
testDeploymentConfig := exutil.FixturePath("testdata", "test-deployment-config.yaml") | ||
testReplicationController := exutil.FixturePath("testdata", "test-replication-controller.yaml") | ||
helloPod := exutil.FixturePath("..", "..", "examples", "hello-openshift", "hello-pod.json") | ||
imageStreamsCentos := exutil.FixturePath("..", "..", "examples", "image-streams", "image-streams-centos7.json") | ||
|
||
g.It("deployment configs from a build", func() { | ||
err := oc.Run("create").Args("-f", testCLIDebug).Execute() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
err = wait.Poll(cliInterval, cliTimeout, func() (bool, error) { | ||
err := oc.Run("get").Args("imagestreamtags", "local-busybox:latest").Execute() | ||
return err == nil, nil | ||
}) | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
||
g.By("should print the imagestream-based container entrypoint/command") | ||
var out string | ||
out, err = oc.Run("debug").Args("dc/local-busybox1").Output() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(out).To(o.ContainSubstring("Starting pod/local-busybox1-debug, command was: sh\n")) | ||
|
||
g.JustBeforeEach(func() { | ||
g.By("calling oc create -f " + templatePath) | ||
err := oc.Run("create").Args("-f", templatePath).Execute() | ||
g.By("should print the overridden imagestream-based container entrypoint/command") | ||
out, err = oc.Run("debug").Args("dc/local-busybox2").Output() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(out).To(o.ContainSubstring("Starting pod/local-busybox2-debug, command was: foo bar baz qux\n")) | ||
|
||
exutil.WaitForAnImageStreamTag(oc, oc.Namespace(), "local-busybox", "latest") | ||
g.By("should print the container image-based container entrypoint/command") | ||
out, err = oc.Run("debug").Args("dc/busybox1").Output() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(out).To(o.ContainSubstring("Starting pod/busybox1-debug ...\n")) | ||
|
||
g.By("should print the overridden container image-based container entrypoint/command") | ||
out, err = oc.Run("debug").Args("dc/busybox2").Output() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(out).To(o.ContainSubstring("Starting pod/busybox2-debug, command was: foo bar baz qux\n")) | ||
}) | ||
|
||
g.It("should print the imagestream-based container entrypoint/command", func() { | ||
out, err := oc.Run("debug").Args("dc/local-busybox1").Output() | ||
g.It("dissect deployment config debug", func() { | ||
err := oc.Run("create").Args("-f", testDeploymentConfig).Execute() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
||
var out string | ||
out, err = oc.Run("debug").Args("dc/test-deployment-config", "-oyaml").Output() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(out).To(o.ContainSubstring("- /bin/sh")) | ||
|
||
out, err = oc.Run("debug").Args("dc/test-deployment-config", "--keep-annotations", "-oyaml").Output() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(out).To(o.ContainSubstring("annotations:")) | ||
|
||
out, err = oc.Run("debug").Args("dc/test-deployment-config", "--as-root", "-oyaml").Output() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(out).To(o.ContainSubstring("runAsUser: 0")) | ||
|
||
out, err = oc.Run("debug").Args("dc/test-deployment-config", "--as-root=false", "-oyaml").Output() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(out).To(o.ContainSubstring("runAsNonRoot: true")) | ||
|
||
out, err = oc.Run("debug").Args("dc/test-deployment-config", "--as-user=1", "-oyaml").Output() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(out).To(o.ContainSubstring("runAsUser: 1")) | ||
|
||
out, err = oc.Run("debug").Args("dc/test-deployment-config", "-t", "-oyaml").Output() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(out).To(o.ContainSubstring("stdinOnce")) | ||
o.Expect(out).To(o.ContainSubstring("tty")) | ||
|
||
out, err = oc.Run("debug").Args("dc/test-deployment-config", "--tty=false", "-oyaml").Output() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(out).NotTo(o.ContainSubstring("tty")) | ||
|
||
out, err = oc.Run("debug").Args("dc/test-deployment-config", "-oyaml", "--", "/bin/env").Output() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(out).To(o.ContainSubstring("Debugging with pod/local-busybox1-debug, original command: sh\n")) | ||
o.Expect(out).To(o.ContainSubstring("- /bin/env")) | ||
o.Expect(out).NotTo(o.ContainSubstring("stdin")) | ||
o.Expect(out).NotTo(o.ContainSubstring("tty")) | ||
|
||
out, err = oc.Run("debug").Args("dc/test-deployment-config", "--node-name=invalid", "--", "/bin/env").Output() | ||
o.Expect(err).To(o.HaveOccurred()) | ||
o.Expect(out).To(o.ContainSubstring(`on node "invalid"`)) | ||
}) | ||
|
||
g.It("should print the overridden imagestream-based container entrypoint/command", func() { | ||
out, err := oc.Run("debug").Args("dc/local-busybox2").Output() | ||
g.It("does not require a real resource on the server", func() { | ||
out, err := oc.Run("debug").Args("-T", "-f", helloPod, "-oyaml").Output() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(out).NotTo(o.ContainSubstring("tty")) | ||
|
||
err = oc.Run("debug").Args("-f", helloPod, "--keep-liveness", "--keep-readiness", "-oyaml").Execute() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(out).To(o.ContainSubstring("Debugging with pod/local-busybox2-debug, original command: foo bar baz qux\n")) | ||
|
||
out, err = oc.Run("debug").Args("-f", helloPod, "-oyaml", "--", "/bin/env").Output() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(out).To(o.ContainSubstring("- /bin/env")) | ||
o.Expect(out).NotTo(o.ContainSubstring("stdin")) | ||
o.Expect(out).NotTo(o.ContainSubstring("tty")) | ||
}) | ||
|
||
g.It("should print the container image-based container entrypoint/command", func() { | ||
out, err := oc.Run("debug").Args("dc/busybox1").Output() | ||
// TODO: write a test that emulates a TTY to verify the correct defaulting of what the pod is created | ||
|
||
g.It("ensure debug does not depend on a container actually existing for the selected resource", func() { | ||
err := oc.Run("create").Args("-f", testReplicationController).Execute() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
err = oc.Run("create").Args("-f", testDeploymentConfig).Execute() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
||
// The command should not hang waiting for an attachable pod. Timeout each cmd after 10s. | ||
err = oc.Run("scale").Args("--replicas=0", "rc/test-replication-controller").Execute() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
||
var out string | ||
out, err = oc.Run("debug").Args("--request-timeout=10s", "-c", "ruby-helloworld", "--one-container", "rc/test-replication-controller", "-o", "jsonpath='{.metadata.name}").Output() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(out).To(o.ContainSubstring("test-replication-controller-debug")) | ||
|
||
err = oc.Run("scale").Args("--replicas=0", "dc/test-deployment-config").Execute() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(out).To(o.ContainSubstring("Debugging with pod/busybox1-debug, original command: sh\n")) | ||
|
||
out, err = oc.Run("debug").Args("--request-timeout=10s", "-c", "ruby-helloworld", "--one-container", "dc/test-deployment-config", "-o", "jsonpath='{.metadata.name}").Output() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(out).To(o.ContainSubstring("test-deployment-config")) | ||
|
||
err = oc.Run("create").Args("-f", "-").InputString(` | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: test-deployment | ||
labels: | ||
deployment: test-deployment | ||
spec: | ||
replicas: 0 | ||
selector: | ||
matchLabels: | ||
deployment: test-deployment | ||
template: | ||
metadata: | ||
labels: | ||
deployment: test-deployment | ||
name: test-deployment | ||
spec: | ||
containers: | ||
- name: ruby-helloworld | ||
image: openshift/origin-pod | ||
imagePullPolicy: IfNotPresent | ||
`).Execute() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
||
out, err = oc.Run("debug").Args("--request-timeout=10s", "-c", "ruby-helloworld", "--one-container", "deploy/test-deployment", "-o", "jsonpath='{.metadata.name}").Output() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(out).To(o.ContainSubstring("test-deployment-debug")) | ||
}) | ||
|
||
g.It("should print the overridden container image-based container entrypoint/command", func() { | ||
out, err := oc.Run("debug").Args("dc/busybox2").Output() | ||
g.It("ensure it works with image streams", func() { | ||
err := oc.Run("create").Args("-f", imageStreamsCentos).Execute() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
err = wait.Poll(cliInterval, cliTimeout, func() (bool, error) { | ||
err := oc.Run("get").Args("imagestreamtags", "wildfly:latest").Execute() | ||
return err == nil, nil | ||
}) | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
||
var out string | ||
out, err = oc.Run("debug").Args("istag/wildfly:latest", "-o", "yaml").Output() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(out).To(o.MatchRegexp("image:.*oc-debug-.*/wildfly@sha256")) | ||
|
||
var sha string | ||
sha, err = oc.Run("get").Args("istag/wildfly:latest", "--template", "{{ .image.metadata.name }}").Output() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
out, err = oc.Run("debug").Args(fmt.Sprintf("isimage/wildfly@%s", sha), "-o", "yaml").Output() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(out).To(o.ContainSubstring("Debugging with pod/busybox2-debug, original command: foo bar baz qux\n")) | ||
o.Expect(out).To(o.ContainSubstring("image: docker.io/openshift/wildfly-150-centos7")) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package cli | ||
|
||
import ( | ||
g "github.com/onsi/ginkgo" | ||
o "github.com/onsi/gomega" | ||
|
||
exutil "github.com/openshift/origin/test/extended/util" | ||
) | ||
|
||
var _ = g.Describe("[sig-cli] oc --request-timeout", func() { | ||
oc := exutil.NewCLI("oc-request-timeout") | ||
|
||
g.It("works as expected", func() { | ||
err := oc.Run("create").Args("deploymentconfig", "testdc", "--image=busybox").Execute() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
||
out, err := oc.Run("get", "dc/testdc").Args("-w", "-v=5", "--request-timeout=1s").Output() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
// timeout is set for both the request and on context in request | ||
// seek8s.io/client-go/rest/request.go#request so if we get timeout | ||
// from server or from context it's ok | ||
o.Expect(out).Should(o.SatisfyAny(o.ContainSubstring("request canceled"), o.ContainSubstring("context deadline exceeded"))) | ||
|
||
out, err = oc.Run("get", "dc/testdc").Args("--request-timeout=1s").Output() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(out).To(o.ContainSubstring("testdc")) | ||
|
||
out, err = oc.Run("get", "dc/testdc").Args("--request-timeout=1").Output() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(out).To(o.ContainSubstring("testdc")) | ||
|
||
out, err = oc.Run("get", "pods").Args("--watch", "-v=5", "--request-timeout=1s").Output() | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(out).Should(o.SatisfyAny(o.ContainSubstring("request canceled"), o.ContainSubstring("context deadline exceeded"))) | ||
}) | ||
}) |
Oops, something went wrong.