You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by lu...@redhat.com on 2012/12/05 02:07:21 UTC
Handle missing subcollections
Patch 1/2 makes sure we can deserialize bare-bones resources like a Machine
with only the mandatory attributes in it.
Uploaded as http://tracker.deltacloud.orgset/180
David
[PATCH 2/2] * tests/cimi/spec_helper.rb: require json/pure so tests can run individually
Posted by lu...@redhat.com.
From: David Lutterkort <lu...@redhat.com>
---
server/tests/cimi/spec_helper.rb | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/server/tests/cimi/spec_helper.rb b/server/tests/cimi/spec_helper.rb
index 6ec7b0d..8e86701 100644
--- a/server/tests/cimi/spec_helper.rb
+++ b/server/tests/cimi/spec_helper.rb
@@ -18,6 +18,7 @@ require 'rubygems'
require 'minitest/autorun'
require 'minitest/spec'
require 'xmlsimple'
+require 'json/pure'
require 'require_relative' if RUBY_VERSION < '1.9'
require_relative '../../lib/deltacloud/core_ext.rb'
--
1.7.7.6
[PATCH 1/2] CIMI: tolerate missing subcollections when parsing
Posted by lu...@redhat.com.
From: David Lutterkort <lu...@redhat.com>
It is legal to omit subcollections, e.g. in Machine; make sure we process
these correctly.
---
server/lib/cimi/models/schema.rb | 8 ++++++--
server/tests/cimi/data/machine-minimal.json | 7 +++++++
server/tests/cimi/data/machine-minimal.xml | 5 +++++
server/tests/cimi/model/machine_spec.rb | 17 +++++++++++++++++
4 files changed, 35 insertions(+), 2 deletions(-)
create mode 100644 server/tests/cimi/data/machine-minimal.json
create mode 100644 server/tests/cimi/data/machine-minimal.xml
diff --git a/server/lib/cimi/models/schema.rb b/server/lib/cimi/models/schema.rb
index 3d6a097..4e1affb 100644
--- a/server/lib/cimi/models/schema.rb
+++ b/server/lib/cimi/models/schema.rb
@@ -229,11 +229,15 @@ class CIMI::Model::Schema
end
def from_xml(xml, model)
- model[name] = @collection_class.schema.from_xml(xml[xml_name].first, {})
+ if xml[xml_name]
+ model[name] = @collection_class.schema.from_xml(xml[xml_name].first, {})
+ end
end
def from_json(json, model)
- model[name] = @collection_class.schema.from_json(json[json_name], {})
+ if json[json_name]
+ model[name] = @collection_class.schema.from_json(json[json_name], {})
+ end
end
def to_xml(model, xml)
diff --git a/server/tests/cimi/data/machine-minimal.json b/server/tests/cimi/data/machine-minimal.json
new file mode 100644
index 0000000..59a7d51
--- /dev/null
+++ b/server/tests/cimi/data/machine-minimal.json
@@ -0,0 +1,7 @@
+{
+ "resourceURI": "http://schemas.dmtf.org/cimi/1/Machine",
+ "id": "http://cimi.example.org/machines/1",
+ "state": "STARTED",
+ "cpu": "4",
+ "memory":12582912
+}
diff --git a/server/tests/cimi/data/machine-minimal.xml b/server/tests/cimi/data/machine-minimal.xml
new file mode 100644
index 0000000..ae2f729
--- /dev/null
+++ b/server/tests/cimi/data/machine-minimal.xml
@@ -0,0 +1,5 @@
+<Machine xmlns="http://schemas.dmtf.org/cimi/1">
+ <id>http://cimi.example.org/machines/1</id>
+ <memory>12582912</memory>
+ <state>STARTED</state>
+</Machine>
diff --git a/server/tests/cimi/model/machine_spec.rb b/server/tests/cimi/model/machine_spec.rb
index aa90cf3..45a02fa 100644
--- a/server/tests/cimi/model/machine_spec.rb
+++ b/server/tests/cimi/model/machine_spec.rb
@@ -23,10 +23,27 @@ describe "Machine model" do
before do
@xml = IO::read(File::join(DATA_DIR, "machine.xml"))
@json = IO::read(File::join(DATA_DIR, "machine.json"))
+ @xml_minimal = IO::read(File::join(DATA_DIR, "machine-minimal.xml"))
+ @json_minimal = IO::read(File::join(DATA_DIR, "machine-minimal.json"))
end
it "can be constructed from XML and JSON" do
should_properly_serialize_model CIMI::Model::Machine, @xml, @json
end
+ it "should parse minimal XML machine" do
+ machine = CIMI::Model::Machine.from_xml(@xml_minimal)
+ machine.id.wont_be_nil
+ machine.state.must_equal "STARTED"
+ machine.disks.entries.wont_be_nil
+ machine.disks.entries.size.must_equal 0
+ end
+
+ it "should parse minimal JSON machine" do
+ machine = CIMI::Model::Machine.from_json(@json_minimal)
+ machine.id.wont_be_nil
+ machine.state.must_equal "STARTED"
+ machine.disks.entries.wont_be_nil
+ machine.disks.entries.size.must_equal 0
+ end
end
--
1.7.7.6