Make atest_migrate_host create hosts as locked initially, to prevent
ACL races. Port the existing locked status. Add missing users to
pre-existing migrated ACLs

Signed-off-by: Martin Bligh <mbligh@google.com>




git-svn-id: http://test.kernel.org/svn/autotest/trunk@2701 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/cli/atest_migrate_host b/cli/atest_migrate_host
index 943105d..bbe7150 100644
--- a/cli/atest_migrate_host
+++ b/cli/atest_migrate_host
@@ -21,7 +21,7 @@
 
 # Create host
 
-new_host = new.create_host(hostname=hostname)
+new_host = new.create_host(hostname=hostname, locked=True)
 
 # Deal with labels
 old_host_labels = old_host.get_labels()
@@ -42,17 +42,24 @@
 
 for acl in old_host_acls:
     # Create any non-existant ACLs
-    if not new.get_acls(name=acl.name):
+    new_acls = new.get_acls(name=acl.name)
+    if new_acls:
+        new_acl = new_acls[0]
+    else:
         new_acl = new.create_acl(name=acl.name, description=acl.description)
-        # Add any users to the ACL that we can
-        for user in acl.users:
-            if user in new_users:
-                new_acl.add_users([user])
-            else:
-                print 'Skipping absent user %s' % user
+    # Add any users to the ACL that we can
+    for user in acl.users:
+        if user in new_users:
+            new_acl.add_users([user])
+        else:
+            print 'Skipping absent user %s' % user
     # Add any missing ACLs to the machine
     if not [a for a in new_host.get_acls() if a.name == acl.name]:
         new_host.add_acl(acl.name)
 
+# Enable the new host
+if not old_host.locked:
+    new_host.modify(locked=False)
+
 # Delete host from old server
 old_host.delete()