From d5d91d341193e669a01804381a1ea054391a8d88 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Fri, 28 Sep 2018 12:51:37 +0200 Subject: [PATCH] TT#44257 Improve reporting on missing interface definitions When we declare an interface in the interfaces key, we should have an interface definition. Change-Id: Idc406ecd9a561c5c522b3b802c922b799c2a12d6 --- sbin/ngcp-network-validator | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sbin/ngcp-network-validator b/sbin/ngcp-network-validator index f9a13c4a..1a97755d 100755 --- a/sbin/ngcp-network-validator +++ b/sbin/ngcp-network-validator @@ -67,6 +67,7 @@ my $schema_iface = YAML::XS::LoadFile($schema_tmpl_iface_file) # Data to track some manual out-of-schema validation. my %miss_peer; +my %miss_iface; my %dupe_dbnode; my %dupe_ip; my %dupe_mac; @@ -122,6 +123,11 @@ foreach my $hostname (sort keys %{$yaml->{hosts}}) { # Fill the interface entries. foreach my $iface (sort @{$host->{interfaces}}) { + if (not exists $host->{$iface}) { + $miss_iface{$iface}++; + next; + } + # Manual interface checks. if (defined $host->{$iface}->{ip} and $host->{$iface}->{ip} ne '' and @@ -202,6 +208,8 @@ foreach my $hostname (sort keys %{$yaml->{hosts}}) { my $hostmap = $schema->{mapping}->{hosts}->{mapping}->{$hostname}; foreach my $iface (sort @{$host->{interfaces}}) { + next unless exists $host->{$iface}; + foreach my $slave (split ' ', $host->{$iface}->{bond_slaves} // '') { my $slavemap = $hostmap->{mapping}->{$slave}; @@ -236,6 +244,7 @@ eval { # Perform out-of-schema checks. $errors += miss_check(\%miss_peer, '[/hosts/] Missing peer'); +$errors += miss_check(\%miss_iface, '[/hosts//] Missing definition for interface declared in [/hosts//interfaces]'); $errors += dupe_check(\%dupe_dbnode, '[/hosts//dbnode] Duplicate dbnode index'); $errors += dupe_check(\%dupe_ip, '[/hosts///ip] Duplicate interface IP'); $errors += dupe_check(\%dupe_mac, '[/hosts///hwaddr] Duplicate interface MAC');