crictl.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. Copyright 2018 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package node
  14. import (
  15. "fmt"
  16. "strings"
  17. "k8s.io/kubernetes/test/e2e/framework"
  18. e2elog "k8s.io/kubernetes/test/e2e/framework/log"
  19. e2essh "k8s.io/kubernetes/test/e2e/framework/ssh"
  20. "github.com/onsi/ginkgo"
  21. )
  22. var _ = SIGDescribe("crictl", func() {
  23. f := framework.NewDefaultFramework("crictl")
  24. ginkgo.BeforeEach(func() {
  25. // `crictl` is not available on all cloud providers.
  26. framework.SkipUnlessProviderIs("gce", "gke")
  27. // The test requires $HOME/.ssh/id_rsa key to be present.
  28. framework.SkipUnlessSSHKeyPresent()
  29. })
  30. ginkgo.It("should be able to run crictl on the node", func() {
  31. // Get all nodes' external IPs.
  32. ginkgo.By("Getting all nodes' SSH-able IP addresses")
  33. hosts, err := e2essh.NodeSSHHosts(f.ClientSet)
  34. if err != nil {
  35. framework.Failf("Error getting node hostnames: %v", err)
  36. }
  37. testCases := []struct {
  38. cmd string
  39. }{
  40. {`sudo crictl version`},
  41. {`sudo crictl info`},
  42. }
  43. for _, testCase := range testCases {
  44. // Choose an arbitrary node to test.
  45. host := hosts[0]
  46. ginkgo.By(fmt.Sprintf("SSH'ing to node %q to run %q", host, testCase.cmd))
  47. result, err := e2essh.SSH(testCase.cmd, host, framework.TestContext.Provider)
  48. stdout, stderr := strings.TrimSpace(result.Stdout), strings.TrimSpace(result.Stderr)
  49. if err != nil {
  50. framework.Failf("Ran %q on %q, got error %v", testCase.cmd, host, err)
  51. }
  52. // Log the stdout/stderr output.
  53. // TODO: Verify the output.
  54. if len(stdout) > 0 {
  55. e2elog.Logf("Got stdout from %q:\n %s\n", host, strings.TrimSpace(stdout))
  56. }
  57. if len(stderr) > 0 {
  58. e2elog.Logf("Got stderr from %q:\n %s\n", host, strings.TrimSpace(stderr))
  59. }
  60. }
  61. })
  62. })