def test_dir_attribs_with_sudo_updates_perms_recursively(self, *args, **kwargs): # make sure we have a user1 and group1 on our docker instance sudo('/usr/sbin/useradd user1') sudo('/usr/sbin/groupadd group1') sudo('mkdir /tmp/temp1') sudo('echo > /tmp/temp1/file1') os_helpers.dir_attribs(location='/tmp/temp1', mode='755', owner='user1', group='group1', recursive=True, use_sudo=True) perms, x, owner, group = sudo('ls -ld /tmp/temp1').split(' ')[0:4] self.assertEquals(perms, 'drwxr-xr-x') self.assertEquals(owner, 'user1') self.assertEquals(group, 'group1') perms, x, owner, group = sudo('ls -l /tmp/temp1/file1').split(' ')[0:4] self.assertEquals(perms, '-rwxr-xr-x') self.assertEquals(owner, 'user1') self.assertEquals(group, 'group1')
def test_dir_attribs_raises_exception_on_failure(self, *args, **kwargs): with self.assertRaises(SystemExit) as cm: os_helpers.dir_attribs(location='/tmp/no-valid-path', mode='755', owner='not-a-valid-user', group='not-a-valid-group', recursive=True, use_sudo=False) self.assertEqual(cm.exception.code, 1)
def test_dir_attribs_without_sudo_updates_perms(self, *args, **kwargs): # make sure we have a user1 and group1 on our docker instance sudo('/usr/sbin/useradd user1') sudo('/usr/sbin/groupadd group1') sudo('echo > /tmp/temp1') os_helpers.dir_attribs(location='/tmp/temp1', mode='755', owner='user1', group='group1', recursive=False, use_sudo=False) perms, x, owner, group = sudo('ls -l /tmp/temp1').split(' ')[0:4] self.assertEquals(perms, '-rwxr-xr-x') self.assertEquals(owner, 'user1') self.assertEquals(group, 'group1')
def test_dir_attribs_returns_True_on_sucess(self, *args, **kwargs): # make sure we have a user1 and group1 on our docker instance sudo('/usr/sbin/useradd user1') sudo('/usr/sbin/groupadd group1') sudo('mkdir /tmp/temp1') sudo('echo > /tmp/temp1/file1') result = os_helpers.dir_attribs(location='/tmp/temp1', mode='755', owner='user1', group='group1', recursive=True, use_sudo=True) self.assertTrue(result)