From 82fbe03756c411d2649b170978d5566158f56c31 Mon Sep 17 00:00:00 2001 From: stdweird Date: Wed, 16 Apr 2014 22:32:09 +0200 Subject: [PATCH 1/8] extended kickstart tests with services --- aii-ks/src/test/perl/kickstart_commands.t | 32 +++++++++++++ aii-ks/src/test/resources/kernel-firmware.pan | 12 +---- aii-ks/src/test/resources/kickstart.pan | 47 +++++++++++++++++++ .../src/test/resources/kickstart_commands.pan | 7 +++ 4 files changed, 87 insertions(+), 11 deletions(-) create mode 100644 aii-ks/src/test/perl/kickstart_commands.t create mode 100644 aii-ks/src/test/resources/kickstart.pan create mode 100644 aii-ks/src/test/resources/kickstart_commands.pan diff --git a/aii-ks/src/test/perl/kickstart_commands.t b/aii-ks/src/test/perl/kickstart_commands.t new file mode 100644 index 00000000..a1993fd9 --- /dev/null +++ b/aii-ks/src/test/perl/kickstart_commands.t @@ -0,0 +1,32 @@ +use strict; +use warnings; +use Test::More; +use Test::Quattor qw(kickstart_commands); +use NCM::Component::ks; +use CAF::FileWriter; +use CAF::Object; + +=pod + +=head1 SYNOPSIS + +Tests for the C method. + +=cut + +$CAF::Object::NoAction = 1; + +my $fh = CAF::FileWriter->new("target/test/ks"); +# This module simply prints to the default filehandle. +select($fh); + +my $ks = NCM::Component::ks->new('ks'); +my $cfg = get_config_for_profile('kickstart_commands'); + +NCM::Component::ks::kscommands($cfg); +# test enable and disable +# check chkconfig --del and services list +like($fh, qr{^\s*services\s*--disabled=disable1,DISABLE2\s*--enabled=enable1,ENABLE2}m, "--dis/enable services present"); + + +done_testing(); diff --git a/aii-ks/src/test/resources/kernel-firmware.pan b/aii-ks/src/test/resources/kernel-firmware.pan index dfd4e079..cc818b6a 100644 --- a/aii-ks/src/test/resources/kernel-firmware.pan +++ b/aii-ks/src/test/resources/kernel-firmware.pan @@ -3,14 +3,4 @@ @} object template kernel-firmware; -prefix "/software/packages"; - -"{kernel*}/{2.6.32-358.1.el6}/arch/x86_64" = ""; -"{kernel-firmware}/{2.6.32-358.1.el6}/arch/noarch" = ""; -"{ncm-spma}/{14.2.1-1}/arch/noarch" = ""; -"{kernel-module-foo}" = nlist(); - -prefix "/system/aii/osinstall/ks"; - -"base_packages" = list("ncm-spma", "kernel-module-foo"); -"disabled_repos" = list(); +include 'kickstart'; diff --git a/aii-ks/src/test/resources/kickstart.pan b/aii-ks/src/test/resources/kickstart.pan new file mode 100644 index 00000000..23f51e8e --- /dev/null +++ b/aii-ks/src/test/resources/kickstart.pan @@ -0,0 +1,47 @@ +@{ +Base kickstart datae +@} +template kickstart; + +"/system/network/hostname" = 'x'; +"/system/network/domainname" = 'y'; + +prefix "/software/packages"; + +"{kernel*}/{2.6.32-358.1.el6}/arch/x86_64" = ""; +"{kernel-firmware}/{2.6.32-358.1.el6}/arch/noarch" = ""; +"{ncm-spma}/{14.2.1-1}/arch/noarch" = ""; +"{kernel-module-foo}" = nlist(); + + +# pxelinux and kickstart couple if bootproto is not dhcp +prefix "/system/aii/nbp/pxelinux"; +"ksdevice" = "eth0"; + +prefix "/system/aii/osinstall/ks"; +"bootproto" = "dhcp"; +"keyboard" = "us"; +"lang" = "en_US.UTF-8"; +"node_profile" = "https://somewhere/node_profile"; +"rootpw" = "veryverysecret"; +"osinstall_protocol" = "https"; +"ackurl" = "http://ack"; +"auth" = list ("enableshadow", "enablemd5"); +"bootloader_location" = "mbr"; +"clearmbr" = true; +"enable_sshd" = false; +"email_success" = false; +"installtype" = "url --url http://baseos"; +"timezone" = "Europe/SomeCity"; +"packages" = list("pacakge", "package2"); +"packages_args" = list("--ignoremissing","--resolvedeps"); +"end_script" = "EENNDD"; +"part_label" = false; +"volgroup_required" = false; + + +# optional +"enable_service" = list("enable1", "ENABLE2"); +"disable_service" = list("disable1", "DISABLE2"); +"base_packages" = list("ncm-spma", "kernel-module-foo"); +"disabled_repos" = list(); diff --git a/aii-ks/src/test/resources/kickstart_commands.pan b/aii-ks/src/test/resources/kickstart_commands.pan new file mode 100644 index 00000000..cedb69e5 --- /dev/null +++ b/aii-ks/src/test/resources/kickstart_commands.pan @@ -0,0 +1,7 @@ +@{ +Profile to ensure that the kickstart commands and packages section are generated +@} +object template kickstart_commands; + +include 'kickstart'; + From 73e597f6acada22ea2dab68036989cb933bffcce Mon Sep 17 00:00:00 2001 From: stdweird Date: Wed, 16 Apr 2014 22:33:08 +0200 Subject: [PATCH 2/8] modify the kickstart services --- aii-ks/src/main/perl/ks.pm | 22 +++++++++++----------- aii-ks/src/main/perl/ks.pod | 9 +++------ 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/aii-ks/src/main/perl/ks.pm b/aii-ks/src/main/perl/ks.pm index d7b891ab..0d156cf7 100755 --- a/aii-ks/src/main/perl/ks.pm +++ b/aii-ks/src/main/perl/ks.pm @@ -301,18 +301,18 @@ EOF print "ignoredisk --drives=", join (',', @{$tree->{ignoredisk}}), "\n"; } + + ## disable and enable services, if any + my @services; + push(@services, "--disabled=".join(',', @{$tree->{disable_service}})) if + (exists($tree->{disable_service}) && @{$tree->{disable_service}}); + push(@services, "--enabled=".join(',', @{$tree->{enable_service}})) if + (exists($tree->{enable_service}) && @{$tree->{enable_service}}); + + print "services ", join (' ', @services), "\n" if (@services); + print "%packages ", join(" ",@{$tree->{packages_args}}), "\n", join ("\n", @{$tree->{packages}}), "\n"; - - ## enable services, if any - if (exists($tree->{enable_service}) && @{$tree->{enable_service}}) { - ## should be a list of strings - my $services = join(" ",@{$tree->{enable_service}}); - if ($services) { - print "services --enabled=", - join (',', @{$tree->{enable_service}}), "\n";; - } - }; } @@ -1018,7 +1018,7 @@ EOF ksfix_grub; } - ## disable services, if any + # delete services, if any if (exists($tree->{disable_service})) { ## should be a list of strings my $services = join(" ",@{$tree->{disable_service}}); diff --git a/aii-ks/src/main/perl/ks.pod b/aii-ks/src/main/perl/ks.pod index 3899bd33..b5e7da9f 100644 --- a/aii-ks/src/main/perl/ks.pod +++ b/aii-ks/src/main/perl/ks.pod @@ -142,9 +142,7 @@ or "permissive". =item * disable_service ? string[] -List of services to be disabled before the reboot, in order to avoid -nasty behaviour such as, f.i, grabbing lots of RPMs from CERN because -of Yum. +List of services to be disabled and removed before the reboot. =item * base_packages ? string[] @@ -206,10 +204,9 @@ Whether or not the firewall must be enabled. List of trusted devices. Traffic from and to these devices will not be filtered. -=item * services : string[] +=item * enable_service : string[] -List of service names to be allowed by the firewall. Each element must -be one of ssh, telnet, smtp, http, ftp. Defaults to "ssh". +List of service names to be allowed by the firewall. =item * ports : long[] From 4fb21a611faf408faeb1e05b26d1a425d861051a Mon Sep 17 00:00:00 2001 From: stdweird Date: Wed, 16 Apr 2014 22:50:45 +0200 Subject: [PATCH 3/8] install keyword followed by installtype --- aii-ks/src/main/perl/ks.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aii-ks/src/main/perl/ks.pm b/aii-ks/src/main/perl/ks.pm index 0d156cf7..42b778f2 100755 --- a/aii-ks/src/main/perl/ks.pm +++ b/aii-ks/src/main/perl/ks.pm @@ -232,9 +232,9 @@ sub kscommands } print <{timezone} rootpw --iscrypted $tree->{rootpw} EOF From 50df6575274672341a1ee47e99e641a96a97ecaf Mon Sep 17 00:00:00 2001 From: stdweird Date: Wed, 16 Apr 2014 23:03:55 +0200 Subject: [PATCH 4/8] add end_script_field to packages section --- aii-ks/src/main/perl/ks.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aii-ks/src/main/perl/ks.pm b/aii-ks/src/main/perl/ks.pm index 42b778f2..981eacdd 100755 --- a/aii-ks/src/main/perl/ks.pm +++ b/aii-ks/src/main/perl/ks.pm @@ -253,7 +253,7 @@ EOF print " --level=$tree->{logging}->{level}" if $tree->{logging}->{level}; print "\n"; } - print "bootloader --location=$tree->{bootloader_location}"; + print "bootloader --location=$tree->{bootloader_location}"; print " --driveorder=", join(',', @{$tree->{bootdisk_order}}) if exists $tree->{bootdisk_order} && @{$tree->{bootdisk_order}}; print " --append=\"$tree->{bootloader_append}\"" @@ -312,8 +312,8 @@ EOF print "services ", join (' ', @services), "\n" if (@services); print "%packages ", join(" ",@{$tree->{packages_args}}), "\n", - join ("\n", @{$tree->{packages}}), "\n"; - + join ("\n", @{$tree->{packages}}), "\n", + $config->getElement(END_SCRIPT_FIELD)->getValue(), "\n"; } # Writes the mountpoint definitions and LVM and MD settings From 1fea9deae27f99b2074685ea0c64db3f22eea954 Mon Sep 17 00:00:00 2001 From: stdweird Date: Wed, 16 Apr 2014 23:04:14 +0200 Subject: [PATCH 5/8] add tests for kickstart_commands --- aii-ks/src/test/perl/kickstart_commands.t | 20 +++++++++++++++++--- aii-ks/src/test/resources/kickstart.pan | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/aii-ks/src/test/perl/kickstart_commands.t b/aii-ks/src/test/perl/kickstart_commands.t index a1993fd9..dbbc0477 100644 --- a/aii-ks/src/test/perl/kickstart_commands.t +++ b/aii-ks/src/test/perl/kickstart_commands.t @@ -24,9 +24,23 @@ my $ks = NCM::Component::ks->new('ks'); my $cfg = get_config_for_profile('kickstart_commands'); NCM::Component::ks::kscommands($cfg); -# test enable and disable -# check chkconfig --del and services list -like($fh, qr{^\s*services\s*--disabled=disable1,DISABLE2\s*--enabled=enable1,ENABLE2}m, "--dis/enable services present"); + +like($fh, qr{^text}m, 'text mode install present'); +like($fh, qr{^reboot}m, 'reboot after install present'); +like($fh, qr{^skipx}m, 'skip x configuration present'); +like($fh, qr{^auth\s--enableshadow\s--enablemd5}m, 'authentication parameters present'); +like($fh, qr{^install\n^url\s--url http://baseos}m, 'installtype present'); +like($fh, qr{^timezone\s--utc Europe/SomeCity}m, 'timezone present'); +like($fh, qr{^rootpw\s--iscrypted veryverysecret}m, 'crypted root password present'); +like($fh, qr{^bootloader\s--location=mbr}m, 'bootloader present'); +like($fh, qr{^lang\sen_US.UTF-8}m, 'lang setting present'); +like($fh, qr{^keyboard\sus}m, 'keyboard present'); +like($fh, qr{^firewall\s--disabled }m, ' present'); +like($fh, qr{^network\s--bootproto=dhcp}m, ' present'); +like($fh, qr{^zerombr yes}m, 'zerombr present'); +like($fh, qr{^services\s--disabled=disable1,DISABLE2\s--enabled=enable1,ENABLE2}m, "--dis/enable services present"); + +like($fh, qr{^%packages\s--ignoremissing\s--resolvedeps\n^package\n^package2\n^EENNDD\n}m, 'installtype present'); done_testing(); diff --git a/aii-ks/src/test/resources/kickstart.pan b/aii-ks/src/test/resources/kickstart.pan index 23f51e8e..08c6f729 100644 --- a/aii-ks/src/test/resources/kickstart.pan +++ b/aii-ks/src/test/resources/kickstart.pan @@ -33,7 +33,7 @@ prefix "/system/aii/osinstall/ks"; "email_success" = false; "installtype" = "url --url http://baseos"; "timezone" = "Europe/SomeCity"; -"packages" = list("pacakge", "package2"); +"packages" = list("package", "package2"); "packages_args" = list("--ignoremissing","--resolvedeps"); "end_script" = "EENNDD"; "part_label" = false; From 1fabe77ca3ab119ae6d610e7c026cb7d8257ace6 Mon Sep 17 00:00:00 2001 From: stdweird Date: Wed, 16 Apr 2014 23:13:36 +0200 Subject: [PATCH 6/8] fix typo --- aii-ks/src/test/resources/kickstart.pan | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aii-ks/src/test/resources/kickstart.pan b/aii-ks/src/test/resources/kickstart.pan index 08c6f729..e67fa452 100644 --- a/aii-ks/src/test/resources/kickstart.pan +++ b/aii-ks/src/test/resources/kickstart.pan @@ -1,5 +1,5 @@ @{ -Base kickstart datae +Base kickstart data @} template kickstart; From 38e931241285267671f959ab3921a5f052828e73 Mon Sep 17 00:00:00 2001 From: stdweird Date: Wed, 16 Apr 2014 23:39:24 +0200 Subject: [PATCH 7/8] Add pxelinux unittests --- aii-pxelinux/pom.xml | 4 +- aii-pxelinux/src/main/perl/pxelinux.pm | 2 +- aii-pxelinux/src/test/perl/pxelinux_block.t | 37 +++++++++++++++++++ aii-pxelinux/src/test/resources/ccm.cfg | 6 +++ aii-pxelinux/src/test/resources/pxelinux.pan | 14 +++++++ .../src/test/resources/pxelinux_block.pan | 3 ++ 6 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 aii-pxelinux/src/test/perl/pxelinux_block.t create mode 100644 aii-pxelinux/src/test/resources/ccm.cfg create mode 100644 aii-pxelinux/src/test/resources/pxelinux.pan create mode 100644 aii-pxelinux/src/test/resources/pxelinux_block.pan diff --git a/aii-pxelinux/pom.xml b/aii-pxelinux/pom.xml index d4593b4c..2abef810 100644 --- a/aii-pxelinux/pom.xml +++ b/aii-pxelinux/pom.xml @@ -54,14 +54,14 @@ org.quattor.maven assemblies tar.gz - 1.22 + 1.34 assemblies org.quattor.maven build-scripts tar.gz - 1.22 + 1.34 scripts diff --git a/aii-pxelinux/src/main/perl/pxelinux.pm b/aii-pxelinux/src/main/perl/pxelinux.pm index 6e9d2f94..a7bf234d 100755 --- a/aii-pxelinux/src/main/perl/pxelinux.pm +++ b/aii-pxelinux/src/main/perl/pxelinux.pm @@ -89,7 +89,7 @@ sub link_filepath } -# Prints the PXE configuration file. +# Writes the PXE configuration file. sub pxeprint { my $cfg = shift; diff --git a/aii-pxelinux/src/test/perl/pxelinux_block.t b/aii-pxelinux/src/test/perl/pxelinux_block.t new file mode 100644 index 00000000..a5eded83 --- /dev/null +++ b/aii-pxelinux/src/test/perl/pxelinux_block.t @@ -0,0 +1,37 @@ +use strict; +use warnings; +use Test::More; +use Test::Quattor qw(pxelinux_block); +use NCM::Component::pxelinux; +use CAF::FileWriter; +use CAF::Object; + +=pod + +=head1 SYNOPSIS + +Tests for the C method. + +=cut + +$CAF::Object::NoAction = 1; + +# mock filepath, it has this_app->option +my $fp = "target/test/pxelinux"; +my $mockpxe = Test::MockModule->new('NCM::Component::pxelinux'); +$mockpxe->mock('filepath', $fp); + +my $ks = NCM::Component::pxelinux->new('pxelinux'); +my $cfg = get_config_for_profile('pxelinux_block'); + +NCM::Component::pxelinux::pxeprint($cfg); + +my $fh = get_file($fp); + +like($fh, qr{^default\skernel\slabel}m, 'default kernel'); +like($fh, qr{^\s{4}label\skernel\slabel}m, 'label default kernel'); +like($fh, qr{^\s{4}kernel\smykernel}m, 'kernel mykernel'); +like($fh, qr{^\s{4}append\sramdisk=32768\sinitrd=path/to/initrd\sks=http://server/ks\sksdevice=eth0}m, 'append line'); + + +done_testing(); diff --git a/aii-pxelinux/src/test/resources/ccm.cfg b/aii-pxelinux/src/test/resources/ccm.cfg new file mode 100644 index 00000000..d0aebda3 --- /dev/null +++ b/aii-pxelinux/src/test/resources/ccm.cfg @@ -0,0 +1,6 @@ +debug 0 +get_timeout 1 +profile https://www.google.com +cache_root target/test/cache +retrieve_wait 0 +retrieve_retries 1 diff --git a/aii-pxelinux/src/test/resources/pxelinux.pan b/aii-pxelinux/src/test/resources/pxelinux.pan new file mode 100644 index 00000000..34295223 --- /dev/null +++ b/aii-pxelinux/src/test/resources/pxelinux.pan @@ -0,0 +1,14 @@ +@{ +Base pxelinux data +@} +template pxelinux; + +"/system/network/hostname" = 'x'; +"/system/network/domainname" = 'y'; + +prefix "/system/aii/nbp/pxelinux"; +"ksdevice" = "eth0"; +"initrd" = "path/to/initrd"; +"kernel" = 'mykernel'; +"kslocation" = "http://server/ks"; +"label" = "kernel label"; diff --git a/aii-pxelinux/src/test/resources/pxelinux_block.pan b/aii-pxelinux/src/test/resources/pxelinux_block.pan new file mode 100644 index 00000000..8e81e925 --- /dev/null +++ b/aii-pxelinux/src/test/resources/pxelinux_block.pan @@ -0,0 +1,3 @@ +object template pxelinux_block; + +include 'pxelinux'; From ce1e88790d748a1bb801d65ee28843bfab168236 Mon Sep 17 00:00:00 2001 From: stdweird Date: Wed, 16 Apr 2014 23:46:07 +0200 Subject: [PATCH 8/8] whitespace cleanup --- aii-pxelinux/src/main/perl/pxelinux.pm | 233 ++++++++++++------------- 1 file changed, 113 insertions(+), 120 deletions(-) diff --git a/aii-pxelinux/src/main/perl/pxelinux.pm b/aii-pxelinux/src/main/perl/pxelinux.pm index a7bf234d..fcaa7a5f 100755 --- a/aii-pxelinux/src/main/perl/pxelinux.pm +++ b/aii-pxelinux/src/main/perl/pxelinux.pm @@ -2,14 +2,6 @@ # ${developer-info # ${author-info} # ${build-info} -# File: pxelinux.pm -# Implementation of ncm-pxelinux -# Author: Luis Fernando Muñoz Mejías -# Version: 1.1.12 : 05/01/12 19:24 -# ** Generated file : do not edit ** -# -# Capitalized methods are "public" methods. Methods in lowercase are -# "private" methods. package NCM::Component::pxelinux; @@ -25,25 +17,25 @@ use LC::Fatal qw (symlink); use File::stat; use Time::localtime; -use constant PXEROOT => "/system/aii/nbp/pxelinux"; -use constant NBPDIR => 'nbpdir'; -use constant LOCALBOOT => 'bootconfig'; -use constant HOSTNAME => "/system/network/hostname"; -use constant DOMAINNAME => "/system/network/domainname"; -use constant ETH => "/system/network/interfaces"; -use constant INSTALL => 'install'; -use constant BOOT => 'boot'; -use constant RESCUE => 'rescue'; +use constant PXEROOT => "/system/aii/nbp/pxelinux"; +use constant NBPDIR => 'nbpdir'; +use constant LOCALBOOT => 'bootconfig'; +use constant HOSTNAME => "/system/network/hostname"; +use constant DOMAINNAME => "/system/network/domainname"; +use constant ETH => "/system/network/interfaces"; +use constant INSTALL => 'install'; +use constant BOOT => 'boot'; +use constant RESCUE => 'rescue'; use constant RESCUEBOOT => 'rescueconfig'; -use constant FIRMWARE => 'firmware'; -use constant LIVECD => 'livecd'; +use constant FIRMWARE => 'firmware'; +use constant LIVECD => 'livecd'; # Hooks for NBP plug-in -use constant RESCUE_HOOK_PATH => '/system/aii/hooks/rescue'; -use constant INSTALL_HOOK_PATH => '/system/aii/hooks/install'; -use constant REMOVE_HOOK_PATH => '/system/aii/hooks/remove'; -use constant BOOT_HOOK_PATH => '/system/aii/hooks/boot'; -use constant FIRMWARE_HOOK_PATH => '/system/aii/hooks/firmware'; -use constant LIVECD_HOOK_PATH => '/system/aii/hooks/livecd'; +use constant RESCUE_HOOK_PATH => '/system/aii/hooks/rescue'; +use constant INSTALL_HOOK_PATH => '/system/aii/hooks/install'; +use constant REMOVE_HOOK_PATH => '/system/aii/hooks/remove'; +use constant BOOT_HOOK_PATH => '/system/aii/hooks/boot'; +use constant FIRMWARE_HOOK_PATH => '/system/aii/hooks/firmware'; +use constant LIVECD_HOOK_PATH => '/system/aii/hooks/livecd'; our @ISA = qw (NCM::Component); our $EC = LC::Exception::Context->new->will_store_all; @@ -70,20 +62,20 @@ sub link_filepath my $cfgpath = PXEROOT . "/" . $cmd; if ($cfg->elementExists ($cfgpath)) { - my $linkname = $cfg->getElement ($cfgpath)->getValue; - return "$dir/$linkname"; + my $linkname = $cfg->getElement ($cfgpath)->getValue; + return "$dir/$linkname"; } elsif ($cmd eq RESCUE) { - # Backwards compatibility: use the option set on the command line - # if the profile does not define a rescue image - my $path = $this_app->option (RESCUEBOOT); - unless ($path =~ m{^([-.\w]+)$}) { - $this_app->error ("Unexpected RESCUE configuration file"); - } - return "$dir/$1"; + # Backwards compatibility: use the option set on the command line + # if the profile does not define a rescue image + my $path = $this_app->option (RESCUEBOOT); + unless ($path =~ m{^([-.\w]+)$}) { + $this_app->error ("Unexpected RESCUE configuration file"); + } + return "$dir/$1"; } else { - my $h = $cfg->getElement (HOSTNAME)->getValue; - my $d = $cfg->getElement (DOMAINNAME)->getValue; - $this_app->debug(3, "No $cmd defined for $h.$d"); + my $h = $cfg->getElement (HOSTNAME)->getValue; + my $d = $cfg->getElement (DOMAINNAME)->getValue; + $this_app->debug(3, "No $cmd defined for $h.$d"); } return undef; } @@ -98,7 +90,8 @@ sub pxeprint my $server = hostname(); $ksloc =~ s{LOCALHOST}{$server}; my $fh = CAF::FileWriter->open (filepath ($cfg), - log => $this_app, mode => 0644); + log => $this_app, + mode => 0644); $t->{append} = "" unless exists $t->{append}; $fh->print (<{label} kernel $t->{kernel} append ramdisk=32768 initrd=$t->{initrd} ks=$ksloc ksdevice=$t->{ksdevice} $t->{append} EOF - ); + ); $fh->print (" ipappend 2\n") if $t->{ksdevice} eq 'bootif'; $fh->close(); @@ -131,49 +124,49 @@ sub pxelink my $t = $cfg->getElement (ETH)->getTree; my $path; if (!$cmd) { - $path = $this_app->option (LOCALBOOT); - $this_app->debug (5, "Configuring on $path"); + $path = $this_app->option (LOCALBOOT); + $this_app->debug (5, "Configuring on $path"); } elsif ($cmd eq BOOT) { - $path = $this_app->option (LOCALBOOT); - unless ($path =~ m{^([-.\w]+)$}) { - $this_app->error ("Unexpected BOOT configuration file"); - return -1; - } - $path = $1; - $this_app->debug (5, "Local booting from $path"); + $path = $this_app->option (LOCALBOOT); + unless ($path =~ m{^([-.\w]+)$}) { + $this_app->error ("Unexpected BOOT configuration file"); + return -1; + } + $path = $1; + $this_app->debug (5, "Local booting from $path"); } elsif ($cmd eq RESCUE || $cmd eq LIVECD || $cmd eq FIRMWARE) { - $path = link_filepath($cfg, $cmd); - if (! -f $path) { - my $h = $cfg->getElement (HOSTNAME)->getValue; - my $d = $cfg->getElement (DOMAINNAME)->getValue; - $this_app->error("Missing $cmd config file for $h.$d: $path"); - return -1; - } - $this_app->debug (5, "Using $cmd from: $path"); + $path = link_filepath($cfg, $cmd); + if (! -f $path) { + my $h = $cfg->getElement (HOSTNAME)->getValue; + my $d = $cfg->getElement (DOMAINNAME)->getValue; + $this_app->error("Missing $cmd config file for $h.$d: $path"); + return -1; + } + $this_app->debug (5, "Using $cmd from: $path"); } elsif ($cmd eq INSTALL) { - $path = filepath ($cfg); - $this_app->debug (5, "Installing on $path"); + $path = filepath ($cfg); + $this_app->debug (5, "Installing on $path"); } else { - $this_app->debug (5, "Unknown command"); - return -1; + $this_app->debug (5, "Unknown command"); + return -1; } # Set the same settings for every network interface that has a # defined IP address. foreach my $st (values (%$t)) { - next unless exists ($st->{ip}); - my $dir = $this_app->option (NBPDIR); - my $lnname = "$dir/".hexip ($st->{ip}); - if ($cmd || ! -l $lnname) { - if ($NoAction) { - $this_app->info ("Would symlink $path to $lnname"); - } else { - unlink ($lnname); - # This must be stripped to work with chroot'edg - # environments. - $path =~ s{$dir/?}{}; - symlink ($path, $lnname); - } - } + next unless exists ($st->{ip}); + my $dir = $this_app->option (NBPDIR); + my $lnname = "$dir/".hexip ($st->{ip}); + if ($cmd || ! -l $lnname) { + if ($NoAction) { + $this_app->info ("Would symlink $path to $lnname"); + } else { + unlink ($lnname); + # This must be stripped to work with chroot'edg + # environments. + $path =~ s{$dir/?}{}; + symlink ($path, $lnname); + } + } } return 0; } @@ -184,10 +177,10 @@ sub Install my ($self, $cfg) = @_; unless (pxelink ($cfg, INSTALL)==0) { - my $h = $cfg->getElement (HOSTNAME)->getValue; - my $d = $cfg->getElement (DOMAINNAME)->getValue; - $self->error ("Failed to change the status of $h.$d to install"); - return 0; + my $h = $cfg->getElement (HOSTNAME)->getValue; + my $d = $cfg->getElement (DOMAINNAME)->getValue; + $self->error ("Failed to change the status of $h.$d to install"); + return 0; } ksuserhooks ($cfg, INSTALL_HOOK_PATH) unless $NoAction; return 1; @@ -199,10 +192,10 @@ sub Firmware my ($self, $cfg) = @_; unless (pxelink ($cfg, FIRMWARE)==0) { - my $h = $cfg->getElement (HOSTNAME)->getValue; - my $d = $cfg->getElement (DOMAINNAME)->getValue; - $self->error ("Failed to change the status of $h.$d to firmware"); - return 0; + my $h = $cfg->getElement (HOSTNAME)->getValue; + my $d = $cfg->getElement (DOMAINNAME)->getValue; + $self->error ("Failed to change the status of $h.$d to firmware"); + return 0; } ksuserhooks ($cfg, FIRMWARE_HOOK_PATH) unless $NoAction; return 1; @@ -214,10 +207,10 @@ sub Livecd my ($self, $cfg) = @_; unless (pxelink ($cfg, LIVECD)==0) { - my $h = $cfg->getElement (HOSTNAME)->getValue; - my $d = $cfg->getElement (DOMAINNAME)->getValue; - $self->error("Failed to change the status of $h.$d to livecd"); - return 0; + my $h = $cfg->getElement (HOSTNAME)->getValue; + my $d = $cfg->getElement (DOMAINNAME)->getValue; + $self->error("Failed to change the status of $h.$d to livecd"); + return 0; } ksuserhooks ($cfg, LIVECD_HOOK_PATH) unless $NoAction; return 1; @@ -229,10 +222,10 @@ sub Rescue my ($self, $cfg) = @_; unless (pxelink ($cfg, RESCUE)==0) { - my $h = $cfg->getElement (HOSTNAME)->getValue; - my $d = $cfg->getElement (DOMAINNAME)->getValue; - $self->error ("Failed to change the status of $h.$d to rescue"); - return 0; + my $h = $cfg->getElement (HOSTNAME)->getValue; + my $d = $cfg->getElement (DOMAINNAME)->getValue; + $self->error ("Failed to change the status of $h.$d to rescue"); + return 0; } ksuserhooks ($cfg, RESCUE_HOOK_PATH) unless $NoAction; return 1; @@ -253,34 +246,34 @@ sub Status my $firmware = link_filepath($cfg, FIRMWARE); my $livecd = link_filepath($cfg, LIVECD); foreach my $s (values (%$t)) { - next unless exists ($s->{ip}); - my $ln = hexip ($s->{ip}); - my $since = "unknown"; - my $st; - if (-l "$dir/$ln") { - $since = ctime(lstat("$dir/$ln")->ctime()); - my $name = readlink ("$dir/$ln"); - my $name_path = "$dir/$name"; - if (! -e $name_path) { - $st = "broken"; - } elsif ($name =~ m{^(?:.*/)?$fqdn\.cfg$}) { - $st = "install"; - } elsif ($name =~ m{^$boot$}) { - $st = "boot"; - } elsif ($firmware && ($name_path =~ m{$firmware})) { - $st = "firmware"; - } elsif ($livecd && ($name_path =~ m{$livecd})) { - $st = "livecd"; - } elsif ($rescue && ($name_path =~ m{$rescue})) { - $st = "rescue"; - } else { - $st = "unknown"; - } - } else { - $st = "undefined"; - } - $self->info(ref($self), " status for $fqdn: $s->{ip} $st ", - "since: $since"); + next unless exists ($s->{ip}); + my $ln = hexip ($s->{ip}); + my $since = "unknown"; + my $st; + if (-l "$dir/$ln") { + $since = ctime(lstat("$dir/$ln")->ctime()); + my $name = readlink ("$dir/$ln"); + my $name_path = "$dir/$name"; + if (! -e $name_path) { + $st = "broken"; + } elsif ($name =~ m{^(?:.*/)?$fqdn\.cfg$}) { + $st = "install"; + } elsif ($name =~ m{^$boot$}) { + $st = "boot"; + } elsif ($firmware && ($name_path =~ m{$firmware})) { + $st = "firmware"; + } elsif ($livecd && ($name_path =~ m{$livecd})) { + $st = "livecd"; + } elsif ($rescue && ($name_path =~ m{$rescue})) { + $st = "rescue"; + } else { + $st = "unknown"; + } + } else { + $st = "undefined"; + } + $self->info(ref($self), " status for $fqdn: $s->{ip} $st ", + "since: $since"); } return 1; } @@ -311,8 +304,8 @@ sub Unconfigure my ($self, $cfg) = @_; if ($NoAction) { - $self->info ("Would remove " . ref ($self)); - return 1; + $self->info ("Would remove " . ref ($self)); + return 1; } my $t = $cfg->getElement (ETH)->getTree;