On 03/26/2013 10:26 PM, Lucas Meneghel Rodrigues wrote:
The old TKO web application (a bunch of cgi scripts located in tko/) was broken with the change to South, since the tko_test_view view was not contemplated in the datbase creation schema and migration info.
Good catch.
As a bunch of things in autotest still rely on TKO, let's bring it back by replicating the original view into the new way of doing DB related operations. We might carefully consider dropping it at a later point, but it'll be a more involved work. CC: Cleber Rosa <[email protected]> Signed-off-by: Lucas Meneghel Rodrigues <[email protected]> --- frontend/tko/migrations/0001_initial.py | 26 +++++++++++++ frontend/tko/models.py | 69 +++++++++++++++++++++++++++++++++ frontend/tko/rpc_interface_unittest.py | 1 + frontend/tko/sql/test.sql | 31 ++++++++++++++- 4 files changed, 126 insertions(+), 1 deletion(-) diff --git a/frontend/tko/migrations/0001_initial.py b/frontend/tko/migrations/0001_initial.py index b2ed798..d0f8486 100644 --- a/frontend/tko/migrations/0001_initial.py +++ b/frontend/tko/migrations/0001_initial.py @@ -323,6 +323,32 @@ class Migration(SchemaMigration): 'test_idx': ('django.db.models.fields.IntegerField', [], {'primary_key': 'True'}), 'test_name': ('django.db.models.fields.CharField', [], {'max_length': '90', 'blank': 'True'}), 'test_started_time': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}) + }, + 'tko.testviewtko': { + 'Meta': {'object_name': 'TestView', 'db_table': "'tko_test_view_2'", 'managed': 'False'}, + 'test_idx': ('django.db.models.fields.IntegerField', [], {'primary_key': 'True'}), + 'job_idx': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}), + 'test': ('django.db.models.fields.CharField', [], {'max_length': '90', 'blank': 'True'}), + 'subdir': ('django.db.models.fields.CharField', [], {'max_length': '180', 'blank': 'True'}), + 'kernel_idx': ('django.db.models.fields.IntegerField', [], {}), + 'status': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'reason': ('django.db.models.fields.CharField', [], {'max_length': '3072', 'blank': 'True'}), + 'machine_idx': ('django.db.models.fields.IntegerField', [], {}), + 'started_time': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + 'finished_time': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + 'job_tag': ('django.db.models.fields.CharField', [], {'max_length': '300', 'blank': 'True'}), + 'job_label': ('django.db.models.fields.CharField', [], {'max_length': '300', 'blank': 'True'}), + 'job_username': ('django.db.models.fields.CharField', [], {'max_length': '300', 'blank': 'True'}), + 'job_queued_time': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + 'job_started_time': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + 'job_finished_time': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), + 'machine_hostname': ('django.db.models.fields.CharField', [], {'max_length': '300', 'blank': 'True'}), + 'machine_group': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}), + 'machine_owner': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}), + 'kernel_hash': ('django.db.models.fields.CharField', [], {'max_length': '105', 'blank': 'True'}), + 'kernel_base': ('django.db.models.fields.CharField', [], {'max_length': '90', 'blank': 'True'}), + 'kernel_printable': ('django.db.models.fields.CharField', [], {'max_length': '300', 'blank': 'True'}), + 'status_word': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}) } }
Actually, we need a new migration file. The work flow would be: 1) Add the changes to the the models.py file 2) Run south's schemamigration command: # $AUTOTEST_ROOT/frontend/manage.py schemamigration --auto <afe|tko> a 0002_<description>.py should be generated. 3) Have that file and the changes to models.py in the same commit. Users, after having applied this patch would run: # $AUTOTEST_ROOT/frontend/manage.py migrate <afe|tko>
diff --git a/frontend/tko/models.py b/frontend/tko/models.pyindex 188a9cb..c817673 100644 --- a/frontend/tko/models.py +++ b/frontend/tko/models.py @@ -696,3 +696,72 @@ class TestView(dbmodels.Model, model_logic.ModelExtensions): class Meta: db_table = 'tko_test_view_2' managed = False + + +class TestViewTko(dbmodels.Model, model_logic.ModelExtensions): + extra_fields = { + 'DATE(job_queued_time)': 'job queued day', + 'DATE(test_finished_time)': 'test finished day', + } + + group_fields = [ + 'test', + 'status_word', + 'kernel_printable', + 'machine_hostname', + 'job_tag', + 'job_name', + 'reason', + 'job_username', + 'job_queued_time', + 'DATE(job_queued_time)', + 'test_started_time', + 'test_finished_time', + 'DATE(test_finished_time)', + ] + + test_idx = dbmodels.IntegerField('test index', primary_key=True) + job_idx = dbmodels.IntegerField('job index', null=True, blank=True) + test = dbmodels.CharField(blank=True, max_length=90) + subdir = dbmodels.CharField('subdirectory', blank=True, max_length=180) + kernel_idx = dbmodels.IntegerField('kernel index') + status = dbmodels.CharField(blank=True, max_length=30) + reason = dbmodels.CharField(blank=True, max_length=3072) + machine_idx = dbmodels.IntegerField('host index') + test_started_time = dbmodels.DateTimeField(null=True, blank=True) + test_finished_time = dbmodels.DateTimeField(null=True, blank=True) + job_tag = dbmodels.CharField(blank=True, max_length=300) + job_label = dbmodels.CharField(blank=True, max_length=300) + job_username = dbmodels.CharField(blank=True, max_length=300) + job_queued_time = dbmodels.DateTimeField(null=True, blank=True) + job_started_time = dbmodels.DateTimeField(null=True, blank=True) + job_finished_time = dbmodels.DateTimeField(null=True, blank=True) + hostname = dbmodels.CharField(blank=True, max_length=300) + machine_group = dbmodels.CharField(blank=True, max_length=240) + machine_owner = dbmodels.CharField(blank=True, max_length=240) + kernel_hash = dbmodels.CharField(blank=True, max_length=105) + kernel_base = dbmodels.CharField(blank=True, max_length=90) + kernel_printable = dbmodels.CharField(max_length=300) + status_word = dbmodels.CharField(max_length=30) + + objects = TestViewManager() + + def save(self): + raise NotImplementedError('TestViewTko is read-only') + + + def delete(self): + raise NotImplementedError('TestViewTko is read-only') + + @classmethod + def query_objects(cls, filter_data, initial_query=None, + apply_presentation=True): + if initial_query is None: + initial_query = cls.objects.get_query_set_with_joins(filter_data) + return super(TestView, cls).query_objects( + filter_data, initial_query=initial_query, + apply_presentation=apply_presentation) + + class Meta: + db_table = 'tko_test_view' + managed = False diff --git a/frontend/tko/rpc_interface_unittest.py b/frontend/tko/rpc_interface_unittest.py index 3fe4413..43f32b9 100755 --- a/frontend/tko/rpc_interface_unittest.py +++ b/frontend/tko/rpc_interface_unittest.py @@ -46,6 +46,7 @@ def setup_test_view(): TestView. So manually create the view. """ cursor = connection.cursor() + cursor.execute('DROP VIEW IF EXISTS tko_test_view') cursor.execute('DROP VIEW IF EXISTS tko_test_view_2') cursor.execute(get_create_test_view_sql())diff --git a/frontend/tko/sql/test.sql b/frontend/tko/sql/test.sqlindex bdf3183..bb4a932 100644 --- a/frontend/tko/sql/test.sql +++ b/frontend/tko/sql/test.sql @@ -1,7 +1,36 @@ +CREATE VIEW tko_test_view AS + SELECT tko_tests.test_idx AS test_idx, + tko_tests.job_idx AS job_idx, + tko_tests.test AS test, + tko_tests.subdir AS subdir, + tko_tests.kernel_idx AS kernel_idx, + tko_tests.status AS status, + tko_tests.reason AS reason, + tko_tests.machine_idx AS machine_idx, + tko_tests.started_time AS test_started_time, + tko_tests.finished_time AS test_finished_time, + tko_jobs.tag AS job_tag, + tko_jobs.label AS job_label, + tko_jobs.username AS job_username, + tko_jobs.queued_time AS job_queued_time, + tko_jobs.started_time AS job_started_time, + tko_jobs.finished_time AS job_finished_time, + tko_machines.hostname AS machine_hostname, + tko_machines.machine_group AS machine_group, + tko_machines.owner AS machine_owner, + tko_kernels.kernel_hash AS kernel_hash, + tko_kernels.base AS kernel_base, + tko_kernels.printable AS kernel_printable, + tko_status.word AS status_word + FROM + tko_tests JOIN tko_jobs ON tko_jobs.job_idx = tko_tests.job_idx + JOIN tko_machines ON tko_machines.machine_idx = tko_jobs.machine_idx + JOIN tko_kernels ON tko_kernels.kernel_idx = tko_tests.kernel_idx + JOIN tko_status ON tko_status.status_idx = tko_tests.status; CREATE VIEW tko_test_view_2 AS SELECT tko_tests.test_idx AS test_idx, - tko_tests.job_idx AS job_idx, + tko_tests.job_idx AS job_idx, tko_tests.test AS test_name, tko_tests.subdir AS subdir, tko_tests.kernel_idx AS kernel_idx,
_______________________________________________ Autotest-kernel mailing list [email protected] https://www.redhat.com/mailman/listinfo/autotest-kernel
