OLD | NEW |
1 """Database model classes for the scheduler. | 1 """Database model classes for the scheduler. |
2 | 2 |
3 Contains model classes abstracting the various DB tables used by the scheduler. | 3 Contains model classes abstracting the various DB tables used by the scheduler. |
4 These overlap the Django models in basic functionality, but were written before | 4 These overlap the Django models in basic functionality, but were written before |
5 the Django models existed and have not yet been phased out. Some of them | 5 the Django models existed and have not yet been phased out. Some of them |
6 (particularly HostQueueEntry and Job) have considerable scheduler-specific logic | 6 (particularly HostQueueEntry and Job) have considerable scheduler-specific logic |
7 which would probably be ill-suited for inclusion in the general Django model | 7 which would probably be ill-suited for inclusion in the general Django model |
8 classes. | 8 classes. |
9 | 9 |
10 Globals: | 10 Globals: |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 _delay_ready_task = None | 820 _delay_ready_task = None |
821 | 821 |
822 # TODO(gps): On scheduler start/recovery we need to call HQE.on_pending() on | 822 # TODO(gps): On scheduler start/recovery we need to call HQE.on_pending() on |
823 # all status='Pending' atomic group HQEs incase a delay was running when the | 823 # all status='Pending' atomic group HQEs incase a delay was running when the |
824 # scheduler was restarted and no more hosts ever successfully exit Verify. | 824 # scheduler was restarted and no more hosts ever successfully exit Verify. |
825 | 825 |
826 def __init__(self, id=None, row=None, **kwargs): | 826 def __init__(self, id=None, row=None, **kwargs): |
827 assert id or row | 827 assert id or row |
828 super(Job, self).__init__(id=id, row=row, **kwargs) | 828 super(Job, self).__init__(id=id, row=row, **kwargs) |
829 self._owner_model = None # caches model instance of owner | 829 self._owner_model = None # caches model instance of owner |
| 830 self.update_image_path = None # path of OS image to install |
830 | 831 |
831 | 832 |
832 def model(self): | 833 def model(self): |
833 return models.Job.objects.get(id=self.id) | 834 return models.Job.objects.get(id=self.id) |
834 | 835 |
835 | 836 |
836 def owner_model(self): | 837 def owner_model(self): |
837 # work around the fact that the Job owner field is a string, not a | 838 # work around the fact that the Job owner field is a string, not a |
838 # foreign key | 839 # foreign key |
839 if not self._owner_model: | 840 if not self._owner_model: |
(...skipping 14 matching lines...) Expand all Loading... |
854 SELECT * FROM afe_host_queue_entries | 855 SELECT * FROM afe_host_queue_entries |
855 WHERE job_id= %s | 856 WHERE job_id= %s |
856 """, (self.id,)) | 857 """, (self.id,)) |
857 entries = [HostQueueEntry(row=i) for i in rows] | 858 entries = [HostQueueEntry(row=i) for i in rows] |
858 | 859 |
859 assert len(entries)>0 | 860 assert len(entries)>0 |
860 | 861 |
861 return entries | 862 return entries |
862 | 863 |
863 | 864 |
| 865 def is_image_update_job(self): |
| 866 """ |
| 867 Discover if the current job requires an OS update. |
| 868 |
| 869 @return: True/False if OS should be updated before job is run. |
| 870 """ |
| 871 # All image update jobs have the parameterized_job_id set. |
| 872 if not self.parameterized_job_id: |
| 873 return False |
| 874 |
| 875 # Retrieve the ID of the ParameterizedJob this job is an instance of. |
| 876 rows = _db.execute(""" |
| 877 SELECT test_id |
| 878 FROM afe_parameterized_jobs |
| 879 WHERE id = %s |
| 880 """, (self.parameterized_job_id,)) |
| 881 if not rows: |
| 882 return False |
| 883 test_id = rows[0][0] |
| 884 |
| 885 # Retrieve the ID of the known autoupdate_ParameterizedJob. |
| 886 rows = _db.execute(""" |
| 887 SELECT id |
| 888 FROM afe_autotests |
| 889 WHERE name = 'autoupdate_ParameterizedJob' |
| 890 """) |
| 891 if not rows: |
| 892 return False |
| 893 update_id = rows[0][0] |
| 894 |
| 895 # If the IDs are the same we've found an image update job. |
| 896 if test_id == update_id: |
| 897 # Finally, get the path to the OS image to install. |
| 898 rows = _db.execute(""" |
| 899 SELECT parameter_value |
| 900 FROM afe_parameterized_job_parameters |
| 901 WHERE parameterized_job_id = %s |
| 902 """, (self.parameterized_job_id,)) |
| 903 if rows: |
| 904 # Save the path in update_image_path to use later as a command |
| 905 # line parameter to autoserv. |
| 906 self.update_image_path = rows[0][0] |
| 907 return True |
| 908 |
| 909 return False |
| 910 |
| 911 |
864 def get_execution_details(self): | 912 def get_execution_details(self): |
865 """ | 913 """ |
866 Get test execution details for this job. | 914 Get test execution details for this job. |
867 | 915 |
868 @return: Dictionary with test execution details | 916 @return: Dictionary with test execution details |
869 """ | 917 """ |
870 def _find_test_jobs(rows): | 918 def _find_test_jobs(rows): |
871 """ | 919 """ |
872 Here we are looking for tests such as SERVER_JOB and CLIENT_JOB.* | 920 Here we are looking for tests such as SERVER_JOB and CLIENT_JOB.* |
873 Those are autotest 'internal job' tests, so they should not be | 921 Those are autotest 'internal job' tests, so they should not be |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1309 def abort_delay_ready_task(self): | 1357 def abort_delay_ready_task(self): |
1310 """Abort the delayed task associated with this job, if any.""" | 1358 """Abort the delayed task associated with this job, if any.""" |
1311 if self._delay_ready_task: | 1359 if self._delay_ready_task: |
1312 # Cancel any pending callback that would try to run again | 1360 # Cancel any pending callback that would try to run again |
1313 # as we are already running. | 1361 # as we are already running. |
1314 self._delay_ready_task.abort() | 1362 self._delay_ready_task.abort() |
1315 | 1363 |
1316 | 1364 |
1317 def __str__(self): | 1365 def __str__(self): |
1318 return '%s-%s' % (self.id, self.owner) | 1366 return '%s-%s' % (self.id, self.owner) |
OLD | NEW |