Skip to content

Commit 1fc833a

Browse files
banatmrakelkar
authored andcommitted
Fix: building json request to hns endpoints (Policies was malformed) (#3)
overlay: Add: details to error messages in overlay_windows.go Fix: building json request to hns endpoints (Policies was malformed) Fix: updated tests to cover netconf policy marshalling fix
1 parent 7de75fc commit 1fc833a

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

pkg/hns/netconf.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,18 @@ func (n *NetConf) MarshalPolicies() []json.RawMessage {
4040

4141
var result []json.RawMessage
4242
for _, policyArg := range n.AdditionalArgs {
43-
if data, err := json.Marshal(policyArg); err == nil {
43+
if !strings.EqualFold(policyArg.Type, "EndpointPolicy") {
44+
continue
45+
}
46+
if data, err := json.Marshal(policyArg.Value); err == nil {
4447
result = append(result, data)
4548
}
4649
}
4750

4851
return result
4952
}
5053

54+
5155
// ApplyOutboundNatPolicy applies NAT Policy in VFP using HNS
5256
// Simultaneously an exception is added for the network that has to be Nat'd
5357
func (n *NetConf) ApplyOutboundNatPolicy(nwToNat string) {

pkg/hns/netconf_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ var _ = Describe("HNS NetConf", func() {
126126
n := NetConf{
127127
AdditionalArgs: []policyArgument{
128128
{
129-
Type: "someType",
129+
Type: "EndpointPolicy",
130130
Value: map[string]interface{}{
131131
"someKey": "someValue",
132132
},
@@ -141,13 +141,13 @@ var _ = Describe("HNS NetConf", func() {
141141
}
142142

143143
result := n.MarshalPolicies()
144-
Expect(len(result)).To(Equal(2))
144+
Expect(len(result)).To(Equal(1))
145145

146-
var policy policyArgument
146+
var policy map[string]interface{}
147147
err := json.Unmarshal(result[0], &policy)
148148
Expect(err).ToNot(HaveOccurred())
149-
Expect(policy.Type).To(Equal("someType"))
150-
Expect(policy.Value).To(HaveKeyWithValue("someKey", "someValue"))
149+
Expect(policy).Should(HaveKey("someKey"))
150+
Expect(policy["someKey"]).To(Equal("someValue"))
151151
})
152152
})
153153

plugins/main/windows/overlay/overlay_windows.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,14 @@ func cmdAdd(args *skel.CmdArgs) error {
6464
if len(n.endpointMacPrefix) != 5 || n.endpointMacPrefix[2] != '-' {
6565
return fmt.Errorf("endpointMacPrefix [%v] is invalid, value must be of the format xx-xx", n.endpointMacPrefix)
6666
}
67+
} else{
68+
n.endpointMacPrefix="0E-2A"
6769
}
6870

6971
networkName := n.Name
7072
hnsNetwork, err := hcsshim.GetHNSNetworkByName(networkName)
7173
if err != nil {
72-
return err
74+
return fmt.Errorf("Error while GETHNSNewtorkByName(%v): %v",networkName,err)
7375
}
7476

7577
if hnsNetwork == nil {
@@ -86,13 +88,13 @@ func cmdAdd(args *skel.CmdArgs) error {
8688
// run the IPAM plugin and get back the config to apply
8789
r, err := ipam.ExecAdd(n.IPAM.Type, args.StdinData)
8890
if err != nil {
89-
return nil, err
91+
return nil, fmt.Errorf("Error while ipam.ExecAdd: %v",err)
9092
}
9193

9294
// Convert whatever the IPAM result was into the current Result type
9395
result, err := current.NewResultFromResult(r)
9496
if err != nil {
95-
return nil, err
97+
return nil, fmt.Errorf("Error while NewResultFromResult: %v",err)
9698
}
9799

98100
if len(result.IPs) == 0 {
@@ -124,12 +126,12 @@ func cmdAdd(args *skel.CmdArgs) error {
124126
})
125127

126128
if err != nil {
127-
return err
129+
return fmt.Errorf("Error while ProvisionEndpoint(%v,%v,%v) :%v",epName, hnsNetwork.Id,args.ContainerID, err)
128130
}
129131

130132
result, err := hns.ConstructResult(hnsNetwork, hnsEndpoint)
131133
if err != nil {
132-
return err
134+
return fmt.Errorf("Error while constructResult: %v",err)
133135
}
134136

135137
return types.PrintResult(result, cniVersion)

0 commit comments

Comments
 (0)