at 23.05-pre 3.0 kB view raw
1{ system ? builtins.currentSystem, 2 config ? {}, 3 pkgs ? import ../.. { inherit system config; } 4}: 5 6with import ../lib/testing-python.nix { inherit system pkgs; }; 7with pkgs.lib; 8 9with import common/ec2.nix { inherit makeTest pkgs; }; 10 11let 12 image = (import ../lib/eval-config.nix { 13 inherit system; 14 modules = [ 15 ../maintainers/scripts/openstack/openstack-image.nix 16 ../modules/testing/test-instrumentation.nix 17 ../modules/profiles/qemu-guest.nix 18 { 19 # Needed by nixos-rebuild due to lack of network access. 20 system.extraDependencies = with pkgs; [ 21 stdenv 22 ]; 23 } 24 ]; 25 }).config.system.build.openstackImage + "/nixos.qcow2"; 26 27 sshKeys = import ./ssh-keys.nix pkgs; 28 snakeOilPrivateKey = sshKeys.snakeOilPrivateKey.text; 29 snakeOilPrivateKeyFile = pkgs.writeText "private-key" snakeOilPrivateKey; 30 snakeOilPublicKey = sshKeys.snakeOilPublicKey; 31 32in { 33 metadata = makeEc2Test { 34 name = "openstack-ec2-metadata"; 35 inherit image; 36 sshPublicKey = snakeOilPublicKey; 37 userData = '' 38 SSH_HOST_ED25519_KEY_PUB:${snakeOilPublicKey} 39 SSH_HOST_ED25519_KEY:${replaceStrings ["\n"] ["|"] snakeOilPrivateKey} 40 ''; 41 script = '' 42 machine.start() 43 machine.wait_for_file("/etc/ec2-metadata/user-data") 44 machine.wait_for_unit("sshd.service") 45 46 machine.succeed("grep unknown /etc/ec2-metadata/ami-manifest-path") 47 48 # We have no keys configured on the client side yet, so this should fail 49 machine.fail("ssh -o BatchMode=yes localhost exit") 50 51 # Let's install our client private key 52 machine.succeed("mkdir -p ~/.ssh") 53 54 machine.copy_from_host_via_shell( 55 "${snakeOilPrivateKeyFile}", "~/.ssh/id_ed25519" 56 ) 57 machine.succeed("chmod 600 ~/.ssh/id_ed25519") 58 59 # We haven't configured the host key yet, so this should still fail 60 machine.fail("ssh -o BatchMode=yes localhost exit") 61 62 # Add the host key; ssh should finally succeed 63 machine.succeed( 64 "echo localhost,127.0.0.1 ${snakeOilPublicKey} > ~/.ssh/known_hosts" 65 ) 66 machine.succeed("ssh -o BatchMode=yes localhost exit") 67 68 # Just to make sure resizing is idempotent. 69 machine.shutdown() 70 machine.start() 71 machine.wait_for_file("/etc/ec2-metadata/user-data") 72 ''; 73 }; 74 75 userdata = makeEc2Test { 76 name = "openstack-ec2-metadata"; 77 inherit image; 78 sshPublicKey = snakeOilPublicKey; 79 userData = '' 80 { pkgs, ... }: 81 { 82 imports = [ 83 <nixpkgs/nixos/modules/virtualisation/openstack-config.nix> 84 <nixpkgs/nixos/modules/testing/test-instrumentation.nix> 85 <nixpkgs/nixos/modules/profiles/qemu-guest.nix> 86 ]; 87 environment.etc.testFile = { 88 text = "whoa"; 89 }; 90 } 91 ''; 92 script = '' 93 machine.start() 94 machine.wait_for_file("/etc/testFile") 95 assert "whoa" in machine.succeed("cat /etc/testFile") 96 ''; 97 }; 98}