Skip to content

Commit 68a9037

Browse files
committed
fix policy delete and epg delete
1 parent dbb7263 commit 68a9037

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

Vagrantfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ SCRIPT
148148

149149
# forward netmaster port
150150
if n == 0 then
151-
node.vm.network "forwarded_port", guest: 9999, host: 8080
151+
node.vm.network "forwarded_port", guest: 9999, host: 9999
152152
end
153153
end
154154
end

netmaster/objApi/apiController.go

+44-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func (ac *APIController) EndpointGroupUpdate(endpointGroup, params *contivModel.
235235
return core.Errorf("Policy not found")
236236
}
237237

238-
// attach policy to epg
238+
// detach policy to epg
239239
err := master.PolicyDetach(endpointGroup, policy)
240240
if err != nil && err != master.EpgPolicyExists {
241241
log.Errorf("Error detaching policy %s from epg %s", policyName, endpointGroup.Key)
@@ -261,6 +261,34 @@ func (ac *APIController) EndpointGroupUpdate(endpointGroup, params *contivModel.
261261
// EndpointGroupDelete deletes end point group
262262
func (ac *APIController) EndpointGroupDelete(endpointGroup *contivModel.EndpointGroup) error {
263263
log.Infof("Received EndpointGroupDelete: %+v", endpointGroup)
264+
265+
// Detach the endpoint group from the Policies
266+
for _, policyName := range endpointGroup.Policies {
267+
policyKey := endpointGroup.TenantName + ":" + policyName
268+
269+
// find the policy
270+
policy := contivModel.FindPolicy(policyKey)
271+
if policy == nil {
272+
log.Errorf("Could not find policy %s", policyName)
273+
return core.Errorf("Policy not found")
274+
}
275+
276+
// detach policy to epg
277+
err := master.PolicyDetach(endpointGroup, policy)
278+
if err != nil && err != master.EpgPolicyExists {
279+
log.Errorf("Error detaching policy %s from epg %s", policyName, endpointGroup.Key)
280+
return err
281+
}
282+
283+
// Remove links
284+
modeldb.RemoveLinkSet(&policy.LinkSets.EndpointGroups, endpointGroup)
285+
modeldb.RemoveLinkSet(&endpointGroup.LinkSets.Policies, policy)
286+
err = policy.Write()
287+
if err != nil {
288+
return err
289+
}
290+
}
291+
264292
return nil
265293
}
266294

@@ -369,6 +397,21 @@ func (ac *APIController) PolicyUpdate(policy, params *contivModel.Policy) error
369397
// PolicyDelete deletes policy
370398
func (ac *APIController) PolicyDelete(policy *contivModel.Policy) error {
371399
log.Infof("Received PolicyDelete: %+v", policy)
400+
401+
// Check if any endpoint group is using the Policy
402+
if len(policy.LinkSets.EndpointGroups) != 0 {
403+
return core.Errorf("Policy is being used")
404+
}
405+
406+
// Delete all associated Rules
407+
for key, _ := range policy.LinkSets.Rules {
408+
// delete the rule
409+
err := contivModel.DeleteRule(key)
410+
if err != nil {
411+
log.Errorf("Error deleting the rule: %s. Err: %v", key, err)
412+
}
413+
}
414+
372415
return nil
373416
}
374417

scripts/python/testbedApi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def startNetplugin(self):
6565
# Start netmaster process
6666
def startNetmaster(self):
6767
ssh_object = self.sshConnect()
68-
command = "/opt/gopath/bin/netmaster > /tmp/netmaster.log 2>&1"
68+
command = "GOPATH=/opt/gopath /opt/gopath/bin/netmaster > /tmp/netmaster.log 2>&1"
6969
self.nmThread = threading.Thread(target=ssh_exec_thread, args=(ssh_object, command))
7070
# npThread.setDaemon(True)
7171
self.nmThread.start()

0 commit comments

Comments
 (0)