From 31cb4aa2b8ff6b8720429970275554c3e49cbfd6 Mon Sep 17 00:00:00 2001 From: xuweibj Date: Thu, 11 Oct 2018 02:19:03 -0400 Subject: [PATCH] modified dependiing on comments --- xCAT-probe/lib/perl/probe_utils.pm | 59 +++++++++++++++++++----------- xCAT-probe/subcmds/xcatmn | 14 +++---- 2 files changed, 44 insertions(+), 29 deletions(-) diff --git a/xCAT-probe/lib/perl/probe_utils.pm b/xCAT-probe/lib/perl/probe_utils.pm index a5bc8da0a..8ea7da62a 100644 --- a/xCAT-probe/lib/perl/probe_utils.pm +++ b/xCAT-probe/lib/perl/probe_utils.pm @@ -512,6 +512,42 @@ sub parse_node_range { #------------------------------------------ +=head3 + Description: + Test if chrony service is ready to use in current operating system + Arguments: + errormsg_ref: (output attribute) if there is something wrong for chrony service, this attribute save the possible reason. + Returns: + 1 : yes + 0 : no +=cut + +#------------------------------------------ +sub is_chrony_ready { + my $errormsg_ref = shift; + $errormsg_ref = shift if (($errormsg_ref) && ($errormsg_ref =~ /probe_utils/)); + + my $chronycoutput = `chronyc tracking 2>&1`; + if ($?) { + if ($chronycoutput =~ /Cannot talk to daemon/) { + $$errormsg_ref = "chronyd service is not running! Please setup ntp in current node"; + return 0; + } + $$errormsg_ref = "command 'chronyc tracking' failed, could not get status of ntp service"; + return 0; + } + if ($chronycoutput =~ /Leap status : (.+)/) { + my $status = $1; + if ($status eq "Not synchronised") { + $$errormsg_ref = "chronyd did not synchronize."; + return 0; + } + } + return 1; +} + +#------------------------------------------ + =head3 Description: Test if ntp service is ready to use in current operating system @@ -524,29 +560,8 @@ sub parse_node_range { #------------------------------------------ sub is_ntp_ready{ - my $check_cmd = shift; - $check_cmd = shift if (($check_cmd) && ($check_cmd =~ /probe_utils/)); my $errormsg_ref = shift; - - if ($check_cmd eq "chronyc") { - my $chronycoutput = 'chronyc tracking 2>&1'; - if ($?) { - if ($chronycoutput =~ /Cannot talk to daemon/) { - $$errormsg_ref = "chronyd service is not running! Please setup ntp in current node"; - return 0; - } - $$errormsg_ref = "command 'chronyc tracking' failed, could not get status of ntp service"; - return 0; - } - if ($chronycoutput =~ /Leap status : (.+)/) { - my $status = $1; - if ($status eq "Not synchronised") { - $$errormsg_ref = "chronyd did not synchronize."; - return 0; - } - } - return 1; - } + $errormsg_ref = shift if (($errormsg_ref) && ($errormsg_ref =~ /probe_utils/)); my $cmd = 'ntpq -c "rv 0"'; $| = 1; diff --git a/xCAT-probe/subcmds/xcatmn b/xCAT-probe/subcmds/xcatmn index b23c99303..25fbcfe08 100755 --- a/xCAT-probe/subcmds/xcatmn +++ b/xCAT-probe/subcmds/xcatmn @@ -565,7 +565,7 @@ sub check_directory { } elsif (($dir eq "tftpdir" and $sitetable_ref->{sharedtftp} ne "1") or ($dir eq "installdir" and !$sitetable_ref->{installloc})) { my $tmpdir = "/tmp/tmp_$dir"; - `mkdir -p $tmpdir`; + mkdir($tmpdir); my $mountrst = `mount $sitetable_ref->{master}:$sitetable_ref->{$dir} $tmpdir 2>&1`; if ($?) { push @$error_ref, "mount $sitetable_ref->{master}:$sitetable_ref->{$dir} $tmpdir failed"; @@ -579,7 +579,7 @@ sub check_directory { $rst = 1; } `umount $tmpdir`; - `rm -rf $tmpdir`; + rmdir($tmpdir); } } } @@ -882,14 +882,14 @@ sub check_ntp_service{ $rst = 1; } else { my $error; - if(!probe_utils->is_ntp_ready("ntpq", \$error)){ + if(!probe_utils->is_ntp_ready(\$error)){ push @$error_ref, "$error"; $rst = 1; } } } else{ my $error; - if(!probe_utils->is_ntp_ready("chronyc", \$error)){ + if(!probe_utils->is_chrony_ready(\$error)){ push @$error_ref, "$error"; $rst = 1; } @@ -1316,7 +1316,7 @@ while ($hierarchy_instance->read_reply(\%reply_cache)) { #print ">>>$reply_cache{$servers}->[$_]<<<\n"; #For cases like below: #c910f02c04p04: [ok] :All xCAT daemons are running - if ($reply_cache{$servers}->[$_] =~ /^(\w\S+)\s*:\s*(\[\w+\]\s*):\s*(.*)/) { + if ($reply_cache{$servers}->[$_] =~ /^(\S+)\s*:\s*(\[\w+\]\s*):\s*(.*)/) { if ("$1" eq "$server") { $logmsg = "$2: $3"; $msg = "$2:[$server]: $3"; @@ -1324,7 +1324,7 @@ while ($hierarchy_instance->read_reply(\%reply_cache)) { #For cases like below: #sn02: ssh: connect to host sn02 port 22: No route to host - } elsif ($reply_cache{$servers}->[$_] =~ /^(\w\S+)\s*:\s*(ssh:.+)/){ + } elsif ($reply_cache{$servers}->[$_] =~ /^(\S+)\s*:\s*(ssh:.+)/){ if("$1" eq "$server") { $logmsg = "$2"; $msg = "[failed] :[$server]: $2"; @@ -1332,7 +1332,7 @@ while ($hierarchy_instance->read_reply(\%reply_cache)) { #For cases like below: #c910f02c04p05: IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! - } elsif ($reply_cache{$servers}->[$_] =~ /^(\w\S+)\s*:\s*(.*)/) { + } elsif ($reply_cache{$servers}->[$_] =~ /^(\S+)\s*:\s*(.*)/) { if ("$1" eq "$server") { $logmsg = "$2"; $msg = "[$server]: $2";