Skip to content

Commit

Permalink
Fixing UTs to match the new behaviour.
Browse files Browse the repository at this point in the history
Added Update counter checks to the cnidel / setup TCs.
These extra assertation now cover the cases related to the IP leaking bug.
  • Loading branch information
Levovar committed Aug 8, 2019
1 parent 0b9369e commit 5e15d4e
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 56 deletions.
1 change: 1 addition & 0 deletions integration/cni_config/00-danm.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"cniVersion": "0.3.1",
"name": "meta_cni",
"name_comment": "Mandatory parameter, but can be anything",
"type": "danm",
Expand Down
3 changes: 2 additions & 1 deletion pkg/cnidel/cnidel.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ func DelegateInterfaceSetup(netConf *datastructs.NetConf, danmClient danmclients
}
//As netInfo is only copied to IPAM above, the IP allocation is not refreshed in the original copy.
//Without re-reading the network body we risk leaking IPs if error happens later on within the same thread!
netInfo,_ = netcontrol.GetNetworkFromEp(danmClient, *ep)
netInfo,err = netcontrol.GetNetworkFromEp(danmClient, *ep)
if err != nil {log.Println("lofasz:" + err.Error())}
ipamOptions = getCniIpamConfig(netInfo, ep.Spec.Iface.Address, ep.Spec.Iface.AddressIPv6)
}
rawConfig, err := getCniPluginConfig(netConf, netInfo, ipamOptions, ep)
Expand Down
15 changes: 9 additions & 6 deletions test/stubs/danm/netclient_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,20 @@ func (netClient *NetClientStub) Update(obj *danmtypes.DanmNet) (*danmtypes.DanmN
}
}
}
if strings.Contains(obj.Spec.NetworkID, "conflict") && obj.ObjectMeta.ResourceVersion != magicVersion {
for index, net := range netClient.TestNets {
if net.Spec.NetworkID == obj.Spec.NetworkID {
netClient.TestNets[index].ObjectMeta.ResourceVersion = magicVersion
}
var netIndex int
for index, net := range netClient.TestNets {
if net.ObjectMeta.Name == obj.ObjectMeta.Name {
netIndex = index
}
}
if strings.Contains(obj.Spec.NetworkID, "conflict") && obj.ObjectMeta.ResourceVersion != magicVersion {
netClient.TestNets[netIndex].ObjectMeta.ResourceVersion = magicVersion
return nil, errors.New(datastructs.OptimisticLockErrorMsg)
}
if strings.Contains(obj.Spec.NetworkID, "error") {
return nil, errors.New("fatal error, don't retry")
}
netClient.TestNets[netIndex] = *obj
return obj, nil
}

Expand All @@ -84,7 +87,7 @@ func (netClient *NetClientStub) Get(netName string, options meta_v1.GetOptions)
return nil, errors.New("fatal error, don't retry")
}
for _, testNet := range netClient.TestNets {
if testNet.Spec.NetworkID == netName {
if testNet.ObjectMeta.Name == netName {
return &testNet, nil
}
}
Expand Down
Loading

0 comments on commit 5e15d4e

Please sign in to comment.