Fix the AtomicGroup name display in the admin interface.
Adds an invalid bool column and use the existing invalid model to avoid
problems when deleting from the django admin interface.
Signed-off-by: Gregory Smith <gps@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@2918 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/frontend/afe/models.py b/frontend/afe/models.py
index 2eb008c..393f4924 100644
--- a/frontend/afe/models.py
+++ b/frontend/afe/models.py
@@ -21,7 +21,7 @@
"""
-class AtomicGroup(model_logic.ModelExtensions, dbmodels.Model):
+class AtomicGroup(model_logic.ModelWithInvalid, dbmodels.Model):
"""\
An atomic group defines a collection of hosts which must only be scheduled
all at once. Any host with a label having an atomic group will only be
@@ -39,9 +39,16 @@
name = dbmodels.CharField(maxlength=255, unique=True)
description = dbmodels.TextField(blank=True)
max_number_of_machines = dbmodels.IntegerField(default=1)
+ invalid = dbmodels.BooleanField(default=False,
+ editable=settings.FULL_ADMIN)
- # Used by model_logic.ModelExtensions.
name_field = 'name'
+ objects = model_logic.ExtendedManager()
+ valid_objects = model_logic.ValidObjectsManager()
+
+
+ def clean_object(self):
+ self.label_set.clear()
class Meta:
@@ -49,6 +56,11 @@
class Admin:
list_display = ('name', 'description', 'max_number_of_machines')
+ # see Host.Admin
+ manager = model_logic.ValidObjectsManager()
+
+ def __str__(self):
+ return self.name
class Label(model_logic.ModelWithInvalid, dbmodels.Model):
diff --git a/frontend/afe/views.py b/frontend/afe/views.py
index 8d7911b..3638770 100644
--- a/frontend/afe/views.py
+++ b/frontend/afe/views.py
@@ -18,7 +18,8 @@
def model_documentation(request):
doc = '<h2>Models</h2>\n'
- for model_name in ('Label', 'Host', 'Test', 'User', 'AclGroup', 'Job'):
+ for model_name in ('Label', 'Host', 'Test', 'User', 'AclGroup', 'Job',
+ 'AtomicGroup'):
model_class = getattr(models, model_name)
doc += '<h3>%s</h3>\n' % model_name
doc += '<pre>\n%s</pre>\n' % model_class.__doc__
diff --git a/scheduler/monitor_db.py b/scheduler/monitor_db.py
index 83df096..8993ca6 100644
--- a/scheduler/monitor_db.py
+++ b/scheduler/monitor_db.py
@@ -1978,7 +1978,8 @@
class AtomicGroup(DBObject):
_table_name = 'atomic_groups'
- _fields = ('id', 'name', 'description', 'max_number_of_machines')
+ _fields = ('id', 'name', 'description', 'max_number_of_machines',
+ 'invalid')
class Label(DBObject):
diff --git a/scheduler/monitor_db_unittest.py b/scheduler/monitor_db_unittest.py
index c5c2a26..ea0f41d 100644
--- a/scheduler/monitor_db_unittest.py
+++ b/scheduler/monitor_db_unittest.py
@@ -744,6 +744,22 @@
models.HostQueueEntry.Status.ABORTED)
+ def test_atomic_group_no_labels_no_scheduling(self):
+ # Never schedule on atomic groups marked invalid.
+ job = self._create_job(metahosts=[self.label5.id], synchronous=True,
+ atomic_group=1)
+ # Deleting an atomic group via the frontend marks it invalid and
+ # removes all label references to the group. The job now references
+ # an invalid atomic group with no labels associated with it.
+ self.label5.atomic_group.invalid = True
+ self.label5.atomic_group.save()
+ self.label5.atomic_group = None
+ self.label5.save()
+
+ self._dispatcher._schedule_new_jobs()
+ self._check_for_extra_schedulings()
+
+
def test_schedule_directly_on_atomic_group_host_fail(self):
# Scheduling a job directly on hosts in an atomic group must
# fail to avoid users inadvertently holding up the use of an