1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

vm and vapp life cycle tests

This commit is contained in:
Rodrigo Estebanez 2013-08-20 13:55:32 +02:00
parent fa7ae92a8b
commit 7a3873d6f0
8 changed files with 6878 additions and 272 deletions

View file

@ -126,6 +126,15 @@ module Fog
end
end
# it adds an attr_loaded? method to know if the value has been loaded yet or not: ie description_loaded?
def make_attr_loaded_method(attr)
self.class.instance_eval do
define_method("#{attr}_loaded?") do
attributes[attr] != NonLoaded
end
end
end
def inspect
@inspecting = true
out = super

View file

@ -6,6 +6,10 @@ VCR.configure do |c|
c.hook_into :webmock
end
def boolean?(item)
[TrueClass, FalseClass].include?(item.class)
end
def vcloudng
@vcloudng ||= Fog::Compute::Vcloudng.new(vcloudng_username: "#{ENV['IMEDIDATA_COM_USERNAME']}@devops",
vcloudng_password: ENV['IMEDIDATA_COM_PASSWORD'],
@ -49,3 +53,17 @@ end
def vapp
vapps.detect {|vapp| vapp.vms.size >= 1 }
end
def the_network
@network ||= organization.networks.get_by_name(NETWORK_NAME)
end
def the_catalog
@catalog ||= organization.catalogs.get_by_name(CATALOG_NAME)
end
def the_catalog_item
return nil unless the_catalog
@catalog_item ||= the_catalog.catalog_items.get_by_name(CATALOG_ITEM_NAME)
end

View file

@ -0,0 +1,94 @@
VAPP_NAME = "shindo02"
NETWORK_NAME = "DevOps - Dev Network Connection"
NETWORK_MODE = "POOL"
CATALOG_NAME = "Public VM Templates"
CATALOG_ITEM_NAME = "DEVWEB"
TAGS = { company: "acme", environment: "testing" }
VCR.use_cassette(File.basename(__FILE__)) do
Shindo.tests("Compute::Vcloudng | vapp", ['creation']) do
pending if Fog.mocking?
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::Vcloudng | vm", ['configuration']) do
vm = vapp.vms.first
tests("Compute::Vcloudng | 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::Vcloudng | 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::Vcloudng | 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::Vcloudng | 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::Vcloudng | 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::Vcloudng | 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::Vcloudng | 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::Vcloudng | 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
end

View file

@ -12,6 +12,7 @@ VCR.use_cassette(File.basename(__FILE__)) do
vm = vms.first
tests("Compute::Vcloudng | vm") do
tests("#model").returns(Fog::Compute::Vcloudng::Vm){vm.class}
tests("#id").returns(String){ vm.id.class }
tests("#name").returns(String){ vm.name.class }
tests("#href").returns(String){ vm.href.class }
@ -25,10 +26,64 @@ VCR.use_cassette(File.basename(__FILE__)) do
tests("#hard_disks").returns(Array){ vm.hard_disks.class }
end
tests("Compute::Vcloudng | 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::Vcloudng | vm | disks") do
tests("#collection").returns(Fog::Compute::Vcloudng::Disks){ vm.disks.class }
tests("#get_by_name").returns(Fog::Compute::Vcloudng::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("lsilogicsas"){ hard_disk.bus_sub_type }
tests("#bus_type").returns(6){ hard_disk.bus_type }
end
tests("Compute::Vcloudng | vm | customization") do
customization = vm.customization
tests("#model").returns(Fog::Compute::Vcloudng::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::Vcloudng | vm | network") do
network = vm.network
tests("#model").returns(Fog::Compute::Vcloudng::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::Vcloudng | vm | tags") do
tags = vm.tags
tests("#collection").returns(Fog::Compute::Vcloudng::Tags){ tags.class }
end
end
end

View file

@ -0,0 +1,27 @@
#!/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) }

View file

@ -0,0 +1,27 @@
#!/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) }

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff