From 165089f9d7419df1bda1d33ebc8b08a4a9be1c20 Mon Sep 17 00:00:00 2001 From: Antoine Eiche Date: Thu, 29 Dec 2016 15:29:51 +0100 Subject: [PATCH] nixos/glance: add test The test starts the glance service, creates a nixos image and ensures Glance list it. Note the test also starts the Keystone service since it is required by Glance. --- nixos/release.nix | 1 + nixos/tests/glance.nix | 77 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 nixos/tests/glance.nix diff --git a/nixos/release.nix b/nixos/release.nix index 366eecf773e2..dfa9b67654fb 100644 --- a/nixos/release.nix +++ b/nixos/release.nix @@ -242,6 +242,7 @@ in rec { tests.firewall = callTest tests/firewall.nix {}; tests.fleet = hydraJob (import tests/fleet.nix { system = "x86_64-linux"; }); #tests.gitlab = callTest tests/gitlab.nix {}; + tests.glance = callTest tests/glance.nix {}; tests.gocd-agent = callTest tests/gocd-agent.nix {}; tests.gocd-server = callTest tests/gocd-server.nix {}; tests.gnome3 = callTest tests/gnome3.nix {}; diff --git a/nixos/tests/glance.nix b/nixos/tests/glance.nix new file mode 100644 index 000000000000..992b77227a4b --- /dev/null +++ b/nixos/tests/glance.nix @@ -0,0 +1,77 @@ +{ system ? builtins.currentSystem }: + +with import ../lib/testing.nix { inherit system; }; +with pkgs.lib; + +let + glanceMysqlPassword = "glanceMysqlPassword"; + glanceAdminPassword = "glanceAdminPassword"; + + createDb = pkgs.writeText "db-provisionning.sql" '' + create database keystone; + GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' IDENTIFIED BY 'keystone'; + GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%' IDENTIFIED BY 'keystone'; + + create database glance; + GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY '${glanceMysqlPassword}'; + GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY '${glanceMysqlPassword}'; + ''; + + image = + (import ../lib/eval-config.nix { + inherit system; + modules = [ ../../nixos/modules/virtualisation/nova-image.nix ]; + }).config.system.build.novaImage; + + # The admin keystone account + adminOpenstackCmd = "OS_TENANT_NAME=admin OS_USERNAME=admin OS_PASSWORD=keystone OS_AUTH_URL=http://localhost:5000/v3 OS_IDENTITY_API_VERSION=3 openstack"; + +in makeTest { + meta = with pkgs.stdenv.lib.maintainers; { + maintainers = [ lewo ]; + }; + machine = + { config, pkgs, ... }: + { + services.mysql.enable = true; + services.mysql.package = pkgs.mysql; + services.mysql.initialScript = createDb; + + virtualisation = { + openstack.keystone = { + enable = true; + database.password = { value = "keystone"; storage = "fromNixStore"; }; + adminToken = { value = "adminToken"; storage = "fromNixStore"; }; + bootstrap.enable = true; + bootstrap.adminPassword = { value = "keystone"; storage = "fromNixStore"; }; + }; + + openstack.glance = { + enable = true; + database.password = { value = glanceMysqlPassword; storage = "fromNixStore"; }; + servicePassword = { value = glanceAdminPassword; storage = "fromNixStore"; }; + + bootstrap = { + enable = true; + keystoneAdminPassword = { value = "keystone"; storage = "fromNixStore"; }; + }; + }; + + memorySize = 2096; + diskSize = 4 * 1024; + }; + + environment.systemPackages = with pkgs.pythonPackages; with pkgs; [ + openstackclient + ]; + }; + + testScript = + '' + $machine->waitForUnit("glance-api.service"); + + # Since Glance api can take time to start, we retry until success + $machine->waitUntilSucceeds("${adminOpenstackCmd} image create nixos --file ${image}/nixos.img --disk-format qcow2 --container-format bare --public"); + $machine->succeed("${adminOpenstackCmd} image list") =~ /nixos/ or die; + ''; +}