From 47e45f211e16b74803dff24d245edc1c6b4779a1 Mon Sep 17 00:00:00 2001 From: nott Date: Tue, 26 Feb 2008 18:07:16 +0000 Subject: [PATCH] Add check for attrs not set in setobjdefs. git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@580 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT-2.0/xCAT/DBobjUtils.pm | 38 +++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/perl-xCAT-2.0/xCAT/DBobjUtils.pm b/perl-xCAT-2.0/xCAT/DBobjUtils.pm index 9e02e09ec..6379ff956 100644 --- a/perl-xCAT-2.0/xCAT/DBobjUtils.pm +++ b/perl-xCAT-2.0/xCAT/DBobjUtils.pm @@ -584,6 +584,8 @@ sub setobjdefs push(@{$attrlist{$type}}, $entry->{'attr_name'}); } +my @attrprovided=(); + # check FINALATTRS to see if all the attrs are valid foreach my $attr (keys %{$objhash{$objname}}) { @@ -607,11 +609,18 @@ sub setobjdefs } next; } +#ndebug1 + push(@attrprovided, $attr); + } # we need to figure out what table to # store each attr # And we must do this in the order given in defspec!! + + + my @setattrlist=(); + foreach $this_attr (@{$datatype->{'attrs'}}) { @@ -619,6 +628,7 @@ sub setobjdefs my %updates; my $attr_name = $this_attr->{attr_name}; + # if we have a value for this attribute then process it # - otherwise go to the next attr if (defined($objhash{$objname}{$attr_name})) @@ -777,7 +787,6 @@ sub setobjdefs } # set the attr values in the DB - $thistable->setAttribs(\%keyhash, \%updates); my ($rc, $str) = $thistable->setAttribs(\%keyhash, \%updates); if (!defined($rc)) { @@ -791,17 +800,44 @@ r\'."; xCAT::MsgUtils->message("I", $rsp, $::callback); } $ret = 1; + $thistable->commit; next; } # $::settableref{$lookup_table} = $thistable; + + push(@setattrlist, $attr_name); $thistable->commit; } } # end - foreach attribute + + # + # check to see if all the attrs got set + # + # debug: print "attrprovided = @attrprovided, setattrlist = @setattrlist\n"; + + my @errlist; + foreach $a (@attrprovided) + { + # is this attr was not set then add it to the error list + if (!grep(/^$a$/, @setattrlist)) + { + push(@errlist, $a); + $ret = 2; + } + + } + if ($ret == 2) { + my $rsp; + $rsp->{data}->[0] = "Could not set the following attributes for the \'$objname\' definition in the xCAT database: \'@errlist\'\n"; + xCAT::MsgUtils->message("E", $rsp, $::callback); + } + } # end - foreach object + return $ret; }