mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|compute] move remaining rspec to shindo
This commit is contained in:
parent
c0c474b193
commit
bf7f269ce6
25 changed files with 134 additions and 1065 deletions
|
@ -218,24 +218,18 @@ module Fog
|
|||
#I tried to call it monitoring= and be smart with attributes[]
|
||||
#but in #save a merge_attribute is called after run_instance
|
||||
#thus making an un-necessary request. Use this until finding a clever solution
|
||||
def monitor=(boolean)
|
||||
|
||||
#we don't have a server yet. the status silently goes in the attributes for run_instances
|
||||
if !identity
|
||||
self.monitoring=boolean
|
||||
end
|
||||
|
||||
case boolean
|
||||
def monitor=(new_monitor)
|
||||
if identity
|
||||
case new_monitor
|
||||
when true
|
||||
response = connection.monitor_instances(identity)
|
||||
when false
|
||||
response = connection.unmonitor_instances(identity)
|
||||
else
|
||||
raise ArgumentError.new("only Boolean allowed here")
|
||||
end
|
||||
end
|
||||
|
||||
#set the attribute, there is only one instance_id here
|
||||
response.body['instancesSet'][0]['monitoring'] == 'enabled' ? self.monitoring=true : self.monitoring=false
|
||||
self.monitoring = new_monitor
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,103 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'Fog::AWS::Compute::Address' do
|
||||
|
||||
describe "#initialize" do
|
||||
|
||||
it "should remap attributes from parser" do
|
||||
address = AWS[:compute].addresses.new(
|
||||
'instanceId' => 'i-00000000',
|
||||
'publicIp' => '0.0.0.0'
|
||||
)
|
||||
address.server_id.should == 'i-00000000'
|
||||
address.public_ip.should == '0.0.0.0'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#addresses" do
|
||||
|
||||
it "should return a Fog::AWS::Compute::Addresses" do
|
||||
AWS[:compute].addresses.new.collection.should be_a(Fog::AWS::Compute::Addresses)
|
||||
end
|
||||
|
||||
it "should be the addresses the address is related to" do
|
||||
addresses = AWS[:compute].addresses
|
||||
addresses.new.collection.should == addresses
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#destroy" do
|
||||
|
||||
it "should return true if the address is deleted" do
|
||||
address = AWS[:compute].addresses.create
|
||||
address.destroy.should be_true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#server=" do
|
||||
before(:each) do
|
||||
@address = AWS[:compute].addresses.new
|
||||
@server = AWS[:compute].servers.create(:image_id => GENTOO_AMI)
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
@address.destroy
|
||||
@server.destroy
|
||||
end
|
||||
|
||||
it "should associate with server to an already saved address" do
|
||||
@address.save.should be_true
|
||||
@server.wait_for { state == 'running' }
|
||||
@address.server = @server
|
||||
@address.server_id.should == @server.id
|
||||
end
|
||||
end
|
||||
|
||||
describe "#reload" do
|
||||
|
||||
before(:each) do
|
||||
@address = AWS[:compute].addresses.create
|
||||
@reloaded = @address.reload
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
@address.destroy
|
||||
end
|
||||
|
||||
it "should return a Fog::AWS::Compute::Address" do
|
||||
@reloaded.should be_a(Fog::AWS::Compute::Address)
|
||||
end
|
||||
|
||||
it "should reset attributes to remote state" do
|
||||
@address.attributes.should == @reloaded.attributes
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#save" do
|
||||
|
||||
before(:each) do
|
||||
@address = AWS[:compute].addresses.new
|
||||
end
|
||||
|
||||
it "should return true when it succeeds" do
|
||||
@address.save.should be_true
|
||||
@address.destroy
|
||||
end
|
||||
|
||||
it "should not exist in addresses before save" do
|
||||
@address.collection.get(@address.public_ip).should be_nil
|
||||
end
|
||||
|
||||
it "should exist in buckets after save" do
|
||||
@address.save
|
||||
@address.collection.get(@address.public_ip).should_not be_nil
|
||||
@address.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -1,70 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'Fog::AWS::Compute::Addresses' do
|
||||
|
||||
describe "#all" do
|
||||
|
||||
it "should return a Fog::AWS::Compute::Addresses" do
|
||||
AWS[:compute].addresses.all.should be_a(Fog::AWS::Compute::Addresses)
|
||||
end
|
||||
|
||||
it "should include persisted addresses" do
|
||||
address = AWS[:compute].addresses.create
|
||||
AWS[:compute].addresses.get(address.public_ip).should_not be_nil
|
||||
address.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#create" do
|
||||
|
||||
before(:each) do
|
||||
@address = AWS[:compute].addresses.create
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
@address.destroy
|
||||
end
|
||||
|
||||
it "should return a Fog::AWS::Compute::Address" do
|
||||
@address.should be_a(Fog::AWS::Compute::Address)
|
||||
end
|
||||
|
||||
it "should exist on ec2" do
|
||||
AWS[:compute].addresses.get(@address.public_ip).should_not be_nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#get" do
|
||||
|
||||
it "should return a Fog::AWS::Compute::Address if a matching address exists" do
|
||||
address = AWS[:compute].addresses.create
|
||||
get = AWS[:compute].addresses.get(address.public_ip)
|
||||
address.attributes.should == get.attributes
|
||||
address.destroy
|
||||
end
|
||||
|
||||
it "should return nil if no matching address exists" do
|
||||
AWS[:compute].addresses.get('0.0.0.0').should be_nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#new" do
|
||||
|
||||
it "should return a Fog::AWS::Compute::Address" do
|
||||
AWS[:compute].addresses.new.should be_a(Fog::AWS::Compute::Address)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#reload" do
|
||||
|
||||
it "should return a Fog::AWS::Compute::Addresses" do
|
||||
AWS[:compute].addresses.all.reload.should be_a(Fog::AWS::Compute::Addresses)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -1,86 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'Fog::AWS::Compute::KeyPair' do
|
||||
|
||||
describe "#initialize" do
|
||||
|
||||
it "should remap attributes from parser" do
|
||||
key_pair = AWS[:compute].key_pairs.new(
|
||||
'keyFingerprint' => 'fingerprint',
|
||||
'keyMaterial' => 'material',
|
||||
'keyName' => 'name'
|
||||
)
|
||||
key_pair.fingerprint.should == 'fingerprint'
|
||||
key_pair.private_key.should == 'material'
|
||||
key_pair.name.should == 'name'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#collection" do
|
||||
|
||||
it "should return a Fog::AWS::Compute::KeyPairs" do
|
||||
AWS[:compute].key_pairs.new.collection.should be_a(Fog::AWS::Compute::KeyPairs)
|
||||
end
|
||||
|
||||
it "should be the key_pairs the keypair is related to" do
|
||||
key_pairs = AWS[:compute].key_pairs
|
||||
key_pairs.new.collection.should == key_pairs
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#destroy" do
|
||||
|
||||
it "should return true if the key_pair is deleted" do
|
||||
address = AWS[:compute].key_pairs.create(:name => 'keyname')
|
||||
address.destroy.should be_true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#reload" do
|
||||
|
||||
before(:each) do
|
||||
@key_pair = AWS[:compute].key_pairs.create(:name => 'keyname')
|
||||
@reloaded = @key_pair.reload
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
@key_pair.destroy
|
||||
end
|
||||
|
||||
it "should return a Fog::AWS::Compute::KeyPair" do
|
||||
@reloaded.should be_a(Fog::AWS::Compute::KeyPair)
|
||||
end
|
||||
|
||||
it "should reset attributes to remote state" do
|
||||
@key_pair.attributes.should == @reloaded.attributes
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#save" do
|
||||
|
||||
before(:each) do
|
||||
@key_pair = AWS[:compute].key_pairs.new(:name => 'keyname')
|
||||
end
|
||||
|
||||
it "should return true when it succeeds" do
|
||||
@key_pair.save.should be_true
|
||||
@key_pair.destroy
|
||||
end
|
||||
|
||||
it "should not exist in key_pairs before save" do
|
||||
AWS[:compute].key_pairs.get(@key_pair.name).should be_nil
|
||||
end
|
||||
|
||||
it "should exist in buckets after save" do
|
||||
@key_pair.save
|
||||
AWS[:compute].key_pairs.get(@key_pair.name).should_not be_nil
|
||||
@key_pair.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -1,71 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'Fog::AWS::Compute::KeyPairs' do
|
||||
|
||||
describe "#all" do
|
||||
|
||||
it "should return a Fog::AWS::Compute::KeyPairs" do
|
||||
AWS[:compute].key_pairs.all.should be_a(Fog::AWS::Compute::KeyPairs)
|
||||
end
|
||||
|
||||
it "should include persisted key_pairs" do
|
||||
key_pair = AWS[:compute].key_pairs.create(:name => 'keyname')
|
||||
AWS[:compute].key_pairs.get(key_pair.name).should_not be_nil
|
||||
key_pair.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#create" do
|
||||
|
||||
before(:each) do
|
||||
@key_pair = AWS[:compute].key_pairs.create(:name => 'keyname')
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
@key_pair.destroy
|
||||
end
|
||||
|
||||
it "should return a Fog::AWS::Compute::KeyPair" do
|
||||
@key_pair.should be_a(Fog::AWS::Compute::KeyPair)
|
||||
end
|
||||
|
||||
it "should exist on ec2" do
|
||||
AWS[:compute].key_pairs.get(@key_pair.name).should_not be_nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#get" do
|
||||
|
||||
it "should return a Fog::AWS::Compute::KeyPair if a matching key_pair exists" do
|
||||
key_pair = AWS[:compute].key_pairs.create(:name => 'keyname')
|
||||
get = AWS[:compute].key_pairs.get(key_pair.name)
|
||||
key_pair.attributes[:fingerprint].should == get.attributes[:fingerprint]
|
||||
key_pair.attributes[:name].should == get.attributes[:name]
|
||||
key_pair.destroy
|
||||
end
|
||||
|
||||
it "should return nil if no matching key_pair exists" do
|
||||
AWS[:compute].key_pairs.get('notakeyname').should be_nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#new" do
|
||||
|
||||
it "should return a Fog::AWS::Compute::KeyPair" do
|
||||
AWS[:compute].key_pairs.new(:name => 'keyname').should be_a(Fog::AWS::Compute::KeyPair)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#reload" do
|
||||
|
||||
it "should return a Fog::AWS::Compute::KeyPairs" do
|
||||
AWS[:compute].key_pairs.all.reload.should be_a(Fog::AWS::Compute::KeyPairs)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -1,88 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'Fog::AWS::Compute::SecurityGroup' do
|
||||
|
||||
describe "#initialize" do
|
||||
|
||||
it "should remap attributes from parser" do
|
||||
security_group = AWS[:compute].security_groups.new(
|
||||
'groupDescription' => 'description',
|
||||
'groupName' => 'name',
|
||||
'ipPermissions' => 'permissions',
|
||||
'ownerId' => 'owner'
|
||||
)
|
||||
security_group.description.should == 'description'
|
||||
security_group.name.should == 'name'
|
||||
security_group.ip_permissions.should == 'permissions'
|
||||
security_group.owner_id.should == 'owner'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#collection" do
|
||||
|
||||
it "should return a Fog::AWS::Compute::SecurityGroups" do
|
||||
AWS[:compute].security_groups.new.collection.should be_a(Fog::AWS::Compute::SecurityGroups)
|
||||
end
|
||||
|
||||
it "should be the security_groups the keypair is related to" do
|
||||
security_groups = AWS[:compute].security_groups
|
||||
security_groups.new.collection.should == security_groups
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#destroy" do
|
||||
|
||||
it "should return true if the security_group is deleted" do
|
||||
address = AWS[:compute].security_groups.create(:description => 'groupdescription', :name => 'keyname')
|
||||
address.destroy.should be_true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#reload" do
|
||||
|
||||
before(:each) do
|
||||
@security_group = AWS[:compute].security_groups.create(:description => 'groupdescription', :name => 'keyname')
|
||||
@reloaded = @security_group.reload
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
@security_group.destroy
|
||||
end
|
||||
|
||||
it "should return a Fog::AWS::Compute::SecurityGroup" do
|
||||
@reloaded.should be_a(Fog::AWS::Compute::SecurityGroup)
|
||||
end
|
||||
|
||||
it "should reset attributes to remote state" do
|
||||
@security_group.attributes.should == @reloaded.attributes
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#save" do
|
||||
|
||||
before(:each) do
|
||||
@security_group = AWS[:compute].security_groups.new(:description => 'groupdescription', :name => 'keyname')
|
||||
end
|
||||
|
||||
it "should return true when it succeeds" do
|
||||
@security_group.save.should be_true
|
||||
@security_group.destroy
|
||||
end
|
||||
|
||||
it "should not exist in security_groups before save" do
|
||||
AWS[:compute].security_groups.get(@security_group.name).should be_nil
|
||||
end
|
||||
|
||||
it "should exist in buckets after save" do
|
||||
@security_group.save
|
||||
AWS[:compute].security_groups.get(@security_group.name).should_not be_nil
|
||||
@security_group.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -1,71 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'Fog::AWS::Compute::SecurityGroups' do
|
||||
|
||||
describe "#all" do
|
||||
|
||||
it "should return a Fog::AWS::Compute::SecurityGroups" do
|
||||
AWS[:compute].security_groups.all.should be_a(Fog::AWS::Compute::SecurityGroups)
|
||||
end
|
||||
|
||||
it "should include persisted security_groups" do
|
||||
security_group = AWS[:compute].security_groups.create(:description => 'groupdescription', :name => 'keyname')
|
||||
AWS[:compute].security_groups.get(security_group.name).should_not be_nil
|
||||
security_group.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#create" do
|
||||
|
||||
before(:each) do
|
||||
@security_group = AWS[:compute].security_groups.create(:description => 'groupdescription', :name => 'keyname')
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
@security_group.destroy
|
||||
end
|
||||
|
||||
it "should return a Fog::AWS::Compute::SecurityGroup" do
|
||||
@security_group.should be_a(Fog::AWS::Compute::SecurityGroup)
|
||||
end
|
||||
|
||||
it "should exist on ec2" do
|
||||
AWS[:compute].security_groups.get(@security_group.name).should_not be_nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#get" do
|
||||
|
||||
it "should return a Fog::AWS::Compute::SecurityGroup if a matching security_group exists" do
|
||||
security_group = AWS[:compute].security_groups.create(:description => 'groupdescription', :name => 'keyname')
|
||||
get = AWS[:compute].security_groups.get(security_group.name)
|
||||
security_group.attributes[:fingerprint].should == get.attributes[:fingerprint]
|
||||
security_group.attributes[:name].should == get.attributes[:name]
|
||||
security_group.destroy
|
||||
end
|
||||
|
||||
it "should return nil if no matching security_group exists" do
|
||||
AWS[:compute].security_groups.get('notasecuritygroupname').should be_nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#new" do
|
||||
|
||||
it "should return a Fog::AWS::Compute::SecurityGroup" do
|
||||
AWS[:compute].security_groups.new(:description => 'groupdescription', :name => 'keyname').should be_a(Fog::AWS::Compute::SecurityGroup)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#reload" do
|
||||
|
||||
it "should return a Fog::AWS::Compute::SecurityGroups" do
|
||||
AWS[:compute].security_groups.all.reload.should be_a(Fog::AWS::Compute::SecurityGroups)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -1,105 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'Fog::AWS::Compute::Server' do
|
||||
|
||||
subject { @server = @servers.new(:image_id => GENTOO_AMI) }
|
||||
|
||||
before(:each) do
|
||||
@servers = AWS[:compute].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({
|
||||
'amiLaunchIndex' => 'ami_launch_index',
|
||||
'clientToken' => 'client_token',
|
||||
'dnsName' => 'dns_name',
|
||||
'imageId' => 'image_id',
|
||||
'instanceId' => 'instance_id',
|
||||
'instanceType' => 'instance_type',
|
||||
'kernelId' => 'kernel_id',
|
||||
'keyName' => 'key_name',
|
||||
'launchTime' => 'launch_time',
|
||||
'productCodes' => 'product_codes',
|
||||
'privateDnsName' => 'private_dns_name',
|
||||
'ramdiskId' => 'ramdisk_id'
|
||||
})
|
||||
server.ami_launch_index.should == 'ami_launch_index'
|
||||
server.client_token.should == 'client_token'
|
||||
server.dns_name.should == 'dns_name'
|
||||
server.image_id.should == 'image_id'
|
||||
server.id.should == 'instance_id'
|
||||
server.kernel_id.should == 'kernel_id'
|
||||
server.key_name.should == 'key_name'
|
||||
server.created_at.should == 'launch_time'
|
||||
server.product_codes.should == 'product_codes'
|
||||
server.private_dns_name.should == 'private_dns_name'
|
||||
server.ramdisk_id.should == 'ramdisk_id'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#addresses" do
|
||||
|
||||
it "should return a Fog::AWS::Compute::Addresses" do
|
||||
subject.save
|
||||
subject.addresses.should be_a(Fog::AWS::Compute::Addresses)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#state" do
|
||||
it "should remap values out of hash" do
|
||||
server = Fog::AWS::Compute::Server.new({
|
||||
'instanceState' => { 'name' => 'instance_state' },
|
||||
})
|
||||
server.state.should == 'instance_state'
|
||||
end
|
||||
end
|
||||
|
||||
describe "#key_pair" do
|
||||
it "should have tests"
|
||||
end
|
||||
|
||||
describe "#key_pair=" do
|
||||
it "should have tests"
|
||||
end
|
||||
|
||||
describe "#monitoring=" do
|
||||
it "should remap values out of hash" do
|
||||
server = Fog::AWS::Compute::Server.new({
|
||||
'monitoring' => { 'state' => true }
|
||||
})
|
||||
server.monitoring.should == true
|
||||
end
|
||||
end
|
||||
|
||||
describe "#placement=" do
|
||||
|
||||
it "should remap values into availability_zone" do
|
||||
server = Fog::AWS::Compute::Server.new({
|
||||
'placement' => { 'availabilityZone' => 'availability_zone' }
|
||||
})
|
||||
server.availability_zone.should == 'availability_zone'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#volumes" do
|
||||
|
||||
it "should return a Fog::AWS::Compute::Volumes" do
|
||||
subject.save
|
||||
subject.volumes.should be_a(Fog::AWS::Compute::Volumes)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -1,79 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'Fog::AWS::Compute::Snapshot' do
|
||||
|
||||
before(:all) do
|
||||
@volume = AWS[:compute].volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1')
|
||||
@volume.wait_for { ready? }
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
@volume.destroy
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
if @snapshot && !@snapshot.new_record?
|
||||
@snapshot.wait_for { ready? }
|
||||
@snapshot.destroy
|
||||
end
|
||||
end
|
||||
|
||||
describe "#initialize" do
|
||||
|
||||
it "should remap attributes from parser" do
|
||||
snapshot = AWS[:compute].snapshots.new(
|
||||
'snapshotId' => 'snap-00000000',
|
||||
'startTime' => 'now',
|
||||
'volumeId' => 'vol-00000000',
|
||||
'description' => 'taken for safety'
|
||||
)
|
||||
snapshot.id.should == 'snap-00000000'
|
||||
snapshot.created_at.should == 'now'
|
||||
snapshot.volume_id.should == 'vol-00000000'
|
||||
snapshot.description.should == 'taken for safety'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#destroy" do
|
||||
|
||||
it "should return true if the snapshot is deleted" do
|
||||
@snapshot = @volume.snapshots.create
|
||||
@snapshot.wait_for { ready? }
|
||||
@snapshot.destroy.should be_true
|
||||
@snapshot = nil # avoid the after(:each) block
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#reload" do
|
||||
|
||||
before(:each) do
|
||||
@snapshot = @volume.snapshots.create
|
||||
@reloaded = @snapshot.reload
|
||||
end
|
||||
|
||||
it "should match the original" do
|
||||
@reloaded.should be_a(Fog::AWS::Compute::Snapshot)
|
||||
@reloaded.attributes.should == @snapshot.attributes
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#save" do
|
||||
|
||||
it "should persist the snapshot" do
|
||||
@snapshot = @volume.snapshots.new
|
||||
AWS[:compute].snapshots.get(@snapshot.id).should be_nil
|
||||
@snapshot.save.should be_true
|
||||
AWS[:compute].snapshots.get(@snapshot.id).should_not be_nil
|
||||
end
|
||||
|
||||
it "should allow a description" do
|
||||
@snapshot = @volume.snapshots.create(:description => 'taken for safety')
|
||||
AWS[:compute].snapshots.get(@snapshot.id).description.should == 'taken for safety'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -1,85 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'Fog::AWS::Compute::Snapshots' do
|
||||
|
||||
before(:all) do
|
||||
@volume = AWS[:compute].volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1')
|
||||
@volume.wait_for { ready? }
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
@volume.destroy
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
if @snapshot && !@snapshot.new_record?
|
||||
@snapshot.wait_for { ready? }
|
||||
@snapshot.destroy
|
||||
end
|
||||
end
|
||||
|
||||
describe "#all" do
|
||||
|
||||
before(:each) do
|
||||
@snapshot = @volume.snapshots.create
|
||||
end
|
||||
|
||||
it "should include persisted snapshots" do
|
||||
AWS[:compute].snapshots.all.map {|snapshot| snapshot.id}.should include(@snapshot.id)
|
||||
end
|
||||
|
||||
it "should limit snapshots by volume if present" do
|
||||
@other_volume = AWS[:compute].volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1')
|
||||
|
||||
@volume.snapshots.map {|snapshot| snapshot.id}.should include(@snapshot.identity)
|
||||
@other_volume.snapshots.map {|snapshot| snapshot.id}.should_not include(@snapshot.identity)
|
||||
|
||||
@other_volume.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#create" do
|
||||
|
||||
before(:each) do
|
||||
@snapshot = @volume.snapshots.create
|
||||
end
|
||||
|
||||
it "should exist on ec2" do
|
||||
AWS[:compute].snapshots.get(@snapshot.id).should_not be_nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#get" do
|
||||
|
||||
it "should return a Fog::AWS::Compute::Snapshot if a matching snapshot exists" do
|
||||
@snapshot = @volume.snapshots.create
|
||||
@snapshot.wait_for { ready? }
|
||||
get = AWS[:compute].snapshots.get(@snapshot.id)
|
||||
@snapshot.attributes.should == get.attributes
|
||||
end
|
||||
|
||||
it "should return nil if no matching address exists" do
|
||||
AWS[:compute].snapshots.get('snap-00000000').should be_nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#new" do
|
||||
|
||||
it "should return a Fog::AWS::Compute::Snapshot" do
|
||||
AWS[:compute].snapshots.new.should be_a(Fog::AWS::Compute::Snapshot)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#reload" do
|
||||
|
||||
it "should return a Fog::AWS::Compute::Snapshots" do
|
||||
AWS[:compute].snapshots.all.reload.should be_a(Fog::AWS::Compute::Snapshots)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -1,174 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'Fog::AWS::Compute::Volume' do
|
||||
|
||||
describe "#initialize" do
|
||||
|
||||
it "should remap attributes from parser" do
|
||||
volume = AWS[:compute].volumes.new(
|
||||
'attachTime' => 'now',
|
||||
'availabilityZone' => 'us-east-1a',
|
||||
'createTime' => 'recently',
|
||||
'instanceId' => 'i-00000000',
|
||||
'snapshotId' => 'snap-00000000',
|
||||
'volumeId' => 'vol-00000000'
|
||||
)
|
||||
volume.attached_at.should == 'now'
|
||||
volume.availability_zone.should == 'us-east-1a'
|
||||
volume.created_at.should == 'recently'
|
||||
volume.server_id.should == 'i-00000000'
|
||||
volume.snapshot_id.should == 'snap-00000000'
|
||||
volume.id.should == 'vol-00000000'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#collection" do
|
||||
|
||||
it "should return a Fog::AWS::Compute::Volumes" do
|
||||
AWS[:compute].volumes.new.collection.should be_a(Fog::AWS::Compute::Volumes)
|
||||
end
|
||||
|
||||
it "should be the volumes the volume is related to" do
|
||||
volumes = AWS[:compute].volumes
|
||||
volumes.new.collection.should == volumes
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#destroy" do
|
||||
|
||||
it "should return true if the volume is deleted" do
|
||||
volume = AWS[:compute].volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => '/dev/sdz1')
|
||||
volume.destroy.should be_true
|
||||
end
|
||||
|
||||
it 'should fail if the volume is attached to an instance' do
|
||||
server = AWS[:compute].servers.create(:image_id => GENTOO_AMI)
|
||||
server.wait_for { ready? }
|
||||
volume = AWS[:compute].volumes.create(:availability_zone => server.availability_zone, :size => 1, :device => '/dev/sdz1')
|
||||
volume.server = server
|
||||
lambda { volume.destroy }.should raise_error
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#server=" do
|
||||
before(:all) do
|
||||
@server = AWS[:compute].servers.create(:image_id => GENTOO_AMI)
|
||||
@server.wait_for { ready? }
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
@server.destroy
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
@volume = AWS[:compute].volumes.new(:availability_zone => @server.availability_zone, :size => 1, :device => '/dev/sdz1')
|
||||
end
|
||||
|
||||
describe "when set to a server" do
|
||||
after(:each) do
|
||||
if @volume.id
|
||||
@volume.wait_for { state == 'in-use' }
|
||||
@volume.server = nil
|
||||
@volume.wait_for { ready? }
|
||||
@volume.destroy
|
||||
end
|
||||
end
|
||||
|
||||
it "should not attach to server if the volume has not been saved" do
|
||||
@volume.server = @server
|
||||
@volume.server_id.should_not == @server.id
|
||||
end
|
||||
|
||||
it "should change the availability_zone if the volume has not been saved" do
|
||||
@volume.server = @server
|
||||
@volume.availability_zone.should == @server.availability_zone
|
||||
end
|
||||
|
||||
it "should attach to server when the volume is saved" do
|
||||
@volume.server = @server
|
||||
@volume.save.should be_true
|
||||
@volume.server_id.should == @server.id
|
||||
end
|
||||
|
||||
it "should attach to server to an already saved volume" do
|
||||
@volume.save.should be_true
|
||||
@volume.server = @server
|
||||
@volume.server_id.should == @server.id
|
||||
end
|
||||
|
||||
it "should not change the availability_zone if the volume has been saved" do
|
||||
@volume.save.should be_true
|
||||
@volume.server = @server
|
||||
@volume.availability_zone.should == @server.availability_zone
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "when set to nil" do
|
||||
after(:each) do
|
||||
@volume.destroy
|
||||
end
|
||||
|
||||
it "should detach from server if the volume has been saved" do
|
||||
@volume.server = @server
|
||||
@volume.save.should be_true
|
||||
@server.reload.volumes.map(&:id).should include(@volume.id)
|
||||
|
||||
@volume.server = nil
|
||||
@volume.wait_for { ready? }
|
||||
@volume.server_id.should be_nil
|
||||
@server.reload.volumes.map(&:id).should_not include(@volume.id)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#reload" do
|
||||
|
||||
before(:each) do
|
||||
@volume = AWS[:compute].volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => '/dev/sdz1')
|
||||
@reloaded = @volume.reload
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
@volume.destroy
|
||||
end
|
||||
|
||||
it "should return a Fog::AWS::Compute::Volume" do
|
||||
@reloaded.should be_a(Fog::AWS::Compute::Volume)
|
||||
end
|
||||
|
||||
it "should reset attributes to remote state" do
|
||||
@volume.attributes.should == @reloaded.attributes
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#save" do
|
||||
|
||||
before(:each) do
|
||||
@volume = AWS[:compute].volumes.new(:availability_zone => 'us-east-1a', :size => 1, :device => '/dev/sdz1')
|
||||
end
|
||||
|
||||
it "should return true when it succeeds" do
|
||||
@volume.save.should be_true
|
||||
@volume.destroy
|
||||
end
|
||||
|
||||
it "should not exist in volumes before save" do
|
||||
AWS[:compute].volumes.get(@volume.id).should be_nil
|
||||
end
|
||||
|
||||
it "should exist in buckets after save" do
|
||||
@volume.save
|
||||
AWS[:compute].volumes.get(@volume.id).should_not be_nil
|
||||
@volume.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -1,71 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'Fog::AWS::Compute::Volumes' do
|
||||
|
||||
describe "#all" do
|
||||
|
||||
it "should return a Fog::AWS::Compute::Volumes" do
|
||||
AWS[:compute].volumes.all.should be_a(Fog::AWS::Compute::Volumes)
|
||||
end
|
||||
|
||||
it "should include persisted volumes" do
|
||||
volume = AWS[:compute].volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1')
|
||||
AWS[:compute].volumes.get(volume.id).should_not be_nil
|
||||
volume.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#create" do
|
||||
|
||||
before(:each) do
|
||||
@volume = AWS[:compute].volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1')
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
@volume.destroy
|
||||
end
|
||||
|
||||
it "should return a Fog::AWS::Compute::Volume" do
|
||||
@volume.should be_a(Fog::AWS::Compute::Volume)
|
||||
end
|
||||
|
||||
it "should exist on ec2" do
|
||||
AWS[:compute].volumes.get(@volume.id).should_not be_nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#get" do
|
||||
|
||||
it "should return a Fog::AWS::Compute::Volume if a matching volume exists" do
|
||||
volume = AWS[:compute].volumes.create(:availability_zone => 'us-east-1a', :size => 1)
|
||||
volume.wait_for { ready? }
|
||||
get = AWS[:compute].volumes.get(volume.id)
|
||||
volume.attributes.should == get.attributes
|
||||
volume.destroy
|
||||
end
|
||||
|
||||
it "should return nil if no matching address exists" do
|
||||
AWS[:compute].volumes.get('vol-00000000').should be_nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#new" do
|
||||
|
||||
it "should return a Fog::AWS::Compute::Volume" do
|
||||
AWS[:compute].volumes.new.should be_a(Fog::AWS::Compute::Volume)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#reload" do
|
||||
|
||||
it "should return a Fog::AWS::Compute::Volumes" do
|
||||
AWS[:compute].volumes.all.reload.should be_a(Fog::AWS::Compute::Volumes)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -6,7 +6,3 @@ require 'fog/bin'
|
|||
if ENV["FOG_MOCK"] == "true"
|
||||
Fog.mock!
|
||||
end
|
||||
|
||||
unless defined?(GENTOO_AMI)
|
||||
GENTOO_AMI = 'ami-5ee70037'
|
||||
end
|
||||
|
|
16
tests/compute/models/aws/address_tests.rb
Normal file
16
tests/compute/models/aws/address_tests.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
Shindo.tests("AWS::Compute | address", ['aws']) do
|
||||
|
||||
model_tests(AWS[:compute].addresses, {}, true) do
|
||||
|
||||
@server = AWS[:compute].servers.create(:image_id => GENTOO_AMI)
|
||||
@server.wait_for { ready? }
|
||||
|
||||
tests('#server=').succeeds do
|
||||
@instance.server = @server
|
||||
end
|
||||
|
||||
@server.destroy
|
||||
|
||||
end
|
||||
|
||||
end
|
5
tests/compute/models/aws/addresses_tests.rb
Normal file
5
tests/compute/models/aws/addresses_tests.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
Shindo.tests("AWS::Compute | addresses", ['aws']) do
|
||||
|
||||
collection_tests(AWS[:compute].addresses, {}, true)
|
||||
|
||||
end
|
5
tests/compute/models/aws/key_pair_tests.rb
Normal file
5
tests/compute/models/aws/key_pair_tests.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
Shindo.tests("AWS::Compute | key_pair", ['aws']) do
|
||||
|
||||
model_tests(AWS[:compute].key_pairs, {:name => 'fogkeyname'}, true)
|
||||
|
||||
end
|
5
tests/compute/models/aws/key_pairs_tests.rb
Normal file
5
tests/compute/models/aws/key_pairs_tests.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
Shindo.tests("AWS::Compute | key_pairs", ['aws']) do
|
||||
|
||||
collection_tests(AWS[:compute].key_pairs, {:name => 'fogkeyname'}, true)
|
||||
|
||||
end
|
5
tests/compute/models/aws/security_group_tests.rb
Normal file
5
tests/compute/models/aws/security_group_tests.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
Shindo.tests("AWS::Compute | security_group", ['aws']) do
|
||||
|
||||
model_tests(AWS[:compute].security_groups, {:description => 'foggroupdescription', :name => 'foggroupname'}, true)
|
||||
|
||||
end
|
5
tests/compute/models/aws/security_groups.rb
Normal file
5
tests/compute/models/aws/security_groups.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
Shindo.tests("AWS::Compute | security_groups", ['aws']) do
|
||||
|
||||
collection_tests(AWS[:compute].security_groups, {:description => 'foggroupdescription', :name => 'foggroupname'}, true)
|
||||
|
||||
end
|
|
@ -1,47 +0,0 @@
|
|||
Shindo.tests("AWS::Compute::Server | monitor", ['aws']) do
|
||||
|
||||
config = compute_providers[AWS]
|
||||
|
||||
if !Fog.mocking? || config[:mocked]
|
||||
@instance = AWS[:compute].servers.new(config[:server_attributes])
|
||||
end
|
||||
|
||||
tests('new instance') do
|
||||
|
||||
test('monitor') do
|
||||
@instance.monitoring = true
|
||||
@instance.attributes[:monitoring] == true
|
||||
end
|
||||
|
||||
test('unmonitor') do
|
||||
@instance.monitoring = false
|
||||
@instance.attributes[:monitoring] == false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('existing instance') do
|
||||
|
||||
@instance.save
|
||||
|
||||
test('monitor') do
|
||||
#what I'd really like to test is if connection.monitor_instances is being called
|
||||
#this is a safeguard
|
||||
@instance.identity != nil
|
||||
@instance.monitoring = false
|
||||
@instance.monitor = true
|
||||
@instance.monitoring == true
|
||||
end
|
||||
|
||||
test('unmonitor') do
|
||||
#what I'd really like to test is if connection.monitor_instances is being called
|
||||
#this is a safeguard
|
||||
@instance.identity != nil
|
||||
@instance.monitoring = true
|
||||
@instance.monitor = false
|
||||
@instance.monitoring == false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
39
tests/compute/models/aws/server_tests.rb
Normal file
39
tests/compute/models/aws/server_tests.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
Shindo.tests("AWS::Compute | monitor", ['aws']) do
|
||||
|
||||
[:addresses, :flavor, :key_pair, :key_pair=, :volume].each do |association|
|
||||
responds_to(association)
|
||||
end
|
||||
|
||||
@instance = AWS[:compute].servers.new(:image_id => 'ami-1a837773')
|
||||
|
||||
tests('new instance') do
|
||||
|
||||
test('#monitor = true') do
|
||||
@instance.monitor = true
|
||||
@instance.attributes[:monitoring] == true
|
||||
end
|
||||
|
||||
test('#monitor = false') do
|
||||
@instance.monitor = false
|
||||
@instance.attributes[:monitoring] == false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('existing instance') do
|
||||
|
||||
@instance.save
|
||||
|
||||
test('#monitor = true') do
|
||||
@instance.monitor = true
|
||||
@instance.monitoring == true
|
||||
end
|
||||
|
||||
test('#monitor = false') do
|
||||
@instance.monitor = false
|
||||
@instance.monitoring == false
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
10
tests/compute/models/aws/snapshot_tests.rb
Normal file
10
tests/compute/models/aws/snapshot_tests.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
Shindo.tests("AWS::Compute | snapshot", ['aws']) do
|
||||
|
||||
@volume = AWS[:compute].volumes.create(:availability_zone => 'us-east-1a', :size => 1)
|
||||
@volume.wait_for { ready? }
|
||||
|
||||
model_tests(AWS[:compute].snapshots, {:volume_id => @volume.identity}, true)
|
||||
|
||||
@volume.destroy
|
||||
|
||||
end
|
10
tests/compute/models/aws/snapshots_tests.rb
Normal file
10
tests/compute/models/aws/snapshots_tests.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
Shindo.tests("AWS::Compute | snapshots", ['aws']) do
|
||||
|
||||
@volume = AWS[:compute].volumes.create(:availability_zone => 'us-east-1a', :size => 1)
|
||||
@volume.wait_for { ready? }
|
||||
|
||||
collection_tests(AWS[:compute].snapshots, {:volume_id => @volume.identity}, true)
|
||||
|
||||
@volume.destroy
|
||||
|
||||
end
|
24
tests/compute/models/aws/volume_tests.rb
Normal file
24
tests/compute/models/aws/volume_tests.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
Shindo.tests("AWS::Compute | volume", ['aws']) do
|
||||
|
||||
@server = AWS[:compute].servers.create(:image_id => GENTOO_AMI)
|
||||
@server.wait_for { ready? }
|
||||
|
||||
model_tests(AWS[:compute].volumes, {:availability_zone => @server.availability_zone, :size => 1, :device => '/dev/sdz1'}, true) do
|
||||
|
||||
tests('#server = @server').succeeds do
|
||||
@instance.server = @server
|
||||
end
|
||||
|
||||
@instance.wait_for { state == 'in-use' }
|
||||
|
||||
tests('#server = nil').succeeds do
|
||||
@instance.server = nil
|
||||
end
|
||||
|
||||
@instance.wait_for { ready? }
|
||||
|
||||
end
|
||||
|
||||
@server.destroy
|
||||
|
||||
end
|
5
tests/compute/models/aws/volumes_tests.rb
Normal file
5
tests/compute/models/aws/volumes_tests.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
Shindo.tests("AWS::Compute | volumes", ['aws']) do
|
||||
|
||||
collection_tests(AWS[:compute].volumes, {:availability_zone => 'us-east-1a', :size => 1, :device => '/dev/sdz1'}, true)
|
||||
|
||||
end
|
Loading…
Reference in a new issue