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

* Added set_attribute request and tests

* Added missing PV_bootloaer attribute to Server
* Added Server.set_attribute method and tests
This commit is contained in:
Sergio Rubio 2012-04-12 13:17:58 +02:00
parent 2754694787
commit e269f7d6de
5 changed files with 75 additions and 1 deletions

View file

@ -54,6 +54,7 @@ module Fog
request :get_record
request :get_records
request :set_affinity
request :set_attribute
request :reboot_server
class Real

View file

@ -31,6 +31,7 @@ module Fog
attribute :other_config
attribute :power_state
attribute :pv_args, :aliases => :PV_args
attribute :pv_bootloader, :aliases => :PV_bootloader
attribute :__resident_on, :aliases => :resident_on
# Virtual Block Devices
attribute :__vbds, :aliases => :VBDs
@ -63,6 +64,14 @@ module Fog
connection.destroy_server( reference )
true
end
def set_attribute(name, val)
data = connection.set_attribute( reference, name, val )
# Do not reload automatically for performance reasons
# We can set multiple attributes at the same time and
# then reload manually
#reload
end
def refresh
data = connection.get_record( reference, 'VM' )

View file

@ -0,0 +1,25 @@
module Fog
module Compute
class XenServer
class Real
require 'fog/xenserver/parser'
def set_attribute( ref, attr_name, value )
@connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => "VM.set_#{attr_name.gsub('-','_')}"}, ref, value)
end
end
class Mock
def set_attribute( ref, attr_name, value )
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -15,7 +15,7 @@ Shindo.tests('Fog::Compute[:xenserver] | server model', ['xenserver']) do
tests('The server model should') do
tests('have the action') do
test('reload') { server.respond_to? 'reload' }
%w{ refresh stop clean_shutdown hard_shutdown start destroy reboot hard_reboot clean_reboot }.each do |action|
%w{ set_attribute refresh stop clean_shutdown hard_shutdown start destroy reboot hard_reboot clean_reboot }.each do |action|
test(action) { server.respond_to? action }
#test("#{action} returns successfully") { server.send(action.to_sym) ? true : false }
end
@ -139,6 +139,12 @@ Shindo.tests('Fog::Compute[:xenserver] | server model', ['xenserver']) do
true
end
test("set attribute PV_bootloader to supergrub") do
server.set_attribute 'PV_bootloader', 'supergrub'
server.reload
server.pv_bootloader == 'supergrub'
end
test("be able to be destroyed!") do
server.destroy
servers.get_by_name('fog-test-server-shindo') == nil

View file

@ -0,0 +1,33 @@
Shindo.tests('Fog::Compute[:xenserver] | set_attribute request', ['xenserver']) do
connection = Fog::Compute[:xenserver]
servers = connection.servers
# pre-flight cleanup
(servers.all :name_matches => test_ephemeral_vm_name).each do |s|
s.destroy
end
server = Fog::Compute[:xenserver].servers.create(:name => test_ephemeral_vm_name,
:template_name => test_template_name)
tests('Setting an attribute with set_attribute should') do
test('set the PV_bootloader attr to foobar') do
response = connection.set_attribute(server.reference, 'PV_bootloader', 'foobar')
server.reload
server.pv_bootloader == 'foobar'
end
test('set the PV-bootloader attr to stuff') do
response = connection.set_attribute(server.reference, 'PV-bootloader', 'stuff')
server.reload
server.pv_bootloader == 'stuff'
end
test('set the other_config attr { "foo" => "bar", :stuff => "crap" }') do
response = connection.set_attribute(server.reference, 'other_config', { "foo" => "bar", :stuff => 'crap' })
server.reload
(server.other_config['foo'] == 'bar') and \
(server.other_config['stuff'] == 'crap')
end
end
tests('The expected options') do
raises(ArgumentError, 'raises ArgumentError when ref,attr,value missing') { connection.get_record }
end
end