Merge pull request #626 from Luap99/tuning-mac

tuning: always update MAC in CNI result
This commit is contained in:
Dan Williams 2021-05-05 10:24:13 -05:00 committed by GitHub
commit faf6d2629d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -152,7 +152,7 @@ func changeMacAddr(ifName string, newMacAddr string) error {
return netlink.LinkSetHardwareAddr(link, addr)
}
func updateResultsMacAddr(config TuningConf, ifName string, newMacAddr string) {
func updateResultsMacAddr(config *TuningConf, ifName string, newMacAddr string) {
// Parse previous result.
if config.PrevResult == nil {
return
@ -166,6 +166,7 @@ func updateResultsMacAddr(config TuningConf, ifName string, newMacAddr string) {
i.Mac = newMacAddr
}
}
config.PrevResult = result
}
func changePromisc(ifName string, val bool) error {
@ -356,7 +357,7 @@ func cmdAdd(args *skel.CmdArgs) error {
}
}
updateResultsMacAddr(*tuningConf, args.IfName, tuningConf.Mac)
updateResultsMacAddr(tuningConf, args.IfName, tuningConf.Mac)
}
if tuningConf.Promisc != false {

View File

@ -468,11 +468,12 @@ var _ = Describe("tuning plugin", func() {
})
It(fmt.Sprintf("[%s] configures and deconfigures mac address (from conf file) with ADD/DEL", ver), func() {
mac := "c2:11:22:33:44:55"
conf := []byte(fmt.Sprintf(`{
"name": "test",
"type": "iplink",
"cniVersion": "%s",
"mac": "c2:11:22:33:44:55",
"mac": "%s",
"prevResult": {
"interfaces": [
{"name": "dummy0", "sandbox":"netns"}
@ -486,7 +487,7 @@ var _ = Describe("tuning plugin", func() {
}
]
}
}`, ver))
}`, ver, mac))
args := &skel.CmdArgs{
ContainerID: "dummy",
@ -511,9 +512,10 @@ var _ = Describe("tuning plugin", func() {
Expect(len(result.IPs)).To(Equal(1))
Expect(result.IPs[0].Address.String()).To(Equal("10.0.0.2/24"))
Expect(result.Interfaces[0].Mac).To(Equal(mac))
link, err := netlink.LinkByName(IFNAME)
Expect(err).NotTo(HaveOccurred())
hw, err := net.ParseMAC("c2:11:22:33:44:55")
hw, err := net.ParseMAC(mac)
Expect(err).NotTo(HaveOccurred())
Expect(link.Attrs().HardwareAddr).To(Equal(hw))