From 5a408187d4185058a3910fdca4a80ad51195f43b Mon Sep 17 00:00:00 2001 From: Miguel Duarte Barroso Date: Tue, 22 Jun 2021 19:17:00 +0200 Subject: [PATCH] static ipam: show confusing error msg Signed-off-by: Miguel Duarte Barroso --- plugins/ipam/static/static_test.go | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/plugins/ipam/static/static_test.go b/plugins/ipam/static/static_test.go index deb1bbad..a109cc17 100644 --- a/plugins/ipam/static/static_test.go +++ b/plugins/ipam/static/static_test.go @@ -546,6 +546,38 @@ var _ = Describe("static Operations", func() { }) Expect(err).Should(MatchError("IPAM config missing 'ipam' key")) }) + + It(fmt.Sprintf("[%s] errors when passed an invalid CIDR", ver), func() { + const ifname string = "eth0" + const nspath string = "/some/where" + const ipStr string = "10.10.0.1" + + conf := fmt.Sprintf(`{ + "cniVersion": "%s", + "name": "mynet", + "type": "bridge", + "ipam": { + "type": "static", + "addresses": [ { + "address": "%s" + }] + } + }`, ver, ipStr) + + args := &skel.CmdArgs{ + ContainerID: "dummy", + Netns: nspath, + IfName: ifname, + StdinData: []byte(conf), + } + + // Allocate the IP + _, _, err := testutils.CmdAddWithArgs(args, func() error { + return cmdAdd(args) + }) + Expect(err).Should( + MatchError(fmt.Sprintf("invalid CIDR %s: invalid CIDR address: %s", ipStr, ipStr))) + }) } })