From 8ad83fd685f21733dbd860103a7fc8eaddb790ab Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Mon, 12 Jul 2021 12:08:19 +0200 Subject: [PATCH] Make crictl tests host local We now use a host local exec instead of SSH commands to simplify the test and make the result more robust. Signed-off-by: Sascha Grunert --- test/e2e/node/crictl.go | 46 ++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/test/e2e/node/crictl.go b/test/e2e/node/crictl.go index 86ba1bdd6b4..a841032e824 100644 --- a/test/e2e/node/crictl.go +++ b/test/e2e/node/crictl.go @@ -18,11 +18,11 @@ package node import ( "fmt" - "strings" "k8s.io/kubernetes/test/e2e/framework" + e2enode "k8s.io/kubernetes/test/e2e/framework/node" e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper" - e2essh "k8s.io/kubernetes/test/e2e/framework/ssh" + "k8s.io/kubernetes/test/e2e/storage/utils" "github.com/onsi/ginkgo" ) @@ -33,42 +33,28 @@ var _ = SIGDescribe("crictl", func() { ginkgo.BeforeEach(func() { // `crictl` is not available on all cloud providers. e2eskipper.SkipUnlessProviderIs("gce", "gke") - // The test requires $HOME/.ssh/id_rsa key to be present. - e2eskipper.SkipUnlessSSHKeyPresent() }) ginkgo.It("should be able to run crictl on the node", func() { - // Get all nodes' external IPs. - ginkgo.By("Getting all nodes' SSH-able IP addresses") - hosts, err := e2essh.NodeSSHHosts(f.ClientSet) - if err != nil { - framework.Failf("Error getting node hostnames: %v", err) - } - e2eskipper.SkipUnlessAtLeast(len(hosts), 1, "Skipping test because found no SSH'able node") + nodes, err := e2enode.GetBoundedReadySchedulableNodes(f.ClientSet, maxNodes) + framework.ExpectNoError(err) - testCases := []struct { - cmd string - }{ - {`sudo crictl version`}, - {`sudo crictl info`}, + testCases := []string{ + "crictl version", + "crictl info", } + hostExec := utils.NewHostExec(f) + for _, testCase := range testCases { - for _, host := range hosts { - ginkgo.By(fmt.Sprintf("SSH'ing to node %q to run %q", host, testCase.cmd)) + for _, node := range nodes.Items { + ginkgo.By(fmt.Sprintf("Testing %q on node %q ", testCase, node.GetName())) - result, err := e2essh.SSH(testCase.cmd, host, framework.TestContext.Provider) - stdout, stderr := strings.TrimSpace(result.Stdout), strings.TrimSpace(result.Stderr) - if err != nil { - framework.Failf("Ran %q on %q, got error %v", testCase.cmd, host, err) - } - // Log the stdout/stderr output. - // TODO: Verify the output. - if len(stdout) > 0 { - framework.Logf("Got stdout from %q:\n %s\n", host, strings.TrimSpace(stdout)) - } - if len(stderr) > 0 { - framework.Logf("Got stderr from %q:\n %s\n", host, strings.TrimSpace(stderr)) + res, err := hostExec.Execute(testCase, &node) + framework.ExpectNoError(err) + + if res.Stdout == "" && res.Stderr == "" { + framework.Fail("output is empty") } } }