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