From b81712433762463723e277c2e680d0667f20d19c Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Sat, 23 Oct 2021 22:53:55 -0400 Subject: [PATCH 1/2] Hydra::Helper::Nix::getMachines: add a test Fix parsing breakage from #1003: assigning the lines to $lines broke chomp and the filters. This test validates the parsing works as expected, and also fixes a minor bug where '-' in features isn't pruned, like in the C++ repo. --- src/lib/Hydra/Helper/Nix.pm | 14 +++++++-- t/Helper/Nix.t | 59 +++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 t/Helper/Nix.t diff --git a/src/lib/Hydra/Helper/Nix.pm b/src/lib/Hydra/Helper/Nix.pm index 3881acbc..09908c92 100644 --- a/src/lib/Hydra/Helper/Nix.pm +++ b/src/lib/Hydra/Helper/Nix.pm @@ -344,11 +344,19 @@ sub getMachines { next unless -e $machinesFile; open(my $conf, "<", $machinesFile) or die; while (my $line = <$conf>) { - chomp; - s/\#.*$//g; - next if /^\s*$/; + chomp($line); + $line =~ s/\#.*$//g; + next if $line =~ /^\s*$/; my @tokens = split /\s/, $line; + + if (!defined($tokens[5]) || $tokens[5] eq "-") { + $tokens[5] = ""; + } my @supportedFeatures = split(/,/, $tokens[5] || ""); + + if (!defined($tokens[6]) || $tokens[6] eq "-") { + $tokens[6] = ""; + } my @mandatoryFeatures = split(/,/, $tokens[6] || ""); $machines{$tokens[0]} = { systemTypes => [ split(/,/, $tokens[1]) ] diff --git a/t/Helper/Nix.t b/t/Helper/Nix.t new file mode 100644 index 00000000..efb073de --- /dev/null +++ b/t/Helper/Nix.t @@ -0,0 +1,59 @@ +use strict; +use warnings; +use Setup; +use File::Temp; + +my %ctx = test_init(); + +require Hydra::Helper::Nix; + +use Test2::V0; + +my $dir = File::Temp->newdir(); +my $machines = "$dir/machines"; + +$ENV{'NIX_REMOTE_SYSTEMS'} = $machines; + +open(my $fh, '>', $machines) or die "Could not open file '$machines' $!"; +print $fh q| +# foobar +root@ip x86_64-darwin /sshkey 15 15 big-parallel,kvm,nixos-test - base64key + +# Macs +# root@bar x86_64-darwin /sshkey 6 1 big-parallel +root@baz aarch64-darwin /sshkey 4 1 big-parallel + +root@bux i686-linux,x86_64-linux /var/sshkey 1 1 kvm,nixos-test benchmark + +|; +close $fh; + +is(Hydra::Helper::Nix::getMachines(), { + 'root@ip' => { + 'systemTypes' => ["x86_64-darwin"], + 'sshKeys' => '/sshkey', + 'maxJobs' => 15, + 'speedFactor' => 15, + 'supportedFeatures' => ["big-parallel", "kvm", "nixos-test" ], + 'mandatoryFeatures' => [ ], + }, + 'root@baz' => { + 'systemTypes' => [ "aarch64-darwin" ], + 'sshKeys' => '/sshkey', + 'maxJobs' => 4, + 'speedFactor' => 1, + 'supportedFeatures' => ["big-parallel"], + 'mandatoryFeatures' => [], + }, + 'root@bux' => { + 'systemTypes' => [ "i686-linux", "x86_64-linux" ], + 'sshKeys' => '/var/sshkey', + 'maxJobs' => 1, + 'speedFactor' => 1, + 'supportedFeatures' => [ "kvm", "nixos-test", "benchmark" ], + 'mandatoryFeatures' => [ "benchmark" ], + }, + +}, ":)"); + +done_testing; From 5fbf1470bd3c784f1b50f874dcf70d99a9867e00 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Sun, 24 Oct 2021 21:24:24 -0400 Subject: [PATCH 2/2] (perl) machines file: support machine lines with multiple spaces between fields --- src/lib/Hydra/Helper/Nix.pm | 2 +- t/Helper/Nix.t | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lib/Hydra/Helper/Nix.pm b/src/lib/Hydra/Helper/Nix.pm index 09908c92..a8ba1ff3 100644 --- a/src/lib/Hydra/Helper/Nix.pm +++ b/src/lib/Hydra/Helper/Nix.pm @@ -347,7 +347,7 @@ sub getMachines { chomp($line); $line =~ s/\#.*$//g; next if $line =~ /^\s*$/; - my @tokens = split /\s/, $line; + my @tokens = split /\s+/, $line; if (!defined($tokens[5]) || $tokens[5] eq "-") { $tokens[5] = ""; diff --git a/t/Helper/Nix.t b/t/Helper/Nix.t index efb073de..788ae685 100644 --- a/t/Helper/Nix.t +++ b/t/Helper/Nix.t @@ -24,6 +24,7 @@ root@ip x86_64-darwin /sshkey 15 15 big-parallel,kvm,nixos-test - base64key root@baz aarch64-darwin /sshkey 4 1 big-parallel root@bux i686-linux,x86_64-linux /var/sshkey 1 1 kvm,nixos-test benchmark +root@lotsofspace i686-linux,x86_64-linux /var/sshkey 1 1 kvm,nixos-test benchmark |; close $fh; @@ -53,6 +54,14 @@ is(Hydra::Helper::Nix::getMachines(), { 'supportedFeatures' => [ "kvm", "nixos-test", "benchmark" ], 'mandatoryFeatures' => [ "benchmark" ], }, + 'root@lotsofspace' => { + 'systemTypes' => [ "i686-linux", "x86_64-linux" ], + 'sshKeys' => '/var/sshkey', + 'maxJobs' => 1, + 'speedFactor' => 1, + 'supportedFeatures' => [ "kvm", "nixos-test", "benchmark" ], + 'mandatoryFeatures' => [ "benchmark" ], + }, }, ":)");