deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Koper, Dies" <di...@fast.au.fujitsu.com>
Subject RE: [PATCH core] CIMI: Added more descriptive CIMI schema errors
Date Wed, 27 Mar 2013 02:16:18 GMT
I was able to apply it with:

git config --global apply.whitespace fix
and
git am 0-f7fac9768e02ee3f12386b8fc311311298ee81a2.patch

but the error message hasn't changed:

E, [2013-03-27T12:25:39.949808 #7780] ERROR -- 502:
[Deltacloud::Exceptions::ProviderError] The
CIMI::Model::MachineConfigurationRef must be initialized using Hash or
CIMI::Resource (is #<CIMI::Service::MachineConfiguration:0x408c420
@model=#<CIMI::Model::MachineConfiguration:0x408c2b8 @select_attrs=[],
@base_id="http:
...
followed by tens of pages of unhelpful debugging output.

And commenting out that line in fgcp_driver_cimi_methods.rb still leads
to

> > > E, [2013-03-26T22:54:23.194324 #4960] ERROR -- 500:
[NoMethodError]
> > > undefined method `[]' for nil:NilClass
> > >
d:/sources/OSS/cloud/deltacloud/server/lib/cimi/models/schema.rb:326:in
`to_xml'

Regards,
Dies Koper


> -----Original Message-----
> From: Koper, Dies [mailto:diesk@fast.au.fujitsu.com]
> Sent: Wednesday, 27 March 2013 12:28 AM
> To: dev@deltacloud.apache.org; mfojtik@redhat.com
> Subject: RE: [PATCH core] CIMI: Added more descriptive CIMI schema
errors
> 
> I couldn't get it to apply:
> 
> d:\sources\OSS\cloud\deltacloud\server>git apply
> 0-f7fac9768e02ee3f12386b8fc311311298ee81a2.patch
> server/0-f7fac9768e02ee3f12386b8fc311311298ee81a2.patch:26: trailing
> whitespace.
>         unless values.is_a?(::Hash) or
> values.kind_of?(CIMI::Model::Resource)
> server/0-f7fac9768e02ee3f12386b8fc311311298ee81a2.patch:27: trailing
> whitespace.
>           raise CIMI::Model::Schema::InvalidAttributeValue.new(
> server/0-f7fac9768e02ee3f12386b8fc311311298ee81a2.patch:28: trailing
> whitespace.
>             "The #{self.class} must be initialized using Hash or
> CIMI::Resource (is #{values.inspect})"
> server/0-f7fac9768e02ee3f12386b8fc311311298ee81a2.patch:29: trailing
> whitespace.
>           )
> server/0-f7fac9768e02ee3f12386b8fc311311298ee81a2.patch:30: trailing
> whitespace.
>         end
> fatal: git apply: bad git-diff - expected /dev/null on line 187
> 
> I tried a few things, like apply.whitespace=fix and
> core.whitespace=nowarn, but no luck.
> 
> Regards,
> Dies Koper
> 
> 
> > -----Original Message-----
> > From: Michal Fojtik [mailto:mfojtik@redhat.com]
> > Sent: Tuesday, 26 March 2013 11:54 PM
> > To: dev@deltacloud.apache.org
> > Subject: Re: [PATCH core] CIMI: Added more descriptive CIMI schema
> errors
> >
> > On 03/26/2013 01:10 PM, Koper, Dies wrote:
> >
> > Can you please try: http://tracker.deltacloud.org/set/402 ?
> >
> >    -- Michal
> >
> > > Hi Michal,
> > >
> > > I tried this patch and it gave the following error when I tried to
> > > retrieve system templates from the fgcp:
> > >
> > > E, [2013-03-26T22:51:05.100517 #1940] ERROR -- 502:
> > > [Deltacloud::Exceptions::ProviderError] The
> > > CIMI::Model::MachineConfigurationRef must be initialized using
Hash
> > or
> > > CIMI::Resource (is #<CIMI::Service::MachineConfiguration:0x411ae30
> > > @model=#<CIMI::Model::MachineConfiguration:0x411ad70
> > @select_attrs=[],
> > > @base_id="http:
> > > //localhost:3001/cimi/machine_configurations/economy",
> > >
> >
> > >
> > > Is the return type of MachineConfiguration.find incorrect?
> > > I tried commenting out that line, but that led to the following
> error:
> > >
> > > E, [2013-03-26T22:54:23.194324 #4960] ERROR -- 500:
[NoMethodError]
> > > undefined method `[]' for nil:NilClass
> > >
> > >
> >
> d:/sources/OSS/cloud/deltacloud/server/lib/cimi/models/schema.rb:325
> > :in
> > > `to_xml'
> > >
> >
> d:/sources/OSS/cloud/deltacloud/server/lib/cimi/models/schema.rb:444
> > :in
> > > `block in to_xml'
> > >
> >
> d:/sources/OSS/cloud/deltacloud/server/lib/cimi/models/schema.rb:444
> > :in
> > > `each'
> > >
> >
> d:/sources/OSS/cloud/deltacloud/server/lib/cimi/models/schema.rb:444
> > :in
> > > `to_xml'
> > >
> >
> d:/sources/OSS/cloud/deltacloud/server/lib/cimi/models/schema.rb:158
> > :in
> > > `convert_to_xml'
> > > ...
> > >
> > > Cheers,
> > > Dies Koper
> > >
> > >
> > >> -----Original Message-----
> > >> From: mfojtik@redhat.com [mailto:mfojtik@redhat.com]
> > >> Sent: Friday, 22 March 2013 11:36 PM
> > >> To: dev@deltacloud.apache.org
> > >> Subject: [PATCH core] CIMI: Added more descriptive CIMI schema
> errors
> > >>
> > >> From: Michal Fojtik <mfojtik@redhat.com>
> > >>
> > >> * Wrong attribute values are not reported correctly
> > >>
> > >> Signed-off-by: Michal fojtik <mfojtik@redhat.com>
> > >> ---
> > >>   server/lib/cimi/models/resource.rb     |   5 ++
> > >>   server/lib/cimi/models/schema.rb       |  88
> > +++++++++++++++++---
> > >>   server/tests/cimi/model/errors_spec.rb | 141
> > >> +++++++++++++++++++++++++++++++++
> > >>   3 files changed, 225 insertions(+), 9 deletions(-)
> > >>   create mode 100644 server/tests/cimi/model/errors_spec.rb
> > >>
> > >> diff --git a/server/lib/cimi/models/resource.rb
> > >> b/server/lib/cimi/models/resource.rb
> > >> index 9f5bb66..2b3de42 100644
> > >> --- a/server/lib/cimi/models/resource.rb
> > >> +++ b/server/lib/cimi/models/resource.rb
> > >> @@ -36,6 +36,11 @@ module CIMI
> > >>         #
> > >>         def initialize(values = {})
> > >>           names = self.class.schema.attribute_names
> > >> +        unless values.is_a?(::Hash) or
> > >> values.kind_of?(CIMI::Model::Resource)
> > >> +          raise CIMI::Model::Schema::InvalidAttributeValue.new(
> > >> +            "The #{self.class} must be initialized using Hash or
> > >> CIMI::Resource (is #{values.inspect})"
> > >> +          )
> > >> +        end
> > >>           @select_attrs = values[:select_attr_list] || []
> > >>           # Make sure we always have the :id of the entity even
> > >>           # the $select parameter is used and :id is filtered out
> > >> diff --git a/server/lib/cimi/models/schema.rb
> > >> b/server/lib/cimi/models/schema.rb
> > >> index 5a2049b..3a9d54c 100644
> > >> --- a/server/lib/cimi/models/schema.rb
> > >> +++ b/server/lib/cimi/models/schema.rb
> > >> @@ -19,6 +19,8 @@ require_relative "../../deltacloud/core_ext"
> > >>   # The smarts of converting from XML and JSON into internal
> objects
> > >>   class CIMI::Model::Schema
> > >>
> > >> +  class InvalidAttributeValue < StandardError; end
> > >> +
> > >>     #
> > >>     # Attributes describe how we extract values from XML/JSON
> > >>     #
> > >> @@ -60,6 +62,12 @@ class CIMI::Model::Schema
> > >>       def valid?(value)
> > >>         !value.nil? and !value.to_s.empty?
> > >>       end
> > >> +
> > >> +    def report_error(message)
> > >> +      message = "The `#{@name}` attribute #{message}"
> > >> +      raise
> > CIMI::Model::Schema::InvalidAttributeValue.new(message)
> > >> +    end
> > >> +
> > >>     end
> > >>
> > >>     class Scalar < Attribute
> > >> @@ -190,6 +198,7 @@ class CIMI::Model::Schema
> > >>           @klass = CIMI::Model::const_get(refname)
> > >>         else
> > >>           @klass = Class.new(opts[:class]) do |m|
> > >> +          def initialize(values={}); super(values); end
> > >>             scalar :href
> > >>           end
> > >>           CIMI::Model::const_set(refname, @klass)
> > >> @@ -207,6 +216,39 @@ class CIMI::Model::Schema
> > >>           a.valid?(value.send(a.name))
> > >>         }
> > >>       end
> > >> +
> > >> +    def to_xml(model, xml)
> > >> +      super if valid_ref?(model[name])
> > >> +    end
> > >> +
> > >> +    def to_json(model, json)
> > >> +      super if valid_ref?(model[name])
> > >> +    end
> > >> +
> > >> +    private
> > >> +
> > >> +    def valid_ref?(value)
> > >> +      return true if value.is_a?(::Hash) or
> > >> value.kind_of?(CIMI::Model::Resource) or value.nil?
> > >> +      report_error "must be a Hash or CIMI::Resource (is
> #{value})"
> > >> +    end
> > >> +  end
> > >> +
> > >> +  class Href < CIMI::Model::Schema::Struct
> > >> +
> > >> +    def to_xml(model, xml)
> > >> +      super if valid_href?(model[name])
> > >> +    end
> > >> +
> > >> +    def to_json(model, json)
> > >> +      super if valid_href?(model[name])
> > >> +    end
> > >> +
> > >> +    private
> > >> +
> > >> +    def valid_href?(value)
> > >> +      return true if value.is_a?(::Hash) or value.is_a?(struct)
> or
> > >> value.nil?
> > >> +      report_error "must be a Hash{:href} or Struct#href (is
> > > #{value})"
> > >> +    end
> > >>     end
> > >>
> > >>     class Array < Attribute
> > >> @@ -239,13 +281,25 @@ class CIMI::Model::Schema
> > >>       end
> > >>
> > >>       def to_xml(model, xml)
> > >> -      ary = (model[name] || []).map { |elt|
> > >> @struct.convert_to_xml(elt) }
> > >> -      xml[xml_name] = ary unless ary.empty?
> > >> +      return unless model[name]
> > >> +      if is_valid_array? model[name]
> > >> +        ary = model[name].map { |elt|
@struct.convert_to_xml(elt)
> }
> > >> +        xml[xml_name] = ary unless ary.empty?
> > >> +      end
> > >>       end
> > >>
> > >>       def to_json(model, json)
> > >> -      ary = (model[name] || []).map { |elt|
> > >> @struct.convert_to_json(elt) }
> > >> -      json[json_name] = ary unless ary.empty?
> > >> +      return unless model[name]
> > >> +      if is_valid_array? model[name]
> > >> +        ary = model[name].map { |elt|
@struct.convert_to_json(elt)
> }
> > >> +        json[json_name] = ary unless ary.empty?
> > >> +      end
> > >> +    end
> > >> +
> > >> +    private
> > >> +
> > >> +    def is_valid_array?(value)
> > >> +      value.is_a?(::Array) ? true : report_error('must be a
valid
> > >> Array')
> > >>       end
> > >>     end
> > >>
> > >> @@ -268,15 +322,26 @@ class CIMI::Model::Schema
> > >>       end
> > >>
> > >>       def to_xml(model, xml)
> > >> -      ary = (model[name] || {}).map { |k, v| { "key" => k,
> "content"
> > >> => v } }
> > >> -      xml[xml_name] = ary unless ary.empty?
> > >> +      return unless model[name]
> > >> +      if is_valid_hash? model[name]
> > >> +        ary = (model[name]).map { |k, v| { "key" => k, "content"
> =>
> > v
> > > } }
> > >> +        xml[xml_name] = ary unless ary.empty?
> > >> +      end
> > >>       end
> > >>
> > >>       def to_json(model, json)
> > >> -      if model[name] && ! model[name].empty?
> > >> -        json[json_name] = model[name]
> > >> +      return unless model[name]
> > >> +      if is_valid_hash? model[name]
> > >> +        json[json_name] = model[name] unless model[name].empty?
> > >>         end
> > >>       end
> > >> +
> > >> +    private
> > >> +
> > >> +    def is_valid_hash?(value)
> > >> +      value.is_a?(::Hash) ? true : report_error('must be a valid
> > > Hash')
> > >> +    end
> > >> +
> > >>     end
> > >>
> > >>     class Collection < Attribute
> > >> @@ -413,7 +478,12 @@ class CIMI::Model::Schema
> > >>
> > >>       def href(*args)
> > >>         opts = args.extract_opts!
> > >> -      args.each { |arg| struct(arg, opts) { scalar :href,
> :required
> > > =>
> > >> opts[:required] } }
> > >> +      #args.each { |arg| struct(arg, opts) { scalar :href,
> :required
> > >> => opts[:required] } }
> > >> +      args.each { |arg|
> > >> +        add_attributes!([arg, opts], Href) {
> > >> +          scalar :href, :required => opts[:required]
> > >> +        }
> > >> +      }
> > >>       end
> > >>
> > >>       def text(*args)
> > >> diff --git a/server/tests/cimi/model/errors_spec.rb
> > >> b/server/tests/cimi/model/errors_spec.rb
> > >> new file mode 100644
> > >> index 0000000..fac38fb
> > >> --- /dev/null
> > >> +++ b/server/tests/cimi/model/errors_spec.rb
> > >> @@ -0,0 +1,141 @@
> > >> +# Licensed to the Apache Software Foundation (ASF) under one or
> more
> > >> +# contributor license agreements.  See the NOTICE file
distributed
> > > with
> > >> +# this work for additional information regarding copyright
> ownership.
> > >> The
> > >> +# ASF licenses this file to you under the Apache License,
Version
> > 2.0
> > >> (the
> > >> +# "License"); you may not use this file except in compliance
with
> > the
> > >> +# License.  You may obtain a copy of the License at
> > >> +#
> > >> +#       http://www.apache.org/licenses/LICENSE-2.0
> > >> +#
> > >> +# Unless required by applicable law or agreed to in writing,
> software
> > >> +# distributed under the License is distributed on an "AS IS"
> BASIS,
> > >> WITHOUT
> > >> +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
> > > See
> > >> the
> > >> +# License for the specific language governing permissions and
> > >> limitations
> > >> +# under the License.
> > >> +#
> > >> +require 'rubygems'
> > >> +require 'require_relative' if RUBY_VERSION < '1.9'
> > >> +
> > >> +require_relative '../spec_helper.rb' if require
> 'minitest/autorun'
> > >> +
> > >> +describe 'Schema' do
> > >> +  describe 'Hash attributes' do
> > >> +
> > >> +    it 'should not report error when attribute is set properly'
> do
> > >> +      machine = CIMI::Model::MachineTemplate.new(:property =>
{})
> > >> +      machine.to_xml.must_be_kind_of String
> > >> +      machine.to_json.must_be_kind_of String
> > >> +    end
> > >> +
> > >> +    it 'should not report error when attribute is nil' do
> > >> +      machine = CIMI::Model::MachineTemplate.new(:property =>
> nil)
> > >> +      machine.to_xml.must_be_kind_of String
> > >> +      machine.to_json.must_be_kind_of String
> > >> +    end
> > >> +
> > >> +    it 'should not report error when attribute is not set' do
> > >> +      machine = CIMI::Model::MachineTemplate.new
> > >> +      machine.to_xml.must_be_kind_of String
> > >> +      machine.to_json.must_be_kind_of String
> > >> +    end
> > >> +
> > >> +    it 'should report invalid value for Hash attribute when set
> to
> > >> String' do
> > >> +      machine = CIMI::Model::MachineTemplate.new(:property =>
'')
> > >> +      lambda { machine.to_xml }.must_raise
> > >> CIMI::Model::Schema::InvalidAttributeValue
> > >> +      lambda { machine.to_json }.must_raise
> > >> CIMI::Model::Schema::InvalidAttributeValue
> > >> +    end
> > >> +
> > >> +    it 'should report invalid value for Hash attribute when set
> to
> > > Array'
> > >> do
> > >> +      machine = CIMI::Model::MachineTemplate.new(:property =>
[])
> > >> +      lambda { machine.to_xml }.must_raise
> > >> CIMI::Model::Schema::InvalidAttributeValue
> > >> +      lambda { machine.to_json }.must_raise
> > >> CIMI::Model::Schema::InvalidAttributeValue
> > >> +    end
> > >> +
> > >> +  end
> > >> +
> > >> +  describe 'Array attributes' do
> > >> +
> > >> +    it 'should report invalid value when set to Hash' do
> > >> +      machine = CIMI::Model::MachineTemplate.new(:volumes => {}
)
> > >> +      lambda { machine.to_xml }.must_raise
> > >> CIMI::Model::Schema::InvalidAttributeValue
> > >> +      lambda { machine.to_json }.must_raise
> > >> CIMI::Model::Schema::InvalidAttributeValue
> > >> +    end
> > >> +
> > >> +    it 'should report invalid value when set to String' do
> > >> +      machine = CIMI::Model::MachineTemplate.new(:volumes => ''
)
> > >> +      lambda { machine.to_xml }.must_raise
> > >> CIMI::Model::Schema::InvalidAttributeValue
> > >> +      lambda { machine.to_json }.must_raise
> > >> CIMI::Model::Schema::InvalidAttributeValue
> > >> +    end
> > >> +
> > >> +    it 'should not report error when attribute is set properly'
> do
> > >> +      machine = CIMI::Model::MachineTemplate.new(:volumes => [])
> > >> +      machine.to_xml.must_be_kind_of String
> > >> +      machine.to_json.must_be_kind_of String
> > >> +    end
> > >> +
> > >> +    it 'should not report error when attribute is nil' do
> > >> +      machine = CIMI::Model::MachineTemplate.new(:volumes =>
nil)
> > >> +      machine.to_xml.must_be_kind_of String
> > >> +      machine.to_json.must_be_kind_of String
> > >> +
> > >> +    end
> > >> +
> > >> +    it 'should not report error when attribute is not set' do
> > >> +      machine = CIMI::Model::MachineTemplate.new
> > >> +      machine.to_xml.must_be_kind_of String
> > >> +      machine.to_json.must_be_kind_of String
> > >> +    end
> > >> +  end
> > >> +
> > >> +  describe 'Ref attributes' do
> > >> +
> > >> +    it 'should report error when initialized using Array' do
> > >> +      lambda {
> > >> +        CIMI::Model::MachineTemplate.new(:machine_config => [])
> > >> +      }.must_raise CIMI::Model::Schema::InvalidAttributeValue
> > >> +    end
> > >> +
> > >> +    it 'should report error when initialized using String' do
> > >> +      lambda {
> > >> +        CIMI::Model::MachineTemplate.new(:machine_config => '')
> > >> +      }.must_raise CIMI::Model::Schema::InvalidAttributeValue
> > >> +    end
> > >> +
> > >> +    it 'could be initialized by the Hash value' do
> > >> +      machine = CIMI::Model::MachineTemplate.new(:machine_config
> > =>
> > >> { :href => 'http://localhost/1' })
> > >> +      machine.machine_config.must_be_instance_of
> > >> CIMI::Model::MachineConfigurationRef
> > >> +      machine.machine_config.href.must_equal
> 'http://localhost/1'
> > >> +      machine.to_xml.must_be_instance_of String
> > >> +      machine.to_json.must_be_instance_of String
> > >> +    end
> > >> +
> > >> +    it 'could be initialized by the Ref value' do
> > >> +      machine = CIMI::Model::MachineTemplate.new(:machine_config
> > =>
> > >> CIMI::Model::MachineConfigurationRef.new(:href =>
> > >> 'http://localhost/1'))
> > >> +      machine.machine_config.must_be_instance_of
> > >> CIMI::Model::MachineConfigurationRef
> > >> +      machine.machine_config.href.must_equal
> 'http://localhost/1'
> > >> +      machine.to_xml.must_be_instance_of String
> > >> +      machine.to_json.must_be_instance_of String
> > >> +    end
> > >> +
> > >> +  end
> > >> +
> > >> +  describe 'Href attributes' do
> > >> +
> > >> +    it 'should report error when value is not a Hash' do
> > >> +      machine = CIMI::Model::Machine.new(:machine_image => '')
> > >> +      lambda {
> > >> +        machine.to_xml
> > >> +      }.must_raise CIMI::Model::Schema::InvalidAttributeValue
> > >> +      lambda {
> > >> +        machine.to_json
> > >> +      }.must_raise CIMI::Model::Schema::InvalidAttributeValue
> > >> +    end
> > >> +
> > >> +    it 'should not report error when initialized correctly' do
> > >> +      machine = CIMI::Model::Machine.new( :machine_image => {
> :href
> > > =>
> > >> 'test' })
> > >> +      machine.to_xml.must_be_instance_of String
> > >> +      machine.to_json.must_be_instance_of String
> > >> +    end
> > >> +  end
> > >> +
> > >> +end
> > >> --
> > >> 1.8.1.4
> > >>
> > >
> > >
> >
> >
> > --
> >
> > Michal Fojtik <mfojtik@redhat.com>
> > Deltacloud API, CloudForms
> 
> 



Mime
View raw message