Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"github.com/docker/docker/pkg/integration/checker"
"github.com/go-check/check"
"strings"
)

/// test invalid url //////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -365,21 +364,3 @@ func (s *DockerSuite) TestLoadFromPublicURLWithQuota(c *check.C) {
out, _ = dockerCmd(c, "info")
c.Assert(out, checker.Contains, "Images: 2")
}

func (s *DockerSuite) TestLoadFromLargeImageArchiveFile(c *check.C) {
printTestCaseName(); defer printTestDuration(time.Now())
testRequires(c, DaemonIsLinux)

imageName := "consol/centos-xfce-vnc";
imageUrl := "http://image-tarball.s3.amazonaws.com/test/public/consol_centos-xfce-vnc.tar"; //1.53GB

output, exitCode, err := dockerCmdWithError("load", "-i", imageUrl)
c.Assert(output, checker.Contains, "Start to download and load the image archive, please wait...\n")
c.Assert(output, checker.Contains, "has been loaded.\n")
c.Assert(exitCode, checker.Equals, 0)
c.Assert(err, checker.IsNil)

images, _ := dockerCmd(c, "images")
c.Assert(images, checker.Contains, imageName)
c.Assert(len(strings.Split(images, "\n")), checker.Equals, 3)
}
27 changes: 27 additions & 0 deletions integration-cli/final/cli/hyper_cli_load_large_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"time"
"github.com/docker/docker/pkg/integration/checker"
"github.com/go-check/check"
"strings"
)


func (s *DockerSuite) TestLoadFromLargeImageArchiveFile(c *check.C) {
printTestCaseName(); defer printTestDuration(time.Now())
testRequires(c, DaemonIsLinux)

imageName := "consol/centos-xfce-vnc";
imageUrl := "http://image-tarball.s3.amazonaws.com/test/public/consol_centos-xfce-vnc.tar"; //1.53GB

output, exitCode, err := dockerCmdWithError("load", "-i", imageUrl)
c.Assert(output, checker.Contains, "Start to download and load the image archive, please wait...\n")
c.Assert(output, checker.Contains, "has been loaded.\n")
c.Assert(exitCode, checker.Equals, 0)
c.Assert(err, checker.IsNil)

images, _ := dockerCmd(c, "images")
c.Assert(images, checker.Contains, imageName)
c.Assert(len(strings.Split(images, "\n")), checker.Equals, 3)
}
165 changes: 165 additions & 0 deletions integration-cli/final/cli/hyper_cli_load_legacy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
package main

import (
"time"
"github.com/docker/docker/pkg/integration/checker"
"github.com/go-check/check"
"strings"

"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"os"
//"fmt"
)

func (s *DockerSuite) TestLoadFromLegacyImageArchiveFile(c *check.C) {
printTestCaseName(); defer printTestDuration(time.Now())
testRequires(c, DaemonIsLinux)

imageName := "ubuntu";
legacyImageUrl := "http://image-tarball.s3.amazonaws.com/test/public/ubuntu_1.8.tar.gz"
imageUrl := "http://image-tarball.s3.amazonaws.com/test/public/ubuntu_1.10.tar.gz"


/////////////////////////////////////////////////////////////////////
checkImageQuota(c, 2)
//load legacy image(saved by docker 1.8)
output, exitCode, err := dockerCmdWithError("load", "-i", legacyImageUrl)
c.Assert(output, checker.Contains, "Start to download and load the image archive, please wait...\n")
c.Assert(output, checker.Contains, "has been loaded.\n")
c.Assert(exitCode, checker.Equals, 0)
c.Assert(err, checker.IsNil)

output, _ = dockerCmd(c, "images")
c.Assert(output, checker.Contains, imageName)
c.Assert(len(strings.Split(output, "\n")), checker.Equals, 3)


/////////////////////////////////////////////////////////////////////
checkImageQuota(c, 1)
//load new format image(saved by docker 1.10)
output, exitCode, err = dockerCmdWithError("load", "-i", imageUrl)
c.Assert(output, checker.Contains, "Start to download and load the image archive, please wait...\n")
c.Assert(output, checker.Contains, "has been loaded.\n")
c.Assert(exitCode, checker.Equals, 0)
c.Assert(err, checker.IsNil)

output, _ = dockerCmd(c, "images")
c.Assert(output, checker.Contains, imageName)
c.Assert(len(strings.Split(output, "\n")), checker.Equals, 3)


/////////////////////////////////////////////////////////////////////
checkImageQuota(c, 1)
//delete single layer
output, _ = dockerCmd(c, "images", "-q", imageName)
imageId := strings.Split(output, "\n")[0]
c.Assert(imageId, checker.Not(checker.Equals), "")

output, _ = dockerCmd(c, "rmi", "--no-prune", imageId)
c.Assert(output, checker.Contains, "Untagged:")
c.Assert(output, checker.Contains, "Deleted:")

checkImageQuota(c, 1)

output, _ = dockerCmd(c, "images")
c.Assert(output, checker.Contains, "<none>")
c.Assert(len(strings.Split(output, "\n")), checker.Equals, 3)
imageId = strings.Split(output, "\n")[0]

output, _ = dockerCmd(c, "images", "-a")
c.Assert(output, checker.Contains, "<none>")
c.Assert(len(strings.Split(output, "\n")), checker.Equals, 6)


/////////////////////////////////////////////////////////////////////
checkImageQuota(c, 1)
//delete all rest layer
output, _ = dockerCmd(c, "images", "-q")
imageId = strings.Split(output, "\n")[0]
c.Assert(imageId, checker.Not(checker.Equals), "")

output, _ = dockerCmd(c, "rmi", imageId)
c.Assert(output, checker.Contains, "Deleted:")

checkImageQuota(c, 2)

output, _ = dockerCmd(c, "images")
c.Assert(len(strings.Split(output, "\n")), checker.Equals, 2)

output, _ = dockerCmd(c, "images", "-a")
c.Assert(len(strings.Split(output, "\n")), checker.Equals, 2)
}


