Remove the old acl_groups_users and acl_groups_hosts many2many pivot
table column name hack.

Renames acl_group_id -> aclgroup_id.

Adds a migration script and updates the one piece of code that actually
depended upon the old name.

This is needed for my upcoming change that ports autotest to Django
1.0.x but seems worth cleaning up as a change of its own.

Signed-off-by: Gregory Smith <[email protected]>



git-svn-id: http://test.kernel.org/svn/autotest/trunk@2764 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/cli/host.py b/cli/host.py
index 72f6dfe..59ffcb3 100755
--- a/cli/host.py
+++ b/cli/host.py
@@ -157,11 +157,11 @@
             check_results['status__in'] = None
 
         if self.acl:
-            filters['acl_group__name'] = self.acl
-            check_results['acl_group__name'] = None
+            filters['aclgroup__name'] = self.acl
+            check_results['aclgroup__name'] = None
         if self.user:
-            filters['acl_group__users__login'] = self.user
-            check_results['acl_group__users__login'] = None
+            filters['aclgroup__users__login'] = self.user
+            check_results['aclgroup__users__login'] = None
         return super(host_list, self).execute(op='get_hosts',
                                               filters=filters,
                                               check_results=check_results)
diff --git a/cli/user.py b/cli/user.py
index 83e69d0..8257c79 100755
--- a/cli/user.py
+++ b/cli/user.py
@@ -80,8 +80,8 @@
         filters = {}
         check_results = {}
         if self.acl:
-            filters['acl_group__name__in'] = [self.acl]
-            check_results['acl_group__name__in'] = None
+            filters['aclgroup__name__in'] = [self.acl]
+            check_results['aclgroup__name__in'] = None
 
         if self.access_level:
             filters['access_level__in'] = [self.access_level]
