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 2012/07/26 13:29:29 UTC

Initial RHEV-M driver unit tests + minor fixes (rev 2)

Hi,

This is an updated version of my previous patch set. This version
includes these fixes:

* The 'common.rb' helpers from tests/drivers/*/ are now clean and
  does not introduce code duplication.

* Added patch to make GET /images/new not fetch the instance from
  backend driver.

* The wait_for! method was moved to Deltacloud library code, which
  makes it available for all tests and also for library consumers.

* Added more explanation to commit messages

  -- Michal


RE: [PATCH core 9/9] Core: Make new image action not require the instance

Posted by "Koper, Dies" <di...@fast.au.fujitsu.com>.
ACK
Could you commit my change for fgcp_driver.rb (attached to the issue)
with it too?

     # destroying a running SLB, etc.
     on /ALREADY_STARTED/ do
-      status 502 #?
+      status 405
     end
 
     # trying to start a running vserver, etc.
     on /ILLEGAL_STATE/ do
-      status 502
+      status 405
     End

Cheers,
Dies

> -----Original Message-----
> From: mfojtik@redhat.com [mailto:mfojtik@redhat.com]
> Sent: Thursday, 26 July 2012 9:30 PM
> To: dev@deltacloud.apache.org
> Subject: [PATCH core 9/9] Core: Make new image action not require the
> instance
> 
> From: Michal Fojtik <mf...@redhat.com>
> 
> This patch will revert patch 537352d6, since fetching
> the instance will affect performance of this operation[1].
> 
> [1] https://issues.apache.org/jira/browse/DTACLOUD-214
> 
> Signed-off-by: Michal fojtik <mf...@redhat.com>
> ---
>  server/lib/deltacloud/collections/images.rb |    3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/server/lib/deltacloud/collections/images.rb
> b/server/lib/deltacloud/collections/images.rb
> index 6c4583d..fe1960a 100644
> --- a/server/lib/deltacloud/collections/images.rb
> +++ b/server/lib/deltacloud/collections/images.rb
> @@ -22,8 +22,7 @@ module Deltacloud::Collections
>      set :capability, lambda { |m| driver.respond_to? m }
> 
>      new_route_for :images do
> -      @instance = driver.instance(credentials, :id =>
params[:instance_id]) if
> params[:instance_id]
> -      halt 404 unless @instance
> +      @instance = Instance.new( :id => params[:instance_id] )
>      end
> 
>      collection :images do
> --
> 1.7.10.2
> 



[PATCH core 9/9] Core: Make new image action not require the instance

Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>

This patch will revert patch 537352d6, since fetching
the instance will affect performance of this operation[1].

[1] https://issues.apache.org/jira/browse/DTACLOUD-214

Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/lib/deltacloud/collections/images.rb |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/server/lib/deltacloud/collections/images.rb b/server/lib/deltacloud/collections/images.rb
index 6c4583d..fe1960a 100644
--- a/server/lib/deltacloud/collections/images.rb
+++ b/server/lib/deltacloud/collections/images.rb
@@ -22,8 +22,7 @@ module Deltacloud::Collections
     set :capability, lambda { |m| driver.respond_to? m }
 
     new_route_for :images do
-      @instance = driver.instance(credentials, :id => params[:instance_id]) if params[:instance_id]
-      halt 404 unless @instance
+      @instance = Instance.new( :id => params[:instance_id] )
     end
 
     collection :images do
-- 
1.7.10.2


[PATCH core 1/9] RHEV-M: Fixed bug that cause instance not pick up image_id

Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>

* images: by convention, drivers return an empty array if
  opts[:id] is specified but no image with that id exists
* create_instance: fix typo
* convert_image: image state needs to be uppercase and stripped

Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
index 95ce678..b66e90e 100644
--- a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
+++ b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
@@ -85,8 +85,13 @@ class RhevmDriver < Deltacloud::BaseDriver
     client = new_client(credentials)
     img_arr = []
     safely do
-      if (!opts.nil? && opts[:id])
-        img_arr << convert_image(client, client.template(opts[:id]))
+      if opts[:id]
+        begin
+          img_arr << convert_image(client, client.template(opts[:id]))
+        rescue OVIRT::OvirtException => e
+          raise e unless e.message =~ /Resource Not Found/
+          img_arr = []
+        end
       else
         img_arr = client.templates.collect { |t| convert_image(client, t) }
       end
@@ -176,7 +181,7 @@ class RhevmDriver < Deltacloud::BaseDriver
         raise "Parameter name must be #{USER_NAME_MAX} characters or less" if opts[:name].length > USER_NAME_MAX
       end
       params[:name] = opts[:name]
-      params[:template] = opts[:image_id]
+      params[:template] = image_id
       params[:cluster] = opts[:realm_id] if opts[:realm_id]
       params[:hwp_id] = opts[:hwp_id] if opts[:hwp_id]
       params[:memory] = (opts[:hwp_memory].to_i * 1024 * 1024) if opts[:hwp_memory]
@@ -308,7 +313,7 @@ class RhevmDriver < Deltacloud::BaseDriver
       :owner_id => client.credentials[:username],
       :architecture => 'x86_64', # All RHEV-M VMs are x86_64
       :hardware_profiles => hardware_profiles(nil),
-      :state => img.status
+      :state => img.status.strip.upcase
     )
   end
 
-- 
1.7.10.2


[PATCH core 3/9] Core: Remove to_s method from Instance model

Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>


Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/lib/deltacloud/models/instance.rb |    4 ----
 1 file changed, 4 deletions(-)

diff --git a/server/lib/deltacloud/models/instance.rb b/server/lib/deltacloud/models/instance.rb
index 421b4ef..f65b9b8 100644
--- a/server/lib/deltacloud/models/instance.rb
+++ b/server/lib/deltacloud/models/instance.rb
@@ -46,10 +46,6 @@ class Instance < BaseModel
     self.create_image
   end
 
-  def to_s
-    name
-  end
-
   def hardware_profile
     instance_profile
   end
-- 
1.7.10.2


[PATCH core 6/9] Core: Removed providers test from Library

Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>

Since the providers method on Library is now returing
providers based on current driver configuration, this
test is now obsoleted and should be replaced with VCR
test for specific driver.

Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/tests/drivers/base/library_test.rb |    4 ----
 1 file changed, 4 deletions(-)

diff --git a/server/tests/drivers/base/library_test.rb b/server/tests/drivers/base/library_test.rb
index 5f68145..a4a7f2f 100644
--- a/server/tests/drivers/base/library_test.rb
+++ b/server/tests/drivers/base/library_test.rb
@@ -28,10 +28,6 @@ describe 'Deltacloud API Library' do
     Deltacloud.new(:mock).current_provider.must_be_nil
   end
 
-  it 'should return pre-defined providers for the driver' do
-    Deltacloud.new(:ec2).providers[:entrypoints].must_be_kind_of Hash
-  end
-
   it 'should yield the backend driver' do
     Deltacloud.new :mock do |mock|
       mock.must_be_instance_of Deltacloud::Drivers::Mock::MockDriver
-- 
1.7.10.2


[PATCH core 8/9] Core: Reorganized common.rb files in driver unit tests

Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>

This patch will move Instance and Image monkey patching
into api.rb file, which will make it available also for
the Library use.

Also Time freezing patch and VCR helper method was moved
to test_helper.rb, which will keep the driver common.rb
reasonably small and without code duplication.

Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/lib/deltacloud/api.rb         |   41 ++++++++++++++++
 server/tests/drivers/ec2/common.rb   |   86 ++--------------------------------
 server/tests/drivers/rhevm/common.rb |   60 +-----------------------
 server/tests/test_helper.rb          |   37 +++++++++++++++
 4 files changed, 83 insertions(+), 141 deletions(-)

diff --git a/server/lib/deltacloud/api.rb b/server/lib/deltacloud/api.rb
index 587c667..23d96e1 100644
--- a/server/lib/deltacloud/api.rb
+++ b/server/lib/deltacloud/api.rb
@@ -29,6 +29,47 @@ require_relative 'models'
 require_relative 'drivers'
 require_relative 'helpers/driver_helper'
 
+module TestPoller
+  # This method will pool the resource until condition is true
+  # Will raise 'Timeout' when it reach retry count
+  #
+  # default opts[:retries] => 10
+  # default opts[:time_between_retry] => 10 (seconds)
+  # default opts[:timeout] => 60 (seconds) -> single request timeout
+  #
+  # opts[:before] => Proc -> executed 'before' making each request
+  # opts[:after] => Proc -> executed 'after' making each request
+  #
+  def wait_for!(driver, opts={}, &block)
+    opts[:retries] ||= 10
+    opts[:time_between_retry] ||= 10
+    opts[:timeout] ||= 60
+    opts[:method] ||= self.class.name.downcase.to_sym
+    opts[:retries].downto(0) do |r|
+      result = begin
+        timeout(opts[:timeout]) do
+          if opts[:before]
+            new_instance = opts[:before].call(r) { driver.send(opts[:method], :id => self.id) }
+          else
+            new_instance = driver.send(opts[:method], :id => self.id)
+          end
+          ((yield new_instance) == true) ? new_instance : false
+        end
+      rescue Timeout::Error
+        false
+      ensure
+        opts[:after].call(r) if opts[:after]
+      end
+      return result unless result == false
+      sleep(opts[:time_between_retry])
+    end
+    raise Timeout::Error
+  end
+end
+
+class Instance; include TestPoller; end
+class Image; include TestPoller; end
+
 module Deltacloud
 
   API_VERSION = '1.0.0'
diff --git a/server/tests/drivers/ec2/common.rb b/server/tests/drivers/ec2/common.rb
index 5434c61..a40a8bc 100644
--- a/server/tests/drivers/ec2/common.rb
+++ b/server/tests/drivers/ec2/common.rb
@@ -1,98 +1,20 @@
-# Make less noise to console
-ENV['RACK_ENV'] ||= 'test'
-
 # Warning: RightHttpConnection has to be required before WebMock is required !!!
 # Lets require that:
 require 'right_http_connection'
-
 require 'vcr'
-require 'time'
-
-# This code was originally copied from:
-# https://github.com/jtrupiano/timecop/issues/8#issuecomment-1396047
-#
-# Since 'timecop' gem has broken 'timezone' support, this small monkey-patching
-# on Time object seems to fix this issue.
-
-class Time
-  module TimeMock
-    attr_accessor :mock_time
-
-    def mock_now
-      @mock_time || Time.original_now
-    end
-
-    def be(a_time)
-      @mock_time = Time.parse(a_time)
-    end
-
-  end
-
-  class << self
-    include TimeMock
-    alias_method :original_now, :now
-    alias_method :now, :mock_now
-  end
-end
-
-class Instance
-  # This method will pool the instance until condition is true
-  # Will raise 'Timeout' when it reach retry count
-  #
-  # default opts[:retries] => 10
-  # default opts[:time_between_retry] => 10 (seconds)
-  # default opts[:timeout] => 60 (seconds) -> single request timeout
-  #
-  # opts[:before] => Proc -> executed 'before' making each request
-  # opts[:after] => Proc -> executed 'after' making each request
-  #
-  def wait_for!(driver, opts={}, &block)
-    opts[:retries] ||= 10
-    opts[:time_between_retry] ||= 10
-    opts[:timeout] ||= 60
-    opts[:retries].downto(0) do |r|
-      result = begin
-        timeout(opts[:timeout]) do
-          if opts[:before]
-            new_instance = opts[:before].call(r) { driver.instance(:id => self.id) }
-          else
-            new_instance = driver.instance(:id => self.id)
-          end
-          ((yield new_instance) == true) ? new_instance : false
-        end
-      rescue Timeout::Error
-        false
-      ensure
-        opts[:after].call(r) if opts[:after]
-      end
-      return result unless result == false
-      sleep(opts[:time_between_retry])
-    end
-    raise Timeout::Error
-  end
-end
 
 # Freeze time, so EC2 signatures have all the same time
 # This will avoid IncorrectSignature exceptions
 
+# NOTE: This timestamp need to be changed when re-recording
+#       the fixtures.
+
 Time.be(DateTime.parse("2012-07-23 12:21:00 +0000").to_s)
 
 VCR.configure do |c|
   # NOTE: Empty this directory before re-recording
   c.cassette_library_dir = File.join(File.dirname(__FILE__), 'fixtures')
   c.hook_into :webmock
-  # Set this to :new_epizodes when you want to 're-record'
+  # Set this to :new_episodes when you want to 're-record'
   c.default_cassette_options = { :record => :none }
 end
-
-# Some test scenarios use .wait_for! method that do multiple retries
-# for requests. We need to deal with that passing a Proc that use
-# different cassette for each request
-
-def record_retries(name='')
-  {
-    :before => Proc.new { |r, &block|
-      VCR.use_cassette("#{__name__}-#{name.empty? ? '' : "#{name}-"}#{r}", &block)
-    }
-  }
-end
diff --git a/server/tests/drivers/rhevm/common.rb b/server/tests/drivers/rhevm/common.rb
index 79f0794..8e039e9 100644
--- a/server/tests/drivers/rhevm/common.rb
+++ b/server/tests/drivers/rhevm/common.rb
@@ -1,9 +1,4 @@
-# Make less noise to console
-ENV['RACK_ENV'] ||= 'test'
-
 require 'vcr'
-require 'pp'
-require 'time'
 
 # Credentials used to access RHEV-M server
 #
@@ -17,63 +12,10 @@ def credentials
   }
 end
 
-module TestPooler
-  # This method will pool the resource until condition is true
-  # Will raise 'Timeout' when it reach retry count
-  #
-  # default opts[:retries] => 10
-  # default opts[:time_between_retry] => 10 (seconds)
-  # default opts[:timeout] => 60 (seconds) -> single request timeout
-  #
-  # opts[:before] => Proc -> executed 'before' making each request
-  # opts[:after] => Proc -> executed 'after' making each request
-  #
-  def wait_for!(driver, opts={}, &block)
-    opts[:retries] ||= 10
-    opts[:time_between_retry] ||= 10
-    opts[:timeout] ||= 60
-    opts[:method] ||= self.class.name.downcase.to_sym
-    opts[:retries].downto(0) do |r|
-      result = begin
-        timeout(opts[:timeout]) do
-          if opts[:before]
-            new_instance = opts[:before].call(r) { driver.send(opts[:method], :id => self.id) }
-          else
-            new_instance = driver.send(opts[:method], :id => self.id)
-          end
-          ((yield new_instance) == true) ? new_instance : false
-        end
-      rescue Timeout::Error
-        false
-      ensure
-        opts[:after].call(r) if opts[:after]
-      end
-      return result unless result == false
-      sleep(opts[:time_between_retry])
-    end
-    raise Timeout::Error
-  end
-end
-
-class Instance; include TestPooler; end
-class Image; include TestPooler; end
-
 VCR.configure do |c|
   # NOTE: Empty this directory before re-recording
   c.cassette_library_dir = File.join(File.dirname(__FILE__), 'fixtures')
   c.hook_into :webmock
-  # Set this to :new_epizodes when you want to 're-record'
+  # Set this to :new_episodes when you want to 're-record'
   c.default_cassette_options = { :record => :none }
 end
-
-# Some test scenarios use .wait_for! method that do multiple retries
-# for requests. We need to deal with that passing a Proc that use
-# different cassette for each request
-
-def record_retries(name='')
-  {
-    :before => Proc.new { |r, &block|
-      VCR.use_cassette("#{__name__}-#{name.empty? ? '' : "#{name}-"}#{r}", &block)
-    }
-  }
-end
diff --git a/server/tests/test_helper.rb b/server/tests/test_helper.rb
index 0b40610..42effb1 100644
--- a/server/tests/test_helper.rb
+++ b/server/tests/test_helper.rb
@@ -17,3 +17,40 @@ unless Kernel.respond_to?(:require_relative)
     end
   end
 end
+
+require 'time'
+
+# This code was originally copied from:
+# https://github.com/jtrupiano/timecop/issues/8#issuecomment-1396047
+#
+# Since 'timecop' gem has broken 'timezone' support, this small monkey-patching
+# on Time object seems to fix this issue.
+
+class Time
+  module TimeMock
+    attr_accessor :mock_time
+
+    def mock_now
+      @mock_time || Time.original_now
+    end
+
+    def be(a_time)
+      @mock_time = Time.parse(a_time)
+    end
+
+  end
+
+  class << self
+    include TimeMock
+    alias_method :original_now, :now
+    alias_method :now, :mock_now
+  end
+end
+
+def record_retries(name='')
+  {
+    :before => Proc.new { |r, &block|
+      VCR.use_cassette("#{__name__}-#{name.empty? ? '' : "#{name}-"}#{r}", &block)
+    }
+  }
+end
-- 
1.7.10.2


Re: Initial RHEV-M driver unit tests + minor fixes (rev 2)

Posted by David Lutterkort <lu...@redhat.com>.
On Thu, 2012-07-26 at 13:29 +0200, mfojtik@redhat.com wrote:
> This is an updated version of my previous patch set. This version
> includes these fixes:
> 
> * The 'common.rb' helpers from tests/drivers/*/ are now clean and
>   does not introduce code duplication.
> 
> * Added patch to make GET /images/new not fetch the instance from
>   backend driver.
> 
> * The wait_for! method was moved to Deltacloud library code, which
>   makes it available for all tests and also for library consumers.
> 
> * Added more explanation to commit messages

These look ok now - the tests fail for me though, and I am wondering
whether it's because there wasn't a new version of patch 4/9; I tried
using the one from yesterday[1] with no success.

David

[1] http://omicron.mifo.sk/0004-Core-Added-initial-RHEV-M-unit-tests.patch.gz


[PATCH core 7/9] Core: Reorganized unit tests and coverage generation

Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>

Since each driver test use it's own VCR settings, it is not
longer possible to load all tests at once with rake test.

For this this patch will split different test tasks so drivers
do no overide their VCR configurations

Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/.simplecov           |   11 ++++++++
 server/Rakefile             |   65 ++++++++++++++++++++++++++++++++++---------
 server/tests/test_helper.rb |   13 ---------
 3 files changed, 63 insertions(+), 26 deletions(-)
 create mode 100644 server/.simplecov

diff --git a/server/.simplecov b/server/.simplecov
new file mode 100644
index 0000000..5feea29
--- /dev/null
+++ b/server/.simplecov
@@ -0,0 +1,11 @@
+SimpleCov.start do
+  command_name 'Minitest tests'
+  project_name 'Deltacloud API'
+  add_filter "tests/"
+  add_group 'Drivers', 'lib/deltacloud/drivers'
+  add_group 'Collections', 'lib/deltacloud/collections'
+  add_group 'Models', 'lib/deltacloud/models'
+  add_group 'Helpers', 'lib/deltacloud/helpers'
+  add_group 'Extensions', 'lib/deltacloud/core_ext'
+  add_group 'Sinatra', 'lib/sinatra'
+end
diff --git a/server/Rakefile b/server/Rakefile
index 41eb7fa..c42ea4b 100644
--- a/server/Rakefile
+++ b/server/Rakefile
@@ -108,18 +108,57 @@ task :routes do
   end
 end
 
-Rake::TestTask.new do |t|
-  t.ruby_opts << '-r./tests/test_helper.rb'   # Load SimpleCov when COVERAGE=1 is set
-  unless RUBY_VERSION < '1.9.0'
-    t.loader = :testrb
+DRIVERS = [:mock, :ec2, :rhevm]
+
+desc 'Run all tests'
+task :test do
+
+  Rake::Task["mock:fixtures:reset"].invoke
+  puts "\n[ \033[1;37;mrake test:base\33[0m ]\n"
+  Rake::Task["test:base"].invoke
+  DRIVERS.each do |driver|
+    puts "\n[ \033[1;37;mrake drivers:#{driver}\33[0m ]\n"
+    Rake::Task["test:drivers:#{driver}"].invoke
   end
-  t.test_files = FileList[
-    'tests/helpers/**/*test.rb',              # Deltacloud extensions (core_ext) and other helpers
-    'tests/drivers/base/*test.rb',            # Deltacloud drivers API tests
-    'tests/drivers/models/*test.rb',          # Deltacloud models tests
-    'tests/deltacloud/*test.rb',              # Deltacloud internal API tests
-    'tests/deltacloud/collections/*test.rb',  # Deltacloud collections
-    'tests/drivers/mock/*test.rb',            # Deltacloud Mock driver specific unit tests
-    'tests/drivers/ec2/*test.rb'              # Deltacloud EC2 driver specific unit tests
-  ]
 end
