/
instance_manager_spec.rb
172 lines (138 loc) · 6.3 KB
/
instance_manager_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# Copyright (c) 2009-2012 VMware, Inc.
require File.expand_path("../../../spec_helper", __FILE__)
BOSH_STEMCELL_TGZ ||= "bosh-instance-1.0.tgz"
describe Bosh::Deployer::InstanceManager do
before(:each) do
@dir = Dir.mktmpdir("bdim_spec")
@config = YAML.load_file(spec_asset("test-bootstrap-config-vcloud.yml"))
@config["dir"] = @dir
@config["name"] = "spec-#{SecureRandom.uuid}"
@config["logging"] = { "file" => "#{@dir}/bmim.log" }
@deployer = Bosh::Deployer::InstanceManager.create(@config)
@cloud = mock("cloud")
Bosh::Deployer::Config.stub!(:cloud).and_return(@cloud)
@agent = mock("agent")
Bosh::Deployer::Config.stub!(:agent).and_return(@agent)
end
after(:each) do
@deployer.state.destroy
FileUtils.remove_entry_secure @dir
end
def load_deployment
@deployer.send(:load_deployments)["instances"].select {
|d| d[:name] == @deployer.state.name }.first
end
it "should not populate disk model" do
disk_model = @deployer.disk_model
disk_model.should == nil
end
it "should create a Bosh instance" do
@deployer.stub!(:service_ip).and_return("10.0.0.10")
spec = YAML.load_file(spec_asset("apply_spec_vcloud.yml"))
Bosh::Deployer::Specification.should_receive(:load_apply_spec).and_return(spec)
Bosh::Deployer::Config.stub(:agent_properties).and_return({})
@deployer.stub!(:run_command)
@deployer.stub!(:wait_until_agent_ready)
@deployer.stub!(:wait_until_director_ready)
@deployer.stub!(:load_apply_spec).and_return(spec)
@deployer.stub!(:load_stemcell_manifest).and_return({"cloud_properties" => {}})
@deployer.state.uuid.should_not be_nil
@deployer.state.stemcell_cid.should be_nil
@deployer.state.vm_cid.should be_nil
@cloud.should_receive(:create_stemcell).and_return("SC-CID-CREATE")
@cloud.should_receive(:create_vm).and_return("VM-CID-CREATE")
@cloud.should_receive(:create_disk).and_return("DISK-CID-CREATE")
@cloud.should_receive(:attach_disk).with("VM-CID-CREATE", "DISK-CID-CREATE")
@agent.should_receive(:run_task).with(:mount_disk, "DISK-CID-CREATE").and_return({})
@agent.should_receive(:run_task).with(:stop)
@agent.should_receive(:run_task).with(:apply, spec)
@agent.should_receive(:run_task).with(:start)
@deployer.create(BOSH_STEMCELL_TGZ)
@deployer.state.stemcell_cid.should == "SC-CID-CREATE"
@deployer.state.vm_cid.should == "VM-CID-CREATE"
@deployer.state.disk_cid.should == "DISK-CID-CREATE"
load_deployment.should == @deployer.state.values
@deployer.renderer.total.should == @deployer.renderer.index
end
it "should destroy a Bosh instance" do
disk_cid = "33"
@deployer.state.disk_cid = disk_cid
@deployer.state.stemcell_cid = "SC-CID-DESTROY"
@deployer.state.stemcell_name = @deployer.state.stemcell_cid
@deployer.state.vm_cid = "VM-CID-DESTROY"
@agent.should_receive(:list_disk).and_return([disk_cid])
@agent.should_receive(:run_task).with(:stop)
@agent.should_receive(:run_task).with(:unmount_disk, disk_cid).and_return({})
@cloud.should_receive(:detach_disk).with("VM-CID-DESTROY", disk_cid)
@cloud.should_receive(:delete_disk).with(disk_cid)
@cloud.should_receive(:delete_vm).with("VM-CID-DESTROY")
@deployer.destroy
@deployer.state.stemcell_cid.should be_nil
@deployer.state.stemcell_name.should be_nil
@deployer.state.vm_cid.should be_nil
@deployer.state.disk_cid.should be_nil
load_deployment.should == @deployer.state.values
@deployer.renderer.total.should == @deployer.renderer.index
end
it "should update a Bosh instance" do
@deployer.stub!(:service_ip).and_return("10.0.0.10")
spec = YAML.load_file(spec_asset("apply_spec_vcloud.yml"))
disk_cid = "22"
Bosh::Deployer::Specification.should_receive(:load_apply_spec).and_return(spec)
Bosh::Deployer::Config.stub(:agent_properties).and_return({})
@deployer.stub!(:run_command)
@deployer.stub!(:wait_until_agent_ready)
@deployer.stub!(:wait_until_director_ready)
@deployer.stub!(:load_apply_spec).and_return(spec)
@deployer.stub!(:load_stemcell_manifest).and_return({"cloud_properties" => {}})
@deployer.stub!(:persistent_disk_changed?).and_return(false)
@deployer.state.stemcell_cid = "SC-CID-UPDATE"
@deployer.state.vm_cid = "VM-CID-UPDATE"
@deployer.state.disk_cid = disk_cid
@agent.should_receive(:run_task).with(:stop)
@agent.should_receive(:run_task).with(:unmount_disk, disk_cid).and_return({})
@cloud.should_receive(:detach_disk).with("VM-CID-UPDATE", disk_cid)
@cloud.should_receive(:delete_vm).with("VM-CID-UPDATE")
@cloud.should_receive(:delete_stemcell).with("SC-CID-UPDATE")
@cloud.should_receive(:create_stemcell).and_return("SC-CID")
@cloud.should_receive(:create_vm).and_return("VM-CID")
@cloud.should_receive(:attach_disk).with("VM-CID", disk_cid)
@agent.should_receive(:run_task).with(:mount_disk, disk_cid).and_return({})
@agent.should_receive(:list_disk).and_return([disk_cid])
@agent.should_receive(:run_task).with(:stop)
@agent.should_receive(:run_task).with(:apply, spec)
@agent.should_receive(:run_task).with(:start)
@deployer.update(BOSH_STEMCELL_TGZ)
@deployer.state.stemcell_cid.should == "SC-CID"
@deployer.state.vm_cid.should == "VM-CID"
@deployer.state.disk_cid.should == disk_cid
load_deployment.should == @deployer.state.values
end
it "should fail to create a Bosh instance if stemcell CID exists" do
@deployer.state.stemcell_cid = "SC-CID"
expect {
@deployer.create(BOSH_STEMCELL_TGZ)
}.to raise_error(Bosh::Cli::CliError)
end
it "should fail to create a Bosh instance if VM CID exists" do
@deployer.state.vm_cid = "VM-CID"
expect {
@deployer.create(BOSH_STEMCELL_TGZ)
}.to raise_error(Bosh::Cli::CliError)
end
it "should fail to destroy a Bosh instance unless stemcell CID exists" do
@deployer.state.vm_cid = "VM-CID"
@agent.should_receive(:run_task).with(:stop)
@cloud.should_receive(:delete_vm).with("VM-CID")
expect {
@deployer.destroy
}.to raise_error(Bosh::Cli::CliError)
end
it "should fail to destroy a Bosh instance unless VM CID exists" do
@deployer.state.stemcell_cid = "SC-CID"
@agent.should_receive(:run_task).with(:stop)
expect {
@deployer.destroy
}.to raise_error(Bosh::Cli::CliError)
end
end