From ad3b48cae4fa5836894fbd98267a340182ca5c9f Mon Sep 17 00:00:00 2001 From: ligc Date: Thu, 6 Dec 2012 13:30:55 +0000 Subject: [PATCH] fix for bug 3221: check if the attributes specified with -i are valid attributes git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@14572 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/DBobjectdefs.pm | 42 ++++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/DBobjectdefs.pm b/xCAT-server/lib/xcat/plugins/DBobjectdefs.pm index ee1ffe9d8..08f06ae13 100644 --- a/xCAT-server/lib/xcat/plugins/DBobjectdefs.pm +++ b/xCAT-server/lib/xcat/plugins/DBobjectdefs.pm @@ -1673,7 +1673,7 @@ sub defch { my $rsp; $rsp->{data}->[0] = - "\'$attr\' is not a valid attribute name for for an object type of \'$::objtype\'."; + "\'$attr\' is not a valid attribute name for an object type of \'$::objtype\'."; $rsp->{data}->[1] = "Skipping to the next attribute."; xCAT::MsgUtils->message("E", $rsp, $::callback); $error = 1; @@ -2282,7 +2282,7 @@ sub setFINALattrs my $rsp; $rsp->{data}->[0] = - "\'$attr\' is not a valid attribute name for for an object type of \'$::objtype\'."; + "\'$attr\' is not a valid attribute name for an object type of \'$::objtype\'."; xCAT::MsgUtils->message("E", $rsp, $::callback); $error = 1; next; @@ -2733,6 +2733,18 @@ sub defls # for each type foreach my $type (@::clobjtypes) { + # Check if -i specifies valid attributes + # get the data type definition from Schema.pm + my %validattrslist; + if ($::opt_i) + { + my $datatype = $xCAT::Schema::defspec{$type}; + foreach my $this_attr (sort @{$datatype->{'attrs'}}) + { + my $a = $this_attr->{attr_name}; + $validattrslist{$a} = 1; + } + } my %defhash; @@ -2807,10 +2819,32 @@ sub defls my @attrlist; if (($type ne 'site') && ($type ne 'monitoring')) { - # get the list of all attrs for this type object + # -i is specified if (scalar(@::AttrList) > 0) { - @attrlist = @::AttrList; + foreach my $attr (@::AttrList) + { + # For site and monitoring, does not check if -i attributes are valid + if (($type eq 'site') || ($type eq 'monitoring')) + { + @attrlist = @::AttrList; + } else { + if (defined($validattrslist{$attr})) + { + if (!grep(/^$attr$/, @attrlist)) + { + push @attrlist, $attr; + } + } else { + my $rsp; + $rsp->{data}->[0] = + "\'$attr\' is not a valid attribute name for an object type of \'$type\'."; + xCAT::MsgUtils->message("E", $rsp, $::callback); + next; + } + } + } } else { + # get the list of all attrs for this type object # get the data type definition from Schema.pm my $datatype = $xCAT::Schema::defspec{$type};