-
Notifications
You must be signed in to change notification settings - Fork 102
/
create_stack_spec.rb
101 lines (91 loc) · 3.5 KB
/
create_stack_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
require 'vagrant-openstack-provider/spec_helper'
require 'ostruct'
require 'sshkey'
include VagrantPlugins::Openstack::Action
include VagrantPlugins::Openstack::HttpUtils
include VagrantPlugins::Openstack::Domain
describe VagrantPlugins::Openstack::Action::CreateStack do
let(:config) do
double('config').tap do |config|
config.stub(:stacks) do
[
{
name: 'stack1',
template: 'template.yml'
},
{
name: 'stack2',
template: 'template.yml'
}
]
end
config.stub(:stack_create_timeout) { 200 }
end
end
let(:heat) do
double('heat')
end
let(:env) do
Hash.new.tap do |env|
env[:ui] = double('ui')
env[:ui].stub(:info).with(anything)
env[:machine] = double('machine')
env[:machine] = OpenStruct.new.tap do |m|
m.provider_config = config
m.id = nil
end
env[:openstack_client] = double('openstack_client')
env[:openstack_client].stub(:heat) { heat }
end
end
before :each do
CreateStack.send(:public, *CreateStack.private_instance_methods)
app = double('app')
app.stub(:call).with(anything)
@action = CreateStack.new(app, nil)
YAML.stub(:load_file).with('template.yml').and_return(YAML.load('
heat_template_version: 2013-05-23
description: Simple template to deploy a single compute instance
resources:
my_instance:
type: OS::Nova::Server
properties:
key_name: julien-mac
image: CoreOS
flavor: 1_vCPU_RAM_512M_HD_10G
'))
end
describe 'call' do
it 'should create stacks on heat twice' do
heat.stub(:create_stack).and_return('idstack')
File.should_receive(:write).with('/stack_stack1_id', 'idstack')
File.should_receive(:write).with('/stack_stack2_id', 'idstack')
# TODO(julienvey) assert content of create call is correct
heat.should_receive(:create_stack).exactly(2).times
heat.stub(:get_stack_details).and_return('stack_status' => 'CREATE_COMPLETE')
@action.call(env)
end
end
describe 'waiting_for_server_to_be_built' do
context 'when server is not yet active' do
it 'become active after one retry' do
heat.stub(:get_stack_details).and_return({ 'stack_status' => 'CREATE_IN_PROGRESS' }, { 'stack_status' => 'CREATE_COMPLETE' })
heat.should_receive(:get_stack_details).with(env, 'stack1', 'id-01').exactly(2).times
config.stub(:stack_create_timeout) { 5 }
@action.waiting_for_stack_to_be_created(env, 'stack1', 'id-01', 1)
end
it 'timeout before the server become active' do
heat.stub(:get_stack_details).and_return({ 'stack_status' => 'CREATE_IN_PROGRESS' }, { 'stack_status' => 'CREATE_IN_PROGRESS' })
heat.should_receive(:get_stack_details).with(env, 'stack1', 'id-01').at_least(2).times
config.stub(:stack_create_timeout) { 3 }
expect { @action.waiting_for_stack_to_be_created(env, 'stack1', 'id-01', 1) }.to raise_error Errors::Timeout
end
it 'raise an error after one retry' do
heat.stub(:get_stack_details).and_return({ 'stack_status' => 'CREATE_IN_PROGRESS' }, { 'stack_status' => 'CREATE_FAILED' })
heat.should_receive(:get_stack_details).with(env, 'stack1', 'id-01').exactly(2).times
config.stub(:stack_create_timeout) { 3 }
expect { @action.waiting_for_stack_to_be_created(env, 'stack1', 'id-01', 1) }.to raise_error Errors::StackStatusError
end
end
end
end