diff --git a/.gitignore b/.gitignore index 8dd0ec74a..ef087879f 100644 --- a/.gitignore +++ b/.gitignore @@ -22,5 +22,3 @@ spec/credentials.yml vendor/* tags tests/digitalocean/fixtures/ -tests/vcloud_director/fixtures/vcloud/v1.5/schema/*.xsd -tests/vcloud_director/vcr_cassettes/ diff --git a/fog.gemspec b/fog.gemspec index 1cc46377a..c1b594885 100644 --- a/fog.gemspec +++ b/fog.gemspec @@ -65,7 +65,6 @@ Gem::Specification.new do |s| s.add_development_dependency('fission') s.add_development_dependency('pry') s.add_development_dependency('google-api-client', '~>0.6.2') - s.add_development_dependency('vcr', '~>2.6') s.add_development_dependency('webmock', '~>1.14') # s.add_development_dependency('ruby-libvirt','~>0.4.0') diff --git a/tests/vcloud_director/models/compute/catalog_items_tests.rb b/tests/vcloud_director/models/compute/catalog_items_tests.rb index fe1440c46..035a5d55f 100644 --- a/tests/vcloud_director/models/compute/catalog_items_tests.rb +++ b/tests/vcloud_director/models/compute/catalog_items_tests.rb @@ -1,42 +1,39 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'helper')) -VCR.use_cassette(File.basename(__FILE__)) do +Shindo.tests("Compute::VcloudDirector | catalog_items", ['vclouddirector', 'all']) do + pending if Fog.mocking? + tests("#There is more than one catalog").returns(true){ catalog.catalog_items.size >= 1 } - Shindo.tests("Compute::VcloudDirector | catalog_items", ['vclouddirector', 'all']) do - pending if Fog.mocking? - tests("#There is more than one catalog").returns(true){ catalog.catalog_items.size >= 1 } + catalog_items = catalog.catalog_items + catalog_item = catalog_items.first - catalog_items = catalog.catalog_items - catalog_item = catalog_items.first + tests("Compute::VcloudDirector | catalog_item") do + tests("#id").returns(String){ catalog_item.id.class } + tests("#name").returns(String){ catalog_item.name.class } + tests("#href").returns(String){ catalog_item.href.class } + tests("#type").returns("application/vnd.vmware.vcloud.catalogItem+xml"){ catalog_item.type } + end - tests("Compute::VcloudDirector | catalog_item") do - tests("#id").returns(String){ catalog_item.id.class } - tests("#name").returns(String){ catalog_item.name.class } - tests("#href").returns(String){ catalog_item.href.class } - tests("#type").returns("application/vnd.vmware.vcloud.catalogItem+xml"){ catalog_item.type } - end - - tests("Compute::VcloudDirector | catalog_item", ['lazy load attrs']) do - catalog_item.lazy_load_attrs.each do |lazy_attr| - tests("##{lazy_attr} is not loaded yet").returns(NonLoaded) { catalog_item.attributes[lazy_attr] } - end - end - - tests("Compute::VcloudDirector | catalog_item", ['load on demand']) do - tests("#description is not loaded yet").returns(NonLoaded) { catalog_item.attributes[:description] } - tests("#description is loaded on demand").returns(String) { catalog_item.description.class } - tests("#description is now loaded").returns(true) { catalog_item.attributes[:description] != NonLoaded } - end - - tests("Compute::VcloudDirector | catalog_item", ['lazy load attrs']) do - catalog.lazy_load_attrs.each do |lazy_attr| - tests("##{lazy_attr} is now loaded").returns(true) { catalog_item.attributes[lazy_attr] != NonLoaded } - end - end - - tests("Compute::VcloudDirector | catalog_item", ['get']) do - tests("#get_by_name").returns(catalog_item.name) { catalog_items.get_by_name(catalog_item.name).name } - tests("#get").returns(catalog_item.id) { catalog_items.get(catalog_item.id).id } + tests("Compute::VcloudDirector | catalog_item", ['lazy load attrs']) do + catalog_item.lazy_load_attrs.each do |lazy_attr| + tests("##{lazy_attr} is not loaded yet").returns(NonLoaded) { catalog_item.attributes[lazy_attr] } end end + + tests("Compute::VcloudDirector | catalog_item", ['load on demand']) do + tests("#description is not loaded yet").returns(NonLoaded) { catalog_item.attributes[:description] } + tests("#description is loaded on demand").returns(String) { catalog_item.description.class } + tests("#description is now loaded").returns(true) { catalog_item.attributes[:description] != NonLoaded } + end + + tests("Compute::VcloudDirector | catalog_item", ['lazy load attrs']) do + catalog.lazy_load_attrs.each do |lazy_attr| + tests("##{lazy_attr} is now loaded").returns(true) { catalog_item.attributes[lazy_attr] != NonLoaded } + end + end + + tests("Compute::VcloudDirector | catalog_item", ['get']) do + tests("#get_by_name").returns(catalog_item.name) { catalog_items.get_by_name(catalog_item.name).name } + tests("#get").returns(catalog_item.id) { catalog_items.get(catalog_item.id).id } + end end diff --git a/tests/vcloud_director/models/compute/catalogs_tests.rb b/tests/vcloud_director/models/compute/catalogs_tests.rb index de01afe9e..bd9d3313e 100644 --- a/tests/vcloud_director/models/compute/catalogs_tests.rb +++ b/tests/vcloud_director/models/compute/catalogs_tests.rb @@ -1,42 +1,39 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'helper')) -VCR.use_cassette(File.basename(__FILE__)) do +Shindo.tests("Compute::VcloudDirector | catalogs", ['vclouddirector', 'all']) do + pending if Fog.mocking? + tests("#There is one or more catalog").returns(true){ organization.catalogs.size >= 1 } - Shindo.tests("Compute::VcloudDirector | catalogs", ['vclouddirector', 'all']) do - pending if Fog.mocking? - tests("#There is one or more catalog").returns(true){ organization.catalogs.size >= 1 } + catalogs = organization.catalogs + catalog = catalogs.first - catalogs = organization.catalogs - catalog = catalogs.first + tests("Compute::VcloudDirector | catalog") do + tests("#id").returns(String){ catalog.id.class } + tests("#name").returns(String){ catalog.name.class } + tests("#href").returns(String){ catalog.href.class } + tests("#type").returns("application/vnd.vmware.vcloud.catalog+xml"){ catalog.type } + end - tests("Compute::VcloudDirector | catalog") do - tests("#id").returns(String){ catalog.id.class } - tests("#name").returns(String){ catalog.name.class } - tests("#href").returns(String){ catalog.href.class } - tests("#type").returns("application/vnd.vmware.vcloud.catalog+xml"){ catalog.type } - end - - tests("Compute::VcloudDirector | catalog", ['lazy load attrs']) do - catalog.lazy_load_attrs.each do |lazy_attr| - tests("##{lazy_attr} is not loaded yet").returns(NonLoaded) { catalog.attributes[lazy_attr] } - end - end - - tests("Compute::VcloudDirector | catalog", ['load on demand']) do - tests("#description is not loaded yet").returns(NonLoaded) { catalog.attributes[:description] } - tests("#description is loaded on demand").returns(String) { catalog.description.class } - tests("#description is now loaded").returns(true) { catalog.attributes[:description] != NonLoaded } - end - - tests("Compute::VcloudDirector | catalog", ['lazy load attrs']) do - catalog.lazy_load_attrs.each do |lazy_attr| - tests("##{lazy_attr} is now loaded").returns(true) { catalog.attributes[lazy_attr] != NonLoaded } - end - end - - tests("Compute::VcloudDirector | catalog", ['get']) do - tests("#get_by_name").returns(catalog.name) { catalogs.get_by_name(catalog.name).name } - tests("#get").returns(catalog.id) { catalogs.get(catalog.id).id } + tests("Compute::VcloudDirector | catalog", ['lazy load attrs']) do + catalog.lazy_load_attrs.each do |lazy_attr| + tests("##{lazy_attr} is not loaded yet").returns(NonLoaded) { catalog.attributes[lazy_attr] } end end + + tests("Compute::VcloudDirector | catalog", ['load on demand']) do + tests("#description is not loaded yet").returns(NonLoaded) { catalog.attributes[:description] } + tests("#description is loaded on demand").returns(String) { catalog.description.class } + tests("#description is now loaded").returns(true) { catalog.attributes[:description] != NonLoaded } + end + + tests("Compute::VcloudDirector | catalog", ['lazy load attrs']) do + catalog.lazy_load_attrs.each do |lazy_attr| + tests("##{lazy_attr} is now loaded").returns(true) { catalog.attributes[lazy_attr] != NonLoaded } + end + end + + tests("Compute::VcloudDirector | catalog", ['get']) do + tests("#get_by_name").returns(catalog.name) { catalogs.get_by_name(catalog.name).name } + tests("#get").returns(catalog.id) { catalogs.get(catalog.id).id } + end end diff --git a/tests/vcloud_director/models/compute/helper.rb b/tests/vcloud_director/models/compute/helper.rb index f0708eaf9..3a6c5a616 100644 --- a/tests/vcloud_director/models/compute/helper.rb +++ b/tests/vcloud_director/models/compute/helper.rb @@ -1,12 +1,5 @@ -require 'vcr' require 'fog/vcloud_director/compute' -VCR.configure do |c| - c.cassette_library_dir = 'tests/vcloud_director/vcr_cassettes' - c.hook_into :webmock - c.allow_http_connections_when_no_cassette = true -end - def boolean?(item) [TrueClass, FalseClass].include?(item.class) end diff --git a/tests/vcloud_director/models/compute/media_tests.rb b/tests/vcloud_director/models/compute/media_tests.rb index b854dba87..23dae7382 100644 --- a/tests/vcloud_director/models/compute/media_tests.rb +++ b/tests/vcloud_director/models/compute/media_tests.rb @@ -1,48 +1,45 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'helper')) -VCR.use_cassette(File.basename(__FILE__)) do +Shindo.tests('Compute::VcloudDirector | media', ['vclouddirector']) do + pending if Fog.mocking? - Shindo.tests('Compute::VcloudDirector | media', ['vclouddirector']) do - pending if Fog.mocking? + medias = vdc.medias + pending if medias.all.empty? + media = medias.first - medias = vdc.medias - pending if medias.all.empty? - media = medias.first + tests('Compute::VcloudDirector | media') do + tests('#href').returns(String) { media.href.class } + tests('#type').returns('application/vnd.vmware.vcloud.media+xml') { media.type } + tests('#id').returns(String) { media.id.class } + tests('#name').returns(String) { media.name.class } + end - tests('Compute::VcloudDirector | media') do - tests('#href').returns(String) { media.href.class } - tests('#type').returns('application/vnd.vmware.vcloud.media+xml') { media.type } - tests('#id').returns(String) { media.id.class } - tests('#name').returns(String) { media.name.class } - end - - tests('Compute::VcloudDirector | media', ['lazy load attrs']) do - media.lazy_load_attrs.each do |lazy_attr| - tests("##{lazy_attr} is not loaded yet").returns(NonLoaded) { media.attributes[lazy_attr] } - end - end - - tests('Compute::VcloudDirector | media', ['load on demand']) do - tests("#description is not loaded yet").returns(NonLoaded) { media.attributes[:description] } - tests("#description is loaded on demand").returns(String) { media.description.class } - tests("#description is now loaded").returns(true) { media.attributes[:description] != NonLoaded } - end - - tests('Compute::VcloudDirector | media', ['lazy load attrs']) do - media.lazy_load_attrs.each do |lazy_attr| - tests("##{lazy_attr} is now loaded").returns(true) { media.attributes[lazy_attr] != NonLoaded } - end - end - - tests('Compute::VcloudDirector | media' ['attributes']) do - tests('#status').returns(Fixnum) { media.status.class } - tests('#image_type').returns(String) { media.image_type.class } - tests('#size').returns(Fixnum) { media.size.class } - end - - tests('Compute::VcloudDirector | media', ['get']) do - tests('#get_by_name').returns(media.name) { medias.get_by_name(media.name).name } - tests('#get').returns(media.id) { medias.get(media.id).id } + tests('Compute::VcloudDirector | media', ['lazy load attrs']) do + media.lazy_load_attrs.each do |lazy_attr| + tests("##{lazy_attr} is not loaded yet").returns(NonLoaded) { media.attributes[lazy_attr] } end end + + tests('Compute::VcloudDirector | media', ['load on demand']) do + tests("#description is not loaded yet").returns(NonLoaded) { media.attributes[:description] } + tests("#description is loaded on demand").returns(String) { media.description.class } + tests("#description is now loaded").returns(true) { media.attributes[:description] != NonLoaded } + end + + tests('Compute::VcloudDirector | media', ['lazy load attrs']) do + media.lazy_load_attrs.each do |lazy_attr| + tests("##{lazy_attr} is now loaded").returns(true) { media.attributes[lazy_attr] != NonLoaded } + end + end + + tests('Compute::VcloudDirector | media' ['attributes']) do + tests('#status').returns(Fixnum) { media.status.class } + tests('#image_type').returns(String) { media.image_type.class } + tests('#size').returns(Fixnum) { media.size.class } + end + + tests('Compute::VcloudDirector | media', ['get']) do + tests('#get_by_name').returns(media.name) { medias.get_by_name(media.name).name } + tests('#get').returns(media.id) { medias.get(media.id).id } + end end diff --git a/tests/vcloud_director/models/compute/organizations_tests.rb b/tests/vcloud_director/models/compute/organizations_tests.rb index 408c9e77b..08983fc9c 100644 --- a/tests/vcloud_director/models/compute/organizations_tests.rb +++ b/tests/vcloud_director/models/compute/organizations_tests.rb @@ -1,22 +1,18 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'helper')) -VCR.use_cassette(File.basename(__FILE__)) do +Shindo.tests("Compute::VcloudDirector | organizations", ['vclouddirector', 'all']) do + organizations = vcloud_director.organizations + tests("#There is at least one organization").returns(true) { organizations.size >= 1 } - Shindo.tests("Compute::VcloudDirector | organizations", ['vclouddirector', 'all']) do - organizations = vcloud_director.organizations - tests("#There is at least one organization").returns(true) { organizations.size >= 1 } + org = organizations.get_by_name(vcloud_director.org_name) - org = organizations.get_by_name(vcloud_director.org_name) - - tests("Compute::VcloudDirector | organization") do - tests("#name").returns(String) { org.name.class } - tests("#type").returns("application/vnd.vmware.vcloud.org+xml") { org.type } - end - - tests("Compute::VcloudDirector | organization", ['get']) do - tests("#get_by_name").returns(org.name) { organizations.get_by_name(org.name).name } - tests("#get").returns(org.id) { organizations.get(org.id).id } - end + tests("Compute::VcloudDirector | organization") do + tests("#name").returns(String) { org.name.class } + tests("#type").returns("application/vnd.vmware.vcloud.org+xml") { org.type } end + tests("Compute::VcloudDirector | organization", ['get']) do + tests("#get_by_name").returns(org.name) { organizations.get_by_name(org.name).name } + tests("#get").returns(org.id) { organizations.get(org.id).id } + end end diff --git a/tests/vcloud_director/models/compute/tasks_tests.rb b/tests/vcloud_director/models/compute/tasks_tests.rb index 448cd7bd9..50880d7db 100644 --- a/tests/vcloud_director/models/compute/tasks_tests.rb +++ b/tests/vcloud_director/models/compute/tasks_tests.rb @@ -1,29 +1,26 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'helper')) -VCR.use_cassette(File.basename(__FILE__)) do +Shindo.tests('Compute::VcloudDirector | tasks', ['vclouddirector']) do + pending if Fog.mocking? - Shindo.tests('Compute::VcloudDirector | tasks', ['vclouddirector']) do - pending if Fog.mocking? + tasks = organization.tasks + pending if tasks.empty? + task = tasks.first - tasks = organization.tasks - pending if tasks.empty? - task = tasks.first + tests('Compute::VcloudDirector | task') do + tests('#href').returns(String) { task.href.class } + tests('#type').returns('application/vnd.vmware.vcloud.task+xml') { task.type } + tests('#id').returns(String) { task.id.class } + tests('#name').returns(String) { task.name.class } + tests('#status').returns(String) { task.status.class } + tests('#end_time').returns(Fog::Time) { task.end_time.class } + tests('#expiry_time').returns(Fog::Time) { task.expiry_time.class } + tests('#operation').returns(String) { task.operation.class } + tests('#operation_name').returns(String) { task.operation_name.class } + end - tests('Compute::VcloudDirector | task') do - tests('#href').returns(String) { task.href.class } - tests('#type').returns('application/vnd.vmware.vcloud.task+xml') { task.type } - tests('#id').returns(String) { task.id.class } - tests('#name').returns(String) { task.name.class } - tests('#status').returns(String) { task.status.class } - tests('#end_time').returns(Fog::Time) { task.end_time.class } - tests('#expiry_time').returns(Fog::Time) { task.expiry_time.class } - tests('#operation').returns(String) { task.operation.class } - tests('#operation_name').returns(String) { task.operation_name.class } - end - - tests('Compute::VcloudDirector | task', ['get']) do - tests('#get_by_name').returns(task.name) { tasks.get_by_name(task.name).name } - tests('#get').returns(task.id) { tasks.get(task.id).id } - end + tests('Compute::VcloudDirector | task', ['get']) do + tests('#get_by_name').returns(task.name) { tasks.get_by_name(task.name).name } + tests('#get').returns(task.id) { tasks.get(task.id).id } end end diff --git a/tests/vcloud_director/models/compute/vapp_life_cycle_tests.rb b/tests/vcloud_director/models/compute/vapp_life_cycle_tests.rb index 2d73f481f..23df1de1b 100644 --- a/tests/vcloud_director/models/compute/vapp_life_cycle_tests.rb +++ b/tests/vcloud_director/models/compute/vapp_life_cycle_tests.rb @@ -1,6 +1,5 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'helper')) - VAPP_NAME = "shindo07" NETWORK_NAME = "DevOps - Dev Network Connection" NETWORK_MODE = "POOL" @@ -8,91 +7,87 @@ CATALOG_NAME = "Public VM Templates" CATALOG_ITEM_NAME = "DEVWEB" TAGS = { :company => "acme", :environment => "testing" } - -VCR.use_cassette(File.basename(__FILE__)) do - - Shindo.tests("Compute::VcloudDirector | vapp", ['vclouddirector', 'creation']) do - pending if Fog.mocking? - pending # FIXME: vCloud environment needs to be set up in advance - tests("#it creates a vApp from a catalog item").returns(true){ the_catalog_item.instantiate(VAPP_NAME, { :network_id => the_network.id, :network_name => NETWORK_NAME}) } - vapp = vapps.get_by_name(VAPP_NAME) - tests("#Finds the just created vApp").returns(VAPP_NAME) { vapp.name } - tests("#it has one vm").returns(1) { vapp.vms.size} - tests("Compute::VcloudDirector | vm", ['configuration']) do - vm = vapp.vms.first - tests("Compute::VcloudDirector | vm", ['network']) do - network = vm.network - network.network = NETWORK_NAME - network.is_connected = true - network.ip_address_allocation_mode = NETWORK_MODE - tests("save network changes").returns(true){ network.save } - network.reload - tests("#network").returns(NETWORK_NAME) { network.network } - tests("#is_connected").returns(true) { network.is_connected } - tests("#ip_address_allocation_mode").returns(NETWORK_MODE) { network.ip_address_allocation_mode } - end - - tests("Compute::VcloudDirector | vm", ['customization']) do - customization = vm.customization - customization.script = 'this is the user data' - customization.enabled = true - tests("save customization changes").returns(true){ customization.save } - tests("#script").returns('this is the user data') { customization.script } - tests("#enabled").returns(true) { customization.enabled } - end - - tests("Compute::VcloudDirector | vm", ['doble the disk size']) do - disk = vm.disks.get_by_name('Hard disk 1') - tests("#disk_size").returns(Fixnum) { disk.capacity.class} - new_size = disk.capacity * 2 - disk.capacity = new_size - disk.reload - tests("#disk_size is now doubled").returns(new_size) { disk.capacity } - end - - tests("Compute::VcloudDirector | vm", ['add a new disk']) do - tests("hard disk 2 doesn't exist").returns(nil) { vm.disks.get_by_name('Hard disk 2') } - tests("#create").returns(true) { vm.disks.create(1024) } - tests("hard disk 2 exists").returns(1024) { vm.disks.get_by_name('Hard disk 2').capacity } - tests("delete disk 2").returns(true) { vm.disks.get_by_name('Hard disk 2').destroy } - tests("hard disk 2 doesn't exist anymore").returns(nil) { vm.disks.get_by_name('Hard disk 2') } - end - - tests("Compute::VcloudDirector | vm", ['doble the memory size']) do - tests("#memory").returns(Fixnum) { vm.memory.class} - new_size = vm.memory * 2 - vm.memory = new_size - vm.reload - tests("#memory is now doubled").returns(new_size) { vm.memory } - end - - tests("Compute::VcloudDirector | vm", ['doble the cpu size']) do - tests("#cpu").returns(Fixnum) { vm.cpu.class} - new_size = vm.cpu * 2 - vm.cpu = new_size - vm.reload - tests("#memory is now doubled").returns(new_size) { vm.cpu } - end - - tests("Compute::VcloudDirector | vm", ['tags']) do - TAGS.each_pair do |k,v| - tests('create tag').returns(true) {vm.tags.create(k, v)} - end - tests('there are two tags').returns(2){ vm.tags.size } - tests('#get_by_name').returns("acme"){ vm.tags.get_by_name('company').value } - tests('#get_by_name').returns("testing"){ vm.tags.get_by_name('environment').value } - tests('delete company').returns(true){ vm.tags.get_by_name('company').destroy } - tests("company doesn't exists anymore").returns(nil){ vm.tags.get_by_name('company') } - tests('there is only one tag').returns(1){ vm.tags.size } - end - - tests("Compute::VcloudDirector | vm", ['power on']) do - tests('#vm is off').returns("off"){ vm.status } - tests('#power_on').returns(true){ vm.power_on } - vm.reload - tests('#vm is on').returns("on"){ vm.status } - end - +Shindo.tests("Compute::VcloudDirector | vapp", ['vclouddirector', 'creation']) do + pending if Fog.mocking? + pending # FIXME: vCloud environment needs to be set up in advance + tests("#it creates a vApp from a catalog item").returns(true){ the_catalog_item.instantiate(VAPP_NAME, { :network_id => the_network.id, :network_name => NETWORK_NAME}) } + vapp = vapps.get_by_name(VAPP_NAME) + tests("#Finds the just created vApp").returns(VAPP_NAME) { vapp.name } + tests("#it has one vm").returns(1) { vapp.vms.size} + tests("Compute::VcloudDirector | vm", ['configuration']) do + vm = vapp.vms.first + tests("Compute::VcloudDirector | vm", ['network']) do + network = vm.network + network.network = NETWORK_NAME + network.is_connected = true + network.ip_address_allocation_mode = NETWORK_MODE + tests("save network changes").returns(true){ network.save } + network.reload + tests("#network").returns(NETWORK_NAME) { network.network } + tests("#is_connected").returns(true) { network.is_connected } + tests("#ip_address_allocation_mode").returns(NETWORK_MODE) { network.ip_address_allocation_mode } end + + tests("Compute::VcloudDirector | vm", ['customization']) do + customization = vm.customization + customization.script = 'this is the user data' + customization.enabled = true + tests("save customization changes").returns(true){ customization.save } + tests("#script").returns('this is the user data') { customization.script } + tests("#enabled").returns(true) { customization.enabled } + end + + tests("Compute::VcloudDirector | vm", ['doble the disk size']) do + disk = vm.disks.get_by_name('Hard disk 1') + tests("#disk_size").returns(Fixnum) { disk.capacity.class} + new_size = disk.capacity * 2 + disk.capacity = new_size + disk.reload + tests("#disk_size is now doubled").returns(new_size) { disk.capacity } + end + + tests("Compute::VcloudDirector | vm", ['add a new disk']) do + tests("hard disk 2 doesn't exist").returns(nil) { vm.disks.get_by_name('Hard disk 2') } + tests("#create").returns(true) { vm.disks.create(1024) } + tests("hard disk 2 exists").returns(1024) { vm.disks.get_by_name('Hard disk 2').capacity } + tests("delete disk 2").returns(true) { vm.disks.get_by_name('Hard disk 2').destroy } + tests("hard disk 2 doesn't exist anymore").returns(nil) { vm.disks.get_by_name('Hard disk 2') } + end + + tests("Compute::VcloudDirector | vm", ['doble the memory size']) do + tests("#memory").returns(Fixnum) { vm.memory.class} + new_size = vm.memory * 2 + vm.memory = new_size + vm.reload + tests("#memory is now doubled").returns(new_size) { vm.memory } + end + + tests("Compute::VcloudDirector | vm", ['doble the cpu size']) do + tests("#cpu").returns(Fixnum) { vm.cpu.class} + new_size = vm.cpu * 2 + vm.cpu = new_size + vm.reload + tests("#memory is now doubled").returns(new_size) { vm.cpu } + end + + tests("Compute::VcloudDirector | vm", ['tags']) do + TAGS.each_pair do |k,v| + tests('create tag').returns(true) {vm.tags.create(k, v)} + end + tests('there are two tags').returns(2){ vm.tags.size } + tests('#get_by_name').returns("acme"){ vm.tags.get_by_name('company').value } + tests('#get_by_name').returns("testing"){ vm.tags.get_by_name('environment').value } + tests('delete company').returns(true){ vm.tags.get_by_name('company').destroy } + tests("company doesn't exists anymore").returns(nil){ vm.tags.get_by_name('company') } + tests('there is only one tag').returns(1){ vm.tags.size } + end + + tests("Compute::VcloudDirector | vm", ['power on']) do + tests('#vm is off').returns("off"){ vm.status } + tests('#power_on').returns(true){ vm.power_on } + vm.reload + tests('#vm is on').returns("on"){ vm.status } + end + end end diff --git a/tests/vcloud_director/models/compute/vapp_tests.rb b/tests/vcloud_director/models/compute/vapp_tests.rb index 136677c98..c15333dce 100644 --- a/tests/vcloud_director/models/compute/vapp_tests.rb +++ b/tests/vcloud_director/models/compute/vapp_tests.rb @@ -1,42 +1,39 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'helper')) -VCR.use_cassette(File.basename(__FILE__)) do +Shindo.tests("Compute::VcloudDirector | vapps", ['vclouddirector', 'all']) do + pending if Fog.mocking? + tests("#There is more than one vapp").returns(true){ vdc.vapps.size >= 1 } - Shindo.tests("Compute::VcloudDirector | vapps", ['vclouddirector', 'all']) do - pending if Fog.mocking? - tests("#There is more than one vapp").returns(true){ vdc.vapps.size >= 1 } + vapps = vdc.vapps + vapp = vapps.first - vapps = vdc.vapps - vapp = vapps.first + tests("Compute::VcloudDirector | vapp") do + tests("#id").returns(String){ vapp.id.class } + tests("#name").returns(String){ vapp.name.class } + tests("#href").returns(String){ vapp.href.class } + tests("#type").returns("application/vnd.vmware.vcloud.vApp+xml"){ vapp.type } + end - tests("Compute::VcloudDirector | vapp") do - tests("#id").returns(String){ vapp.id.class } - tests("#name").returns(String){ vapp.name.class } - tests("#href").returns(String){ vapp.href.class } - tests("#type").returns("application/vnd.vmware.vcloud.vApp+xml"){ vapp.type } - end - - tests("Compute::VcloudDirector | vapp", ['lazy load attrs']) do - vapp.lazy_load_attrs.each do |lazy_attr| - tests("##{lazy_attr} is not loaded yet").returns(NonLoaded) { vapp.attributes[lazy_attr] } - end - end - - tests("Compute::VcloudDirector | vapp", ['load on demand']) do - tests("#description is not loaded yet").returns(NonLoaded) { vapp.attributes[:description] } - tests("#description is loaded on demand").returns(String) { vapp.description.class } - tests("#description is now loaded").returns(true) { vapp.attributes[:description] != NonLoaded } - end - - tests("Compute::VcloudDirector | vapp", ['lazy load attrs']) do - vapp.lazy_load_attrs.each do |lazy_attr| - tests("##{lazy_attr} is now loaded").returns(true) { vapp.attributes[lazy_attr] != NonLoaded } - end - end - - tests("Compute::VcloudDirector | vapp", ['get']) do - tests("#get_by_name").returns(vapp.name) { vapps.get_by_name(vapp.name).name } - tests("#get").returns(vapp.id) { vapps.get(vapp.id).id } + tests("Compute::VcloudDirector | vapp", ['lazy load attrs']) do + vapp.lazy_load_attrs.each do |lazy_attr| + tests("##{lazy_attr} is not loaded yet").returns(NonLoaded) { vapp.attributes[lazy_attr] } end end + + tests("Compute::VcloudDirector | vapp", ['load on demand']) do + tests("#description is not loaded yet").returns(NonLoaded) { vapp.attributes[:description] } + tests("#description is loaded on demand").returns(String) { vapp.description.class } + tests("#description is now loaded").returns(true) { vapp.attributes[:description] != NonLoaded } + end + + tests("Compute::VcloudDirector | vapp", ['lazy load attrs']) do + vapp.lazy_load_attrs.each do |lazy_attr| + tests("##{lazy_attr} is now loaded").returns(true) { vapp.attributes[lazy_attr] != NonLoaded } + end + end + + tests("Compute::VcloudDirector | vapp", ['get']) do + tests("#get_by_name").returns(vapp.name) { vapps.get_by_name(vapp.name).name } + tests("#get").returns(vapp.id) { vapps.get(vapp.id).id } + end end diff --git a/tests/vcloud_director/models/compute/vdcs_tests.rb b/tests/vcloud_director/models/compute/vdcs_tests.rb index 42c4e5542..c8a9f6815 100644 --- a/tests/vcloud_director/models/compute/vdcs_tests.rb +++ b/tests/vcloud_director/models/compute/vdcs_tests.rb @@ -1,45 +1,41 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'helper')) -VCR.use_cassette(File.basename(__FILE__)) do +Shindo.tests("Compute::VcloudDirector | vdcs", ['vclouddirector', 'all']) do + pending if Fog.mocking? + tests("#There is one or more vdc").returns(true){ organization.vdcs.size >= 1 } - Shindo.tests("Compute::VcloudDirector | vdcs", ['vclouddirector', 'all']) do - pending if Fog.mocking? - tests("#There is one or more vdc").returns(true){ organization.vdcs.size >= 1 } + vdcs = organization.vdcs + vdc = vdcs.first - vdcs = organization.vdcs - vdc = vdcs.first + tests("Compute::VcloudDirector | vdc") do + tests("#id").returns(String) { vdc.id.class } + tests("#name").returns(String) { vdc.name.class } + tests("#href").returns(String) { vdc.href.class } + tests("#type").returns("application/vnd.vmware.vcloud.vdc+xml") { vdc.type } + end - tests("Compute::VcloudDirector | vdc") do - tests("#id").returns(String) { vdc.id.class } - tests("#name").returns(String) { vdc.name.class } - tests("#href").returns(String) { vdc.href.class } - tests("#type").returns("application/vnd.vmware.vcloud.vdc+xml") { vdc.type } - end - - tests("Compute::VcloudDirector | vdc", ['lazy load attrs']) do - vdc.lazy_load_attrs.each do |lazy_attr| - tests("##{lazy_attr} is not loaded yet").returns(NonLoaded) { vdc.attributes[lazy_attr] } - end - end - - tests("Compute::VcloudDirector | vdc", ['load on demand']) do - tests("#description is not loaded yet").returns(NonLoaded) { vdc.attributes[:description] } - tests("#description is loaded on demand").returns(String) { vdc.description.class } - tests("#description is now loaded").returns(true) { vdc.attributes[:description] != NonLoaded } - end - - tests("Compute::VcloudDirector | vdc", ['lazy load attrs']) do - lazy_attrs = vdc.lazy_load_attrs - lazy_attrs.delete(:storage_capacity) if vcloud_director.api_version.to_f >= 5.1 - lazy_attrs.each do |lazy_attr| - tests("##{lazy_attr} is now loaded").returns(true) { vdc.attributes[lazy_attr] != NonLoaded } - end - end - - tests("Compute::VcloudDirector | vdc", ['get']) do - tests("#get_by_name").returns(vdc.name) { vdcs.get_by_name(vdc.name).name } - tests("#get").returns(vdc.id) { vdcs.get(vdc.id).id } + tests("Compute::VcloudDirector | vdc", ['lazy load attrs']) do + vdc.lazy_load_attrs.each do |lazy_attr| + tests("##{lazy_attr} is not loaded yet").returns(NonLoaded) { vdc.attributes[lazy_attr] } end end + tests("Compute::VcloudDirector | vdc", ['load on demand']) do + tests("#description is not loaded yet").returns(NonLoaded) { vdc.attributes[:description] } + tests("#description is loaded on demand").returns(String) { vdc.description.class } + tests("#description is now loaded").returns(true) { vdc.attributes[:description] != NonLoaded } + end + + tests("Compute::VcloudDirector | vdc", ['lazy load attrs']) do + lazy_attrs = vdc.lazy_load_attrs + lazy_attrs.delete(:storage_capacity) if vcloud_director.api_version.to_f >= 5.1 + lazy_attrs.each do |lazy_attr| + tests("##{lazy_attr} is now loaded").returns(true) { vdc.attributes[lazy_attr] != NonLoaded } + end + end + + tests("Compute::VcloudDirector | vdc", ['get']) do + tests("#get_by_name").returns(vdc.name) { vdcs.get_by_name(vdc.name).name } + tests("#get").returns(vdc.id) { vdcs.get(vdc.id).id } + end end diff --git a/tests/vcloud_director/models/compute/vms_tests.rb b/tests/vcloud_director/models/compute/vms_tests.rb index 6db3eaf99..151ff6fab 100644 --- a/tests/vcloud_director/models/compute/vms_tests.rb +++ b/tests/vcloud_director/models/compute/vms_tests.rb @@ -1,89 +1,85 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'helper')) -VCR.use_cassette(File.basename(__FILE__)) do +Shindo.tests("Compute::VcloudDirector | vms", ['vclouddirector', 'all']) do + pending if Fog.mocking? + vapp = vapps.detect {|v| v.vms.size >= 1} - Shindo.tests("Compute::VcloudDirector | vms", ['vclouddirector', 'all']) do - pending if Fog.mocking? - vapp = vapps.detect {|v| v.vms.size >= 1} - - tests("#There is more than one vm").returns(true){ vapp.vms.size >= 1 } - - vms = vapp.vms - vm = vms.first - - tests("Compute::VcloudDirector | vm") do - tests("#model").returns(Fog::Compute::VcloudDirector::Vm){vm.class} - tests("#id").returns(String){ vm.id.class } - tests("#name").returns(String){ vm.name.class } - tests("#href").returns(String){ vm.href.class } - tests("#type").returns("application/vnd.vmware.vcloud.vm+xml"){ vm.type } - tests("#vapp_id").returns(String){ vm.vapp_id.class } - tests("#status").returns(String){ vm.status.class } - tests("#operating_system").returns(String){ vm.operating_system.class } - tests("#ip_address").returns(String){ vm.ip_address.class } - tests("#cpu").returns(Fixnum){ vm.cpu.class } - tests("#memory").returns(Fixnum){ vm.memory.class } - tests("#hard_disks").returns(Array){ vm.hard_disks.class } - end - - tests("Compute::VcloudDirector | vm", ['get']) do - tests("#get_by_name").returns(vm.name) { vms.get_by_name(vm.name).name } - tests("#get").returns(vm.id) { vms.get(vm.id).id } - end - - tests("Compute::VcloudDirector | vm | disks") do - tests("#collection").returns(Fog::Compute::VcloudDirector::Disks){ vm.disks.class } - tests("#get_by_name").returns(Fog::Compute::VcloudDirector::Disk) { vm.disks.get_by_name("Hard disk 1").class } - - hard_disk = vm.disks.get_by_name("Hard disk 1") - tests("#id").returns(2000){ hard_disk.id } - tests("#name").returns("Hard disk 1"){ hard_disk.name } - tests("#description").returns("Hard disk"){ hard_disk.description } - tests("#resource_type").returns(17){ hard_disk.resource_type } - tests("#address_on_parent").returns(0){ hard_disk.address_on_parent } - tests("#parent").returns(2){ hard_disk.parent } - tests("#capacity").returns(Fixnum){ hard_disk.capacity.class } - tests("#bus_sub_type").returns(String){ hard_disk.bus_sub_type.class } - tests("#bus_type").returns(6){ hard_disk.bus_type } - end - - tests("Compute::VcloudDirector | vm | customization") do - customization = vm.customization - tests("#model").returns(Fog::Compute::VcloudDirector::VmCustomization){customization.class} - tests("#id").returns(String){ customization.id.class } - tests("#href").returns(String){ customization.href.class } - tests("#type").returns("application/vnd.vmware.vcloud.guestCustomizationSection+xml"){ customization.type } - tests("#virtual_machine_id").returns(String){ customization.virtual_machine_id.class } - tests("#computer_name").returns(String){ customization.computer_name.class } - tests("#enabled").returns(true){ boolean? customization.enabled } - tests("#change_sid").returns(true){ boolean? customization.change_sid } - tests("#join_domain_enabled").returns(true){ boolean? customization.join_domain_enabled } - tests("#use_org_settings").returns(true){ boolean? customization.use_org_settings } - tests("#admin_password_enabled").returns(true){ boolean? customization.admin_password_enabled } - tests("#reset_password_required").returns(true){ boolean? customization.reset_password_required } - end - - tests("Compute::VcloudDirector | vm | network") do - network = vm.network - tests("#model").returns(Fog::Compute::VcloudDirector::VmNetwork){network.class} - tests("#id").returns(String){ network.id.class } - tests("#href").returns(String){ network.href.class } - tests("#type").returns("application/vnd.vmware.vcloud.networkConnectionSection+xml"){ network.type } - tests("#info").returns(String){ network.info.class } - tests("#primary_network_connection_index").returns(Fixnum){ network.primary_network_connection_index.class } - tests("#network").returns(String){ network.network.class } - tests("#network_connection_index").returns(Fixnum){ network.network_connection_index.class } - tests("#mac_address").returns(String){ network.mac_address.class } - tests("#ip_address_allocation_mode").returns(String){ network.ip_address_allocation_mode.class } - tests("#needs_customization").returns(true){ boolean? network.needs_customization } - tests("#is_connected").returns(true){ boolean? network.is_connected } - end - - tests("Compute::VcloudDirector | vm | tags") do - tags = vm.tags - tests("#collection").returns(Fog::Compute::VcloudDirector::Tags){ tags.class } - end + tests("#There is more than one vm").returns(true){ vapp.vms.size >= 1 } + vms = vapp.vms + vm = vms.first + tests("Compute::VcloudDirector | vm") do + tests("#model").returns(Fog::Compute::VcloudDirector::Vm){vm.class} + tests("#id").returns(String){ vm.id.class } + tests("#name").returns(String){ vm.name.class } + tests("#href").returns(String){ vm.href.class } + tests("#type").returns("application/vnd.vmware.vcloud.vm+xml"){ vm.type } + tests("#vapp_id").returns(String){ vm.vapp_id.class } + tests("#status").returns(String){ vm.status.class } + tests("#operating_system").returns(String){ vm.operating_system.class } + tests("#ip_address").returns(String){ vm.ip_address.class } + tests("#cpu").returns(Fixnum){ vm.cpu.class } + tests("#memory").returns(Fixnum){ vm.memory.class } + tests("#hard_disks").returns(Array){ vm.hard_disks.class } end + + tests("Compute::VcloudDirector | vm", ['get']) do + tests("#get_by_name").returns(vm.name) { vms.get_by_name(vm.name).name } + tests("#get").returns(vm.id) { vms.get(vm.id).id } + end + + tests("Compute::VcloudDirector | vm | disks") do + tests("#collection").returns(Fog::Compute::VcloudDirector::Disks){ vm.disks.class } + tests("#get_by_name").returns(Fog::Compute::VcloudDirector::Disk) { vm.disks.get_by_name("Hard disk 1").class } + + hard_disk = vm.disks.get_by_name("Hard disk 1") + tests("#id").returns(2000){ hard_disk.id } + tests("#name").returns("Hard disk 1"){ hard_disk.name } + tests("#description").returns("Hard disk"){ hard_disk.description } + tests("#resource_type").returns(17){ hard_disk.resource_type } + tests("#address_on_parent").returns(0){ hard_disk.address_on_parent } + tests("#parent").returns(2){ hard_disk.parent } + tests("#capacity").returns(Fixnum){ hard_disk.capacity.class } + tests("#bus_sub_type").returns(String){ hard_disk.bus_sub_type.class } + tests("#bus_type").returns(6){ hard_disk.bus_type } + end + + tests("Compute::VcloudDirector | vm | customization") do + customization = vm.customization + tests("#model").returns(Fog::Compute::VcloudDirector::VmCustomization){customization.class} + tests("#id").returns(String){ customization.id.class } + tests("#href").returns(String){ customization.href.class } + tests("#type").returns("application/vnd.vmware.vcloud.guestCustomizationSection+xml"){ customization.type } + tests("#virtual_machine_id").returns(String){ customization.virtual_machine_id.class } + tests("#computer_name").returns(String){ customization.computer_name.class } + tests("#enabled").returns(true){ boolean? customization.enabled } + tests("#change_sid").returns(true){ boolean? customization.change_sid } + tests("#join_domain_enabled").returns(true){ boolean? customization.join_domain_enabled } + tests("#use_org_settings").returns(true){ boolean? customization.use_org_settings } + tests("#admin_password_enabled").returns(true){ boolean? customization.admin_password_enabled } + tests("#reset_password_required").returns(true){ boolean? customization.reset_password_required } + end + + tests("Compute::VcloudDirector | vm | network") do + network = vm.network + tests("#model").returns(Fog::Compute::VcloudDirector::VmNetwork){network.class} + tests("#id").returns(String){ network.id.class } + tests("#href").returns(String){ network.href.class } + tests("#type").returns("application/vnd.vmware.vcloud.networkConnectionSection+xml"){ network.type } + tests("#info").returns(String){ network.info.class } + tests("#primary_network_connection_index").returns(Fixnum){ network.primary_network_connection_index.class } + tests("#network").returns(String){ network.network.class } + tests("#network_connection_index").returns(Fixnum){ network.network_connection_index.class } + tests("#mac_address").returns(String){ network.mac_address.class } + tests("#ip_address_allocation_mode").returns(String){ network.ip_address_allocation_mode.class } + tests("#needs_customization").returns(true){ boolean? network.needs_customization } + tests("#is_connected").returns(true){ boolean? network.is_connected } + end + + tests("Compute::VcloudDirector | vm | tags") do + tags = vm.tags + tests("#collection").returns(Fog::Compute::VcloudDirector::Tags){ tags.class } + end + end diff --git a/tests/vcloud_director/models/tools/reduced_vcr_requests.rb b/tests/vcloud_director/models/tools/reduced_vcr_requests.rb deleted file mode 100755 index 98626190f..000000000 --- a/tests/vcloud_director/models/tools/reduced_vcr_requests.rb +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/local/bin/ruby - -# TO FIX: it reduces the number of requests but it make the tests to faile -require 'yaml' -PATH = ARGV.shift -vcr_cassete = YAML.load_file(PATH) - -@num_request = 0 -@pending_requests = {} - -reduced_requests = vcr_cassete["http_interactions"].reject do |i| - @num_request += 1 - if i["response"]["body"]["string"] =~ /running/ && i["response"]["headers"]["Content-Type"].to_s == 'application/vnd.vmware.vcloud.task+xml;version=1.5' - @pending_requests[@num_request]=true - @pending_requests[@num_request] && @pending_requests[@num_request-1] && @pending_requests[@num_request-2] - else - @pending_requests[@num_request]=false - end -end - -cleaned = vcr_cassete["http_interactions"].size - reduced_requests.size -puts "cleaned: #{cleaned} requests" - -vcr_cassete["http_interactions"] = reduced_requests - -File.open(PATH, 'w') {|f| f.write(vcr_cassete.to_yaml) } -