From 15df1eb96eee6cc8474297a716ba55a5c4ccdb05 Mon Sep 17 00:00:00 2001 From: Wesley Beary Date: Tue, 12 Jan 2010 22:00:49 -0800 Subject: [PATCH] fixes for shared server specs, and get them passing for rackspace --- lib/fog/rackspace/models/servers/server.rb | 29 +++++++---- lib/fog/rackspace/models/servers/servers.rb | 4 +- spec/aws/models/ec2/server_spec.rb | 5 +- spec/rackspace/models/servers/server_spec.rb | 51 ++++++++++++++++++++ spec/shared_examples/server_examples.rb | 17 +++---- 5 files changed, 85 insertions(+), 21 deletions(-) create mode 100644 spec/rackspace/models/servers/server_spec.rb diff --git a/lib/fog/rackspace/models/servers/server.rb b/lib/fog/rackspace/models/servers/server.rb index e01fcd8b5..293b0bd08 100644 --- a/lib/fog/rackspace/models/servers/server.rb +++ b/lib/fog/rackspace/models/servers/server.rb @@ -6,33 +6,44 @@ module Fog identity :id - attribute :admin_pass, 'adminPass' - attribute :name - attribute :image_id, 'imageId' + attribute :addresses + attribute :password, 'adminPass' attribute :flavor_id, 'flavorId' attribute :host_id, 'hostId' - attribute :status + attribute :image_id, 'imageId' + attribute :metadata + attribute :name attribute :personality attribute :progress - attribute :addresses - attribute :metadata + attribute :status def destroy requires :id - connection.delete_server(@id) true end + def flavor + requires :flavor_id + connection.flavors.get(@flavor_id) + end + + def image + requires :image_id + connection.images.get(@image_id) + end + def images requires :id - connection.images(:server => self) end + def ready? + @status == 'ACTIVE' + end + def reboot(type = 'SOFT') requires :id - connection.reboot_server(@id, type) true end diff --git a/lib/fog/rackspace/models/servers/servers.rb b/lib/fog/rackspace/models/servers/servers.rb index bccf42bdc..9f9c8b7b6 100644 --- a/lib/fog/rackspace/models/servers/servers.rb +++ b/lib/fog/rackspace/models/servers/servers.rb @@ -23,7 +23,9 @@ module Fog end def get(server_id) - connection.get_server_details(server_id) + if server = connection.get_server_details(server_id).body['server'] + new(server) + end rescue Excon::Errors::NotFound nil end diff --git a/spec/aws/models/ec2/server_spec.rb b/spec/aws/models/ec2/server_spec.rb index 10bc9855d..0fc06d010 100644 --- a/spec/aws/models/ec2/server_spec.rb +++ b/spec/aws/models/ec2/server_spec.rb @@ -13,14 +13,15 @@ describe 'Fog::AWS::EC2::Server' do after(:each) do if @server && !@server.new_record? - eventually { @server.destroy } + @server.wait_for { ready? } + @server.destroy.should be_true end end describe "#initialize" do it "should remap attributes from parser" do - server = ec2.servers.new({ + server = @servers.new({ 'amiLaunchIndex' => 'ami_launch_index', 'dnsName' => 'dns_name', 'groupId' => 'group_id', diff --git a/spec/rackspace/models/servers/server_spec.rb b/spec/rackspace/models/servers/server_spec.rb new file mode 100644 index 000000000..2e3c9cb54 --- /dev/null +++ b/spec/rackspace/models/servers/server_spec.rb @@ -0,0 +1,51 @@ +require File.dirname(__FILE__) + '/../../../spec_helper' +require File.dirname(__FILE__) + '/../../../shared_examples/server_examples' + +describe 'Fog::AWS::EC2::Server' do + + it_should_behave_like "Server" + + # flavor 1 = 256, image 3 = gentoo 2008.0 + subject { @server = @servers.new(:flavor_id => 1, :image_id => 3, :name => 'name') } + + before(:each) do + @servers = servers.servers + end + + after(:each) do + if @server && !@server.new_record? + @server.wait_for { ready? } + @server.destroy.should be_true + end + end + + describe "#initialize" do + + it "should remap attributes from parser" do + server = @servers.new({ + 'addresses' => 'addresses', + 'adminPass' => 'password', + 'flavorId' => 'flavor_id', + 'hostId' => 'host_id', + 'imageId' => 'image_id', + 'metadata' => 'metadata', + 'name' => 'name', + 'personality' => 'personality', + 'progress' => 'progress', + 'status' => 'status' + }) + server.addresses.should == 'addresses' + server.password.should == 'password' + server.flavor_id.should == 'flavor_id' + server.host_id.should == 'host_id' + server.image_id.should == 'image_id' + server.metadata.should == 'metadata' + server.name.should == 'name' + server.personality.should == 'personality' + server.progress.should == 'progress' + server.status.should == 'status' + end + + end + +end diff --git a/spec/shared_examples/server_examples.rb b/spec/shared_examples/server_examples.rb index 3b7a02e15..fa0c320ae 100644 --- a/spec/shared_examples/server_examples.rb +++ b/spec/shared_examples/server_examples.rb @@ -1,10 +1,11 @@ shared_examples_for "Server" do - describe "#destroy" do + describe "#reboot" do - it "should return true if the server is deleted" do + it "should succeed" do subject.save - subject.destroy.should be_true + subject.wait_for { ready? } + subject.reboot.should be_true end end @@ -13,9 +14,8 @@ shared_examples_for "Server" do it "should reset attributes to remote state" do subject.save - eventually do - @reloaded = subject.reload - end + subject.wait_for { ready? } + @reloaded = subject.reload subject.attributes.should == @reloaded.attributes end @@ -33,9 +33,8 @@ shared_examples_for "Server" do it "should exist remotely after save" do subject.save - eventually do - @servers.get(subject.id).should_not be_nil - end + subject.wait_for { ready? } + @servers.get(subject.id).should_not be_nil end end