Ejemplo n.º 1
0
  def test_upload_file(self):
    with tempfile.NamedTemporaryFile() as local_file:
      # Make sure we can upload larger than the UPLOAD chunk size
      file_size = DEFAULT_WRITE_SIZE * 2
      local_file.write('0' * file_size)
      local_file.flush()

      dest_dir = self.get_test_path('test_upload')
      local_file = local_file.name
      dest_path = '%s/%s' % (dest_dir, os.path.basename(local_file))

      add_permission(self.user.username, 'has_s3', permname='s3_access', appname='filebrowser')
      try:
        # Just upload the current python file
        resp = self.c.post('/filebrowser/upload/file?dest=%s' % dest_dir, dict(dest=dest_dir, hdfs_file=file(local_file)))
        response = json.loads(resp.content)
      finally:
        remove_from_group(self.user.username, 'has_s3')

      assert_equal(0, response['status'], response)
      stats = self.fs.stats(dest_path)

      f = self.fs.open(dest_path)
      actual = f.read(file_size)
      expected = file(local_file).read()
      assert_equal(actual, expected, 'files do not match: %s != %s' % (len(actual), len(expected)))
Ejemplo n.º 2
0
    def test_upload(self):
        with tempfile.NamedTemporaryFile() as local_file:
            # Make sure we can upload larger than the UPLOAD chunk size
            file_size = DEFAULT_WRITE_SIZE * 2
            local_file.write('0' * file_size)
            local_file.flush()
            self.client.mkdir(self.test_fs + '/test_upload')
            dest_dir = self.test_fs + '/test_upload'
            local_file = local_file.name
            dest_path = '%s/%s' % (dest_dir, os.path.basename(local_file))

            add_permission(self.user.username,
                           'has_abfs',
                           permname='abfs_access',
                           appname='filebrowser')
            # Just upload the current python file
            try:
                resp = self.c.post(
                    '/filebrowser/upload/file?dest=%s' % dest_dir,
                    dict(dest=dest_dir, hdfs_file=file(local_file)))
                response = json.loads(resp.content)
            finally:
                remove_from_group(self.user.username, 'has_abfs')

            assert_equal(0, response['status'], response)
            stats = self.client.stats(dest_path)

            actual = self.client.read(dest_path)
            expected = file(local_file).read()
            assert_equal(
                actual, expected,
                'files do not match: %s != %s' % (len(actual), len(expected)))
Ejemplo n.º 3
0
  def test_fs_permissions_regular_user(self):
    user_client = make_logged_in_client(username='******', groupname='default', recreate=True, is_superuser=False)
    user = User.objects.get(username='******')

    proxy_fs = ProxyFS({'s3a': MockFs(), 'hdfs': MockFs()}, 'hdfs')
    proxy_fs.setuser(user)

    f = proxy_fs._get_fs

    remove_from_group(user.username, 'has_s3')

    # No perms by default
    assert_raises(Exception, f, 's3a://bucket')
    assert_raises(Exception, f, 'S3A://bucket/key')
    f('hdfs://path')
    f('/tmp')

    try:
      # Add perm
      add_permission(user.username, 'has_s3', permname='s3_access', appname='filebrowser')

      f('s3a://bucket')
      f('S3A://bucket/key')
      f('hdfs://path')
      f('/tmp')
    finally:
      remove_from_group(user.username, 'has_s3')