Skip to content

Commit 4601758

Browse files
authored
Merge pull request #1110 from sunnylovestiramisu/cleanup
Clean up error logging in test
2 parents 900f5f7 + de22bd3 commit 4601758

12 files changed

+103
-103
lines changed

Diff for: test/e2e/tests/multi_zone_e2e_test.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func testAttachWriteReadDetach(volID string, volName string, instance *remote.In
157157
testFile := filepath.Join(a.publishDir, "testfile")
158158
err := testutils.WriteFile(instance, testFile, testFileContents)
159159
if err != nil {
160-
return fmt.Errorf("Failed to write file: %v", err)
160+
return fmt.Errorf("Failed to write file: %v", err.Error())
161161
}
162162
}
163163
return nil
@@ -168,7 +168,7 @@ func testAttachWriteReadDetach(volID string, volName string, instance *remote.In
168168
secondTestFile := filepath.Join(a.publishDir, "testfile")
169169
readContents, err := testutils.ReadFile(instance, secondTestFile)
170170
if err != nil {
171-
return fmt.Errorf("ReadFile failed with error: %v", err)
171+
return fmt.Errorf("ReadFile failed with error: %v", err.Error())
172172
}
173173
if strings.TrimSpace(string(readContents)) != testFileContents {
174174
return fmt.Errorf("wanted test file content: %s, got content: %s", testFileContents, readContents)
@@ -184,7 +184,7 @@ func testLifecycleWithVerify(volID string, volName string, instance *remote.Inst
184184
// Attach Disk
185185
err = client.ControllerPublishVolume(volID, instance.GetNodeID())
186186
if err != nil {
187-
return fmt.Errorf("ControllerPublishVolume failed with error for disk %v on node %v: %v", volID, instance.GetNodeID(), err)
187+
return fmt.Errorf("ControllerPublishVolume failed with error for disk %v on node %v: %v", volID, instance.GetNodeID(), err.Error())
188188
}
189189

190190
defer func() {
@@ -232,11 +232,11 @@ func testLifecycleWithVerify(volID string, volName string, instance *remote.Inst
232232
}
233233

234234
if err != nil {
235-
return fmt.Errorf("NodePublishVolume failed with error: %v", err)
235+
return fmt.Errorf("NodePublishVolume failed with error: %v", err.Error())
236236
}
237237
err = testutils.ForceChmod(instance, filepath.Join("/tmp/", volName), "777")
238238
if err != nil {
239-
return fmt.Errorf("Chmod failed with error: %v", err)
239+
return fmt.Errorf("Chmod failed with error: %v", err.Error())
240240
}
241241

242242
a := verifyArgs{
@@ -251,7 +251,7 @@ func testLifecycleWithVerify(volID string, volName string, instance *remote.Inst
251251
// Unmount Disk
252252
err = client.NodeUnpublishVolume(volID, publishDir)
253253
if err != nil {
254-
return fmt.Errorf("NodeUnpublishVolume failed with error: %v", err)
254+
return fmt.Errorf("NodeUnpublishVolume failed with error: %v", err.Error())
255255
}
256256

257257
if secondMountVerify != nil {
@@ -263,7 +263,7 @@ func testLifecycleWithVerify(volID string, volName string, instance *remote.Inst
263263
err = client.NodePublishVolume(volID, stageDir, secondPublishDir)
264264
}
265265
if err != nil {
266-
return fmt.Errorf("NodePublishVolume failed with error: %v", err)
266+
return fmt.Errorf("NodePublishVolume failed with error: %v", err.Error())
267267
}
268268
err = testutils.ForceChmod(instance, filepath.Join("/tmp/", volName), "777")
269269
if err != nil {
@@ -275,13 +275,13 @@ func testLifecycleWithVerify(volID string, volName string, instance *remote.Inst
275275
}
276276
err = secondMountVerify(b)
277277
if err != nil {
278-
return fmt.Errorf("failed to verify after second mount to %s: %v", publishDir, err)
278+
return fmt.Errorf("failed to verify after second mount to %s: %v", publishDir, err.Error())
279279
}
280280

281281
// Unmount Disk
282282
err = client.NodeUnpublishVolume(volID, secondPublishDir)
283283
if err != nil {
284-
return fmt.Errorf("NodeUnpublishVolume failed with error: %v", err)
284+
return fmt.Errorf("NodeUnpublishVolume failed with error: %v", err.Error())
285285
}
286286
}
287287

Diff for: test/e2e/tests/single_zone_e2e_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ var _ = Describe("GCE PD CSI Driver", func() {
692692
verifyVolumeStats := func(a verifyArgs) error {
693693
available, capacity, used, inodesFree, inodes, inodesUsed, err := client.NodeGetVolumeStats(volID, a.publishDir)
694694
if err != nil {
695-
return fmt.Errorf("failed to get node volume stats: %v", err)
695+
return fmt.Errorf("failed to get node volume stats: %v", err.Error())
696696
}
697697
if available != 0 || capacity != common.GbToBytes(defaultSizeGb) || used != 0 ||
698698
inodesFree != 0 || inodes != 0 || inodesUsed != 0 {
@@ -729,7 +729,7 @@ var _ = Describe("GCE PD CSI Driver", func() {
729729
verifyVolumeStats := func(a verifyArgs) error {
730730
available, capacity, used, inodesFree, inodes, inodesUsed, err := client.NodeGetVolumeStats(volID, a.publishDir)
731731
if err != nil {
732-
return fmt.Errorf("failed to get node volume stats: %v", err)
732+
return fmt.Errorf("failed to get node volume stats: %v", err.Error())
733733
}
734734
if !equalWithinEpsilon(available, common.GbToBytes(defaultSizeGb), defaultEpsilon) || !equalWithinEpsilon(capacity, common.GbToBytes(defaultSizeGb), defaultEpsilon) || !equalWithinEpsilon(used, 0, defaultEpsilon) ||
735735
inodesFree == 0 || inodes == 0 || inodesUsed == 0 {
@@ -795,14 +795,14 @@ var _ = Describe("GCE PD CSI Driver", func() {
795795
writeFunc := func(a verifyArgs) error {
796796
err := testutils.WriteBlock(instance, a.publishDir, testFileContents)
797797
if err != nil {
798-
return fmt.Errorf("Failed to write file: %v", err)
798+
return fmt.Errorf("Failed to write file: %v", err.Error())
799799
}
800800
return nil
801801
}
802802
verifyReadFunc := func(a verifyArgs) error {
803803
readContents, err := testutils.ReadBlock(instance, a.publishDir, len(testFileContents))
804804
if err != nil {
805-
return fmt.Errorf("ReadFile failed with error: %v", err)
805+
return fmt.Errorf("ReadFile failed with error: %v", err.Error())
806806
}
807807
if strings.TrimSpace(string(readContents)) != testFileContents {
808808
return fmt.Errorf("wanted test file content: %s, got content: %s", testFileContents, readContents)

Diff for: test/e2e/utils/utils.go

+17-17
Original file line numberDiff line numberDiff line change
@@ -147,43 +147,43 @@ func SetupProwConfig(resourceType string) (project, serviceAccount string) {
147147
func ForceChmod(instance *remote.InstanceInfo, filePath string, perms string) error {
148148
originalumask, err := instance.SSHNoSudo("umask")
149149
if err != nil {
150-
return fmt.Errorf("failed to umask. Output: %v, errror: %v", originalumask, err)
150+
return fmt.Errorf("failed to umask. Output: %v, errror: %v", originalumask, err.Error())
151151
}
152152
output, err := instance.SSHNoSudo("umask", "0000")
153153
if err != nil {
154-
return fmt.Errorf("failed to umask. Output: %v, errror: %v", output, err)
154+
return fmt.Errorf("failed to umask. Output: %v, errror: %v", output, err.Error())
155155
}
156156
output, err = instance.SSH("chmod", "-R", perms, filePath)
157157
if err != nil {
158-
return fmt.Errorf("failed to chmod file %s. Output: %v, errror: %v", filePath, output, err)
158+
return fmt.Errorf("failed to chmod file %s. Output: %v, errror: %v", filePath, output, err.Error())
159159
}
160160
output, err = instance.SSHNoSudo("umask", originalumask)
161161
if err != nil {
162-
return fmt.Errorf("failed to umask. Output: %v, errror: %v", output, err)
162+
return fmt.Errorf("failed to umask. Output: %v, errror: %v", output, err.Error())
163163
}
164164
return nil
165165
}
166166

167167
func WriteFile(instance *remote.InstanceInfo, filePath, fileContents string) error {
168168
output, err := instance.SSHNoSudo("echo", fileContents, ">", filePath)
169169
if err != nil {
170-
return fmt.Errorf("failed to write test file %s. Output: %v, errror: %v", filePath, output, err)
170+
return fmt.Errorf("failed to write test file %s. Output: %v, errror: %v", filePath, output, err.Error())
171171
}
172172
return nil
173173
}
174174

175175
func ReadFile(instance *remote.InstanceInfo, filePath string) (string, error) {
176176
output, err := instance.SSHNoSudo("cat", filePath)
177177
if err != nil {
178-
return "", fmt.Errorf("failed to read test file %s. Output: %v, errror: %v", filePath, output, err)
178+
return "", fmt.Errorf("failed to read test file %s. Output: %v, errror: %v", filePath, output, err.Error())
179179
}
180180
return output, nil
181181
}
182182

183183
func WriteBlock(instance *remote.InstanceInfo, path, fileContents string) error {
184184
output, err := instance.SSHNoSudo("echo", fileContents, "|", "dd", "of="+path)
185185
if err != nil {
186-
return fmt.Errorf("failed to write test file %s. Output: %v, errror: %v", path, output, err)
186+
return fmt.Errorf("failed to write test file %s. Output: %v, errror: %v", path, output, err.Error())
187187
}
188188
return nil
189189
}
@@ -192,15 +192,15 @@ func ReadBlock(instance *remote.InstanceInfo, path string, length int) (string,
192192
lengthStr := strconv.Itoa(length)
193193
output, err := instance.SSHNoSudo("dd", "if="+path, "bs="+lengthStr, "count=1", "2>", "/dev/null")
194194
if err != nil {
195-
return "", fmt.Errorf("failed to read test file %s. Output: %v, errror: %v", path, output, err)
195+
return "", fmt.Errorf("failed to read test file %s. Output: %v, errror: %v", path, output, err.Error())
196196
}
197197
return output, nil
198198
}
199199

200200
func GetFSSizeInGb(instance *remote.InstanceInfo, mountPath string) (int64, error) {
201201
output, err := instance.SSH("df", "--output=size", "-BG", mountPath, "|", "awk", "'NR==2'")
202202
if err != nil {
203-
return -1, fmt.Errorf("failed to get size of path %s. Output: %v, error: %v", mountPath, output, err)
203+
return -1, fmt.Errorf("failed to get size of path %s. Output: %v, error: %v", mountPath, output, err.Error())
204204
}
205205
output = strings.TrimSuffix(strings.TrimSpace(output), "G")
206206
n, err := strconv.ParseInt(output, 10, 64)
@@ -213,7 +213,7 @@ func GetFSSizeInGb(instance *remote.InstanceInfo, mountPath string) (int64, erro
213213
func GetBlockSizeInGb(instance *remote.InstanceInfo, devicePath string) (int64, error) {
214214
output, err := instance.SSH("blockdev", "--getsize64", devicePath)
215215
if err != nil {
216-
return -1, fmt.Errorf("failed to get size of path %s. Output: %v, error: %v", devicePath, output, err)
216+
return -1, fmt.Errorf("failed to get size of path %s. Output: %v, error: %v", devicePath, output, err.Error())
217217
}
218218
n, err := strconv.ParseInt(strings.TrimSpace(output), 10, 64)
219219
if err != nil {
@@ -225,31 +225,31 @@ func GetBlockSizeInGb(instance *remote.InstanceInfo, devicePath string) (int64,
225225
func Symlink(instance *remote.InstanceInfo, src, dest string) error {
226226
output, err := instance.SSH("ln", "-s", src, dest)
227227
if err != nil {
228-
return fmt.Errorf("failed to symlink from %s to %s. Output: %v, errror: %v", src, dest, output, err)
228+
return fmt.Errorf("failed to symlink from %s to %s. Output: %v, errror: %v", src, dest, output, err.Error())
229229
}
230230
return nil
231231
}
232232

233233
func RmAll(instance *remote.InstanceInfo, filePath string) error {
234234
output, err := instance.SSH("rm", "-rf", filePath)
235235
if err != nil {
236-
return fmt.Errorf("failed to delete all %s. Output: %v, errror: %v", filePath, output, err)
236+
return fmt.Errorf("failed to delete all %s. Output: %v, errror: %v", filePath, output, err.Error())
237237
}
238238
return nil
239239
}
240240

241241
func MkdirAll(instance *remote.InstanceInfo, dir string) error {
242242
output, err := instance.SSH("mkdir", "-p", dir)
243243
if err != nil {
244-
return fmt.Errorf("failed to mkdir -p %s. Output: %v, errror: %v", dir, output, err)
244+
return fmt.Errorf("failed to mkdir -p %s. Output: %v, errror: %v", dir, output, err.Error())
245245
}
246246
return nil
247247
}
248248

249249
func CopyFile(instance *remote.InstanceInfo, src, dest string) error {
250250
output, err := instance.SSH("cp", src, dest)
251251
if err != nil {
252-
return fmt.Errorf("failed to copy %s to %s. Output: %v, errror: %v", src, dest, output, err)
252+
return fmt.Errorf("failed to copy %s to %s. Output: %v, errror: %v", src, dest, output, err.Error())
253253
}
254254
return nil
255255
}
@@ -273,7 +273,7 @@ func ValidateLogicalLinkIsDisk(instance *remote.InstanceInfo, link, diskName str
273273

274274
devFsPath, err := instance.SSH("find", link, "-printf", "'%l'")
275275
if err != nil {
276-
return false, fmt.Errorf("failed to find symbolic link for %s. Output: %v, errror: %v", link, devFsPath, err)
276+
return false, fmt.Errorf("failed to find symbolic link for %s. Output: %v, errror: %v", link, devFsPath, err.Error())
277277
}
278278
if len(devFsPath) == 0 {
279279
return false, nil
@@ -282,7 +282,7 @@ func ValidateLogicalLinkIsDisk(instance *remote.InstanceInfo, link, diskName str
282282
fullDevPath := path.Join("/dev/", string(sdx))
283283
scsiIDOut, err := instance.SSH("/lib/udev_containerized/scsi_id", "--page=0x83", "--whitelisted", fmt.Sprintf("--device=%v", fullDevPath))
284284
if err != nil {
285-
return false, fmt.Errorf("failed to find %s's SCSI ID. Output: %v, errror: %v", devFsPath, scsiIDOut, err)
285+
return false, fmt.Errorf("failed to find %s's SCSI ID. Output: %v, errror: %v", devFsPath, scsiIDOut, err.Error())
286286
}
287287
scsiID := scsiRegex.FindStringSubmatch(scsiIDOut)
288288
if len(scsiID) == 0 {
@@ -296,7 +296,7 @@ func ValidateLogicalLinkIsDisk(instance *remote.InstanceInfo, link, diskName str
296296
fullDevPath := path.Join("/dev/", string(nvmex))
297297
nvmeIDOut, err := instance.SSH("/lib/udev_containerized/google_nvme_id", fmt.Sprintf("-d%v", fullDevPath))
298298
if err != nil {
299-
return false, fmt.Errorf("failed to find %s's NVME ID. Output: %v, errror: %v", devFsPath, nvmeIDOut, err)
299+
return false, fmt.Errorf("failed to find %s's NVME ID. Output: %v, errror: %v", devFsPath, nvmeIDOut, err.Error())
300300
}
301301
nvmeID := nvmeSerialRegex.FindStringSubmatch(nvmeIDOut)
302302
if len(nvmeID) == 0 {

Diff for: test/k8s-integration/cluster.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func clusterDownGKE(gceZone, gceRegion string) error {
5454
locationArg, locationVal, "--quiet")
5555
err = runCommand("Bringing Down E2E Cluster on GKE", cmd)
5656
if err != nil {
57-
return fmt.Errorf("failed to bring down kubernetes e2e cluster on gke: %v", err)
57+
return fmt.Errorf("failed to bring down kubernetes e2e cluster on gke: %v", err.Error())
5858
}
5959
return nil
6060
}
@@ -126,7 +126,7 @@ func clusterUpGCE(k8sDir, gceZone string, numNodes int, numWindowsNodes int, ima
126126
cmd.Env = os.Environ()
127127
err = runCommand("Starting E2E Cluster on GCE", cmd)
128128
if err != nil {
129-
return fmt.Errorf("failed to bring up kubernetes e2e cluster on gce: %v", err)
129+
return fmt.Errorf("failed to bring up kubernetes e2e cluster on gce: %v", err.Error())
130130
}
131131

132132
return nil
@@ -170,7 +170,7 @@ func clusterUpGKE(gceZone, gceRegion string, numNodes int, numWindowsNodes int,
170170
fmt.Sprintf("name=%s", *gkeTestClusterName)).CombinedOutput()
171171

172172
if err != nil {
173-
return fmt.Errorf("failed to check for previous test cluster: %v %s", err, out)
173+
return fmt.Errorf("failed to check for previous test cluster: %v %s", err.Error(), out)
174174
}
175175
if len(out) > 0 {
176176
klog.Infof("Detected previous cluster %s. Deleting so a new one can be created...", *gkeTestClusterName)
@@ -203,7 +203,7 @@ func clusterUpGKE(gceZone, gceRegion string, numNodes int, numWindowsNodes int,
203203
cmd = exec.Command("gcloud", cmdParams...)
204204
err = runCommand("Starting E2E Cluster on GKE", cmd)
205205
if err != nil {
206-
return fmt.Errorf("failed to bring up kubernetes e2e cluster on gke: %v", err)
206+
return fmt.Errorf("failed to bring up kubernetes e2e cluster on gke: %v", err.Error())
207207
}
208208

209209
// Because gcloud cannot disable addons on cluster create, the deployment has
@@ -216,7 +216,7 @@ func clusterUpGKE(gceZone, gceRegion string, numNodes int, numWindowsNodes int,
216216
"--update-addons", "GcePersistentDiskCsiDriver=DISABLED")
217217
err = runCommand("Updating E2E Cluster on GKE to disable driver deployment", cmd)
218218
if err != nil {
219-
return fmt.Errorf("failed to update kubernetes e2e cluster on gke: %v", err)
219+
return fmt.Errorf("failed to update kubernetes e2e cluster on gke: %v", err.Error())
220220
}
221221
}
222222

@@ -245,15 +245,15 @@ func downloadKubernetesSource(pkgDir, k8sIoDir, kubeVersion string) error {
245245
klog.Info("cloning k8s master")
246246
out, err := exec.Command("git", "clone", "https://github.com/kubernetes/kubernetes", k8sDir).CombinedOutput()
247247
if err != nil {
248-
return fmt.Errorf("failed to clone kubernetes master: %s, err: %v", out, err)
248+
return fmt.Errorf("failed to clone kubernetes master: %s, err: %v", out, err.Error())
249249
}
250250
} else {
251251
// Shallow clone of a release branch.
252252
vKubeVersion := "v" + kubeVersion
253253
klog.Infof("shallow clone of k8s %s", vKubeVersion)
254254
out, err := exec.Command("git", "clone", "--depth", "1", "https://github.com/kubernetes/kubernetes", k8sDir).CombinedOutput()
255255
if err != nil {
256-
return fmt.Errorf("failed to clone kubernetes %s: %s, err: %v", vKubeVersion, out, err)
256+
return fmt.Errorf("failed to clone kubernetes %s: %s, err: %v", vKubeVersion, out, err.Error())
257257
}
258258
}
259259
return nil
@@ -289,7 +289,7 @@ func getGKEKubeTestArgs(gceZone, gceRegion, imageType string, useKubetest2 bool)
289289
cmd := exec.Command("gcloud", "config", "get-value", "project")
290290
project, err := cmd.Output()
291291
if err != nil {
292-
return nil, fmt.Errorf("failed to get current project: %v", err)
292+
return nil, fmt.Errorf("failed to get current project: %v", err.Error())
293293
}
294294

295295
// kubetest arguments
@@ -353,7 +353,7 @@ func getNormalizedVersion(kubeVersion, gkeVersion string) (string, error) {
353353
func getKubeClusterVersion() (string, error) {
354354
out, err := exec.Command("kubectl", "version", "-o=json").Output()
355355
if err != nil {
356-
return "", fmt.Errorf("failed to obtain cluster version, error: %v; output was %s", err, out)
356+
return "", fmt.Errorf("failed to obtain cluster version, error: %v; output was %s", err.Error(), out)
357357
}
358358
type version struct {
359359
ClientVersion *apimachineryversion.Info `json:"clientVersion,omitempty" yaml:"clientVersion,omitempty"`
@@ -363,7 +363,7 @@ func getKubeClusterVersion() (string, error) {
363363
var v version
364364
err = json.Unmarshal(out, &v)
365365
if err != nil {
366-
return "", fmt.Errorf("Failed to parse kubectl version output, error: %v", err)
366+
return "", fmt.Errorf("Failed to parse kubectl version output, error: %v", err.Error())
367367
}
368368

369369
return v.ServerVersion.GitVersion, nil
@@ -401,11 +401,11 @@ func getKubeClient() (kubernetes.Interface, error) {
401401
}
402402
config, err := clientcmd.BuildConfigFromFlags("", kubeConfig)
403403
if err != nil {
404-
return nil, fmt.Errorf("failed to create config: %v", err)
404+
return nil, fmt.Errorf("failed to create config: %v", err.Error())
405405
}
406406
kubeClient, err := kubernetes.NewForConfig(config)
407407
if err != nil {
408-
return nil, fmt.Errorf("failed to create client: %v", err)
408+
return nil, fmt.Errorf("failed to create client: %v", err.Error())
409409
}
410410
return kubeClient, nil
411411
}

0 commit comments

Comments
 (0)