deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [3/6] git commit: Core: Added initial tests for Mock driver API
Date Mon, 23 Jul 2012 09:06:00 GMT
Core: Added initial tests for Mock driver API


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

Branch: refs/heads/master
Commit: ade3d60bc1dad1e94eb044361b87bb14b60e6cb0
Parents: 1d8cb17
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Fri Jul 20 15:38:55 2012 +0200
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Fri Jul 20 17:44:23 2012 +0200

----------------------------------------------------------------------
 server/Rakefile                                    |    3 +-
 server/tests/drivers/mock/images_test.rb           |   55 ++++++++
 server/tests/drivers/mock/instances_test.rb        |   99 +++++++++++++++
 server/tests/drivers/mock/keys_test.rb             |   46 +++++++
 server/tests/drivers/mock/realms_test.rb           |   37 ++++++
 .../tests/drivers/mock/storage_snapshots_test.rb   |   37 ++++++
 server/tests/drivers/mock/storage_volumes_test.rb  |   59 +++++++++
 7 files changed, 335 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ade3d60b/server/Rakefile
----------------------------------------------------------------------
diff --git a/server/Rakefile b/server/Rakefile
index ef1ab1a..f232933 100644
--- a/server/Rakefile
+++ b/server/Rakefile
@@ -118,6 +118,7 @@ Rake::TestTask.new do |t|
     '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/deltacloud/collections/*test.rb',  # Deltacloud collections
+    'tests/drivers/*/*test.rb'                # Deltacloud driver specific unit tests
   ]
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ade3d60b/server/tests/drivers/mock/images_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/mock/images_test.rb b/server/tests/drivers/mock/images_test.rb
new file mode 100644
index 0000000..746000c
--- /dev/null
+++ b/server/tests/drivers/mock/images_test.rb
@@ -0,0 +1,55 @@
+require 'minitest/autorun'
+
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
+
+describe 'MockDriver Images' do
+
+  before do
+    @driver = Deltacloud::new(:mock, :user => 'mockuser', :password => 'mockpassword')
+  end
+
+  it 'must throw error when wrong credentials' do
+    Proc.new do
+      @driver.backend.images(OpenStruct.new(:user => 'unknown', :password => 'wrong'))
+    end.must_raise Deltacloud::ExceptionHandler::AuthenticationFailure, 'Authentication Failure'
+  end
+
+  it 'must return list of images' do
+    @driver.images.wont_be_empty
+    @driver.images.first.must_be_kind_of Image
+  end
+
+  it 'must allow to filter images' do
+    @driver.images(:id => 'img1').wont_be_empty
+    @driver.images(:id => 'img1').must_be_kind_of Array
+    @driver.images(:id => 'img1').size.must_equal 1
+    @driver.images(:id => 'img1').first.id.must_equal 'img1'
+    @driver.images(:owner_id => 'mockuser').size.must_equal 1
+    @driver.images(:owner_id => 'mockuser').first.owner_id.must_equal 'mockuser'
+    @driver.images(:id => 'unknown').must_be_empty
+  end
+
+  it 'must allow to retrieve single image' do
+    @driver.image(:id => 'img1').wont_be_nil
+    @driver.image(:id => 'img1').must_be_kind_of Image
+    @driver.image(:id => 'img1').id.must_equal 'img1'
+    @driver.image(:id => 'unknown').must_be_nil
+  end
+
+  it 'must allow to create a new image if instance supported' do
+    @driver.create_image(:id => 'inst1', :name => 'img1-test', :description => 'Test1').must_be_kind_of
Image
+    @driver.image(:id => 'img1-test').wont_be_nil
+    @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'
+    @driver.image(:id => 'test').must_be_nil
+  end
+
+  it 'must allow to destroy created image' do
+    @driver.create_image(:id => 'inst1', :name => 'img1-test-destroy').must_be_kind_of
Image
+    @driver.destroy_image('img1-test-destroy')
+    @driver.image(:id => 'img1-test-destroy').must_be_nil
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ade3d60b/server/tests/drivers/mock/instances_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/mock/instances_test.rb b/server/tests/drivers/mock/instances_test.rb
new file mode 100644
index 0000000..fcb690a
--- /dev/null
+++ b/server/tests/drivers/mock/instances_test.rb
@@ -0,0 +1,99 @@
+require 'minitest/autorun'
+
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
+
+describe 'MockDriver Instances' do
+
+  before do
+    @driver = Deltacloud::new(:mock, :user => 'mockuser', :password => 'mockpassword')
+  end
+
+  it 'must throw error when wrong credentials' do
+    Proc.new do
+      @driver.backend.instances(OpenStruct.new(:user => 'unknown', :password => 'wrong'))
+    end.must_raise Deltacloud::ExceptionHandler::AuthenticationFailure, 'Authentication Failure'
+  end
+
+  it 'must return list of instances' do
+    @driver.instances.wont_be_empty
+    @driver.instances.first.must_be_kind_of Instance
+  end
+
+  it 'must allow to filter instances' do
+    @driver.instances(:id => 'inst1').wont_be_empty
+    @driver.instances(:id => 'inst1').must_be_kind_of Array
+    @driver.instances(:id => 'inst1').size.must_equal 1
+    @driver.instances(:id => 'inst1').first.id.must_equal 'inst1'
+    @driver.instances(:owner_id => 'mockuser').size.must_equal 2
+    @driver.instances(:owner_id => 'mockuser').first.owner_id.must_equal 'mockuser'
+    @driver.instances(:id => 'unknown').must_be_empty
+  end
+
+  it 'must allow to retrieve single instance' do
+    @driver.instance(:id => 'inst1').wont_be_nil
+    @driver.instance(:id => 'inst1').must_be_kind_of Instance
+    @driver.instance(:id => 'inst1').id.must_equal 'inst1'
+    @driver.instance(:id => 'unknown').must_be_nil
+  end
+
+  it 'must allow to create a new instance if instance supported' do
+    instance = @driver.create_instance('img1', :name => 'inst1-test', :realm_id =>
'us', :hwp_id => 'm1-small')
+    instance.must_be_kind_of Instance
+    @driver.instance(:id => instance.id).wont_be_nil
+    @driver.instance(:id => instance.id).id.must_equal instance.id
+    @driver.instance(:id => instance.id).name.must_equal 'inst1-test'
+    @driver.instance(:id => instance.id).instance_profile.name.must_equal 'm1-small'
+    @driver.instance(:id => instance.id).realm_id.must_equal 'us'
+    @driver.instance(:id => instance.id).owner_id.must_equal 'mockuser'
+    @driver.instance(:id => instance.id).state.must_equal 'RUNNING'
+    @driver.instance(:id => instance.id).public_addresses.wont_be_empty
+    @driver.instance(:id => instance.id).actions.must_include :reboot
+    @driver.instance(:id => instance.id).actions.must_include :stop
+    @driver.destroy_instance(instance.id)
+    @driver.instance(:id => instance.id).must_be_nil
+  end
+
+  it 'must allow to destroy created instance' do
+    instance = @driver.create_instance('img1', :name => 'inst1-test-destroy')
+    instance.must_be_kind_of Instance
+    @driver.destroy_instance(instance.id)
+    @driver.instance(:id => instance.id).must_be_nil
+  end
+
+  it 'must allow to stop instance in running state' do
+    instance = @driver.create_instance('img1', :name => 'inst1-test-destroy')
+    instance.must_be_kind_of Instance
+    instance.state.must_equal 'RUNNING'
+    @driver.stop_instance(instance.id)
+    @driver.instance(:id => instance.id).state.must_equal 'STOPPED'
+    @driver.destroy_instance(instance.id)
+    @driver.instance(:id => instance.id).must_be_nil
+  end
+
+  it 'must allow to start instance in stopped state' do
+    instance = @driver.create_instance('img1', :name => 'inst1-test-destroy')
+    instance.must_be_kind_of Instance
+    instance.state.must_equal 'RUNNING'
+    @driver.stop_instance(instance.id)
+    @driver.instance(:id => instance.id).state.must_equal 'STOPPED'
+    @driver.start_instance(instance.id)
+    @driver.instance(:id => instance.id).state.must_equal 'RUNNING'
+    @driver.destroy_instance(instance.id)
+    @driver.instance(:id => instance.id).must_be_nil
+  end
+
+  it 'must allow to reboot instance in running state' do
+    instance = @driver.create_instance('img1', :name => 'inst1-test-destroy')
+    instance.must_be_kind_of Instance
+    instance.state.must_equal 'RUNNING'
+    @driver.reboot_instance(instance.id)
+    @driver.instance(:id => instance.id).state.must_equal 'RUNNING'
+    @driver.stop_instance(instance.id)
+    @driver.instance(:id => instance.id).state.must_equal 'STOPPED'
+    @driver.reboot_instance(instance.id)
+    @driver.instance(:id => instance.id).state.must_equal 'RUNNING'
+    @driver.destroy_instance(instance.id)
+    @driver.instance(:id => instance.id).must_be_nil
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ade3d60b/server/tests/drivers/mock/keys_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/mock/keys_test.rb b/server/tests/drivers/mock/keys_test.rb
new file mode 100644
index 0000000..bebe3ec
--- /dev/null
+++ b/server/tests/drivers/mock/keys_test.rb
@@ -0,0 +1,46 @@
+require 'minitest/autorun'
+
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
+
+describe 'MockDriver Keys' do
+
+  before do
+    @driver = Deltacloud::new(:mock, :user => 'mockuser', :password => 'mockpassword')
+  end
+
+  it 'must throw error when wrong credentials' do
+    Proc.new do
+      @driver.backend.keys(OpenStruct.new(:user => 'unknown', :password => 'wrong'))
+    end.must_raise Deltacloud::ExceptionHandler::AuthenticationFailure, 'Authentication Failure'
+  end
+
+  it 'must return list of keys' do
+    @driver.keys.wont_be_empty
+    @driver.keys.first.must_be_kind_of Key
+  end
+
+  it 'must allow to filter keys' do
+    @driver.keys(:id => 'test-key').wont_be_empty
+    @driver.keys(:id => 'test-key').must_be_kind_of Array
+    @driver.keys(:id => 'test-key').size.must_equal 1
+    @driver.keys(:id => 'test-key').first.id.must_equal 'test-key'
+    @driver.keys(:id => 'unknown').must_be_empty
+  end
+
+  it 'must allow to retrieve single key' do
+    @driver.key(:id => 'test-key').wont_be_nil
+    @driver.key(:id => 'test-key').must_be_kind_of Key
+    @driver.key(:id => 'test-key').id.must_equal 'test-key'
+    @driver.key(:id => 'unknown').must_be_nil
+  end
+
+  it 'must allow to create a new key' 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'
+    @driver.destroy_key :id => key.id
+    @driver.key(:id => key.id).must_be_nil
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ade3d60b/server/tests/drivers/mock/realms_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/mock/realms_test.rb b/server/tests/drivers/mock/realms_test.rb
new file mode 100644
index 0000000..046e5b5
--- /dev/null
+++ b/server/tests/drivers/mock/realms_test.rb
@@ -0,0 +1,37 @@
+require 'minitest/autorun'
+
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
+
+describe 'MockDriver Realms' do
+
+  before do
+    @driver = Deltacloud::new(:mock, :user => 'mockuser', :password => 'mockpassword')
+  end
+
+  it 'must throw error when wrong credentials' do
+    Proc.new do
+      @driver.backend.realms(OpenStruct.new(:user => 'unknown', :password => 'wrong'))
+    end.must_raise Deltacloud::ExceptionHandler::AuthenticationFailure, 'Authentication Failure'
+  end
+
+  it 'must return list of realms' do
+    @driver.realms.wont_be_empty
+    @driver.realms.first.must_be_kind_of Realm
+  end
+
+  it 'must allow to filter realms' do
+    @driver.realms(:id => 'us').wont_be_empty
+    @driver.realms(:id => 'us').must_be_kind_of Array
+    @driver.realms(:id => 'us').size.must_equal 1
+    @driver.realms(:id => 'us').first.id.must_equal 'us'
+    @driver.realms(:id => 'unknown').must_be_empty
+  end
+
+  it 'must allow to retrieve single realm' do
+    @driver.realm(:id => 'us').wont_be_nil
+    @driver.realm(:id => 'us').must_be_kind_of Realm
+    @driver.realm(:id => 'us').id.must_equal 'us'
+    @driver.realm(:id => 'unknown').must_be_nil
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ade3d60b/server/tests/drivers/mock/storage_snapshots_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/mock/storage_snapshots_test.rb b/server/tests/drivers/mock/storage_snapshots_test.rb
new file mode 100644
index 0000000..83ab110
--- /dev/null
+++ b/server/tests/drivers/mock/storage_snapshots_test.rb
@@ -0,0 +1,37 @@
+require 'minitest/autorun'
+
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
+
+describe 'MockDriver StorageSnapshots' do
+
+  before do
+    @driver = Deltacloud::new(:mock, :user => 'mockuser', :password => 'mockpassword')
+  end
+
+  it 'must throw error when wrong credentials' do
+    Proc.new do
+      @driver.backend.storage_snapshots(OpenStruct.new(:user => 'unknown', :password =>
'wrong'))
+    end.must_raise Deltacloud::ExceptionHandler::AuthenticationFailure, 'Authentication Failure'
+  end
+
+  it 'must return list of storage_snapshots' do
+    @driver.storage_snapshots.wont_be_empty
+    @driver.storage_snapshots.first.must_be_kind_of StorageSnapshot
+  end
+
+  it 'must allow to filter storage_snapshots' do
+    @driver.storage_snapshots(:id => 'snap1').wont_be_empty
+    @driver.storage_snapshots(:id => 'snap1').must_be_kind_of Array
+    @driver.storage_snapshots(:id => 'snap1').size.must_equal 1
+    @driver.storage_snapshots(:id => 'snap1').first.id.must_equal 'snap1'
+    @driver.storage_snapshots(:id => 'unknown').must_be_empty
+  end
+
+  it 'must allow to retrieve single storage_snapshot' do
+    @driver.storage_snapshot(:id => 'snap1').wont_be_nil
+    @driver.storage_snapshot(:id => 'snap1').must_be_kind_of StorageSnapshot
+    @driver.storage_snapshot(:id => 'snap1').id.must_equal 'snap1'
+    @driver.storage_snapshot(:id => 'unknown').must_be_nil
+  end
+
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ade3d60b/server/tests/drivers/mock/storage_volumes_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/mock/storage_volumes_test.rb b/server/tests/drivers/mock/storage_volumes_test.rb
new file mode 100644
index 0000000..4285d2e
--- /dev/null
+++ b/server/tests/drivers/mock/storage_volumes_test.rb
@@ -0,0 +1,59 @@
+require 'minitest/autorun'
+
+require_relative File.join('..', '..', '..', 'lib', 'deltacloud', 'api.rb')
+
+describe 'MockDriver StorageVolumes' do
+
+  before do
+    @driver = Deltacloud::new(:mock, :user => 'mockuser', :password => 'mockpassword')
+  end
+
+  it 'must throw error when wrong credentials' do
+    Proc.new do
+      @driver.backend.storage_volumes(OpenStruct.new(:user => 'unknown', :password =>
'wrong'))
+    end.must_raise Deltacloud::ExceptionHandler::AuthenticationFailure, 'Authentication Failure'
+  end
+
+  it 'must return list of storage_volumes' do
+    @driver.storage_volumes.wont_be_empty
+    @driver.storage_volumes.first.must_be_kind_of StorageVolume
+  end
+
+  it 'must allow to filter storage_volumes' do
+    @driver.storage_volumes(:id => 'vol1').wont_be_empty
+    @driver.storage_volumes(:id => 'vol1').must_be_kind_of Array
+    @driver.storage_volumes(:id => 'vol1').size.must_equal 1
+    @driver.storage_volumes(:id => 'vol1').first.id.must_equal 'vol1'
+    @driver.storage_volumes(:id => 'unknown').must_be_empty
+  end
+
+  it 'must allow to retrieve single storage_volume' do
+    @driver.storage_volume(:id => 'vol1').wont_be_nil
+    @driver.storage_volume(:id => 'vol1').must_be_kind_of StorageVolume
+    @driver.storage_volume(:id => 'vol1').id.must_equal 'vol1'
+    @driver.storage_volume(:id => 'unknown').must_be_nil
+  end
+
+  it 'must allow to create and destroy the storage volume' do
+    volume = @driver.create_storage_volume(:name => 'Test Volume', :capacity => '100')
+    volume.must_be_kind_of StorageVolume
+    volume.name.must_equal 'Test Volume'
+    volume.capacity.must_equal '100'
+    @driver.destroy_storage_volume(:id => volume.id)
+    @driver.storage_volume(:id => volume.id).must_be_nil
+  end
+
+  it 'must allow to attach and detach storage volume to instance' do
+    volume = @driver.create_storage_volume(:name => 'Test Volume', :capacity => '100')
+    volume.must_be_kind_of StorageVolume
+    @driver.attach_storage_volume(:id => volume.id, :device => '/dev/sda', :instance_id
=> 'inst1')
+    @driver.storage_volume(:id => volume.id).instance_id.must_equal 'inst1'
+    @driver.storage_volume(:id => volume.id).device.must_equal '/dev/sda'
+    @driver.detach_storage_volume(:id => volume.id, :instance_id => 'inst1')
+    @driver.storage_volume(:id => volume.id).instance_id.must_be_nil
+    @driver.storage_volume(:id => volume.id).device.must_be_nil
+    @driver.destroy_storage_volume(:id => volume.id)
+    @driver.storage_volume(:id => volume.id).must_be_nil
+  end
+
+end


Mime
View raw message