Hydra::Helper::Nix::getMachines: add a test

[?]
Oct 24, 2021, 2:53 AM
QTZ6UUOMFFHMHEMZ2UKRHRZAITXO3WBCXAD3EGLRNKT52K7SANZAC

Dependencies

  • [2] S2KNQCPB NixExprs: extract the `escape` function and test it
  • [3] 6MNLYIXO perlcritic: explicitly assign the result of readdir/file reads
  • [4] HTL6HIBM machine-status: Read /etc/nix.machines instead of using the BuildMachines table
  • [5] L6PVAEWJ perlcritic: don't open files as bare words
  • [6] M4FPGVN4 perlcritic: make all open() calls three-argument
  • [7] O3NM62IZ Support multiple machines files
  • [*] 2GK5DOU7 * Downloading closures.

Change contents

  • replacement in src/lib/Hydra/Helper/Nix.pm at line 347
    [3.37][4.669:741](),[4.171][4.669:741](),[4.669][4.669:741]()
    chomp;
    s/\#.*$//g;
    next if /^\s*$/;
    [3.37]
    [3.38]
    chomp($line);
    $line =~ s/\#.*$//g;
    next if $line =~ /^\s*$/;
  • edit in src/lib/Hydra/Helper/Nix.pm at line 351
    [3.82]
    [4.782]
    if (!defined($tokens[5]) || $tokens[5] eq "-") {
    $tokens[5] = "";
    }
  • edit in src/lib/Hydra/Helper/Nix.pm at line 356
    [4.848]
    [4.848]
    if (!defined($tokens[6]) || $tokens[6] eq "-") {
    $tokens[6] = "";
    }
  • file addition: Nix.t (----------)
    [2.981]
    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;