|
| 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 | +} |
0 commit comments