Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit e9239ab

Browse files
committed
[integration-test] clear resource before test
1 parent d2c7d5b commit e9239ab

File tree

7 files changed

+54
-8
lines changed

7 files changed

+54
-8
lines changed

integration-cli/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ $ docker run -it --rm \
345345
$ docker run -it --rm \
346346
-e ACCESS_KEY=${ACCESS_KEY} \
347347
-e SECRET_KEY=${SECRET_KEY} \
348-
-e BRANCH="#221" \
348+
-e BRANCH="#221" \
349349
hyperhq/hypercli-auto-test:qa go test -check.f TestCli -timeout 180m
350350
351351

integration-cli/check_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,23 @@ func (s *DockerSuite) TearDownTest(c *check.C) {
3535
deleteAllImages()
3636
deleteAllSnapshots()
3737
deleteAllVolumes()
38+
deleteAllFips()
3839
//deleteAllNetworks()
3940
}
4041

4142
func init() {
4243
check.Suite(&DockerRegistrySuite{
4344
ds: &DockerSuite{},
4445
})
46+
47+
fmt.Printf("INFO: clear resources(containers, images, snapshots, volumes, fips)\n")
48+
deleteAllContainers()
49+
deleteAllImages()
50+
deleteAllSnapshots()
51+
deleteAllVolumes()
52+
deleteAllFips()
53+
54+
fmt.Println("INFO: finish init")
4555
}
4656

4757
type DockerRegistrySuite struct {

integration-cli/docker_utils.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ func init() {
114114
if os.Getenv("DOCKER_HOST") != "" {
115115
flag_host = "--host=" + os.Getenv("DOCKER_HOST")
116116
}
117-
fmt.Println("finish init")
118117
}
119118

120119
// Daemon represents a Docker daemon for the testing framework.
@@ -845,6 +844,44 @@ func deleteAllImages() error {
845844
return nil
846845
}
847846

847+
func deleteAllFips() error {
848+
fips, err := getAllFips()
849+
if err != nil {
850+
return err
851+
}
852+
853+
for _, v := range strings.Split(fips,"\n") {
854+
if v == "" {
855+
continue
856+
}
857+
fip := strings.Trim(v, " ")
858+
releaseFipCmd := exec.Command(dockerBinary, flag_host, "fip", "release", fip)
859+
out, exitCode, err := runCommandWithOutput(releaseFipCmd)
860+
if exitCode != 0 && err == nil {
861+
err = fmt.Errorf("failed to release fip: %v\n", out)
862+
return err
863+
}
864+
}
865+
return nil
866+
}
867+
868+
func getAllFips() (string, error) {
869+
//load via pipe
870+
getFipsCmd := exec.Command(dockerBinary, flag_host, "fip", "ls")
871+
grepCmd := exec.Command("grep", "-v", "^Floating IP")
872+
873+
getFipOut, err := getFipsCmd.StdoutPipe()
874+
getFipsCmd.Start()
875+
876+
grepCmd.Stdin = getFipOut
877+
output, err := grepCmd.Output()
878+
879+
if err != nil {
880+
err = fmt.Errorf("failed to get a list of fips: %v\n", output)
881+
}
882+
return string(output), err
883+
}
884+
848885
//status only support : created, restarting, running, exited (https://github.com/getdvm/hyper-api-router/blob/master/pkg/apiserver/router/local/container.go#L204)
849886
/*
850887
func getPausedContainers() (string, error) {

integration-cli/hyper_cli_links_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ func (s *DockerSuite) TestCliLinksEnvs(c *check.C) {
192192
testRequires(c, DaemonIsLinux)
193193
printTestCaseName()
194194
defer printTestDuration(time.Now())
195+
pullImageIfNotExist("busybox")
195196
dockerCmd(c, "run", "-d", "-e", "e1=", "-e", "e2=v2", "-e", "e3=v3=v3", "--name=first", "busybox", "top")
196197
out, _ := dockerCmd(c, "run", "--name=second", "--link=first:first", "busybox", "env")
197198
/* FIXME

integration-cli/hyper_cli_logs_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func (s *DockerSuite) TestCliLogsSince(c *check.C) {
208208
pullImageIfNotExist("busybox")
209209
name := "testlogssince"
210210
dockerCmd(c, "run", "--name="+name, "-d", "busybox", "/bin/sh", "-c", "for i in $(seq 1 30); do sleep 2; echo log$i; done")
211-
time.Sleep(5*time.Second)
211+
time.Sleep(10*time.Second)
212212

213213
out, _ := dockerCmd(c, "logs", "-t", name)
214214

@@ -249,7 +249,7 @@ func (s *DockerSuite) TestCliLogsSinceFutureFollow(c *check.C) {
249249
testRequires(c, DaemonIsLinux)
250250
pullImageIfNotExist("busybox")
251251
out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", `for i in $(seq 1 50); do date +%s; sleep 1; done`)
252-
time.Sleep(5 * time.Second)
252+
time.Sleep(20 * time.Second)
253253
id := strings.TrimSpace(out)
254254

255255
now := daemonTime(c).Unix()

integration-cli/hyper_cli_ps_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ func (s *DockerSuite) TestCliPsListContainersBase(c *check.C) {
117117
}
118118

119119
func assertContainerList(out string, expected []string) bool {
120-
printTestCaseName()
121-
defer printTestDuration(time.Now())
122120

123121
lines := strings.Split(strings.Trim(out, "\n "), "\n")
124122
if len(lines)-1 != len(expected) {

integration-cli/hyper_cli_run_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,8 +1110,8 @@ func (s *DockerSuite) TestCliRunRestartMaxRetries(c *check.C) {
11101110
printTestCaseName()
11111111
defer printTestDuration(time.Now())
11121112
pullImageIfNotExist("busybox")
1113-
out, _ := dockerCmd(c, "run", "-d", "--restart=on-failure:3", "busybox", "sh", "-c", "sleep 15; false")
1114-
timeout := 90 * time.Second
1113+
out, _ := dockerCmd(c, "run", "-d", "--restart=on-failure:3", "busybox", "sh", "-c", "sleep 20; false")
1114+
timeout := 100 * time.Second
11151115
if daemonPlatform == "windows" {
11161116
timeout = 45 * time.Second
11171117
}

0 commit comments

Comments
 (0)