deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject git commit: * lib/cimi/service/disk.rb: correctly look up DiskCollection
Date Wed, 10 Apr 2013 20:41:20 GMT
Updated Branches:
  refs/heads/master 344199882 -> 04006b7a0


* lib/cimi/service/disk.rb: correctly look up DiskCollection

The DiskCollection is generated scoped inside the class in which it is used
as a collection (CIMI::Model::Machine) Use the correct class name in
collection_for_instance.

Fixes https://issues.apache.org/jira/browse/DTACLOUD-536


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/04006b7a
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/04006b7a
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/04006b7a

Branch: refs/heads/master
Commit: 04006b7a03073f16804a1911b4bd34b5776ec4a8
Parents: 3441998
Author: David Lutterkort <lutter@redhat.com>
Authored: Tue Apr 9 15:45:58 2013 -0700
Committer: David Lutterkort <lutter@redhat.com>
Committed: Wed Apr 10 13:40:54 2013 -0700

----------------------------------------------------------------------
 server/lib/cimi/service/disk.rb                |    9 ++-------
 server/tests/cimi/collections/common.rb        |    8 +++++++-
 server/tests/cimi/collections/machines_test.rb |   12 ++++++++++++
 3 files changed, 21 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/04006b7a/server/lib/cimi/service/disk.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/disk.rb b/server/lib/cimi/service/disk.rb
index 1af908e..8fde6b5 100644
--- a/server/lib/cimi/service/disk.rb
+++ b/server/lib/cimi/service/disk.rb
@@ -62,18 +62,13 @@ class CIMI::Service::Disk < CIMI::Service::Base
   def self.collection_for_instance(instance_id, context)
     instance = context.driver.instance(context.credentials, :id => instance_id)
     disks = find(instance, nil, context)
-    unless CIMI::Model.const_defined?('DiskCollection')
-      collection_class = CIMI::Model::Collection.generate(self)
-    else
-      collection_class = CIMI::Model::DiskCollection
-    end
-    collection_class.new(context, :values => {
+    CIMI::Model::Machine::DiskCollection.new(
       :id => context.url("/machines/#{instance_id}/disks"),
       :name => 'default',
       :count => disks.size,
       :description => "Disk collection for Machine #{instance_id}",
       :entries => disks
-    })
+    )
   end
 
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/04006b7a/server/tests/cimi/collections/common.rb
----------------------------------------------------------------------
diff --git a/server/tests/cimi/collections/common.rb b/server/tests/cimi/collections/common.rb
index f44f9cd..ce9b516 100644
--- a/server/tests/cimi/collections/common.rb
+++ b/server/tests/cimi/collections/common.rb
@@ -36,7 +36,13 @@ def model_class
   else
     raise "Unexpected content type #{resp.content_type}"
   end
-  CIMI::Model::const_get(resource)
+  if resource == "DiskCollection"
+    # We scope subcollections within the containing class
+    # CIMI resource_uri's don't
+    CIMI::Model::Machine::DiskCollection
+  else
+    CIMI::Model::const_get(resource)
+  end
 end
 
 def model

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/04006b7a/server/tests/cimi/collections/machines_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/cimi/collections/machines_test.rb b/server/tests/cimi/collections/machines_test.rb
index 5e8346e..b6f1de1 100644
--- a/server/tests/cimi/collections/machines_test.rb
+++ b/server/tests/cimi/collections/machines_test.rb
@@ -42,6 +42,18 @@ describe CIMI::Collections::Machines do
     add_ops.size.must_equal 1
   end
 
+  it "should return the disks collection for a machine" do
+    get root_url + '/machines'
+    model.operations.wont_be_empty
+    href = model.entries.first.disks[:href]
+    href.wont_be_empty
+    get href
+    status.must_equal 200
+    model.must_be_kind_of CIMI::Model::Machine::DiskCollection
+    model.entries.size.must_equal 1
+    model.entries.first.name.must_equal "inst0_disk_0"
+  end
+
   describe "$expand" do
     def machine(*expand)
       url = '/machines/inst1'


Mime
View raw message