Merge branch 'master' of ssh://git.code.sf.net/p/xcat/xcat-core

This commit is contained in:
Jarrod Johnson 2014-05-15 10:24:24 -04:00
commit 2e40553fb7
51 changed files with 1747 additions and 144 deletions

View File

@ -86,7 +86,7 @@ if [ "$c_flag" -a "$d_flag" ];then
exit 2
fi
uploader="bp-sawyers"
uploader="ligc"
# Find where this script is located to set some build variables
old_pwd=`pwd`
cd `dirname $0`
@ -279,7 +279,7 @@ __EOF__
cat << '__EOF__' > mklocalrepo.sh
. /etc/lsb-release
cd `dirname $0`
echo deb file://"`pwd`" $DISTRIB_CODENAME main > /etc/apt/sources.list.d/xcat-core.list
echo deb [arch=amd64] file://"`pwd`" $DISTRIB_CODENAME main > /etc/apt/sources.list.d/xcat-core.list
__EOF__
chmod 775 mklocalrepo.sh
@ -380,7 +380,7 @@ __EOF__
cat << '__EOF__' > mklocalrepo.sh
. /etc/lsb-release
cd `dirname $0`
echo deb file://"`pwd`" $DISTRIB_CODENAME main > /etc/apt/sources.list.d/xcat-dep.list
echo deb [arch=amd64] file://"`pwd`" $DISTRIB_CODENAME main > /etc/apt/sources.list.d/xcat-dep.list
__EOF__
chmod 775 mklocalrepo.sh

View File

@ -0,0 +1,10 @@
# AIX Bundle file for compiler runtime packages
I:xlC.aix61
I:xlC.rte
I:xlfrte
I:xlfrte.aix61
I:xlfrte.msg.en_US
I:xlsmp.aix61.rte
I:xlsmp.msg.en_US.rte
I:xlsmp.rte

View File

@ -89,7 +89,7 @@ rm -rf $RPM_BUILD_ROOT
%ifos linux
if [ -f "/proc/cmdline" ]; then # prevent running it during install into chroot image
if [ -f $RPM_INSTALL_PREFIX0/sbin/xcatd ]; then
/etc/init.d/xcatd reload
/etc/init.d/xcatd restart
fi
fi
%endif

View File

