Experiment.pm 1.57 KB
Newer Older
Kevin Tew's avatar
Kevin Tew committed
1
#!/usr/bin/perl
2
use SemiModern::Perl;
Kevin Tew's avatar
Kevin Tew committed
3 4

package TestBed::TestSuite::Experiment;
5 6
use Mouse;
use TestBed::XMLRPC::Client::Experiment;
Kevin Tew's avatar
Kevin Tew committed
7
use Tools::PingTest;
8 9
use Tools::TBSSH;
use Data::Dumper;
Kevin Tew's avatar
Kevin Tew committed
10

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
extends 'Exporter', 'TestBed::XMLRPC::Client::Experiment';
require Exporter;
our @EXPORT;

push @EXPORT, qw(e ep launchpingkill launchpingswapkill);

sub ep { TestBed::TestSuite::Experiment->new }
sub e  { TestBed::TestSuite::Experiment->new('pid'=> shift, 'eid' => shift) }

sub ping_test {
  my ($e) = @_;
  my $nodes = $e->nodeinfo();
  for (@$nodes) {
    ping($_);
  }
}

sub ssh_hostname_test {
  my ($e) = @_;
  my $nodes = $e->nodeinfo();
  for (@$nodes) {
    Tools::TBSSH::sshhostname($_, $TBConfig::EMULAB_USER);
  }
}

sub trytest(&$) {
  eval {$_[0]->()};
  if ($@) {
    say $@;
    $_[1]->end;
    0; 
  }
  else {
    1;
  }
}

sub launchpingkill {
  my ($pid, $eid, $ns) = @_;
  my $e = e($pid, $eid);
  trytest {
    $e->batchexp_ns_wait($ns) && die "batchexp $eid failed";
    $e->ping_test             && die "connectivity test $eid failed";
    $e->end                   && die "exp end $eid failed";
  } $e;
Kevin Tew's avatar
Kevin Tew committed
56 57 58 59 60
}

sub launchpingswapkill {
  my ($pid, $eid, $ns) = @_;
  my $e = e($pid, $eid);
61 62 63 64 65 66 67 68
  trytest {
    $e->batchexp_ns_wait($ns) && die "batchexp $eid failed";
    $e->ping_test             && die "connectivity test $eid failed";
    $e->swapout_wait          && die "swap out $eid failed";
    $e->swapin_wait           && die "swap in $eid failed";
    $e->ping_test             && die "connectivity test $eid failed";
    $e->end                   && die "exp end $eid failed";
  } $e;
Kevin Tew's avatar
Kevin Tew committed
69 70
}
1;