[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [OSSTEST RFC 07/16] Osstest/CentOS: kickstart_create to generate an autoinstall recipe
Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx> --- Osstest/CentOS.pm | 215 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 215 insertions(+) diff --git a/Osstest/CentOS.pm b/Osstest/CentOS.pm index 33479b1..dbba354 100644 --- a/Osstest/CentOS.pm +++ b/Osstest/CentOS.pm @@ -28,13 +28,22 @@ BEGIN { $VERSION = 1.00; @ISA = qw(Exporter); @EXPORT = qw( + kickstart_create + kickstart_hook_command kickstart_installcmdline_core + ks_vg_name ); %EXPORT_TAGS = ( ); @EXPORT_OK = qw(); } +# -Y off disables any proxy, since there is no point going through the +# proxy when fetching stuff from the local controller or the local cache. +our $kickstart_wget = 'wget -Y off'; + +our %kickstart_cmds; + sub kickstart_installcmdline_core ($$;@) { my ($tho, $ks_url, %xopts) = @_; @@ -48,4 +57,210 @@ sub kickstart_installcmdline_core ($$;@) { return @cl; } +sub ks_vg_name($) { + my ($ho) = @_; + + return "$ho->{Name}-vg"; +} + +sub kickstart_ssh ($$) { + my ($ho,$sfx) = @_; + + my $authkeys_url= create_webfile($ho, "authkeys$sfx", authorized_keys()); + my $knownhosts_url= create_webfile($ho, "known_hosts$sfx", known_hosts()); + + kickstart_hook_command($ho, 'post', $sfx, <<END); +#!/bin/sh +set -ex + +r=/root +cd \$r + +umask 022 +mkdir -p .ssh +$kickstart_wget -O .ssh/authorized_keys '$authkeys_url' +$kickstart_wget -O .ssh/known_hosts '$knownhosts_url' + +u=osstest +h=/home/\$u +mkdir -p \$h/.ssh +cp .ssh/authorized_keys \$h/.ssh +chown -R \$u.\$u \$h/.ssh +END +} + +sub kickstart_hook_overlay ($$$$) { + my ($ho, $sfx, $srcdir, $tfilename) = @_; + my $url= create_webfile($ho, "$tfilename$sfx", sub { + my ($fh) = @_; + contents_make_cpio($fh, 'ustar', $srcdir); + }); + kickstart_hook_command($ho, 'post', $sfx, <<END); +#!/bin/sh +set -ex + +r=/root +cd \$r + +umask 022 + +$kickstart_wget -O overlay.tar '$url' +cd / +tar xf \$r/overlay.tar +cd \$r +rm overlay.tar + +END +} + +sub kickstart_base ($$;@) { + my ($ho,$sfx,%xopts) = @_; + + kickstart_ssh($ho, $sfx); + + kickstart_hook_overlay($ho, $sfx, $c{OverlayLocal}, 'overlay-local.tar'); + + my $ntpserver = get_target_property($ho,'NtpServer'); + if ($ntpserver) { + $ntpserver = "--ntpservers=$ntpserver"; + } + my $kickstart_file = <<"END"; +#version=RHEL7 +# System authorization information +auth --enableshadow --passalgo=sha512 +# License agreement +eula --agreed +# Use text mode install +text +# Keyboard layouts +keyboard --vckeymap=us --xlayouts='us' +# System language +lang en_GB.UTF-8 +# Do not configure the X Window System +skipx +# System timezone +timezone $c{Timezone} --isUtc $ntpserver +# Reboot after installation +reboot + +# Root password +rootpw --plaintext xenroot +# osstest user +user --name=osstest --plaintext --password=osstest --gecos="FLOSS Xen Test" +END + + return $kickstart_file; +} + +sub kickstart_create ($$;@) { + my ($ho, $sfx, %xopts) = @_; + + my $disk= $xopts{DiskDevice} || '/dev/sda'; + + # Start an update, which pulls packages from the updates repo + push @{ $kickstart_cmds{post} }, "yum -y update"; + + my $releasever = '7'; + my $basearch = 'x86_64'; + + my $proxy = ''; + $proxy = '--proxy='. $c{HttpProxy} + if $c{HttpProxy}; + + # CentOS mirror found on this list: + # http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os + my $mirror = 'http://centos.mirroring.pulsant.co.uk/7.4.1708/os/x86_64/'; + + our $vgname = ks_vg_name($ho); + + my $kickstart_file = kickstart_base($ho, $sfx, %xopts); + $kickstart_file .= <<"END"; +# Use network installation +url --url=$mirror $proxy + +# Network information +network --bootproto=dhcp --device=bootif --hostname=$xopts{Hostname}.$c{TestHostDomain} + +# Clear the Master Boot Record +zerombr +# Partition clearing information +clearpart --all --drives=$disk +# Disk partitioning information +part /boot --asprimary --size=$c{HostDiskBoot} --fstype=ext3 --ondrive=$disk +part pv.01 --grow --ondrive=$disk +volgroup $vgname pv.01 +logvol / --name=root --size=$c{HostDiskRoot} --vgname=$vgname --fstype=ext4 +logvol swap --name=swap --size=$c{HostDiskSwap} --vgname=$vgname + +# System bootloader configuration +bootloader --location=mbr --boot-drive=$disk +END + + kickstart_hook_command($ho, 'post', $sfx, <<END); +#!/bin/sh +set -ex +cmdline=\$(cat /proc/cmdline) +bootif=\${cmdline#*BOOTIF=} +[ "\$cmdline" != "\$bootif" ] +bootif=\${bootif% *} +bootif=\${bootif#01-} +bootif=\${bootif//-/:} + +# Remove generated network profiles +rm -v /etc/sysconfig/network-scripts/ifcfg-* + +# Replace them with one based on MAC rather than interface name +tee /etc/sysconfig/network-scripts/ifcfg-osstest-if0 <<ENDCFG +TYPE=Ethernet +HWADDR=\$bootif +ONBOOT=yes +BOOTPROTO=dhcp +ENDCFG +END + + # pre & post sections + $kickstart_file .= kickstart_hook_cmds(); + + # packages section + $kickstart_file .= <<"END"; +%packages +\@core +wget +ed +%end +END + + # Disable kdump + $kickstart_file .= <<END; +%addon com_redhat_kdump --disable +%end +END + + return create_webfile($ho, "kickstart$sfx", $kickstart_file); +} + + +sub kickstart_hook_command ($$$$) { + my ($ho, $ks_section, $sfx, $text) = @_; + my $ix= $#{ $kickstart_cmds{$ks_section} } + 1; + my $url= create_webfile($ho, "$ks_section-$ix$sfx", $text); + my $file= "/tmp/$ks_section-$ix"; + my $cmd_cmd= "$kickstart_wget -O $file '$url' && chmod +x $file && $file"; + push @{ $kickstart_cmds{$ks_section} }, $cmd_cmd; +} + +sub kickstart_hook_cmds () { + my $kickstart; + foreach my $ks_section (keys %kickstart_cmds) { + my $cmds = join("\n", @{ $kickstart_cmds{$ks_section} }); + $kickstart .= <<"END"; +%$ks_section --log=/root/ks-$ks_section.log +set -x +$cmds +%end +END + } + return $kickstart; +} + 1; -- Anthony PERARD _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |