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

Commit 1001de4

Browse files
committed
[integration-test] fix test case issue
1 parent f43e51a commit 1001de4

13 files changed

+420
-294
lines changed

integration-cli/README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Integration test for hyper cli
33

44
> functional test for hyper cli
55
> use apirouter service on packet(dev env) as backend
6-
76
<!-- TOC depthFrom:1 depthTo:6 withLinks:1 updateOnSave:1 orderedList:0 -->
87
98
- [Project status](#project-status)
@@ -25,6 +24,7 @@ Integration test for hyper cli
2524
- [Run test on localhost](#run-test-on-localhost)
2625
- [prepare](#prepare)
2726
- [run test case](#run-test-case)
27+
- [test case name](#test-case-name)
2828

2929
<!-- /TOC -->
3030

@@ -252,3 +252,33 @@ $ ./util.sh test -check.f TestCliLoadFromLocalTar
252252
// combined use
253253
$ ./util.sh test -check.f 'TestCliLoadFromLocalTarEmpty|TestCliLoadFromLocalPullAndLoad' -timeout 20m
254254
```
255+
256+
### test case name
257+
258+
- TestCliConfig
259+
- TestCliCreate
260+
- TestCliExec
261+
- TestCliFip
262+
- TestCliHelp
263+
- TestCliHistory
264+
- TestCliInfo
265+
- TestCliInspect
266+
- TestCliKill
267+
- TestCliLinks
268+
- TestCliLoadFromUrl
269+
- TestCliLoadFromLocal
270+
- TestCliLogin
271+
- TestCliLogs
272+
- TestCliPort
273+
- TestCliPs
274+
- TestCliPull
275+
- TestCliRename
276+
- TestCliRestart
277+
- TestCliRmi
278+
- TestCliRm
279+
- TestCliRun
280+
- TestCliSearch
281+
- TestCliSnapshot
282+
- TestCliStart
283+
- TestCliVersion
284+
- TestCliVolume
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"github.com/docker/docker/pkg/integration/checker"
6+
"github.com/go-check/check"
7+
"os"
8+
"time"
9+
)
10+
11+
//Prerequisite: update image balance to 2 in tenant collection of hypernetes in mongodb
12+
//db.tenant.update({tenantid:"<tenant_id>"},{$set:{"resourceinfo.balance.images":2}})
13+
func (s *DockerSuite) TestCliLoadUrlBasicFromPublicURLWithQuota(c *check.C) {
14+
printTestCaseName()
15+
defer printTestDuration(time.Now())
16+
testRequires(c, DaemonIsLinux)
17+
18+
deleteAllImages()
19+
20+
helloworldURL := "http://image-tarball.s3.amazonaws.com/test/public/helloworld.tar"
21+
multiImgURL := "http://image-tarball.s3.amazonaws.com/test/public/busybox_alpine.tar"
22+
ubuntuURL := "http://image-tarball.s3.amazonaws.com/test/public/ubuntu.tar.gz"
23+
//exceedQuotaMsg := "Exceeded quota, please either delete images, or email support@hyper.sh to request increased quota"
24+
exceedQuotaMsg := "you do not have enough quota"
25+
26+
///// [init] /////
27+
// balance 3, images 0
28+
out, _ := dockerCmd(c, "info")
29+
c.Assert(out, checker.Contains, "Images: 0")
30+
31+
///// [step 1] load new hello-world image /////
32+
// balance 3 -> 2, image: 0 -> 1
33+
output, exitCode, err := dockerCmdWithError("load", "-i", helloworldURL)
34+
c.Assert(output, checker.Contains, "has been loaded.")
35+
c.Assert(exitCode, checker.Equals, 0)
36+
c.Assert(err, checker.IsNil)
37+
38+
checkImage(c, true, "hello-world")
39+
40+
out, _ = dockerCmd(c, "info")
41+
c.Assert(out, checker.Contains, "Images: 1")
42+
43+
///// [step 2] load hello-world image again /////
44+
// balance 2 -> 2, image 1 -> 1
45+
output, exitCode, err = dockerCmdWithError("load", "-i", helloworldURL)
46+
c.Assert(output, checker.Contains, "has been loaded.")
47+
c.Assert(exitCode, checker.Equals, 0)
48+
c.Assert(err, checker.IsNil)
49+
50+
checkImage(c, true, "hello-world")
51+
52+
out, _ = dockerCmd(c, "info")
53+
c.Assert(out, checker.Contains, "Images: 1")
54+
55+
///// [step 3] load multiple image(busybox+alpine) /////
56+
// balance 2 -> 2, image 1 -> 1
57+
output, exitCode, err = dockerCmdWithError("load", "-i", multiImgURL)
58+
c.Assert(output, checker.Contains, exceedQuotaMsg)
59+
c.Assert(exitCode, checker.Equals, 1)
60+
c.Assert(err, checker.NotNil)
61+
62+
checkImage(c, false, "busybox")
63+
checkImage(c, false, "alpine")
64+
65+
out, _ = dockerCmd(c, "info")
66+
c.Assert(out, checker.Contains, "Images: 1")
67+
68+
///// [step 4] load new ubuntu image /////
69+
// balance 2 -> 1, image 1 -> 2
70+
output, exitCode, err = dockerCmdWithError("load", "-i", ubuntuURL)
71+
c.Assert(output, checker.Contains, "has been loaded.")
72+
c.Assert(exitCode, checker.Equals, 0)
73+
c.Assert(err, checker.IsNil)
74+
75+
checkImage(c, true, "ubuntu")
76+
77+
out, _ = dockerCmd(c, "info")
78+
c.Assert(out, checker.Contains, "Images: 2")
79+
80+
///// [step 5] remove hello-world image /////
81+
// balance 1 -> 2, image 2 -> 1
82+
images, _ := dockerCmd(c, "rmi", "-f", "hello-world")
83+
c.Assert(images, checker.Contains, "Untagged: hello-world:latest")
84+
85+
checkImage(c, false, "hello-world")
86+
87+
out, _ = dockerCmd(c, "info")
88+
c.Assert(out, checker.Contains, "Images: 1")
89+
90+
///// [step 6] remove busybox and ubuntu image /////
91+
// balance 2 -> 3, image 1 -> 0
92+
images, _ = dockerCmd(c, "rmi", "-f", "ubuntu:latest")
93+
c.Assert(images, checker.Contains, "Untagged: ubuntu:latest")
94+
95+
checkImage(c, false, "ubuntu")
96+
97+
out, _ = dockerCmd(c, "info")
98+
c.Assert(out, checker.Contains, "Images: 0")
99+
100+
///// [step 7] load multiple image(busybox+alpine) again /////
101+
// balance 3 -> 0, image 0 -> 3
102+
output, exitCode, err = dockerCmdWithError("load", "-i", multiImgURL)
103+
c.Assert(output, checker.Contains, "has been loaded.")
104+
c.Assert(exitCode, checker.Equals, 0)
105+
c.Assert(err, checker.IsNil)
106+
107+
checkImage(c, true, "busybox")
108+
checkImage(c, true, "alpine")
109+
110+
out, _ = dockerCmd(c, "info")
111+
c.Assert(out, checker.Contains, "Images: 3")
112+
}
113+
114+
func (s *DockerSuite) TestCliLoadUrlBasicFromAWSS3PreSignedURL(c *check.C) {
115+
printTestCaseName()
116+
defer printTestDuration(time.Now())
117+
testRequires(c, DaemonIsLinux)
118+
119+
deleteAllImages()
120+
121+
s3Region := "us-west-1"
122+
s3Bucket := "image-tarball"
123+
s3Key := "test/private/cirros.tar"
124+
preSignedUrl, err_ := generateS3PreSignedURL(s3Region, s3Bucket, s3Key)
125+
c.Assert(err_, checker.IsNil)
126+
time.Sleep(1 * time.Second)
127+
128+
output, err := dockerCmd(c, "load", "-i", preSignedUrl)
129+
if err != 0 {
130+
fmt.Printf("preSignedUrl:[%v]\n", preSignedUrl)
131+
fmt.Printf("output:\n%v\n", output)
132+
}
133+
c.Assert(output, checker.Contains, "has been loaded.")
134+
c.Assert(err, checker.Equals, 0)
135+
136+
checkImage(c, true, "cirros")
137+
}
138+
139+
func (s *DockerSuite) TestCliLoadUrlBasicFromBasicAuthURL(c *check.C) {
140+
printTestCaseName()
141+
defer printTestDuration(time.Now())
142+
testRequires(c, DaemonIsLinux)
143+
144+
urlWithAuth := os.Getenv("URL_WITH_BASIC_AUTH")
145+
c.Assert(urlWithAuth, checker.NotNil)
146+
147+
dockerCmd(c, "load", "-i", urlWithAuth)
148+
149+
images, _ := dockerCmd(c, "images", "ubuntu")
150+
c.Assert(images, checker.Contains, "ubuntu")
151+
}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
package main
2+
3+
import (
4+
"time"
5+
"github.com/docker/docker/pkg/integration/checker"
6+
"github.com/go-check/check"
7+
"strings"
8+
9+
"gopkg.in/mgo.v2"
10+
"gopkg.in/mgo.v2/bson"
11+
"os"
12+
//"fmt"
13+
)
14+
15+
func (s *DockerSuite) TestCliLoadFromUrlLegacyImageArchiveFileWithQuota(c *check.C) {
16+
printTestCaseName(); defer printTestDuration(time.Now())
17+
testRequires(c, DaemonIsLinux)
18+
19+
imageName := "ubuntu";
20+
legacyImageUrl := "http://image-tarball.s3.amazonaws.com/test/public/old/ubuntu_1.8.tar.gz"
21+
imageUrl := "http://image-tarball.s3.amazonaws.com/test/public/ubuntu.tar.gz"
22+
23+
24+
/////////////////////////////////////////////////////////////////////
25+
checkImageQuota(c, 2)
26+
//load legacy image(saved by docker 1.8)
27+
output, exitCode, err := dockerCmdWithError("load", "-i", legacyImageUrl)
28+
c.Assert(output, checker.Contains, "Starting to download and load the image archive, please wait...\n")
29+
c.Assert(output, checker.Contains, "has been loaded.\n")
30+
c.Assert(exitCode, checker.Equals, 0)
31+
c.Assert(err, checker.IsNil)
32+
33+
output, _ = dockerCmd(c, "images")
34+
c.Assert(output, checker.Contains, imageName)
35+
c.Assert(len(strings.Split(output, "\n")), checker.Equals, 3)
36+
37+
38+
/////////////////////////////////////////////////////////////////////
39+
checkImageQuota(c, 1)
40+
//load new format image(saved by docker 1.10)
41+
output, exitCode, err = dockerCmdWithError("load", "-i", imageUrl)
42+
c.Assert(output, checker.Contains, "Start to download and load the image archive, please wait...\n")
43+
c.Assert(output, checker.Contains, "has been loaded.\n")
44+
c.Assert(exitCode, checker.Equals, 0)
45+
c.Assert(err, checker.IsNil)
46+
47+
output, _ = dockerCmd(c, "images")
48+
c.Assert(output, checker.Contains, imageName)
49+
c.Assert(len(strings.Split(output, "\n")), checker.Equals, 3)
50+
51+
52+
/////////////////////////////////////////////////////////////////////
53+
checkImageQuota(c, 1)
54+
//delete single layer
55+
output, _ = dockerCmd(c, "images", "-q", imageName)
56+
imageId := strings.Split(output, "\n")[0]
57+
c.Assert(imageId, checker.Not(checker.Equals), "")
58+
59+
output, _ = dockerCmd(c, "rmi", "--no-prune", imageId)
60+
c.Assert(output, checker.Contains, "Untagged:")
61+
c.Assert(output, checker.Contains, "Deleted:")
62+
63+
checkImageQuota(c, 1)
64+
65+
output, _ = dockerCmd(c, "images")
66+
c.Assert(output, checker.Contains, "<none>")
67+
c.Assert(len(strings.Split(output, "\n")), checker.Equals, 3)
68+
imageId = strings.Split(output, "\n")[0]
69+
70+
output, _ = dockerCmd(c, "images", "-a")
71+
c.Assert(output, checker.Contains, "<none>")
72+
c.Assert(len(strings.Split(output, "\n")), checker.Equals, 6)
73+
74+
75+
/////////////////////////////////////////////////////////////////////
76+
checkImageQuota(c, 1)
77+
//delete all rest layer
78+
output, _ = dockerCmd(c, "images", "-q")
79+
imageId = strings.Split(output, "\n")[0]
80+
c.Assert(imageId, checker.Not(checker.Equals), "")
81+
82+
output, _ = dockerCmd(c, "rmi", imageId)
83+
c.Assert(output, checker.Contains, "Deleted:")
84+
85+
checkImageQuota(c, 2)
86+
87+
output, _ = dockerCmd(c, "images")
88+
c.Assert(len(strings.Split(output, "\n")), checker.Equals, 2)
89+
90+
output, _ = dockerCmd(c, "images", "-a")
91+
c.Assert(len(strings.Split(output, "\n")), checker.Equals, 2)
92+
}
93+
94+
95+
//func (s *DockerSuite) TestCliLoadFromUrlLegacyCheckImageQuota(c *check.C) {
96+
// printTestCaseName(); defer printTestDuration(time.Now())
97+
// testRequires(c, DaemonIsLinux)
98+
// checkImageQuota(c, 2)
99+
//}
100+
101+
func checkImageQuota(c *check.C, expected int) {
102+
103+
//collection struct: credential
104+
type Credential struct {
105+
TenantId string `bson:"tenantId"`
106+
}
107+
108+
//collection struct: tenant
109+
type Total struct {
110+
Images int `bson:"images"`
111+
}
112+
type Balance struct {
113+
Images int `bson:"images"`
114+
}
115+
type Resourceinfo struct {
116+
Total Total `bson:"total"`
117+
Balance Balance `bson:"balance"`
118+
}
119+
type Tenant struct {
120+
Resourceinfo Resourceinfo `bson:"resourceinfo"`
121+
}
122+
123+
124+
///////////////////////////////////////////
125+
//init connection to mongodb
126+
session, err := mgo.Dial(os.Getenv("MONGODB_URL"))
127+
if err != nil {
128+
panic(err)
129+
}
130+
defer session.Close()
131+
// Optional. Switch the session to a monotonic behavior.
132+
session.SetMode(mgo.Monotonic, true)
133+
db := session.DB("hypernetes")
134+
135+
///////////////////////////////////////////
136+
// query tenantId by accessKey
137+
collection := db.C("credentials")
138+
resultCred := Credential{}
139+
140+
//countNum, _ := collection.Find(condition).Count()
141+
//fmt.Println("\ncount:\n", countNum)
142+
143+
collection.Find(bson.M{"accessKey": os.Getenv("ACCESS_KEY")}).Select(bson.M{"tenantId": 1}).One(&resultCred)
144+
c.Assert(resultCred.TenantId, checker.NotNil)
145+
tenantId := resultCred.TenantId
146+
147+
148+
///////////////////////////////////////////
149+
// query image quota by tenant
150+
collection = db.C("tenant")
151+
resultTenant := Tenant{}
152+
153+
//countNum, _ := collection.Find(condition).Count()
154+
//fmt.Println("\ncount:\n", countNum)
155+
156+
collection.Find(bson.M{"tenantid": tenantId}).Select(bson.M{"resourceinfo": 1}).One(&resultTenant)
157+
//fmt.Printf("total images: %v\n", resultTenant.Resourceinfo.Total.Images)
158+
//fmt.Printf("balance images: %v\n", resultTenant.Resourceinfo.Balance.Images)
159+
totalImages := resultTenant.Resourceinfo.Total.Images
160+
balanceImages := resultTenant.Resourceinfo.Balance.Images
161+
162+
c.Assert(totalImages, checker.GreaterThan, 0)
163+
c.Assert(balanceImages, checker.LessOrEqualThan, totalImages)
164+
c.Assert(balanceImages, checker.Equals, expected)
165+
}

0 commit comments

Comments
 (0)