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

Commit 8754a3f

Browse files
authored
Merge pull request #124 from Jimmy-Xu/integration-test
[Integration-test] add new test case for hyper load
2 parents 5eee319 + cc9d5d7 commit 8754a3f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+14568
-19
lines changed

integration-cli/final/cli/hyper_cli_save_load_test.go renamed to integration-cli/final/cli/hyper_cli_load_basic_test.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"github.com/docker/docker/pkg/integration/checker"
88
"github.com/go-check/check"
9-
"strings"
109
)
1110

1211
/// test invalid url //////////////////////////////////////////////////////////////////////////
@@ -365,21 +364,3 @@ func (s *DockerSuite) TestLoadFromPublicURLWithQuota(c *check.C) {
365364
out, _ = dockerCmd(c, "info")
366365
c.Assert(out, checker.Contains, "Images: 2")
367366
}
368-
369-
func (s *DockerSuite) TestLoadFromLargeImageArchiveFile(c *check.C) {
370-
printTestCaseName(); defer printTestDuration(time.Now())
371-
testRequires(c, DaemonIsLinux)
372-
373-
imageName := "consol/centos-xfce-vnc";
374-
imageUrl := "http://image-tarball.s3.amazonaws.com/test/public/consol_centos-xfce-vnc.tar"; //1.53GB
375-
376-
output, exitCode, err := dockerCmdWithError("load", "-i", imageUrl)
377-
c.Assert(output, checker.Contains, "Start to download and load the image archive, please wait...\n")
378-
c.Assert(output, checker.Contains, "has been loaded.\n")
379-
c.Assert(exitCode, checker.Equals, 0)
380-
c.Assert(err, checker.IsNil)
381-
382-
images, _ := dockerCmd(c, "images")
383-
c.Assert(images, checker.Contains, imageName)
384-
c.Assert(len(strings.Split(images, "\n")), checker.Equals, 3)
385-
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
10+
11+
func (s *DockerSuite) TestLoadFromLargeImageArchiveFile(c *check.C) {
12+
printTestCaseName(); defer printTestDuration(time.Now())
13+
testRequires(c, DaemonIsLinux)
14+
15+
imageName := "consol/centos-xfce-vnc";
16+
imageUrl := "http://image-tarball.s3.amazonaws.com/test/public/consol_centos-xfce-vnc.tar"; //1.53GB
17+
18+
output, exitCode, err := dockerCmdWithError("load", "-i", imageUrl)
19+
c.Assert(output, checker.Contains, "Start to download and load the image archive, please wait...\n")
20+
c.Assert(output, checker.Contains, "has been loaded.\n")
21+
c.Assert(exitCode, checker.Equals, 0)
22+
c.Assert(err, checker.IsNil)
23+
24+
images, _ := dockerCmd(c, "images")
25+
c.Assert(images, checker.Contains, imageName)
26+
c.Assert(len(strings.Split(images, "\n")), checker.Equals, 3)
27+
}
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) TestLoadFromLegacyImageArchiveFile(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/ubuntu_1.8.tar.gz"
21+
imageUrl := "http://image-tarball.s3.amazonaws.com/test/public/ubuntu_1.10.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, "Start 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) TestCheckImageQuota(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+
}

integration-cli/util.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ AWS_ACCESS_KEY=
5050
AWS_SECRET_KEY=
5151
5252
53+
#########################################
54+
##MONGODB
55+
#########################################
56+
MONGODB_URL=
57+
58+
5359
##For test load image from basic auth url
5460
URL_WITH_BASIC_AUTH=http://username:password@test.xx.xx/ubuntu.tar.gz
5561
EOF
@@ -86,6 +92,7 @@ case $1 in
8692
-e AWS_ACCESS_KEY=${AWS_ACCESS_KEY} \
8793
-e AWS_SECRET_KEY=${AWS_SECRET_KEY} \
8894
-e URL_WITH_BASIC_AUTH=${URL_WITH_BASIC_AUTH} \
95+
-e MONGODB_URL=${MONGODB_URL} \
8996
-v $(pwd)/../:/go/src/github.com/hyperhq/hypercli \
9097
hyperhq/hypercli zsh
9198
;;

vendor/src/gopkg.in/mgo.v2/LICENSE

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
mgo - MongoDB driver for Go
2+
3+
Copyright (c) 2010-2013 - Gustavo Niemeyer <gustavo@niemeyer.net>
4+
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are met:
9+
10+
1. Redistributions of source code must retain the above copyright notice, this
11+
list of conditions and the following disclaimer.
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
The MongoDB driver for Go
2+
-------------------------
3+
4+
Please go to [http://labix.org/mgo](http://labix.org/mgo) for all project details.

0 commit comments

Comments
 (0)