Set permissions after running mic appliance
authorEd Bartosh <eduard.bartosh@intel.com>
Sun, 15 Sep 2013 13:40:31 +0000 (16:40 +0300)
committerHasan Wan <hasan.wan@intel.com>
Mon, 16 Sep 2013 07:35:12 +0000 (00:35 -0700)
Due to the bug in Plan9 driver or in qemu permissions of files and
directories on plan9 share are set only for owner(jenkins in our case).
This makes mic/output/* unreadable after directory is rsynced to
download server. Apache raises 403 Forbidden error when
post-image-creation job tries to access build results.

Fixes: #1206

Change-Id: Id723d7323452c7d6ea4df1f131f1498351a78eb2
Signed-off-by: Ed Bartosh <eduard.bartosh@intel.com>
Reviewed-on: https://otctools.jf.intel.com/review/6439
Tested-by: OTC Tools Tester <ed.bartosh@linux.intel.com>
Reviewed-by: Hasan Wan <hasan.wan@intel.com>
common/utils.py
job_imager.py

index 9050af6..2f33671 100644 (file)
@@ -120,3 +120,15 @@ def sync(source, destination):
         raise RuntimeException("Execution of %s failed: %s" % (cmd, str(err)))
 
     return ret_code
+
+def set_permissions(tpath, modes=(0644, 0755)):
+    """
+    Recursively set permission bits for files and directories.
+    Parameters:
+        tpath: top directory path
+        modes: sequence of two modes: (mode_for_files, mode_for_directories)
+    """
+    for root, dirs, files in os.walk(tpath):
+        for fname in files + dirs:
+            path = os.path.join(root, fname)
+            os.chmod(path, os.stat(path).st_mode | modes[fname in dirs])
index f4d63b8..c4b48c2 100755 (executable)
@@ -8,7 +8,7 @@ import shutil
 import subprocess
 
 from common.buildtrigger import trigger_info, trigger_next
-from common.utils import sync
+from common.utils import sync, set_permissions
 
 def get_xml(image_dir, ks_name):
     """ Get the xml the image, return the body as string """
@@ -91,6 +91,8 @@ def main():
         print 'starting mic inside VM to create image'
         ret = run_inside_vm(vm_image, os.getenv("VM_MEMORY", 8192),
                             os.getenv("VM_CPUS", 8), basedir)
+        # workaround for qemu/9p bug in mapping permissions
+        set_permissions(outdir, (0644, 0755))
     else:
         log = os.path.join(outdir, '%s_%s.log.txt' % (build_id, name))
         cache = os.path.join(basedir, 'cache')