You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by ma...@redhat.com on 2013/01/31 18:14:42 UTC
[PATCH] CIMI bug - create CIMI db resource with no properties - Fix for DTACLOUD-448
From: marios <ma...@redhat.com>
https://issues.apache.org/jira/browse/DTACLOUD-448
Signed-off-by: marios <ma...@redhat.com>
---
server/lib/cimi/models/address_template.rb | 6 +++---
server/lib/cimi/models/machine_template.rb | 6 +++---
server/lib/cimi/models/volume_configuration.rb | 6 +++---
server/lib/cimi/models/volume_template.rb | 4 ++--
4 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/server/lib/cimi/models/address_template.rb b/server/lib/cimi/models/address_template.rb
index 41d86f6..b804396 100644
--- a/server/lib/cimi/models/address_template.rb
+++ b/server/lib/cimi/models/address_template.rb
@@ -67,7 +67,7 @@ class CIMI::Model::AddressTemplate < CIMI::Model::Base
:dns => json['dns'],
:protocol => json['protocol'],
:mask => json['mask'],
- :ent_properties => json['properties'].to_json
+ :ent_properties => json['properties'] ? json['properties'].to_json : {}
)
from_db(new_template, context)
end
@@ -85,7 +85,7 @@ class CIMI::Model::AddressTemplate < CIMI::Model::Base
:dns => xml['dns'].first,
:protocol => xml['protocol'].nil? ? nil : xml['protocol'].first,
:mask => xml['mask'].first,
- :ent_properties => JSON::dump(xml['property'].inject({}) { |r, p| r[p['key']]=p['content']; r })
+ :ent_properties => xml['property'] ? JSON::dump(xml['property'].inject({}) { |r, p| r[p['key']]=p['content']; r }) : {}
)
from_db(new_template, context)
end
@@ -108,7 +108,7 @@ class CIMI::Model::AddressTemplate < CIMI::Model::Base
:dns => model.dns,
:protocol => model.protocol,
:mask => model.mask,
- :property => JSON::parse(model.ent_properties),
+ :property => (model.ent_properties ? JSON::parse(model.ent_properties) : nil),
:operations => [
{ :href => context.destroy_address_template_url(model.id), :rel => 'http://schemas.dmtf.org/cimi/1/action/delete' }
]
diff --git a/server/lib/cimi/models/machine_template.rb b/server/lib/cimi/models/machine_template.rb
index 32d2c13..5ba9b3e 100644
--- a/server/lib/cimi/models/machine_template.rb
+++ b/server/lib/cimi/models/machine_template.rb
@@ -59,7 +59,7 @@ class CIMI::Model::MachineTemplate < CIMI::Model::Base
:description => json['description'],
:machine_config => json['machineConfig']['href'],
:machine_image => json['machineImage']['href'],
- :ent_properties => json['properties'].to_json
+ :ent_properties => json['properties'] ? json['properties'].to_json : {}
)
from_db(new_template, context)
end
@@ -71,7 +71,7 @@ class CIMI::Model::MachineTemplate < CIMI::Model::Base
:description => xml['description'].first,
:machine_config => xml['machineConfig'].first['href'],
:machine_image => xml['machineImage'].first['href'],
- :ent_properties => JSON::dump(xml['property'].inject({}) { |r, p| r[p['key']]=p['content']; r })
+ :ent_properties => xml['property'] ? JSON::dump(xml['property'].inject({}) { |r, p| r[p['key']]=p['content']; r }) : {}
)
from_db(new_template, context)
end
@@ -89,7 +89,7 @@ class CIMI::Model::MachineTemplate < CIMI::Model::Base
:description => model.description,
:machine_config => { :href => model.machine_config },
:machine_image => { :href => model.machine_image },
- :property => JSON::parse(model.ent_properties),
+ :property => (model.ent_properties ? JSON::parse(model.ent_properties) : nil),
:created => Time.parse(model.created_at.to_s).xmlschema,
:operations => [
{ :href => context.destroy_machine_template_url(model.id), :rel => 'http://schemas.dmtf.org/cimi/1/action/delete' }
diff --git a/server/lib/cimi/models/volume_configuration.rb b/server/lib/cimi/models/volume_configuration.rb
index 9f15635..031ec44 100644
--- a/server/lib/cimi/models/volume_configuration.rb
+++ b/server/lib/cimi/models/volume_configuration.rb
@@ -32,7 +32,7 @@ class CIMI::Model::VolumeConfiguration < CIMI::Model::Base
:description => json['description'],
:format => json['format'],
:capacity => json['capacity'],
- :ent_properties => json['properties'].to_json
+ :ent_properties => json['properties'] ? json['properties'].to_json : {}
)
from_db(new_config, context)
end
@@ -45,7 +45,7 @@ class CIMI::Model::VolumeConfiguration < CIMI::Model::Base
:description => xml['description'].first,
:format => xml['format'].first,
:capacity => xml['capacity'].first,
- :ent_properties => JSON::dump(xml['property'].inject({}) { |r, p| r[p['key']]=p['content']; r })
+ :ent_properties => xml['property'] ? JSON::dump(xml['property'].inject({}) { |r, p| r[p['key']]=p['content']; r }) : {}
)
from_db(new_config, context)
end
@@ -81,7 +81,7 @@ class CIMI::Model::VolumeConfiguration < CIMI::Model::Base
:description => model.description,
:format => model.format,
:capacity => context.to_kibibyte(model.capacity, "GB"),
- :property => JSON::parse(model.ent_properties),
+ :property => (model.ent_properties ? JSON::parse(model.ent_properties) : nil),
:operations => [
{ :href => context.destroy_volume_configuration_url(model.id), :rel => 'http://schemas.dmtf.org/cimi/1/action/delete' }
]
diff --git a/server/lib/cimi/models/volume_template.rb b/server/lib/cimi/models/volume_template.rb
index 3a98128..41d8b92 100644
--- a/server/lib/cimi/models/volume_template.rb
+++ b/server/lib/cimi/models/volume_template.rb
@@ -56,7 +56,7 @@ class CIMI::Model::VolumeTemplate < CIMI::Model::Base
:description => input['description'],
:volume_config => input['volumeConfig']['href'],
:volume_image => vol_image,
- :ent_properties => JSON::dump(input['property'].inject({}) { |r, p| r[p['key']]=p['content']; r })
+ :ent_properties => input['property'] ? JSON::dump(input['property'].inject({}) { |r, p| r[p['key']]=p['content']; r }) : {}
)
from_db(new_template, context)
end
@@ -74,7 +74,7 @@ private
:description => model.description,
:volume_config => {:href => model.volume_config},
:volume_image => {:href => model.volume_image},
- :property => JSON::parse(model.ent_properties),
+ :property => (model.ent_properties ? JSON::parse(model.ent_properties) : nil),
:operations => [
{ :href => context.destroy_volume_template_url(model.id), :rel => 'http://schemas.dmtf.org/cimi/1/action/delete' }
]
--
1.7.11.7
Re: [PATCH] CIMI bug - create CIMI db resource with no properties
- Fix for DTACLOUD-448
Posted by "marios@redhat.com" <ma...@redhat.com>.
On 08/02/13 02:46, David Lutterkort wrote:
> On Thu, 2013-01-31 at 19:14 +0200, marios@redhat.com wrote:
>> diff --git a/server/lib/cimi/models/address_template.rb b/server/lib/cimi/models/address_template.rb
>> index 41d86f6..b804396 100644
>> --- a/server/lib/cimi/models/address_template.rb
>> +++ b/server/lib/cimi/models/address_template.rb
>> @@ -67,7 +67,7 @@ class CIMI::Model::AddressTemplate < CIMI::Model::Base
>> :dns => json['dns'],
>> :protocol => json['protocol'],
>> :mask => json['mask'],
>> - :ent_properties => json['properties'].to_json
>> + :ent_properties => json['properties'] ? json['properties'].to_json : {}
>
> You're assigning either a string or a hash; shouldn't that be
> :ent_properties => (json['properties'] || {}).to_json
>
right thanks - these were already pushed (we need to come up with a way
of relating tracker to list so people know if a patch on list has
already been dealt with)
I made the edits as you suggest and they are at
http://tracker.deltacloud.org/set/305
marios
> Other than that, ACK to the patch - though we should get rid of handling
> json/xml representations directly in favor of XXXCreate models.
>
> David
>
>
Re: [PATCH] CIMI bug - create CIMI db resource with no properties -
Fix for DTACLOUD-448
Posted by David Lutterkort <lu...@redhat.com>.
On Thu, 2013-01-31 at 19:14 +0200, marios@redhat.com wrote:
> diff --git a/server/lib/cimi/models/address_template.rb b/server/lib/cimi/models/address_template.rb
> index 41d86f6..b804396 100644
> --- a/server/lib/cimi/models/address_template.rb
> +++ b/server/lib/cimi/models/address_template.rb
> @@ -67,7 +67,7 @@ class CIMI::Model::AddressTemplate < CIMI::Model::Base
> :dns => json['dns'],
> :protocol => json['protocol'],
> :mask => json['mask'],
> - :ent_properties => json['properties'].to_json
> + :ent_properties => json['properties'] ? json['properties'].to_json : {}
You're assigning either a string or a hash; shouldn't that be
:ent_properties => (json['properties'] || {}).to_json
Other than that, ACK to the patch - though we should get rid of handling
json/xml representations directly in favor of XXXCreate models.
David