@ -86,7 +86,7 @@ sub addKernelParms {
# get this nodes nic, ip, netmask, gateway, and mac. Returns them in a 5 element array.
sub getNodeIpInfo {
my $args = shift @_;
my ($ipprefix) = $args->{mnip}=~m/^(\d+\.\d+)\./; #todo: this is a hack, just using the 1st 2 octets of the mn ip addr
my ($ipprefix) = $args->{mnip}=~m/^(\d+)\./; #todo: this is a hack, just using the 1st octet of the mn ip addr
verbose("using IP prefix $ipprefix");
# parse ip addr show output, looking for ipprefix, to determine nic and ip
@ -106,12 +106,13 @@ sub getNodeIpInfo {
my @nics = grep(m/\s+master\s+$nic\s+/, @output);
if (!scalar(@nics)) { die "Error: can't find the NICs that are part of $nic.\n"; }
($realnic) = $nics[0]=~m/^\d+:\s+(\S+): /;
# go back thru the ip add show output and find the mac of this nic
foreach my $line (@output) {
my ($nictmp, $mactmp, $foundnic);
if (($nictmp) = $line=~m/^\d+:\s+(\S+): / && $nictmp eq $realnic) { $foundnic = 1; }
if (($mactmp) = $line=~m|^\s+link/ether\s+(\S+) | && $foundnic) { $mac = $mactmp; last; } # got mac, we are done
}
# do not need to go back thru the ip addr show output and find the mac of this nic because the mac
# of the bond nic is the same. Plus the code below does not work right for some reason anyway.
#foreach my $line (@output) {
# my ($nictmp, $mactmp, $foundnic);
# if (($nictmp) = $line=~m/^\d+:\s+(\S+): / && $nictmp eq $realnic) { $foundnic = 1; }
# if (($mactmp) = $line=~m|^\s+link/ether\s+(\S+) | && $foundnic) { $mac = $mactmp; last; } # got mac, we are done
#}
}
# finally, find the gateway

View File

@ -131,8 +131,7 @@ sub updateGrubOnNodes {
}
# Hack the autoinst files to wait in a key spot to make them work even tho it takes
# the NICs almost a min before they can transmit after a state change.
# Hack the autoinst files to overcome the nic coming up delay.
#todo: this has only been tested with SLES nodes
sub modifyAutoinstFiles {
my $nr = shift @_;
@ -142,21 +141,28 @@ sub modifyAutoinstFiles {
my @nodes = runcmd("nodels $nr");
chomp(@nodes);
# Modify chroot.sles to insert a wait in the /etc/init.d/network of each node. This is
# necessary because even tho compute.sles11.softlayer.tmpl configures bonding, when autoyast
# reboots the node after installing the rpms, it does not bring up the network in the normal way
# at first and seems to skip any bonding and the if-up.d scripts. So we are left doing this.
# (After autoyast is done with all of its post-configuration, it brings up the network in the
# normal way, so bonding gets done then, which is good at least.)
# Edit each file to have chroot.sles insert a wait at the end of /etc/init.d/network
# this finds the end of boot.sh script (which is chroot.sles)
my $search = '\n\]\]>\s*</source>\s*</script>\s*</chroot-scripts>';
# hack the /etc/init.d/network script to put a wait in it
my $file = '/mnt/etc/init.d/network'; # at this point in the installation, the permanent file system is just mounted
#my $waitstring = 'echo Sleeping for 55s;sleep 55';
# this is the string to insert in the nodes /etc/init.d/network script. It is a while loop pinging the mn, but some of the chars need to be escaped for sed
my $waitstring = 'echo -n Waiting to reach xCAT mgmt node ' . $bootparms->{mnip} . '.;xcatretries=60;while \[ \$\(\(xcati+=1\)\) -le \$xcatretries \] \&\& ! ping -c2 -w3 ' . $bootparms->{mnip} .' \>\/dev\/null 2\>\&1; do echo -n .; done; if \[ \$xcati -le \$xcatretries \]; then echo success; else echo failed; fi; sleep 3';
my $waitstring = 'echo -n Waiting to reach xCAT mgmt node ' . $bootparms->{mnip} . '.;xcatretries=60;while \[ \$\(\(xcati+=1\)\) -le \$xcatretries \] \&\& ! ping -c2 -w3 ' . $bootparms->{mnip} .' \>\/dev\/null 2\>\&1; do echo -n .; done; if \[ \$xcati -le \$xcatretries \]; then echo success; else echo failed; fi';
# this crazy sed string is from google. It gathers up the whole file into the hold buffer, and then the substitution is done on the whole file
my $sedstring = q|sed -n '1h;1!H;${;g;s/\(\t\treload_firewall\n\)\n/\1\t\t| . $waitstring . q(\n\n/g;p;}') . " $file > $file.new";
# finally create the perl replace string that will be used to modify the autoinst file
my $replace = "$sedstring\nchmod 755 $file.new; mv -f $file.new $file";
# Now instead we add a script that gets invoked by the OS after the nic is brought up
# Add a script that gets invoked by the OS after the nic is brought up
# Note: this does not work, because midway thru the autoyast process, the if-up.d scripts do not seem to get invoked
# so autoyast fails to get the media
# these are specific to SLES
#my $netdir = '/etc/sysconfig/network';
#my $filename = '/etc/sysconfig/network/if-up.d/xcat-sl-wait';
@ -164,9 +170,6 @@ sub modifyAutoinstFiles {
#todo: to support rhel, use these values instead
#my $netdir='/etc/sysconfig/network-scripts';
#my $filename='/sbin/ifup-local';
# this does not work, because midway thru the autoyast process, the if-up.d scripts do not seem to get invoked
# so autoyast fails to get he media
#my $replace = qq(
#FILENAME=$filename
#NETDIR=$netdir
@ -194,10 +197,15 @@ sub modifyAutoinstFiles {
#chmod +x $FILENAME
#);
# now actually update the file
# The compute.sles11.softlayer.tmpl file contains 2 variables (node ip and netmask) that are
# not replaced by Template.pm. Substitute those in the autoinst files now.
# Also use our own multiline sed to put the network script hack in.
print "Updating /install/autoinst files.\n";
foreach my $n (@nodes) {
my $f = "/install/autoinst/$n";
my ($ip, $netmask, $gateway) = getNodeIpInfo($n);
runcmd("sed -i 's/#NODEIPADDR#/$ip/;s/#NODENETMASK#/$netmask/;s/#NODEGATEWAY#/$gateway/' $f");
my $matches = sed($f, $search, $replace, mode=>'insertbefore');
if (!$matches) { die "Error: could not find the right place in $f to insert the sed of the network wait.\n"; }
}
@ -213,8 +221,65 @@ sub copySyscloneFiles {
}
# Get IP and network of a node
sub getNodeIpInfo {
my $node = shift;
# get ip for the node
my @output = runcmd("nodels $node hosts.ip");
chomp($output[0]);
my ($junk, $ip) = split(/\s+/, $output[0]);
#todo: also support getting the ip from name resolution
if (!$ip) { die "Error: the ip attribute must be set for $node.\n"; }
# find relevant network in the networks table
# first get the networks in a hash
my %networks;
@output = runcmd("lsdef -t network -ci net,mask,gateway");
foreach my $line (@output) {
chomp($line);
my ($netname, $attr, $val) = $line =~ m/^(.+):\s+(.+?)=(.+)$/;
$networks{$netname}->{$attr} = $val;
}
# now go thru the networks looking for the correct one
my ($netmask, $gateway);
foreach my $key (keys %networks) {
if (isIPinNet($ip, $networks{$key}->{net}, $networks{$key}->{mask})) { # found it
$netmask = $networks{$key}->{mask};
$gateway = $networks{$key}->{gateway};
last;
}
}
if (!$netmask) { die "Error: could not find a network in the networks table that $node $ip is part of.\n"; }
if (!$gateway) { die "Error: gateway not specified in the networks table for the network that $node $ip is part of.\n"; }
verbose("IP info for $node: ip=$ip, netmask=$netmask, gateway=$gateway");
return ($ip, $netmask, $gateway);
}
# Is the IP in the network/netmask combo
sub isIPinNet {
my ($ip, $net, $mask) = @_;
my $ipbin = convert2bin($ip);
my $netbin = convert2bin($net);
my $maskbin = convert2bin($mask);
$ipbin &= $maskbin;
if ($ipbin && $netbin && ($ipbin == $netbin)) { return 1; }
else { return 0; }
}
# Convert dotted decimal format (1.2.3.4) to a binary number
sub convert2bin {
my @arr=split(/\./, shift);
my ($bin) = unpack('N', pack('C4',@arr ) );
return $bin;
}
# this is like multi-line sed replace function
# Args: filename, search-string, replace-string
# Args: filename, search-string, replace-string, options (mode=>{insertbefore,insertafter,replace})
sub sed {
my ($file, $search, $replace, %options) = @_;
#my $opts = 's';

View File

@ -0,0 +1,228 @@
#!/usr/bin/perl
# xCAT postscript for configuring bonding of nics.
# Usage: configbond bond1 eth1 [eth3]
#
# Note: this postscript currently has some assumptions that are specific to the softlayer environment.
# It is only used to configure bond1, because bond0 gets configured by the node provisioning process.
use strict;
# Check number of args
my $nargs = $#ARGV + 1;
if (scalar(@ARGV) < 2 || scalar(@ARGV) > 3) {
system("logger -t xcat -p local4.err 'Usage: configbond bond dev0 [dev1]'");
exit 1;
}
my $bond = shift(@ARGV);
my $nic = $ARGV[0];
my @devs = ();
push(@devs,$ARGV[0]);
if (defined($ARGV[1])) { push(@devs,$ARGV[1]); }
my $nicips = $ENV{NICIPS};
my $nicnetworks = $ENV{NICNETWORKS};
my $net_cnt = $ENV{NETWORKS_LINES};
#todo: these are specific to softlayer. They should be another attribute or argument
my $bondingopts = 'mode=4 miimon=100 downdelay=0 updelay=0 lacp_rate=fast xmit_hash_policy=1';
my $netmask ='';
my $ipaddr = '';
my $nic_num = '';
my $subnet = '';
my $nic_net = '';
my $net_name = '';
my @nic_nets = (); # array of networks for this nic
my @nic_ips =(); # array of ipaddresses for this nic
my @networks = (); # array of all networks from networks table.
# { network_name, subnet, netmask }
system("logger -t xcat -p local4.err 'configbond: Master: $bond'");
system("logger -t xcat -p local4.err 'configbond: Slaves: @devs'");
#system("logger -t xcat -p local4.err 'configbond: NIC: $nic'");
system("logger -t xcat -p local4.err 'configbond: NICNETWORKS: $nicnetworks'");
system("logger -t xcat -p local4.err 'configbond: NICIPS: $nicips'");
# Update modprobe
my $file = "/etc/modprobe.d/$bond.conf";
if (!open(FILE, ">$file")) { system("logger -t xcat -p local4.err 'configbond: cannot open $file.'"); exit 1; }
print FILE "alias $bond bonding\n";
# the bonding options are put in the ifcfg file instead
#print FILE "options $bond mode=balance-rr miimon=100\n";
close FILE;
# create array of network info. Needed in case where there are
# more than one ip address per nic and shouldn't be many networks.
my $net_info;
my $cnt = 1;
while ( $cnt <= $net_cnt ) {
$net_info = $ENV{"NETWORKS_LINE$cnt"};
$net_info =~ /^netname=([^\|]*)\|\|/;
$net_name = $1;
$net_info =~ /net=([^\|]*)\|\|/;
$subnet = $1;
$net_info =~ /mask=([^\|]*)\|\|/;
$netmask = $1;
push @{ $networks[$cnt-1] }, ($net_name, $subnet, $netmask);
$cnt +=1;
}
# get network or networks for this nic from NICNETWORKS:
# eth0:1_0_0_0-255_255_0_0|network2,eth1:1_1_0_0
# create array of networks for this nic
foreach my $nic_networks (split(/,/,$nicnetworks)) {
my @net = ();
if ( $nic_networks =~ /!/ ) {
@net = split(/!/,$nic_networks);
} else {
@net = split(/:/,$nic_networks);
}
if ($net[0] eq $nic) {
@nic_nets = split(/\|/,$net[1]);
last;
}
}
# get all nic ipaddress from $nicips: i.e. eth0:1.0.0.1|2.0.0.1,eth1:1.1.1.1
# Then get all ips for this specific nic, i.e. eth0.
foreach my $ips (split(/,/,$nicips)) {
my @ip = ();
if ( $ips =~ /!/ ) {
@ip = split(/!/,$ips);
} else {
@ip = split(/:/,$ips);
}
if ($ip[0] eq $nic ) {
@nic_ips = split(/\|/,$ip[1]);
}
}
my $i;
for ($i=0; $i < (scalar @nic_ips) ; $i++ ) {
# Time to create the interfaces.
# loop through the nic networks, find the matching networks to get the
# subnet and netmask and then create the appropriate ifcfg file for linux
my $specific_nic = $nic;
if ($i > 0) {
$specific_nic = $nic . ":" . ($i);
}
#todo: support case in which nicnetworks is not specified, find the correct network by calculation
$cnt = 0;
$subnet = "";
$netmask = "";
$net_name = "";
while ( $cnt < $net_cnt ) {
if ( $networks[$cnt][0] eq $nic_nets[$i] ) {
$subnet = $networks[$cnt][1];
$netmask = $networks[$cnt][2];
$cnt = $net_cnt; # found match - get out.
}
else {
$cnt++;
}
}
# check that there is a subnet and netmask set
if ( !(length($subnet) > 0) || !(length($netmask) > 0) ) {
system("logger -t xcat -p local4.err 'configbond: network subnet or netmask not set.'");
exit 1;
}
system("logger -t xcat -p local4.err 'configbond: network subnet and netmask: $subnet, $netmask'");
system("logger -t xcat -p local4.err 'configbond: $specific_nic, $nic_ips[$i]'");
# Write the master info to the ifcfg file
if (-d "/etc/sysconfig/network-scripts") {
# rhel/centos/fedora
my $dir = "/etc/sysconfig/network-scripts";
if (!open(FILE, ">$dir/ifcfg-$bond")) { system("logger -t xcat -p local4.err 'configbond: cannot open $dir/ifcfg-$bond.'"); exit 1; }
print FILE "DEVICE=$bond\n";
print FILE "BOOTPROTO=none\n";
print FILE "IPADDR=$nic_ips[$i]\n";
print FILE "NETMASK=$netmask\n";
print FILE "ONBOOT=yes\n";
print FILE "USERCTL=no\n";
print FILE qq(BONDING_OPTS="$bondingopts"\n);
close FILE;
# Configure slaves
foreach my $dev (@devs) {
system("logger -t xcat -p local4.err 'configbond: slave dev: $dev'");
if (!open(FILE, ">$dir/ifcfg-$dev")) { system("logger -t xcat -p local4.err 'configbond: cannot open $dir/ifcfg-$dev'"); exit 1; }
print FILE "DEVICE=$dev\n";
print FILE "BOOTPROTO=none\n";
print FILE "MASTER=$bond\n";
print FILE "ONBOOT=yes\n";
print FILE "SLAVE=yes\n";
print FILE "USERCTL=no\n";
close FILE;
}
}
elsif (-d "/etc/sysconfig/network") {
# sles
my $dir = "/etc/sysconfig/network";
if (!open(FILE, ">$dir/ifcfg-$bond")) { system("logger -t xcat -p local4.err 'configbond: cannot open $dir/ifcfg-$bond.'"); exit 1; }
print FILE "BOOTPROTO=static\n";
print FILE "BONDING_MASTER=yes\n";
print FILE "BONDING_MODULE_OPTS='$bondingopts'\n";
print FILE "NAME='Bonded Interface'\n";
print FILE "IPADDR=$nic_ips[$i]\n";
print FILE "NETMASK=$netmask\n";
print FILE "STARTMODE=onboot\n";
print FILE "USERCONTROL=no\n";
my $devnum = 0;
foreach my $dev (@devs) {
print FILE "BONDING_SLAVE_$devnum=$dev\n";
$devnum++;
}
close FILE;
# Configure slaves
foreach my $dev (@devs) {
system("logger -t xcat -p local4.err 'configbond: slave dev: $dev'");
if (!open(FILE, ">$dir/ifcfg-$dev")) { system("logger -t xcat -p local4.err 'configbond: cannot open $dir/ifcfg-$dev'"); exit 1; }
print FILE "BOOTPROTO=none\n";
print FILE "STARTMODE=hotplug\n";
close FILE;
}
}
else {
# do not recognize this distro
system("logger -t xcat -p local4.err 'configbond: network directory is not either the Red Hat or SuSE format.'");
exit 1;
}
# Apply the changes. Since we are only doing bond1 right now, lets not restart the whole network
# so we dont disrupt the installnic connection. Instead we just need to bring down the slave nics,
# and then bring up the bond nic.
#runcmd("service network restart");
foreach my $dev (@devs) {
runcmd("ifdown $dev");
}
runcmd("ifdown $bond"); # in case it was already up
runcmd("ifup $bond"); # note: this wont reload the bonding kernel module, so we are depending on the provisioning process to already have set the correct bonding options
system("logger -t xcat -p local4.info 'configbond: successfully configured $specific_nic.'");
}
exit 0;
sub runcmd {
my $cmd = shift @_;
$cmd .= ' 2>&1';
my @output = `$cmd`;
my $rc = $? >> 8;
if ($rc) {
system("logger -t xcat -p local4.err 'configeth: command $cmd failed with rc $rc: " . join('',@output) . "'");
my $errout= "configeth: command $cmd failed with rc $rc.";
`echo $errout`;
exit $rc;
}
}

View File

@ -1,6 +1,28 @@
#!/bin/bash
# set the default route of the node to the ip address and nic passed in
# this should be added to the postbootscripts, NOT postscripts
set -x
ip route replace to default via $1 dev $2
gateway="$1"
nic="$2"
# set it temporarily
echo "ip route replace to default via $gateway dev $nic"
ip route replace to default via $gateway dev $nic
# set it permanently
#todo: this is only for sles right now
file=/etc/sysconfig/network/routes
if grep -q -E '^default ' $file; then
# replace the default route that is already in there
sed -i 's/^default .*$/default '$gateway' - -/' $file
else
# no default route yet, append to file
echo "default $gateway - -" >>$file
fi
# While we are here, clean up the network wait hack, if it is still there.
# (It was added during scripted install, because autoyast will not use the bond
# configuration for 1 part of the process.) Do not know a better place to clean
# this up.
sed -i '/Waiting to reach xCAT mgmt node/d' /etc/init.d/network

View File

@ -67,7 +67,6 @@
</user>
</users>
<networking>
<keep_install_network config:type="boolean">true</keep_install_network>
<dns>
<domain>#TABLE:site:key=domain:value#</domain>
<hostname>#TABLE:nodelist:$NODE:node#</hostname>
@ -78,10 +77,46 @@
<search>#TABLE:site:key=domain:value#</search>
</searchlist>
</dns>
<interfaces config:type="list">
<interface>
<bonding_master>yes</bonding_master>
<bonding_module_opts>mode=4 miimon=100 downdelay=0 updelay=0 lacp_rate=fast xmit_hash_policy=1</bonding_module_opts>
<bonding_slave0>eth0</bonding_slave0>
<device>bond0</device>
<bootproto>static</bootproto>
<startmode>auto</startmode>
<ipaddr>#NODEIPADDR#</ipaddr>
<netmask>#NODENETMASK#</netmask>
<usercontrol>no</usercontrol>
</interface>
<interface>
<bootproto>none</bootproto>
<device>eth0</device>
<name>Ethernet Card 0</name>
<startmode>off</startmode>
</interface>
</interfaces>
<routing>
<ip_forward config:type="boolean">false</ip_forward>
<routes config:type="list">
<route>
<destination>default</destination>
<device>-</device>
<gateway>#NODEGATEWAY#</gateway>
<netmask>-</netmask>
</route>
</routes>
</routing>
</networking>
<files config:type="list">
<file>
<file_contents><![CDATA[alias bond0 bonding
]]></file_contents>
<file_owner>root</file_owner>
<file_path>/etc/modprobe.d/bond0.conf</file_path>
<file_permissions>644</file_permissions>
</file>
</files>
<scripts>
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.sles#
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/chroot.sles#

View File

@ -1,43 +0,0 @@
#!/bin/bash
# Add a script that will run when the network is brought up to wait until the
# xcat mn can be pinged.
. /tmp/post-install/variables.txt
if [ -d "/etc/sysconfig/network-scripts/" ];then
#redhat
NETDIR=/etc/sysconfig/network-scripts
filename=/sbin/ifup-local
elif [ -d "/etc/sysconfig/network/" ];then
#suse
NETDIR=/etc/sysconfig/network
filename=/etc/sysconfig/network/if-up.d/xcat-sl-wait
else
#ubuntu
echo "Does not support ubuntu."
exit 1
fi
# Create the wait script, overwriting a copy that may have come from the golden client
# (in case the mn/image server is different).
# this part of the file we want to expand the variables in the content
cat >$filename << EOF1
MNIP=$IMAGESERVER
NETDIR=$NETDIR
EOF1
# this part of the file we do NOT want to expand the variables in the content
cat >>$filename << 'EOF2'
NIC="$1"
# look in this ifcfg script to get the nics ip to see if this is the one we should be waiting on
NICIP=`awk -F= '/^IPADDR/ {print $2}' $NETDIR/ifcfg-$NIC | tr -d \' `
if [ "${NICIP%.*.*}" != "${MNIP%.*.*}" ]; then exit; fi # hack: compare the 1st 2 octets
echo -n Waiting to reach xCAT mgmt node $MNIP.
xcatretries=60
while [ $((xcati+=1)) -le $xcatretries ] && ! ping -c2 -w3 $MNIP >/dev/null 2>&1; do echo -n .; done
if [ $xcati -le $xcatretries ]; then echo " success"; else echo " failed"; fi
sleep 3
EOF2
chmod +x $filename

View File

@ -0,0 +1,82 @@
#!/bin/bash
# SI post-install script to configure the efi boot mgr or grub after SI has installed the OS
# SI post-install scripts run in a chroot environment of the final OS image
if [ -d /sys/firmware/efi ]; then
echo "Setting Boot Manager for the next boot."
echo "delete all sysclone boot list"
str_bootnums=`efibootmgr | grep 'syscloneLinux' | awk '{print $1}' | sed 's/boot//i' | sed 's/*//'`
for str_num in $str_bootnums
do
efibootmgr -b $str_num -B -q
done
if [ -f "/boot/efi/EFI/redhat/grub.efi" ];then
efibootmgr -c -l \\EFI\\redhat\\grub.efi -L syscloneLinux
elif [ -f "/boot/efi/efi/SuSE/elilo.efi" ];then
efibootmgr -c -l \\efi\\SuSE\\elilo.efi -L syscloneLinux
else
echo "Can not find the boot loader."
exit 1
fi
else
echo "run grub-install to configure the MBR."
if [ -e /etc/mtab ];then
mv /etc/mtab /etc/mtab.bak
fi
grep -v rootfs /proc/mounts > /etc/mtab
boot_device=''
if [ -f "/etc/systemconfig/systemconfig.conf" ];then
boot_device=`cat /etc/systemconfig/systemconfig.conf | grep BOOTDEV | awk '{print $3}'`
else
boot_root=`mount | grep -E ' on\s+/ type ' | awk '{print $1}'`
boot_device=`echo $boot_root | sed -e 's/[0-9]*$//'`
#str_temp=`mount | awk '{print $1","$3}'`
#for line in $str_temp
#do
# mp=`echo $line | awk -F, '{print $2}'`
# if [ "$mp" = "/" ];then
# boot_device=`echo $line | awk -F, '{print $1}' | sed -e 's/[0-9]*$//'`
# break
# fi
#done
fi
if [ -n "$boot_device" ];then
echo "The boot device is $boot_device"
echo "The boot root device is $boot_root"
else
echo "Can not find the boot device, return error"
exit 1
fi
# set grub to use this boot device
if grep -qe '^VERSION\s*=\s*11' /etc/SuSE-release; then
#sles11, run grub-install.unsupported directly
echo "grub-install.unsupported --no-floppy --recheck $boot_device"
grub-install.unsupported --no-floppy --recheck $boot_device
# note: the error about grub-set-default not existing is harmless, because we want the default to be 0 anyway
else
#for sles10, should run grub-install with parameters
echo "grub-install --no-floppy --recheck $boot_device"
grub-install --no-floppy --recheck $boot_device
fi
# change the entries in the grub conf file to use the correct boot root device
# (not the one leftover from the golden image)
if [ -f "/boot/grub/grub.conf" ];then
conffile="/boot/grub/grub.conf"
else
conffile="/boot/grub/menu.lst"
fi
sed -i 's| root=\S*| root='$boot_root'|' $conffile
sed -i 's| resume=\S*| noresume|' $conffile
if [ -e /etc/mtab.bak ];then
mv -f /etc/mtab.bak /etc/mtab
else
rm -f /etc/mtab
fi
fi

View File

@ -1,9 +1,12 @@
#!/bin/bash
# Configure network settings after SI has installed the OS
# SI post-install script to configure network settings after SI has installed the OS
# SI post-install scripts run in a chroot environment of the final OS image
. /tmp/post-install/variables.txt
bondingopts='mode=4 miimon=100 downdelay=0 updelay=0 lacp_rate=fast xmit_hash_policy=1'
# determine if we should be using a static ip or dhcp
staticIP () {
# Eventually we should use the SI variable IP_ASSIGNMENT_METHOD below to determine this.
@ -35,11 +38,13 @@ if [ -n "$rule_file" ];then
fi
hostname $HOSTNAME
bond=bond0
device_names=`ifconfig -a | grep -i hwaddr | grep -i 'Ethernet' | grep -v usb| awk '{print $1}'`
str_cfg_file=''
if [ -d "/etc/sysconfig/network-scripts/" ];then
#redhat
dir="/etc/sysconfig/network-scripts"
grep -i HOSTNAME /etc/sysconfig/network
if [ $? -eq 0 ];then
sed -i "s/HOSTNAME=.*/HOSTNAME=$HOSTNAME/g" /etc/sysconfig/network
@ -47,21 +52,44 @@ if [ -d "/etc/sysconfig/network-scripts/" ];then
echo "HOSTNAME=$HOSTNAME" >> /etc/sysconfig/network
fi
if staticIP; then
# delete all nic cfg files left over from the golden node
for i in $device_names;do
rm -f "$dir/ifcfg-$i"
done
# set static ip from variables in variables.txt
i="$DEVICE"
str_cfg_file="/etc/sysconfig/network-scripts/ifcfg-$i"
# write ifcfg-bond0. For now we assume the installnic should be part of bond0,
# because in SL i think that is always the case.
i="$bond"
str_cfg_file="$dir/ifcfg-$i"
echo "DEVICE=$i" > $str_cfg_file
echo "BOOTPROTO=static" >> $str_cfg_file
echo "BOOTPROTO=none" >> $str_cfg_file
echo "ONBOOT=yes" >> $str_cfg_file
echo "USERCTL=no" >> $str_cfg_file
echo 'BONDING_OPTS="'$bondingopts'"' >> $str_cfg_file
echo "IPADDR=$IPADDR" >> $str_cfg_file
echo "NETMASK=$NETMASK" >> $str_cfg_file
echo "NETWORK=$NETWORK" >> $str_cfg_file
echo "BROADCAST=$BROADCAST" >> $str_cfg_file
#todo: add gateway config? Not sure, because the boot kernels gateway might not be the final OS gateway
# write ifcfg-eth0
i="$DEVICE"
str_cfg_file="$dir/ifcfg-$i"
echo "DEVICE=$i" > $str_cfg_file
echo "BOOTPROTO=none" >> $str_cfg_file
echo "MASTER=$bond" >> $str_cfg_file
echo "ONBOOT=yes" >> $str_cfg_file
echo "SLAVE=yes" >> $str_cfg_file
echo "USERCTL=no" >> $str_cfg_file
# write modprobe alias config
str_cfg_file="/etc/modprobe.d/$bond.conf"
echo "alias $bond bonding" > $str_cfg_file
else
# use dhcp for all nics
for i in $device_names;do
str_cfg_file="/etc/sysconfig/network-scripts/ifcfg-$i"
str_cfg_file="$dir/ifcfg-$i"
echo "DEVICE=$i" > $str_cfg_file
echo "BOOTPROTO=dhcp" >> $str_cfg_file
echo "NM_CONTROLLED=yes" >> $str_cfg_file
@ -70,23 +98,54 @@ if [ -d "/etc/sysconfig/network-scripts/" ];then
fi
elif [ -d "/etc/sysconfig/network/" ];then
#suse
dir="/etc/sysconfig/network"
echo "$HOSTNAME" > /etc/HOSTNAME
if staticIP; then
# delete all nic cfg files left over from the golden node
for i in $device_names;do
rm -f "$dir/ifcfg-$i"
done
# set static ip from variables in variables.txt
i="$DEVICE"
str_cfg_file="/etc/sysconfig/network/ifcfg-$i"
echo "DEVICE=$i" > $str_cfg_file
echo "BOOTPROTO=static" >> $str_cfg_file
# write ifcfg-bond0. For now we assume the installnic should be part of bond0,
# because in SL i think that is always the case.
i="$bond"
str_cfg_file="$dir/ifcfg-$i"
echo "BOOTPROTO=static" > $str_cfg_file
echo "STARTMODE=onboot" >> $str_cfg_file
echo "BONDING_MASTER=yes" >> $str_cfg_file
echo "BONDING_MODULE_OPTS='$bondingopts'" >> $str_cfg_file
echo "NAME='Bonded Interface'" >> $str_cfg_file
echo "IPADDR=$IPADDR" >> $str_cfg_file
echo "NETMASK=$NETMASK" >> $str_cfg_file
echo "NETWORK=$NETWORK" >> $str_cfg_file
echo "BROADCAST=$BROADCAST" >> $str_cfg_file
echo "USERCONTROL=no" >> $str_cfg_file
echo "BONDING_SLAVE_0=$DEVICE" >> $str_cfg_file
# write ifcfg-eth0
i="$DEVICE"
str_cfg_file="$dir/ifcfg-$i"
echo "BOOTPROTO=none" > $str_cfg_file
echo "STARTMODE=hotplug" >> $str_cfg_file
# write modprobe alias config
str_cfg_file="/etc/modprobe.d/$bond.conf"
echo "alias $bond bonding" > $str_cfg_file
# this was the original config of the eth0 nic (without bonding)
#echo "DEVICE=$i" > $str_cfg_file
#echo "BOOTPROTO=static" >> $str_cfg_file
#echo "STARTMODE=onboot" >> $str_cfg_file
#echo "IPADDR=$IPADDR" >> $str_cfg_file
#echo "NETMASK=$NETMASK" >> $str_cfg_file
#echo "NETWORK=$NETWORK" >> $str_cfg_file
#echo "BROADCAST=$BROADCAST" >> $str_cfg_file
#todo: add gateway config? Not sure, because the boot kernels gateway might not be the final OS gateway
else
# use dhcp for all nics
for i in $device_names;do
str_cfg_file="/etc/sysconfig/network/ifcfg-$i"
str_cfg_file="$dir/ifcfg-$i"
echo "DEVICE=$i" > $str_cfg_file
echo "BOOTPROTO=dhcp" >> $str_cfg_file
echo "STARTMODE=onboot" >> $str_cfg_file

View File

@ -0,0 +1,25 @@
#!/bin/bash
# SI post-install script, run after SI has installed the OS, to kill processes SI does not kill
# (so /a can be umounted cleanly)
# SI post-install scripts run in a chroot environment of the final OS image
if [ -f "/etc/SuSE-release" ];then
str_out=`ps -ef | grep -v grep | grep syslog-ng`
if [ $? -eq 0 ];then
str_id=`echo $str_out | awk '{print $2}'`
kill -9 $str_id
fi
fi
# SI starts klogd in the chroot, but does not kill it
killall klogd
# flush all write buffers, just in case SI can not umount /a
echo "Syncing file systems"
sync
#todo: remove
#echo "Processes still using /:"
#fuser -v /
#sleep 30

View File

@ -115,7 +115,11 @@ else
length=`expr $index2 - $index1`
length=`expr $length - 1`
cons_ip=`expr substr "$result" $pos $length`
ifconfig |grep "$cons_ip"
if [ "$os" == "AIX" ]; then
ifconfig |grep "$cons_ip"
else
ip addr |grep "$cons_ip"
fi
if [ $? -eq 0 ]; then
CONSERVER=""
fi

View File

@ -106,7 +106,7 @@ fi
%ifos linux
if [ -f "/proc/cmdline" ]; then # prevent running it during install into chroot image
if [ -f $RPM_INSTALL_PREFIX0/sbin/xcatd ]; then
/etc/init.d/xcatd reload
/etc/init.d/xcatd restart
fi
fi
%else

View File

@ -105,11 +105,6 @@ sub subvars {
}
my @managedaddressmode = xCAT::TableUtils->get_site_attribute("managedaddressmode");
my $tmp=$managedaddressmode[0];
if( defined($tmp) ){
$ENV{MANAGEDADDRESSMODE}=$tmp;
}
#replace the env with the right value so that correct include files can be found
$inc =~ s/#ENV:([^#]+)#/envvar($1)/eg;
@ -249,6 +244,7 @@ sub subvars {
$inc =~ s/#WINDISABLENULLADMIN#/windows_disable_null_admin()/eg;
$inc =~ s/#MANAGEDADDRESSMODE#/managed_address_mode()/eg;
$inc =~ s/#HOSTNAME#/$node/g;
$inc =~ s/#GETNODEDOMAIN:([^#]+)#/get_node_domain($1)/eg;
my $nrtab = xCAT::Table->new("noderes");
my $tftpserver = $nrtab->getNodeAttribs($node, ['tftpserver']);
@ -638,6 +634,22 @@ sub get_win_prodkey {
sub managed_address_mode {
return $::XCATSITEVALS{managedaddressmode};
}
sub get_node_domain {
my $lcnode=shift;
if ( $lcnode eq 'THISNODE' ){
$lcnode=$node;
}
my $nd = xCAT::NetworkUtils->getNodeDomains([$lcnode]);
my %nodedomains = %$nd;
my $domain=$nodedomains{$lcnode};
return $domain;
}
sub esxipv6setup {
if (not $::XCATSITEVALS{managedaddressmode} or $::XCATSITEVALS{managedaddressmode} =~ /v4/) { return ""; } # blank line for ipv4 schemes
my $v6addr;
@ -705,7 +717,7 @@ sub kickstartnetwork {
push @nameserversIP, $ip;
}
#there is no network option to set dns search domain in kickstart, it will be set in %post
if (scalar @nameserversIP) {
$line .=" --nameserver=". join(",",@nameserversIP);
}

View File

@ -1548,9 +1548,9 @@ sub mkinstall
foreach(@addfiles){
$kcmdline .= " --- $rtftppath/$_";
}
}elsif ($pkvm) {
$k = "$httpmethod://$instserver:$httpport$tftppath/vmlinuz";
$i = "$httpmethod://$instserver:$httpport$tftppath/initrd.img";
#}elsif ($pkvm) {
# $k = "$httpmethod://$instserver:$httpport$tftppath/vmlinuz";
# $i = "$httpmethod://$instserver:$httpport$tftppath/initrd.img";
}else{
$k = "$rtftppath/vmlinuz";
$i = "$rtftppath/initrd.img";

View File

@ -884,10 +884,15 @@ sub check_options
# if not help and not -n, dhcpd needs to be running
if (!($opt->{h})&& (!($opt->{n}))) {
if (xCAT::Utils->isLinux()) {
my @output = xCAT::Utils->runcmd("service dhcpd status", -1);
my $DHCPSERVER="dhcpd";
if( -e "/etc/init.d/isc-dhcp-server" ){
$DHCPSERVER="isc-dhcp-server";
}
my @output = xCAT::Utils->runcmd("service $DHCPSERVER status", -1);
if ($::RUNCMD_RC != 0) { # not running
my $rsp = {};
$rsp->{data}->[0] = "dhcpd is not running. Run service dhcpd start and rerun your command.";
$rsp->{data}->[0] = "$DHCPSERVER is not running. Run service $DHCPSERVER start and rerun your command.";
xCAT::MsgUtils->message("E", $rsp, $callback, 1);
return 1;
}

View File

@ -1901,7 +1901,7 @@ sub make_files {
}
if ( $hasplugin ) {
# Issue xcatd reload to load the new plugins
system("/etc/init.d/xcatd reload");
system("/etc/init.d/xcatd restart");
$hasplugin=0;
}

View File

@ -1411,7 +1411,7 @@ sub addkit
if ( $hasplugin ) {
# Issue xcatd reload to load the new plugins
system("/etc/init.d/xcatd reload");
system("/etc/init.d/xcatd restart");
}
}
}
@ -1716,7 +1716,7 @@ sub rmkit
if ( $hasplugin ) {
# Issue xcatd reload to load the new plugins
system("/etc/init.d/xcatd reload");
system("/etc/init.d/xcatd restart");
}
}

View File

@ -612,7 +612,25 @@ sub rflash {
# run the cmd on the host to flash the mic
my @args = ("-s", "-v", "-e");
push @args, "$::XCATROOT/sbin/flashmic";
my $master = $request->{'_xcatdest'};
# assume that all hosts are on the same network connected to this master
# (otherwise, will need to move this call into loop above for each host
# and build separate miccfg calls for each unique returned value from
# my_ip_facing)
my $ipfn = xCAT::NetworkUtils->my_ip_facing(@hosts[0]);
if ($ipfn) {
$master = $ipfn;
} else {
my $hostname = "";
my $hostnamecmd = "/bin/hostname";
my @thostname = xCAT::Utils->runcmd($hostnamecmd, 0);
if ($::RUNCMD_RC = 0) {
$hostname = "from server $thostname[0]";
}
xCAT::MsgUtils->message("E", {error=>["Cannot detect an active network interface $hostname to @hosts[0]."], errorcode=>["1"]}, $callback);
return;
}
}
push @args, ("-m", "$master");
push @args, ("-p", "$tftpdir/xcat/miccfg");
@ -912,7 +930,23 @@ sub nodeset {
# run the cmd on the host to configure the mic
my @args = ("-s", "-v", "-e");
push @args, "$::XCATROOT/sbin/configmic";
my $master = $request->{'_xcatdest'};
# assume that all hosts are on the same network connected to this master
# (otherwise, will need to move this call into loop above for each host
# and build separate miccfg calls for each unique returned value from
# my_ip_facing)
my $ipfn = xCAT::NetworkUtils->my_ip_facing(@hosts[0]);
if ($ipfn) {
$master = $ipfn;
} else {
my $hostname = "";
my $hostnamecmd = "/bin/hostname";
my @thostname = xCAT::Utils->runcmd($hostnamecmd, 0);
if ($::RUNCMD_RC = 0) {
$hostname = "from server $thostname[0]";
}
xCAT::MsgUtils->message("E", {error=>["Cannot detect an active network interface $hostname to @hosts[0]."], errorcode=>["1"]}, $callback);
return;
}
push @args, ("-m", "$master");
push @args, ("-p", "$tftpdir/xcat/miccfg");

View File

@ -10,6 +10,10 @@ my $globaltftpdir = xCAT::TableUtils->getTftpDir();
my %usage = (
"nodeset" => "Usage: nodeset <noderange> osimage[=<imagename>]",
);
my $httpmethod="http";
my $httpport = "80";
sub handled_commands {
return {
nodeset => "noderes:netboot"
@ -79,7 +83,21 @@ sub setstate {
my %nrhash = %{shift()};
my $linuximghash = shift();
my $kern = $bphash{$node}->[0]; #$bptab->getNodeAttribs($node,['kernel','initrd','kcmdline']);
if ($kern->{kcmdline} =~ /!myipfn!/) {
#my $nodereshash=$noderestab->getNodesAttribs(\@nodes,['tftpdir','xcatmaster','nfsserver', 'servicenode']);
if ($kern->{kernel} !~ /^$tftpdir/) {
my $nodereshash = $nrhash{$node}->[0];
my $installsrv;
if ($nodereshash and $nodereshash->{nfsserver} ) {
$installsrv = $nodereshash->{nfsserver};
} elsif ($nodereshash->{xcatmaster}) {
$installsrv = $nodereshash->{xcatmaster};
} else {
$installsrv = '!myipfn!';
}
$kern->{kernel} = "$httpmethod://$installsrv:$httpport$tftpdir/".$kern->{kernel};
$kern->{initrd} = "$httpmethod://$installsrv:$httpport$tftpdir/".$kern->{initrd};
}
if ($kern->{kcmdline} =~ /!myipfn!/ or $kern->{kernel} =~ /!myipfn!/) {
my $ipfn = xCAT::NetworkUtils->my_ip_facing($node);
unless ($ipfn) {
my $servicenodes = $nrhash{$node}->[0];
@ -118,6 +136,8 @@ sub setstate {
$kern->{kcmdline} =~ s/!myipfn!/$ipfn/g;
}
}
if ($kern->{addkcmdline}) {
$kern->{kcmdline} .= " ".$kern->{addkcmdline};
}
@ -303,6 +323,8 @@ sub process_request {
my $command = $request->{command}->[0];
%breaknetbootnodes=();
%normalnodes=();
if ($::XCATSITEVALS{"httpmethod"}) { $httpmethod = $::XCATSITEVALS{"httpmethod"}; }
if ($::XCATSITEVALS{"httpport"}) { $httpport = $::XCATSITEVALS{"httpport"}; }
my @args;
my @nodes;
@ -384,11 +406,9 @@ sub process_request {
my $chaintab=xCAT::Table->new('chain',-create=>1);
my $chainhash=$chaintab->getNodesAttribs(\@nodes,['currstate']);
my $noderestab=xCAT::Table->new('noderes',-create=>1);
my $nodereshash=$noderestab->getNodesAttribs(\@nodes,['tftpdir']);
my $nodereshash=$noderestab->getNodesAttribs(\@nodes,['tftpdir','xcatmaster','nfsserver', 'servicenode']);
my $mactab=xCAT::Table->new('mac',-create=>1);
my $machash=$mactab->getNodesAttribs(\@nodes,['mac']);
my $nrtab=xCAT::Table->new('noderes',-create=>1);
my $nrhash=$nrtab->getNodesAttribs(\@nodes,['servicenode']);
my $typetab=xCAT::Table->new('nodetype',-create=>1);
my $typehash=$typetab->getNodesAttribs(\@nodes,['os','provmethod','arch','profile']);
my $linuximgtab=xCAT::Table->new('linuximage',-create=>1);
@ -415,7 +435,7 @@ sub process_request {
my $linuximghash = $linuximghash = $linuximgtab->getAttribs({imagename => $osimgname}, 'boottarget', 'addkcmdline');
($rc,$errstr) = setstate($_,$bphash,$chainhash,$machash,$tftpdir,$nrhash,$linuximghash);
($rc,$errstr) = setstate($_,$bphash,$chainhash,$machash,$tftpdir,$nodereshash,$linuximghash);
if ($rc) {
$response{node}->[0]->{errorcode}->[0]= $rc;
$response{node}->[0]->{errorc}->[0]= $errstr;

View File

@ -1182,11 +1182,19 @@ sub mkinstall
}
if(scalar @nameserversIP){
$kcmdline .=" dns=".join(",",@nameserversIP);
$kcmdline .=" Nameserver=".join(",",@nameserversIP);
}
my $nd = xCAT::NetworkUtils->getNodeDomains([$node]);
my %nodedomains = %$nd;
my $domain=$nodedomains{$node};
$kcmdline .=" Domain=$domain ";
}
if (defined $sent->{serialport})
{

View File

@ -27,7 +27,8 @@ rootpw --iscrypted #CRYPT:passwd:key=system,username=root:password#
#partition / --ondisk=/dev/mapper/ibmpkvm_vg_root-ibmpkvm_lv_root
partition / --ondisk=/dev/sda
network --bootproto dhcp
#the --devicename must specify right now, but without network command, it can also work, so we delete it.
#network --bootproto dhcp
%post
touch "/startpost"

View File

@ -2,6 +2,7 @@
#cmdline
lang en_US
#KICKSTARTNET#
#
# Where's the source?

View File

@ -3,6 +3,7 @@
#cmdline
lang en_US
#KICKSTARTNET#
#
# Where's the source?

View File

@ -2,6 +2,8 @@
# Setup hostname
#
echo "post scripts" >/root/post.log
export PRINIC=#TABLEBLANKOKAY:noderes:THISNODE:primarynic#
if [ "$PRINIC" == "mac" ]
then

View File

@ -1,5 +1,5 @@
#!/bin/sh
export MANAGEDADDRESSMODE="#XCATVAR:MANAGEDADDRESSMODE#"
export MANAGEDADDRESSMODE=#MANAGEDADDRESSMODE#
cd /etc/sysconfig/network

View File

@ -14,6 +14,17 @@ if [ -r /tmp/updates/etc/pki/tls/certs/ca-bundle.crt ]; then
fi
#there is no boot option to set dns search domain in kickstart file,
#the search domain in /etc/resolv.conf is set in the pre installation script
export MANAGEDADDRESSMODE=#MANAGEDADDRESSMODE#
export SEARCHDOMAIN=#GETNODEDOMAIN:THISNODE#
if [ "$MANAGEDADDRESSMODE" == "static" ]; then
echo "#appended by %pre " >> /etc/resolv.conf
echo "search $SEARCHDOMAIN" >> /etc/resolv.conf
fi
cat >/tmp/baz.py <<EOF
#!/usr/bin/python

View File

@ -26,8 +26,6 @@ proc /proc proc rw 0 0
sysfs /sys sysfs rw 0 0
devpts /dev/pts devpts rw,gid=5,mode=620 0 0
${profile}_${arch} / tmpfs rw 0 1
none /tmp tmpfs defaults,size=10m 0 2
none /var/tmp tmpfs defaults,size=10m 0 2
END

View File

@ -0,0 +1,3 @@
#!/bin/sh
[ "$1" = "-d" ] && echo network
exit 0

View File

@ -0,0 +1,9 @@
#!/bin/sh
echo $drivers
dracut_install wget cpio gzip modprobe touch echo cut wc
dracut_install grep ifconfig hostname awk egrep grep dirname expr
dracut_install mount.nfs
dracut_install parted mke2fs bc mkswap swapon chmod
inst "$moddir/xcat-updateflag" "/tmp/updateflag"
inst "$moddir/xcatroot" "/sbin/xcatroot"
inst_hook cmdline 10 "$moddir/xcat-cmdline.sh"

View File

@ -0,0 +1,8 @@
#!/bin/sh
echo $drivers
dracut_install wget cpio gzip modprobe wc touch echo cut
dracut_install grep ifconfig hostname awk egrep grep dirname expr
dracut_install parted mke2fs bc mkswap swapon chmod
inst "$moddir/xcat-updateflag" "/tmp/updateflag"
inst_hook pre-mount 5 "$moddir/xcat-premount.sh"
inst_hook pre-pivot 5 "$moddir/xcat-prepivot.sh"

View File

@ -0,0 +1,2 @@
#!/bin/bash
instmods nfs sunrpc

View File

@ -0,0 +1,4 @@
root=1
rootok=1
netroot=xcat
echo '[ -e $NEWROOT/proc ]' > $hookdir/initqueue/finished/xcatroot.sh

View File

@ -0,0 +1,18 @@
#!/bin/sh
#script to update nodelist.nodestatus during provision
MASTER=`echo $XCAT |awk -F: '{print $1}'`
getarg nonodestatus
NODESTATUS=$?
XCATIPORT="$(getarg XCATIPORT=)"
if [ $? -ne 0 ]; then
XCATIPORT="3002"
fi
if [ $NODESTATUS -ne 0 ];then
/tmp/updateflag $MASTER $XCATIPORT "installstatus netbooting"
fi

View File

@ -0,0 +1,126 @@
#!/bin/sh
NEWROOT=/sysroot
SERVER=${SERVER%%/*}
SERVER=${SERVER%:}
RWDIR=.statelite
if [ ! -z $STATEMNT ]; then #btw, uri style might have left future options other than nfs open, will u se // to detect uri in the future I guess
SNAPSHOTSERVER=${STATEMNT%:*}
SNAPSHOTROOT=${STATEMNT#*/}
#echo $SNAPSHOTROOT
#echo $SNAPSHOTSERVER
# may be that there is not server and just a directory.
if [ -z $SNAPSHOTROOT ]; then
SNAPSHOTROOT=$SNAPSHOTSERVER
SNAPSHOTSERVER=
fi
fi
echo Setting up Statelite
mkdir -p $NEWROOT
# now we need to mount the rest of the system. This is the read/write portions
# echo Mounting snapshot directories
MAXTRIES=7
ITER=0
if [ ! -e "$NEWROOT/$RWDIR" ]; then
echo ""
echo "This NFS root directory doesn't have a /$RWDIR directory for me to mount a rw filesystem. You'd better create it... "
echo ""
/bin/sh
fi
if [ ! -e "$NEWROOT/etc/init.d/statelite" ]; then
echo ""
echo "$NEWROOT/etc/init.d/statelite doesn't exist. Perhaps you didn't create this image with th e -m statelite mode"
echo ""
/bin/sh
fi
mount -t tmpfs rw $NEWROOT/$RWDIR
mkdir -p $NEWROOT/$RWDIR/tmpfs
ME=`hostname`
if [ ! -z $NODE ]; then
ME=$NODE
fi
# mount the SNAPSHOT directory here for persistent use.
if [ ! -z $SNAPSHOTSERVER ]; then
mkdir -p $NEWROOT/$RWDIR/persistent
MAXTRIES=5
ITER=0
if [ -z $MNTOPTS ]; then
MNT_OPTIONS="nolock,rsize=32768,tcp,nfsvers=3,timeo=14"
else
MNT_OPTIONS=$MNTOPTS
fi
while ! mount $SNAPSHOTSERVER:/$SNAPSHOTROOT $NEWROOT/$RWDIR/persistent -o $MNT_OPTIONS; do
ITER=$(( ITER + 1 ))
if [ "$ITER" == "$MAXTRIES" ]; then
echo "Your are dead, rpower $ME boot to play again."
echo "Possible problems:
1. $SNAPSHOTSERVER is not exporting $SNAPSHOTROOT ?
2. Is DNS set up? Maybe that's why I can't mount $SNAPSHOTSERVER."
/bin/sh
exit
fi
RS= $(( $RANDOM % 20 ))
echo "Trying again in $RS seconds..."
sleep $RS
done
# create directory which is named after my node name
mkdir -p $NEWROOT/$RWDIR/persistent/$ME
ITER=0
# umount current persistent mount
while ! umount -l $NEWROOT/$RWDIR/persistent; do
ITER=$(( ITER + 1 ))
if [ "$ITER" == "$MAXTRIES" ]; then
echo "Your are dead, rpower $ME boot to play again."
echo "Cannot umount $NEWROOT/$RWDIR/persistent."
/bin/sh
exit
fi
RS= $(( $RANDOM % 20 ))
echo "Trying again in $RS seconds..."
sleep $RS
done
# mount persistent to server:/rootpath/nodename
ITER=0
while ! mount $SNAPSHOTSERVER:/$SNAPSHOTROOT/$ME $NEWROOT/$RWDIR/persistent -o $MNT_OPTIONS; do
ITER=$(( ITER + 1 ))
if [ "$ITER" == "$MAXTRIES" ]; then
echo "Your are dead, rpower $ME boot to play again."
echo "Possible problems: cannot mount to $SNAPSHOTSERVER:/$SNAPSHOTROOT/$ME."
/bin/sh
exit
fi
RS= $(( $RANDOM % 20 ))
echo "Trying again in $RS seconds..."
sleep $RS
done
fi
# TODO: handle the dhclient/resolv.conf/ntp, etc
echo "Get to enable localdisk"
$NEWROOT/etc/init.d/localdisk
$NEWROOT/etc/init.d/statelite
READONLY=yes
export READONLY
fastboot=yes
export fastboot
keep_old_ip=yes
export keep_old_ip
mount -n --bind /dev $NEWROOT/dev
mount -n --bind /proc $NEWROOT/proc
mount -n --bind /sys $NEWROOT/sys
if [ -d "$NEWROOT/etc/sysconfig" -a ! -e "$NEWROOT/etc/sysconfig/selinux" ]; then
echo "SELINUX=disabled" >> "$NEWROOT/etc/sysconfig/selinux"
fi
# inject new exit_if_exists
echo 'settle_exit_if_exists="--exit-if-exists=/dev/root"; rm "$job"' > $hookdir/initqueue/xcat.sh
# force udevsettle to break
> $hookdir/initqueue/work

View File

@ -0,0 +1,24 @@
#!/bin/awk -f
#script to feedback the node provision status to xcatd
BEGIN {
xcatdhost = ARGV[1]
xcatiport = ARGV[2]
ns = "/inet/tcp/0/" xcatdhost "/" xcatiport
print "xCAT_xcatd" |& ns
while(1) {
ns |& getline
if($0 == "ready")
print ARGV[3] |& ns
if($0 == "done")
break
}
close(ns)
exit 0
}

View File

@ -0,0 +1,278 @@
#!/bin/sh
NEWROOT=$3
RWDIR=.statelite
XCATMASTER=$XCAT
. /lib/dracut-lib.sh
rootlimit="$(getarg rootlimit=)"
getarg nonodestatus
NODESTATUS=$?
MASTER=`echo $XCATMASTER |awk -F: '{print $1}'`
XCATIPORT="$(getarg XCATIPORT=)"
if [ $? -ne 0 ]; then
XCATIPORT="3002"
fi
if [ $NODESTATUS -ne 0 ];then
/tmp/updateflag $MASTER $XCATIPORT "installstatus netbooting"
fi
if [ ! -z "$imgurl" ]; then
if [ xhttp = x${imgurl%%:*} ]; then
NFS=0
FILENAME=${imgurl##*/}
while [ ! -r "$FILENAME" ]; do
echo Getting $imgurl...
if ! wget $imgurl; then
rm -f $FILENAME
sleep 27
fi
done
elif [ xnfs = x${imgurl%%:*} ]; then
NFS=1
SERVER=${imgurl#nfs:}
SERVER=${SERVER#/}
SERVER=${SERVER#/}
ROOTDIR=$SERVER
SERVER=${SERVER%%/*}
SERVER=${SERVER%:}
ROOTDIR=/${ROOTDIR#*/}
fi
fi
#echo 0 > /proc/sys/vm/zone_reclaim_mode #Avoid kernel bug
if [ -r /rootimg.sfs ]; then
echo Setting up squashfs with ram overlay.
mknod /dev/loop0 b 7 0
mkdir -p /ro
mkdir -p /rw
mount -t squashfs /rootimg.sfs /ro
mount -t tmpfs rw /rw
mount -t aufs -o dirs=/rw:/ro mergedroot $NEWROOT
mkdir -p $NEWROOT/ro
mkdir -p $NEWROOT/rw
mount --move /ro $NEWROOT/ro
mount --move /rw $NEWROOT/rw
elif [ -r /rootimg.gz ]; then
echo Setting up RAM-root tmpfs.
if [ -z $rootlimit ];then
mount -t tmpfs -o mode=755 rootfs $NEWROOT
else
mount -t tmpfs -o mode=755,size=$rootlimit rootfs $NEWROOT
fi
cd $NEWROOT
echo -n "Extracting root filesystem:"
if [ -x /bin/cpio ]; then
gzip -cd /rootimg.gz |/bin/cpio -idum
else
gzip -cd /rootimg.gz |cpio -idum
fi
$NEWROOT/etc/init.d/localdisk
echo Done
elif [ -r /rootimg-statelite.gz ]; then
echo Setting up RAM-root tmpfs for statelite mode.
if [ -z $rootlimit];then
mount -t tmpfs -o mode=755 rootfs $NEWROOT
else
mount -t tmpfs -o mode=755,size=$rootlimit rootfs $NEWROOT
fi
cd $NEWROOT
echo -n "Extracting root filesystem:"
if [ -x /bin/cpio ]; then
gzip -cd /rootimg-statelite.gz |/bin/cpio -idum
else
gzip -cd /rootimg-statelite.gz |cpio -idum
fi
echo Done
# then, the statelite staffs will be processed
echo Setting up Statelite
modprobe nfs
MAXTRIES=7
ITER=0
if [ ! -e "$NEWROOT/$RWDIR" ]; then
echo ""
echo "The /$RWDIR directory doesn't exist in the rootimg... "
echo ""
/bin/sh
fi
if [ ! -e "$NEWROOT/etc/init.d/statelite" ]; then
echo ""
echo "$NEWROOT/etc/init.d/statelite doesn't exist... "
echo ""
/bin/sh
fi
mount -t tmpfs rw $NEWROOT/$RWDIR
mkdir -p $NEWROOT/$RWDIR/tmpfs
ME=`hostname`
if [ ! -z $NODE ]; then
ME=$NODE
fi
# mount the SNAPSHOT directory here for persistent use.
if [ ! -z $STATEMNT ]; then
SNAPSHOTSERVER=${STATEMNT%:*}
SNAPSHOTROOT=${STATEMNT#*/}
if [ -z $SNAPSHOTROOT ]; then
SNAPSHOTROOT=$SNAPSHOTSERVER
SNAPSHOTSERVER=
fi
fi
if [ ! -z $SNAPSHOTSERVER ]; then
mkdir -p $NEWROOT/$RWDIR/persistent
MAXTRIES=5
ITER=0
if [ -z $MNTOPTS ]; then
MNT_OPTIONS="nolock,rsize=32768,tcp,nfsvers=3,timeo=14"
else
MNT_OPTIONS=$MNTOPTS
fi
while ! mount $SNAPSHOTSERVER:/$SNAPSHOTROOT $NEWROOT/$RWDIR/persistent -o $MNT_OPTIONS; do
ITER=$(( ITER + 1 ))
if [ "$ITER" == "$MAXTRIES" ]; then
echo "You are dead, rpower $ME boot to play again."
echo "Possible problems:
1. $SNAPSHOTSERVER is not exporting $SNAPSHOTROOT ?
2. Is DNS set up? Maybe that's why I can't mount $SNAPSHOTSERVER."
/bin/sh
exit
fi
RS=$(( $RANDOM % 20 ))
echo "Trying again in $RS seconds ..."
sleep $RS
done
# create directory which is named after my node name
mkdir -p $NEWROOT/$RWDIR/persistent/$ME
ITER=0
# umount current persistent mount
while ! umount -l $NEWROOT/$RWDIR/persistent; do
ITER=$(( ITER + 1 ))
if [ "$ITER" == "$MAXTRIES" ]; then
echo "Your are dead, rpower $ME boot to play again."
echo "Cannot umount $NEWROOT/$RWDIR/persistent."
/bin/sh
exit
fi
RS= $(( $RANDOM % 20 ))
echo "Trying again in $RS seconds..."
sleep $RS
done
# mount persistent to server:/rootpath/nodename
ITER=0
while ! mount $SNAPSHOTSERVER:/$SNAPSHOTROOT/$ME $NEWROOT/$RWDIR/persistent -o $MNT_OPTIONS; do
ITER=$(( ITER + 1 ))
if [ "$ITER" == "$MAXTRIES" ]; then
echo "Your are dead, rpower $ME boot to play again."
echo "Possible problems: cannot mount to $SNAPSHOTSERVER:/$SNAPSHOTROOT/$ME."
/bin/sh
exit
fi
RS= $(( $RANDOM % 20 ))
echo "Trying again in $RS seconds..."
sleep $RS
done
fi
$NEWROOT/etc/init.d/localdisk
$NEWROOT/etc/init.d/statelite
fastboot=yes
export fastboot
keep_old_ip=yes
export keep_old_ip
mount -n --bind /dev $NEWROOT/dev
mount -n --bind /proc $NEWROOT/proc
mount -n --bind /sys $NEWROOT/sys
else
echo -n Failed to download image, panicing in 5...
for i in 4 3 2 1 0; do
/bin/sleep 1
echo -n $i...
done
echo
echo "You're dead. rpower nodename reset to play again.
* Did you packimage with -m cpio, -m squashfs, or -m nfs?
* If using -m squashfs did you include aufs.ko with geninitrd?
e.g.: -n tg3,squashfs,aufs,loop
* If using -m nfs did you export NFS and sync rootimg? And
did you include the aufs and nfs modules in the proper order:
e.g.: -n tg3,aufs,loop,sunrpc,lockd,nfs_acl,nfs
"
/bin/dash
exit
fi
cd /
function getdevfrommac() {
boothwaddr=$1
ip link show | while read line
do
dev=`echo $line | egrep "^[0-9]+: [0-9A-Za-z]+" | cut -d ' ' -f 2 | cut -d ':' -f 1`
if [ "X$dev" != "X" ]; then
devname=$dev
fi
if [ "X$devname" != "X" ]; then
hwaddr=`echo $line | egrep "^[ ]*link" | awk '{print $2}'`
if [ "X$hwaddr" = "X$boothwaddr" ]; then
echo $devname
fi
fi
done
}
if [ -z $STATEMNT ]; then
for lf in /tmp/dhclient.*.lease; do
netif=${lf#*.}
netif=${netif%.*}
cp $lf "$NEWROOT/var/lib/dhclient/dhclient-$netif.leases"
done
if [ ! -z "$ifname" ]; then
MACX=${ifname#*:}
ETHX=${ifname%:$MACX*}
elif [ ! -z "$netdev" ]; then
ETHX=$netdev
MACX=`ip link show $netdev | grep ether | awk '{print $2}'`
elif [ ! -z "$BOOTIF" ]; then
MACX=$BOOTIF
ETHX=$(getdevfrommac $BOOTIF)
fi
if [ ! -z "$MACX" ] && [ ! -z "$ETHX" ]; then
if [ ! -e $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX ]; then
touch $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
fi
echo "DEVICE=$ETHX" > $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
echo "BOOTPROTO=dhcp" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
echo "HWADDR=$MACX" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
echo "ONBOOT=yes" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
fi
fi
cp /etc/resolv.conf "$NEWROOT/etc/"
if [ -d "$NEWROOT/etc/sysconfig" -a ! -e "$NEWROOT/etc/sysconfig/selinux" ]; then
echo "SELINUX=disabled" >> "$NEWROOT/etc/sysconfig/selinux"
fi
# inject new exit_if_exists
echo 'settle_exit_if_exists="--exit-if-exists=/dev/root"; rm "$job"' > $hookdir/initqueue/xcat.sh
# force udevsettle to break
> $hookdir/initqueue/work

View File

@ -583,8 +583,8 @@ if ( (-d "$rootimg_dir/usr/share/dracut") or (-d "$rootimg_dir/usr/lib/dracut")
my $dracutver = `rpm --root $rootimg_dir -qi dracut | grep Version | awk -F' ' '{print \$3}'`;
chomp($dracutver);
if ($dracutver =~ /^\d\d\d$/) {
if (($dracutver >= "009") and ($dracutver < "033")) {
$dracutdir = "dracut_009";
if ($dracutver >= "033") {
$dracutdir = "dracut_033";
} else {
$dracutdir = "dracut"; # The default directory
}
@ -779,8 +779,8 @@ system("chroot $rootimg_dir depmod $kernelver");
# the other one is for statelite
if ($dracutmode) {
mkinitrd_dracut("statelite");
mkinitrd_dracut("stateless");
mkinitrd_dracut("statelite");
} else {
mkinitrd("statelite");
mkinitrd("stateless");
@ -924,7 +924,11 @@ sub mkinitrd_dracut {
$additional_options= qq{--include /tmp/cmdline /etc/cmdline};
}
system("chroot $rootimg_dir dracut $additional_options -f /tmp/initrd.$$.gz $kernelver");
# force the dracut run in non-hostonly mode for dracut higher than version 033
if ($dracutver > "033") {
$additional_options .= " -N";
}
system("chroot $rootimg_dir dracut -N $additional_options -f /tmp/initrd.$$.gz $kernelver");
print "the initial ramdisk for $mode is generated successfully.\n";
move("$rootimg_dir/tmp/initrd.$$.gz", "$destdir/initrd-$mode.gz");
}
@ -1665,7 +1669,11 @@ sub using_systemd {
my $os = shift;
if ($os =~ /fedora(\d+)/) {
if ($1 >= 15) {
return 1;
return 1;
}
}elsif ($os =~ /rhels(\d+)/) {
if ($1 >= 7) {
return 1;
}
}

507
xCAT-test/restapitest Executable file
View File

@ -0,0 +1,507 @@
#!/usr/bin/env perl
###############################################################################
# This script is used for rest-api automation test
# Flags are used for test input:
# -m method. Should be GET, POST, PUT, DELETE
# -r resource
# -t token
# -h host
# -u user
# -p passwd
# -P port (BC)
# -d data
# -c cert
# -n hostname
# Flags are used for check output:
# -o expected output
# -O logical operator
#
# Expected result format is '{ANY:{ANY:content}}'
# These steps are used to explain how to scan result
# step 1. go through to see if content can be found
# step 2. compare content if found
# options are used as followed:
# == returns 0 if found and equal, returns 1 if not found or found but not equal
# != returns 0 if found, returns 1 if not found
# =~ returns 0 if match, returns 1 if not match
# !=~ returns 0 if not match, returns 1 if match
################################################################################
BEGIN
{
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
}
use Getopt::Long qw{:config bundling no_ignore_case};
use Data::Dumper;
use strict;
my $help;
my $method;
my $token;
my $resource;
my $host;
my $user;
my $passwd;
my $port;
my $data;
my $cert;
my $hostname;
my $output;
my $loperator;
my $debug;
my $defaulthash;
my $defaulthttpresult = 0;
my $outputfile = "/tmp/testrestapiresult";
if (
!GetOptions("h|?" => \$help,
"m=s" => \$method,
"t=s" => \$token,
"r=s" => \$resource,
"h=s" => \$host,
"u=s" => \$user,
"p=s" => \$passwd,
"P=s" => \$port,
"d=s" => \$data,
"c=s" => \$cert,
"n=s" => \$hostname,
"o=s" => \$output,
"O=s" => \$loperator,
"debug" => \$debug,
)
) {
&usage;
exit 1;
}
##############################################################
# check result
##############################################################
if ($output) {
if ($method or $resource) {
&usage;
exit 1;
}
my $res = check_result($output,$loperator,$outputfile);
print_debug( "check result runs with $output and $loperator, result is $res\n" );
exit $res;
}
##############################################################
# return help
##############################################################
if ($help) {
&usage;
exit 0;
}
##############################################################
# Give default values for optional vars.
###############################################################
my $rootdir = "$::XCATROOT/share/xcat/tools/autotest";
my $resultdir = "$rootdir/result";
my $logfile = "$rootdir/result/restapitest.log"; #/opt/xcat/share/xcat/tools/autotest/result/restapitest.log
my $cert1 = "/root/ca-cert.pem";
# get token
my $gettoken = `curl -X POST -k 'https://127.0.0.1/xcatws/tokens?userName=root&password=cluster' -H Content-Type:application/json --data '{"userName":"root","password":"cluster"}' 2>/dev/null`;
my $reshash = parse_json($gettoken);
my $token1 = $$reshash{token}{id};
# get hostname
unless ($hostname) {
$hostname = `hostname`;
chomp($hostname);
}
# keey default test result for save
my $res = run_restapi($method, $resource, $data, "", $port, "127.0.0.1", "root", "cluster");
$defaulthash = parse_json($res);
$defaulthttpresult = check_errcode();
# debug info
print_debug( "get token $token1. \n" );
print_debug( "get hostname $hostname.\n");
print_debug( "default result is $res. \n" );
print_debug( "default resulthash is: \n" );
print_debug($defaulthash);
print_debug( "default errcode is $defaulthttpresult \n" );
####################################################
# Begin to run test cases
####################################################
my @users = ("root","wsuser", $user);
my @passwds = ("cluster","cluster", $passwd);
my @tokens = ("", $token1, $token);
my @certs = ("", $cert1, $cert);
unless ($host) {
$host = "127.0.0.1";
}
log_me("**************begin restapi test***************");
my $i = 0;
for my $u (@users) {
next unless($u);
my $p = $passwds[$i];
$i++;
for my $t (@tokens) {
for my $c (@certs){
my $res = run_restapi($method, $resource, $data, $c, $port, $host, $u, $p, $t);
if($res){
my $reshash = parse_json($res);
print_debug("parse curl result and got:\n");
print_debug($reshash);
if (%$reshash != %$defaulthash) {
log_me("restapi test cases run different result");
print_debug( "restapi test cases run different result with $method, $resource, $data, $c, $port, $host, $u, $p, $t\n" );
exit 1;
}
}
my $errcode = check_errcode();
print_debug("get curl error code: $errcode\n");
if ($errcode != $defaulthttpresult) {
log_me("restapi test cases run different errcode");
print_debug( "restapi test cases run different error code with $method, $resource, $data, $c, $port, $host, $u, $p, $t\n" );
exit 1;
}
}
}
}
exit $defaulthttpresult;
################################################
# begin subroutine
################################################
##########
# usage #
##########
sub usage
{
print "Usage:testrestapi - Run xcat test cases.\n";
print " testrestapi [-?|-h]\n";
print " testrestapi [-m method] [-r resource] [-t tocken]\n";
print " [-h host] [-P port][-u user] [-p passwd]\n";
print " [-d data] [-c cert] [-n hostname]\n";
print " [-o expect_output] [-O logical_operator] \n";
print " [--debug]\n";
print "\n";
return;
}
###############
# record log #
###############
sub log_me
{
my $msg = shift;
open (LOG, ">>$logfile")
or return 1;
my $date = `date`;
print LOG "$date\: $msg\n";
}
#####################
# print debug infor #
#####################
sub print_debug
{
my $msg = shift;
return 0 unless($debug);
if(ref($msg) eq 'HASH') {
print Dumper($msg);
} elsif( ref($msg) eq 'ARRAY') {
print Dumper($msg);
} else {
print "$msg";
}
}
#########################
# run rest-api command #
#########################
sub run_restapi
{
my ($m,$r,$d,$c,$p,$h,$u,$a,$t) = @_;
my $cmd = "curl";
$cmd .= " -X $m";
unless ($c) {
$cmd .= " -k ";
}else {
$cmd .= " --cacert $c";
}
if($t){
$cmd .= " -H X-Auth-Token:$t ";
}
if($t or $c){
$cmd .= " 'https://$hostname";
} else {
$cmd .= " 'https://$h";
}
if ($p) {
$cmd .= ":$p";
}
$cmd .= "/xcatws";
$cmd .= "$r?";
unless($t){
$cmd .= "userName=$u&password=$a'";
}else {
$cmd .= "'";
}
if($d) {
$cmd .= " -H Content-Type:application/json --data '$d'";
}
$cmd .= " -D /tmp/err.log";
log_me("Begin to run restapi test with $cmd");
my $res = `$cmd 2>/dev/null`;
print_debug("run curl: $cmd\n");
print_debug("result is $res\n");
if (!open (RESULT, ">$outputfile")) {
log_me("wirte outputfile error");
}
print RESULT $res;
close RESULT;
return $res;
}
############################
# transfer json into hash #
############################
sub parse_json
{
my $input = shift;
my %hash;
if ($input =~ /:/) {
# for those who look like:
# {"networks":[{"mgtifname":"eth1","mask":"255.255.255.0"},{"mgtifname":"eth1","mask":"255.255.255.0"}]}
if ($input =~ /^\[(.*)\]$/s) {
my $content = $1;
print "[:] content is $content \n" if($debug);
parse_json($content);
}
# for those who look like
# {"clustersite":{"domain":"cluster.com","master":"192.168.1.15"}}
elsif ($input =~ /^\s*{(.*)}\s*$/s) {
my $content = $1;
print "{} content is $content \n" if($debug);
parse_json($content);
}
# for those who look like
# "domain":"cluster.com","master":"192.168.1.15"
elsif ($input =~ /,/ and !($input =~ /}/)) {
my @contents = split /,/, $input;
my @reval;
# record result
foreach my $t (@contents) {
print ", content is $t \n" if($debug);
my $re = parse_json($t);
push @reval, $re;
}
# merge hash
foreach my $t (@reval) {
if(ref($t) =~ "HASH") {
foreach my $k (keys %$t){
$hash{$k} = $$t{$k};
}
}
}
return \%hash;
}
# for those who look like:
# "clustersite":{"domain":"cluster.com","master":"192.168.1.15"}
# "domain":"cluster.com"
elsif ($input =~ /\"(\S+?)\":(.+)/s) {
my $key = $1;
my $value = $2;
if ($value =~ /{/) {
# "clustersite":{"domain":"cluster.com","master":"192.168.1.15"}
print "{ content is $value \n" if($debug);
$hash{$key} = parse_json($value, $key);
return \%hash;
} else {
# "domain":"cluster.com"
$value =~ /\"(\S+)\"/;
$hash{$key} = $1;
return \%hash;
}
}
}
# for those who look like
# ["10.1.255.250","192.168.200.16","192.168.200.19","192.168.200.22"]
else {
if ($input =~ /^\[(.*)\]/s) {
my $content = $1;
print "[] content is $content \n" if($debug);
my @all = split /,/, $content;
foreach my $n (@all) {
$n =~ /\"(.*)\"/;
$hash{$1} = "restapiarray";
}
return \%hash;
}
}
}
############################
# check curl running code #
############################
sub check_errcode
{
if(!open (ERRLOG, "</tmp/err.log")) {
log_me("can't open err.log in tmp");
return 1;
}
my $num;
while (<ERRLOG>){
if (/HTTP\/\w*\.*\w* (\w+) (\w+)/) {
$num = $1;
last;
}
}
close ERRLOG;
print_debug("can't get errorcode\n") unless($num);
return $num;
}
############################
# check curl return result #
############################
sub check_result
{
my $data = shift;
my $opterator = shift;
my $output = shift;
if ( !open (OUTPUT, "<$output")) {
log_me("can't read output file");
return 1;
}
my $res;
while (<OUTPUT>) {
$res .= $_;
}
close OUTPUT;
my $expects = transf_hash(parse_json($data)); # one entry
my $actuals = transf_hash(parse_json($res)); # serval entries
print_debug("expected result is:\n");
print_debug($expects);
print_debug("testcase run result is \n");
print_debug($actuals);
my $flag = 0;
my %flaghash;
my $expect = $$expects[0]; # $expect = ANY:ANY:x86_64
my @expectvalue = split /:/, $expect; #@expectvalue = ANY, ANY, x86_64
$flag = 0;
foreach my $expval (@expectvalue) { # $expval = ANY
foreach my $actual (@$actuals) { # $actual = nodetype:arch:x86_64
if($flaghash{$actual} eq "none"){
next;
}
my @actualvalue = split /:/, $actual; # @actualvalue = nodetype, arch, x86_64
print_debug("begin to compare $expval and $actualvalue[$flag]");
if(($expval eq "restapiarray" ) and ($actualvalue[$flag] eq "restapiarray")){
next;
}
if(($expval eq $actualvalue[$flag]) or ($expval eq "ANY")) { #ANY =~ nodetype
$flaghash{$actual} = "eq";
} elsif (($actualvalue[$flag] =~ $expval) or ($expval eq "ANY")) {
$flaghash{$actual} = "match";
} else {
$flaghash{$actual} = "none";
}
print_debug(", compare result is $flaghash{$actual}\n");
}
$flag++;
}
print_debug("search result is \n");
print_debug(\%flaghash);
if ($opterator eq "!="){
foreach my $val (keys %flaghash) {
if ($flaghash{$val} eq "eq") {
print_debug("compare result: failed\n");
return 1; # fail
}
}
print_debug("compare result: succeed\n");
return 0; #succeed
}
if ($opterator eq "=="){
foreach my $val (keys %flaghash) {
if ($flaghash{$val} eq "eq") {
print_debug("compare result: succeed\n");
return 0; # succeed
}
}
print_debug("compare result: failed\n");
return 1; #fail
}
if ($opterator eq "=~"){
foreach my $val (keys %flaghash) {
if ($flaghash{$val} eq "match") {
print_debug("compare result: succeed\n");
return 0; # succeed
}
}
print_debug("compare result: failed\n");
return 1; #fail
}
if ($opterator eq "!=~"){
foreach my $val (keys %flaghash) {
if ($flaghash{$val} eq "match") {
print_debug("compare result: failed\n");
return 1; # fail
}
}
print_debug("compare result: succeed\n");
return 0; #succeed
}
}
####################################
# help to transfer hash into array #
####################################
sub find_key
{
my $input = shift;
my $en = shift;
my $ou = shift;
if( ref($input) =~ "HASH") {
foreach my $val (keys %$input) {
my $tmp = $$en; # keey head
$$en .= "$val:";
my $t1 = find_key($$input{$val}, $en, $ou);
if ($$en == ""){
$$en = $tmp; #restore head
}
}
} else {
$$en .= $input;
push @$ou, $$en;
$$en = ""; # clear entry;
}
}
############################
# transfer hash into array #
############################
sub transf_hash
{
my $input = shift;
my $entry;
my @array;
find_key($input, \$entry, \@array);
return \@array;
}

View File

@ -39,6 +39,7 @@ pod2html pods/man1/xcattest.1.pod > share/doc/man1/xcattest.1.html
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/%{prefix}/bin
mkdir -p $RPM_BUILD_ROOT/%{prefix}/sbin
mkdir -p $RPM_BUILD_ROOT/%{prefix}/share/xcat/tools/autotest
mkdir -p $RPM_BUILD_ROOT/%{prefix}/share/man/man1
mkdir -p $RPM_BUILD_ROOT/%{prefix}/share/doc/man1
@ -46,6 +47,9 @@ mkdir -p $RPM_BUILD_ROOT/%{prefix}/share/doc/man1
cp xcattest $RPM_BUILD_ROOT/%{prefix}/bin
chmod 755 $RPM_BUILD_ROOT/%{prefix}/bin/*
cp restapitest $RPM_BUILD_ROOT/%{prefix}/sbin
chmod 755 $RPM_BUILD_ROOT/%{prefix}/sbin/*
# These were built dynamically in the build phase
cp share/man/man1/* $RPM_BUILD_ROOT/%{prefix}/share/man/man1
chmod 444 $RPM_BUILD_ROOT/%{prefix}/share/man/man1/*

View File

@ -25,10 +25,10 @@ my $string1 = undef;
if (
!GetOptions("h|?" => \$needhelp,
"f=s" => \$configfile,
"b=s" => \$bundle_list,
"t=s" => \$case_list,
"c=s" => \$cmd_list,
"l" => \$needshow,
"b=s" => \$bundle_list,
"t=s" => \$case_list,
"c=s" => \$cmd_list,
"l" => \$needshow,
"restore"=>\$restore)
)
{
@ -221,7 +221,7 @@ sub getConfig
}
}
}
if(exists $config{object}){
foreach my $type (keys %{$config{object}}){
foreach my $name (keys %{$config{object}{$type}}){
@ -344,7 +344,7 @@ sub init
log_this("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/){
if($config{var}{ARCH} =~ /ppc/){
$config{var}{ARCH} = 'ppc';
}elsif($config{var}{ARCH}=~/86/){
$config{var}{ARCH} = 'x86';
@ -432,7 +432,7 @@ sub loadcase
my $j = -1;
my $z = 0;
my $skip = 0;
my @caserange = ();
my @rightcase = ();
my @notrightcase = ();
@ -452,7 +452,7 @@ sub loadcase
}
}
if($case_list){
@caserange = split /,/, $case_list;
@caserange = split /,/, $case_list;
}
foreach $file (@files){
if(!open(FILE, "<$file")){
@ -498,13 +498,13 @@ sub loadcase
$cases[$i]->{os}=$string1;
}
if($cases[$i]->{os} !~ /$config{var}{OS}/){
push(@notrightcase, $cases[$i]->{name});
pop(@rightcase);
$skip = 1;
}
}elsif($line =~ /^arch\s*:\s*(\w[\w\,]+)/){
next if $skip;
$cases[$i]->{arch}=$1;
@ -631,7 +631,7 @@ sub getfunc
$func = $1;
$parameter = $2;
@para = split /\s*,\s*/, trim($parameter);
if($func eq "GETNODEATTR"){
if($func eq "GETNODEATTR"){
$value= getnodeattr(@para);
if($value eq "Unknown"){
$value = '';
@ -669,9 +669,9 @@ sub runcase
my $time1=gmtime $now1;
log_this("------START:$$case{name}::Time:$time1------");
push @record, "------START:$$case{name}::Time:$time1------";
push @record, "FILENAME:$$case{filename}";
push @record, "FILENAME:$$case{filename}";
foreach my $cmd (@{$$case{cmd}}){
$cmd = getfunc($cmd);
$cmd = getfunc($cmd);
#by
my $runstart=timelocal(localtime());
@ -684,10 +684,10 @@ sub runcase
my $diffduration=$runstop-$runstart;
log_this("\n[$cmd] Running Time:$diffduration sec");
push(@record,("\n[$cmd] Running Time:$diffduration sec"));
log_this("RETURN: rc = $rc","OUTPUT:",@output);
push(@record,("RETURN rc = $rc","OUTPUT:",@output));
foreach my $check (@{$$case{check}->[$j]}){
if($failed){
@ -766,7 +766,17 @@ sub runcase
}
}
foreach my $cmdcheck (@{$$case{cmdcheck}->[$j]}){
&runcmd($cmdcheck);
if($cmdcheck) {
&runcmd($cmdcheck);
$rc = $::RUNCMD_RC;
if($rc == 1) {
log_this("CMDCHECK:output $cmdcheck\t[Failed]");
push(@record, "CHECK:output $cmdcheck\t[Failed]");
} elsif ($rc == 0) {
log_this("CMDCHECK:output $cmdcheck\t[Pass]");
push(@record, "CHECK:output $cmdcheck\t[Pass]");
}
}
}
$j = $j + 1;
}
@ -798,6 +808,7 @@ sub runcmd
if ($?)
{
$rc = $? ;
$rc = $rc >> 8;
$::RUNCMD_RC = $rc;
}
chomp(@$outref);
@ -835,3 +846,5 @@ sub getreport
close(FD);
close(STDOUT);
}

View File

@ -5,4 +5,5 @@ install/prescripts
install/kdump
opt/xcat/share/xcat
etc/apache2/conf.d
etc/apache2/conf-enabled
opt/xcat/share/doc/packages/xCAT

View File

@ -1,5 +1,5 @@
xcat.conf etc/apache2/conf.d/
xcat.conf.apach24 etc/apache2/conf.d/
xcat.conf.apach24 etc/apache2/conf-enabled
LICENSE.html opt/xcat/share/doc/packages/xCAT
postscripts/* install/postscripts/
prescripts/* install/prescripts/

View File

@ -40,12 +40,9 @@ case "$1" in
else
xcatconfig -i -d -s
fi
ver=$(cat /etc/issue |awk '{print $2}')
num=${ver%.*}
file="xcat.conf.apach24"
if [ $num -gt 12 ];then
mv /etc/apache2/conf.d/xcat.conf.apach24 /etc/apache2/conf-enabled/
fi
# [ -e /etc/apache2/conf-enabled/xcat.conf ] && rm /etc/apache2/conf-enabled/xcat.conf
# mv /etc/apache2/conf-enabled/xcat.conf.apach24 /etc/apache2/conf-enabled/xcat.conf
/etc/init.d/apache2 restart
;;

View File

@ -335,7 +335,8 @@ elif [ "$1" = "-s" ];then
if [ -n "$MACADDRESS" ];then
str_inst_mac=$MACADDRESS
else
str_inst_mac=`ifconfig $str_inst_nic | grep HWaddr | awk -F'HWaddr' '{print $2}' | sed 's/\s*//'`
#str_inst_mac=`ifconfig $str_inst_nic | grep HWaddr | awk -F'HWaddr' '{print $2}' | sed 's/\s*//'`
str_inst_mac=`ip link show $netdev | grep ether | awk '{print $2}'`
fi
if [ -z "$str_inst_ip" -o -z "$str_inst_mask" ];then

View File

@ -1,4 +1,4 @@
#!/bin/sh
PREFIXMASK#!/bin/sh
# pmatch determines if 1st argument string is matched by 2nd argument pattern
pmatch ()
@ -9,6 +9,18 @@ pmatch ()
return 1 # non-zero return code means string not matched by pattern
}
# converts netmask CIDR fromat to x.x.x.x mask value
maskfromprefix ()
{
prefixlen=$1
maskval=$((0xffffffff>>(32-prefixlen)<<(32-prefixlen)))
mask1=$((maskval >> 24))
mask2=$((maskval >> 16 & 0xff))
mask3=$((maskval >> 8 & 0xff))
mask4=$((maskval & 0xff))
echo $mask1.$mask2.$mask3.$mask4
NETMASK=$mask1.$mask2.$mask3.$mask4
}
network_ipv4calc ()
{
@ -56,9 +68,12 @@ else
echo "GATEWAY=$defgw" >> /etc/sysconfig/network
fi
fi
for nic in `ifconfig -a|grep -B1 "inet addr"|awk '{print $1}'|grep -v inet|grep -v -- --|grep -v lo`; do
IPADDR=`ifconfig $nic |grep "inet addr"|awk '{print $2}' |awk -F: '{print $2}'`
NETMASK=`ifconfig $nic |grep "inet addr"|awk '{print $4}' |awk -F: '{print $2}'`
for nic in `ip link |grep "BROADCAST" |awk '{print $2}' | sed s/://`; do
IPADDRMASK=`ip addr show dev $nic | grep inet | grep -v inet6 | awk '{print $2}' | head -n 1`
IPADDR=`echo $IPADDRMASK | awk -F'/' '{print $1}'`
PREFIXMASK=`echo $IPADDRMASK | awk -F'/' '{print $2}'`
# converts to x.x.x.x mask value
maskfromprefix $PREFIXMASK
if ( pmatch $OSVER "ubuntu*" )
then
NETWORK=`network_ipv4calc $IPADDR $NETMASK`
@ -69,7 +84,7 @@ for nic in `ifconfig -a|grep -B1 "inet addr"|awk '{print $1}'|grep -v inet|grep
else
gateway_line=""
fi
# add info to interfaces file on ubuntu, TBD does unbuntu change to systemd, this will not exist
cat >>/etc/network/interfaces <<EOF
auto $nic
iface $nic inet static
@ -81,12 +96,14 @@ iface $nic inet static
EOF
# not ubuntu
else
if [ -f ${NICFILEPRE}${nic} ]
then
NICFILE=${NICFILEPRE}${nic}
else
mac=`ifconfig $nic|grep HWaddr|awk '{print $5}'|tr "[A-Z]" "[a-z]"`
#mac=`ifconfig $nic|grep HWaddr|awk '{print $5}'|tr "[A-Z]" "[a-z]"`
mac=`ip link show $nic | grep ether | awk '{print $2}'`
NICFILE=${NICFILEPRE}eth-id-${mac}
fi
sed -i s/BOOTPROTO=dhcp/BOOTPROTO=static/ $NICFILE

View File

@ -47,7 +47,8 @@ then
echo "KeyRegenerationInterval 0" >>/etc/ssh/sshd_config
sed -i '/MaxStartups /'d /etc/ssh/sshd_config
echo "MaxStartups 1024" >>/etc/ssh/sshd_config
sed -i 's/^\s*\(PermitRootLogin\s*\).*/\1yes/' /etc/ssh/sshd_config
if [ "$SETUPFORPCM" = "1" ];then
sed -i '/PasswordAuthentication /'d /etc/ssh/sshd_config
echo "PasswordAuthentication yes" >>/etc/ssh/sshd_config

0
xCAT/postscripts/setupesx Normal file → Executable file
View File

View File

@ -10,7 +10,7 @@
# Change these two parameters according to your requirements
$::NFSRETRIES = 3;
$::NFSTIMEO = 10;
$::NFSTIMEO = 50;
# Candidate commands: mount, df, lsfs, nfs4cl showfs
# Only the mount command could list all file systems

View File

@ -11,7 +11,8 @@ hostname $HOSTNAME
#write the config files, the device name may change after reboot
#so use the dhcp for all interface
device_names=`ifconfig -a | grep -i hwaddr | grep -i 'Ethernet' | grep -v usb| awk '{print $1}'`
#device_names=`ifconfig -a | grep -i hwaddr | grep -i 'Ethernet' | grep -v usb| awk '{print $1}'`
device_names=`ip link |grep "BROADCAST" |awk '{print $2}' | sed s/://`
str_cfg_file=''
if [ -d "/etc/sysconfig/network-scripts/" ];then
#redhat