2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-08-22 19:20:24 +00:00

Modify depending on comments

This commit is contained in:
hu-weihua
2017-08-14 01:07:09 -04:00
parent 807c2f0634
commit e421982a59

View File

@@ -15,7 +15,6 @@ my $discovery_mode = undef;
my $discovery_target_node = undef;
my $bmc_dynamic_ip_range = undef;
#my $node_dynamic_ip_range = undef;
my $bmc_target_mac = undef;
my $osimage = undef;
my $bmc_discovery_only = 0;
@@ -44,11 +43,19 @@ my $be_discovered_bmc_node;
my $discovery_prodefine_node_name_in_automation = "discovery_prodefine_node_name_in_automation";
my @expected_attrs_for_bmc_discovery = ("mtm", "serial", "bmcusername", "bmcpassword", "bmc");
my $expected_attrs_for_bmc_discovery_str = join(",", @expected_attrs_for_bmc_discovery);
my @expected_attrs_for_mtms_based_node_discovery = ("ip", "bmc", "mtm", "serial", "mgt", "cons", "netboot", "mac", "bmcusername", "bmcpassword");
my $expected_attrs_for_mtms_based_node_discovery_str = join(",",@expected_attrs_for_mtms_based_node_discovery);
my @expected_attrs_for_switch_based_node_discovery = ("ip", "bmc", "mtm", "serial", "mgt", "cons", "netboot", "mac", "bmcusername", "bmcpassword", "switch", "switchport");
my $expected_attrs_for_switch_based_node_discovery_str = join(",", @expected_attrs_for_switch_based_node_discovery);
#----------------------usage--------------------
$::USAGE = "Usage:
To test bmc discovery process, switch_based node discovery process or mtms_based node discovery process.
To get help:
$program_name -h
@@ -62,12 +69,18 @@ To test the whole process of switch_based node discovery
$program_name --discovery_mode switch --discovery_target_node <node_name> --bmc_dynamic_ip_range <ip_range> --osimage <image>
Options:
discovery_target_node: Required. The node planned to be discovered which must be definied in xcat DB ahead.
discovery_target_node: Required. The reference node planned to be discovered which must be definied in xcat DB ahead.
bmc_dynamic_ip_range: Required. A valid dymanic ip range which has been configured in DHCP server and can offer service before invoking $program_name. The format of ip range is x.y1-y2.n1-n2.m1-m2
discovery_mode: The mode of discovery. Valid mode are mtms, switch.
osimage: The image used to deploy on target node.
bmc_discovery_only: Just test bmc discovery process, not test node discovery process.
discovery_mode: The mode of discovery. Valid mode are mtms or switch. Used with option 'osimage'. Can not be used with 'bmc_discovery_only' at the same time.
osimage: The image used to deploy on target node. Used with option 'discovery_mode'. Can not be used with option 'bmc_discovery_only' at the same time.
bmc_discovery_only: Just test bmc discovery process, not test node discovery process. Can not be used with option 'osimage' or 'discovery_mode' at the same time.
Notes:
Up to now, only support one reference test node.
When preparing reference test node, below atrributes are required for each test scenario.
For only bmc discovery: $expected_attrs_for_bmc_discovery_str
For mtm_based node discovery: $expected_attrs_for_mtms_based_node_discovery_str
For switch_based node discovery: $expected_attrs_for_switch_based_node_discovery_str
";
@@ -83,7 +96,7 @@ if (
"bmc_discovery_only" => \$bmc_discovery_only)
)
{
print "[ERROR] Invalid usage.\n$::USAGE";
print "[ERROR] Invalid usage.\n\n$::USAGE";
to_exit(1);
}
@@ -94,19 +107,25 @@ if ($needhelp)
}
unless(defined $discovery_target_node and defined $bmc_dynamic_ip_range){
print "[ERROR] Missing option.\n$::USAGE";
print "[ERROR] options 'discovery_target_node' and 'bmc_dynamic_ip_range' are required.\n\n$::USAGE";
to_exit(1);
}
if (defined $discovery_mode)
{
unless ($discovery_mode eq "mtms" || $discovery_mode eq "switch") {
print "[ERROR] Invalid value of option 'discovery_mode'\n$::USAGE";
if($bmc_discovery_only){
if($discovery_mode or $osimage){
print "[ERROR] option 'bmc_discovery_only' can not be used with 'discovery_mode' or 'osimage' at the sametime\n\n$::USAGE";
to_exit(1);
}
unless($osimage){
print "[ERROR] Missing option osimage.\n$::USAGE";
}else{
unless($discovery_mode and $osimage){
print "[ERROR] options 'discovery_mode' and 'osimage' are necessary for testing node discovery process. Or use option 'bmc_discovery_only' to test bmc discovery\n\n$::USAGE";
to_exit(1);
}
}
if (defined $discovery_mode){
unless ($discovery_mode eq "mtms" || $discovery_mode eq "switch") {
print "[ERROR] Invalid value of option 'discovery_mode'\n$::USAGE";
to_exit(1);
}
}
@@ -116,26 +135,26 @@ $SIG{TERM} = $SIG{INT} = sub {
};
print "----------------Check the configuration of test case itself----------------\n";
$rst = check_test_case_self_conf($discovery_mode, $discovery_target_node, \@error);
$rst = check_test_case_self_conf(\@error);
if ($rst) {
print "To Check the configration of test case itself......[Failed]\n";
dump_error(\@error);
dump_info(\@error);
to_exit(1);
} else {
print "To Check the configration of test case itself......[pass]\n";
print "The discovery mode is $discovery_mode\n" if ($discovery_mode);
print "The reference node is $discovery_target_node\n";
my @output = runcmd("lsdef $discovery_target_node");
print "$_\n" foreach (@output);
dump_info(\@output);
print "The reference bmc mac is $bmc_target_mac\n" if ($bmc_target_mac);
print "The bmc dynamic ip range is $bmc_dynamic_ip_range\n" if ($bmc_dynamic_ip_range);
}
print "----------------To set up test environment for bmc discovery----------------\n";
$rst = set_up_test_env_for_bmc_discovery(\@error);
$rst = reset_bmc_to_factory(\@error);
if ($rst) {
print "To set up test environment......[Failed]\n";
dump_error(\@error);
dump_info(\@error);
to_exit(1);
} else {
print "To set up test environment......[pass]\n";
@@ -147,13 +166,13 @@ print "----------------To discover BMC of $discovery_target_node ---------------
$rst = bmc_discovery(\@error);
if ($rst) {
print "To discover BMC of $discovery_target_node......[Failed]\n";
dump_error(\@error);
dump_info(\@error);
to_exit(1);
} else {
print "To discover BMC of $discovery_target_node......[pass]\n";
print "The discovered BMC is $be_discovered_bmc_node\n";
my @output = runcmd("lsdef $be_discovered_bmc_node");
print "$_\n" foreach (@output);
dump_info(\@output);
}
if ($bmc_discovery_only) {
@@ -164,26 +183,26 @@ print "----------------To set up test environment for node discovery------------
$rst = set_up_test_env_for_node_discovery(\@error);
if ($rst) {
print "To set up test environment......[Failed]\n";
dump_error(\@error);
dump_info(\@error);
to_exit(1);
} else {
print "To set up test environment......[pass]\n";
print "The predefine node used to be discovered is $discovery_prodefine_node_name_in_automation\n";
my @output = runcmd("lsdef $discovery_prodefine_node_name_in_automation");
print "$_\n" foreach (@output);
dump_info(\@output);
}
print "----------------To discover node $discovery_target_node ----------------\n";
$rst = node_discovery(\@error);
if ($rst) {
print "To discover node $discovery_prodefine_node_name_in_automation......[Failed]\n";
dump_error(\@error);
dump_info(\@error);
to_exit(1);
} else {
print "To discover node $discovery_prodefine_node_name_in_automation......[pass]\n";
print "The discovered node is $discovery_prodefine_node_name_in_automation\n";
my @output = runcmd("lsdef $discovery_prodefine_node_name_in_automation");
print "$_\n" foreach (@output);
dump_info(\@output);
}
to_exit(0);
@@ -198,15 +217,13 @@ to_exit(0);
# Retrun code:
#--------------------------------------------------------
sub check_test_case_self_conf {
my $discovery_mode = shift;
my $target_node = shift;
my $error_ref = shift;
@$error_ref = ();
$discovery_target_node_info{nodename} = $target_node;
my @output = runcmd("lsdef -l $target_node");
$discovery_target_node_info{nodename} = $discovery_target_node;
my @output = runcmd("lsdef -l $discovery_target_node");
if ($::RUNCMD_RC) {
push @$error_ref, "The reference node $target_node is not defined in xcat database";
push @$error_ref, "The reference node $discovery_target_node is not defined in xcat database";
} else {
#backup original node definition
@@ -235,7 +252,7 @@ sub check_test_case_self_conf {
if (@missing_attrs) {
my $missing_attrs_str = join(",", @missing_attrs);
push @$error_ref, "The reference node '$target_node' is missing '$missing_attrs_str' attribute";
push @$error_ref, "The reference node '$discovery_target_node' is missing '$missing_attrs_str' attribute";
}
}
@@ -367,12 +384,12 @@ sub runcmd {
#--------------------------------------------------------
# Fuction name: dump_error
# Fuction name: dump_info
# Description:
# Atrributes:
# Retrun code:
#--------------------------------------------------------
sub dump_error {
sub dump_info {
my $error_ref = shift;
foreach (@$error_ref) {
print "$_\n";
@@ -380,13 +397,12 @@ sub dump_error {
}
#--------------------------------------------------------
# Fuction name: set_up_test_env_for_bmc_discovery
# Fuction name: reset_bmc_to_factory
# Description:
# Atrributes:
# Retrun code:
#--------------------------------------------------------
sub set_up_test_env_for_bmc_discovery {
my $error_ref = shift;
sub reset_bmc_to_factory {
my @output;
my $tmp_bmc_name;
@@ -420,7 +436,7 @@ sub set_up_test_env_for_bmc_discovery {
@output = runcmd("$cmd");
if ($::RUNCMD_RC) {
print "[Failed]\n";
dump_error(\@output);
dump_info(\@output);
return 1;
} else {
print "[Successful]\n";
@@ -437,7 +453,6 @@ sub set_up_test_env_for_bmc_discovery {
# Retrun code:
#--------------------------------------------------------
sub set_up_test_env_for_node_discovery {
my $error_ref = shift;
my @output;
#To clear up history and predefine node
@@ -474,7 +489,7 @@ sub set_up_test_env_for_node_discovery {
@output = runcmd("$cmd");
if ($::RUNCMD_RC) {
print "failed\n";
dump_error(\@output);
dump_info(\@output);
return 1;
} else {
print "successful\n";
@@ -602,7 +617,7 @@ sub node_discovery {
my $error_ref = shift;
my @output;
print "Boot target node $discovery_target_node, start discovery process\n";
print "Boot target node $discovery_prodefine_node_name_in_automation, start discovery process\n";
my @cmds = ("rsetboot $be_discovered_bmc_node net",
"rpower $be_discovered_bmc_node boot");
foreach my $cmd (@cmds) {
@@ -615,6 +630,8 @@ sub node_discovery {
}
}
print "Waiting for node $discovery_prodefine_node_name_in_automation be discoveried\n";
#suppose discovery process should get MAC address for predined node in 10 minuts
my $find_me_succ = 0;
my $mac_in_find_me;
@@ -659,7 +676,7 @@ sub node_discovery {
@output = runcmd("$cmd");
print "$_\n" foreach (@output);
if ($::RUNCMD_RC) {
push @$error_ref, "Add getadapter into chain failed";
push @$error_ref, "Add getadapter,bmcsetup,osimage into chain failed";
return 1;
}
}
@@ -683,7 +700,7 @@ sub node_discovery {
return 1;
}
print "getadapter obtain below adapter infomation\n";
print "$_\n" foreach (@output);
dump_info(\@output);
if (!(grep { /$discovery_target_node_info{mac}/i } @output)) {
push @$error_ref, "The adapters information obtained by getadapter does not contain expected mac $discovery_target_node_info{mac}";
@@ -782,18 +799,17 @@ sub node_discovery {
#--------------------------------------------------------
sub parse_dynamic_ip_range {
my $original_dynamic_ip_str = shift;
my @ips = ();
my @sec = split(/\./, $original_dynamic_ip_str);
for (my $i = 0 ; $i <= $#sec ; $i++) {
$sec[$i] = "{$1,$2}" if ($sec[$i] =~ /(\d+)-(\d+)/);
$sec[$i] = "{$1..$2}" if ($sec[$i] =~ /(\d+)-(\d+)/);
}
my $str = join(".", @sec);
my @output = runcmd("echo $str");
return split(/ /, $output[0]);
}
}
#--------------------------------------------------------
# Fuction name: parse_dynamic_ip_range
# Fuction name: calculate_bmc_info
# Description:
# Atrributes:
# Retrun code: