profitbricks 0.9.9 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -2
- data/Gemfile.lock +19 -22
- data/Guardfile +9 -0
- data/Manifest.txt +15 -0
- data/README.md +1 -1
- data/Rakefile +13 -5
- data/lib/profitbricks.rb +7 -5
- data/lib/profitbricks/data_center.rb +19 -20
- data/lib/profitbricks/extensions.rb +0 -3
- data/lib/profitbricks/firewall.rb +14 -20
- data/lib/profitbricks/image.rb +4 -6
- data/lib/profitbricks/ip_block.rb +5 -6
- data/lib/profitbricks/load_balancer.rb +23 -48
- data/lib/profitbricks/model.rb +8 -35
- data/lib/profitbricks/nic.rb +17 -22
- data/lib/profitbricks/profitbricks.rb +35 -27
- data/lib/profitbricks/rule.rb +2 -2
- data/lib/profitbricks/server.rb +96 -18
- data/lib/profitbricks/storage.rb +17 -22
- data/profitbricks.gemspec +6 -6
- data/spec/fixtures/get_server/two_nics.json +1 -0
- data/spec/fixtures/get_server/two_nics.xml +1 -0
- data/spec/fixtures/get_storage/mount_image.json +21 -0
- data/spec/fixtures/get_storage/mount_image.xml +1 -0
- data/spec/fixtures/power_off_server/success.json +1 -0
- data/spec/fixtures/power_off_server/success.xml +1 -0
- data/spec/fixtures/reset_server/success.json +1 -0
- data/spec/fixtures/reset_server/success.xml +1 -0
- data/spec/fixtures/shutdown_server/success.json +1 -0
- data/spec/fixtures/shutdown_server/success.xml +1 -0
- data/spec/fixtures/start_server/success.json +1 -0
- data/spec/fixtures/start_server/success.xml +1 -0
- data/spec/live/data_center_spec.rb +47 -0
- data/spec/live/server_spec.rb +58 -0
- data/spec/profitbricks/cli_spec.rb +13 -6
- data/spec/profitbricks/data_center_spec.rb +54 -29
- data/spec/profitbricks/firewall_spec.rb +17 -11
- data/spec/profitbricks/image_spec.rb +8 -5
- data/spec/profitbricks/ip_block_spec.rb +8 -5
- data/spec/profitbricks/load_balancer_spec.rb +23 -16
- data/spec/profitbricks/model_spec.rb +10 -13
- data/spec/profitbricks/nic_spec.rb +16 -13
- data/spec/profitbricks/server_spec.rb +117 -11
- data/spec/profitbricks/storage_spec.rb +22 -13
- data/spec/spec_helper.rb +10 -23
- metadata +19 -5
- data/.gemtest +0 -0
@@ -2,47 +2,53 @@ require 'spec_helper'
|
|
2
2
|
require 'json'
|
3
3
|
|
4
4
|
describe Profitbricks::Firewall do
|
5
|
-
include Savon::
|
5
|
+
include Savon::SpecHelper
|
6
|
+
|
7
|
+
before(:all) { savon.mock! }
|
8
|
+
after(:all) { savon.unmock! }
|
9
|
+
|
6
10
|
let(:dc) { DataCenter.new(JSON.parse(File.open('spec/fixtures/get_data_center/firewall.json').read)["get_data_center_response"]["return"])}
|
7
11
|
|
8
12
|
it "should add new rules to a firewall of a load balancer" do
|
9
|
-
savon.expects(:add_firewall_rules_to_load_balancer).returns(:success)
|
13
|
+
savon.expects(:add_firewall_rules_to_load_balancer).with(message: {load_balancer_id: dc.load_balancers.first.id, request: [{port_range_start: 80, port_range_end: 80, protocol: 'TCP'}]}).returns(f :add_firewall_rules_to_load_balancer, :success)
|
14
|
+
savon.expects(:get_firewall).with(message: {firewall_id: 'aa5e5270-1e6d-6e3a-ba7b-0b1f2d9e2425'}).returns(f :get_firewall, :success)
|
10
15
|
fw = dc.load_balancers.first.firewall
|
11
16
|
rule = FirewallRule.new(:port_range_start => 80, :port_range_end => 80, :protocol => 'TCP')
|
12
17
|
fw.add_rules([rule]).should == true
|
13
18
|
end
|
14
19
|
|
15
20
|
it "should add new rules to a firewall of a nic" do
|
16
|
-
savon.expects(:add_firewall_rules_to_nic).returns(:success)
|
21
|
+
savon.expects(:add_firewall_rules_to_nic).with(message: {nic_id: dc.servers.first.nics.first.id, request: [{port_range_start: 80, port_range_end: 80, protocol: 'TCP'}]}).returns(f :add_firewall_rules_to_nic, :success)
|
22
|
+
savon.expects(:get_firewall).with(message: {firewall_id: '33f4e0a5-41d9-eb57-81d1-24854ed89834'}).returns(f :get_firewall, :success)
|
17
23
|
fw = dc.servers.first.nics.first.firewall
|
18
24
|
rule = FirewallRule.new(:port_range_start => 80, :port_range_end => 80, :protocol => 'TCP')
|
19
25
|
fw.add_rules([rule]).should == true
|
20
26
|
end
|
21
27
|
|
22
28
|
it "should activate a firewall" do
|
23
|
-
savon.expects(:get_firewall).returns(:success)
|
24
|
-
savon.expects(:activate_firewalls).returns(:success)
|
29
|
+
savon.expects(:get_firewall).with(message: {firewall_id: '33f4e0a5-41d9-eb57-81d1-24854ed89834'}).returns(f :get_firewall, :success)
|
30
|
+
savon.expects(:activate_firewalls).with(message: {firewall_ids: '33f4e0a5-41d9-eb57-81d1-24854ed89834'}).returns(f :activate_firewalls, :success)
|
25
31
|
fw = Firewall.find(:id => "33f4e0a5-41d9-eb57-81d1-24854ed89834")
|
26
32
|
fw.activate.should == true
|
27
33
|
end
|
28
34
|
|
29
35
|
it "should deactivate a firewall" do
|
30
|
-
savon.expects(:get_firewall).returns(:success)
|
31
|
-
savon.expects(:deactivate_firewalls).returns(:success)
|
36
|
+
savon.expects(:get_firewall).with(message: {firewall_id: '33f4e0a5-41d9-eb57-81d1-24854ed89834'}).returns(f :get_firewall, :success)
|
37
|
+
savon.expects(:deactivate_firewalls).with(message: {firewall_ids: '33f4e0a5-41d9-eb57-81d1-24854ed89834'}).returns(f :deactivate_firewalls, :success)
|
32
38
|
fw = Firewall.find(:id => "33f4e0a5-41d9-eb57-81d1-24854ed89834")
|
33
39
|
fw.deactivate.should == true
|
34
40
|
end
|
35
41
|
|
36
42
|
it "should delete a firewall" do
|
37
|
-
savon.expects(:get_firewall).returns(:success)
|
38
|
-
savon.expects(:delete_firewalls).returns(:success)
|
43
|
+
savon.expects(:get_firewall).with(message: {firewall_id: '33f4e0a5-41d9-eb57-81d1-24854ed89834'}).returns(f :get_firewall, :success)
|
44
|
+
savon.expects(:delete_firewalls).with(message: {firewall_ids: '33f4e0a5-41d9-eb57-81d1-24854ed89834'}).returns(f :delete_firewalls, :success)
|
39
45
|
fw = Firewall.find(:id => "33f4e0a5-41d9-eb57-81d1-24854ed89834")
|
40
46
|
fw.delete.should == true
|
41
47
|
end
|
42
48
|
|
43
49
|
it "should delete a firewall rule" do
|
44
|
-
savon.expects(:get_firewall).returns(:success)
|
45
|
-
savon.expects(:remove_firewall_rules).returns(:success)
|
50
|
+
savon.expects(:get_firewall).with(message: {firewall_id: '33f4e0a5-41d9-eb57-81d1-24854ed89834'}).returns(f :get_firewall, :success)
|
51
|
+
savon.expects(:remove_firewall_rules).with(message: {firewall_rule_ids: '77e8e8bd-5b72-b657-e97b-c010937cefdf'}).returns(f :remove_firewall_rules, :success)
|
46
52
|
fw = Firewall.find(:id => "33f4e0a5-41d9-eb57-81d1-24854ed89834")
|
47
53
|
fw.rules.first.delete.should == true
|
48
54
|
end
|
@@ -1,22 +1,25 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Profitbricks::Image do
|
4
|
-
include Savon::
|
4
|
+
include Savon::SpecHelper
|
5
|
+
|
6
|
+
before(:all) { savon.mock! }
|
7
|
+
after(:all) { savon.unmock! }
|
5
8
|
|
6
9
|
it "should find all images" do
|
7
|
-
savon.expects(:get_all_images).returns(:success)
|
10
|
+
savon.expects(:get_all_images).with(message: {}).returns(f :get_all_images, :success)
|
8
11
|
Image.all.count.should == 7
|
9
12
|
end
|
10
13
|
|
11
14
|
it "should find an image by name" do
|
12
|
-
savon.expects(:get_all_images).returns(:success)
|
15
|
+
savon.expects(:get_all_images).with(message: {}).returns(f :get_all_images, :success)
|
13
16
|
image = Image.find(:name => "Windows8-ConsumerPreview-64bit-English.iso")
|
14
17
|
image.os_type.should == "UNKNOWN"
|
15
18
|
end
|
16
19
|
|
17
20
|
it "should update the os_type" do
|
18
|
-
savon.expects(:get_all_images).returns(:success)
|
19
|
-
savon.expects(:set_image_os_type).returns(:success)
|
21
|
+
savon.expects(:get_all_images).with(message: {}).returns(f :get_all_images, :success)
|
22
|
+
savon.expects(:set_image_os_type).with(message: {image_id: '5f58656e-66c3-11e1-8c6f-0025901dfe2a', os_type: 'WINDOWS'}).returns(f :set_image_os_type, :success)
|
20
23
|
image = Image.find(:name => "Windows8-ConsumerPreview-64bit-English.iso")
|
21
24
|
image.set_os_type("WINDOWS").os_type.should == "WINDOWS"
|
22
25
|
end
|
@@ -1,24 +1,27 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Profitbricks::IpBlock do
|
4
|
-
include Savon::
|
4
|
+
include Savon::SpecHelper
|
5
|
+
|
6
|
+
before(:all) { savon.mock! }
|
7
|
+
after(:all) { savon.unmock! }
|
5
8
|
|
6
9
|
it "should reserve a block" do
|
7
|
-
savon.expects(:reserve_public_ip_block).returns(:success)
|
10
|
+
savon.expects(:reserve_public_ip_block).with(message: {block_size: 2}).returns(f :reserve_public_ip_block, :success)
|
8
11
|
block = IpBlock.reserve(2)
|
9
12
|
block.ips.count.should == 2
|
10
13
|
end
|
11
14
|
|
12
15
|
it "should list all available blocks" do
|
13
|
-
savon.expects(:get_all_public_ip_blocks).returns(:success)
|
16
|
+
savon.expects(:get_all_public_ip_blocks).with(message: {}).returns(f :get_all_public_ip_blocks, :success)
|
14
17
|
blocks = IpBlock.all()
|
15
18
|
blocks.count.should == 1
|
16
19
|
blocks.first.ips.count.should == 2
|
17
20
|
end
|
18
21
|
|
19
22
|
it "should release a block properly" do
|
20
|
-
savon.expects(:get_all_public_ip_blocks).returns(:success)
|
21
|
-
savon.expects(:release_public_ip_block).returns(:success)
|
23
|
+
savon.expects(:get_all_public_ip_blocks).with(message: {}).returns(f :get_all_public_ip_blocks, :success)
|
24
|
+
savon.expects(:release_public_ip_block).with(message: {block_id: '167bc48c-4f80-4870-b5db-13d7d762e1cd'}).returns(f :release_public_ip_block, :success)
|
22
25
|
blocks = IpBlock.all()
|
23
26
|
blocks.first.release.should == true
|
24
27
|
end
|
@@ -1,12 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Profitbricks::LoadBalancer do
|
4
|
-
include Savon::
|
4
|
+
include Savon::SpecHelper
|
5
|
+
|
6
|
+
before(:all) { savon.mock! }
|
7
|
+
after(:all) { savon.unmock! }
|
8
|
+
|
5
9
|
let(:servers) { [Server.new(:id => "206d10f2-035f-4ef2-8d24-3022653e9706")]}
|
6
10
|
|
7
11
|
it "create a new LoadBalancer" do
|
8
|
-
|
9
|
-
savon.expects(:
|
12
|
+
create_msg = {arg0: {data_center_id: "1111", name: "Test", server_ids: servers.collect(&:id), algorithm: 'ROUND_ROBIN'}}
|
13
|
+
savon.expects(:create_load_balancer).with(message: create_msg).returns(f :create_load_balancer, :success)
|
14
|
+
savon.expects(:get_load_balancer).with(message: {load_balancer_id: '5dadd2b2-3405-4ec5-a450-0df497bebab0'}).returns(f :get_load_balancer, :success)
|
10
15
|
lb = LoadBalancer.create(:data_center_id => "1111", :name => "Test", :servers => servers, :algorithm => 'ROUND_ROBIN')
|
11
16
|
lb.name.should == "Test"
|
12
17
|
lb.lan_id.should == 0
|
@@ -14,9 +19,9 @@ describe Profitbricks::LoadBalancer do
|
|
14
19
|
end
|
15
20
|
|
16
21
|
it "should update an existing LoadBalancer" do
|
17
|
-
savon.expects(:get_load_balancer).returns(:success)
|
18
|
-
savon.expects(:update_load_balancer).returns(:success)
|
19
|
-
savon.expects(:get_load_balancer).returns(:success)
|
22
|
+
savon.expects(:get_load_balancer).with(message: {load_balancer_id: '5dadd2b2-3405-4ec5-a450-0df497bebab0'}).returns(f :get_load_balancer, :success)
|
23
|
+
savon.expects(:update_load_balancer).with(message: {arg0: {load_balancer_id: '3e3cb642-4d50-4371-980a-65959b2fa428', load_balancer_name: 'Wee'}}).returns(f :update_load_balancer, :success)
|
24
|
+
savon.expects(:get_load_balancer).with(message: {load_balancer_id: '3e3cb642-4d50-4371-980a-65959b2fa428'}).returns(f :get_load_balancer, :success)
|
20
25
|
lb = LoadBalancer.find(:id => "5dadd2b2-3405-4ec5-a450-0df497bebab0")
|
21
26
|
lb.update(:name => "Wee").should == true
|
22
27
|
# FIXME seems to be a bug in the API
|
@@ -24,36 +29,38 @@ describe Profitbricks::LoadBalancer do
|
|
24
29
|
end
|
25
30
|
|
26
31
|
it "should be deleted" do
|
27
|
-
savon.expects(:get_load_balancer).returns(:success)
|
28
|
-
savon.expects(:delete_load_balancer).returns(:success)
|
32
|
+
savon.expects(:get_load_balancer).with(message: {load_balancer_id: '5dadd2b2-3405-4ec5-a450-0df497bebab0'}).returns(f :get_load_balancer, :success)
|
33
|
+
savon.expects(:delete_load_balancer).with(message: {load_balancer_id: '3e3cb642-4d50-4371-980a-65959b2fa428'}).returns(f :delete_load_balancer, :success)
|
29
34
|
lb = LoadBalancer.find(:id => "5dadd2b2-3405-4ec5-a450-0df497bebab0")
|
30
35
|
lb.delete.should == true
|
31
36
|
end
|
32
37
|
|
33
38
|
it "should register a server" do
|
34
|
-
savon.expects(:get_load_balancer).returns(:success)
|
35
|
-
savon.expects(:register_servers_on_load_balancer).returns(:success)
|
39
|
+
savon.expects(:get_load_balancer).with(message: {load_balancer_id: '5dadd2b2-3405-4ec5-a450-0df497bebab0'}).returns(f :get_load_balancer, :success)
|
40
|
+
savon.expects(:register_servers_on_load_balancer).with(message: id_with_servers).returns(f :register_servers_on_load_balancer, :success)
|
41
|
+
savon.expects(:get_load_balancer).with(message: {load_balancer_id: '3e3cb642-4d50-4371-980a-65959b2fa428'}).returns(f :get_load_balancer, :success)
|
36
42
|
lb = LoadBalancer.find(:id => "5dadd2b2-3405-4ec5-a450-0df497bebab0")
|
37
43
|
lb.register_servers(servers).should == true
|
38
44
|
end
|
39
45
|
|
40
46
|
it "should deregister a server" do
|
41
|
-
savon.expects(:get_load_balancer).returns(:success)
|
42
|
-
savon.expects(:deregister_servers_on_load_balancer).returns(:success)
|
47
|
+
savon.expects(:get_load_balancer).with(message: {load_balancer_id: '5dadd2b2-3405-4ec5-a450-0df497bebab0'}).returns(f :get_load_balancer, :success)
|
48
|
+
savon.expects(:deregister_servers_on_load_balancer).with(message: id_with_servers).returns(f :deregister_servers_on_load_balancer, :success)
|
43
49
|
lb = LoadBalancer.find(:id => "5dadd2b2-3405-4ec5-a450-0df497bebab0")
|
44
50
|
lb.deregister_servers(servers).should == true
|
45
51
|
end
|
46
52
|
|
53
|
+
let(:id_with_servers) { {load_balancer_id: '3e3cb642-4d50-4371-980a-65959b2fa428', server_ids: servers.collect(&:id)} }
|
47
54
|
it "should activate a server" do
|
48
|
-
savon.expects(:get_load_balancer).returns(:success)
|
49
|
-
savon.expects(:activate_load_balancing_on_servers).returns(:success)
|
55
|
+
savon.expects(:get_load_balancer).with(message: {load_balancer_id: '5dadd2b2-3405-4ec5-a450-0df497bebab0'}).returns(f :get_load_balancer, :success)
|
56
|
+
savon.expects(:activate_load_balancing_on_servers).with(message: id_with_servers).returns(f :activate_load_balancing_on_servers, :success)
|
50
57
|
lb = LoadBalancer.find(:id => "5dadd2b2-3405-4ec5-a450-0df497bebab0")
|
51
58
|
lb.activate_servers(servers).should == true
|
52
59
|
end
|
53
60
|
|
54
61
|
it "should deactivate a server" do
|
55
|
-
savon.expects(:get_load_balancer).returns(:success)
|
56
|
-
savon.expects(:deactivate_load_balancing_on_servers).returns(:success)
|
62
|
+
savon.expects(:get_load_balancer).with(message: {load_balancer_id: '5dadd2b2-3405-4ec5-a450-0df497bebab0'}).returns(f :get_load_balancer, :success)
|
63
|
+
savon.expects(:deactivate_load_balancing_on_servers).with(message: id_with_servers).returns(f :deactivate_load_balancing_on_servers, :success)
|
57
64
|
lb = LoadBalancer.find(:id => "5dadd2b2-3405-4ec5-a450-0df497bebab0")
|
58
65
|
lb.deactivate_servers(servers).should == true
|
59
66
|
end
|
@@ -11,6 +11,10 @@ module Profitbricks
|
|
11
11
|
class ModelBelongsToTest < Profitbricks::Model
|
12
12
|
belongs_to :model_has_many_test
|
13
13
|
end
|
14
|
+
|
15
|
+
class ModelBelongsToWithClassNameTest < Profitbricks::Model
|
16
|
+
belongs_to :undefined_model, :class_name => :model_test
|
17
|
+
end
|
14
18
|
end
|
15
19
|
|
16
20
|
describe Profitbricks::Model do
|
@@ -43,6 +47,12 @@ describe Profitbricks::Model do
|
|
43
47
|
mt.model_has_many_test.name.should == 'One'
|
44
48
|
end
|
45
49
|
|
50
|
+
it "should create a belongs_to association with class_name correclty" do
|
51
|
+
mt = Profitbricks::ModelBelongsToWithClassNameTest.new( :undefined_model => {:name => 'One'} )
|
52
|
+
mt.undefined_model.class.should == Profitbricks::ModelTest
|
53
|
+
mt.undefined_model.name.should == 'One'
|
54
|
+
end
|
55
|
+
|
46
56
|
it "should raise an LoadError exception" do
|
47
57
|
lambda {
|
48
58
|
module Profitbricks
|
@@ -52,17 +62,4 @@ describe Profitbricks::Model do
|
|
52
62
|
end
|
53
63
|
}.should raise_error(LoadError)
|
54
64
|
end
|
55
|
-
describe "get_xml_and_update_attributes" do
|
56
|
-
it "should execute update_attributes correclty" do
|
57
|
-
mt = Profitbricks::ModelTest.new({:name => 'Test', :camel_case => 'works'})
|
58
|
-
xml = mt.get_xml_and_update_attributes({:name => 'Test2', :camel_case => 'fails?'}, [:name, :camel_case])
|
59
|
-
xml.should == "<camelCase>fails?</camelCase><modelTestName>Test2</modelTestName>"
|
60
|
-
mt.name.should == 'Test2'
|
61
|
-
mt.camel_case.should == 'fails?'
|
62
|
-
end
|
63
|
-
it "should work as class method" do
|
64
|
-
xml = Profitbricks::ModelTest.get_xml_and_update_attributes({:name => 'Test2', :camel_case => 'fails?'}, [:name, :camel_case])
|
65
|
-
xml.should == "<camelCase>fails?</camelCase><modelTestName>Test2</modelTestName>"
|
66
|
-
end
|
67
|
-
end
|
68
65
|
end
|
@@ -1,11 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Profitbricks::Nic do
|
4
|
-
include Savon::
|
4
|
+
include Savon::SpecHelper
|
5
|
+
|
6
|
+
before(:all) { savon.mock! }
|
7
|
+
after(:all) { savon.unmock! }
|
5
8
|
|
6
9
|
it "create a new Nic" do
|
7
|
-
savon.expects(:create_nic).returns(:success)
|
8
|
-
savon.expects(:get_nic).returns(:success)
|
10
|
+
savon.expects(:create_nic).with(message: {arg0: {lan_id: 1, ip: '192.168.0.11', nic_name: 'Internal', server_id: '4cb6550f-3777-4818-8f4c-51233162a980'}}).returns(f :create_nic, :success)
|
11
|
+
savon.expects(:get_nic).with(message: {nic_id: 'cba8af39-b5de-477b-9795-2f02ea9cf04f'}).returns(f :get_nic, :success)
|
9
12
|
nic = Nic.create(:lan_id => 1, :ip => "192.168.0.11", :name => "Internal", :server_id => "4cb6550f-3777-4818-8f4c-51233162a980")
|
10
13
|
nic.name.should == "Internal"
|
11
14
|
nic.lan_id.should == 1
|
@@ -13,30 +16,30 @@ describe Profitbricks::Nic do
|
|
13
16
|
end
|
14
17
|
|
15
18
|
it "should update an existing Nic" do
|
16
|
-
savon.expects(:get_nic).returns(:success)
|
17
|
-
savon.expects(:update_nic).returns(:success)
|
19
|
+
savon.expects(:get_nic).with(message: {nic_id: 'cba8af39-b5de-477b-9795-2f02ea9cf04f'}).returns(f :get_nic, :success)
|
20
|
+
savon.expects(:update_nic).with(message: {arg0: {nic_id: 'cba8af39-b5de-477b-9795-2f02ea9cf04f', nic_name: 'External'}}).returns(f :update_nic, :success)
|
18
21
|
nic = Nic.find(:id => "cba8af39-b5de-477b-9795-2f02ea9cf04f")
|
19
22
|
nic.update(:name => "External").should == true
|
20
23
|
nic.name.should == "External"
|
21
24
|
end
|
22
25
|
|
23
26
|
it "should set the internet access" do
|
24
|
-
savon.expects(:get_nic).returns(:success)
|
25
|
-
savon.expects(:set_internet_access).returns(:success)
|
27
|
+
savon.expects(:get_nic).with(message: {nic_id: 'cba8af39-b5de-477b-9795-2f02ea9cf04f'}).returns(f :get_nic, :success)
|
28
|
+
savon.expects(:set_internet_access).with(message: {data_center_id: 'b3eebede-5c78-417c-b1bc-ff5de01a0602', lan_id: 1, internet_access: true}).returns(f :set_internet_access, :success)
|
26
29
|
nic = Nic.find(:id => "cba8af39-b5de-477b-9795-2f02ea9cf04f")
|
27
30
|
(nic.set_internet_access = true).should == true
|
28
31
|
end
|
29
32
|
|
30
33
|
it "should be deleted" do
|
31
|
-
savon.expects(:get_nic).returns(:success)
|
32
|
-
savon.expects(:delete_nic).returns(:success)
|
34
|
+
savon.expects(:get_nic).with(message: {nic_id: 'cba8af39-b5de-477b-9795-2f02ea9cf04f'}).returns(f :get_nic, :success)
|
35
|
+
savon.expects(:delete_nic).with(message: {nic_id: 'cba8af39-b5de-477b-9795-2f02ea9cf04f'}).returns(f :delete_nic, :success)
|
33
36
|
nic = Nic.find(:id => "cba8af39-b5de-477b-9795-2f02ea9cf04f")
|
34
37
|
nic.delete.should == true
|
35
38
|
end
|
36
39
|
|
37
40
|
it "should add an ip" do
|
38
|
-
savon.expects(:get_nic).returns(:success)
|
39
|
-
savon.expects(:add_public_ip_to_nic).returns(:success)
|
41
|
+
savon.expects(:get_nic).with(message: {nic_id: 'cba8af39-b5de-477b-9795-2f02ea9cf04f'}).returns(f :get_nic, :success)
|
42
|
+
savon.expects(:add_public_ip_to_nic).with(message: {nic_id: 'cba8af39-b5de-477b-9795-2f02ea9cf04f', ip: '46.16.74.13'}).returns(f :add_public_ip_to_nic, :success)
|
40
43
|
nic = Nic.find(:id => "cba8af39-b5de-477b-9795-2f02ea9cf04f")
|
41
44
|
nic.add_ip("46.16.74.13")
|
42
45
|
nic.ips.count.should == 2
|
@@ -46,8 +49,8 @@ describe Profitbricks::Nic do
|
|
46
49
|
end
|
47
50
|
|
48
51
|
it "should remove an ip" do
|
49
|
-
savon.expects(:get_nic).returns(:success)
|
50
|
-
savon.expects(:remove_public_ip_from_nic).returns(:success)
|
52
|
+
savon.expects(:get_nic).with(message: {nic_id: 'cba8af39-b5de-477b-9795-2f02ea9cf04f'}).returns(f :get_nic, :success)
|
53
|
+
savon.expects(:remove_public_ip_from_nic).with(message: {nic_id: 'cba8af39-b5de-477b-9795-2f02ea9cf04f', ip: '46.16.74.13'}).returns(f :remove_public_ip_from_nic, :success)
|
51
54
|
nic = Nic.find(:id => "cba8af39-b5de-477b-9795-2f02ea9cf04f")
|
52
55
|
nic.remove_ip("46.16.74.13")
|
53
56
|
nic.ips.count.should == 1
|
@@ -1,8 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Profitbricks::Server do
|
4
|
-
include Savon::
|
4
|
+
include Savon::SpecHelper
|
5
5
|
|
6
|
+
before(:all) { savon.mock! }
|
7
|
+
after(:all) { savon.unmock! }
|
8
|
+
|
6
9
|
describe "enforcing required arguments" do
|
7
10
|
describe "on create" do
|
8
11
|
it "should require :cores and :ram" do
|
@@ -39,8 +42,8 @@ describe Profitbricks::Server do
|
|
39
42
|
end
|
40
43
|
describe "on update" do
|
41
44
|
before(:each) do
|
42
|
-
savon.expects(:create_server).returns(:minimal)
|
43
|
-
savon.expects(:get_server).returns(:after_create)
|
45
|
+
savon.expects(:create_server).with(message: {arg0: {ram: 256, cores: 1}}).returns(f :create_server, :minimal)
|
46
|
+
savon.expects(:get_server).with(message: {server_id: 'b7a5f3d1-324a-4490-aa8e-56cdec436e3f'}).returns(f :get_server, :after_create)
|
44
47
|
@server = Server.create(:ram => 256, :cores => 1)
|
45
48
|
end
|
46
49
|
|
@@ -74,32 +77,135 @@ describe Profitbricks::Server do
|
|
74
77
|
|
75
78
|
|
76
79
|
it "should create a new server with minimal arguments" do
|
77
|
-
savon.expects(:create_server).returns(:minimal)
|
78
|
-
savon.expects(:get_server).returns(:after_create)
|
80
|
+
savon.expects(:create_server).with(message: {arg0: {ram: 256, cores: 1, server_name: 'Test Server', data_center_id: 'b3eebede-5c78-417c-b1bc-ff5de01a0602'}}).returns(f :create_server, :minimal)
|
81
|
+
savon.expects(:get_server).with(message: {server_id: 'b7a5f3d1-324a-4490-aa8e-56cdec436e3f'}).returns(f :get_server, :after_create)
|
79
82
|
s = Server.create(:cores => 1, :ram => 256, :name => 'Test Server', :data_center_id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
80
83
|
s.cores.should == 1
|
81
84
|
s.ram.should == 256
|
82
85
|
s.name.should == 'Test Server'
|
83
86
|
s.data_center_id.should == "b3eebede-5c78-417c-b1bc-ff5de01a0602"
|
84
87
|
end
|
88
|
+
|
85
89
|
it "should reboot on request" do
|
86
|
-
savon.expects(:get_server).returns(:after_create)
|
87
|
-
savon.expects(:reboot_server).returns(:success)
|
90
|
+
savon.expects(:get_server).with(message: {server_id: 'b3eebede-5c78-417c-b1bc-ff5de01a0602'}).returns(f :get_server, :after_create)
|
91
|
+
savon.expects(:reboot_server).with(message: {server_id: 'b7a5f3d1-324a-4490-aa8e-56cdec436e3f'}).returns(f :reboot_server, :success)
|
88
92
|
s = Server.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
89
93
|
s.reboot.should == true
|
90
94
|
end
|
91
95
|
|
96
|
+
it "should reset on request" do
|
97
|
+
savon.expects(:get_server).with(message: {server_id: 'b3eebede-5c78-417c-b1bc-ff5de01a0602'}).returns(f :get_server, :after_create)
|
98
|
+
savon.expects(:reset_server).with(message: {server_id: 'b7a5f3d1-324a-4490-aa8e-56cdec436e3f'}).returns(f :reset_server, :success)
|
99
|
+
s = Server.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
100
|
+
s.reset.should == true
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should start on request" do
|
104
|
+
savon.expects(:get_server).with(message: {server_id: 'b3eebede-5c78-417c-b1bc-ff5de01a0602'}).returns(f :get_server, :after_create)
|
105
|
+
savon.expects(:start_server).with(message: {server_id: 'b7a5f3d1-324a-4490-aa8e-56cdec436e3f'}).returns(f :start_server, :success)
|
106
|
+
s = Server.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
107
|
+
s.start.should == true
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should power off on request" do
|
111
|
+
savon.expects(:get_server).with(message: {server_id: 'b3eebede-5c78-417c-b1bc-ff5de01a0602'}).returns(f :get_server, :after_create)
|
112
|
+
savon.expects(:power_off_server).with(message: {server_id: 'b7a5f3d1-324a-4490-aa8e-56cdec436e3f'}).returns(f :power_off_server, :success)
|
113
|
+
s = Server.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
114
|
+
s.power_off.should == true
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should shutdown on request" do
|
118
|
+
savon.expects(:get_server).with(message: {server_id: 'b3eebede-5c78-417c-b1bc-ff5de01a0602'}).returns(f :get_server, :after_create)
|
119
|
+
savon.expects(:shutdown_server).with(message: {server_id: 'b7a5f3d1-324a-4490-aa8e-56cdec436e3f'}).returns(f :shutdown_server, :success)
|
120
|
+
s = Server.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
121
|
+
s.shutdown.should == true
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should check if its running" do
|
125
|
+
savon.expects(:get_server).with(message: {server_id: 'b3eebede-5c78-417c-b1bc-ff5de01a0602'}).returns(f :get_server, :after_create)
|
126
|
+
savon.expects(:get_server).with(message: {server_id: 'b7a5f3d1-324a-4490-aa8e-56cdec436e3f'}).returns(f :get_server, :after_create)
|
127
|
+
s = Server.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
128
|
+
s.running?.should == false
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should wait until it is running" do
|
132
|
+
savon.expects(:get_server).with(message: {server_id: 'b3eebede-5c78-417c-b1bc-ff5de01a0602'}).returns(f :get_server, :after_create)
|
133
|
+
s = Server.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
134
|
+
s.should_receive(:running?).and_return(false,true)
|
135
|
+
s.wait_for_running
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should return false on provisioned?" do
|
139
|
+
savon.expects(:get_server).with(message: {server_id: 'b3eebede-5c78-417c-b1bc-ff5de01a0602'}).returns(f :get_server, :after_create)
|
140
|
+
s = Server.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
141
|
+
savon.expects(:get_server).with(message: {server_id: 'b7a5f3d1-324a-4490-aa8e-56cdec436e3f'}).returns(f :get_server, :after_create)
|
142
|
+
s.provisioned?.should == false
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should return true on provisioned?" do
|
146
|
+
savon.expects(:get_server).with(message: {server_id: 'b3eebede-5c78-417c-b1bc-ff5de01a0602'}).returns(f :get_server, :after_create)
|
147
|
+
s = Server.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
148
|
+
savon.expects(:get_server).with(message: {server_id: 'b7a5f3d1-324a-4490-aa8e-56cdec436e3f'}).returns(f :get_server, :connected_storage)
|
149
|
+
s.provisioned?.should == true
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should wait for provisioning to finish" do
|
153
|
+
savon.expects(:get_server).with(message: {server_id: 'b3eebede-5c78-417c-b1bc-ff5de01a0602'}).returns(f :get_server, :after_create)
|
154
|
+
s = Server.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
155
|
+
s.should_receive(:provisioned?).and_return(false,true)
|
156
|
+
s.wait_for_provisioning
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should call Nic.create correctly via the create_nic helper" do
|
160
|
+
savon.expects(:get_server).with(message: {server_id: 'b3eebede-5c78-417c-b1bc-ff5de01a0602'}).returns(f :get_server, :after_create)
|
161
|
+
s = Server.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
162
|
+
Nic.should_receive(:create).with(:server_id => "b7a5f3d1-324a-4490-aa8e-56cdec436e3f")
|
163
|
+
s.create_nic({})
|
164
|
+
end
|
165
|
+
|
92
166
|
it "should be deleted" do
|
93
|
-
savon.expects(:get_server).returns(:after_create)
|
94
|
-
savon.expects(:delete_server).returns(:success)
|
167
|
+
savon.expects(:get_server).with(message: {server_id: 'b3eebede-5c78-417c-b1bc-ff5de01a0602'}).returns(f :get_server, :after_create)
|
168
|
+
savon.expects(:delete_server).with(message: {server_id: 'b7a5f3d1-324a-4490-aa8e-56cdec436e3f'}).returns(f :delete_server, :success)
|
95
169
|
s = Server.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
96
170
|
s.delete.should == true
|
97
171
|
end
|
98
172
|
|
173
|
+
it "should return all Servers" do
|
174
|
+
savon.expects(:get_all_data_centers).with(message: {}).returns(f :get_all_data_centers, :test_datacenter)
|
175
|
+
savon.expects(:get_data_center).with(message: {data_center_id: 'b3eebede-5c78-417c-b1bc-ff5de01a0602'}).returns(f :get_data_center, :two_servers_with_storage)
|
176
|
+
#DataCenter.should_receive(:all).and_return
|
177
|
+
servers = Server.all
|
178
|
+
servers.class.should == Array
|
179
|
+
servers.length.should == 2
|
180
|
+
servers.first.class.should == Server
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should return all connected_storages via the storages helper" do
|
184
|
+
savon.expects(:get_server).with(message: {server_id: 'b3eebede-5c78-417c-b1bc-ff5de01a0602'}).returns(f :get_server, :connected_storage)
|
185
|
+
s = Server.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
186
|
+
s.connected_storages.class.should == Array
|
187
|
+
s.connected_storages.length.should == 1
|
188
|
+
s.connected_storages.first.class.should == Storage
|
189
|
+
end
|
190
|
+
|
191
|
+
describe "nic helper methods" do
|
192
|
+
it "should return all public ip adresses" do
|
193
|
+
savon.expects(:get_server).with(message: {server_id: 'b3eebede-5c78-417c-b1bc-ff5de01a0602'}).returns(f :get_server, :two_nics)
|
194
|
+
s = Server.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
195
|
+
s.public_ips.should == ["46.16.73.167"]
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should return all private ip adresses" do
|
199
|
+
savon.expects(:get_server).with(message: {server_id: 'b3eebede-5c78-417c-b1bc-ff5de01a0602'}).returns(f :get_server, :two_nics)
|
200
|
+
s = Server.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
201
|
+
s.private_ips.should == ["10.14.38.11"]
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
99
205
|
describe "updating" do
|
100
206
|
it "should update basic attributes correctly" do
|
101
|
-
savon.expects(:get_server).returns(:after_create)
|
102
|
-
savon.expects(:update_server).returns(:basic)
|
207
|
+
savon.expects(:get_server).with(message: {server_id: 'b3eebede-5c78-417c-b1bc-ff5de01a0602'}).returns(f :get_server, :after_create)
|
208
|
+
savon.expects(:update_server).with(message: {arg0: {server_id: 'b7a5f3d1-324a-4490-aa8e-56cdec436e3f', server_name: 'Power of two', os_type: 'WINDOWS', cores: 2, ram: 512}}).returns(f :update_server, :basic)
|
103
209
|
s = Server.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
|
104
210
|
s.update(:cores => 2, :ram => 512, :name => "Power of two", :os_type => 'WINDOWS')
|
105
211
|
s.cores.should == 2
|