diff --git a/cli/user_unittest.py b/cli/user_unittest.py
index 8593f2c..d037a3d 100755
--- a/cli/user_unittest.py
+++ b/cli/user_unittest.py
@@ -88,7 +88,7 @@
 
     def test_execute_list_all_with_acl(self):
         self.run_cmd(argv=['atest', 'user', 'list', '--acl', 'acl0'],
-                     rpcs=[('get_users', {'acl_group__name__in': ['acl0']},
+                     rpcs=[('get_users', {'aclgroup__name__in': ['acl0']},
                             True,
                             [{u'access_level': 2,
                               u'login': u'user0',
@@ -140,7 +140,7 @@
 
     def test_execute_list_all_with_acl_verbose(self):
         self.run_cmd(argv=['atest', 'user', 'list', '--acl', 'acl0', '-v'],
-                     rpcs=[('get_users', {'acl_group__name__in': ['acl0']},
+                     rpcs=[('get_users', {'aclgroup__name__in': ['acl0']},
                             True,
                             [{u'access_level': 2,
                               u'login': u'user0',
diff --git a/frontend/afe/doctests/001_rpc_test.txt b/frontend/afe/doctests/001_rpc_test.txt
index 7af406e..40a4a8d 100644
--- a/frontend/afe/doctests/001_rpc_test.txt
+++ b/frontend/afe/doctests/001_rpc_test.txt
@@ -551,7 +551,7 @@
 2
 
 # get hosts ACL'd to a user
->>> hosts = rpc_interface.get_hosts(acl_group__users__login='debug_user')
+>>> hosts = rpc_interface.get_hosts(aclgroup__users__login='debug_user')
 >>> sorted([host['hostname'] for host in hosts])
 ['host1', 'host2']
 
@@ -566,10 +566,10 @@
 >>> data['users'], data['hosts']
 (['debug_user'], ['host1'])
 
->>> hosts = rpc_interface.get_hosts(acl_group__users__login='debug_user')
+>>> hosts = rpc_interface.get_hosts(aclgroup__users__login='debug_user')
 >>> sorted([host['hostname'] for host in hosts])
 ['host1', 'host2']
->>> hosts = rpc_interface.get_hosts(acl_group__users__login='showard')
+>>> hosts = rpc_interface.get_hosts(aclgroup__users__login='showard')
 >>> [host['hostname'] for host in hosts]
 ['host2']
 
diff --git a/frontend/afe/doctests/002_site_rpc_test.txt b/frontend/afe/doctests/002_site_rpc_test.txt
index e69de29..05aa916 100644
--- a/frontend/afe/doctests/002_site_rpc_test.txt
+++ b/frontend/afe/doctests/002_site_rpc_test.txt
@@ -0,0 +1 @@
+# This file is for site-specific doctests of the AFE RPC interface.
diff --git a/frontend/afe/models.py b/frontend/afe/models.py
index ac938fe..54facec 100644
--- a/frontend/afe/models.py
+++ b/frontend/afe/models.py
@@ -402,7 +402,7 @@
         if user.is_superuser():
             return
         accessible_host_ids = set(
-            host.id for host in Host.objects.filter(acl_group__users=user))
+            host.id for host in Host.objects.filter(aclgroup__users=user))
         for host in hosts:
             # Check if the user has access to this host,
             # but only if it is not a metahost
@@ -428,9 +428,9 @@
         # filtering on M2M fields is broken in Django 0.96.  It's better in 1.0.
         accessible_ids = set(
             entry.id for entry
-            in not_owned.filter(host__acl_group__users__login=user.login))
+            in not_owned.filter(host__aclgroup__users__login=user.login))
         public_ids = set(entry.id for entry
-                         in not_owned.filter(host__acl_group__name='Everyone'))
+                         in not_owned.filter(host__aclgroup__name='Everyone'))
         cannot_abort = [entry for entry in not_owned.select_related()
                         if entry.id not in accessible_ids
                         or entry.id in public_ids]
@@ -460,14 +460,14 @@
         # works is kind of a coincidence of Django internals.  This trick
         # doesn't work in general (on all foreign key relationships).  I'll
         # replace it with a better technique when the need arises.
-        orphaned_hosts = Host.valid_objects.filter(acl_group__id__isnull=True)
+        orphaned_hosts = Host.valid_objects.filter(aclgroup__id__isnull=True)
         everyone.hosts.add(*orphaned_hosts.distinct())
 
         # find hosts in both Everyone and another ACL group, and remove them
         # from Everyone
         hosts_in_everyone = Host.valid_objects.filter_custom_join(
-            '_everyone', acl_group__name='Everyone')
-        acled_hosts = hosts_in_everyone.exclude(acl_group__name='Everyone')
+            '_everyone', aclgroup__name='Everyone')
+        acled_hosts = hosts_in_everyone.exclude(aclgroup__name='Everyone')
         everyone.hosts.remove(*acled_hosts.distinct())
 
 
@@ -516,10 +516,6 @@
     def __str__(self):
         return self.name
 
-# hack to make the column name in the many-to-many DB tables match the one
-# generated by ruby
-AclGroup._meta.object_name = 'acl_group'
-
 
 class JobManager(model_logic.ExtendedManager):
     'Custom manager to provide efficient status counts querying.'
diff --git a/frontend/client/src/autotest/afe/HostTableDecorator.java b/frontend/client/src/autotest/afe/HostTableDecorator.java
index 4741108..0d63020 100644
--- a/frontend/client/src/autotest/afe/HostTableDecorator.java
+++ b/frontend/client/src/autotest/afe/HostTableDecorator.java
@@ -25,7 +25,7 @@
         private JSONValue username;
         
         public AclAccessibleFilter() {
-            super("acl_group__users__login");
+            super("aclgroup__users__login");
             username = new JSONString(StaticDataRepository.getRepository().getCurrentUserLogin());
         }
 
diff --git a/frontend/migrations/025_aclgroup_id_column_rename.py b/frontend/migrations/025_aclgroup_id_column_rename.py
new file mode 100644
index 0000000..8bf3ed8
--- /dev/null
+++ b/frontend/migrations/025_aclgroup_id_column_rename.py
@@ -0,0 +1,25 @@
+# acl_group_id in the many2many pivot table was an old Ruby-ism which
+# required a gross hack on Django 0.96 to support.  The Django name for the
+# column is aclgroup_id, it requires no unsupportable hacks.
+
+# NOTE: This is annoying the MySQL way of renaming columns.
+UP_SQL = """
+ALTER TABLE acl_groups_hosts CHANGE
+    acl_group_id aclgroup_id int(11) default NULL;
+ALTER TABLE acl_groups_users CHANGE
+    acl_group_id aclgroup_id int(11) default NULL;
+"""
+
+DOWN_SQL = """
+ALTER TABLE acl_groups_hosts CHANGE
+    aclgroup_id acl_group_id int(11) default NULL;
+ALTER TABLE acl_groups_users CHANGE
+    aclgroup_id acl_group_id int(11) default NULL;
+"""
+
+def migrate_up(manager):
+    manager.execute_script(UP_SQL)
+
+
+def migrate_down(manager):
+    manager.execute_script(DOWN_SQL)
diff --git a/scheduler/monitor_db.py b/scheduler/monitor_db.py
index 19f0c90..b295b5e 100644
--- a/scheduler/monitor_db.py
+++ b/scheduler/monitor_db.py
@@ -222,7 +222,7 @@
     @classmethod
     def _get_job_acl_groups(cls, job_ids):
         query = """
-        SELECT jobs.id, acl_groups_users.acl_group_id
+        SELECT jobs.id, acl_groups_users.aclgroup_id
         FROM jobs
         INNER JOIN users ON users.login = jobs.owner
         INNER JOIN acl_groups_users ON acl_groups_users.user_id = users.id
@@ -254,7 +254,7 @@
     @classmethod
     def _get_host_acls(cls, host_ids):
         query = """
-        SELECT host_id, acl_group_id
+        SELECT host_id, aclgroup_id
         FROM acl_groups_hosts
         WHERE host_id IN (%s)
         """
@@ -634,7 +634,7 @@
         query = models.Job.objects.filter(
             created_on__lt=timeout_start,
             hostqueueentry__status='Pending',
-            hostqueueentry__host__acl_group__name='Everyone')
+            hostqueueentry__host__aclgroup__name='Everyone')
         for job in query.distinct():
             print 'Aborting job %d due to start timeout' % job.id
             entries_to_abort = job.hostqueueentry_set.exclude(
diff --git a/scheduler/monitor_db_unittest.py b/scheduler/monitor_db_unittest.py
index 6985674..6dc8f77 100644
--- a/scheduler/monitor_db_unittest.py
+++ b/scheduler/monitor_db_unittest.py
@@ -1266,7 +1266,7 @@
 
     def test_run_synchronous_ready(self):
         self._create_job(hosts=[1, 2], synchronous=True)
-        self._update_hqe("status='Pending', execution_subdir='")
+        self._update_hqe("status='Pending', execution_subdir=''")
         self._setup_directory_expects('group0')
 
         tasks = self._test_run_helper(expect_starting=True)