Browse code

Windows CI: Address simple failures in TestPS*

Signed-off-by: John Howard <jhoward@microsoft.com>

John Howard authored on 2016/01/23 13:44:46
Showing 1 changed files
... ...
@@ -16,7 +16,16 @@ import (
16 16
 	"github.com/go-check/check"
17 17
 )
18 18
 
19
+var sleepCmd = "/bin/sleep"
20
+
21
+func init() {
22
+	if daemonPlatform == "windows" {
23
+		sleepCmd = "sleep"
24
+	}
25
+}
26
+
19 27
 func (s *DockerSuite) TestPsListContainersBase(c *check.C) {
28
+	// Problematic on Windows as busybox doesn't support top
20 29
 	testRequires(c, DaemonIsLinux)
21 30
 	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
22 31
 	firstID := strings.TrimSpace(out)
... ...
@@ -127,6 +136,7 @@ func assertContainerList(out string, expected []string) bool {
127 127
 }
128 128
 
129 129
 func (s *DockerSuite) TestPsListContainersSize(c *check.C) {
130
+	// Problematic on Windows as it doesn't report the size correctly @swernli
130 131
 	testRequires(c, DaemonIsLinux)
131 132
 	dockerCmd(c, "run", "-d", "busybox", "echo", "hello")
132 133
 
... ...
@@ -168,8 +178,6 @@ func (s *DockerSuite) TestPsListContainersSize(c *check.C) {
168 168
 }
169 169
 
170 170
 func (s *DockerSuite) TestPsListContainersFilterStatus(c *check.C) {
171
-	testRequires(c, DaemonIsLinux)
172
-
173 171
 	// start exited container
174 172
 	out, _ := dockerCmd(c, "run", "-d", "busybox")
175 173
 	firstID := strings.TrimSpace(out)
... ...
@@ -193,26 +201,28 @@ func (s *DockerSuite) TestPsListContainersFilterStatus(c *check.C) {
193 193
 	out, _, _ = dockerCmdWithTimeout(time.Second*60, "ps", "-a", "-q", "--filter=status=rubbish")
194 194
 	c.Assert(out, checker.Contains, "Unrecognised filter value for status", check.Commentf("Expected error response due to invalid status filter output: %q", out))
195 195
 
196
-	// pause running container
197
-	out, _ = dockerCmd(c, "run", "-itd", "busybox")
198
-	pausedID := strings.TrimSpace(out)
199
-	dockerCmd(c, "pause", pausedID)
200
-	// make sure the container is unpaused to let the daemon stop it properly
201
-	defer func() { dockerCmd(c, "unpause", pausedID) }()
202
-
203
-	out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter=status=paused")
204
-	containerOut = strings.TrimSpace(out)
205
-	c.Assert(containerOut, checker.Equals, pausedID)
196
+	// Windows doesn't support pausing of containers
197
+	if daemonPlatform != "windows" {
198
+		// pause running container
199
+		out, _ = dockerCmd(c, "run", "-itd", "busybox")
200
+		pausedID := strings.TrimSpace(out)
201
+		dockerCmd(c, "pause", pausedID)
202
+		// make sure the container is unpaused to let the daemon stop it properly
203
+		defer func() { dockerCmd(c, "unpause", pausedID) }()
204
+
205
+		out, _ = dockerCmd(c, "ps", "--no-trunc", "-q", "--filter=status=paused")
206
+		containerOut = strings.TrimSpace(out)
207
+		c.Assert(containerOut, checker.Equals, pausedID)
208
+	}
206 209
 }
207 210
 
208 211
 func (s *DockerSuite) TestPsListContainersFilterID(c *check.C) {
209
-	testRequires(c, DaemonIsLinux)
210 212
 	// start container
211 213
 	out, _ := dockerCmd(c, "run", "-d", "busybox")
212 214
 	firstID := strings.TrimSpace(out)
213 215
 
214 216
 	// start another container
215
-	dockerCmd(c, "run", "-d", "busybox", "top")
217
+	dockerCmd(c, "run", "-d", "busybox", sleepCmd, "60")
216 218
 
217 219
 	// filter containers by id
218 220
 	out, _ = dockerCmd(c, "ps", "-a", "-q", "--filter=id="+firstID)
... ...
@@ -222,13 +232,12 @@ func (s *DockerSuite) TestPsListContainersFilterID(c *check.C) {
222 222
 }
223 223
 
224 224
 func (s *DockerSuite) TestPsListContainersFilterName(c *check.C) {
225
-	testRequires(c, DaemonIsLinux)
226 225
 	// start container
227 226
 	out, _ := dockerCmd(c, "run", "-d", "--name=a_name_to_match", "busybox")
228 227
 	firstID := strings.TrimSpace(out)
229 228
 
230 229
 	// start another container
231
-	dockerCmd(c, "run", "-d", "--name=b_name_to_match", "busybox", "top")
230
+	dockerCmd(c, "run", "-d", "--name=b_name_to_match", "busybox", sleepCmd, "60")
232 231
 
233 232
 	// filter containers by name
234 233
 	out, _ = dockerCmd(c, "ps", "-a", "-q", "--filter=name=a_name_to_match")
... ...
@@ -246,7 +255,6 @@ func (s *DockerSuite) TestPsListContainersFilterName(c *check.C) {
246 246
 // - Run containers for each of those image (busybox, images_ps_filter_test1, images_ps_filter_test2)
247 247
 // - Filter them out :P
248 248
 func (s *DockerSuite) TestPsListContainersFilterAncestorImage(c *check.C) {
249
-	testRequires(c, DaemonIsLinux)
250 249
 	// Build images
251 250
 	imageName1 := "images_ps_filter_test1"
252 251
 	imageID1, err := buildImage(imageName1,
... ...
@@ -342,7 +350,6 @@ func checkPsAncestorFilterOutput(c *check.C, out string, filterName string, expe
342 342
 }
343 343
 
344 344
 func (s *DockerSuite) TestPsListContainersFilterLabel(c *check.C) {
345
-	testRequires(c, DaemonIsLinux)
346 345
 	// start container
347 346
 	out, _ := dockerCmd(c, "run", "-d", "-l", "match=me", "-l", "second=tag", "busybox")
348 347
 	firstID := strings.TrimSpace(out)
... ...
@@ -379,8 +386,9 @@ func (s *DockerSuite) TestPsListContainersFilterLabel(c *check.C) {
379 379
 }
380 380
 
381 381
 func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
382
+	// TODO Windows CI: Enable for TP5. Fails on TP4
382 383
 	testRequires(c, DaemonIsLinux)
383
-	dockerCmd(c, "run", "-d", "--name", "top", "busybox", "top")
384
+	dockerCmd(c, "run", "-d", "--name", "sleep", "busybox", sleepCmd, "60")
384 385
 
385 386
 	dockerCmd(c, "run", "--name", "zero1", "busybox", "true")
386 387
 	firstZero, err := getIDByName("zero1")
... ...
@@ -417,16 +425,17 @@ func (s *DockerSuite) TestPsListContainersFilterExited(c *check.C) {
417 417
 }
418 418
 
419 419
 func (s *DockerSuite) TestPsRightTagName(c *check.C) {
420
+	// TODO Investigate further why this fails on Windows to Windows CI
420 421
 	testRequires(c, DaemonIsLinux)
421 422
 	tag := "asybox:shmatest"
422 423
 	dockerCmd(c, "tag", "busybox", tag)
423 424
 
424 425
 	var id1 string
425
-	out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
426
+	out, _ := dockerCmd(c, "run", "-d", "busybox", sleepCmd, "60")
426 427
 	id1 = strings.TrimSpace(string(out))
427 428
 
428 429
 	var id2 string
429
-	out, _ = dockerCmd(c, "run", "-d", tag, "top")
430
+	out, _ = dockerCmd(c, "run", "-d", tag, sleepCmd, "60")
430 431
 	id2 = strings.TrimSpace(string(out))
431 432
 
432 433
 	var imageID string
... ...
@@ -434,7 +443,7 @@ func (s *DockerSuite) TestPsRightTagName(c *check.C) {
434 434
 	imageID = strings.TrimSpace(string(out))
435 435
 
436 436
 	var id3 string
437
-	out, _ = dockerCmd(c, "run", "-d", imageID, "top")
437
+	out, _ = dockerCmd(c, "run", "-d", imageID, sleepCmd, "60")
438 438
 	id3 = strings.TrimSpace(string(out))
439 439
 
440 440
 	out, _ = dockerCmd(c, "ps", "--no-trunc")
... ...
@@ -458,9 +467,10 @@ func (s *DockerSuite) TestPsRightTagName(c *check.C) {
458 458
 }
459 459
 
460 460
 func (s *DockerSuite) TestPsLinkedWithNoTrunc(c *check.C) {
461
+	// Problematic on Windows as it doesn't support links as of Jan 2016
461 462
 	testRequires(c, DaemonIsLinux)
462
-	dockerCmd(c, "run", "--name=first", "-d", "busybox", "top")
463
-	dockerCmd(c, "run", "--name=second", "--link=first:first", "-d", "busybox", "top")
463
+	dockerCmd(c, "run", "--name=first", "-d", "busybox", sleepCmd, "60")
464
+	dockerCmd(c, "run", "--name=second", "--link=first:first", "-d", "busybox", sleepCmd, "60")
464 465
 
465 466
 	out, _ := dockerCmd(c, "ps", "--no-trunc")
466 467
 	lines := strings.Split(strings.TrimSpace(string(out)), "\n")
... ...
@@ -476,6 +486,7 @@ func (s *DockerSuite) TestPsLinkedWithNoTrunc(c *check.C) {
476 476
 }
477 477
 
478 478
 func (s *DockerSuite) TestPsGroupPortRange(c *check.C) {
479
+	// Problematic on Windows as it doesn't support port ranges as of Jan 2016
479 480
 	testRequires(c, DaemonIsLinux)
480 481
 	portRange := "3800-3900"
481 482
 	dockerCmd(c, "run", "-d", "--name", "porttest", "-p", portRange+":"+portRange, "busybox", "top")
... ...
@@ -487,6 +498,7 @@ func (s *DockerSuite) TestPsGroupPortRange(c *check.C) {
487 487
 }
488 488
 
489 489
 func (s *DockerSuite) TestPsWithSize(c *check.C) {
490
+	// Problematic on Windows as it doesn't report the size correctly @swernli
490 491
 	testRequires(c, DaemonIsLinux)
491 492
 	dockerCmd(c, "run", "-d", "--name", "sizetest", "busybox", "top")
492 493
 
... ...
@@ -495,7 +507,6 @@ func (s *DockerSuite) TestPsWithSize(c *check.C) {
495 495
 }
496 496
 
497 497
 func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) {
498
-	testRequires(c, DaemonIsLinux)
499 498
 	// create a container
500 499
 	out, _ := dockerCmd(c, "create", "busybox")
501 500
 	cID := strings.TrimSpace(out)
... ...
@@ -526,6 +537,7 @@ func (s *DockerSuite) TestPsListContainersFilterCreated(c *check.C) {
526 526
 }
527 527
 
528 528
 func (s *DockerSuite) TestPsFormatMultiNames(c *check.C) {
529
+	// Problematic on Windows as it doesn't support link as of Jan 2016
529 530
 	testRequires(c, DaemonIsLinux)
530 531
 	//create 2 containers and link them
531 532
 	dockerCmd(c, "run", "--name=child", "-d", "busybox", "top")
... ...
@@ -554,19 +566,17 @@ func (s *DockerSuite) TestPsFormatMultiNames(c *check.C) {
554 554
 }
555 555
 
556 556
 func (s *DockerSuite) TestPsFormatHeaders(c *check.C) {
557
-	testRequires(c, DaemonIsLinux)
558 557
 	// make sure no-container "docker ps" still prints the header row
559 558
 	out, _ := dockerCmd(c, "ps", "--format", "table {{.ID}}")
560 559
 	c.Assert(out, checker.Equals, "CONTAINER ID\n", check.Commentf(`Expected 'CONTAINER ID\n', got %v`, out))
561 560
 
562 561
 	// verify that "docker ps" with a container still prints the header row also
563
-	dockerCmd(c, "run", "--name=test", "-d", "busybox", "top")
562
+	dockerCmd(c, "run", "--name=test", "-d", "busybox", sleepCmd, "60")
564 563
 	out, _ = dockerCmd(c, "ps", "--format", "table {{.Names}}")
565 564
 	c.Assert(out, checker.Equals, "NAMES\ntest\n", check.Commentf(`Expected 'NAMES\ntest\n', got %v`, out))
566 565
 }
567 566
 
568 567
 func (s *DockerSuite) TestPsDefaultFormatAndQuiet(c *check.C) {
569
-	testRequires(c, DaemonIsLinux)
570 568
 	config := `{
571 569
 		"psFormat": "default {{ .ID }}"
572 570
 }`
... ...
@@ -577,7 +587,7 @@ func (s *DockerSuite) TestPsDefaultFormatAndQuiet(c *check.C) {
577 577
 	err = ioutil.WriteFile(filepath.Join(d, "config.json"), []byte(config), 0644)
578 578
 	c.Assert(err, checker.IsNil)
579 579
 
580
-	out, _ := dockerCmd(c, "run", "--name=test", "-d", "busybox", "top")
580
+	out, _ := dockerCmd(c, "run", "--name=test", "-d", "busybox", sleepCmd, "60")
581 581
 	id := strings.TrimSpace(out)
582 582
 
583 583
 	out, _ = dockerCmd(c, "--config", d, "ps", "-q")
... ...
@@ -586,8 +596,8 @@ func (s *DockerSuite) TestPsDefaultFormatAndQuiet(c *check.C) {
586 586
 
587 587
 // Test for GitHub issue #12595
588 588
 func (s *DockerSuite) TestPsImageIDAfterUpdate(c *check.C) {
589
+	// TODO: Investigate why this fails on Windows to Windows CI further.
589 590
 	testRequires(c, DaemonIsLinux)
590
-
591 591
 	originalImageName := "busybox:TestPsImageIDAfterUpdate-original"
592 592
 	updatedImageName := "busybox:TestPsImageIDAfterUpdate-updated"
593 593
 
... ...
@@ -598,7 +608,7 @@ func (s *DockerSuite) TestPsImageIDAfterUpdate(c *check.C) {
598 598
 	originalImageID, err := getIDByName(originalImageName)
599 599
 	c.Assert(err, checker.IsNil)
600 600
 
601
-	runCmd = exec.Command(dockerBinary, "run", "-d", originalImageName, "top")
601
+	runCmd = exec.Command(dockerBinary, "run", "-d", originalImageName, sleepCmd, "60")
602 602
 	out, _, err = runCommandWithOutput(runCmd)
603 603
 	c.Assert(err, checker.IsNil)
604 604
 	containerID := strings.TrimSpace(out)