You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2011/11/16 21:34:29 UTC
CIMI: Fixed various inconsistencies between JSON and XML samples and revampled specs
Hi,
Thanks David for review and suggestion to move all assertions to single helper
in order to check sanity between JSON->XML and vice versa serializations.
Also I fixed various typos in XML and JSON samples and fixed wrong property
types in MachineImage and MachineConfiguration model.
I'll continue tomorrow with improving spec files (add more check but keep it DRY
as possible).
-- Michal
Re: [PATCH core 1/4] CIMI: Added helper methods to check serialization
and inconsistencies between JSON and XML
Posted by "marios@redhat.com" <ma...@redhat.com>.
ACK
On 16/11/11 22:34, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
>
> ---
> server/spec/spec_helper.rb | 10 ++++++++++
> 1 files changed, 10 insertions(+), 0 deletions(-)
>
> diff --git a/server/spec/spec_helper.rb b/server/spec/spec_helper.rb
> index d046260..c8b41fc 100644
> --- a/server/spec/spec_helper.rb
> +++ b/server/spec/spec_helper.rb
> @@ -90,6 +90,16 @@ class HashCmp
> end
> end
>
> +def should_serialize_from_xml!(model, xml, json)
> + model.to_xml.should serialize_to xml, :fmt => :xml
> + model.to_json.should serialize_to json, :fmt => :json
> +end
> +
> +def should_serialize_from_json!(model, xml, json)
> + model.to_xml.should serialize_to xml, :fmt => :xml
> + model.to_json.should serialize_to json, :fmt => :json
> +end
> +
> RSpec::Matchers.define :serialize_to do |exp, opts|
> match do |act|
> matcher(exp, act, opts[:fmt]).match?
Re: [PATCH core 1/4] CIMI: Added helper methods to check
serialization and inconsistencies between JSON and XML
Posted by David Lutterkort <lu...@redhat.com>.
On Wed, 2011-11-16 at 21:34 +0100, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
>
> ---
> server/spec/spec_helper.rb | 10 ++++++++++
> 1 files changed, 10 insertions(+), 0 deletions(-)
>
> diff --git a/server/spec/spec_helper.rb b/server/spec/spec_helper.rb
> index d046260..c8b41fc 100644
> --- a/server/spec/spec_helper.rb
> +++ b/server/spec/spec_helper.rb
> @@ -90,6 +90,16 @@ class HashCmp
> end
> end
>
> +def should_serialize_from_xml!(model, xml, json)
> + model.to_xml.should serialize_to xml, :fmt => :xml
> + model.to_json.should serialize_to json, :fmt => :json
> +end
> +
> +def should_serialize_from_json!(model, xml, json)
> + model.to_xml.should serialize_to xml, :fmt => :xml
> + model.to_json.should serialize_to json, :fmt => :json
> +end
Aren't these two methods doing exactly the same ? What I had in mind was
def check_serialization(model_class, xml, json)
# Roundtrip in same format
model_class.from_xml(xml).should serialize_to xml, :fmt
=> :xml
model_class.from_json(json).should serialize_to json, :fmt => :json
# Roundtrip crossing format
model_class.from_xml(xml).should serialize_to json, :fmt
=> :json
model_class.from_json(json).should serialize_to xml, :fmt
=> :xml
end
David
[PATCH core 1/4] CIMI: Added helper methods to check serialization and inconsistencies between JSON and XML
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
---
server/spec/spec_helper.rb | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/server/spec/spec_helper.rb b/server/spec/spec_helper.rb
index d046260..c8b41fc 100644
--- a/server/spec/spec_helper.rb
+++ b/server/spec/spec_helper.rb
@@ -90,6 +90,16 @@ class HashCmp
end
end
+def should_serialize_from_xml!(model, xml, json)
+ model.to_xml.should serialize_to xml, :fmt => :xml
+ model.to_json.should serialize_to json, :fmt => :json
+end
+
+def should_serialize_from_json!(model, xml, json)
+ model.to_xml.should serialize_to xml, :fmt => :xml
+ model.to_json.should serialize_to json, :fmt => :json
+end
+
RSpec::Matchers.define :serialize_to do |exp, opts|
match do |act|
matcher(exp, act, opts[:fmt]).match?
--
1.7.7.3
Re: [PATCH core 4/4] CIMI: Revampled spec files once again to use
the helpers for checking sanity of serialization
Posted by Michal Fojtik <mf...@redhat.com>.
Thanks! Fixed MachineConfig data to match with latest WIP and pushed.
-- Michal
marios@redhat.com wrote:
> ACK
>
> On 16/11/11 22:34, mfojtik@redhat.com wrote:
>> From: Michal Fojtik <mf...@redhat.com>
>>
>> ---
>> .../spec/cimi/model/machine_configuration_spec.rb | 99 ++------------
>> server/spec/cimi/model/machine_image_spec.rb | 82 +----------
>> server/spec/cimi/model/machine_template_spec.rb | 152 +------------------
>> 3 files changed, 25 insertions(+), 308 deletions(-)
>>
>> diff --git a/server/spec/cimi/model/machine_configuration_spec.rb b/server/spec/cimi/model/machine_configuration_spec.rb
>> index d60286e..454e8c4 100644
>> --- a/server/spec/cimi/model/machine_configuration_spec.rb
>> +++ b/server/spec/cimi/model/machine_configuration_spec.rb
>> @@ -20,97 +20,16 @@ describe "MachineConfiguration model" do
>> @json = IO::read(File::join(DATA_DIR, "machine_configuration.json"))
>> end
>>
>> - describe 'XML' do
>> - it "can be constructed" do
>> - conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
>> - conf.should_not be_nil
>> - conf.should serialize_to @xml, :fmt => :xml
>> - end
>> -
>> - it "should convert strings in keys to symbols when contructed from XML" do
>> - conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
>> - conf.should_not be_nil
>> - conf.attribute_values.keys.each { |key| key.should be_a(Symbol) }
>> - end
>> -
>> - it "should have default properties" do
>> - conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
>> - conf.name.should == 'MachineConfiguration1'
>> - conf.uri == 'http://cimi.example.org/machine_configurations/1'
>> - conf.description == 'Example MachineConfiguration One'
>> - conf.created.should == "2011-11-14"
>> - end
>> -
>> - it "should have cpu and memory properties" do
>> - conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
>> - conf.cpu.should == "2"
>> - conf.memory.should be_an_instance_of Hash
>> - conf.memory['quantity'].should == '1'
>> - conf.memory['units'].should == 'gigabyte'
>> - end
>> -
>> - it "should have disk array property with capacity" do
>> - conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
>> - conf.disk.size.should == 1
>> - conf.disk[0].respond_to?(:capacity).should be_true
>> - conf.disk[0].capacity.size.should == 1
>> - conf.disk[0].capacity[0]['format'] == 'ext4'
>> - conf.disk[0].capacity[0]['quantity'] == '1'
>> - conf.disk[0].capacity[0]['attachmentPoint'] == '/'
>> - conf.disk[0].capacity[0]['units'] == 'terabyte'
>> - end
>> -
>> - it "should have edit and delete operations" do
>> - conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
>> - conf.operations.size.should == 2
>> - conf.operations.any? { |operation| operation.rel == 'edit' }.should be_true
>> - conf.operations.any? { |operation| operation.rel == 'delete' }.should be_true
>> - conf.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
>> - end
>> + it "can be constructed from XML" do
>> + conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
>> + conf.should_not be_nil
>> + should_serialize_from_xml! conf, @xml, @json
>> end
>>
>> - describe "JSON" do
>> - it "can be constructed" do
>> - conf = CIMI::Model::MachineConfiguration.from_json(@json)
>> - conf.should_not be_nil
>> - conf.should serialize_to @json, :fmt => :json
>> - end
>> -
>> - it "should have default properties" do
>> - conf = CIMI::Model::MachineConfiguration.from_json(@json)
>> - conf.name.should == 'MachineConfiguration1'
>> - conf.uri == 'http://cimi.example.org/machine_configurations/1'
>> - conf.description == 'Example MachineConfiguration One'
>> - conf.created.should == "2011-11-14"
>> - end
>> -
>> - it "should have cpu and memory properties" do
>> - conf = CIMI::Model::MachineConfiguration.from_json(@json)
>> - conf.cpu.should == "2"
>> - conf.memory.should be_an_instance_of Hash
>> - conf.memory['quantity'].should == '1'
>> - conf.memory['units'].should == 'gigabyte'
>> - end
>> -
>> - it "should have disk array property with capacity" do
>> - conf = CIMI::Model::MachineConfiguration.from_json(@json)
>> - conf.disk.should be_an_instance_of Array
>> - conf.disk.size.should > 0
>> - conf.disk[0].should respond_to :capacity
>> - conf.disk[0].capacity.size.should == 1
>> - conf.disk[0].capacity[0]['format'] == 'ext4'
>> - conf.disk[0].capacity[0]['quantity'] == '1'
>> - conf.disk[0].capacity[0]['attachmentPoint'] == '/'
>> - conf.disk[0].capacity[0]['units'] == 'terabyte'
>> - end
>> -
>> - it "should have edit and delete operations" do
>> - conf = CIMI::Model::MachineConfiguration.from_json(@json)
>> - conf.operations.size.should == 2
>> - conf.operations.any? { |operation| operation.rel == 'edit' }.should be_true
>> - conf.operations.any? { |operation| operation.rel == 'delete' }.should be_true
>> - conf.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
>> - end
>> -
>> + it "can be constructed from JSON" do
>> + conf = CIMI::Model::MachineConfiguration.from_json(@json)
>> + conf.should_not be_nil
>> + should_serialize_from_json! conf, @xml, @json
>> end
>> +
>> end
>> diff --git a/server/spec/cimi/model/machine_image_spec.rb b/server/spec/cimi/model/machine_image_spec.rb
>> index 517769a..824d032 100644
>> --- a/server/spec/cimi/model/machine_image_spec.rb
>> +++ b/server/spec/cimi/model/machine_image_spec.rb
>> @@ -21,82 +21,16 @@ describe "MachineImage model" do
>> @json = IO::read(File::join(DATA_DIR, "machine_image.json"))
>> end
>>
>> - describe "XML" do
>> - it "can be constructed" do
>> - img = CIMI::Model::MachineImage.from_xml(@xml)
>> - img.should_not be_nil
>> - img.should serialize_to @xml, :fmt => :xml
>> - end
>> -
>> - it "should have default properties" do
>> - img = CIMI::Model::MachineImage.from_xml(@xml)
>> - img.uri.should == "http://cimi.example.org/machine_image/1"
>> - img.name.should == "img1"
>> - img.description.should == "Machine Image One"
>> - img.created.should == "2011-11-14"
>> - end
>> -
>> - it "should have image location property" do
>> - img = CIMI::Model::MachineImage.from_xml(@xml)
>> - img.image_location.should be_an_instance_of Hash
>> - img.image_location['href'].should == 'nfs://cimi.example.com/images/1.img'
>> - end
>> -
>> - it "should have edit and delete operations" do
>> - img = CIMI::Model::MachineImage.from_xml(@xml)
>> - img.operations.any? { |operation| operation.rel == 'edit' }.should be_true
>> - img.operations.any? { |operation| operation.rel == 'delete' }.should be_true
>> - img.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
>> - end
>> -
>> - it "should parse properties correctly in XML" do
>> - img = CIMI::Model::MachineImage.from_xml(@xml)
>> - img.property.any? { |p| p.name == 'status' }.should be_true
>> - img.property.any? { |p| p.name == 'locked' }.should be_true
>> - img.property.size.should == 2
>> - end
>> -
>> - it "should convert strings in keys to symbols when contructed from XML" do
>> - imgl = CIMI::Model::MachineImage.from_xml(@xml)
>> - imgl.should_not be_nil
>> - imgl.attribute_values.keys.each { |key| key.should be_a_kind_of(Symbol) }
>> - end
>> + it "can be constructed from XML" do
>> + conf = CIMI::Model::MachineImage.from_xml(@xml)
>> + conf.should_not be_nil
>> + should_serialize_from_xml! conf, @xml, @json
>> end
>>
>> - describe 'JSON' do
>> - it "can be constructed" do
>> - img = CIMI::Model::MachineImage.from_json(@json)
>> - img.should_not be_nil
>> - img.should serialize_to @json, :fmt => :json
>> - end
>> -
>> - it "should have default properties" do
>> - img = CIMI::Model::MachineImage.from_json(@json)
>> - img.uri.should == "http://cimi.example.org/machine_images/1"
>> - img.name.should == "img1"
>> - img.description.should == "Machine Image One"
>> - img.created.should == "2011-11-14"
>> - end
>> -
>> - it "should have image location property" do
>> - img = CIMI::Model::MachineImage.from_json(@json)
>> - img.image_location.should be_an_instance_of Hash
>> - img.image_location['href'].should == 'nfs://cimi.example.com/images/1.img'
>> - end
>> -
>> - it "should have edit and delete operations" do
>> - img = CIMI::Model::MachineImage.from_json(@json)
>> - img.operations.any? { |operation| operation.rel == 'edit' }.should be_true
>> - img.operations.any? { |operation| operation.rel == 'delete' }.should be_true
>> - img.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
>> - end
>> -
>> - it "should parse properties correctly in XML" do
>> - img = CIMI::Model::MachineImage.from_json(@json)
>> - img.property.any? { |p| p.name == 'status' }.should be_true
>> - img.property.any? { |p| p.name == 'locked' }.should be_true
>> - img.property.size.should == 2
>> - end
>> + it "can be constructed from JSON" do
>> + conf = CIMI::Model::MachineImage.from_json(@json)
>> + conf.should_not be_nil
>> + should_serialize_from_json! conf, @xml, @json
>> end
>>
>> end
>> diff --git a/server/spec/cimi/model/machine_template_spec.rb b/server/spec/cimi/model/machine_template_spec.rb
>> index 8ccd9ae..0c6f50a 100644
>> --- a/server/spec/cimi/model/machine_template_spec.rb
>> +++ b/server/spec/cimi/model/machine_template_spec.rb
>> @@ -20,152 +20,16 @@ describe "MachineTemplate model" do
>> @json = IO::read(File::join(DATA_DIR, "machine_template.json"))
>> end
>>
>> - describe 'XML' do
>> - it "can be constructed" do
>> - templ = CIMI::Model::MachineTemplate.from_xml(@xml)
>> - templ.should_not be_nil
>> - templ.should serialize_to @xml, :fmt => :xml
>> - end
>> -
>> - it "should have default properties" do
>> - templ = CIMI::Model::MachineTemplate.from_xml(@xml)
>> - templ.created.should == "2011-11-01"
>> - templ.name.should == "My First Template"
>> - templ.description.should == "A template for testing"
>> - templ.uri.should == "http://cimi.example.org/machine_templates/1"
>> - end
>> -
>> - it "should convert strings in keys to symbols when contructed from XML" do
>> - templ = CIMI::Model::MachineTemplate.from_xml(@xml)
>> - templ.should_not be_nil
>> - templ.attribute_values.keys.each { |key| key.should be_a_kind_of(Symbol) }
>> - end
>> -
>> - it "should reference machine_config" do
>> - templ = CIMI::Model::MachineTemplate.from_xml(@xml)
>> - templ.machine_config.should be_an_instance_of Struct::CIMI_MachineConfig
>> - templ.machine_config.href.should == "http://cimi.example.org/machine_configs/1"
>> - end
>> -
>> - it "should reference machine_image" do
>> - templ = CIMI::Model::MachineTemplate.from_xml(@xml)
>> - templ.machine_image.should be_an_instance_of Struct::CIMI_MachineImage
>> - templ.machine_image.href.should == "http://cimi.example.org/machine_images/1"
>> - end
>> -
>> - it "should have list of attached volumes" do
>> - templ = CIMI::Model::MachineTemplate.from_xml(@xml)
>> - templ.volumes.should be_a_kind_of Array
>> - templ.volumes.each do |volume|
>> - volume.href.should =~ /^http:\/\/.*\/volumes\/(\w+)$/
>> - volume.protocol.should == 'nfs'
>> - volume.attachment_point == '/dev/sda'
>> - volume.should be_an_instance_of Struct::CIMI_Volume
>> - end
>> - end
>> -
>> - it "should have list of network interfaces" do
>> - templ = CIMI::Model::MachineTemplate.from_xml(@xml)
>> - templ.network_interfaces.should be_an_instance_of Array
>> - templ.network_interfaces.each do |interface|
>> - interface.hostname == 'host.cimi.example.org'
>> - interface.mac_address == '00:11:22:33:44:55'
>> - interface.state == 'UP'
>> - interface.protocol == 'TCP'
>> - interface.allocation == 'static'
>> - interface.address == '192.168.0.17'
>> - interface.default_gateway == '192.168.0.1'
>> - interface.dns == '192.168.0.1'
>> - interface.max_transmission_unit == '1500'
>> - interface.vsp.should_not be_nil
>> - interface.vsp.should be_an_instance_of Struct::CIMI_Vsp
>> - interface.vsp.href.should =~ /^http:\/\/.*\/vsps\/(\w+)$/
>> - interface.should be_an_instance_of Struct::CIMI_NetworkInterface
>> - end
>> - end
>> -
>> - it "should have edit and delete operations" do
>> - templ = CIMI::Model::MachineTemplate.from_xml(@xml)
>> - templ.operations.size.should == 2
>> - templ.operations.any? { |operation| operation.rel == 'edit' }.should be_true
>> - templ.operations.any? { |operation| operation.rel == 'delete' }.should be_true
>> - templ.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
>> - end
>> -
>> + it "can be constructed from XML" do
>> + conf = CIMI::Model::MachineTemplate.from_xml(@xml)
>> + conf.should_not be_nil
>> + should_serialize_from_xml! conf, @xml, @json
>> end
>>
>> - describe 'JSON' do
>> - it "can be constructed" do
>> - templ = CIMI::Model::MachineTemplate.from_json(@json)
>> - templ.should_not be_nil
>> - templ.should serialize_to @xml, :fmt => :xml
>> - end
>> -
>> - it "should have default properties" do
>> - templ = CIMI::Model::MachineTemplate.from_json(@json)
>> - templ.created.should == "2011-11-01"
>> - templ.name.should == "My First Template"
>> - templ.description.should == "A template for testing"
>> - templ.uri.should == "http://cimi.example.org/machine_templates/1"
>> - end
>> -
>> - it "should convert strings in keys to symbols when contructed from XML" do
>> - templ = CIMI::Model::MachineTemplate.from_json(@json)
>> - templ.should_not be_nil
>> - templ.attribute_values.keys.each { |key| key.should be_a_kind_of(Symbol) }
>> - end
>> -
>> - it "should reference machine_config" do
>> - templ = CIMI::Model::MachineTemplate.from_json(@json)
>> - templ.machine_config.should be_an_instance_of Struct::CIMI_MachineConfig
>> - templ.machine_config.href.should == "http://cimi.example.org/machine_configs/1"
>> - end
>> -
>> - it "should reference machine_image" do
>> - templ = CIMI::Model::MachineTemplate.from_json(@json)
>> - templ.machine_image.should be_an_instance_of Struct::CIMI_MachineImage
>> - templ.machine_image.href.should == "http://cimi.example.org/machine_images/1"
>> - end
>> -
>> - it "should have list of attached volumes" do
>> - templ = CIMI::Model::MachineTemplate.from_json(@json)
>> - templ.volumes.should be_a_kind_of Array
>> - templ.volumes.each do |volume|
>> - volume.href.should =~ /^http:\/\/.*\/volumes\/(\w+)$/
>> - volume.protocol.should == 'nfs'
>> - volume.attachment_point == '/dev/sda'
>> - volume.should be_an_instance_of Struct::CIMI_Volume
>> - end
>> - end
>> -
>> - it "should have list of network interfaces" do
>> - templ = CIMI::Model::MachineTemplate.from_json(@json)
>> - templ.network_interfaces.should be_an_instance_of Array
>> - templ.network_interfaces.each do |interface|
>> - interface.hostname == 'host.cimi.example.org'
>> - interface.mac_address == '00:11:22:33:44:55'
>> - interface.state == 'UP'
>> - interface.protocol == 'TCP'
>> - interface.allocation == 'static'
>> - interface.address == '192.168.0.17'
>> - interface.default_gateway == '192.168.0.1'
>> - interface.dns == '192.168.0.1'
>> - interface.max_transmission_unit == '1500'
>> - interface.vsp.should_not be_nil
>> - interface.vsp.should be_an_instance_of Struct::CIMI_Vsp
>> - interface.vsp.href.should =~ /^http:\/\/.*\/vsps\/(\w+)$/
>> - interface.should be_an_instance_of Struct::CIMI_NetworkInterface
>> - end
>> - end
>> -
>> - it "should have edit and delete operations" do
>> - templ = CIMI::Model::MachineTemplate.from_json(@json)
>> - templ.operations.size.should == 2
>> - templ.operations.any? { |operation| operation.rel == 'edit' }.should be_true
>> - templ.operations.any? { |operation| operation.rel == 'delete' }.should be_true
>> - templ.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
>> - end
>> -
>> + it "can be constructed from JSON" do
>> + conf = CIMI::Model::MachineTemplate.from_json(@json)
>> + conf.should_not be_nil
>> + should_serialize_from_json! conf, @xml, @json
>> end
>>
>> end
>
Re: [PATCH core 4/4] CIMI: Revampled spec files once again to use
the helpers for checking sanity of serialization
Posted by "marios@redhat.com" <ma...@redhat.com>.
ACK
On 16/11/11 22:34, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
>
> ---
> .../spec/cimi/model/machine_configuration_spec.rb | 99 ++------------
> server/spec/cimi/model/machine_image_spec.rb | 82 +----------
> server/spec/cimi/model/machine_template_spec.rb | 152 +------------------
> 3 files changed, 25 insertions(+), 308 deletions(-)
>
> diff --git a/server/spec/cimi/model/machine_configuration_spec.rb b/server/spec/cimi/model/machine_configuration_spec.rb
> index d60286e..454e8c4 100644
> --- a/server/spec/cimi/model/machine_configuration_spec.rb
> +++ b/server/spec/cimi/model/machine_configuration_spec.rb
> @@ -20,97 +20,16 @@ describe "MachineConfiguration model" do
> @json = IO::read(File::join(DATA_DIR, "machine_configuration.json"))
> end
>
> - describe 'XML' do
> - it "can be constructed" do
> - conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
> - conf.should_not be_nil
> - conf.should serialize_to @xml, :fmt => :xml
> - end
> -
> - it "should convert strings in keys to symbols when contructed from XML" do
> - conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
> - conf.should_not be_nil
> - conf.attribute_values.keys.each { |key| key.should be_a(Symbol) }
> - end
> -
> - it "should have default properties" do
> - conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
> - conf.name.should == 'MachineConfiguration1'
> - conf.uri == 'http://cimi.example.org/machine_configurations/1'
> - conf.description == 'Example MachineConfiguration One'
> - conf.created.should == "2011-11-14"
> - end
> -
> - it "should have cpu and memory properties" do
> - conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
> - conf.cpu.should == "2"
> - conf.memory.should be_an_instance_of Hash
> - conf.memory['quantity'].should == '1'
> - conf.memory['units'].should == 'gigabyte'
> - end
> -
> - it "should have disk array property with capacity" do
> - conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
> - conf.disk.size.should == 1
> - conf.disk[0].respond_to?(:capacity).should be_true
> - conf.disk[0].capacity.size.should == 1
> - conf.disk[0].capacity[0]['format'] == 'ext4'
> - conf.disk[0].capacity[0]['quantity'] == '1'
> - conf.disk[0].capacity[0]['attachmentPoint'] == '/'
> - conf.disk[0].capacity[0]['units'] == 'terabyte'
> - end
> -
> - it "should have edit and delete operations" do
> - conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
> - conf.operations.size.should == 2
> - conf.operations.any? { |operation| operation.rel == 'edit' }.should be_true
> - conf.operations.any? { |operation| operation.rel == 'delete' }.should be_true
> - conf.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
> - end
> + it "can be constructed from XML" do
> + conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
> + conf.should_not be_nil
> + should_serialize_from_xml! conf, @xml, @json
> end
>
> - describe "JSON" do
> - it "can be constructed" do
> - conf = CIMI::Model::MachineConfiguration.from_json(@json)
> - conf.should_not be_nil
> - conf.should serialize_to @json, :fmt => :json
> - end
> -
> - it "should have default properties" do
> - conf = CIMI::Model::MachineConfiguration.from_json(@json)
> - conf.name.should == 'MachineConfiguration1'
> - conf.uri == 'http://cimi.example.org/machine_configurations/1'
> - conf.description == 'Example MachineConfiguration One'
> - conf.created.should == "2011-11-14"
> - end
> -
> - it "should have cpu and memory properties" do
> - conf = CIMI::Model::MachineConfiguration.from_json(@json)
> - conf.cpu.should == "2"
> - conf.memory.should be_an_instance_of Hash
> - conf.memory['quantity'].should == '1'
> - conf.memory['units'].should == 'gigabyte'
> - end
> -
> - it "should have disk array property with capacity" do
> - conf = CIMI::Model::MachineConfiguration.from_json(@json)
> - conf.disk.should be_an_instance_of Array
> - conf.disk.size.should > 0
> - conf.disk[0].should respond_to :capacity
> - conf.disk[0].capacity.size.should == 1
> - conf.disk[0].capacity[0]['format'] == 'ext4'
> - conf.disk[0].capacity[0]['quantity'] == '1'
> - conf.disk[0].capacity[0]['attachmentPoint'] == '/'
> - conf.disk[0].capacity[0]['units'] == 'terabyte'
> - end
> -
> - it "should have edit and delete operations" do
> - conf = CIMI::Model::MachineConfiguration.from_json(@json)
> - conf.operations.size.should == 2
> - conf.operations.any? { |operation| operation.rel == 'edit' }.should be_true
> - conf.operations.any? { |operation| operation.rel == 'delete' }.should be_true
> - conf.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
> - end
> -
> + it "can be constructed from JSON" do
> + conf = CIMI::Model::MachineConfiguration.from_json(@json)
> + conf.should_not be_nil
> + should_serialize_from_json! conf, @xml, @json
> end
> +
> end
> diff --git a/server/spec/cimi/model/machine_image_spec.rb b/server/spec/cimi/model/machine_image_spec.rb
> index 517769a..824d032 100644
> --- a/server/spec/cimi/model/machine_image_spec.rb
> +++ b/server/spec/cimi/model/machine_image_spec.rb
> @@ -21,82 +21,16 @@ describe "MachineImage model" do
> @json = IO::read(File::join(DATA_DIR, "machine_image.json"))
> end
>
> - describe "XML" do
> - it "can be constructed" do
> - img = CIMI::Model::MachineImage.from_xml(@xml)
> - img.should_not be_nil
> - img.should serialize_to @xml, :fmt => :xml
> - end
> -
> - it "should have default properties" do
> - img = CIMI::Model::MachineImage.from_xml(@xml)
> - img.uri.should == "http://cimi.example.org/machine_image/1"
> - img.name.should == "img1"
> - img.description.should == "Machine Image One"
> - img.created.should == "2011-11-14"
> - end
> -
> - it "should have image location property" do
> - img = CIMI::Model::MachineImage.from_xml(@xml)
> - img.image_location.should be_an_instance_of Hash
> - img.image_location['href'].should == 'nfs://cimi.example.com/images/1.img'
> - end
> -
> - it "should have edit and delete operations" do
> - img = CIMI::Model::MachineImage.from_xml(@xml)
> - img.operations.any? { |operation| operation.rel == 'edit' }.should be_true
> - img.operations.any? { |operation| operation.rel == 'delete' }.should be_true
> - img.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
> - end
> -
> - it "should parse properties correctly in XML" do
> - img = CIMI::Model::MachineImage.from_xml(@xml)
> - img.property.any? { |p| p.name == 'status' }.should be_true
> - img.property.any? { |p| p.name == 'locked' }.should be_true
> - img.property.size.should == 2
> - end
> -
> - it "should convert strings in keys to symbols when contructed from XML" do
> - imgl = CIMI::Model::MachineImage.from_xml(@xml)
> - imgl.should_not be_nil
> - imgl.attribute_values.keys.each { |key| key.should be_a_kind_of(Symbol) }
> - end
> + it "can be constructed from XML" do
> + conf = CIMI::Model::MachineImage.from_xml(@xml)
> + conf.should_not be_nil
> + should_serialize_from_xml! conf, @xml, @json
> end
>
> - describe 'JSON' do
> - it "can be constructed" do
> - img = CIMI::Model::MachineImage.from_json(@json)
> - img.should_not be_nil
> - img.should serialize_to @json, :fmt => :json
> - end
> -
> - it "should have default properties" do
> - img = CIMI::Model::MachineImage.from_json(@json)
> - img.uri.should == "http://cimi.example.org/machine_images/1"
> - img.name.should == "img1"
> - img.description.should == "Machine Image One"
> - img.created.should == "2011-11-14"
> - end
> -
> - it "should have image location property" do
> - img = CIMI::Model::MachineImage.from_json(@json)
> - img.image_location.should be_an_instance_of Hash
> - img.image_location['href'].should == 'nfs://cimi.example.com/images/1.img'
> - end
> -
> - it "should have edit and delete operations" do
> - img = CIMI::Model::MachineImage.from_json(@json)
> - img.operations.any? { |operation| operation.rel == 'edit' }.should be_true
> - img.operations.any? { |operation| operation.rel == 'delete' }.should be_true
> - img.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
> - end
> -
> - it "should parse properties correctly in XML" do
> - img = CIMI::Model::MachineImage.from_json(@json)
> - img.property.any? { |p| p.name == 'status' }.should be_true
> - img.property.any? { |p| p.name == 'locked' }.should be_true
> - img.property.size.should == 2
> - end
> + it "can be constructed from JSON" do
> + conf = CIMI::Model::MachineImage.from_json(@json)
> + conf.should_not be_nil
> + should_serialize_from_json! conf, @xml, @json
> end
>
> end
> diff --git a/server/spec/cimi/model/machine_template_spec.rb b/server/spec/cimi/model/machine_template_spec.rb
> index 8ccd9ae..0c6f50a 100644
> --- a/server/spec/cimi/model/machine_template_spec.rb
> +++ b/server/spec/cimi/model/machine_template_spec.rb
> @@ -20,152 +20,16 @@ describe "MachineTemplate model" do
> @json = IO::read(File::join(DATA_DIR, "machine_template.json"))
> end
>
> - describe 'XML' do
> - it "can be constructed" do
> - templ = CIMI::Model::MachineTemplate.from_xml(@xml)
> - templ.should_not be_nil
> - templ.should serialize_to @xml, :fmt => :xml
> - end
> -
> - it "should have default properties" do
> - templ = CIMI::Model::MachineTemplate.from_xml(@xml)
> - templ.created.should == "2011-11-01"
> - templ.name.should == "My First Template"
> - templ.description.should == "A template for testing"
> - templ.uri.should == "http://cimi.example.org/machine_templates/1"
> - end
> -
> - it "should convert strings in keys to symbols when contructed from XML" do
> - templ = CIMI::Model::MachineTemplate.from_xml(@xml)
> - templ.should_not be_nil
> - templ.attribute_values.keys.each { |key| key.should be_a_kind_of(Symbol) }
> - end
> -
> - it "should reference machine_config" do
> - templ = CIMI::Model::MachineTemplate.from_xml(@xml)
> - templ.machine_config.should be_an_instance_of Struct::CIMI_MachineConfig
> - templ.machine_config.href.should == "http://cimi.example.org/machine_configs/1"
> - end
> -
> - it "should reference machine_image" do
> - templ = CIMI::Model::MachineTemplate.from_xml(@xml)
> - templ.machine_image.should be_an_instance_of Struct::CIMI_MachineImage
> - templ.machine_image.href.should == "http://cimi.example.org/machine_images/1"
> - end
> -
> - it "should have list of attached volumes" do
> - templ = CIMI::Model::MachineTemplate.from_xml(@xml)
> - templ.volumes.should be_a_kind_of Array
> - templ.volumes.each do |volume|
> - volume.href.should =~ /^http:\/\/.*\/volumes\/(\w+)$/
> - volume.protocol.should == 'nfs'
> - volume.attachment_point == '/dev/sda'
> - volume.should be_an_instance_of Struct::CIMI_Volume
> - end
> - end
> -
> - it "should have list of network interfaces" do
> - templ = CIMI::Model::MachineTemplate.from_xml(@xml)
> - templ.network_interfaces.should be_an_instance_of Array
> - templ.network_interfaces.each do |interface|
> - interface.hostname == 'host.cimi.example.org'
> - interface.mac_address == '00:11:22:33:44:55'
> - interface.state == 'UP'
> - interface.protocol == 'TCP'
> - interface.allocation == 'static'
> - interface.address == '192.168.0.17'
> - interface.default_gateway == '192.168.0.1'
> - interface.dns == '192.168.0.1'
> - interface.max_transmission_unit == '1500'
> - interface.vsp.should_not be_nil
> - interface.vsp.should be_an_instance_of Struct::CIMI_Vsp
> - interface.vsp.href.should =~ /^http:\/\/.*\/vsps\/(\w+)$/
> - interface.should be_an_instance_of Struct::CIMI_NetworkInterface
> - end
> - end
> -
> - it "should have edit and delete operations" do
> - templ = CIMI::Model::MachineTemplate.from_xml(@xml)
> - templ.operations.size.should == 2
> - templ.operations.any? { |operation| operation.rel == 'edit' }.should be_true
> - templ.operations.any? { |operation| operation.rel == 'delete' }.should be_true
> - templ.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
> - end
> -
> + it "can be constructed from XML" do
> + conf = CIMI::Model::MachineTemplate.from_xml(@xml)
> + conf.should_not be_nil
> + should_serialize_from_xml! conf, @xml, @json
> end
>
> - describe 'JSON' do
> - it "can be constructed" do
> - templ = CIMI::Model::MachineTemplate.from_json(@json)
> - templ.should_not be_nil
> - templ.should serialize_to @xml, :fmt => :xml
> - end
> -
> - it "should have default properties" do
> - templ = CIMI::Model::MachineTemplate.from_json(@json)
> - templ.created.should == "2011-11-01"
> - templ.name.should == "My First Template"
> - templ.description.should == "A template for testing"
> - templ.uri.should == "http://cimi.example.org/machine_templates/1"
> - end
> -
> - it "should convert strings in keys to symbols when contructed from XML" do
> - templ = CIMI::Model::MachineTemplate.from_json(@json)
> - templ.should_not be_nil
> - templ.attribute_values.keys.each { |key| key.should be_a_kind_of(Symbol) }
> - end
> -
> - it "should reference machine_config" do
> - templ = CIMI::Model::MachineTemplate.from_json(@json)
> - templ.machine_config.should be_an_instance_of Struct::CIMI_MachineConfig
> - templ.machine_config.href.should == "http://cimi.example.org/machine_configs/1"
> - end
> -
> - it "should reference machine_image" do
> - templ = CIMI::Model::MachineTemplate.from_json(@json)
> - templ.machine_image.should be_an_instance_of Struct::CIMI_MachineImage
> - templ.machine_image.href.should == "http://cimi.example.org/machine_images/1"
> - end
> -
> - it "should have list of attached volumes" do
> - templ = CIMI::Model::MachineTemplate.from_json(@json)
> - templ.volumes.should be_a_kind_of Array
> - templ.volumes.each do |volume|
> - volume.href.should =~ /^http:\/\/.*\/volumes\/(\w+)$/
> - volume.protocol.should == 'nfs'
> - volume.attachment_point == '/dev/sda'
> - volume.should be_an_instance_of Struct::CIMI_Volume
> - end
> - end
> -
> - it "should have list of network interfaces" do
> - templ = CIMI::Model::MachineTemplate.from_json(@json)
> - templ.network_interfaces.should be_an_instance_of Array
> - templ.network_interfaces.each do |interface|
> - interface.hostname == 'host.cimi.example.org'
> - interface.mac_address == '00:11:22:33:44:55'
> - interface.state == 'UP'
> - interface.protocol == 'TCP'
> - interface.allocation == 'static'
> - interface.address == '192.168.0.17'
> - interface.default_gateway == '192.168.0.1'
> - interface.dns == '192.168.0.1'
> - interface.max_transmission_unit == '1500'
> - interface.vsp.should_not be_nil
> - interface.vsp.should be_an_instance_of Struct::CIMI_Vsp
> - interface.vsp.href.should =~ /^http:\/\/.*\/vsps\/(\w+)$/
> - interface.should be_an_instance_of Struct::CIMI_NetworkInterface
> - end
> - end
> -
> - it "should have edit and delete operations" do
> - templ = CIMI::Model::MachineTemplate.from_json(@json)
> - templ.operations.size.should == 2
> - templ.operations.any? { |operation| operation.rel == 'edit' }.should be_true
> - templ.operations.any? { |operation| operation.rel == 'delete' }.should be_true
> - templ.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
> - end
> -
> + it "can be constructed from JSON" do
> + conf = CIMI::Model::MachineTemplate.from_json(@json)
> + conf.should_not be_nil
> + should_serialize_from_json! conf, @xml, @json
> end
>
> end
[PATCH core 4/4] CIMI: Revampled spec files once again to use the helpers for checking sanity of serialization
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
---
.../spec/cimi/model/machine_configuration_spec.rb | 99 ++------------
server/spec/cimi/model/machine_image_spec.rb | 82 +----------
server/spec/cimi/model/machine_template_spec.rb | 152 +------------------
3 files changed, 25 insertions(+), 308 deletions(-)
diff --git a/server/spec/cimi/model/machine_configuration_spec.rb b/server/spec/cimi/model/machine_configuration_spec.rb
index d60286e..454e8c4 100644
--- a/server/spec/cimi/model/machine_configuration_spec.rb
+++ b/server/spec/cimi/model/machine_configuration_spec.rb
@@ -20,97 +20,16 @@ describe "MachineConfiguration model" do
@json = IO::read(File::join(DATA_DIR, "machine_configuration.json"))
end
- describe 'XML' do
- it "can be constructed" do
- conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
- conf.should_not be_nil
- conf.should serialize_to @xml, :fmt => :xml
- end
-
- it "should convert strings in keys to symbols when contructed from XML" do
- conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
- conf.should_not be_nil
- conf.attribute_values.keys.each { |key| key.should be_a(Symbol) }
- end
-
- it "should have default properties" do
- conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
- conf.name.should == 'MachineConfiguration1'
- conf.uri == 'http://cimi.example.org/machine_configurations/1'
- conf.description == 'Example MachineConfiguration One'
- conf.created.should == "2011-11-14"
- end
-
- it "should have cpu and memory properties" do
- conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
- conf.cpu.should == "2"
- conf.memory.should be_an_instance_of Hash
- conf.memory['quantity'].should == '1'
- conf.memory['units'].should == 'gigabyte'
- end
-
- it "should have disk array property with capacity" do
- conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
- conf.disk.size.should == 1
- conf.disk[0].respond_to?(:capacity).should be_true
- conf.disk[0].capacity.size.should == 1
- conf.disk[0].capacity[0]['format'] == 'ext4'
- conf.disk[0].capacity[0]['quantity'] == '1'
- conf.disk[0].capacity[0]['attachmentPoint'] == '/'
- conf.disk[0].capacity[0]['units'] == 'terabyte'
- end
-
- it "should have edit and delete operations" do
- conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
- conf.operations.size.should == 2
- conf.operations.any? { |operation| operation.rel == 'edit' }.should be_true
- conf.operations.any? { |operation| operation.rel == 'delete' }.should be_true
- conf.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
- end
+ it "can be constructed from XML" do
+ conf = CIMI::Model::MachineConfiguration.from_xml(@xml)
+ conf.should_not be_nil
+ should_serialize_from_xml! conf, @xml, @json
end
- describe "JSON" do
- it "can be constructed" do
- conf = CIMI::Model::MachineConfiguration.from_json(@json)
- conf.should_not be_nil
- conf.should serialize_to @json, :fmt => :json
- end
-
- it "should have default properties" do
- conf = CIMI::Model::MachineConfiguration.from_json(@json)
- conf.name.should == 'MachineConfiguration1'
- conf.uri == 'http://cimi.example.org/machine_configurations/1'
- conf.description == 'Example MachineConfiguration One'
- conf.created.should == "2011-11-14"
- end
-
- it "should have cpu and memory properties" do
- conf = CIMI::Model::MachineConfiguration.from_json(@json)
- conf.cpu.should == "2"
- conf.memory.should be_an_instance_of Hash
- conf.memory['quantity'].should == '1'
- conf.memory['units'].should == 'gigabyte'
- end
-
- it "should have disk array property with capacity" do
- conf = CIMI::Model::MachineConfiguration.from_json(@json)
- conf.disk.should be_an_instance_of Array
- conf.disk.size.should > 0
- conf.disk[0].should respond_to :capacity
- conf.disk[0].capacity.size.should == 1
- conf.disk[0].capacity[0]['format'] == 'ext4'
- conf.disk[0].capacity[0]['quantity'] == '1'
- conf.disk[0].capacity[0]['attachmentPoint'] == '/'
- conf.disk[0].capacity[0]['units'] == 'terabyte'
- end
-
- it "should have edit and delete operations" do
- conf = CIMI::Model::MachineConfiguration.from_json(@json)
- conf.operations.size.should == 2
- conf.operations.any? { |operation| operation.rel == 'edit' }.should be_true
- conf.operations.any? { |operation| operation.rel == 'delete' }.should be_true
- conf.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
- end
-
+ it "can be constructed from JSON" do
+ conf = CIMI::Model::MachineConfiguration.from_json(@json)
+ conf.should_not be_nil
+ should_serialize_from_json! conf, @xml, @json
end
+
end
diff --git a/server/spec/cimi/model/machine_image_spec.rb b/server/spec/cimi/model/machine_image_spec.rb
index 517769a..824d032 100644
--- a/server/spec/cimi/model/machine_image_spec.rb
+++ b/server/spec/cimi/model/machine_image_spec.rb
@@ -21,82 +21,16 @@ describe "MachineImage model" do
@json = IO::read(File::join(DATA_DIR, "machine_image.json"))
end
- describe "XML" do
- it "can be constructed" do
- img = CIMI::Model::MachineImage.from_xml(@xml)
- img.should_not be_nil
- img.should serialize_to @xml, :fmt => :xml
- end
-
- it "should have default properties" do
- img = CIMI::Model::MachineImage.from_xml(@xml)
- img.uri.should == "http://cimi.example.org/machine_image/1"
- img.name.should == "img1"
- img.description.should == "Machine Image One"
- img.created.should == "2011-11-14"
- end
-
- it "should have image location property" do
- img = CIMI::Model::MachineImage.from_xml(@xml)
- img.image_location.should be_an_instance_of Hash
- img.image_location['href'].should == 'nfs://cimi.example.com/images/1.img'
- end
-
- it "should have edit and delete operations" do
- img = CIMI::Model::MachineImage.from_xml(@xml)
- img.operations.any? { |operation| operation.rel == 'edit' }.should be_true
- img.operations.any? { |operation| operation.rel == 'delete' }.should be_true
- img.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
- end
-
- it "should parse properties correctly in XML" do
- img = CIMI::Model::MachineImage.from_xml(@xml)
- img.property.any? { |p| p.name == 'status' }.should be_true
- img.property.any? { |p| p.name == 'locked' }.should be_true
- img.property.size.should == 2
- end
-
- it "should convert strings in keys to symbols when contructed from XML" do
- imgl = CIMI::Model::MachineImage.from_xml(@xml)
- imgl.should_not be_nil
- imgl.attribute_values.keys.each { |key| key.should be_a_kind_of(Symbol) }
- end
+ it "can be constructed from XML" do
+ conf = CIMI::Model::MachineImage.from_xml(@xml)
+ conf.should_not be_nil
+ should_serialize_from_xml! conf, @xml, @json
end
- describe 'JSON' do
- it "can be constructed" do
- img = CIMI::Model::MachineImage.from_json(@json)
- img.should_not be_nil
- img.should serialize_to @json, :fmt => :json
- end
-
- it "should have default properties" do
- img = CIMI::Model::MachineImage.from_json(@json)
- img.uri.should == "http://cimi.example.org/machine_images/1"
- img.name.should == "img1"
- img.description.should == "Machine Image One"
- img.created.should == "2011-11-14"
- end
-
- it "should have image location property" do
- img = CIMI::Model::MachineImage.from_json(@json)
- img.image_location.should be_an_instance_of Hash
- img.image_location['href'].should == 'nfs://cimi.example.com/images/1.img'
- end
-
- it "should have edit and delete operations" do
- img = CIMI::Model::MachineImage.from_json(@json)
- img.operations.any? { |operation| operation.rel == 'edit' }.should be_true
- img.operations.any? { |operation| operation.rel == 'delete' }.should be_true
- img.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
- end
-
- it "should parse properties correctly in XML" do
- img = CIMI::Model::MachineImage.from_json(@json)
- img.property.any? { |p| p.name == 'status' }.should be_true
- img.property.any? { |p| p.name == 'locked' }.should be_true
- img.property.size.should == 2
- end
+ it "can be constructed from JSON" do
+ conf = CIMI::Model::MachineImage.from_json(@json)
+ conf.should_not be_nil
+ should_serialize_from_json! conf, @xml, @json
end
end
diff --git a/server/spec/cimi/model/machine_template_spec.rb b/server/spec/cimi/model/machine_template_spec.rb
index 8ccd9ae..0c6f50a 100644
--- a/server/spec/cimi/model/machine_template_spec.rb
+++ b/server/spec/cimi/model/machine_template_spec.rb
@@ -20,152 +20,16 @@ describe "MachineTemplate model" do
@json = IO::read(File::join(DATA_DIR, "machine_template.json"))
end
- describe 'XML' do
- it "can be constructed" do
- templ = CIMI::Model::MachineTemplate.from_xml(@xml)
- templ.should_not be_nil
- templ.should serialize_to @xml, :fmt => :xml
- end
-
- it "should have default properties" do
- templ = CIMI::Model::MachineTemplate.from_xml(@xml)
- templ.created.should == "2011-11-01"
- templ.name.should == "My First Template"
- templ.description.should == "A template for testing"
- templ.uri.should == "http://cimi.example.org/machine_templates/1"
- end
-
- it "should convert strings in keys to symbols when contructed from XML" do
- templ = CIMI::Model::MachineTemplate.from_xml(@xml)
- templ.should_not be_nil
- templ.attribute_values.keys.each { |key| key.should be_a_kind_of(Symbol) }
- end
-
- it "should reference machine_config" do
- templ = CIMI::Model::MachineTemplate.from_xml(@xml)
- templ.machine_config.should be_an_instance_of Struct::CIMI_MachineConfig
- templ.machine_config.href.should == "http://cimi.example.org/machine_configs/1"
- end
-
- it "should reference machine_image" do
- templ = CIMI::Model::MachineTemplate.from_xml(@xml)
- templ.machine_image.should be_an_instance_of Struct::CIMI_MachineImage
- templ.machine_image.href.should == "http://cimi.example.org/machine_images/1"
- end
-
- it "should have list of attached volumes" do
- templ = CIMI::Model::MachineTemplate.from_xml(@xml)
- templ.volumes.should be_a_kind_of Array
- templ.volumes.each do |volume|
- volume.href.should =~ /^http:\/\/.*\/volumes\/(\w+)$/
- volume.protocol.should == 'nfs'
- volume.attachment_point == '/dev/sda'
- volume.should be_an_instance_of Struct::CIMI_Volume
- end
- end
-
- it "should have list of network interfaces" do
- templ = CIMI::Model::MachineTemplate.from_xml(@xml)
- templ.network_interfaces.should be_an_instance_of Array
- templ.network_interfaces.each do |interface|
- interface.hostname == 'host.cimi.example.org'
- interface.mac_address == '00:11:22:33:44:55'
- interface.state == 'UP'
- interface.protocol == 'TCP'
- interface.allocation == 'static'
- interface.address == '192.168.0.17'
- interface.default_gateway == '192.168.0.1'
- interface.dns == '192.168.0.1'
- interface.max_transmission_unit == '1500'
- interface.vsp.should_not be_nil
- interface.vsp.should be_an_instance_of Struct::CIMI_Vsp
- interface.vsp.href.should =~ /^http:\/\/.*\/vsps\/(\w+)$/
- interface.should be_an_instance_of Struct::CIMI_NetworkInterface
- end
- end
-
- it "should have edit and delete operations" do
- templ = CIMI::Model::MachineTemplate.from_xml(@xml)
- templ.operations.size.should == 2
- templ.operations.any? { |operation| operation.rel == 'edit' }.should be_true
- templ.operations.any? { |operation| operation.rel == 'delete' }.should be_true
- templ.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
- end
-
+ it "can be constructed from XML" do
+ conf = CIMI::Model::MachineTemplate.from_xml(@xml)
+ conf.should_not be_nil
+ should_serialize_from_xml! conf, @xml, @json
end
- describe 'JSON' do
- it "can be constructed" do
- templ = CIMI::Model::MachineTemplate.from_json(@json)
- templ.should_not be_nil
- templ.should serialize_to @xml, :fmt => :xml
- end
-
- it "should have default properties" do
- templ = CIMI::Model::MachineTemplate.from_json(@json)
- templ.created.should == "2011-11-01"
- templ.name.should == "My First Template"
- templ.description.should == "A template for testing"
- templ.uri.should == "http://cimi.example.org/machine_templates/1"
- end
-
- it "should convert strings in keys to symbols when contructed from XML" do
- templ = CIMI::Model::MachineTemplate.from_json(@json)
- templ.should_not be_nil
- templ.attribute_values.keys.each { |key| key.should be_a_kind_of(Symbol) }
- end
-
- it "should reference machine_config" do
- templ = CIMI::Model::MachineTemplate.from_json(@json)
- templ.machine_config.should be_an_instance_of Struct::CIMI_MachineConfig
- templ.machine_config.href.should == "http://cimi.example.org/machine_configs/1"
- end
-
- it "should reference machine_image" do
- templ = CIMI::Model::MachineTemplate.from_json(@json)
- templ.machine_image.should be_an_instance_of Struct::CIMI_MachineImage
- templ.machine_image.href.should == "http://cimi.example.org/machine_images/1"
- end
-
- it "should have list of attached volumes" do
- templ = CIMI::Model::MachineTemplate.from_json(@json)
- templ.volumes.should be_a_kind_of Array
- templ.volumes.each do |volume|
- volume.href.should =~ /^http:\/\/.*\/volumes\/(\w+)$/
- volume.protocol.should == 'nfs'
- volume.attachment_point == '/dev/sda'
- volume.should be_an_instance_of Struct::CIMI_Volume
- end
- end
-
- it "should have list of network interfaces" do
- templ = CIMI::Model::MachineTemplate.from_json(@json)
- templ.network_interfaces.should be_an_instance_of Array
- templ.network_interfaces.each do |interface|
- interface.hostname == 'host.cimi.example.org'
- interface.mac_address == '00:11:22:33:44:55'
- interface.state == 'UP'
- interface.protocol == 'TCP'
- interface.allocation == 'static'
- interface.address == '192.168.0.17'
- interface.default_gateway == '192.168.0.1'
- interface.dns == '192.168.0.1'
- interface.max_transmission_unit == '1500'
- interface.vsp.should_not be_nil
- interface.vsp.should be_an_instance_of Struct::CIMI_Vsp
- interface.vsp.href.should =~ /^http:\/\/.*\/vsps\/(\w+)$/
- interface.should be_an_instance_of Struct::CIMI_NetworkInterface
- end
- end
-
- it "should have edit and delete operations" do
- templ = CIMI::Model::MachineTemplate.from_json(@json)
- templ.operations.size.should == 2
- templ.operations.any? { |operation| operation.rel == 'edit' }.should be_true
- templ.operations.any? { |operation| operation.rel == 'delete' }.should be_true
- templ.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ }
- end
-
+ it "can be constructed from JSON" do
+ conf = CIMI::Model::MachineTemplate.from_json(@json)
+ conf.should_not be_nil
+ should_serialize_from_json! conf, @xml, @json
end
end
--
1.7.7.3
Re: [PATCH core 3/4] CIMI: Fixed wrong properties types in MachineImage
and MachineConfiguration models
Posted by "marios@redhat.com" <ma...@redhat.com>.
minor issue with nesting of MachineConfiguration attributes, otherwise, ACK:
On 16/11/11 22:34, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
>
> class CIMI::Model::MachineConfiguration < CIMI::Model::Base
>
> - array :disk do
> - scalar :capacity
> + array :disks do
> + struct :capacity do
> + scalar :format
> + scalar :quantity
> + scalar :attachment_point
> + scalar :units
> + end
> end
should be:
array :disks do
struct :capacity do
scalar :quantity
scalar :units
end
scalar :format
scalar :attachment_point
end
i.e. :quantity and :units are nested attributes of :capacity but :format
and :attachment_point are direct attributes of each :disk
>
> array :operations do
> diff --git a/server/lib/cimi/model/machine_image.rb b/server/lib/cimi/model/machine_image.rb
> index a23638f..18d91d4 100644
> --- a/server/lib/cimi/model/machine_image.rb
> +++ b/server/lib/cimi/model/machine_image.rb
> @@ -15,7 +15,7 @@
>
> class CIMI::Model::MachineImage < CIMI::Model::Base
>
> - scalar :image_location
> + href :image_location
> text :image_data
>
> array :operations do
[PATCH core 3/4] CIMI: Fixed wrong properties types in MachineImage and MachineConfiguration models
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
---
server/lib/cimi/model/machine_configuration.rb | 15 ++++++++++++---
server/lib/cimi/model/machine_image.rb | 2 +-
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/server/lib/cimi/model/machine_configuration.rb b/server/lib/cimi/model/machine_configuration.rb
index 221236c..ea78217 100644
--- a/server/lib/cimi/model/machine_configuration.rb
+++ b/server/lib/cimi/model/machine_configuration.rb
@@ -15,11 +15,20 @@
class CIMI::Model::MachineConfiguration < CIMI::Model::Base
- scalar :memory
+ struct :memory do
+ scalar :quantity
+ scalar :units
+ end
+
text :cpu
- array :disk do
- scalar :capacity
+ array :disks do
+ struct :capacity do
+ scalar :format
+ scalar :quantity
+ scalar :attachment_point
+ scalar :units
+ end
end
array :operations do
diff --git a/server/lib/cimi/model/machine_image.rb b/server/lib/cimi/model/machine_image.rb
index a23638f..18d91d4 100644
--- a/server/lib/cimi/model/machine_image.rb
+++ b/server/lib/cimi/model/machine_image.rb
@@ -15,7 +15,7 @@
class CIMI::Model::MachineImage < CIMI::Model::Base
- scalar :image_location
+ href :image_location
text :image_data
array :operations do
--
1.7.7.3
Re: [PATCH core 2/4] CIMI: Fixed typos in sample data
Posted by "marios@redhat.com" <ma...@redhat.com>.
ACK
(I have to change this is MachineAdmin too... thats what you get for
copying ;) )
On 16/11/11 22:34, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
>
> ---
> server/spec/cimi/data/machine_configuration.json | 4 ++--
> server/spec/cimi/data/machine_image.xml | 6 +++---
> 2 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/server/spec/cimi/data/machine_configuration.json b/server/spec/cimi/data/machine_configuration.json
> index 4ed3214..1d33c5a 100644
> --- a/server/spec/cimi/data/machine_configuration.json
> +++ b/server/spec/cimi/data/machine_configuration.json
> @@ -11,7 +11,7 @@
> "properties": [ { "architectore": "i386" } ],
> "operations": [
> { "rel": "edit",
> - "href": "http://cimi.example.org/machine_images/1/edit" },
> + "href": "http://cimi.example.org/machine_configurations/1/edit" },
> { "rel": "delete",
> - "href": "http://cimi.example.org/machine_images/1/delete" }]
> + "href": "http://cimi.example.org/machine_configurations/1/delete" }]
> }
> diff --git a/server/spec/cimi/data/machine_image.xml b/server/spec/cimi/data/machine_image.xml
> index a02bc36..2614dac 100644
> --- a/server/spec/cimi/data/machine_image.xml
> +++ b/server/spec/cimi/data/machine_image.xml
> @@ -1,11 +1,11 @@
> <MachineImage xmlns="http://www.dmtf.org/cimi">
> - <uri>http://cimi.example.org/machine_image/1</uri>
> + <uri>http://cimi.example.org/machine_images/1</uri>
> <name>img1</name>
> <description>Machine Image One</description>
> <created>2011-11-14</created>
> <property name="status">BUILD</property>
> <property name="locked">true</property>
> <imageLocation href="nfs://cimi.example.com/images/1.img"/>
> - <operation rel="edit" href="http://cimi.example.org/machine_image/1/edit"/>
> - <operation rel="delete" href="http://cimi.example.org/machine_image/1/delete"/>
> + <operation rel="edit" href="http://cimi.example.org/machine_images/1/edit"/>
> + <operation rel="delete" href="http://cimi.example.org/machine_images/1/delete"/>
> </MachineImage>
[PATCH core 2/4] CIMI: Fixed typos in sample data
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
---
server/spec/cimi/data/machine_configuration.json | 4 ++--
server/spec/cimi/data/machine_image.xml | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/server/spec/cimi/data/machine_configuration.json b/server/spec/cimi/data/machine_configuration.json
index 4ed3214..1d33c5a 100644
--- a/server/spec/cimi/data/machine_configuration.json
+++ b/server/spec/cimi/data/machine_configuration.json
@@ -11,7 +11,7 @@
"properties": [ { "architectore": "i386" } ],
"operations": [
{ "rel": "edit",
- "href": "http://cimi.example.org/machine_images/1/edit" },
+ "href": "http://cimi.example.org/machine_configurations/1/edit" },
{ "rel": "delete",
- "href": "http://cimi.example.org/machine_images/1/delete" }]
+ "href": "http://cimi.example.org/machine_configurations/1/delete" }]
}
diff --git a/server/spec/cimi/data/machine_image.xml b/server/spec/cimi/data/machine_image.xml
index a02bc36..2614dac 100644
--- a/server/spec/cimi/data/machine_image.xml
+++ b/server/spec/cimi/data/machine_image.xml
@@ -1,11 +1,11 @@
<MachineImage xmlns="http://www.dmtf.org/cimi">
- <uri>http://cimi.example.org/machine_image/1</uri>
+ <uri>http://cimi.example.org/machine_images/1</uri>
<name>img1</name>
<description>Machine Image One</description>
<created>2011-11-14</created>
<property name="status">BUILD</property>
<property name="locked">true</property>
<imageLocation href="nfs://cimi.example.com/images/1.img"/>
- <operation rel="edit" href="http://cimi.example.org/machine_image/1/edit"/>
- <operation rel="delete" href="http://cimi.example.org/machine_image/1/delete"/>
+ <operation rel="edit" href="http://cimi.example.org/machine_images/1/edit"/>
+ <operation rel="delete" href="http://cimi.example.org/machine_images/1/delete"/>
</MachineImage>
--
1.7.7.3