//func (s *DockerSuite) TestCheckImageQuota(c *check.C) {
// printTestCaseName(); defer printTestDuration(time.Now())
// testRequires(c, DaemonIsLinux)
// checkImageQuota(c, 2)
//}

func checkImageQuota(c *check.C, expected int) {

//collection struct: credential
type Credential struct {
TenantId string `bson:"tenantId"`
}

//collection struct: tenant
type Total struct {
Images int `bson:"images"`
}
type Balance struct {
Images int `bson:"images"`
}
type Resourceinfo struct {
Total Total `bson:"total"`
Balance Balance `bson:"balance"`
}
type Tenant struct {
Resourceinfo Resourceinfo `bson:"resourceinfo"`
}


///////////////////////////////////////////
//init connection to mongodb
session, err := mgo.Dial(os.Getenv("MONGODB_URL"))
if err != nil {
panic(err)
}
defer session.Close()
// Optional. Switch the session to a monotonic behavior.
session.SetMode(mgo.Monotonic, true)
db := session.DB("hypernetes")

///////////////////////////////////////////
// query tenantId by accessKey
collection := db.C("credentials")
resultCred := Credential{}

//countNum, _ := collection.Find(condition).Count()
//fmt.Println("\ncount:\n", countNum)

collection.Find(bson.M{"accessKey": os.Getenv("ACCESS_KEY")}).Select(bson.M{"tenantId": 1}).One(&resultCred)
c.Assert(resultCred.TenantId, checker.NotNil)
tenantId := resultCred.TenantId


///////////////////////////////////////////
// query image quota by tenant
collection = db.C("tenant")
resultTenant := Tenant{}

//countNum, _ := collection.Find(condition).Count()
//fmt.Println("\ncount:\n", countNum)

collection.Find(bson.M{"tenantid": tenantId}).Select(bson.M{"resourceinfo": 1}).One(&resultTenant)
//fmt.Printf("total images: %v\n", resultTenant.Resourceinfo.Total.Images)
//fmt.Printf("balance images: %v\n", resultTenant.Resourceinfo.Balance.Images)
totalImages := resultTenant.Resourceinfo.Total.Images
balanceImages := resultTenant.Resourceinfo.Balance.Images

c.Assert(totalImages, checker.GreaterThan, 0)
c.Assert(balanceImages, checker.LessOrEqualThan, totalImages)
c.Assert(balanceImages, checker.Equals, expected)
}
7 changes: 7 additions & 0 deletions integration-cli/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ AWS_ACCESS_KEY=
AWS_SECRET_KEY=


#########################################
##MONGODB
#########################################
MONGODB_URL=


##For test load image from basic auth url
URL_WITH_BASIC_AUTH=http://username:password@test.xx.xx/ubuntu.tar.gz
EOF
Expand Down Expand Up @@ -86,6 +92,7 @@ case $1 in
-e AWS_ACCESS_KEY=${AWS_ACCESS_KEY} \
-e AWS_SECRET_KEY=${AWS_SECRET_KEY} \
-e URL_WITH_BASIC_AUTH=${URL_WITH_BASIC_AUTH} \
-e MONGODB_URL=${MONGODB_URL} \
-v $(pwd)/../:/go/src/github.com/hyperhq/hypercli \
hyperhq/hypercli zsh
;;
Expand Down
25 changes: 25 additions & 0 deletions vendor/src/gopkg.in/mgo.v2/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
mgo - MongoDB driver for Go

Copyright (c) 2010-2013 - Gustavo Niemeyer <gustavo@niemeyer.net>

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 changes: 4 additions & 0 deletions vendor/src/gopkg.in/mgo.v2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The MongoDB driver for Go
-------------------------

Please go to [http://labix.org/mgo](http://labix.org/mgo) for all project details.
Loading