From 9ebe025e1385a0a4fa8e24ad62cc1c0f8808fb9c Mon Sep 17 00:00:00 2001 From: ssmith Date: Mon, 18 May 2020 18:08:35 -0400 Subject: Reworks resource tests into model validation where possible. Change-Id: Ieb77cc38a42345107c2cac62ba1499bd7974ad77 Signed-off-by: Sean Smith --- src/resource_inventory/models.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/resource_inventory/models.py') diff --git a/src/resource_inventory/models.py b/src/resource_inventory/models.py index d1b7a75..33d98a0 100644 --- a/src/resource_inventory/models.py +++ b/src/resource_inventory/models.py @@ -439,6 +439,9 @@ class InterfaceConfiguration(models.Model): def __str__(self): return "type " + str(self.profile) + " on host " + str(self.resource_config) + def save(self, *args, **kwargs): + super().save(*args, **kwargs) + """ OPNFV / Software configuration models @@ -504,12 +507,21 @@ class Interface(models.Model): mac_address = models.CharField(max_length=17) bus_address = models.CharField(max_length=50) config = models.ManyToManyField(Vlan) - acts_as = models.OneToOneField(InterfaceConfiguration, null=True, on_delete=models.SET_NULL) + acts_as = models.OneToOneField(InterfaceConfiguration, null=True, on_delete=models.CASCADE) profile = models.ForeignKey(InterfaceProfile, on_delete=models.CASCADE) def __str__(self): return self.mac_address + " on host " + str(self.profile.host.name) + def clean(self, *args, **kwargs): + if self.acts_as.profile != self.profile: + raise ValidationError("Interface Configuration's Interface Profile does not match Interface Profile chosen for Interface.") + super().clean(*args, **kwargs) + + def save(self, *args, **kwargs): + self.full_clean() + super().save(*args, **kwargs) + """ Some Enums for dealing with global constants. -- cgit 1.2.3-korg