2012-04-02 07:25:03 -04:00
|
|
|
|
|
|
|
Shindo.tests('Fog::Compute[:xenserver] | server model', ['xenserver']) do
|
|
|
|
|
2012-04-04 13:48:21 -04:00
|
|
|
connection = Fog::Compute[:xenserver]
|
|
|
|
servers = connection.servers
|
2012-04-02 07:25:03 -04:00
|
|
|
# pre-flight cleanup
|
|
|
|
(servers.all :name_matches => test_ephemeral_vm_name).each do |s|
|
|
|
|
s.destroy
|
|
|
|
end
|
2012-04-13 06:44:49 -04:00
|
|
|
(servers.templates.find_all { |t| t.name == test_ephemeral_vm_name}).each do |s|
|
|
|
|
s.destroy
|
|
|
|
end
|
2013-07-30 13:01:35 -04:00
|
|
|
|
|
|
|
server = Fog::Compute[:xenserver].servers.create(:name => test_ephemeral_vm_name,
|
2012-04-02 07:25:03 -04:00
|
|
|
:template_name => test_template_name)
|
2012-04-04 03:01:55 -04:00
|
|
|
server.reload
|
2012-04-02 07:25:03 -04:00
|
|
|
|
|
|
|
tests('The server model should') do
|
|
|
|
tests('have the action') do
|
|
|
|
test('reload') { server.respond_to? 'reload' }
|
2012-04-13 06:44:49 -04:00
|
|
|
%w{ affinity set_attribute refresh stop clean_shutdown hard_shutdown start destroy reboot hard_reboot clean_reboot }.each do |action|
|
2012-04-02 07:25:03 -04:00
|
|
|
test(action) { server.respond_to? action }
|
|
|
|
#test("#{action} returns successfully") { server.send(action.to_sym) ? true : false }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
tests('have attributes') do
|
|
|
|
model_attribute_hash = server.attributes
|
2013-07-30 13:01:35 -04:00
|
|
|
attributes = [
|
2012-04-02 07:25:03 -04:00
|
|
|
:reference,
|
|
|
|
:uuid,
|
|
|
|
:is_a_template,
|
2012-04-13 06:44:49 -04:00
|
|
|
:__affinity,
|
2012-04-02 07:25:03 -04:00
|
|
|
:allowed_operations,
|
2013-07-30 13:01:35 -04:00
|
|
|
:__consoles,
|
2012-04-02 07:25:03 -04:00
|
|
|
:domarch,
|
|
|
|
:domid,
|
2012-04-04 03:01:55 -04:00
|
|
|
:__guest_metrics,
|
2012-04-02 07:25:03 -04:00
|
|
|
:is_a_snapshot,
|
|
|
|
:is_a_template,
|
|
|
|
:is_control_domain,
|
|
|
|
:memory_dynamic_max,
|
|
|
|
:memory_dynamic_min,
|
|
|
|
:memory_static_max,
|
|
|
|
:memory_static_min,
|
|
|
|
:memory_target,
|
|
|
|
:metrics,
|
|
|
|
:name_description,
|
|
|
|
:other_config,
|
|
|
|
:power_state,
|
2013-07-30 13:01:35 -04:00
|
|
|
:pv_args,
|
2012-04-04 03:01:55 -04:00
|
|
|
:__resident_on,
|
2013-07-30 13:01:35 -04:00
|
|
|
:__vbds,
|
2012-04-13 06:44:49 -04:00
|
|
|
:__vifs,
|
|
|
|
:vcpus_params,
|
|
|
|
:vcpus_at_startup,
|
|
|
|
:vcpus_max,
|
|
|
|
:hvm_boot_policy,
|
|
|
|
:hvm_boot_params,
|
|
|
|
:pci_bus,
|
|
|
|
:pv_kernel,
|
|
|
|
:pv_ramdisk,
|
|
|
|
:pv_legacy_args,
|
2013-06-25 00:33:44 -04:00
|
|
|
:pv_bootloader_args,
|
|
|
|
:snapshots
|
2012-04-02 07:25:03 -04:00
|
|
|
]
|
|
|
|
tests("The server model should respond to") do
|
|
|
|
attributes.each do |attribute|
|
|
|
|
test("#{attribute}") { server.respond_to? attribute }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
tests("The attributes hash should have key") do
|
|
|
|
attributes.each do |attribute|
|
|
|
|
test("#{attribute}") { model_attribute_hash.has_key? attribute }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test('be a kind of Fog::Compute::XenServer::Server') { server.kind_of? Fog::Compute::XenServer::Server }
|
2012-04-13 06:44:49 -04:00
|
|
|
#test('return a Fog::Compute::XenServer::Host affinity') { server.affinity.kind_of? Fog::Compute::XenServer::Host }
|
2012-04-02 07:25:03 -04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2012-04-04 13:48:21 -04:00
|
|
|
tests("Creating a server") do
|
|
|
|
tests("it should create a server") do
|
|
|
|
s = nil
|
2012-04-09 06:36:08 -04:00
|
|
|
test("named #{test_ephemeral_vm_name}") do
|
2013-07-30 13:01:35 -04:00
|
|
|
s = servers.create(:name => test_ephemeral_vm_name,
|
2012-04-04 13:48:21 -04:00
|
|
|
:template_name => test_template_name)
|
2012-04-09 06:36:08 -04:00
|
|
|
servers.get(s.reference).name == test_ephemeral_vm_name
|
2012-04-04 13:48:21 -04:00
|
|
|
end
|
|
|
|
test("and destroy it afterwards") { s.destroy }
|
|
|
|
end
|
|
|
|
tests("it should create a server") do
|
|
|
|
s = nil
|
2012-04-09 06:36:08 -04:00
|
|
|
# The template has 2 VIFs already, we add 2 more
|
|
|
|
test("with 4 NICs") do
|
2013-07-30 13:01:35 -04:00
|
|
|
s = servers.create(:name => test_ephemeral_vm_name,
|
2012-04-04 13:48:21 -04:00
|
|
|
:template_name => test_template_name,
|
2012-04-09 06:36:08 -04:00
|
|
|
:networks => [connection.default_network, connection.default_network])
|
2012-04-04 13:48:21 -04:00
|
|
|
s.reload
|
2012-04-09 06:36:08 -04:00
|
|
|
s.networks.size == 4
|
2012-04-04 13:48:21 -04:00
|
|
|
end
|
|
|
|
test("and destroy it afterwards") { s.destroy }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
tests("A real server should") do
|
|
|
|
tests("return valid vbds") do
|
|
|
|
test("as an array") { server.vbds.kind_of? Array }
|
2013-07-30 13:01:35 -04:00
|
|
|
server.vbds.each { |i|
|
|
|
|
test("and each VBD should be a Fog::Compute::XenServer::VBD") { i.kind_of? Fog::Compute::XenServer::VBD }
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('return valid consoles') do
|
|
|
|
test('as an array') { server.consoles.kind_of? Array }
|
|
|
|
server.consoles.each { |i|
|
|
|
|
test('and each Console should be a Fog::Compute::XenServer::Console') { i.kind_of? Fog::Compute::XenServer::Console }
|
|
|
|
}
|
2012-04-02 07:25:03 -04:00
|
|
|
end
|
2012-04-04 13:48:21 -04:00
|
|
|
|
|
|
|
test("have 0 or more networks") { server.networks.kind_of? Array }
|
|
|
|
|
|
|
|
tests("have networks if networks > 0") do
|
|
|
|
if server.networks.size > 0
|
|
|
|
server.networks.each do |n|
|
|
|
|
test("and network is of type Fog::Compute::XenServer::Network") do
|
|
|
|
n.kind_of? Fog::Compute::XenServer::Network
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-04-04 03:01:55 -04:00
|
|
|
test("reside on a Fog::Compute::XenServer::Host") { server.resident_on.kind_of? Fog::Compute::XenServer::Host }
|
|
|
|
#test("have Fog::Compute::XenServer::GuestMetrics") { server.guest_metrics.kind_of? Fog::Compute::XenServer::GuestMetrics }
|
2012-04-02 07:25:03 -04:00
|
|
|
test("be able to refresh itself") { server.refresh }
|
|
|
|
|
|
|
|
test("always stop when I say stop('hard')") do
|
|
|
|
server.stop 'hard'
|
|
|
|
end
|
2013-07-30 13:01:35 -04:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
# shutdown is async apparently, we wait
|
|
|
|
test("not be running when it's stopped") do
|
|
|
|
server.wait_for { !server.running? }
|
|
|
|
true
|
|
|
|
end
|
2013-07-30 13:01:35 -04:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
test("do nothing when I say stop('hard') but it's not running") do
|
|
|
|
server.stop('hard') == false
|
|
|
|
end
|
2013-07-30 13:01:35 -04:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
test("always start when I say start") do
|
|
|
|
server.start
|
|
|
|
end
|
2013-07-30 13:01:35 -04:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
# start is async apparently, we wait
|
|
|
|
test("be running if I started the server") do
|
|
|
|
server.wait_for { server.running? }
|
|
|
|
true
|
|
|
|
end
|
2013-07-30 13:01:35 -04:00
|
|
|
|
2012-04-12 07:17:58 -04:00
|
|
|
test("set attribute PV_bootloader to supergrub") do
|
|
|
|
server.set_attribute 'PV_bootloader', 'supergrub'
|
|
|
|
server.reload
|
|
|
|
server.pv_bootloader == 'supergrub'
|
|
|
|
end
|
2013-07-30 13:01:35 -04:00
|
|
|
|
2013-06-25 00:33:44 -04:00
|
|
|
tests("Creating a snapshot") do
|
2013-06-28 18:16:45 -04:00
|
|
|
snap_ref = server.snapshot('newsnapshot')
|
2013-06-25 00:33:44 -04:00
|
|
|
tests("it should create a snapshot") do
|
|
|
|
snap_ref = server.snapshot('newsnapshot')
|
|
|
|
servers.get(snap_ref).reference == snap_ref
|
|
|
|
end
|
2013-06-28 18:16:45 -04:00
|
|
|
test("and destroy it afterwards") { servers.get(snap_ref).destroy }
|
2013-06-25 00:33:44 -04:00
|
|
|
end
|
2013-07-30 13:01:35 -04:00
|
|
|
|
2013-06-28 18:16:45 -04:00
|
|
|
test("be able to be destroyed!") do
|
|
|
|
server.destroy
|
|
|
|
servers.get_by_name('fog-test-server-shindo') == nil
|
|
|
|
end
|
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|