slapos.util: use find to chown in chownDirectory.

Used to decrease writes done by slapos.format.
Also disable specific chgrp for webrunner.
parent baf0630e
......@@ -83,28 +83,28 @@ class TestUtil(unittest.TestCase):
uid_check_root_slaptest = os.stat(root_slaptest)[4]
gid_check_root_slaptest = os.stat(root_slaptest)[5]
self.assertTrue(uid == uid_check_root_slaptest)
self.assertTrue(gid == gid_check_root_slaptest)
self.assertEquals(uid, uid_check_root_slaptest)
self.assertEquals(gid, gid_check_root_slaptest)
uid_check_wanted_directory0 = os.stat(wanted_directory0)[4]
gid_check_wanted_directory0 = os.stat(wanted_directory0)[5]
self.assertTrue(uid == uid_check_wanted_directory0)
self.assertTrue(gid == gid_check_wanted_directory0)
self.assertEquals(uid, uid_check_wanted_directory0)
self.assertEquals(gid, gid_check_wanted_directory0)
uid_check_wanted_directory1 = os.stat(wanted_directory1)[4]
gid_check_wanted_directory1 = os.stat(wanted_directory1)[5]
self.assertTrue(uid == uid_check_wanted_directory1)
self.assertTrue(gid == gid_check_wanted_directory1)
self.assertEquals(uid, uid_check_wanted_directory1)
self.assertEquals(gid, gid_check_wanted_directory1)
uid_check_wanted_directory2 = os.stat(wanted_directory2)[4]
gid_check_wanted_directory2 = os.stat(wanted_directory2)[5]
self.assertTrue(uid == uid_check_wanted_directory2)
self.assertTrue(gid == gid_check_wanted_directory2)
self.assertEquals(uid, uid_check_wanted_directory2)
self.assertEquals(gid, gid_check_wanted_directory2)
uid_check_file_txt = os.stat(create_file_txt[1])[4]
gid_check_file_txt = os.stat(create_file_txt[1])[5]
self.assertTrue(uid == uid_check_file_txt)
self.assertTrue(gid == gid_check_file_txt)
self.assertEquals(uid, uid_check_file_txt)
self.assertEquals(gid, gid_check_file_txt)
shutil.rmtree(root_slaptest)
......
......@@ -49,16 +49,14 @@ def mkdir_p(path, mode=0o700):
def chownDirectory(path, uid, gid):
if os.getuid() == 0:
subprocess.check_call(['/bin/chown', '-R', '%s:%s' % (uid, gid), path])
else:
# we are probably inside webrunner
chgrp_location = '/bin/chgrp'
if not os.path.exists(chgrp_location):
chgrp_location = '/usr/bin/chgrp'
if not os.path.exists(chgrp_location):
chgrp_location = 'chgrp'
subprocess.check_call([chgrp_location, '-R', '%s' % gid, path])
if os.getuid() != 0:
# we are probably inside of a webrunner
return
# find /opt/slapgrid -not -user 1000 -exec chown slapsoft:slapsoft {} \;
subprocess.check_call([
'/usr/bin/find', path, '-not', '-user', str(uid), '-exec',
'/bin/chown', '%s:%s' % (uid, gid), '{}', ';'
])
def parse_certificate_key_pair(html):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment