incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mandr...@redhat.com
Subject ['PATCH'] updates mock driver with basic blobstore functions (get+post+delete buckets, get blobs). Also some yaml for mocking buckets/blobs.
Date Fri, 24 Sep 2010 16:32:00 GMT
From: marios <marios@redhat.com>

---
 .../drivers/mock/data/buckets/blobs/blob1.yml      |    5 +
 .../drivers/mock/data/buckets/blobs/blob2.yml      |    5 +
 .../drivers/mock/data/buckets/blobs/blob3.yml      |    5 +
 .../drivers/mock/data/buckets/blobs/blob4.yml      |    5 +
 .../drivers/mock/data/buckets/blobs/blob5.yml      |    5 +
 .../drivers/mock/data/buckets/bucket1.yml          |    2 +
 .../drivers/mock/data/buckets/bucket2.yml          |    2 +
 server/lib/deltacloud/drivers/mock/mock_driver.rb  |   78 +++++++++++++++++++-
 8 files changed, 106 insertions(+), 1 deletions(-)
 create mode 100644 server/lib/deltacloud/drivers/mock/data/buckets/blobs/blob1.yml
 create mode 100644 server/lib/deltacloud/drivers/mock/data/buckets/blobs/blob2.yml
 create mode 100644 server/lib/deltacloud/drivers/mock/data/buckets/blobs/blob3.yml
 create mode 100644 server/lib/deltacloud/drivers/mock/data/buckets/blobs/blob4.yml
 create mode 100644 server/lib/deltacloud/drivers/mock/data/buckets/blobs/blob5.yml
 create mode 100644 server/lib/deltacloud/drivers/mock/data/buckets/bucket1.yml
 create mode 100644 server/lib/deltacloud/drivers/mock/data/buckets/bucket2.yml

diff --git a/server/lib/deltacloud/drivers/mock/data/buckets/blobs/blob1.yml b/server/lib/deltacloud/drivers/mock/data/buckets/blobs/blob1.yml
new file mode 100644
index 0000000..5ead10f
--- /dev/null
+++ b/server/lib/deltacloud/drivers/mock/data/buckets/blobs/blob1.yml
@@ -0,0 +1,5 @@
+:bucket: bucket1
+:content_length: 12627
+:content_type: text/plain
+:last_modified: 2010-09-23 16:44:54 +0100
+:content: "content of blob 1"
\ No newline at end of file
diff --git a/server/lib/deltacloud/drivers/mock/data/buckets/blobs/blob2.yml b/server/lib/deltacloud/drivers/mock/data/buckets/blobs/blob2.yml
new file mode 100644
index 0000000..4e62dd0
--- /dev/null
+++ b/server/lib/deltacloud/drivers/mock/data/buckets/blobs/blob2.yml
@@ -0,0 +1,5 @@
+:bucket: bucket1
+:content_length: 4420
+:content_type: text/html
+:last_modified: 2010-09-23 16:55:05 +0100
+:content: "content of blob 2"
\ No newline at end of file
diff --git a/server/lib/deltacloud/drivers/mock/data/buckets/blobs/blob3.yml b/server/lib/deltacloud/drivers/mock/data/buckets/blobs/blob3.yml
new file mode 100644
index 0000000..31cc1b3
--- /dev/null
+++ b/server/lib/deltacloud/drivers/mock/data/buckets/blobs/blob3.yml
@@ -0,0 +1,5 @@
+:bucket: bucket1
+:content_length: 98732
+:content_type: text/plain
+:last_modified: 2010-08-14 02:14:31 +0100
+:content: "content of blob 3"
\ No newline at end of file
diff --git a/server/lib/deltacloud/drivers/mock/data/buckets/blobs/blob4.yml b/server/lib/deltacloud/drivers/mock/data/buckets/blobs/blob4.yml
new file mode 100644
index 0000000..c9873ac
--- /dev/null
+++ b/server/lib/deltacloud/drivers/mock/data/buckets/blobs/blob4.yml
@@ -0,0 +1,5 @@
+:bucket: bucket2
+:content_length: 983232
+:content_type: application/octet-stream
+:last_modified: 2010-09-21 06:17:24 +0100
+:content: "content of blob 4"
\ No newline at end of file
diff --git a/server/lib/deltacloud/drivers/mock/data/buckets/blobs/blob5.yml b/server/lib/deltacloud/drivers/mock/data/buckets/blobs/blob5.yml
new file mode 100644
index 0000000..5014c89
--- /dev/null
+++ b/server/lib/deltacloud/drivers/mock/data/buckets/blobs/blob5.yml
@@ -0,0 +1,5 @@
+:bucket: bucket2
+:content_length: 651922
+:content_type: application/pdf
+:last_modified: 2009-07-21 11:12:13 +0100
+:content: "content of blob 5"
\ No newline at end of file
diff --git a/server/lib/deltacloud/drivers/mock/data/buckets/bucket1.yml b/server/lib/deltacloud/drivers/mock/data/buckets/bucket1.yml
new file mode 100644
index 0000000..d97f2c0
--- /dev/null
+++ b/server/lib/deltacloud/drivers/mock/data/buckets/bucket1.yml
@@ -0,0 +1,2 @@
+:blob_list: [blob1, blob2, blob3]
+:size: 3
diff --git a/server/lib/deltacloud/drivers/mock/data/buckets/bucket2.yml b/server/lib/deltacloud/drivers/mock/data/buckets/bucket2.yml
new file mode 100644
index 0000000..2e9abe9
--- /dev/null
+++ b/server/lib/deltacloud/drivers/mock/data/buckets/bucket2.yml
@@ -0,0 +1,2 @@
+:blob_list: [blob4, blob5]
+:size: 2
diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
index 4e7b605..3956a76 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -25,6 +25,10 @@ module Deltacloud
     module Mock
 class MockDriver < Deltacloud::BaseDriver
 
+  def supported_collections
+    DEFAULT_COLLECTIONS + [ :buckets ]
+  end
+
   ( REALMS = [
     Realm.new({
       :id=>'us',
@@ -104,7 +108,6 @@ class MockDriver < Deltacloud::BaseDriver
   #
   # Images
   #
-
   def images(credentials, opts=nil )
     check_credentials( credentials )
     images = []
@@ -251,6 +254,79 @@ class MockDriver < Deltacloud::BaseDriver
     snapshots
   end
 
+#--
+# Buckets
+#--
+  def buckets(credentials, opts=nil)
+    check_credentials(credentials)
+    buckets=[]
+     Dir[ "#{@storage_root}/buckets/*.yml" ].each do |bucket_file|
+      bucket = YAML.load( File.read( bucket_file ) )
+      bucket[:id] = File.basename( bucket_file, ".yml" )
+      bucket[:name] = bucket[:id]
+      buckets << Bucket.new( bucket )
+    end
+    buckets = filter_on( buckets, :id, opts )
+    buckets
+  end
+
+#--
+# Create bucket
+#--
+  def create_bucket(credentials, name, opts=nil)
+    check_credentials(credentials)
+    bucket = {
+      :name=>name,
+      :size=>'0',
+      :blob_list=>[]
+    }
+    File.open( "#{@storage_root}/buckets/#{name}.yml", 'w' ) {|b| YAML.dump( bucket, b )}
+    Bucket.new(bucket)
+  end
+
+#--
+# Delete bucket
+#--
+  def delete_bucket(credentials, name, opts=nil)
+    bucket = bucket(credentials, {:id => name})
+    unless (bucket.size == "0")
+     raise Deltacloud::BackendError.new(403, self.class.to_s, "bucket-not-empty", "delete
operation not valid for non-empty bucket")
+    end
+    safely do
+      File.delete("#{@storage_root}/buckets/#{name}.yml")
+    end
+  end
+
+#--
+# Blobs
+#--
+  def blobs(credentials, opts = nil)
+    check_credentials(credentials)
+    blobs=[]
+    Dir[ "#{@storage_root}/buckets/blobs/*.yml" ].each do |blob_file|
+      blob = YAML.load( File.read( blob_file ) )
+      blob[:id] = File.basename( blob_file, ".yml" )
+      blob[:name] = blob[:id]
+      blobs << Blob.new( blob )
+    end
+    blobs = filter_on( blobs, :id, opts )
+    blobs
+  end
+
+#--
+# Blob content
+#--
+  def blob_data(credentials, bucket_id, blob_id, opts = nil)
+    check_credentials(credentials)
+    blob=nil
+    Dir[ "#{@storage_root}/buckets/blobs/*.yml" ].each do |blob_file|
+      if File.basename(blob_file, ".yml") == blob_id 
+        blob = YAML.load(File.read(blob_file))
+        blob[:content].each {|part| yield part}
+      end
+    end
+  end
+
   def valid_credentials?(credentials)
     begin
       check_credentials(credentials)
-- 
1.7.2.3


Mime
View raw message