From cb7b48070f3ad690e0ce6ba8b458b170338f8fb1 Mon Sep 17 00:00:00 2001 From: caomengmeng Date: Tue, 9 Aug 2016 04:51:27 -0400 Subject: [PATCH 1/8] update option check,-f/-b files check and delete -l output files --- xCAT-test/xcattest | 52 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/xCAT-test/xcattest b/xCAT-test/xcattest index 3523c04e6..e4ab5eb68 100755 --- a/xCAT-test/xcattest +++ b/xCAT-test/xcattest @@ -14,7 +14,7 @@ BEGIN use lib "$::XCATROOT/lib/perl"; my $rootdir = "$::XCATROOT/share/xcat/tools/autotest"; my $needhelp = 0; -my $configfile = "$rootdir/default.conf"; +my $config_info = "$rootdir/default.conf"; my $bundle_list = undef; my $case_list = undef; my $cmd_list = undef; @@ -24,7 +24,7 @@ my $ret = 0; my $string1 = undef; if ( !GetOptions("h|?" => \$needhelp, - "f=s" => \$configfile, + "f=s" => \$config_info, "b=s" => \$bundle_list, "t=s" => \$case_list, "c=s" => \$cmd_list, @@ -36,12 +36,48 @@ if ( exit 1; } +unless(defined($bundle_list) || defined($case_list) || defined($cmd_list) || defined($needshow)){ + &usage; + exit 1; +} if ($needhelp) { &usage; exit 0; } +#check config file and system label +my $configfile = undef; +my $inital_info = undef; +if ($config_info){ + if ($config_info =~ /:/){ + my @config_info = split /:/, $config_info; + $configfile = $config_info[0]; + $inital_info = $config_info[1]; + if ($inital_info ne "system"){ + print "Failed: $inital_info in $config_info is not supported!\n"; + exit 1; + } + }else{ + $configfile = $config_info; + } +} +if (!open(FILE, "$configfile")) { + print "can't open config file: $configfile\n"; + exit 1; +} + +#check bundle files +if ($bundle_list){ + my @bundles = split /,/, $bundle_list; + foreach my $bundle (@bundles){ + if (!open(FILE, "<$rootdir/bundle/$bundle")) { + print "can't open bundle file: $rootdir/bundle/$bundle\n"; + exit 1; + } + } +} + #load case to $cases # key type #$cases[x](x>0): hash @@ -51,7 +87,6 @@ if ($needhelp) # hcp:hmc/mm/bmc/fsp string # cmd: array # check: array - my @cases = (); if ($needshow) { &loadcase; @@ -150,10 +185,6 @@ sub getConfig log_this("******************************"); log_this("Reading Configure"); log_this("******************************"); - if (!(-e $configfile)) { - log_this("Warning: The xCAT test Configure file doesn't exist!"); - return 0; - } my $type = undef; #Script_Prev,Script_Post,Table,Object,System,Custom my $sub_type = undef; # The string after $type_ @@ -175,7 +206,6 @@ sub getConfig my $mgt_name = undef; - open(FILE, "$configfile") or die "can't to open $configfile"; while (my $line = ) { $line = &trim($line); next if (length($line) == 0); @@ -444,7 +474,7 @@ sub Get_Files_Recursive } else { my $dirpath = $dir . '/' . $direntry . "\n"; - print $dirpath; + # print $dirpath; #print $dir."\n"; push(@filespath, glob("$dirpath")); @@ -501,10 +531,6 @@ sub loadcase if ($bundle_list) { my @bundles = split /,/, $bundle_list; foreach my $bundle (@bundles) { - if (!open(FILE, "<$rootdir/bundle/$bundle")) { - log_this("can't open $rootdir/bundle/$bundle"); - return 1; - } while ($line = ) { $line = trim($line); next if (length($line) == 0); From ae51b3358dbdc1fcc6200cb858ce88b7340704a6 Mon Sep 17 00:00:00 2001 From: caomengmeng Date: Mon, 5 Sep 2016 05:37:03 -0400 Subject: [PATCH 2/8] version 1 after review --- .../autotest/testcase/install_xCAT/case0 | 46 ++++ xCAT-test/xcattest | 227 ++++++++++++------ 2 files changed, 196 insertions(+), 77 deletions(-) create mode 100644 xCAT-test/autotest/testcase/install_xCAT/case0 diff --git a/xCAT-test/autotest/testcase/install_xCAT/case0 b/xCAT-test/autotest/testcase/install_xCAT/case0 new file mode 100644 index 000000000..9979f45ea --- /dev/null +++ b/xCAT-test/autotest/testcase/install_xCAT/case0 @@ -0,0 +1,46 @@ +start:install_xCAT_on_rhels_sles +description:install xCAT with go-xcat tool in a fresh environment for rhels and sles +os:Linux +stop:yes +cmd:if grep "Red Hat" /etc/*release >/dev/null; then yum install -y yum-utils bzip2; fi +check:rc==0 +cmd:cp /core-*-snap.tar.bz2 /xcat-core.tar.bz2 +check:rc==0 +cmd:cp /xcat-dep*.tar.bz2 /xcat-dep.tar.bz2 +check:rc==0 +cmd:cd /; ./go-xcat --xcat-core=/xcat-core.tar.bz2 --xcat-dep=/xcat-dep.tar.bz2 -y install; +check:rc==0 +cmd:source "/etc/profile.d/xcat.sh" +check:rc==0 +cmd:lsxcatd -v +check:rc==0 +check:output=~Version +cmd:service xcatd status +check:rc==0 +check:output=~running +cmd:rm -rf /xcat-core.tar.bz2 /xcat-dep.tar.bz2 +end + +start:install_xCAT_on_ubuntu +description:install xCAT with go-xcat tool in a fresh environment for ubuntu +os:Linux +stop:yes +cmd:arc_all=`uname -a`; code=`lsb_release -sc`;if [[ $arc_all =~ "ppc64le" ]]; then arch="ppc64el";else arch="x86_64";fi; cp "/opt/xcat/share/xcat/tools/autotest/testcase/go-xcat/$code-$arch.sources.list" "/etc/apt/sources.list" +cmd:apt-get clean;apt-get update +check:rc==0 +cmd:cp /core-*-snap.tar.bz2 /xcat-core.tar.bz2 +check:rc==0 +cmd:cp /xcat-dep*.tar.bz2 /xcat-dep.tar.bz2 +check:rc==0 +cmd:./go-xcat --xcat-core=/xcat-core.tar.bz2 --xcat-dep=/xcat-dep.tar.bz2 -y install; +check:rc==0 +cmd:source "/etc/profile.d/xcat.sh" +check:rc==0 +cmd:lsxcatd -v +check:rc==0 +check:output=~Version +cmd:service xcatd status +check:rc==0 +check:output=~running +cmd:rm -rf /xcat-core.tar.bz2 /xcat-dep.tar.bz2 +end diff --git a/xCAT-test/xcattest b/xCAT-test/xcattest index e4ab5eb68..cf053eea5 100755 --- a/xCAT-test/xcattest +++ b/xCAT-test/xcattest @@ -12,23 +12,30 @@ BEGIN $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr'; } use lib "$::XCATROOT/lib/perl"; -my $rootdir = "$::XCATROOT/share/xcat/tools/autotest"; -my $needhelp = 0; -my $config_info = "$rootdir/default.conf"; -my $bundle_list = undef; -my $case_list = undef; -my $cmd_list = undef; -my $needshow = 0; -my $restore = 0; -my $ret = 0; -my $string1 = undef; +my $rootdir = "$::XCATROOT/share/xcat/tools/autotest"; +my $needhelp = 0; +my $configinfo = undef; +my $configfile = "$rootdir/default.conf";; +my $initallabel = 0; +my $bundledir = "$rootdir/bundle"; +my $bundlelist = undef; +my $caselist = undef; +my $cmdlist = undef; +my $needshow = 0; +my $showbundlefiles = 0; +my $restore = 0; +my $ret = 0; +my $string1 = undef; +my $loadsysteminfo = "System"; + if ( !GetOptions("h|?" => \$needhelp, - "f=s" => \$config_info, - "b=s" => \$bundle_list, - "t=s" => \$case_list, - "c=s" => \$cmd_list, + "f=s" => \$configinfo, + "b=s" => \$bundlelist, + "t=s" => \$caselist, + "c=s" => \$cmdlist, "l" => \$needshow, + "bl" => \$showbundlefiles, "restore" => \$restore) ) { @@ -36,48 +43,24 @@ if ( exit 1; } -unless(defined($bundle_list) || defined($case_list) || defined($cmd_list) || defined($needshow)){ - &usage; - exit 1; -} if ($needhelp) { &usage; exit 0; } -#check config file and system label -my $configfile = undef; -my $inital_info = undef; -if ($config_info){ - if ($config_info =~ /:/){ - my @config_info = split /:/, $config_info; - $configfile = $config_info[0]; - $inital_info = $config_info[1]; - if ($inital_info ne "system"){ - print "Failed: $inital_info in $config_info is not supported!\n"; - exit 1; - } - }else{ - $configfile = $config_info; - } -} -if (!open(FILE, "$configfile")) { - print "can't open config file: $configfile\n"; - exit 1; -} - -#check bundle files -if ($bundle_list){ - my @bundles = split /,/, $bundle_list; - foreach my $bundle (@bundles){ - if (!open(FILE, "<$rootdir/bundle/$bundle")) { - print "can't open bundle file: $rootdir/bundle/$bundle\n"; - exit 1; - } - } +if (&checkoptions) +{ + &usage; + exit 1; } +if ($showbundlefiles) +{ + &listbundlefiles; + exit 0; +} + #load case to $cases # key type #$cases[x](x>0): hash @@ -119,9 +102,11 @@ if ($ret != 0) { goto EXIT; } -$ret = &init; -if ($ret != 0) { - goto EXIT; +if ($initallabel){ + $ret = &init; + if ($ret != 0) { + goto EXIT; + } } my @filespath = (); @@ -132,7 +117,7 @@ if ($ret != 0) { } #run case -&reordercases if (defined($bundle_list) || defined($case_list)); +&reordercases if (defined($bundlelist) || defined($caselist)); &runcase; EXIT: @@ -203,10 +188,33 @@ sub getConfig my $value = undef; my $c = 0; my $cmd = undef; - my $mgt_name = undef; + + if (!open(FILE, "$configfile")) { + log_this("Error: can't open xCAT config file: $configfile"); + close(FILE); + return 1; + } + + #Only load System information + if (defined($initallabel) && ($initallabel eq $loadsysteminfo)) { + while (my $line = ) { + $line = &trim($line); + next if (length($line) == 0); - while (my $line = ) { + #Only read System variable + if ($line =~ /\[System\]/) { + $type = "Varible"; + } + if (defined($type) && ($type eq "Varible")) { + if ($line =~ /(\w+)\s*=\s*([\w\.\-\+\/:]+)/) { + $config{var}{$1} = $2; + } + } + } + }else{ + #Load all config files information + while (my $line = ) { $line = &trim($line); next if (length($line) == 0); @@ -262,6 +270,7 @@ sub getConfig } } } +} if (exists $config{object}) { foreach my $type (keys %{ $config{object} }) { @@ -385,7 +394,7 @@ sub init if (!exists $config{var}{ARCH}) { if (!exists $config{var}{CN}) { $config{var}{ARCH} = "Unknown"; - log_this("No compute node defined,can't get ARCH of compute node"); + log_this("Error: No compute node defined, can't get ARCH of compute node"); } else { $config{var}{ARCH} = getnodeattr($config{var}{CN}, "arch"); if ($config{var}{ARCH} =~ /ppc/) { @@ -399,7 +408,7 @@ sub init if (!exists $config{var}{HCP}) { if (!exists $config{var}{CN}) { $config{var}{HCP} = "Unknown"; - log_this("No compute node defined,can't get HCP TYPE of compute node"); + log_this("Error: No compute node defined, can't get HCP TYPE of compute node"); } else { $config{var}{HCP} = getnodeattr($config{var}{CN}, "mgt"); log_this("Detecting: HCP = $config{var}{HCP}"); @@ -446,7 +455,7 @@ sub uninit log_this($cmd); runcmd($cmd); if ($::RUNCMD_RC != 0) { - log_this("Fail to run $cmd"); + log_this("Error: Fail to run $cmd"); return 1; } } @@ -494,8 +503,8 @@ sub loadcase my $casedir = "/opt/xcat/share/xcat/tools/autotest/testcase"; my @files = (); - #if($cmd_list){ - # my @cmds = split /,/,$cmd_list; + #if($caselist){ + # my @cmds = split /,/,$caselist; # for my $cmd (@cmds){ # push (@files, glob("$casedir/$cmd/*")); # } @@ -505,8 +514,8 @@ sub loadcase Get_Files_Recursive("$casedir"); for (my $countfile = 0 ; $countfile < @filespath ; $countfile++) { - if ($cmd_list) { - my @cmds = split /,/, $cmd_list; + if ($caselist) { + my @cmds = split /,/, $caselist; for (my $countcmd = 0 ; $countcmd < @cmds ; $countcmd++) { if ($filespath[$countfile] =~ m/\/$cmds[$countcmd]\/case/) { push(@files, glob("$filespath[$countfile]")); @@ -528,9 +537,14 @@ sub loadcase my @caserange = (); my @rightcase = (); my @notrightcase = (); - if ($bundle_list) { - my @bundles = split /,/, $bundle_list; + if ($bundlelist) { + my @bundles = split /,/, $bundlelist; foreach my $bundle (@bundles) { + if (!open(FILE, "<$bundledir/$bundle")){ + log_this("Error: Can't open bundle file: $bundle"); + close(FILE); + return 1; + } while ($line = ) { $line = trim($line); next if (length($line) == 0); @@ -539,12 +553,12 @@ sub loadcase close(FILE); } } - if ($case_list) { - @caserange = split /,/, $case_list; + if ($caselist) { + @caserange = split /,/, $caselist; } foreach $file (@files) { if (!open(FILE, "<$file")) { - log_this("can't open $file"); + log_this("Error: Can't open $file"); return 1; } while ($line = ) { @@ -682,7 +696,7 @@ sub getnodeattr # return "Unknown"; foreach $t (1 .. 40) { - log_this("could not get node attr $attr "); + log_this("Error: could not get node attr $attr "); @output = runcmd("lsdef -t node -o $node -i $attr"); last if ($::RUNCMD_RC == 0); } @@ -728,7 +742,7 @@ sub getvar if (exists($config{var}{$varname})) { $str =~ s/\$\$$varname/$config{var}{$varname}/g; } else { - log_this("Error:can't get varible $varname"); + log_this("Error: can't get varible $varname"); return ''; } } @@ -945,13 +959,25 @@ sub usage { print "Usage:xcattest - Run xcat test cases.\n"; print " xcattest [-?|-h]\n"; - print " xcattest [-f configure file] [-b case bundle list] [--restore]\n"; - print " xcattest [-f configure file] [-t case list] [--restore]\n"; - print " xcattest [-f configure file] [-c cmd list] [-l] [--restore]\n"; + print " xcattest [-f configure file] [-b case bundle list]\n"; + print " xcattest [-f configure file] [-t case list]\n"; + print " xcattest [-f configure file] [-c cmd list]\n"; + print " xcattest [-f configure file:System] [-t case] \n"; + print " xcattest [-f configure file] [-b case bundle list] [-l]\n"; + print " xcattest [-f configure file] [-t case list] [-l]\n"; + print " xcattest [-f configure file] [-c cmd list] [-l]\n"; + print " xcattest [-bl]"; print "\n"; return; } +sub listbundlefiles +{ + print "Bundle files listed in $bundledir/:\n"; + system("ls $bundledir "); + return 0; +} + sub getreport { open(INDOC, ">$_[1]") || die("open STDOUT failed"); @@ -976,11 +1002,11 @@ sub getreport sub reordercases { my @caserange = (); my $line; - if ($bundle_list) { - my @bundles = split /,/, $bundle_list; + if ($bundlelist) { + my @bundles = split /,/, $bundlelist; foreach my $bundle (@bundles) { - if (!open(FILE, "<$rootdir/bundle/$bundle")) { - log_this("can't open $rootdir/bundle/$bundle"); + if (!open(FILE, "<$bundledir/$bundle")){ + log_this("Error: Can't open bundle file: $bundle"); return 1; } while ($line = ) { @@ -991,8 +1017,8 @@ sub reordercases { close(FILE); } } - if ($case_list) { - @caserange = split /,/, $case_list; + if ($caselist) { + @caserange = split /,/, $caselist; } my @tmpcases = (); @@ -1012,3 +1038,50 @@ sub reordercases { @cases = @tmpcases; } +sub checkoptions{ + #bundle, cases lists and command lists, one of them must be defined + if (!defined($bundlelist) && !defined($caselist) && !defined($caselist) && !defined($showbundlefiles)){ + &usage; + exit 1; + } + + #get and check config file and System label + #this System label means only the [System] variable will be loaded + if ($configinfo){ + if ($configinfo =~ /(\w+):(\w+)/){ + $configfile =$1; + $initallabel = $2; + if ($initallabel ne $loadsysteminfo){ + print "Error: $initallabel is not supported!\n"; + log_this("Error: $initallabel is not supported!"); + return 1; + } + }else{ + $configfile = $configinfo; + } + } + if (!(-e $configfile)) { + print "Error: Can't open config file: $configfile\n"; + log_this("Error: Can't open config file: $configfile"); + return 1; + } + + #check bundle files + if ($bundlelist){ + my @bundles = split /,/, $bundlelist; + foreach my $bundle (@bundles){ + if (!(-e "$bundledir/$bundle")) { + print "Error: Can't open bundle file: $bundledir/$bundle\n"; + log_this("Error: Can't open bundle file: $bundledir/$bundle"); + return 1; + } + } + } + + return 0; +} + + + + + From 83270bf120793b4f130a0fd3d4b50fec547e218f Mon Sep 17 00:00:00 2001 From: caomengmeng Date: Thu, 8 Sep 2016 08:47:35 -0400 Subject: [PATCH 3/8] complete V1 --- xCAT-test/xcattest | 272 +++++++++++++++++++++++++++++++-------------- 1 file changed, 186 insertions(+), 86 deletions(-) diff --git a/xCAT-test/xcattest b/xCAT-test/xcattest index cf053eea5..eb0d85b87 100755 --- a/xCAT-test/xcattest +++ b/xCAT-test/xcattest @@ -15,19 +15,31 @@ use lib "$::XCATROOT/lib/perl"; my $rootdir = "$::XCATROOT/share/xcat/tools/autotest"; my $needhelp = 0; my $configinfo = undef; -my $configfile = "$rootdir/default.conf";; -my $initallabel = 0; +my $configfile = "$rootdir/default.conf"; +my $initallabel = undef; my $bundledir = "$rootdir/bundle"; my $bundlelist = undef; my $caselist = undef; my $cmdlist = undef; my $needshow = 0; -my $showbundlefiles = 0; +my $showbundlefiles = undef; +my $showcommandslist= undef; my $restore = 0; my $ret = 0; my $string1 = undef; my $loadsysteminfo = "System"; +my $resultdir = "$rootdir/result"; +my $stop_to_keep_env = 0; + +#Create result directory +mkdir $resultdir unless -d $resultdir; + +# create a log +my $timestamp = `date +"%Y%m%d%H%M%S"`; +open(LOG, ">$resultdir/xcattest.log.$timestamp") + or die "Can't open logfile for writing: $!"; + if ( !GetOptions("h|?" => \$needhelp, "f=s" => \$configinfo, @@ -36,6 +48,7 @@ if ( "c=s" => \$cmdlist, "l" => \$needshow, "bl" => \$showbundlefiles, + "cl" => \$showcommandslist, "restore" => \$restore) ) { @@ -49,10 +62,11 @@ if ($needhelp) exit 0; } + if (&checkoptions) { &usage; - exit 1; + exit 1; } if ($showbundlefiles) @@ -60,7 +74,13 @@ if ($showbundlefiles) &listbundlefiles; exit 0; } - + +if ($showcommandslist) +{ + &listcommands; + exit 0; +} + #load case to $cases # key type #$cases[x](x>0): hash @@ -70,22 +90,13 @@ if ($showbundlefiles) # hcp:hmc/mm/bmc/fsp string # cmd: array # check: array + my @cases = (); if ($needshow) { &loadcase; exit 0; } -my $resultdir = "$rootdir/result"; -my $stop_to_keep_env = 0; - -#Create result directory -mkdir $resultdir unless -d $resultdir; - -# create a log -my $timestamp = `date +"%Y%m%d%H%M%S"`; -open(LOG, ">$resultdir/xcattest.log.$timestamp") - or die "Can't open logfile for writing: $!"; &log_this("xCAT automated test started at " . scalar(localtime())); open(LOG_ERR, ">$resultdir/failedcases.$timestamp") or die "Can't open error logfile for writing: $!"; @@ -102,7 +113,7 @@ if ($ret != 0) { goto EXIT; } -if ($initallabel){ +if (!defined($initallabel)){ $ret = &init; if ($ret != 0) { goto EXIT; @@ -146,9 +157,6 @@ if ($stop_to_keep_env) { sub log_this { - if ($needshow) { - return; - } print LOG join("\n", @_), "\n"; my $msg = join("\n", @_); if ($msg =~ /\[Pass\]/) { @@ -192,7 +200,6 @@ sub getConfig if (!open(FILE, "$configfile")) { log_this("Error: can't open xCAT config file: $configfile"); - close(FILE); return 1; } @@ -483,7 +490,7 @@ sub Get_Files_Recursive } else { my $dirpath = $dir . '/' . $direntry . "\n"; - # print $dirpath; + #print $dirpath; #print $dir."\n"; push(@filespath, glob("$dirpath")); @@ -494,7 +501,6 @@ sub Get_Files_Recursive } } - sub loadcase { log_this("******************************"); @@ -503,8 +509,8 @@ sub loadcase my $casedir = "/opt/xcat/share/xcat/tools/autotest/testcase"; my @files = (); - #if($caselist){ - # my @cmds = split /,/,$caselist; + #if($cmdlist){ + # my @cmds = split /,/,$cmdlist; # for my $cmd (@cmds){ # push (@files, glob("$casedir/$cmd/*")); # } @@ -514,8 +520,9 @@ sub loadcase Get_Files_Recursive("$casedir"); for (my $countfile = 0 ; $countfile < @filespath ; $countfile++) { - if ($caselist) { - my @cmds = split /,/, $caselist; + #TODO:if commands are not right, no action or message now + if ($cmdlist) { + my @cmds = split /,/, $cmdlist; for (my $countcmd = 0 ; $countcmd < @cmds ; $countcmd++) { if ($filespath[$countfile] =~ m/\/$cmds[$countcmd]\/case/) { push(@files, glob("$filespath[$countfile]")); @@ -537,12 +544,12 @@ sub loadcase my @caserange = (); my @rightcase = (); my @notrightcase = (); + my @wrongnamecase= (); if ($bundlelist) { my @bundles = split /,/, $bundlelist; foreach my $bundle (@bundles) { - if (!open(FILE, "<$bundledir/$bundle")){ - log_this("Error: Can't open bundle file: $bundle"); - close(FILE); + if (!open(FILE, "<$rootdir/bundle/$bundle")) { + log_this("can't open $rootdir/bundle/$bundle"); return 1; } while ($line = ) { @@ -553,12 +560,15 @@ sub loadcase close(FILE); } } + + #TODO:if cases are not existed, no action or message. if ($caselist) { @caserange = split /,/, $caselist; } + foreach $file (@files) { if (!open(FILE, "<$file")) { - log_this("Error: Can't open $file"); + log_this("can't open $file"); return 1; } while ($line = ) { @@ -571,26 +581,39 @@ sub loadcase #TODO: description line is treated as a comment line for now next if ($line =~ /^description\s*:/); - if ($line =~ /^start\s*:\s*([\w-]+)/) { - $skip = 0; - my $name = $1; - if ($caserange[0] && !(grep { /^$name$/ } @caserange)) { - $skip = 1; - next; - } - $j = -1; - $cases[$i] = {}; - $cases[$i]->{name} = $name; - $cases[$i]->{filename} = $file; - if (!$needshow) { - $cases[$i]->{cmd} = []; - $cases[$i]->{check} = []; - $cases[$i]->{cmdcheck} = []; - push(@rightcase, $name); - } else { - $skip = 1; - $i = $i + 1; - } + if ($line =~ /^start\s*:\s*(.*)/) { + my $name =$1; + if ($name =~ /[^a-zA-Z0-9_-]/) { + $skip = 1; + push(@wrongnamecase, $name); + next; + }else { + $skip = 0; + if ($caserange[0] && !(grep { /^$name$/ } @caserange)) { + $skip = 1; + next; + } + $j = -1; + $cases[$i] = {}; + $cases[$i]->{name} = $name; + $cases[$i]->{filename} = $file; + if (!$needshow) { + $cases[$i]->{cmd} = []; + $cases[$i]->{check} = []; + $cases[$i]->{cmdcheck} = []; + push(@rightcase, $name); + } else { + $skip = 1; + $i = $i + 1; + } + } +#elsif($line =~ /^start:\s*:\s*(.*)/) { +# $skip = 1; +# my $wrongcasename = $1; +# push(@wrongnamecase, $wrongcasename); +# next; +# } + } elsif ($line =~ /^os\s*:\s*(\w[\w\,]+)/) { next if $skip; $string1 = $1; @@ -677,16 +700,19 @@ sub loadcase close(FILE); } if ($needshow) { + log_this("*Test cases:"); foreach my $case (@cases) { - print "$case->{name}\n"; + log_this("$case->{name}"); } + log_this("*Case name not supported:", @wrongnamecase); return 0; } - log_this("To run:", @rightcase); - log_this("Not to run:", @notrightcase); + + log_this("*To run:", @rightcase); + log_this("*Not to run:", @notrightcase); + log_this("*Case name not supported:", @wrongnamecase); return 0; } - sub getnodeattr { my ($node, $attr) = @_; @@ -957,27 +983,97 @@ sub runcmd sub usage { - print "Usage:xcattest - Run xcat test cases.\n"; - print " xcattest [-?|-h]\n"; - print " xcattest [-f configure file] [-b case bundle list]\n"; - print " xcattest [-f configure file] [-t case list]\n"; - print " xcattest [-f configure file] [-c cmd list]\n"; - print " xcattest [-f configure file:System] [-t case] \n"; - print " xcattest [-f configure file] [-b case bundle list] [-l]\n"; - print " xcattest [-f configure file] [-t case list] [-l]\n"; - print " xcattest [-f configure file] [-c cmd list] [-l]\n"; - print " xcattest [-bl]"; - print "\n"; + log_this("Usage:"); + log_this("Run xcat test cases:"); + log_this(" xcattest [-?|-h]"); + log_this(" xcattest [-f configure file] [-b case bundle files]"); + log_this(" xcattest [-f configure file] [-t cases list]"); + log_this(" xcattest [-f configure file] [-c cmds list]"); + log_this(" xcattest [-f configure file:System] [-t case list]"); + log_this("Show xcat test cases, bundle files, commands lists:"); + log_this(" xcattest [-f configure file] [-b case bundle files] [-l]"); + log_this(" xcattest [-f configure file] [-t cases list] [-l]"); + log_this(" xcattest [-f configure file] [-c cmds list] [-l]"); + log_this(" xcattest [-bl]"); + log_this(" xcattest [-cl]"); + log_this(""); return; } sub listbundlefiles { - print "Bundle files listed in $bundledir/:\n"; - system("ls $bundledir "); + log_this("******************************"); + log_this("show bundle files and descriptions"); + log_this("******************************"); + + my %bundlefilesinfo = (); + my @bundlefiles = (); + + #get all .bundle files from /opt/xcat/share/xcat/tools/autotest/bundle/ + opendir(DIR, $bundledir); + my @files = readdir(DIR); + foreach my $file (@files){ + next if (-d $file); + if ($file =~ /\.bundle$/){ + push(@bundlefiles, $file); + } + } + closedir(DIR); + + #read all .bundle files, get descriptions for each file. + my $skip =0; + my $line; + foreach my $bundlefile (@bundlefiles) { + if (!open(FILE, "<$bundledir/$bundlefile")) { + log_this("Error: Can't open $bundlefile"); + return 1; + } + $skip = 0; + while ($line = ) { + $line = &trim($line); + next if (length($line) == 0); + + #description line is treated as a comment line for now + if ($line =~ /^description\s*:\s*(.*)/){ + if (length($1) != 0) { + $bundlefilesinfo{$bundlefile} = $1; + $skip=1; + last; + } + } + } + + if (!$skip){ + $bundlefilesinfo{$bundlefile} = "No description, add with \"description: details\" in this bundle file"; + } + } + + while (my ($file, $description) = each (%bundlefilesinfo)){ + print "\nFile: $file \n"; + print "Description: $description \n"; + } + return 0; } +sub listcommands +{ + log_this("******************************"); + log_this("show commands list"); + log_this("******************************"); + + my $casedir = "/opt/xcat/share/xcat/tools/autotest/testcase"; + my @files = (); + + Get_Files_Recursive("$casedir"); + for (my $countfile = 0 ; $countfile < @ filespath ; $countfile++) + { + if ($filespath[$countfile] =~ /testcase\/(.*)\/case/) { + log_this("$1"); + } + } +} + sub getreport { open(INDOC, ">$_[1]") || die("open STDOUT failed"); @@ -1011,7 +1107,7 @@ sub reordercases { } while ($line = ) { $line = trim($line); - next if (length($line) == 0); + next if ((length($line) == 0) || ($line =~ /^description\s*:\s*(.*)/)); push(@caserange, $line); } close(FILE); @@ -1039,20 +1135,26 @@ sub reordercases { } sub checkoptions{ - #bundle, cases lists and command lists, one of them must be defined - if (!defined($bundlelist) && !defined($caselist) && !defined($caselist) && !defined($showbundlefiles)){ - &usage; - exit 1; - } + #-b,-c,-t,-bl,-cl should be defined at least one + if (!defined($bundlelist) && !defined($caselist) && !defined($cmdlist) && !defined($showbundlefiles) && !defined($showcommandslist)){ + log_this("Error: please define options correctly"); + return 1; + }elsif ((defined($showbundlefiles) || defined($showcommandslist)) && (defined($bundlelist) || defined($caselist) || defined($cmdlist))){ + # -bl or -cl can't be used together with -c,-b,-t + log_this("Error: -b,-c or -t can't be used together with -bl or -cl"); + return 1; + }elsif ((defined($showbundlefiles) && defined($showcommandslist)) || (defined($showbundlefiles) && $needshow) || ($needshow && defined($showcommandslist))){ + log_this("Error: -bl, -cl, -l can't be used together"); + return 1; + } #get and check config file and System label #this System label means only the [System] variable will be loaded if ($configinfo){ - if ($configinfo =~ /(\w+):(\w+)/){ - $configfile =$1; + if ($configinfo =~ /(.*):(.*)/){ + $configfile = $1; $initallabel = $2; if ($initallabel ne $loadsysteminfo){ - print "Error: $initallabel is not supported!\n"; log_this("Error: $initallabel is not supported!"); return 1; } @@ -1061,18 +1163,21 @@ sub checkoptions{ } } if (!(-e $configfile)) { - print "Error: Can't open config file: $configfile\n"; - log_this("Error: Can't open config file: $configfile"); + log_this("Error: Can't open config file: $configfile"); return 1; } - + #check bundle files if ($bundlelist){ my @bundles = split /,/, $bundlelist; foreach my $bundle (@bundles){ + if ("$bundledir/$bundle" !~ /\.bundle$/){ + log_this("Error: please input the .bundle file"); + return 1; + } if (!(-e "$bundledir/$bundle")) { - print "Error: Can't open bundle file: $bundledir/$bundle\n"; - log_this("Error: Can't open bundle file: $bundledir/$bundle"); + log_this("Error: Can't open bundle file: $bundle"); + log_this("Use 'xcattest -bl' to list out available bundles"); return 1; } } @@ -1080,8 +1185,3 @@ sub checkoptions{ return 0; } - - - - - From 07f6eba13e0c7d47525cbe45b8aebbfea8d779d0 Mon Sep 17 00:00:00 2001 From: caomengmeng Date: Thu, 8 Sep 2016 23:48:31 -0400 Subject: [PATCH 4/8] updated V1 --- xCAT-test/xcattest | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/xCAT-test/xcattest b/xCAT-test/xcattest index eb0d85b87..d2292acb4 100755 --- a/xCAT-test/xcattest +++ b/xCAT-test/xcattest @@ -607,13 +607,6 @@ sub loadcase $i = $i + 1; } } -#elsif($line =~ /^start:\s*:\s*(.*)/) { -# $skip = 1; -# my $wrongcasename = $1; -# push(@wrongnamecase, $wrongcasename); -# next; -# } - } elsif ($line =~ /^os\s*:\s*(\w[\w\,]+)/) { next if $skip; $string1 = $1; @@ -704,13 +697,12 @@ sub loadcase foreach my $case (@cases) { log_this("$case->{name}"); } - log_this("*Case name not supported:", @wrongnamecase); - return 0; + }else{ + log_this("*To run:", @rightcase); + log_this("*Not to run:", @notrightcase); } - log_this("*To run:", @rightcase); - log_this("*Not to run:", @notrightcase); - log_this("*Case name not supported:", @wrongnamecase); + log_this("*Case name not supported, please use 'a-zA-Z0-9_-' :", @wrongnamecase); return 0; } sub getnodeattr @@ -1155,7 +1147,7 @@ sub checkoptions{ $configfile = $1; $initallabel = $2; if ($initallabel ne $loadsysteminfo){ - log_this("Error: $initallabel is not supported!"); + log_this("Error: $initallabel is not supported, please use $loadsysteminfo"); return 1; } }else{ From 06109e8dff88322606bbbe1315cdf798cd5fa486 Mon Sep 17 00:00:00 2001 From: caomengmeng Date: Tue, 13 Sep 2016 01:58:11 -0400 Subject: [PATCH 5/8] update after review V1 --- .../autotest/testcase/install_xCAT/case0 | 6 +- xCAT-test/xcattest | 209 +++++++++++------- 2 files changed, 138 insertions(+), 77 deletions(-) diff --git a/xCAT-test/autotest/testcase/install_xCAT/case0 b/xCAT-test/autotest/testcase/install_xCAT/case0 index 9979f45ea..5c1a76a54 100644 --- a/xCAT-test/autotest/testcase/install_xCAT/case0 +++ b/xCAT-test/autotest/testcase/install_xCAT/case0 @@ -8,6 +8,8 @@ cmd:cp /core-*-snap.tar.bz2 /xcat-core.tar.bz2 check:rc==0 cmd:cp /xcat-dep*.tar.bz2 /xcat-dep.tar.bz2 check:rc==0 +cmd:ls /go-xcat +check:rc==0 cmd:cd /; ./go-xcat --xcat-core=/xcat-core.tar.bz2 --xcat-dep=/xcat-dep.tar.bz2 -y install; check:rc==0 cmd:source "/etc/profile.d/xcat.sh" @@ -32,7 +34,9 @@ cmd:cp /core-*-snap.tar.bz2 /xcat-core.tar.bz2 check:rc==0 cmd:cp /xcat-dep*.tar.bz2 /xcat-dep.tar.bz2 check:rc==0 -cmd:./go-xcat --xcat-core=/xcat-core.tar.bz2 --xcat-dep=/xcat-dep.tar.bz2 -y install; +cmd:ls /go-xcat +check:rc==0 +cmd:cd /; ./go-xcat --xcat-core=/xcat-core.tar.bz2 --xcat-dep=/xcat-dep.tar.bz2 -y install; check:rc==0 cmd:source "/etc/profile.d/xcat.sh" check:rc==0 diff --git a/xCAT-test/xcattest b/xCAT-test/xcattest index d2292acb4..d50d1a404 100755 --- a/xCAT-test/xcattest +++ b/xCAT-test/xcattest @@ -16,28 +16,33 @@ my $rootdir = "$::XCATROOT/share/xcat/tools/autotest"; my $needhelp = 0; my $configinfo = undef; my $configfile = "$rootdir/default.conf"; -my $initallabel = undef; +my $casedir = "$rootdir/testcase"; my $bundledir = "$rootdir/bundle"; +my $resultdir = "$rootdir/result"; my $bundlelist = undef; my $caselist = undef; my $cmdlist = undef; +my $showbundlesorcommands = undef; my $needshow = 0; -my $showbundlefiles = undef; -my $showcommandslist= undef; my $restore = 0; my $ret = 0; my $string1 = undef; +#below System label means: only load the [System] aspects in config file +#this usage is only for the first install_xCAT cases used for xCAT daily regression +#it is a workaround to avoid change the xcattest structure, so no need to public +my $initallabel = undef; my $loadsysteminfo = "System"; - -my $resultdir = "$rootdir/result"; +my $showbundlefiles = 0; +my $showcommandslist = 0; my $stop_to_keep_env = 0; + #Create result directory mkdir $resultdir unless -d $resultdir; -# create a log +# create a log for xcattest -h,-s,-l related my $timestamp = `date +"%Y%m%d%H%M%S"`; -open(LOG, ">$resultdir/xcattest.log.$timestamp") +open(LOG, ">$resultdir/command.logs.$timestamp") or die "Can't open logfile for writing: $!"; if ( @@ -46,9 +51,8 @@ if ( "b=s" => \$bundlelist, "t=s" => \$caselist, "c=s" => \$cmdlist, + "s=s" => \$showbundlesorcommands, "l" => \$needshow, - "bl" => \$showbundlefiles, - "cl" => \$showcommandslist, "restore" => \$restore) ) { @@ -69,12 +73,15 @@ if (&checkoptions) exit 1; } +#show bundle files under $bundledir with .bundle as file suffix +my %bundlefilesinfo = (); if ($showbundlefiles) { - &listbundlefiles; + &undlefiles; exit 0; -} +} +#show commands, which is the folder name $casedir, with case* files and test cases if ($showcommandslist) { &listcommands; @@ -97,11 +104,19 @@ if ($needshow) { exit 0; } + +# create a log for run test cases +$timestamp = `date +"%Y%m%d%H%M%S"`; +open(LOG, ">$resultdir/xcattest.log.$timestamp") + or die "Can't open logfile for writing: $!"; &log_this("xCAT automated test started at " . scalar(localtime())); open(LOG_ERR, ">$resultdir/failedcases.$timestamp") or die "Can't open error logfile for writing: $!"; - + #read config file +log_this("******************************"); +log_this("Reading Configure"); +log_this("******************************"); #config{object}{type}{name}{attr} #config{table}{name}{entry}{key} #config{script_prev}->[] @@ -113,28 +128,42 @@ if ($ret != 0) { goto EXIT; } +#if not only load System aspects from config file, then init test enviroment if (!defined($initallabel)){ + log_this("******************************"); + log_this("Initialize xCAT test evironment"); + log_this("******************************"); $ret = &init; if ($ret != 0) { goto EXIT; } } -my @filespath = (); +my @filespath = (); #loading and check cases +log_this("******************************"); +log_this("loading test cases"); +log_this("******************************"); $ret = &loadcase; if ($ret != 0) { goto EXIT; } #run case +log_this("******************************"); +log_this("Start to run test cases"); +log_this("******************************"); &reordercases if (defined($bundlelist) || defined($caselist)); &runcase; EXIT: +log_this("******************************"); +log_this("un-initialize xCAT test evironment"); +log_this("******************************"); if ($restore) { &uninit; } + &log_this("\nxCAT automated test finished at " . scalar(localtime())); &log_this("Please check results in the $resultdir, \nand see $resultdir/failedcases.$timestamp file for failed cases.\nsee $resultdir/performance.report.$timestamp file for time consumption"); close(LOG); @@ -175,10 +204,6 @@ sub log_error sub getConfig { - log_this("******************************"); - log_this("Reading Configure"); - log_this("******************************"); - my $type = undef; #Script_Prev,Script_Post,Table,Object,System,Custom my $sub_type = undef; # The string after $type_ # Script--> @@ -343,9 +368,6 @@ sub init return 1; } } - log_this("******************************"); - log_this("Initialize xCAT test evironment"); - log_this("******************************"); my $cmd = undef; foreach $cmd (@{ $config{script_prev} }) { log_this("$cmd"); @@ -427,9 +449,6 @@ sub init sub uninit { - log_this("******************************"); - log_this("un-initialize xCAT test evironment"); - log_this("******************************"); my $cmd = undef; # if(exists $config{object}){ @@ -503,10 +522,6 @@ sub Get_Files_Recursive sub loadcase { - log_this("******************************"); - log_this("loading test cases"); - log_this("******************************"); - my $casedir = "/opt/xcat/share/xcat/tools/autotest/testcase"; my @files = (); #if($cmdlist){ @@ -548,8 +563,8 @@ sub loadcase if ($bundlelist) { my @bundles = split /,/, $bundlelist; foreach my $bundle (@bundles) { - if (!open(FILE, "<$rootdir/bundle/$bundle")) { - log_this("can't open $rootdir/bundle/$bundle"); + if (!open(FILE, "<$bundledir/$bundle")) { + log_this("can't open $bundledir/$bundle"); return 1; } while ($line = ) { @@ -697,12 +712,13 @@ sub loadcase foreach my $case (@cases) { log_this("$case->{name}"); } - }else{ - log_this("*To run:", @rightcase); - log_this("*Not to run:", @notrightcase); + log_this("*Case name not supported:", @wrongnamecase); + return 0; } - log_this("*Case name not supported, please use 'a-zA-Z0-9_-' :", @wrongnamecase); + log_this("*To run:", @rightcase) if (@rightcase); + log_this("*Not to run:", @notrightcase) if (@notrightcase); + log_this("*Case name not supported:", @wrongnamecase) if (@wrongnamecase); return 0; } sub getnodeattr @@ -797,9 +813,6 @@ sub getfunc sub runcase { - log_this("******************************"); - log_this("Start to run test cases"); - log_this("******************************"); my @output = (); my $rc = 0; my $j = 0; @@ -975,30 +988,22 @@ sub runcmd sub usage { - log_this("Usage:"); - log_this("Run xcat test cases:"); + log_this("Usage:Run xcat test cases:"); log_this(" xcattest [-?|-h]"); log_this(" xcattest [-f configure file] [-b case bundle files]"); log_this(" xcattest [-f configure file] [-t cases list]"); log_this(" xcattest [-f configure file] [-c cmds list]"); - log_this(" xcattest [-f configure file:System] [-t case list]"); log_this("Show xcat test cases, bundle files, commands lists:"); log_this(" xcattest [-f configure file] [-b case bundle files] [-l]"); log_this(" xcattest [-f configure file] [-t cases list] [-l]"); log_this(" xcattest [-f configure file] [-c cmds list] [-l]"); - log_this(" xcattest [-bl]"); - log_this(" xcattest [-cl]"); + log_this(" xcattest [-s command|bundle]"); log_this(""); return; } sub listbundlefiles { - log_this("******************************"); - log_this("show bundle files and descriptions"); - log_this("******************************"); - - my %bundlefilesinfo = (); my @bundlefiles = (); #get all .bundle files from /opt/xcat/share/xcat/tools/autotest/bundle/ @@ -1017,7 +1022,8 @@ sub listbundlefiles my $line; foreach my $bundlefile (@bundlefiles) { if (!open(FILE, "<$bundledir/$bundlefile")) { - log_this("Error: Can't open $bundlefile"); + log_this("Error: Can't open bundle file: $bundlefile"); + log_this("Use 'xcattest -s bundle' to list out available bundles"); return 1; } $skip = 0; @@ -1036,25 +1042,57 @@ sub listbundlefiles } if (!$skip){ - $bundlefilesinfo{$bundlefile} = "No description, add with \"description: details\" in this bundle file"; + $bundlefilesinfo{$bundlefile} = "No description, add \"description: details\" in this bundle file"; } } - - while (my ($file, $description) = each (%bundlefilesinfo)){ - print "\nFile: $file \n"; - print "Description: $description \n"; - } + &listformatbundleinfo(%bundlefilesinfo); return 0; } +sub listformatbundleinfo +{ + my $maxlen = 0; + foreach my $filename (keys %bundlefilesinfo) { + $maxlen = length($filename) if (length($filename) > $maxlen); + } + $maxlen += 4; + + my $desiredwidth = 120; + my $screenwidth = (`tput cols` + 0); + my $finallen = ($screenwidth > $desiredwidth ? $desiredwidth : $screenwidth); + + print "bundle files and descriptions:\n"; + + foreach my $filename (keys %bundlefilesinfo) { + my @desc = split(" ", $bundlefilesinfo{$filename}); + my $str = ""; + my @formatdesc = (); + foreach my $word (@desc) { + if (length($str) + length($word) > $finallen - $maxlen) { + $str =~ s/([^\s]+)\s$/$1/g; + push @formatdesc, $str; + $str = ""; + } + $str .= $word . " "; + } + $str =~ s/([^\s]+)\s$/$1/g; + push @formatdesc, $str; + + print "$filename"; + + my $space = " " x ($maxlen - length($filename)); + print "$space$formatdesc[0]\n"; + delete $formatdesc[0]; + $space = " " x $maxlen; + foreach my $line (@formatdesc) { + print "$space$line\n" if (length($line)); + } + } +} + sub listcommands { - log_this("******************************"); - log_this("show commands list"); - log_this("******************************"); - - my $casedir = "/opt/xcat/share/xcat/tools/autotest/testcase"; my @files = (); Get_Files_Recursive("$casedir"); @@ -1087,7 +1125,8 @@ sub getreport } -sub reordercases { +sub reordercases +{ my @caserange = (); my $line; if ($bundlelist) { @@ -1126,50 +1165,66 @@ sub reordercases { @cases = @tmpcases; } -sub checkoptions{ - #-b,-c,-t,-bl,-cl should be defined at least one - if (!defined($bundlelist) && !defined($caselist) && !defined($cmdlist) && !defined($showbundlefiles) && !defined($showcommandslist)){ +sub checkoptions +{ +#print "$showbundlesorcommands\n"; +#print "$needshow\n"; + #-b,-c,-t,-s should be defined at least one + if (!defined($bundlelist) && !defined($caselist) && !defined($cmdlist) && !defined($showbundlesorcommands)) { log_this("Error: please define options correctly"); return 1; - }elsif ((defined($showbundlefiles) || defined($showcommandslist)) && (defined($bundlelist) || defined($caselist) || defined($cmdlist))){ - # -bl or -cl can't be used together with -c,-b,-t - log_this("Error: -b,-c or -t can't be used together with -bl or -cl"); + }elsif (defined($showbundlesorcommands) && (defined($bundlelist) || defined($caselist) || defined($cmdlist))) { + # -s can't be used together with -c,-b,-t + log_this("Error: -b,-c or -t can't be used together with -s"); return 1; - }elsif ((defined($showbundlefiles) && defined($showcommandslist)) || (defined($showbundlefiles) && $needshow) || ($needshow && defined($showcommandslist))){ - log_this("Error: -bl, -cl, -l can't be used together"); + }elsif (defined($showbundlesorcommands) && $needshow) { + log_this("Error: -s, -l can't be used together"); return 1; } - + + #check the L option, it only should be bundle or command + if (defined($showbundlesorcommands)) { + if (($showbundlesorcommands ne "bundle") && ($showbundlesorcommands ne "command")) { + log_this("Error: please use \"bundle\" or \"command\" as the \-s value"); + return 1; + }elsif ($showbundlesorcommands eq "bundle") { + $showbundlefiles = 1; + }else { + } + $showcommandslist= 1; + } #get and check config file and System label #this System label means only the [System] variable will be loaded - if ($configinfo){ - if ($configinfo =~ /(.*):(.*)/){ + if ($configinfo) { + if ($configinfo =~ /(.*):(.*)/) { $configfile = $1; $initallabel = $2; - if ($initallabel ne $loadsysteminfo){ - log_this("Error: $initallabel is not supported, please use $loadsysteminfo"); + if ($initallabel ne $loadsysteminfo) { + log_this("Error: $initallabel is not supported!"); return 1; } - }else{ + }else { $configfile = $configinfo; } } + if (!(-e $configfile)) { log_this("Error: Can't open config file: $configfile"); return 1; } #check bundle files - if ($bundlelist){ + if (defined($bundlelist)) { my @bundles = split /,/, $bundlelist; foreach my $bundle (@bundles){ - if ("$bundledir/$bundle" !~ /\.bundle$/){ + if ("$bundledir/$bundle" !~ /\.bundle$/) { log_this("Error: please input the .bundle file"); + log_this("Use 'xcattest -s bundle' to list out available bundles"); return 1; } if (!(-e "$bundledir/$bundle")) { log_this("Error: Can't open bundle file: $bundle"); - log_this("Use 'xcattest -bl' to list out available bundles"); + log_this("Use 'xcattest -b bundle' to list out available bundles"); return 1; } } @@ -1177,3 +1232,5 @@ sub checkoptions{ return 0; } + + From e3a07ac4f2d5936c18aed9bfcbaad51527c0177b Mon Sep 17 00:00:00 2001 From: caomengmeng Date: Tue, 13 Sep 2016 04:49:53 -0400 Subject: [PATCH 6/8] complete 9.13 --- .../autotest/testcase/install_xCAT/case0 | 21 +++++---- xCAT-test/autotest/testcase/noderange/cases0 | 12 ++--- xCAT-test/xcattest | 46 +++++++++++++------ 3 files changed, 49 insertions(+), 30 deletions(-) diff --git a/xCAT-test/autotest/testcase/install_xCAT/case0 b/xCAT-test/autotest/testcase/install_xCAT/case0 index 5c1a76a54..0047a302e 100644 --- a/xCAT-test/autotest/testcase/install_xCAT/case0 +++ b/xCAT-test/autotest/testcase/install_xCAT/case0 @@ -4,13 +4,13 @@ os:Linux stop:yes cmd:if grep "Red Hat" /etc/*release >/dev/null; then yum install -y yum-utils bzip2; fi check:rc==0 -cmd:cp /core-*-snap.tar.bz2 /xcat-core.tar.bz2 +cmd:cp /core-*-snap.tar.bz2 /install_xCAT_xcat-core.tar.bz2 check:rc==0 -cmd:cp /xcat-dep*.tar.bz2 /xcat-dep.tar.bz2 +cmd:cp /xcat-dep*.tar.bz2 /install_xCAT_xcat-dep.tar.bz2 check:rc==0 cmd:ls /go-xcat check:rc==0 -cmd:cd /; ./go-xcat --xcat-core=/xcat-core.tar.bz2 --xcat-dep=/xcat-dep.tar.bz2 -y install; +cmd:cd /; ./go-xcat --xcat-core=/install_xCAT_xcat-core.tar.bz2 --xcat-dep=/install_xCAT_xcat-dep.tar.bz2 -y install; check:rc==0 cmd:source "/etc/profile.d/xcat.sh" check:rc==0 @@ -20,23 +20,24 @@ check:output=~Version cmd:service xcatd status check:rc==0 check:output=~running -cmd:rm -rf /xcat-core.tar.bz2 /xcat-dep.tar.bz2 +cmd:rm -rf /install_xCAT_xcat-core.tar.bz2 /install_xCAT_xcat-dep.tar.bz2 end + start:install_xCAT_on_ubuntu description:install xCAT with go-xcat tool in a fresh environment for ubuntu os:Linux stop:yes -cmd:arc_all=`uname -a`; code=`lsb_release -sc`;if [[ $arc_all =~ "ppc64le" ]]; then arch="ppc64el";else arch="x86_64";fi; cp "/opt/xcat/share/xcat/tools/autotest/testcase/go-xcat/$code-$arch.sources.list" "/etc/apt/sources.list" +cmd:arc_all=`uname -a`; code=`lsb_release -sc`;if [[ $arc_all =~ "ppc64le" ]]; then arch="ppc64el";else arch="x86_64";fi; cp "/opt/xcat/share/xcat/tools/autotest/testcase/go-xcat/$code-$arch.sources.list" "/etc/apt/sources.list" cmd:apt-get clean;apt-get update check:rc==0 -cmd:cp /core-*-snap.tar.bz2 /xcat-core.tar.bz2 +cmd:cp /core-*-snap.tar.bz2 /install_xCAT_xcat-core.tar.bz2 check:rc==0 -cmd:cp /xcat-dep*.tar.bz2 /xcat-dep.tar.bz2 +cmd:cp /xcat-dep*.tar.bz2 /install_xCAT_xcat-dep.tar.bz2 check:rc==0 cmd:ls /go-xcat check:rc==0 -cmd:cd /; ./go-xcat --xcat-core=/xcat-core.tar.bz2 --xcat-dep=/xcat-dep.tar.bz2 -y install; +cmd:cd /; ./go-xcat --xcat-core=/install_xCAT_xcat-core.tar.bz2 --xcat-dep=/install_xCAT_xcat-dep.tar.bz2 -y install; check:rc==0 cmd:source "/etc/profile.d/xcat.sh" check:rc==0 @@ -46,5 +47,7 @@ check:output=~Version cmd:service xcatd status check:rc==0 check:output=~running -cmd:rm -rf /xcat-core.tar.bz2 /xcat-dep.tar.bz2 +cmd:rm -rf /install_xCAT_xcat-core.tar.bz2 /install_xCAT_xcat-dep.tar.bz2 end + + diff --git a/xCAT-test/autotest/testcase/noderange/cases0 b/xCAT-test/autotest/testcase/noderange/cases0 index c0bccfdbf..59b401628 100644 --- a/xCAT-test/autotest/testcase/noderange/cases0 +++ b/xCAT-test/autotest/testcase/noderange/cases0 @@ -31,7 +31,7 @@ cmd:rmdef -t node -o nrtestnode01-nrtestnode10 check:rc==0 end -start:noderange_node[01-10] +start:noderange_node_01-10 description: noderange node[01-10] cmd:mkdef -t node -o nrtestnode[01-10] groups=all check:rc==0 @@ -44,7 +44,7 @@ cmd:rmdef -t node -o nrtestnode[01-10] check:rc==0 end -start:noderange_node[01:10] +start:noderange_node01_10 description: noderange node[01:10] cmd:mkdef -t node -o nrtestnode[01:10] groups=all check:rc==0 @@ -57,7 +57,7 @@ cmd:rmdef -t node -o nrtestnode[01:10] check:rc==0 end -start:noderange_f[1-2]n[1-3] +start:noderange_f1-f2_n1-n3 description: noderange f[1-2]n[1-3] cmd:mkdef -t node -o f[1-2]n[1-3] groups=all check:rc==0 @@ -101,7 +101,7 @@ end #check:rc==0 #end -start:noderange_node10+3 +start:noderange_node10_plus_3 description: noderange node10+3 cmd:mkdef -t node -o nrtestnode10+3 groups=all check:rc==0 @@ -142,7 +142,7 @@ cmd: XCAT_NODE_PREFIX=abc XCAT_NODE_SUFFIX=def XCATBYPASS=1 nodels 10-20 check:output=~abc10def,abc11def,abc12def,abc13def,abc14def,abc15def,abc16def,abc17def,abc18def,abc19def,abc20def end -start:noderange_/nrtestnode.* +start:noderange_slash_urtestnode_dot_star description: noderange /nrtestnode.* cmd:mkdef -t node -o nrtestnode1-nrtestnode3 groups=all check:rc==0 @@ -155,7 +155,7 @@ cmd:rmdef -t node -o nrtestnode1-nrtestnode3 check:rc==0 end -start:noderange_/tmp/nodelistfile +start:noderange_dir_tmp-nodelistfile description: noderange ^/tmp/nodelistfile #cmd:echo #testnode1 > /tmp/nodelist cmd:mkdef -t node -o nrnode1,nrnode2 groups=all diff --git a/xCAT-test/xcattest b/xCAT-test/xcattest index d50d1a404..c0060c415 100755 --- a/xCAT-test/xcattest +++ b/xCAT-test/xcattest @@ -27,15 +27,22 @@ my $needshow = 0; my $restore = 0; my $ret = 0; my $string1 = undef; -#below System label means: only load the [System] aspects in config file -#this usage is only for the first install_xCAT cases used for xCAT daily regression -#it is a workaround to avoid change the xcattest structure, so no need to public -my $initallabel = undef; -my $loadsysteminfo = "System"; my $showbundlefiles = 0; my $showcommandslist = 0; my $stop_to_keep_env = 0; +#----------------------------------- +=head1 + System label usage: + In order to make install xCAT to be the first case for automation daily regression, "System" label is used in this xcattest command. + xcattest -f /opt/xcat/share/xcat/tools/autotest/default.conf:System -t install_xCAT_on_rhels_sles + xcattest -f /opt/xcat/share/xcat/tools/autotest/default.conf:System -t install_xCAT_on_ubuntu + System label means only the [System] aspect will be loaded and no other inital action will be done. +=cut + +#----------------------------------- +my $initallabel = undef; +my $loadsysteminfo = "System"; #Create result directory mkdir $resultdir unless -d $resultdir; @@ -77,7 +84,7 @@ if (&checkoptions) my %bundlefilesinfo = (); if ($showbundlefiles) { - &undlefiles; + &listbundlefiles; exit 0; } @@ -707,18 +714,27 @@ sub loadcase close(FILE); } + if ($needshow) { - log_this("*Test cases:"); - foreach my $case (@cases) { - log_this("$case->{name}"); - } - log_this("*Case name not supported:", @wrongnamecase); + if (@cases) { + log_this("Test cases:"); + foreach my $case (@cases) { + log_this("$case->{name}"); + } + }else { + log_this("Error: Please check the case name or command name"); + } + log_this("Case name not supported:", @wrongnamecase) if (@wrongnamecase); return 0; } - - log_this("*To run:", @rightcase) if (@rightcase); - log_this("*Not to run:", @notrightcase) if (@notrightcase); - log_this("*Case name not supported:", @wrongnamecase) if (@wrongnamecase); + + if (@rightcase) { + log_this("To run:", @rightcase); + }else { + log_this("Error: No case to run, please check the case name or command name"); + } + log_this("Not to run:", @notrightcase) if (@notrightcase); + log_this("Case name not supported:", @wrongnamecase) if (@wrongnamecase); return 0; } sub getnodeattr From ad100dfb5693364599d6deea705d9979a31fa9e3 Mon Sep 17 00:00:00 2001 From: caomengmeng Date: Tue, 20 Sep 2016 02:36:00 -0400 Subject: [PATCH 7/8] update xcattest after PR --- xCAT-test/xcattest | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/xCAT-test/xcattest b/xCAT-test/xcattest index c0060c415..0b931a528 100755 --- a/xCAT-test/xcattest +++ b/xCAT-test/xcattest @@ -47,9 +47,9 @@ my $loadsysteminfo = "System"; #Create result directory mkdir $resultdir unless -d $resultdir; -# create a log for xcattest -h,-s,-l related +# create a log for xcattest my $timestamp = `date +"%Y%m%d%H%M%S"`; -open(LOG, ">$resultdir/command.logs.$timestamp") +open(LOG, ">$resultdir/xcattest.log.$timestamp") or die "Can't open logfile for writing: $!"; if ( @@ -113,9 +113,6 @@ if ($needshow) { # create a log for run test cases -$timestamp = `date +"%Y%m%d%H%M%S"`; -open(LOG, ">$resultdir/xcattest.log.$timestamp") - or die "Can't open logfile for writing: $!"; &log_this("xCAT automated test started at " . scalar(localtime())); open(LOG_ERR, ">$resultdir/failedcases.$timestamp") or die "Can't open error logfile for writing: $!"; @@ -1056,7 +1053,7 @@ sub listbundlefiles } } } - + close(FILE); if (!$skip){ $bundlefilesinfo{$bundlefile} = "No description, add \"description: details\" in this bundle file"; } @@ -1183,11 +1180,9 @@ sub reordercases sub checkoptions { -#print "$showbundlesorcommands\n"; -#print "$needshow\n"; #-b,-c,-t,-s should be defined at least one if (!defined($bundlelist) && !defined($caselist) && !defined($cmdlist) && !defined($showbundlesorcommands)) { - log_this("Error: please define options correctly"); + log_this("Error: please define options correctly, see below usage information:"); return 1; }elsif (defined($showbundlesorcommands) && (defined($bundlelist) || defined($caselist) || defined($cmdlist))) { # -s can't be used together with -c,-b,-t From 2c400fd595ac5c21587b4567e03e90687a5c8470 Mon Sep 17 00:00:00 2001 From: caomengmeng Date: Wed, 21 Sep 2016 04:06:27 -0400 Subject: [PATCH 8/8] update go-xcat permission --- xCAT-test/autotest/testcase/install_xCAT/case0 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xCAT-test/autotest/testcase/install_xCAT/case0 b/xCAT-test/autotest/testcase/install_xCAT/case0 index 0047a302e..3f0d0d21e 100644 --- a/xCAT-test/autotest/testcase/install_xCAT/case0 +++ b/xCAT-test/autotest/testcase/install_xCAT/case0 @@ -10,7 +10,7 @@ cmd:cp /xcat-dep*.tar.bz2 /install_xCAT_xcat-dep.tar.bz2 check:rc==0 cmd:ls /go-xcat check:rc==0 -cmd:cd /; ./go-xcat --xcat-core=/install_xCAT_xcat-core.tar.bz2 --xcat-dep=/install_xCAT_xcat-dep.tar.bz2 -y install; +cmd:chmod 777 /go-xcat; /go-xcat --xcat-core=/install_xCAT_xcat-core.tar.bz2 --xcat-dep=/install_xCAT_xcat-dep.tar.bz2 -y install; check:rc==0 cmd:source "/etc/profile.d/xcat.sh" check:rc==0 @@ -37,7 +37,7 @@ cmd:cp /xcat-dep*.tar.bz2 /install_xCAT_xcat-dep.tar.bz2 check:rc==0 cmd:ls /go-xcat check:rc==0 -cmd:cd /; ./go-xcat --xcat-core=/install_xCAT_xcat-core.tar.bz2 --xcat-dep=/install_xCAT_xcat-dep.tar.bz2 -y install; +cmd:chmod 777 /go-xcat; /go-xcat --xcat-core=/install_xCAT_xcat-core.tar.bz2 --xcat-dep=/install_xCAT_xcat-dep.tar.bz2 -y install; check:rc==0 cmd:source "/etc/profile.d/xcat.sh" check:rc==0