[CORD-2550] Fixing profile/enodeb update and adding debug info
[CORD-2714] Not adding profiles to the same handover
Change-Id: I7f84362c8de43753f9712f53fbf1bead3ece58f3
diff --git a/xos/models/models.py b/xos/models/models.py
index babf8b5..25a37df 100644
--- a/xos/models/models.py
+++ b/xos/models/models.py
@@ -1,3 +1,17 @@
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
from xos.exceptions import XOSValidationError
from models_decl import ProgranService_decl
@@ -5,12 +19,6 @@
from models_decl import Handover_decl
from models_decl import ProgranServiceInstance_decl
-
-
-
-
-
-
class ProgranService(ProgranService_decl):
class Meta:
proxy = True
@@ -43,6 +51,10 @@
except self.DoesNotExist:
pass
+ if self.is_new and not self.created_by:
+ # NOTE if created_by is null it has been created by XOS
+ self.created_by = "XOS"
+
super(ENodeB, self).save(*args, **kwargs)
@@ -50,6 +62,13 @@
class Meta:
proxy = True
+ def save(self, *args, **kwargs):
+ if self.is_new and not self.created_by:
+ # NOTE if created_by is null it has been created by XOS
+ self.created_by = "XOS"
+ super(Handover, self).save(*args, **kwargs)
+
+
class ProgranServiceInstance(ProgranServiceInstance_decl):
class Meta:
@@ -73,24 +92,30 @@
except self.DoesNotExist:
pass
+ if self.is_new and not self.created_by:
+ # NOTE if created_by is null it has been created by XOS
+ self.created_by = "XOS"
+
+
# check that the sum of upload and download rate for a single enodeb is not greater than 95
- limit = 95
- same_enodeb = ProgranServiceInstance.objects.filter(enodeb_id=self.enodeb_id)
+ if not self.deleted:
+ limit = 95
+ same_enodeb = ProgranServiceInstance.objects.filter(enodeb_id=self.enodeb_id)
- total_up = self.UlAllocRBRate
- total_down = self.DlAllocRBRate
+ total_up = self.UlAllocRBRate
+ total_down = self.DlAllocRBRate
- for p in same_enodeb:
- total_up = total_up + p.UlAllocRBRate
- total_down = total_down + p.DlAllocRBRate
+ for p in same_enodeb:
+ if p.pk != self.pk:
+ total_up = total_up + p.UlAllocRBRate
+ total_down = total_down + p.DlAllocRBRate
- if total_up > limit:
- raise XOSValidationError("UlAllocRBRate for the enodeb associated with this profile is greater than %s" % limit)
+ if total_up > limit:
+ raise XOSValidationError("UlAllocRBRate for the enodeb associated with this profile is greater than %s" % limit)
- if total_down > limit:
- raise XOSValidationError("DlAllocRBRate for the enodeb associated with this profile is greater than %s" % limit)
+ if total_down > limit:
+ raise XOSValidationError("DlAllocRBRate for the enodeb associated with this profile is greater than %s" % limit)
- # TODO when saving set status to "in progress"
super(ProgranServiceInstance, self).save(*args, **kwargs)