Permalink
Browse files

* [xenserver|compute] set_attribute request now accepts var args

  - added new tests

* [xenserver|compute]  VBD fixes and cleanup
  - VBD.metrics now returns nil when VBD not attached
  - VBD tests fixes and cleanup

* [xenserver|compute] cleanup tests and add new helpers
  • Loading branch information...
1 parent 7ec382c commit 65e1c98c3d79ef7dbd6ebd9dd164ae4e38d7723a @rubiojr rubiojr committed Apr 19, 2012
@@ -77,8 +77,8 @@ def destroy
true
end
- def set_attribute(name, val)
- data = connection.set_attribute( 'VM', reference, name, val )
+ def set_attribute(name, *val)
+ data = connection.set_attribute( 'VM', reference, name, *val )
# Do not reload automatically for performance reasons
# We can set multiple attributes at the same time and
# then reload manually
@@ -70,7 +70,15 @@ def insert(vdi)
connection.insert_vbd reference, vdi.reference
end
+ #
+ # return nil if the VBD is not attached
+ #
+ # TODO: Confirm that the VBD_metrics handle is invalid
+ # when the VBD is NOT attached. I get a HANDLE_INVALID
+ # exception in that case.
+ #
def metrics
+ return nil unless currently_attached
rec = connection.get_record( __metrics, 'VBD_metrics' )
Fog::Compute::XenServer::VbdMetrics.new(rec)
end
@@ -53,8 +53,8 @@ def initialize(attributes = {})
super
end
- def set_attribute(name, val)
- data = connection.set_attribute( 'VDI', reference, name, val )
+ def set_attribute(name, *val)
+ data = connection.set_attribute( 'VDI', reference, name, *val )
end
def snapshot_of
@@ -6,8 +6,8 @@ class Real
require 'fog/xenserver/parser'
- def set_attribute( klass, ref, attr_name, value )
- @connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => "#{klass}.set_#{attr_name.gsub('-','_')}"}, ref, value)
+ def set_attribute( klass, ref, attr_name, *value )
+ @connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => "#{klass}.set_#{attr_name.gsub('-','_')}"}, ref, *value)
end
end
View
@@ -10,3 +10,25 @@ def valid_ref?(ref)
(ref =~ /OpaqueRef:/) and \
(ref != "OpaqueRef:NULL" )
end
+
+def create_ephemeral_vm
+ Fog::Compute[:xenserver].servers.create(:name => test_ephemeral_vm_name,
+ :template_name => test_template_name)
+end
+def create_ephemeral_server
+ create_ephemeral_vm
+end
+
+def destroy_ephemeral_servers
+ servers = Fog::Compute[:xenserver].servers
+ # Teardown cleanup
+ (servers.all :name_matches => test_ephemeral_vm_name).each do |s|
+ s.destroy
+ end
+ (servers.templates.find_all { |t| t.name == test_ephemeral_vm_name}).each do |s|
+ s.destroy
+ end
+end
+def destroy_ephemeral_vms
+ destroy_ephemeral_servers
+end
@@ -1,11 +1,7 @@
Shindo.tests('Fog::Compute[:xenserver] | servers collection', ['xenserver']) do
- #require 'pp'
conn = Fog::Compute[:xenserver]
- # pre-flight cleanup
- (conn.servers.all :name_matches => test_ephemeral_vm_name).each do |s|
- s.destroy
- end
+ destroy_ephemeral_servers
servers = conn.servers
templates = conn.servers.templates
@@ -86,4 +82,7 @@
end
+ # Teardown cleaup
+ destroy_ephemeral_servers
+
end
@@ -2,6 +2,8 @@
vbds = Fog::Compute[:xenserver].vbds
vbd = vbds.first
+ servers = Fog::Compute[:xenserver].servers
+ server = create_ephemeral_vm
tests('The VBD model should') do
tests('have the action') do
@@ -83,15 +85,17 @@
true
end
end
- end
- tests("return a nil when type is CD") do
- vbds.each do |vbd|
+ test("return a VbdMetrics object when attached") do
+ if vbd.currently_attached
+ vbd.metrics.kind_of? Fog::Compute::XenServer::VbdMetrics
+ else
+ vbd.metrics.nil?
+ end
end
end
tests("return valid Server") do
test("should be a Fog::Compute::XenServer::Server") { vbd.server.kind_of? Fog::Compute::XenServer::Server }
end
- test("return a VbdMetrics object") { vbd.metrics.kind_of? Fog::Compute::XenServer::VbdMetrics }
test("be able to be unplugged when type is CD") do
if vbd.type == "CD"
vbd.unpluggable == true
@@ -103,7 +107,9 @@
end
tests("VBD Metrics should") do
- test("have a last_updated Time property") { vbd.metrics.last_updated.kind_of? Time }
+ test("have a last_updated Time property") { server.vbds.first.metrics.last_updated.kind_of? Time }
end
+ destroy_ephemeral_servers
+
end
@@ -1,13 +1,12 @@
Shindo.tests('Fog::Compute[:xenserver] | set_attribute request', ['xenserver']) do
+ # Setup cleanup
+ destroy_ephemeral_servers
+
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)
+ server = create_ephemeral_server
+
tests('Setting an attribute with set_attribute should') do
test('set the PV_bootloader attr to foobar') do
response = connection.set_attribute('VM', server.reference, 'PV_bootloader', 'foobar')
@@ -25,9 +24,33 @@
(server.other_config['foo'] == 'bar') and \
(server.other_config['stuff'] == 'crap')
end
+ test('set the multiple valued attribute memory_limits }') do
+ server = create_ephemeral_server
+ server.stop 'hard'
+ server.wait_for { not running? }
+ response = connection.set_attribute('VM',
+ server.reference,
+ 'memory_limits',
+ '1073741824',
+ '1073741824',
+ '1073741824',
+ '1073741824'
+ )
+ server.reload
+ (server.memory_dynamic_max == "1073741824") and \
+ (server.memory_dynamic_min == "1073741824") and \
+ (server.memory_static_max == "1073741824") and \
+ (server.memory_static_min == "1073741824")
+
+ server.start
+ end
end
tests('The expected options') do
raises(ArgumentError, 'raises ArgumentError when ref,attr,value missing') { connection.get_record }
end
+
+ # Teardown cleanup
+ destroy_ephemeral_servers
+
end

0 comments on commit 65e1c98

Please sign in to comment.