+
+namespace :test do
+
+  desc "Run all tests and generate code coverage report"
+  task :coverage do
+    ENV['COVERAGE'] = '1'
+    puts "[ \033[1;37;mCoverage report will be generated to server/coverage\33[0m ]\n\n"
+    Rake::Task["test"].invoke
+  end
+
+  namespace :drivers do
+
+    DRIVERS.each do |driver|
+      Rake::TestTask.new(driver) do |t|
+        t.ruby_opts << '-r./tests/test_helper.rb'   # Load SimpleCov when COVERAGE=1 is set
+        unless RUBY_VERSION < '1.9.0'
+          t.loader = :testrb
+        end
+        t.test_files = FileList["tests/drivers/#{driver}/*test.rb"]
+      end
+    end
+
+  end
+
+  Rake::TestTask.new(:base) do |t|
+    t.ruby_opts << '-r./tests/test_helper.rb'   # Load SimpleCov when COVERAGE=1 is set
+    unless RUBY_VERSION < '1.9.0'
+      t.loader = :testrb
+    end
+    t.test_files = FileList[
+      'tests/helpers/core_ext/*test.rb',        # Deltacloud extensions (core_ext) and other helpers
+      'tests/drivers/base/*test.rb',            # Deltacloud drivers API tests
+      'tests/drivers/models/*test.rb',          # Deltacloud models tests
+      'tests/deltacloud/*test.rb',              # Deltacloud internal API tests
+      'tests/deltacloud/collections/*test.rb',  # Deltacloud collections
+    ]
+  end
+
+end
+
+
diff --git a/server/tests/test_helper.rb b/server/tests/test_helper.rb
index 5aed571..0b40610 100644
--- a/server/tests/test_helper.rb
+++ b/server/tests/test_helper.rb
@@ -2,22 +2,9 @@ require 'pp'
 
 ENV['RACK_ENV'] = 'test'
 
-%x[rake mock:fixtures:reset]
-
 if ENV['COVERAGE']
   begin
     require 'simplecov'
-    SimpleCov.start do
-      command_name 'Minitest tests'
-      project_name 'Deltacloud API'
-      add_filter "tests/"
-      add_group 'Drivers', 'lib/deltacloud/drivers'
-      add_group 'Collections', 'lib/deltacloud/collections'
-      add_group 'Models', 'lib/deltacloud/models'
-      add_group 'Helpers', 'lib/deltacloud/helpers'
-      add_group 'Extensions', 'lib/deltacloud/core_ext'
-      add_group 'Sinatra', 'lib/sinatra'
-    end
   rescue LoadError
     warn "To generate code coverage you need to install 'simplecov' (gem install simplecov OR bundle)"
   end
-- 
1.7.10.2


[PATCH core 5/9] Core: Make tests pickup correct exceptions

Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>


Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/tests/drivers/mock/images_test.rb |    2 +-
 server/tests/drivers/mock/keys_test.rb   |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/server/tests/drivers/mock/images_test.rb b/server/tests/drivers/mock/images_test.rb
index 746000c..7165e65 100644
--- a/server/tests/drivers/mock/images_test.rb
+++ b/server/tests/drivers/mock/images_test.rb
@@ -42,7 +42,7 @@ describe 'MockDriver Images' do
     @driver.image(:id => 'img1-test').id.must_equal 'img1-test'
     @driver.image(:id => 'img1-test').name.must_equal 'img1-test'
     @driver.image(:id => 'img1-test').description.must_equal 'Test1'
-    Proc.new { @driver.create_image(:id => 'unknown-instance', :name => 'test') }.must_raise Deltacloud::ExceptionHandler::ProviderError, 'CreateImageNotSupported'
+    Proc.new { @driver.create_image(:id => 'unknown-instance', :name => 'test') }.must_raise Deltacloud::ExceptionHandler::BackendError, 'CreateImageNotSupported'
     @driver.image(:id => 'test').must_be_nil
   end
 
diff --git a/server/tests/drivers/mock/keys_test.rb b/server/tests/drivers/mock/keys_test.rb
index bebe3ec..296b909 100644
--- a/server/tests/drivers/mock/keys_test.rb
+++ b/server/tests/drivers/mock/keys_test.rb
@@ -38,7 +38,7 @@ describe 'MockDriver Keys' do
     key = @driver.create_key(:key_name => 'test1')
     key.wont_be_nil
     key.must_be_kind_of Key
-    Proc.new { @driver.create_key(:key_name => 'test1') }.must_raise Deltacloud::ExceptionHandler::ProviderError, 'KeyExist'
+    Proc.new { @driver.create_key(:key_name => 'test1') }.must_raise Deltacloud::ExceptionHandler::ForbiddenError, 'KeyExist'
     @driver.destroy_key :id => key.id
     @driver.key(:id => key.id).must_be_nil
   end
-- 
1.7.10.2


[PATCH core 2/9] Core: Make Deltacloud::Library return driver providers

Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>


Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/lib/deltacloud/api.rb |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/server/lib/deltacloud/api.rb b/server/lib/deltacloud/api.rb
index 2b520d4..587c667 100644
--- a/server/lib/deltacloud/api.rb
+++ b/server/lib/deltacloud/api.rb
@@ -65,7 +65,15 @@ module Deltacloud
     end
 
     def providers
-      Deltacloud.drivers[current_driver.to_sym]
+      if backend.respond_to? :providers
+        backend.providers(@credentials)
+      else
+        Deltacloud.drivers[current_driver.to_sym]
+      end
+    end
+
+    def provider(opts={})
+      providers.find { |p| p.id == opts[:id] }
     end
 
     def method_missing(name, *args)
-- 
1.7.10.2