CORD-1354 fix NetworkSlice and ControllerSite created when they already exists
Change-Id: Ic37464dac40b3e5f92b705f30337ddc77df54ac0
diff --git a/xos/synchronizer/model_policies/model_policy_Site.py b/xos/synchronizer/model_policies/model_policy_Site.py
index f800092..07fe6f3 100644
--- a/xos/synchronizer/model_policies/model_policy_Site.py
+++ b/xos/synchronizer/model_policies/model_policy_Site.py
@@ -5,9 +5,10 @@
# make sure site has a ControllerSite record for each controller
ctrl_sites = ControllerSite.objects.filter(site_id=site.id)
existing_controllers = [cs.controller for cs in ctrl_sites]
+ existing_controller_ids = [c.id for c in existing_controllers]
all_controllers = Controller.objects.all()
for ctrl in all_controllers:
- if ctrl not in existing_controllers:
+ if ctrl.id not in existing_controller_ids:
ctrl_site = ControllerSite(controller=ctrl, site=site)
ctrl_site.save()
diff --git a/xos/synchronizer/model_policies/model_policy_Slice.py b/xos/synchronizer/model_policies/model_policy_Slice.py
index 68aa596..dfc136a 100644
--- a/xos/synchronizer/model_policies/model_policy_Slice.py
+++ b/xos/synchronizer/model_policies/model_policy_Slice.py
@@ -85,10 +85,11 @@
net_slices = [x for x in net_slices if x.network_id in public_net_ids+private_net_ids]
for net_slice in net_slices:
- if net_slice.network in public_nets:
+ if net_slice.network.id in public_nets_ids:
public_net_slice = net_slice
- elif net_slice.network in private_nets:
+ elif net_slice.network.id in private_nets_ids:
private_net_slice = net_slice
+
if support_nat_net and (not public_net_slice):
public_net_slice = NetworkSlice(slice=slice, network=public_nets[0])
public_net_slice.save()