Author: sandervanderburg
Date: Mon Feb 21 15:33:02 2011
New Revision: 26042
URL: https://svn.nixos.org/websvn/nix/?rev=26042&sc=1
Log:
Implemented order function + testcase
Added:
disnix/dydisnix/trunk/tests/qos/qos-order.nix
Modified:
disnix/dydisnix/trunk/data/intfilters.nix
disnix/dydisnix/trunk/release.nix
disnix/dydisnix/trunk/tests/infrastructure.nix
Modified: disnix/dydisnix/trunk/data/intfilters.nix
==============================================================================
--- disnix/dydisnix/trunk/data/intfilters.nix Mon Feb 21 14:35:42 2011
(r26041)
+++ disnix/dydisnix/trunk/data/intfilters.nix Mon Feb 21 15:33:02 2011
(r26042)
@@ -1,7 +1,7 @@
{lib}:
rec {
- inherit (builtins) listToAttrs attrNames getAttr hasAttr;
+ inherit (builtins) listToAttrs attrNames getAttr hasAttr lessThan;
inherit (lib) filter elem;
filterDerivations = services:
@@ -101,4 +101,15 @@
}
) (attrNames distribution))
;
+
+ order = {infrastructure, distribution, targetProperty}:
+ lib.mapAttrs (serviceName: mapping:
+ lib.sort (targetAName: targetBName:
+ let
+ targetA = getAttr targetAName infrastructure;
+ targetB = getAttr targetBName infrastructure;
+ in
+ lessThan (getAttr targetProperty targetA) (getAttr targetProperty
targetB) ) mapping
+ ) distribution
+ ;
}
Modified: disnix/dydisnix/trunk/release.nix
==============================================================================
--- disnix/dydisnix/trunk/release.nix Mon Feb 21 14:35:42 2011 (r26041)
+++ disnix/dydisnix/trunk/release.nix Mon Feb 21 15:33:02 2011 (r26042)
@@ -181,6 +181,24 @@
die "line 17 should contain testtarget2!\n";
}
+ # Execute order. The targets are order by looking to the priority
+ # attribute. The order of the targets should be reversed.
+ # This test should succeed.
+
+ my $result =
$machine->mustSucceed("NIXPKGS_ALL=${nixpkgs}/pkgs/top-level/all-packages.nix
dydisnix-gendist -s ${tests}/services.nix -i ${tests}/infrastructure.nix -q
${tests}/qos/qos-order.nix");
+ my @distribution = split('\n', $machine->mustSucceed("cat
$result"));
+
+ if(@distribution[7] =~ /testtarget2/) {
+ print "line 7 contains testtarget2!\n";
+ } else {
+ print "line 7 should contain testtarget2!\n";
+ }
+
+ if(@distribution[8] =~ /testtarget2/) {
+ print "line 8 contains testtarget1!\n";
+ } else {
+ print "line 8 should contain testtarget1!\n";
+ }
# Execute the highest bidder method. testService1 should be
# assigned to testtarget2. testService2 should be assigned to
# targettarget1. testService3 should be assigned to testtarget2.
Modified: disnix/dydisnix/trunk/tests/infrastructure.nix
==============================================================================
--- disnix/dydisnix/trunk/tests/infrastructure.nix Mon Feb 21 14:35:42
2011 (r26041)
+++ disnix/dydisnix/trunk/tests/infrastructure.nix Mon Feb 21 15:33:02
2011 (r26042)
@@ -6,6 +6,7 @@
zone = "US";
cost = 100;
access = "public";
+ priority = 2;
};
testtarget2 = {
@@ -15,5 +16,6 @@
zone = "Europe";
cost = 200;
access = "private";
+ priority = 1;
};
}
Added: disnix/dydisnix/trunk/tests/qos/qos-order.nix
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ disnix/dydisnix/trunk/tests/qos/qos-order.nix Mon Feb 21 15:33:02
2011 (r26042)
@@ -0,0 +1,7 @@
+{services, infrastructure, initialDistribution, previousDistribution, filters}:
+
+filters.order {
+ inherit infrastructure;
+ distribution = initialDistribution;
+ targetProperty = "priority";
+}
_______________________________________________
nix-commits mailing list
[email protected]
http://mail.cs.uu.nl/mailman/listinfo/nix-commits