def _create_user_dir(self, grouping_f, path_f, storage_name): """Create the directories and files for some user location. @type grouping: function that yields the grouping path for the location. @type path: function that yields the actual path for the location. """ try: (grouping_path, fileset) = grouping_f() self._create_grouping_fileset(self.storage[storage_name].filesystem, grouping_path, fileset) path = path_f() if self.gpfs.is_symlink(path): logging.warning("Trying to make a user dir, but a symlink already exists at %s", path) return create_stat_directory( path, 0o700, int(self.account.vsc_id_number), int(self.usergroup.vsc_id_number), self.gpfs ) except Exception: logging.exception("Could not create dir %s for user %s", path, self.account.vsc_id) raise
def _create_member_dir(self, member, target): """Create a member-owned directory in the VO fileset.""" create_stat_directory( target, 0o700, int(member.account.vsc_id_number), int(member.usergroup.vsc_id_number), self.gpfs, False # we should not override permissions on an existing dir where users may have changed them )
def test_create_stat_dir_existing_no_override_diff_uid( self, mock_posix, mock_os_stat): """ Test to see what happens if the dir already exists """ test_uid = 2048 test_gid = 4096 test_path = '/tmp/test' test_permissions = 0o711 Statinfo = namedtuple("Statinfo", ["st_uid", "st_gid"]) mock_os_stat.result_value = Statinfo(test_uid + 1, test_gid) create_stat_directory(test_path, test_permissions, test_uid, test_gid, mock_posix, False) mock_os_stat.assert_called_with(test_path) self.assertFalse(mock_posix.make_dir.called) mock_posix.chown.assert_called_with(test_uid, test_gid, test_path)
def test_create_stat_dir_new(self, mock_posix, mock_os_stat): """ Test to see what happens if the dir already exists """ mock_os_stat.side_effect = OSError('dir not found') mock_posix.make_dir.result_value = True mock_posix.chmod.result_value = None test_uid = 2048 test_gid = 4096 test_path = '/tmp/test' test_permissions = 0o711 create_stat_directory(test_path, test_permissions, test_uid, test_gid, mock_posix, False) mock_os_stat.assert_called_with(test_path) mock_posix.make_dir.assert_called_with(test_path) mock_posix.chmod.assert_called_with(test_permissions, test_path) mock_posix.chown.assert_called_with(test_uid, test_gid, test_path)