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): ...@@ -83,28 +83,28 @@ class TestUtil(unittest.TestCase):
uid_check_root_slaptest = os.stat(root_slaptest)[4] uid_check_root_slaptest = os.stat(root_slaptest)[4]
gid_check_root_slaptest = os.stat(root_slaptest)[5] gid_check_root_slaptest = os.stat(root_slaptest)[5]
self.assertTrue(uid == uid_check_root_slaptest) self.assertEquals(uid, uid_check_root_slaptest)
self.assertTrue(gid == gid_check_root_slaptest) self.assertEquals(gid, gid_check_root_slaptest)
uid_check_wanted_directory0 = os.stat(wanted_directory0)[4] uid_check_wanted_directory0 = os.stat(wanted_directory0)[4]
gid_check_wanted_directory0 = os.stat(wanted_directory0)[5] gid_check_wanted_directory0 = os.stat(wanted_directory0)[5]
self.assertTrue(uid == uid_check_wanted_directory0) self.assertEquals(uid, uid_check_wanted_directory0)
self.assertTrue(gid == gid_check_wanted_directory0) self.assertEquals(gid, gid_check_wanted_directory0)
uid_check_wanted_directory1 = os.stat(wanted_directory1)[4] uid_check_wanted_directory1 = os.stat(wanted_directory1)[4]
gid_check_wanted_directory1 = os.stat(wanted_directory1)[5] gid_check_wanted_directory1 = os.stat(wanted_directory1)[5]
self.assertTrue(uid == uid_check_wanted_directory1) self.assertEquals(uid, uid_check_wanted_directory1)
self.assertTrue(gid == gid_check_wanted_directory1) self.assertEquals(gid, gid_check_wanted_directory1)
uid_check_wanted_directory2 = os.stat(wanted_directory2)[4] uid_check_wanted_directory2 = os.stat(wanted_directory2)[4]
gid_check_wanted_directory2 = os.stat(wanted_directory2)[5] gid_check_wanted_directory2 = os.stat(wanted_directory2)[5]
self.assertTrue(uid == uid_check_wanted_directory2) self.assertEquals(uid, uid_check_wanted_directory2)
self.assertTrue(gid == gid_check_wanted_directory2) self.assertEquals(gid, gid_check_wanted_directory2)
uid_check_file_txt = os.stat(create_file_txt[1])[4] uid_check_file_txt = os.stat(create_file_txt[1])[4]
gid_check_file_txt = os.stat(create_file_txt[1])[5] gid_check_file_txt = os.stat(create_file_txt[1])[5]
self.assertTrue(uid == uid_check_file_txt) self.assertEquals(uid, uid_check_file_txt)
self.assertTrue(gid == gid_check_file_txt) self.assertEquals(gid, gid_check_file_txt)
shutil.rmtree(root_slaptest) shutil.rmtree(root_slaptest)
......
...@@ -49,16 +49,14 @@ def mkdir_p(path, mode=0o700): ...@@ -49,16 +49,14 @@ def mkdir_p(path, mode=0o700):
def chownDirectory(path, uid, gid): def chownDirectory(path, uid, gid):
if os.getuid() == 0: if os.getuid() != 0:
subprocess.check_call(['/bin/chown', '-R', '%s:%s' % (uid, gid), path]) # we are probably inside of a webrunner
else: return
# we are probably inside webrunner # find /opt/slapgrid -not -user 1000 -exec chown slapsoft:slapsoft {} \;
chgrp_location = '/bin/chgrp' subprocess.check_call([
if not os.path.exists(chgrp_location): '/usr/bin/find', path, '-not', '-user', str(uid), '-exec',
chgrp_location = '/usr/bin/chgrp' '/bin/chown', '%s:%s' % (uid, gid), '{}', ';'
if not os.path.exists(chgrp_location): ])
chgrp_location = 'chgrp'
subprocess.check_call([chgrp_location, '-R', '%s' % gid, path])
def parse_certificate_key_pair(html): 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