| 
									
										
										
										
											2019-01-28 11:59:18 +01:00
										 |  |  | { system ? builtins.currentSystem, | 
					
						
							|  |  |  |   config ? {}, | 
					
						
							|  |  |  |   pkgs ? import ../.. { inherit system config; } | 
					
						
							|  |  |  | }: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 09:48:11 +01:00
										 |  |  | with import ../lib/testing-python.nix { inherit system pkgs; }; | 
					
						
							| 
									
										
										
										
											2019-01-28 11:59:18 +01:00
										 |  |  | with pkgs.lib; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | with import common/ec2.nix { inherit makeTest pkgs; }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | let | 
					
						
							| 
									
										
										
										
											2020-02-02 09:48:11 +01:00
										 |  |  |   image = (import ../lib/eval-config.nix { | 
					
						
							|  |  |  |     inherit system; | 
					
						
							|  |  |  |     modules = [ | 
					
						
							|  |  |  |       ../maintainers/scripts/openstack/openstack-image.nix | 
					
						
							|  |  |  |       ../modules/testing/test-instrumentation.nix | 
					
						
							|  |  |  |       ../modules/profiles/qemu-guest.nix | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         # Needed by nixos-rebuild due to lack of network access. | 
					
						
							|  |  |  |         system.extraDependencies = with pkgs; [ | 
					
						
							|  |  |  |           stdenv | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     ]; | 
					
						
							|  |  |  |   }).config.system.build.openstackImage + "/nixos.qcow2"; | 
					
						
							| 
									
										
										
										
											2019-01-28 11:59:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-08 09:20:40 +01:00
										 |  |  |   sshKeys = import ./ssh-keys.nix pkgs; | 
					
						
							|  |  |  |   snakeOilPrivateKey = sshKeys.snakeOilPrivateKey.text; | 
					
						
							| 
									
										
										
										
											2020-02-02 09:48:11 +01:00
										 |  |  |   snakeOilPrivateKeyFile = pkgs.writeText "private-key" snakeOilPrivateKey; | 
					
						
							| 
									
										
										
										
											2019-02-08 09:20:40 +01:00
										 |  |  |   snakeOilPublicKey = sshKeys.snakeOilPublicKey; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-28 14:44:41 +01:00
										 |  |  | in { | 
					
						
							|  |  |  |   metadata = makeEc2Test { | 
					
						
							| 
									
										
										
										
											2019-01-28 15:09:48 +01:00
										 |  |  |     name = "openstack-ec2-metadata"; | 
					
						
							| 
									
										
										
										
											2019-01-28 11:59:18 +01:00
										 |  |  |     inherit image; | 
					
						
							| 
									
										
										
										
											2019-01-28 14:44:41 +01:00
										 |  |  |     sshPublicKey = snakeOilPublicKey; | 
					
						
							| 
									
										
										
										
											2019-01-28 11:59:18 +01:00
										 |  |  |     userData = ''
 | 
					
						
							|  |  |  |       SSH_HOST_ED25519_KEY_PUB:${snakeOilPublicKey} | 
					
						
							|  |  |  |       SSH_HOST_ED25519_KEY:${replaceStrings ["\n"] ["|"] snakeOilPrivateKey} | 
					
						
							|  |  |  |     '';
 | 
					
						
							|  |  |  |     script = ''
 | 
					
						
							| 
									
										
										
										
											2020-02-02 09:48:11 +01:00
										 |  |  |       machine.start() | 
					
						
							|  |  |  |       machine.wait_for_file("/etc/ec2-metadata/user-data") | 
					
						
							|  |  |  |       machine.wait_for_unit("sshd.service") | 
					
						
							| 
									
										
										
										
											2019-01-28 11:59:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 09:48:11 +01:00
										 |  |  |       machine.succeed("grep unknown /etc/ec2-metadata/ami-manifest-path") | 
					
						
							| 
									
										
										
										
											2019-01-28 11:59:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       # We have no keys configured on the client side yet, so this should fail | 
					
						
							| 
									
										
										
										
											2020-02-02 09:48:11 +01:00
										 |  |  |       machine.fail("ssh -o BatchMode=yes localhost exit") | 
					
						
							| 
									
										
										
										
											2019-01-28 11:59:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       # Let's install our client private key | 
					
						
							| 
									
										
										
										
											2020-02-02 09:48:11 +01:00
										 |  |  |       machine.succeed("mkdir -p ~/.ssh") | 
					
						
							| 
									
										
										
										
											2019-01-28 11:59:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 09:48:11 +01:00
										 |  |  |       machine.copy_from_host_via_shell( | 
					
						
							|  |  |  |           "${snakeOilPrivateKeyFile}", "~/.ssh/id_ed25519" | 
					
						
							|  |  |  |       ) | 
					
						
							|  |  |  |       machine.succeed("chmod 600 ~/.ssh/id_ed25519") | 
					
						
							| 
									
										
										
										
											2019-01-28 11:59:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       # We haven't configured the host key yet, so this should still fail | 
					
						
							| 
									
										
										
										
											2020-02-02 09:48:11 +01:00
										 |  |  |       machine.fail("ssh -o BatchMode=yes localhost exit") | 
					
						
							| 
									
										
										
										
											2019-01-28 11:59:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       # Add the host key; ssh should finally succeed | 
					
						
							| 
									
										
										
										
											2020-02-02 09:48:11 +01:00
										 |  |  |       machine.succeed( | 
					
						
							|  |  |  |           "echo localhost,127.0.0.1 ${snakeOilPublicKey} > ~/.ssh/known_hosts" | 
					
						
							|  |  |  |       ) | 
					
						
							|  |  |  |       machine.succeed("ssh -o BatchMode=yes localhost exit") | 
					
						
							| 
									
										
										
										
											2019-01-28 11:59:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       # Just to make sure resizing is idempotent. | 
					
						
							| 
									
										
										
										
											2020-02-02 09:48:11 +01:00
										 |  |  |       machine.shutdown() | 
					
						
							|  |  |  |       machine.start() | 
					
						
							|  |  |  |       machine.wait_for_file("/etc/ec2-metadata/user-data") | 
					
						
							| 
									
										
										
										
											2019-01-28 11:59:18 +01:00
										 |  |  |     '';
 | 
					
						
							| 
									
										
										
										
											2019-01-28 14:44:41 +01:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   userdata = makeEc2Test { | 
					
						
							| 
									
										
										
										
											2019-01-28 15:09:48 +01:00
										 |  |  |     name = "openstack-ec2-metadata"; | 
					
						
							| 
									
										
										
										
											2019-01-28 14:44:41 +01:00
										 |  |  |     inherit image; | 
					
						
							|  |  |  |     sshPublicKey = snakeOilPublicKey; | 
					
						
							|  |  |  |     userData = ''
 | 
					
						
							|  |  |  |       { pkgs, ... }: | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         imports = [ | 
					
						
							| 
									
										
										
										
											2019-01-28 15:09:48 +01:00
										 |  |  |           <nixpkgs/nixos/modules/virtualisation/openstack-config.nix> | 
					
						
							| 
									
										
										
										
											2019-01-28 14:44:41 +01:00
										 |  |  |           <nixpkgs/nixos/modules/testing/test-instrumentation.nix> | 
					
						
							|  |  |  |           <nixpkgs/nixos/modules/profiles/qemu-guest.nix> | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |         environment.etc.testFile = { | 
					
						
							|  |  |  |           text = "whoa"; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     '';
 | 
					
						
							|  |  |  |     script = ''
 | 
					
						
							| 
									
										
										
										
											2020-02-02 09:48:11 +01:00
										 |  |  |       machine.start() | 
					
						
							|  |  |  |       machine.wait_for_file("/etc/testFile") | 
					
						
							|  |  |  |       assert "whoa" in machine.succeed("cat /etc/testFile") | 
					
						
							| 
									
										
										
										
											2019-01-28 14:44:41 +01:00
										 |  |  |     '';
 | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | } |