MCPcopy
hub / github.com/google/cadvisor / PushAndRunTests

Function PushAndRunTests

integration/runner/runner.go:92–196  ·  view source on GitHub ↗
(host, testDir string)

Source from the content-addressed store, hash-verified

90}
91
92func PushAndRunTests(host, testDir string) (result error) {
93 // Push binary.
94 klog.Infof("Pushing cAdvisor binary to %q...", host)
95
96 err := RunSshCommand("ssh", host, "--", "mkdir", "-p", testDir)
97 if err != nil {
98 return fmt.Errorf("failed to make remote testing directory: %v", err)
99 }
100 defer func() {
101 err = RunSshCommand("ssh", host, "--", "rm", "-rf", testDir)
102 if err != nil {
103 klog.Errorf("Failed to cleanup test directory: %v", err)
104 }
105 }()
106
107 err = RunSshCommand("scp", "-r", cadvisorBinary, fmt.Sprintf("%s:%s", host, testDir))
108 if err != nil {
109 return fmt.Errorf("failed to copy binary: %v", err)
110 }
111
112 // Start cAdvisor.
113 klog.Infof("Running cAdvisor on %q...", host)
114 portStr := strconv.Itoa(*port)
115 errChan := make(chan error, 1)
116 go func() {
117 err = RunSshCommand("ssh", host, "--", fmt.Sprintf("sudo GORACE='halt_on_error=1' %s --port %s --logtostderr --env_metadata_whitelist=TEST_VAR &> %s/log.txt", path.Join(testDir, cadvisorBinary), portStr, testDir))
118 if err != nil {
119 errChan <- fmt.Errorf("error running cAdvisor: %v", err)
120 }
121 }()
122 defer func() {
123 err = RunSshCommand("ssh", host, "--", "sudo", "pkill", cadvisorBinary)
124 if err != nil {
125 klog.Errorf("Failed to cleanup: %v", err)
126 }
127 }()
128 defer func() {
129 if result != nil {
130 // Copy logs from the host
131 err := RunSshCommand("scp", fmt.Sprintf("%s:%s/log.txt", host, testDir), "./")
132 if err != nil {
133 result = fmt.Errorf("error fetching logs: %v for %v", err, result)
134 return
135 }
136 defer os.Remove("./log.txt")
137 logs, err := os.ReadFile("./log.txt")
138 if err != nil {
139 result = fmt.Errorf("error reading local log file: %v for %v", err, result)
140 return
141 }
142 klog.Errorf("----------------------\nLogs from Host: %q\n%v\n", host, string(logs))
143
144 // Get attributes for debugging purposes.
145 attributes, err := getAttributes(host, portStr)
146 if err != nil {
147 klog.Errorf("Failed to read host attributes: %v", err)
148 }
149 result = fmt.Errorf("error on host %s: %v\n%+v", host, result, attributes)

Callers 1

RunFunction · 0.85

Calls 11

RunSshCommandFunction · 0.85
getAttributesFunction · 0.85
RunCommandFunction · 0.85
InfofMethod · 0.80
ErrorfMethod · 0.80
ReadFileMethod · 0.80
WarningfMethod · 0.80
AddMethod · 0.65
GetMethod · 0.65
StringMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…