cadvisor_e2e.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 remote
  14. import (
  15. "fmt"
  16. "os"
  17. "os/exec"
  18. "time"
  19. "k8s.io/klog"
  20. "k8s.io/kubernetes/test/utils"
  21. )
  22. // CAdvisorE2ERemote contains the specific functions in the cadvisor e2e test suite.
  23. type CAdvisorE2ERemote struct{}
  24. // InitCAdvisorE2ERemote performs initialization for cadvisor remote testing
  25. func InitCAdvisorE2ERemote() TestSuite {
  26. return &CAdvisorE2ERemote{}
  27. }
  28. // SetupTestPackage implements TestSuite.SetupTestPackage
  29. func (n *CAdvisorE2ERemote) SetupTestPackage(tardir, systemSpecName string) error {
  30. cadvisorRootDir, err := utils.GetCAdvisorRootDir()
  31. if err != nil {
  32. return err
  33. }
  34. // build the cadvisor binary and tests
  35. if err := runCommand(fmt.Sprintf("%s/build/prow_e2e.sh", cadvisorRootDir)); err != nil {
  36. return err
  37. }
  38. // transfer the entire directory to each node
  39. if err := runCommand("cp", "-R", cadvisorRootDir, fmt.Sprintf("%s/", tardir)); err != nil {
  40. return err
  41. }
  42. return nil
  43. }
  44. func runCommand(command string, args ...string) error {
  45. cmd := exec.Command(command, args...)
  46. cmd.Stdout = os.Stdout
  47. cmd.Stderr = os.Stderr
  48. err := cmd.Run()
  49. if err != nil {
  50. return fmt.Errorf("failed to run command %s. error: %v", command, err)
  51. }
  52. return nil
  53. }
  54. // RunTest implements TestSuite.RunTest
  55. func (n *CAdvisorE2ERemote) RunTest(host, workspace, results, imageDesc, junitFilePrefix, testArgs, ginkgoArgs, systemSpecName, extraEnvs string, timeout time.Duration) (string, error) {
  56. // Kill any running node processes
  57. cleanupNodeProcesses(host)
  58. klog.V(2).Infof("Starting tests on %q", host)
  59. return SSH(host, "sh", "-c", getSSHCommand(" && ",
  60. fmt.Sprintf("cd %s/cadvisor", workspace),
  61. fmt.Sprintf("timeout -k 30s %fs ./build/integration.sh ../results/cadvisor.log",
  62. timeout.Seconds()),
  63. ))
  64. }