From da7455266023274dd1aca1fb9854a6bbe8985f67 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Sat, 24 May 2008 16:25:22 +0000 Subject: * heavily redesigned and improved the checking of attributes: instead of dying on the first error, we now collect all errors and return them. The caller can now decide what to do - die or just print a warning or whatever. * slxconfig now dies with the list of all attribute problems if there were any * slxconfig-demuxer prints warnings for all attribute problems that were found (checking for each system & client in turn) * adjusted desktop plugin to API changes concerning the attribute checks git-svn-id: http://svn.openslx.org/svn/openslx/openslx/trunk@1796 95ad53e4-c205-0410-b2fa-d234c58c8868 --- config-db/OpenSLX/AttributeRoster.pm | 57 ++++++++++++++++++++++-------------- config-db/slxconfig | 16 ++++++++-- config-db/slxconfig-demuxer | 32 ++++++++++---------- 3 files changed, 65 insertions(+), 40 deletions(-) (limited to 'config-db') diff --git a/config-db/OpenSLX/AttributeRoster.pm b/config-db/OpenSLX/AttributeRoster.pm index 61825f77..de7b5ced 100644 --- a/config-db/OpenSLX/AttributeRoster.pm +++ b/config-db/OpenSLX/AttributeRoster.pm @@ -498,22 +498,26 @@ sub getClientAttrs keys %AttributeInfo } -=item C +=item C Checks if the given stage3 attribute values are allowed (and make sense). -If all values are ok, this method returns 1 - if not, it dies with an -appropriate message. + +This method returns an array-ref of problems found. If there were no problems, +this methods returns undef. =cut -sub checkValues +sub findProblematicValues { - my $class = shift; - my $stage3Attrs = shift || {}; - my $vendorOSName = shift; + my $class = shift; + my $stage3Attrs = shift || {}; + my $vendorOSName = shift; + my $installedPlugins = shift; $class->_init() if !%AttributeInfo; + my @problems; + my %attrsByPlugin; foreach my $key (sort keys %{$stage3Attrs}) { my $value = $stage3Attrs->{$key}; @@ -531,30 +535,39 @@ sub checkValues || die _tr('attribute "%s" is unknown!', $key); my $regex = $attrInfo->{content_regex}; if ($regex && $value !~ $regex) { - die _tr( + push @problems, _tr( "the value '%s' for attribute %s is not allowed.\nAllowed values are: %s", $value, $key, $attrInfo->{content_descr} ); } } - # if no vendorOS-name has been provided, we can't initialize any plugins, - # so we are done - return 1 if !$vendorOSName; - - # now give each plugin a chance to check it's own attributes by itself - foreach my $pluginName (sort keys %attrsByPlugin) { - # create & start OSPlugin-engine for vendor-OS and current plugin - my $engine = OpenSLX::OSPlugin::Engine->new; - $engine->initialize($pluginName, $vendorOSName); - if (!$engine->{'plugin-path'}) { - warn _tr('unable to create engine for plugin "%s"!', $pluginName); - next; + # if no vendorOS-name has been provided or there are no plugins installed, + # we can't do any further checks + if ($vendorOSName && $installedPlugins) { + # now give each installed plugin a chance to check it's own attributes + # by itself + foreach my $pluginInfo (sort @$installedPlugins) { + my $pluginName = $pluginInfo->{plugin_name}; + vlog 2, "checking attrs of plugin: $pluginName\n"; + # create & start OSPlugin-engine for vendor-OS and current plugin + my $engine = OpenSLX::OSPlugin::Engine->new; + $engine->initialize($pluginName, $vendorOSName); + if (!$engine->{'plugin-path'}) { + warn _tr( + 'unable to create engine for plugin "%s"!', $pluginName + ); + next; + } + $engine->checkStage3AttrValues( + $attrsByPlugin{$pluginName}, \@problems + ); } - $engine->checkStage3AttrValues($attrsByPlugin{$pluginName}); } - return 1; + return if !@problems; + + return \@problems; } 1; diff --git a/config-db/slxconfig b/config-db/slxconfig index d4656e5e..02029a81 100755 --- a/config-db/slxconfig +++ b/config-db/slxconfig @@ -269,12 +269,24 @@ sub checkGivenStage3Attrs my $stage3Attrs = shift; my $vendorOSID = shift; + my $attrProblems; + if ($vendorOSID) { my $vendorOS = $openslxDB->fetchVendorOSByID($vendorOSID); - OpenSLX::AttributeRoster->checkValues($stage3Attrs, $vendorOS->{name}); + my @installedPlugins = $openslxDB->fetchInstalledPlugins($vendorOSID); + $attrProblems = OpenSLX::AttributeRoster->findProblematicValues( + $stage3Attrs, $vendorOS->{name}, \@installedPlugins + ); } else { - OpenSLX::AttributeRoster->checkValues($stage3Attrs); + $attrProblems = OpenSLX::AttributeRoster->findProblematicValues( + $stage3Attrs + ); + } + + if ($attrProblems) { + my $complaint = join "\n", @$attrProblems; + die $complaint; } return 1; diff --git a/config-db/slxconfig-demuxer b/config-db/slxconfig-demuxer index 6eb613a3..5d0928ae 100755 --- a/config-db/slxconfig-demuxer +++ b/config-db/slxconfig-demuxer @@ -641,14 +641,14 @@ sub writeClientConfigurationsForSystem $externalSystemID, $buildPath, $externalClientName ); - my $attrsOK = eval { - OpenSLX::AttributeRoster->checkValues( - $client->{attrs}, $info->{'vendor-os'}->{name} - ); - 1; - }; - if (!$attrsOK && $@) { - warn $@; + my $attrProblems = OpenSLX::AttributeRoster->findProblematicValues( + $client->{attrs}, $info->{'vendor-os'}->{name}, + $info->{'installed-plugins'} + ); + if ($attrProblems) { + my $complaint = join "\n", @$attrProblems; + $complaint =~ s{^}{client $client->{name}: }gms; + warn $complaint; } writeAttributesToFile($client, $attrFile); @@ -746,14 +746,14 @@ sub writeSystemConfiguration ) ); - my $attrsOK = eval { - OpenSLX::AttributeRoster->checkValues( - $info->{attrs}, $info->{'vendor-os'}->{name} - ); - 1; - }; - if (!$attrsOK && $@) { - warn $@; + my $attrProblems = OpenSLX::AttributeRoster->findProblematicValues( + $info->{attrs}, $info->{'vendor-os'}->{name}, + $info->{'installed-plugins'} + ); + if ($attrProblems) { + my $complaint = join "\n", @$attrProblems; + $complaint =~ s{^}{system $info->{name}: }gms; + warn $complaint; } my $attrFile = "$buildPath/initramfs/machine-setup"; -- cgit v1.2.3-55-g7522