| 1 | // Copyright 2017-2020 CNI authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package sysctl_testscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl_test`/ |
| 16 | |
| 17 | import ( |
| 18 | "fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/" |
| 19 | "math/randscip-go gomod github.com/golang/go/src go1.24.2 `math/rand`/" |
| 20 | "runtimescip-go gomod github.com/golang/go/src go1.24.2 runtime/" |
| 21 | "stringsscip-go gomod github.com/golang/go/src go1.24.2 strings/" |
| 22 | |
| 23 | . "github.com/onsi/ginkgo/v2scip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/" |
| 24 | . "github.com/onsi/gomegascip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/" |
| 25 | "github.com/vishvananda/netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/" |
| 26 | |
| 27 | "github.com/containernetworking/plugins/pkg/nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/" |
| 28 | "github.com/containernetworking/plugins/pkg/testutilsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/" |
| 29 | "github.com/containernetworking/plugins/pkg/utils/sysctlscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl`/" |
| 30 | ) |
| 31 | |
| 32 | const ( |
| 33 | sysctlDotKeyTemplatescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl_test`/sysctlDotKeyTemplate. = "net.ipv4.conf.%s.proxy_arp" |
| 34 | sysctlSlashKeyTemplatescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl_test`/sysctlSlashKeyTemplate. = "net/ipv4/conf/%s/proxy_arp" |
| 35 | ) |
| 36 | |
| 37 | var _ = Describescip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Describe().("Sysctl tests", func() { |
| 38 | var testIfaceNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl_test`/_:testIfaceName. string |
| 39 | var cleanupscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl_test`/_:cleanup. func() |
| 40 | |
| 41 | beforeEach := func() { |
| 42 | // Save a reference to the original namespace, |
| 43 | // Add a new NS |
| 44 | currNs, err := nsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/.GetCurrentNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/GetCurrentNS().() |
| 45 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 46 | |
| 47 | testNs, err := testutilsscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/.NewNSscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/testutils`/NewNS().() |
| 48 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 49 | |
| 50 | testIfaceNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl_test`/_:testIfaceName. = fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Sprintf().("cnitest.%d", randscip-go gomod github.com/golang/go/src go1.24.2 `math/rand`/.Intnscip-go gomod github.com/golang/go/src go1.24.2 `math/rand`/Intn().(100000)) |
| 51 | testLinkAttrs := netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.NewLinkAttrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/NewLinkAttrs().() |
| 52 | testLinkAttrs.Namescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#Name. = testIfaceNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl_test`/_:testIfaceName. |
| 53 | testLinkAttrs.Namespacescip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAttrs#Namespace. = netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.NsFdscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/NsFd#(int(testNs.Fdscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Fd.())) |
| 54 | testIface := &netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.Dummyscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Dummy#{ |
| 55 | LinkAttrsscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/Dummy#LinkAttrs.: testLinkAttrs, |
| 56 | } |
| 57 | |
| 58 | err = netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.LinkAddscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkAdd().(testIface) |
| 59 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 60 | |
| 61 | runtimescip-go gomod github.com/golang/go/src go1.24.2 runtime/.LockOSThreadscip-go gomod github.com/golang/go/src go1.24.2 runtime/LockOSThread().() |
| 62 | err = testNs.Setscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Set.() |
| 63 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 64 | |
| 65 | cleanupscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl_test`/_:cleanup. = func() { |
| 66 | netlinkscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/.LinkDelscip-go gomod github.com/vishvananda/netlink v1.3.1 `github.com/vishvananda/netlink`/LinkDel().(testIface) |
| 67 | currNs.Setscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/ns`/NetNS#Set.() |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | AfterEachscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/AfterEach().(func() { |
| 72 | cleanupscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl_test`/_:cleanup.() |
| 73 | }) |
| 74 | |
| 75 | Describescip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Describe().("Sysctl", func() { |
| 76 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("reads keys with dot separators", func() { |
| 77 | beforeEach() |
| 78 | sysctlIfaceName := stringsscip-go gomod github.com/golang/go/src go1.24.2 strings/.ReplaceAllscip-go gomod github.com/golang/go/src go1.24.2 strings/ReplaceAll().(testIfaceNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl_test`/_:testIfaceName., ".", "/") |
| 79 | sysctlKey := fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Sprintf().(sysctlDotKeyTemplatescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl_test`/sysctlDotKeyTemplate., sysctlIfaceName) |
| 80 | |
| 81 | _, err := sysctlscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl`/.Sysctlscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl`/Sysctl().(sysctlKey) |
| 82 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 83 | }) |
| 84 | }) |
| 85 | |
| 86 | Describescip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Describe().("Sysctl", func() { |
| 87 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("reads keys with slash separators", func() { |
| 88 | beforeEach() |
| 89 | sysctlKey := fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Sprintf().(sysctlSlashKeyTemplatescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl_test`/sysctlSlashKeyTemplate., testIfaceNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl_test`/_:testIfaceName.) |
| 90 | |
| 91 | _, err := sysctlscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl`/.Sysctlscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl`/Sysctl().(sysctlKey) |
| 92 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 93 | }) |
| 94 | }) |
| 95 | |
| 96 | Describescip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Describe().("Sysctl", func() { |
| 97 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("writes keys with dot separators", func() { |
| 98 | beforeEach() |
| 99 | sysctlIfaceName := stringsscip-go gomod github.com/golang/go/src go1.24.2 strings/.ReplaceAllscip-go gomod github.com/golang/go/src go1.24.2 strings/ReplaceAll().(testIfaceNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl_test`/_:testIfaceName., ".", "/") |
| 100 | sysctlKey := fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Sprintf().(sysctlDotKeyTemplatescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl_test`/sysctlDotKeyTemplate., sysctlIfaceName) |
| 101 | |
| 102 | _, err := sysctlscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl`/.Sysctlscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl`/Sysctl().(sysctlKey, "1") |
| 103 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 104 | }) |
| 105 | }) |
| 106 | |
| 107 | Describescip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/Describe().("Sysctl", func() { |
| 108 | Itscip-go gomod github.com/onsi/ginkgo/v2 v2.25.1 `github.com/onsi/ginkgo/v2`/It().("writes keys with slash separators", func() { |
| 109 | beforeEach() |
| 110 | sysctlKey := fmtscip-go gomod github.com/golang/go/src go1.24.2 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.24.2 fmt/Sprintf().(sysctlSlashKeyTemplatescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl_test`/sysctlSlashKeyTemplate., testIfaceNamescip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl_test`/_:testIfaceName.) |
| 111 | |
| 112 | _, err := sysctlscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl`/.Sysctlscip-go gomod github.com/containernetworking/plugins . `github.com/containernetworking/plugins/pkg/utils/sysctl`/Sysctl().(sysctlKey, "1") |
| 113 | Expectscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/Expect().(err).NotToscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega/types`/Assertion#NotTo().(HaveOccurredscip-go gomod github.com/onsi/gomega v1.38.1 `github.com/onsi/gomega`/HaveOccurred().()) |
| 114 | }) |
| 115 | }) |
| 116 | }) |