From 0fafd7fab660ac66d532d4514083943214d54f14 Mon Sep 17 00:00:00 2001 From: XuWei Date: Thu, 30 Jun 2016 21:45:44 -0400 Subject: [PATCH 1/2] xCAT probe discovery dhcp dynamic check --- xCAT-probe/subcmds/discovery | 82 +++++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/xCAT-probe/subcmds/discovery b/xCAT-probe/subcmds/discovery index b0a43e958..8e037b96d 100755 --- a/xCAT-probe/subcmds/discovery +++ b/xCAT-probe/subcmds/discovery @@ -284,6 +284,86 @@ sub check_genesis_file { sub dhcp_dynamic_range_check { my $nets = shift; my $rst = 0; + + my $dhcpconfig = "/etc/dhcp/dhcpd.conf"; + my $os = probe_utils->get_os(); + + if ($os =~ "unknown") { + probe_utils->send_msg("$output", "d", "The OS is not supported.") if ($verbose); + return 1; + } elsif ($os =~ "ubuntu") { + if (! -e "/etc/dhcp") { + $dhcpconfig = "/etc/dhcp3/dhcpd.conf"; + } + } + + my $config_line; + my $net_ip; + my $net_mask; + my $is_match; + my $dynamic_range; + my $net_file; + my $arch = `uname -i`; + chomp($arch); + my $tftpdir = `tabdump site | grep "tftpdir" | awk -F "," '{print \$2}'`; + chomp($tftpdir); + $tftpdir =~ s/"//g; + + foreach $net (@$nets){ + ($net_ip, $net_mask) = split ('/', $net); + $net_str = "subnet $net_ip netmask $net_mask"; + + $is_match = 0; + $dynamic_range = ""; + + unless (open (FILE, $dhcpconfig)) { + probe_utils->send_msg("$output", "d", "Cannot open file $dhcpconfig.") if ($verbose); + return 1; + } + + while ($config_line = ) { + chomp($config_line); + $config_line =~ s/^\s+|\s+$//g; + + if ($config_line =~ /^$net_str/) { + $is_match = 1; + probe_utils->send_msg("$output", "d", "The net $net is matched.") if ($verbose); + } + + if ($config_line =~ /subnet_end/) { + if ($is_match eq 0) { + probe_utils->send_msg("$output", "d", "There is no subnet match net $net.") if ($verbose); + $rst = 1; + next; + } + unless ($dynamic_range) { + probe_utils->send_msg("$output", "d", "Dynamic range for net $net did not be configured.") if ($verbose); + $rst = 1; + } + } + + if (($config_line =~ /^range dynamic-bootp/) and ($is_match eq 1)) { + my @range_tmp = split(' ', $config_line); + $dynamic_range = "$range_tmp[2]-$range_tmp[3]"; + probe_utils->send_msg("$output", "d", "Dynamic range for net $net is $dynamic_range.") if ($verbose); + } + } + + my $net_cdir = xCAT::NetworkUtils::formatNetmask($net_mask, 0, 1); + if ($arch =~ /ppc64/i) { + $net_file = "$tftpdir/pxelinux.cfg/p/$net_ip"."_$net_cdir"; + } else { + $net_file = "$tftpdir/xcat/xnba/nets/$net_ip"."_$net_cdir.uefi"; + } + + if (-e "$net_file") { + probe_utils->send_msg("$output", "d", "The genesis file $net_file for net $net exists.") if ($verbose); + } else { + probe_utils->send_msg("$output", "d", "The genesis file $net_file for net $net dose not exist.") if ($verbose); + $rst = 1; + } + } + return $rst; } @@ -1001,7 +1081,7 @@ if (!$no_pre_check) { $rst = do_pre_check(); exit 1 if ($rst); } - +exit; $rst = do_monitor(); exit $rst; From de8bc849acb756324ef2b639325d1a0ff5f6d5f0 Mon Sep 17 00:00:00 2001 From: XuWei Date: Thu, 30 Jun 2016 21:47:32 -0400 Subject: [PATCH 2/2] xCAT probe discovery dhcp dynamic check --- xCAT-probe/subcmds/discovery | 120 ++++++++++++++++++----------------- 1 file changed, 63 insertions(+), 57 deletions(-) diff --git a/xCAT-probe/subcmds/discovery b/xCAT-probe/subcmds/discovery index 8e037b96d..b8ab90c5b 100755 --- a/xCAT-probe/subcmds/discovery +++ b/xCAT-probe/subcmds/discovery @@ -273,8 +273,8 @@ sub check_genesis_file { 1. check if there are dynamic range for specific networks defineded in dhcp conf file 2. check if these specific networks have corresponding genesis configuration Arguments: - networks: A Comma separated list of networks. Every network is combined by network address and mask(i.e. network/mask). - For example: 10.0.0.0/255.0.0.0,50.1.0.0/255.255.0.0 + networks: Array of networks. Every network is combined by network address and mask(i.e. network/mask). + For example: (10.0.0.0/255.0.0.0, 50.1.0.0/255.255.0.0) Returns: 0 : pass 1 : failed @@ -285,71 +285,77 @@ sub dhcp_dynamic_range_check { my $nets = shift; my $rst = 0; - my $dhcpconfig = "/etc/dhcp/dhcpd.conf"; - my $os = probe_utils->get_os(); + my $dhcpconfig; + if (-e "/etc/dhcp/dhcpd.conf"){ + $dhcpconfig = "/etc/dhcp/dhcpd.conf"; + } elsif (-e "/etc/dhcp3/dhcpd.conf"){ + $dhcpconfig = "/etc/dhcp3/dhcpd.conf"; + } - if ($os =~ "unknown") { - probe_utils->send_msg("$output", "d", "The OS is not supported.") if ($verbose); + unless ($dhcpconfig) { + probe_utils->send_msg("$output", "d", "Cannot find the dhcpd.conf file.") if ($verbose); return 1; - } elsif ($os =~ "ubuntu") { - if (! -e "/etc/dhcp") { - $dhcpconfig = "/etc/dhcp3/dhcpd.conf"; - } } my $config_line; - my $net_ip; - my $net_mask; - my $is_match; + my $subnet; my $dynamic_range; - my $net_file; + my %subnet_hash; + + unless (open (FILE, $dhcpconfig)) { + probe_utils->send_msg("$output", "d", "Cannot open file $dhcpconfig.") if ($verbose); + ($net_ip, $net_mask) = split ('/', $net); + return 1; + } + + while ($config_line = ) { + chomp($config_line); + $config_line =~ s/^\s+|\s+$//g; + + if ($config_line =~ /^subnet\s+(\d+\.\d+\.\d+\.\d+)\s+netmask\s+(\d+\.\d+\.\d+\.\d+)\s+/) { + $subnet = "$1/$2"; + $subnet_hash{$subnet} = "unknown"; + } + if ($config_line =~ /subnet_end/) { + $subnet_hash{$subnet} = $dynamic_range if ($dynamic_range); + $subnet = ""; + $dynamic_range = ""; + } + if ($config_line =~ /^range dynamic-bootp (\d+.\d+.\d+.\d+) (\d+.\d+.\d+.\d+)/) { + $dynamic_range = "$1-$2"; + } + } + + my $net_ip; + my $netmask; + my $netfile; + my $net_cdir; my $arch = `uname -i`; chomp($arch); - my $tftpdir = `tabdump site | grep "tftpdir" | awk -F "," '{print \$2}'`; + my $tftpdir = `lsdef -t site -i tftpdir -c | awk -F "=" '{print \$2}'`; chomp($tftpdir); - $tftpdir =~ s/"//g; + unless ($tftpdir) { + $tftpdir = "/tftpboot"; + } + + foreach my $net (@$nets){ + + if ( !exists($subnet_hash{$net})) { + probe_utils->send_msg("$output", "d", "The net $net is not matched.") if ($verbose); + $rst = 1; + next; + } + + if ($subnet_hash{$net} ne "unknown") { + probe_utils->send_msg("$output", "d", "Dynamic range for net $net is $subnet_hash{$net}.") if ($verbose); + } else { + probe_utils->send_msg("$output", "d", "Dynamic range for net $net did not be configured.") if ($verbose); + $rst = 1; + next; + } - foreach $net (@$nets){ ($net_ip, $net_mask) = split ('/', $net); - $net_str = "subnet $net_ip netmask $net_mask"; - - $is_match = 0; - $dynamic_range = ""; - - unless (open (FILE, $dhcpconfig)) { - probe_utils->send_msg("$output", "d", "Cannot open file $dhcpconfig.") if ($verbose); - return 1; - } - - while ($config_line = ) { - chomp($config_line); - $config_line =~ s/^\s+|\s+$//g; - - if ($config_line =~ /^$net_str/) { - $is_match = 1; - probe_utils->send_msg("$output", "d", "The net $net is matched.") if ($verbose); - } - - if ($config_line =~ /subnet_end/) { - if ($is_match eq 0) { - probe_utils->send_msg("$output", "d", "There is no subnet match net $net.") if ($verbose); - $rst = 1; - next; - } - unless ($dynamic_range) { - probe_utils->send_msg("$output", "d", "Dynamic range for net $net did not be configured.") if ($verbose); - $rst = 1; - } - } - - if (($config_line =~ /^range dynamic-bootp/) and ($is_match eq 1)) { - my @range_tmp = split(' ', $config_line); - $dynamic_range = "$range_tmp[2]-$range_tmp[3]"; - probe_utils->send_msg("$output", "d", "Dynamic range for net $net is $dynamic_range.") if ($verbose); - } - } - - my $net_cdir = xCAT::NetworkUtils::formatNetmask($net_mask, 0, 1); + $net_cdir = xCAT::NetworkUtils::formatNetmask($net_mask, 0, 1); if ($arch =~ /ppc64/i) { $net_file = "$tftpdir/pxelinux.cfg/p/$net_ip"."_$net_cdir"; } else { @@ -1081,7 +1087,7 @@ if (!$no_pre_check) { $rst = do_pre_check(); exit 1 if ($rst); } -exit; + $rst = do_monitor(); exit $rst;