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.
This commit is contained in:
Antoine Eiche 2016-12-29 15:29:51 +01:00
parent 6c94d6437d
commit 165089f9d7
2 changed files with 78 additions and 0 deletions

View file

@ -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 {};

77
nixos/tests/glance.nix Normal file
View file

@ -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;
'';
}