at 22.05-pre 1.8 kB view raw
1import ./make-test-python.nix ({ pkgs, ...} : 2let 3 accessKey = "BKIKJAA5BMMU2RHO6IBB"; 4 secretKey = "V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12"; 5 minioPythonScript = pkgs.writeScript "minio-test.py" '' 6 #! ${pkgs.python3.withPackages(ps: [ ps.minio ])}/bin/python 7 import io 8 import os 9 from minio import Minio 10 minioClient = Minio('localhost:9000', 11 access_key='${accessKey}', 12 secret_key='${secretKey}', 13 secure=False) 14 sio = io.BytesIO() 15 sio.write(b'Test from Python') 16 sio.seek(0, os.SEEK_END) 17 sio_len = sio.tell() 18 sio.seek(0) 19 minioClient.put_object('test-bucket', 'test.txt', sio, sio_len, content_type='text/plain') 20 ''; 21in { 22 name = "minio"; 23 meta = with pkgs.lib.maintainers; { 24 maintainers = [ bachp ]; 25 }; 26 27 nodes = { 28 machine = { pkgs, ... }: { 29 services.minio = { 30 enable = true; 31 rootCredentialsFile = pkgs.writeText "minio-credentials" '' 32 MINIO_ROOT_USER=${accessKey} 33 MINIO_ROOT_PASSWORD=${secretKey} 34 ''; 35 }; 36 environment.systemPackages = [ pkgs.minio-client ]; 37 38 # Minio requires at least 1GiB of free disk space to run. 39 virtualisation.diskSize = 4 * 1024; 40 }; 41 }; 42 43 testScript = '' 44 start_all() 45 machine.wait_for_unit("minio.service") 46 machine.wait_for_open_port(9000) 47 48 # Create a test bucket on the server 49 machine.succeed( 50 "mc config host add minio http://localhost:9000 ${accessKey} ${secretKey} --api s3v4" 51 ) 52 machine.succeed("mc mb minio/test-bucket") 53 machine.succeed("${minioPythonScript}") 54 assert "test-bucket" in machine.succeed("mc ls minio") 55 assert "Test from Python" in machine.succeed("mc cat minio/test-bucket/test.txt") 56 machine.shutdown() 57 ''; 58})