fixes for shared server specs, and get them passing for rackspace

This commit is contained in:
Wesley Beary 2010-01-12 22:00:49 -08:00
parent 63d939f6ed
commit 15df1eb96e
5 changed files with 85 additions and 21 deletions

View File

@ -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

View File

@ -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

View File

@ -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',

View File

@ -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

View File

@ -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
subject.wait_for { ready? }
@reloaded = subject.reload
end
subject.attributes.should == @reloaded.attributes
end
@ -33,10 +33,9 @@ shared_examples_for "Server" do
it "should exist remotely after save" do
subject.save
eventually do
subject.wait_for { ready? }
@servers.get(subject.id).should_not be_nil
end
end
end