Commit 568beb0b authored by David Johnson's avatar David Johnson

Add linktest.pl and more closely emulate the Ammon env via /etc/hosts.

parent 6b226688
Pipeline #3057 passed with stages
in 15 seconds
......@@ -258,14 +258,14 @@ for (k,v) in addrs.iteritems():
if params.bestEffort:
link.best_effort = True
iface = nodes[srcname].addInterface("if%s%s" % (dst,postfix))
iface = nodes[srcname].addInterface("%s%s" % (dst,postfix))
sdnum = addrs["node-%s-%s%s" % (src,dst,postfix)]
iface.addAddress(
IPv4Address("%s.%s" % (prefix4,str(sdnum)),prefixlen=bits4))
iface.addAddress(
IPv6Address("%s::%s" % (prefix6,hex(sdnum)[2:]),prefixlen=bits6))
link.addInterface(iface)
iface = nodes[dstname].addInterface("if%s%s" % (src,postfix))
iface = nodes[dstname].addInterface("%s%s" % (src,postfix))
dsnum = addrs["node-%s-%s%s" % (dst,src,postfix)]
iface.addAddress(
IPv4Address("%s.%s" % (prefix4,str(dsnum)),prefixlen=bits4))
......
#!/usr/bin/perl -w
use strict;
use English;
use Getopt::Std;
use Data::Dumper;
my $HOSTS = "/etc/hosts";
my $doint = 0;
sub usage {
print STDERR "Usage: $ARGV[0] [-hi] [node-to-skip node-to-skip ...]\n";
print STDERR " -h\tPrint this help.\n";
print STDERR " -i\tPing interfaces directly.\n";
exit(-1);
}
my $optlist = "hi";
my %options = ();
if (!getopts($optlist,\%options)) {
usage();
}
if (defined($options{'h'})) {
usage();
}
if (defined($options{'i'})) {
$doint = 1;
}
my @skipnodes = @ARGV;
my %hostmap = ();
open(FD,$HOSTS)
or die "open($HOSTS): $!\n";
while (my $line = <FD>) {
chomp($line);
if ($line =~ /^([0-9a-z:]+)\s+node-([0-9a-z]+)-([0-9a-z]+)$/) {
if (!exists($hostmap{$2})) {
$hostmap{$2} = {};
}
$hostmap{$2}{$3} = $1;
#print "$line\n";
}
elsif ($line =~ /^([0-9a-z:]+)\s+node-([0-9a-z]+)-([-0-9a-z]+)$/) {
if (!exists($hostmap{$2})) {
$hostmap{$2} = {};
}
$hostmap{$2}{$3} = $1;
#print "$line\n";
}
}
close(FD);
#print Dumper(%hostmap)."\n";
my ($f,$s) = (0,0);
for my $dn (sort(keys(%hostmap))) {
for my $sn (sort(keys(%{$hostmap{$dn}}))) {
my $daddr = $hostmap{$dn}{$sn};
my $dest = "node-$dn-$sn";
my ($srcnode,$dstnode);
if ($sn =~ /^([0-9a-z]+)-(\d+)$/) {
$srcnode = "node-$1";
$dstnode = "node-$dn";
}
else {
$srcnode = "node-$sn";
$dstnode = "node-$dn";
}
if ($doint) {
$dest = "node-$dn-$sn";
$srcnode = "node-$dn";
$dstnode = $srcnode;
}
my $cmd = "ssh $srcnode ping6 -n -c 4 -i 0.25 -t 2 $dest";
print "$srcnode\t-> $dstnode\t$dest ($daddr):\t";
if (grep {$_ eq $srcnode} @skipnodes) {
print "SKIPPED ($srcnode)\n";
next;
}
if (grep {$_ eq $dstnode} @skipnodes) {
print "SKIPPED ($dstnode)\n";
next;
}
my @lines = `$cmd 2>&1`;
if ($?) {
print "FAILURE\n";
print STDERR " ($cmd)\n";
$f++;
}
else {
print "SUCCESS\n";
$s++;
}
if (@lines > 0) {
for (my $i = @lines - 1; $i >= 0; $i--) {
chomp($lines[$i]);
if ($lines[$i] ne "") {
print " " . $lines[$i] . "\n";
last;
}
}
}
}
}
print "\nSUMMARY: $s succeeded, $f failed.\n";
exit($f);
......@@ -49,19 +49,22 @@ if not node:
print "Setting addresses for %s ..." % (hostname,)
hostslines = []
for i in node.findall("g:interface",namespaces=nsmap):
mac = i.get("mac_address")
if not mac:
continue
dev = findif(mac=mac)
if not dev:
continue
dev = None
if mac:
dev = findif(mac=mac)
addrs = []
for a in i.findall("c:ip",namespaces=nsmap):
if a.get("type") != "ipv6":
continue
addrs.append("%s/%s" % (a.get("address"),a.get("prefixlen")))
if addrs:
(addr,prefixlen) = (a.get("address"),a.get("prefixlen"))
addrs.append("%s/%s" % (addr,prefixlen))
# Save for /etc/hosts
name = i.client_id.replace(':','-')
hostslines.append("%s\t%s\n" % (addr,name))
if dev and addrs:
print "Enabling overall ipv6 forwarding and segment routing..."
os.system("sysctl -w net.ipv6.conf.all.forwarding=1")
os.system("sysctl -w net.ipv6.conf.all.seg6_enabled=1")
......@@ -80,3 +83,9 @@ for i in node.findall("g:interface",namespaces=nsmap):
os.system("ip -6 addr add %s dev %s" % (a,dev))
print "Bringing up interface %s ..." % (dev,)
os.system("ip link set %s up" % (dev,))
print "Writing to /etc/hosts..."
fd = open("/etc/hosts","a")
for line in hostslines:
fd.write(line)
fd.close()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment