From 7f98cfd7c7ebbe3a3086218d1c3958454e8cce8c Mon Sep 17 00:00:00 2001 From: Gaius Date: Mon, 22 Apr 2024 14:06:45 +0800 Subject: [PATCH] test: add proxy e2e testing Signed-off-by: Gaius --- test/e2e/v2/proxy_test.go | 398 ++++++++++++++++++++++++++++ test/testdata/charts/config-v2.yaml | 14 + 2 files changed, 412 insertions(+) create mode 100644 test/e2e/v2/proxy_test.go diff --git a/test/e2e/v2/proxy_test.go b/test/e2e/v2/proxy_test.go new file mode 100644 index 00000000000..31159454fac --- /dev/null +++ b/test/e2e/v2/proxy_test.go @@ -0,0 +1,398 @@ +/* + * Copyright 2024 The Dragonfly Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package e2e + +import ( + "fmt" + + . "github.com/onsi/ginkgo/v2" //nolint + . "github.com/onsi/gomega" //nolint + + "d7y.io/dragonfly/v2/test/e2e/v2/util" +) + +var _ = Describe("Download with proxy", func() { + Context("/etc/containerd/config.toml file", func() { + It("download should be ok", Label("proxy", "download"), func() { + clientPod, err := util.ClientExec() + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + + out, err := clientPod.Command("sh", "-c", fmt.Sprintf("curl -x 127.0.0.1:4001 -H 'X-Dragonfly-Tag: proxy' %s --output %s", util.GetFileURL("/etc/containerd/config.toml"), util.GetOutputPath("config-proxy.coml"))).CombinedOutput() + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + fmt.Println(string(out)) + + fileMetadata := util.FileMetadata{ + ID: "0ef882badaeb3195aed759a203cfb61951d158bf614f90ab0a20504fb7f97992", + Sha256: "66404431f9a0d5c78205e5a3eb041f76767094fc278c0a091d4ffa10f06cf641", + } + + sha256sum, err := util.CalculateSha256ByTaskID([]*util.PodExec{clientPod}, fileMetadata.ID) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + + sha256sum, err = util.CalculateSha256ByOutput([]*util.PodExec{clientPod}, util.GetOutputPath("config-proxy.coml")) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + + seedClientPods := make([]*util.PodExec, 3) + for i := 0; i < 3; i++ { + seedClientPods[i], err = util.SeedClientExec(i) + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + } + + sha256sum, err = util.CalculateSha256ByTaskID(seedClientPods, fileMetadata.ID) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + }) + }) + + Context("/bin/kubectl file", func() { + It("download should be ok", Label("proxy", "download"), func() { + clientPod, err := util.ClientExec() + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + + out, err := clientPod.Command("sh", "-c", fmt.Sprintf("curl -x 127.0.0.1:4001 -H 'X-Dragonfly-Tag: proxy' %s --output %s", util.GetFileURL("/bin/kubectl"), util.GetOutputPath("kubectl-proxy"))).CombinedOutput() + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + fmt.Println(string(out)) + + fileMetadata := util.FileMetadata{ + ID: "e37fccc0c725a947c0a8856e2e1f6a14a4a5792338a73dcafa7e5ebd6443f7b4", + Sha256: "327b4022d0bfd1d5e9c0701d4a3f989a536f7e6e865e102dcd77c7e7adb31f9a", + } + + sha256sum, err := util.CalculateSha256ByTaskID([]*util.PodExec{clientPod}, fileMetadata.ID) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + + sha256sum, err = util.CalculateSha256ByOutput([]*util.PodExec{clientPod}, util.GetOutputPath("kubectl-proxy")) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + + seedClientPods := make([]*util.PodExec, 3) + for i := 0; i < 3; i++ { + seedClientPods[i], err = util.SeedClientExec(i) + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + } + + sha256sum, err = util.CalculateSha256ByTaskID(seedClientPods, fileMetadata.ID) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + }) + }) + + Context("/bin/x86_64 file", func() { + It("download should be ok", Label("proxy", "download"), func() { + clientPod, err := util.ClientExec() + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + + out, err := clientPod.Command("sh", "-c", fmt.Sprintf("curl -x 127.0.0.1:4001 -H 'X-Dragonfly-Tag: proxy' %s --output %s", util.GetFileURL("/bin/x86_64"), util.GetOutputPath("x86_64-proxy"))).CombinedOutput() + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + fmt.Println(string(out)) + + fileMetadata := util.FileMetadata{ + ID: "7c7cf5c8303626754ba4ae6575c1c96cd3fcad985687ec0d15744e68b15661d6", + Sha256: "a1cbf1bf2d66757121677fd7fefafacd4f843a2cb44a451131002803bae56a65", + } + + sha256sum, err := util.CalculateSha256ByTaskID([]*util.PodExec{clientPod}, fileMetadata.ID) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + + sha256sum, err = util.CalculateSha256ByOutput([]*util.PodExec{clientPod}, util.GetOutputPath("x86_64-proxy")) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + + seedClientPods := make([]*util.PodExec, 3) + for i := 0; i < 3; i++ { + seedClientPods[i], err = util.SeedClientExec(i) + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + } + + sha256sum, err = util.CalculateSha256ByTaskID(seedClientPods, fileMetadata.ID) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + }) + }) + + Context("/bin/zless file", func() { + It("download should be ok", Label("proxy", "download"), func() { + clientPod, err := util.ClientExec() + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + + out, err := clientPod.Command("sh", "-c", fmt.Sprintf("curl -x 127.0.0.1:4001 -H 'X-Dragonfly-Tag: proxy' %s --output %s", util.GetFileURL("/bin/zless"), util.GetOutputPath("zless-proxy"))).CombinedOutput() + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + fmt.Println(string(out)) + + fileMetadata := util.FileMetadata{ + ID: "297205e16a85e8cf803067c84fdd659c1877ff595e76e7633e4aa52b64321dee", + Sha256: "b0cfe211f851049a78f5812cf5b1d7cb4f3fbb101c02c1865c940d5797f4b73b", + } + + sha256sum, err := util.CalculateSha256ByTaskID([]*util.PodExec{clientPod}, fileMetadata.ID) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + + sha256sum, err = util.CalculateSha256ByOutput([]*util.PodExec{clientPod}, util.GetOutputPath("zless-proxy")) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + + seedClientPods := make([]*util.PodExec, 3) + for i := 0; i < 3; i++ { + seedClientPods[i], err = util.SeedClientExec(i) + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + } + + sha256sum, err = util.CalculateSha256ByTaskID(seedClientPods, fileMetadata.ID) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + }) + }) + + Context("/bin/bash file", func() { + It("download should be ok", Label("proxy", "download"), func() { + clientPod, err := util.ClientExec() + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + + out, err := clientPod.Command("sh", "-c", fmt.Sprintf("curl -x 127.0.0.1:4001 -H 'X-Dragonfly-Tag: proxy' %s --output %s", util.GetFileURL("/bin/bash"), util.GetOutputPath("bash-proxy"))).CombinedOutput() + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + fmt.Println(string(out)) + + fileMetadata := util.FileMetadata{ + ID: "b4df90b001f49adcc64d71f68b1c01ad462f631c94c7c7ffc12d97f351874da1", + Sha256: "c37f93c73cf2f303f874c094f6f76e47b2421a3da9f0e7e0b98bea8a3d685322", + } + + sha256sum, err := util.CalculateSha256ByTaskID([]*util.PodExec{clientPod}, fileMetadata.ID) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + + sha256sum, err = util.CalculateSha256ByOutput([]*util.PodExec{clientPod}, util.GetOutputPath("bash-proxy")) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + + seedClientPods := make([]*util.PodExec, 3) + for i := 0; i < 3; i++ { + seedClientPods[i], err = util.SeedClientExec(i) + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + } + + sha256sum, err = util.CalculateSha256ByTaskID(seedClientPods, fileMetadata.ID) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + }) + }) + + Context("/etc/containerd/config.toml file", func() { + It("download should be ok", Label("proxy", "download", "range "), func() { + clientPod, err := util.ClientExec() + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + + out, err := clientPod.Command("sh", "-c", fmt.Sprintf("curl -x 127.0.0.1:4001 -H 'X-Dragonfly-Tag: proxy' %s --output %s", util.GetFileURL("/etc/containerd/config.toml"), util.GetOutputPath("config-proxy.coml"))).CombinedOutput() + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + fmt.Println(string(out)) + + fileMetadata := util.FileMetadata{ + ID: "0ef882badaeb3195aed759a203cfb61951d158bf614f90ab0a20504fb7f97992", + Sha256: "66404431f9a0d5c78205e5a3eb041f76767094fc278c0a091d4ffa10f06cf641", + } + + sha256sum, err := util.CalculateSha256ByTaskID([]*util.PodExec{clientPod}, fileMetadata.ID) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + + sha256sum, err = util.CalculateSha256ByOutput([]*util.PodExec{clientPod}, util.GetOutputPath("config-proxy.coml")) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + + seedClientPods := make([]*util.PodExec, 3) + for i := 0; i < 3; i++ { + seedClientPods[i], err = util.SeedClientExec(i) + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + } + + sha256sum, err = util.CalculateSha256ByTaskID(seedClientPods, fileMetadata.ID) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + }) + }) + + Context("/bin/kubectl file", func() { + It("download should be ok", Label("proxy", "download", "range: bytes=-100"), func() { + clientPod, err := util.ClientExec() + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + + out, err := clientPod.Command("sh", "-c", fmt.Sprintf("curl -x 127.0.0.1:4001 -r -100 -H 'X-Dragonfly-Tag: proxy-bytes-100' %s --output %s", util.GetFileURL("/bin/kubectl"), util.GetOutputPath("kubectl-proxy-bytes-100"))).CombinedOutput() + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + fmt.Println(string(out)) + + fileMetadata := util.FileMetadata{ + ID: "e37fccc0c725a947c0a8856e2e1f6a14a4a5792338a73dcafa7e5ebd6443f7b4", + Sha256: "327b4022d0bfd1d5e9c0701d4a3f989a536f7e6e865e102dcd77c7e7adb31f9a", + } + + sha256sum, err := util.CalculateSha256ByTaskID([]*util.PodExec{clientPod}, fileMetadata.ID) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + + sha256sum, err = util.CalculateSha256ByOutput([]*util.PodExec{clientPod}, util.GetOutputPath("kubectl-proxy-bytes-100")) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + + seedClientPods := make([]*util.PodExec, 3) + for i := 0; i < 3; i++ { + seedClientPods[i], err = util.SeedClientExec(i) + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + } + + sha256sum, err = util.CalculateSha256ByTaskID(seedClientPods, fileMetadata.ID) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + }) + }) + + Context("/bin/kubectl file", func() { + It("download should be ok", Label("proxy", "download", "range: bytes=100-"), func() { + clientPod, err := util.ClientExec() + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + + out, err := clientPod.Command("sh", "-c", fmt.Sprintf("curl -x 127.0.0.1:4001 -r 100- -H 'X-Dragonfly-Tag: proxy-bytes-100-' %s --output %s", util.GetFileURL("/bin/kubectl"), util.GetOutputPath("kubectl-proxy-bytes-100-"))).CombinedOutput() + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + fmt.Println(string(out)) + + fileMetadata := util.FileMetadata{ + ID: "e37fccc0c725a947c0a8856e2e1f6a14a4a5792338a73dcafa7e5ebd6443f7b4", + Sha256: "327b4022d0bfd1d5e9c0701d4a3f989a536f7e6e865e102dcd77c7e7adb31f9a", + } + + sha256sum, err := util.CalculateSha256ByTaskID([]*util.PodExec{clientPod}, fileMetadata.ID) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + + sha256sum, err = util.CalculateSha256ByOutput([]*util.PodExec{clientPod}, util.GetOutputPath("kubectl-proxy-bytes-100-")) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + + seedClientPods := make([]*util.PodExec, 3) + for i := 0; i < 3; i++ { + seedClientPods[i], err = util.SeedClientExec(i) + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + } + + sha256sum, err = util.CalculateSha256ByTaskID(seedClientPods, fileMetadata.ID) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + }) + }) + + Context("/bin/kubectl file", func() { + It("download should be ok", Label("proxy", "download", "range: bytes=100-10240"), func() { + clientPod, err := util.ClientExec() + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + + out, err := clientPod.Command("sh", "-c", fmt.Sprintf("curl -x 127.0.0.1:4001 -r 100-10240 -H 'X-Dragonfly-Tag: proxy-bytes-100-10240' %s --output %s", util.GetFileURL("/bin/kubectl"), util.GetOutputPath("kubectl-proxy-bytes-100-10240"))).CombinedOutput() + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + fmt.Println(string(out)) + + fileMetadata := util.FileMetadata{ + ID: "e37fccc0c725a947c0a8856e2e1f6a14a4a5792338a73dcafa7e5ebd6443f7b4", + Sha256: "327b4022d0bfd1d5e9c0701d4a3f989a536f7e6e865e102dcd77c7e7adb31f9a", + } + + sha256sum, err := util.CalculateSha256ByTaskID([]*util.PodExec{clientPod}, fileMetadata.ID) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + + sha256sum, err = util.CalculateSha256ByOutput([]*util.PodExec{clientPod}, util.GetOutputPath("kubectl-proxy-bytes-100-10240")) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + + seedClientPods := make([]*util.PodExec, 3) + for i := 0; i < 3; i++ { + seedClientPods[i], err = util.SeedClientExec(i) + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + } + + sha256sum, err = util.CalculateSha256ByTaskID(seedClientPods, fileMetadata.ID) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + }) + }) + + Context("/bin/kubectl file", func() { + It("download should be ok", Label("proxy", "download", "range: bytes=100-1024"), func() { + clientPod, err := util.ClientExec() + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + + out, err := clientPod.Command("sh", "-c", fmt.Sprintf("curl -x 127.0.0.1:4001 -r 100-1024 -H 'X-Dragonfly-Tag: proxy-bytes-100-1024' %s --output %s", util.GetFileURL("/bin/kubectl"), util.GetOutputPath("kubectl-proxy-bytes-100-1024"))).CombinedOutput() + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + fmt.Println(string(out)) + + fileMetadata := util.FileMetadata{ + ID: "e37fccc0c725a947c0a8856e2e1f6a14a4a5792338a73dcafa7e5ebd6443f7b4", + Sha256: "327b4022d0bfd1d5e9c0701d4a3f989a536f7e6e865e102dcd77c7e7adb31f9a", + } + + sha256sum, err := util.CalculateSha256ByTaskID([]*util.PodExec{clientPod}, fileMetadata.ID) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + + sha256sum, err = util.CalculateSha256ByOutput([]*util.PodExec{clientPod}, util.GetOutputPath("kubectl-proxy-bytes-100-1024")) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + + seedClientPods := make([]*util.PodExec, 3) + for i := 0; i < 3; i++ { + seedClientPods[i], err = util.SeedClientExec(i) + fmt.Println(err) + Expect(err).NotTo(HaveOccurred()) + } + + sha256sum, err = util.CalculateSha256ByTaskID(seedClientPods, fileMetadata.ID) + Expect(err).NotTo(HaveOccurred()) + Expect(fileMetadata.Sha256).To(Equal(sha256sum)) + }) + }) +}) diff --git a/test/testdata/charts/config-v2.yaml b/test/testdata/charts/config-v2.yaml index 79a124fe4df..576fec31937 100644 --- a/test/testdata/charts/config-v2.yaml +++ b/test/testdata/charts/config-v2.yaml @@ -86,6 +86,13 @@ seedClient: announceInterval: 2s log: level: info + proxy: + prefetch: false + registryMirror: + addr: https://index.docker.io + rules: + - regex: blobs/sha256.* + - regxe: file-server.* client: enable: true @@ -133,6 +140,13 @@ client: announceInterval: 2s log: level: info + proxy: + prefetch: false + registryMirror: + addr: https://index.docker.io + rules: + - regex: blobs/sha256.* + - regxe: file-server.* dfdaemon: enable: false