@@ -28,7 +28,7 @@ var _ = Describe("OOB Plugin", func() {
2828 Expect (err ).NotTo (HaveOccurred ())
2929 Expect (config ).NotTo (BeNil ())
3030 Expect (config .Namespace ).To (Equal (ns .Name ))
31- Expect (config .SubnetLabel ).To (Equal (subnetLabel ))
31+ Expect (config .SubnetLabel ).To (Equal ("subnet=foo" ))
3232 })
3333
3434 It ("should return an error if the configuration file is missing" , func () {
@@ -106,6 +106,48 @@ var _ = Describe("OOB Plugin", func() {
106106 })
107107 })
108108
109+ Describe ("K8s Client tests" , func () {
110+ It ("should successfully match the subnet" , func () {
111+ subnets := k8sClient .getOOBNetworks (ipamv1alpha1 .CIPv6SubnetType )
112+ Expect (subnets ).NotTo (BeNil ())
113+ Expect (subnets ).To (HaveLen (1 ))
114+ })
115+
116+ It ("should match the subnet" , func () {
117+ subnet , err := k8sClient .getMatchingSubnet ("foo-v6" , linkLocalIPV6Addr )
118+ Expect (err ).NotTo (HaveOccurred ())
119+ Expect (subnet ).NotTo (BeNil ())
120+ })
121+
122+ It ("should return (nil, nil) and not match the subnet if random subnet passed" , func () {
123+ subnet , err := k8sClient .getMatchingSubnet ("randomfoo" , linkLocalIPV6Addr )
124+ Expect (err ).ToNot (HaveOccurred ())
125+ Expect (subnet ).To (BeNil ())
126+ })
127+
128+ It ("should not match the subnet" , func () {
129+ m , err := net .ParseMAC (unknownMachineMACAddress )
130+ Expect (err ).NotTo (HaveOccurred ())
131+ i := net .ParseIP ("fe90::" )
132+ unknownIPV6Addr , err := eui64 .ParseMAC (i , m )
133+ Expect (err ).NotTo (HaveOccurred ())
134+
135+ subnet , err := k8sClient .getMatchingSubnet ("foo" , unknownIPV6Addr )
136+ Expect (err ).ToNot (HaveOccurred ())
137+ Expect (subnet ).To (BeNil ())
138+ })
139+
140+ It ("return true checks the ip in CIDR" , func () {
141+ checkIP := checkIPInCIDR (linkLocalIPV6Addr , "fe80::/64" )
142+ Expect (checkIP ).To (BeTrue ())
143+ })
144+
145+ It ("return false, if invalid CIDR" , func () {
146+ checkIP := checkIPInCIDR (linkLocalIPV6Addr , "fe80::" )
147+ Expect (checkIP ).To (BeFalse ())
148+ })
149+ })
150+
109151 Describe ("Plugin Setup4" , func () {
110152 It ("should return an error for invalid subnetLabel in the config" , func () {
111153 invalidConfig := & api.OOBConfig {
@@ -151,57 +193,15 @@ var _ = Describe("OOB Plugin", func() {
151193 Expect (resp ).To (BeNil ())
152194 })
153195
154- // It("should successfully handle request", func() {
155- // req, _ := dhcpv4.New()
156- // resp, _ := dhcpv4.NewReplyFromRequest(req)
157-
158- // resp, stop := handler4(req, resp)
159- // Expect(stop).To(BeFalse())
160- // Expect(resp).NotTo(BeNil())
161- // })
162- })
163-
164- Describe ("K8s Client tests" , func () {
165- It ("should successfully match the subnet" , func () {
166- subnets := k8sClient .getOOBNetworks (ipamv1alpha1 .CIPv6SubnetType )
167- Expect (subnets ).NotTo (BeNil ())
168- Expect (subnets ).To (HaveLen (1 ))
169- })
170-
171- It ("should match the subnet" , func () {
172- subnet , err := k8sClient .getMatchingSubnet ("foo" , linkLocalIPV6Addr )
173- Expect (err ).NotTo (HaveOccurred ())
174- Expect (subnet ).NotTo (BeNil ())
175- })
176-
177- It ("should return (nil, nil) and not match the subnet if random subnet passed" , func () {
178- subnet , err := k8sClient .getMatchingSubnet ("randomfoo" , linkLocalIPV6Addr )
179- Expect (err ).ToNot (HaveOccurred ())
180- Expect (subnet ).To (BeNil ())
181- })
182-
183- It ("should not match the subnet" , func () {
184- m , err := net .ParseMAC (unknownMachineMACAddress )
185- Expect (err ).NotTo (HaveOccurred ())
186- i := net .ParseIP ("fe90::" )
187- unknownIPV6Addr , err := eui64 .ParseMAC (i , m )
188- Expect (err ).NotTo (HaveOccurred ())
189-
190- subnet , err := k8sClient .getMatchingSubnet ("foo" , unknownIPV6Addr )
191- Expect (err ).ToNot (HaveOccurred ())
192- Expect (subnet ).To (BeNil ())
193- })
194-
195- It ("return true checks the ip in CIDR" , func () {
196- checkIP := checkIPInCIDR (linkLocalIPV6Addr , "fe80::/64" )
197- Expect (checkIP ).To (BeTrue ())
198- })
196+ It ("should successfully handle request" , func () {
197+ req , _ := dhcpv4 .New ()
198+ req .ClientHWAddr , _ = net .ParseMAC (machineWithIPAddressMACAddress )
199+ req .ClientIPAddr = net .ParseIP (privateIPV4Address )
200+ resp , _ := dhcpv4 .NewReplyFromRequest (req )
199201
200- It ( "return false, if invalid CIDR" , func () {
201- checkIP := checkIPInCIDR ( linkLocalIPV6Addr , "fe80::" )
202- Expect (checkIP ). To ( BeFalse ())
202+ _ , stop := handler4 ( req , resp )
203+ Expect ( stop ). To ( BeFalse () )
204+ Expect (resp ). NotTo ( BeNil ())
203205 })
204-
205206 })
206-
207207})
0 commit comments