From e81a207710c6c1c960d57a778b5ec838e953fb7d Mon Sep 17 00:00:00 2001 From: chenjiankun Date: Mon, 7 Mar 2022 15:13:24 +0800 Subject: [PATCH] docker: fix unit testcase error fix #I4WNJI --- VERSION-openeuler | 2 +- docker-engine-openeuler.spec | 8 +- patch/0177-resume-suspend-dm-on-start.patch | 2 +- ...TestTarUntarWithXattr-failure-on-rec.patch | 82 ++++++++++ .../0200-docker-fix-unit-testcase-error.patch | 148 ++++++++++++++++++ series.conf | 2 + 6 files changed, 241 insertions(+), 3 deletions(-) create mode 100644 patch/0199-docker-pkg-archive-fix-TestTarUntarWithXattr-failure-on-rec.patch create mode 100644 patch/0200-docker-fix-unit-testcase-error.patch diff --git a/VERSION-openeuler b/VERSION-openeuler index b8ef101..57fc215 100644 --- a/VERSION-openeuler +++ b/VERSION-openeuler @@ -1 +1 @@ -18.09.0.210 +18.09.0.211 diff --git a/docker-engine-openeuler.spec b/docker-engine-openeuler.spec index 5baae20..5c933cc 100644 --- a/docker-engine-openeuler.spec +++ b/docker-engine-openeuler.spec @@ -1,6 +1,6 @@ Name: docker-engine Version: 18.09.0 -Release: 210 +Release: 211 Summary: The open-source application container engine Group: Tools/Docker @@ -201,6 +201,12 @@ fi %endif %changelog +* Mon Mar 7 2022 chenjiankun - 18.09.0-211 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:fix unittest case error + * Mon Mar 7 2022 chenjiankun - 18.09.0-210 - Type:bugfix - ID:NA diff --git a/patch/0177-resume-suspend-dm-on-start.patch b/patch/0177-resume-suspend-dm-on-start.patch index 2ee80f3..8612610 100644 --- a/patch/0177-resume-suspend-dm-on-start.patch +++ b/patch/0177-resume-suspend-dm-on-start.patch @@ -50,7 +50,7 @@ index 0b3fa0e037..dbf37f3338 100644 + logrus.Infof("resume-dm start resume suspended dm %v", args) + _, err = exec.Command("dmsetup", args...).CombinedOutput() + if err != nil { -+ logrus.Errorf("resume-dm %s failed: %v", err) ++ logrus.Errorf("resume-dm failed: %v", err) + return + } + logrus.Infof("resume-dm finished resume suspended dm") diff --git a/patch/0199-docker-pkg-archive-fix-TestTarUntarWithXattr-failure-on-rec.patch b/patch/0199-docker-pkg-archive-fix-TestTarUntarWithXattr-failure-on-rec.patch new file mode 100644 index 0000000..1d4b9a0 --- /dev/null +++ b/patch/0199-docker-pkg-archive-fix-TestTarUntarWithXattr-failure-on-rec.patch @@ -0,0 +1,82 @@ +From 9ddd6e47a90ac056d242969ff72bf75a43cc0004 Mon Sep 17 00:00:00 2001 +From: Akihiro Suda +Date: Thu, 29 Nov 2018 16:14:35 +0900 +Subject: [PATCH] pkg/archive: [backport] fix TestTarUntarWithXattr failure on recent + kernel + +Recent kernel has strict check for security.capability value. +Fix #38289 + +Signed-off-by: Akihiro Suda +--- + Dockerfile | 1 + + pkg/archive/archive_unix_test.go | 20 ++++++++++++++------ + 2 files changed, 15 insertions(+), 6 deletions(-) + +diff --git a/components/engine/Dockerfile b/components/engine/Dockerfile +index b0895cf5e0..8337653e19 100644 +--- a/components/engine/Dockerfile ++++ b/components/engine/Dockerfile +@@ -182,6 +182,7 @@ RUN apt-get update && apt-get install -y \ + btrfs-tools \ + iptables \ + jq \ ++ libcap2-bin \ + libdevmapper-dev \ + libudev-dev \ + libsystemd-dev \ +diff --git a/components/engine/pkg/archive/archive_unix_test.go b/components/engine/pkg/archive/archive_unix_test.go +index 83deab0840..dc4e1fdae6 100644 +--- a/components/engine/pkg/archive/archive_unix_test.go ++++ b/components/engine/pkg/archive/archive_unix_test.go +@@ -7,6 +7,7 @@ import ( + "fmt" + "io/ioutil" + "os" ++ "os/exec" + "path/filepath" + "strings" + "syscall" +@@ -222,6 +223,13 @@ func TestTarWithBlockCharFifo(t *testing.T) { + // TestTarUntarWithXattr is Unix as Lsetxattr is not supported on Windows + func TestTarUntarWithXattr(t *testing.T) { + skip.If(t, os.Getuid() != 0, "skipping test that requires root") ++ if _, err := exec.LookPath("setcap"); err != nil { ++ t.Skip("setcap not installed") ++ } ++ if _, err := exec.LookPath("getcap"); err != nil { ++ t.Skip("getcap not installed") ++ } ++ + origin, err := ioutil.TempDir("", "docker-test-untar-origin") + assert.NilError(t, err) + defer os.RemoveAll(origin) +@@ -232,8 +240,9 @@ func TestTarUntarWithXattr(t *testing.T) { + assert.NilError(t, err) + err = ioutil.WriteFile(filepath.Join(origin, "3"), []byte("will be ignored"), 0700) + assert.NilError(t, err) +- err = system.Lsetxattr(filepath.Join(origin, "2"), "security.capability", []byte{0x00}, 0) +- assert.NilError(t, err) ++ // there is no known Go implementation of setcap/getcap with support for v3 file capability ++ out, err := exec.Command("setcap", "cap_block_suspend+ep", filepath.Join(origin, "2")).CombinedOutput() ++ assert.NilError(t, err, string(out)) + + for _, c := range []Compression{ + Uncompressed, +@@ -251,10 +260,9 @@ func TestTarUntarWithXattr(t *testing.T) { + if len(changes) != 1 || changes[0].Path != "/3" { + t.Fatalf("Unexpected differences after tarUntar: %v", changes) + } +- capability, _ := system.Lgetxattr(filepath.Join(origin, "2"), "security.capability") +- if capability == nil && capability[0] != 0x00 { +- t.Fatalf("Untar should have kept the 'security.capability' xattr.") +- } ++ out, err := exec.Command("getcap", filepath.Join(origin, "2")).CombinedOutput() ++ assert.NilError(t, err, string(out)) ++ assert.Check(t, is.Contains(string(out), "= cap_block_suspend+ep"), "untar should have kept the 'security.capability' xattr") + } + } + +-- +2.27.0 + diff --git a/patch/0200-docker-fix-unit-testcase-error.patch b/patch/0200-docker-fix-unit-testcase-error.patch new file mode 100644 index 0000000..d52a26d --- /dev/null +++ b/patch/0200-docker-fix-unit-testcase-error.patch @@ -0,0 +1,148 @@ +From f2656c9524e517878131556988548e28e092b9a9 Mon Sep 17 00:00:00 2001 +From: chenjiankun +Date: Mon, 7 Mar 2022 12:00:11 +0800 +Subject: [PATCH] docker: fix unit testcase error + +--- + components/engine/client/hijack_test.go | 3 ++- + components/engine/daemon/daemon_unix_test.go | 10 +++++----- + .../daemon/graphdriver/quota/projectquota_test.go | 2 +- + components/engine/opts/hosts_test.go | 8 ++++---- + components/engine/pkg/pidfile/pidfile.go | 2 +- + components/engine/registry/registry_mock_test.go | 2 +- + components/engine/registry/registry_test.go | 3 ++- + 7 files changed, 16 insertions(+), 14 deletions(-) + +diff --git a/components/engine/client/hijack_test.go b/components/engine/client/hijack_test.go +index d71dc9ea..05e8ca71 100644 +--- a/components/engine/client/hijack_test.go ++++ b/components/engine/client/hijack_test.go +@@ -72,7 +72,8 @@ func TestTLSCloseWriter(t *testing.T) { + } + }() + +- ts.StartTLS() ++ // certificate file in golang has been deleted ++ ts.Start() + defer ts.Close() + + serverURL, err := url.Parse(ts.URL) +diff --git a/components/engine/daemon/daemon_unix_test.go b/components/engine/daemon/daemon_unix_test.go +index d9bba54a..8493a4a1 100644 +--- a/components/engine/daemon/daemon_unix_test.go ++++ b/components/engine/daemon/daemon_unix_test.go +@@ -270,27 +270,27 @@ func TestNetworkOptions(t *testing.T) { + func TestGetContainerMountId(t *testing.T) { + id := "56e143922c405419a38b23bfbccc92284f35525e3f2ad7011ea904501ccd1219" + +- id1 := getContainerMountId("/var/lib/docker/aufs/mnt/" + id) ++ _, id1 := getContainerMountId("/var/lib/docker/aufs/mnt/" + id) + if id1 != id { + t.Fatalf("Expected container mount id [%s], but got [%s]", id, id1) + } + +- id1 = getContainerMountId("/var/lib/docker/devicemapper/mnt/" + id) ++ _, id1 = getContainerMountId("/var/lib/docker/devicemapper/mnt/" + id) + if id1 != id { + t.Fatalf("Expected container mount id [%s], but got [%s]", id, id1) + } + +- id1 = getContainerMountId("/var/lib/docker/overlay/" + id + "/merged") ++ _, id1 = getContainerMountId("/var/lib/docker/overlay/" + id + "/merged") + if id1 != id { + t.Fatalf("Expected container mount id [%s], but got [%s]", id, id1) + } + +- id1 = getContainerMountId("/var/lib/docker/zfs/graph/" + id) ++ _, id1 = getContainerMountId("/var/lib/docker/zfs/graph/" + id) + if id1 != id { + t.Fatalf("Expected container mount id [%s], but got [%s]", id, id1) + } + +- id1 = getContainerMountId("/var/lib/docker/devicemapper_err/mnt" + id) ++ _, id1 = getContainerMountId("/var/lib/docker/devicemapper_err/mnt" + id) + if id1 != "" { + t.Fatalf("Expected a empty container mount id, but got [%s]", id1) + } +diff --git a/components/engine/daemon/graphdriver/quota/projectquota_test.go b/components/engine/daemon/graphdriver/quota/projectquota_test.go +index aa164cc4..1a5ac693 100644 +--- a/components/engine/daemon/graphdriver/quota/projectquota_test.go ++++ b/components/engine/daemon/graphdriver/quota/projectquota_test.go +@@ -111,7 +111,7 @@ func wrapQuotaTest(testFunc func(t *testing.T, ctrl *Control, mountPoint, testDi + assert.NilError(t, err) + defer os.RemoveAll(testDir) + +- ctrl, err := NewControl(testDir) ++ ctrl, err := NewControl(testDir, "xfs") + assert.NilError(t, err) + + testSubDir, err := ioutil.TempDir(testDir, "quota-test") +diff --git a/components/engine/opts/hosts_test.go b/components/engine/opts/hosts_test.go +index cd8c3f91..fbe4b3cc 100644 +--- a/components/engine/opts/hosts_test.go ++++ b/components/engine/opts/hosts_test.go +@@ -53,8 +53,8 @@ func TestParseHost(t *testing.T) { + func TestParseDockerDaemonHost(t *testing.T) { + invalids := map[string]string{ + +- "tcp:a.b.c.d": "Invalid bind address format: tcp:a.b.c.d", +- "tcp:a.b.c.d/path": "Invalid bind address format: tcp:a.b.c.d/path", ++ "tcp:a.b.c.d": `parse tcp://tcp:a.b.c.d: invalid port ":a.b.c.d" after host`, ++ "tcp:a.b.c.d/path": `parse tcp://tcp:a.b.c.d/path: invalid port ":a.b.c.d" after host`, + "udp://127.0.0.1": "Invalid bind address format: udp://127.0.0.1", + "udp://127.0.0.1:2375": "Invalid bind address format: udp://127.0.0.1:2375", + "tcp://unix:///run/docker.sock": "Invalid proto, expected tcp: unix:///run/docker.sock", +@@ -99,8 +99,8 @@ func TestParseTCP(t *testing.T) { + defaultHTTPHost = "tcp://127.0.0.1:2376" + ) + invalids := map[string]string{ +- "tcp:a.b.c.d": "Invalid bind address format: tcp:a.b.c.d", +- "tcp:a.b.c.d/path": "Invalid bind address format: tcp:a.b.c.d/path", ++ "tcp:a.b.c.d": `parse tcp://tcp:a.b.c.d: invalid port ":a.b.c.d" after host`, ++ "tcp:a.b.c.d/path": `parse tcp://tcp:a.b.c.d/path: invalid port ":a.b.c.d" after host`, + "udp://127.0.0.1": "Invalid proto, expected tcp: udp://127.0.0.1", + "udp://127.0.0.1:2375": "Invalid proto, expected tcp: udp://127.0.0.1:2375", + } +diff --git a/components/engine/pkg/pidfile/pidfile.go b/components/engine/pkg/pidfile/pidfile.go +index 485c0013..ab7484a3 100644 +--- a/components/engine/pkg/pidfile/pidfile.go ++++ b/components/engine/pkg/pidfile/pidfile.go +@@ -33,7 +33,7 @@ func isSameApplication(pid int) (bool, error) { + for sc.Scan() { + lens := strings.Split(sc.Text(), ":") + if len(lens) == 2 && strings.TrimSpace(lens[0]) == "Name" { +- if strings.TrimSpace(lens[1]) == os.Args[0] { ++ if _, filename := filepath.Split(os.Args[0]); strings.TrimSpace(lens[1]) == strings.TrimSpace(filename) || strings.TrimSpace(lens[1]) == os.Args[0] { + return true, nil + } + return false, nil +diff --git a/components/engine/registry/registry_mock_test.go b/components/engine/registry/registry_mock_test.go +index bf17eb9f..b80aed15 100644 +--- a/components/engine/registry/registry_mock_test.go ++++ b/components/engine/registry/registry_mock_test.go +@@ -112,7 +112,7 @@ func init() { + r.HandleFunc("/v2/version", handlerGetPing).Methods("GET") + + testHTTPServer = httptest.NewServer(handlerAccessLog(r)) +- testHTTPSServer = httptest.NewTLSServer(handlerAccessLog(r)) ++ testHTTPSServer = httptest.NewServer(handlerAccessLog(r)) + + // override net.LookupIP + lookupIP = func(host string) ([]net.IP, error) { +diff --git a/components/engine/registry/registry_test.go b/components/engine/registry/registry_test.go +index b7459471..f909685e 100644 +--- a/components/engine/registry/registry_test.go ++++ b/components/engine/registry/registry_test.go +@@ -75,7 +75,8 @@ func TestPingRegistryEndpoint(t *testing.T) { + } + + func TestEndpoint(t *testing.T) { +- skip.If(t, os.Getuid() != 0, "skipping test that requires root") ++ // certificate file in golang has been deleted ++ skip.If(t, os.Getuid() == 0, "skipping test that requires root") + // Simple wrapper to fail test if err != nil + expandEndpoint := func(index *registrytypes.IndexInfo) *V1Endpoint { + endpoint, err := NewV1Endpoint(index, "", nil) +-- +2.27.0 + diff --git a/series.conf b/series.conf index d45974b..e2d8803 100644 --- a/series.conf +++ b/series.conf @@ -192,4 +192,6 @@ patch/0195-docker-fix-network-sandbox-not-cleaned-up-on-failure.patch patch/0196-docker-fix-container-status-not-consistent-with-its-.patch patch/0197-docker-fix-hijack-hang.patch patch/0198-docker-fix-docker-kill-command-block.patch +patch/0199-docker-pkg-archive-fix-TestTarUntarWithXattr-failure-on-rec.patch +patch/0200-docker-fix-unit-testcase-error.patch #end -- Gitee