nixosTests.udisks2: port to python

+26 -18
+26 -18
nixos/tests/udisks2.nix
··· 1 - import ./make-test.nix ({ pkgs, ... }: 1 + import ./make-test-python.nix ({ pkgs, ... }: 2 2 3 3 let 4 4 ··· 30 30 31 31 testScript = 32 32 '' 33 - my $stick = $machine->stateDir . "/usbstick.img"; 34 - system("xz -d < ${stick} > $stick") == 0 or die; 33 + import lzma 35 34 36 - $machine->succeed("udisksctl info -b /dev/vda >&2"); 37 - $machine->fail("udisksctl info -b /dev/sda1"); 35 + with lzma.open( 36 + "${stick}" 37 + ) as data, open(machine.state_dir + "/usbstick.img", "wb") as stick: 38 + stick.write(data.read()) 39 + 40 + machine.succeed("udisksctl info -b /dev/vda >&2") 41 + machine.fail("udisksctl info -b /dev/sda1") 38 42 39 43 # Attach a USB stick and wait for it to show up. 40 - $machine->sendMonitorCommand("drive_add 0 id=stick,if=none,file=$stick,format=raw"); 41 - $machine->sendMonitorCommand("device_add usb-storage,id=stick,drive=stick"); 42 - $machine->waitUntilSucceeds("udisksctl info -b /dev/sda1"); 43 - $machine->succeed("udisksctl info -b /dev/sda1 | grep 'IdLabel:.*USBSTICK'"); 44 + machine.send_monitor_command( 45 + f"drive_add 0 id=stick,if=none,file={stick.name},format=raw" 46 + ) 47 + machine.send_monitor_command("device_add usb-storage,id=stick,drive=stick") 48 + machine.wait_until_succeeds("udisksctl info -b /dev/sda1") 49 + machine.succeed("udisksctl info -b /dev/sda1 | grep 'IdLabel:.*USBSTICK'") 44 50 45 51 # Mount the stick as a non-root user and do some stuff with it. 46 - $machine->succeed("su - alice -c 'udisksctl info -b /dev/sda1'"); 47 - $machine->succeed("su - alice -c 'udisksctl mount -b /dev/sda1'"); 48 - $machine->succeed("su - alice -c 'cat /run/media/alice/USBSTICK/test.txt'") =~ /Hello World/ or die; 49 - $machine->succeed("su - alice -c 'echo foo > /run/media/alice/USBSTICK/bar.txt'"); 52 + machine.succeed("su - alice -c 'udisksctl info -b /dev/sda1'") 53 + machine.succeed("su - alice -c 'udisksctl mount -b /dev/sda1'") 54 + machine.succeed( 55 + "su - alice -c 'cat /run/media/alice/USBSTICK/test.txt' | grep -q 'Hello World'" 56 + ) 57 + machine.succeed("su - alice -c 'echo foo > /run/media/alice/USBSTICK/bar.txt'") 50 58 51 59 # Unmounting the stick should make the mountpoint disappear. 52 - $machine->succeed("su - alice -c 'udisksctl unmount -b /dev/sda1'"); 53 - $machine->fail("[ -d /run/media/alice/USBSTICK ]"); 60 + machine.succeed("su - alice -c 'udisksctl unmount -b /dev/sda1'") 61 + machine.fail("[ -d /run/media/alice/USBSTICK ]") 54 62 55 63 # Remove the USB stick. 56 - $machine->sendMonitorCommand("device_del stick"); 57 - $machine->waitUntilFails("udisksctl info -b /dev/sda1"); 58 - $machine->fail("[ -e /dev/sda ]"); 64 + machine.send_monitor_command("device_del stick") 65 + machine.wait_until_fails("udisksctl info -b /dev/sda1") 66 + machine.fail("[ -e /dev/sda ]") 59 67 ''; 60 68 61 69 })