From 823a1530ee07b05992eadeb91097e7a1c6462266 Mon Sep 17 00:00:00 2001 From: xuweibj Date: Fri, 12 Oct 2018 01:45:07 -0400 Subject: [PATCH] fix issue 5694, not try to install tree for xCAT-probe --- xCAT-probe/debian/control | 2 +- xCAT-probe/lib/perl/probe_utils.pm | 66 ++++++++++++++++++++++++++++++ xCAT-probe/subcmds/xcatmn | 24 +++++++++-- xCAT-probe/xCAT-probe.spec | 1 - 4 files changed, 87 insertions(+), 6 deletions(-) diff --git a/xCAT-probe/debian/control b/xCAT-probe/debian/control index bd70c6f31..7140f1513 100644 --- a/xCAT-probe/debian/control +++ b/xCAT-probe/debian/control @@ -8,5 +8,5 @@ Standards-Version: 3.9.4 Package: xcat-probe Architecture: all Depends: ${perl:Depends} -Recommends: wget, dnsutils, tftp-hpa, tcpdump, tree +Recommends: wget, dnsutils, tftp-hpa, tcpdump Description: Provides a toolkit to probe possible issues in xCAT diff --git a/xCAT-probe/lib/perl/probe_utils.pm b/xCAT-probe/lib/perl/probe_utils.pm index 12ea2938e..039a9c8e7 100644 --- a/xCAT-probe/lib/perl/probe_utils.pm +++ b/xCAT-probe/lib/perl/probe_utils.pm @@ -697,6 +697,72 @@ sub convert_second_to_time { #------------------------------------------ +=head3 + Description: + Call get_files_recursive to get all files under given dir, + and save to target file + Arguments: + dir: the dir want to get files + target_file: the file to save files list + +=cut + +#------------------------------------------ +sub list_files_to_file { + my $src_dir = shift; + $src_dir = shift if (($src_dir) && ($src_dir =~ /probe_utils/)); + my $target_file = shift; + my $errormsg_ref = shift; + + my @files = (); + get_files_recursive("$src_dir", \@files); + my $all_file = join("\n", @files); + + if (!open f,"> $target_file") { + $$errormsg_ref = "Can not open file $target_file to save files list"; + return 1; + } + print f $all_file; + close f; + + return 0; +} + +#------------------------------------------ + +=head3 + Description: + Get all files under the given dir + Arguments: + dir: the dir want to get files + files_path_ref: list of all files +=cut + +#------------------------------------------ +sub get_files_recursive { + my $dir = shift; + my $files_path_ref = shift; + + my $fd = undef; + opendir($fd, $dir); + for (; ;) + { + my $direntry = readdir($fd); + last unless (defined($direntry)); + next if ($direntry =~ m/^\.\w*/); + next if ($direntry eq '..'); + my $target = "$dir/$direntry"; + if (-d $target) { + get_files_recursive($target, $files_path_ref); + } else { + push(@{$files_path_ref}, glob("$target\n")); + } + } + closedir($fd); +} + +#------------------------------------------ + =head3 Description: print table diff --git a/xCAT-probe/subcmds/xcatmn b/xCAT-probe/subcmds/xcatmn index 1bb84e807..9264a5174 100755 --- a/xCAT-probe/subcmds/xcatmn +++ b/xCAT-probe/subcmds/xcatmn @@ -579,13 +579,29 @@ sub check_directory { $flag = "w" if (!$rst); $rst = 1; } else { - my $diffout = `bash -c 'diff <(tree -i --noreport $sitetable_ref->{$dir}) <(tree -i --noreport $tmpdir) | wc -l'`; - if ($diffout > 4) { - push @$error_ref, "$dir '$sitetable_ref->{$dir}' is not the same with MN's, may be error"; + my $dir_list_file = "/tmp/$dir" . "_list"; + my $mnt_list_file = $tmpdir . "_list"; + my $error; + if (probe_utils->list_files_to_file($sitetable_ref->{$dir}, $dir_list_file, \$error)) { + push @$error_ref, "$error"; $flag = "w" if (!$rst); $rst = 1; + } elsif (probe_utils->list_files_to_file($tmpdir, $mnt_list_file, \$error)) { + push @$error_ref, "$error"; + $flag = "w" if (!$rst); + $rst = 1; + } else { + `sed -i "s|^$tmpdir|$sitetable_ref->{$dir}|g" $mnt_list_file`; + my $diffout = `diff $dir_list_file $mnt_list_file`; + if ($diffout) { + push @$error_ref, "$dir '$sitetable_ref->{$dir}' is not the same with MN's, may be error"; + $flag = "w" if (!$rst); + $rst = 1; + } } `umount $tmpdir`; + unlink($dir_list_file) if (-e "$dir_list_file"); + unlink($mnt_list_file) if (-e "$mnt_list_file"); rmdir($tmpdir); } } @@ -1194,7 +1210,7 @@ sub get_attribute_value { if ($command_info =~ /$attr=(\d+)/) { $cmd_value = $1 } - print_check_result("Checking $table table attribute... $attr=$cmd_value", 0, 0, \@error); + probe_utils->send_msg("$output", "i", "Checking $table table attribute... $attr=$cmd_value") if($verbose); return $cmd_value } diff --git a/xCAT-probe/xCAT-probe.spec b/xCAT-probe/xCAT-probe.spec index 62a8df7e8..5c0c463b2 100644 --- a/xCAT-probe/xCAT-probe.spec +++ b/xCAT-probe/xCAT-probe.spec @@ -21,7 +21,6 @@ BuildArch: noarch Requires: /usr/bin/nslookup Requires: /usr/bin/tftp Requires: /usr/bin/wget -Requires: /usr/bin/tree # Tool detect_dhcpd requires tcpdump Requires: /usr/sbin/tcpdump %endif