knife-ec2 0.6.4 → 0.6.6.rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +3 -0
- data/.travis.yml +4 -0
- data/Gemfile +1 -7
- data/README.md +114 -0
- data/Rakefile +2 -1
- data/knife-ec2.gemspec +23 -18
- data/lib/chef/knife/ec2_base.rb +30 -2
- data/lib/chef/knife/ec2_server_create.rb +209 -22
- data/lib/chef/knife/ec2_server_delete.rb +33 -2
- data/lib/chef/knife/ec2_server_list.rb +79 -1
- data/lib/knife-ec2/version.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/ec2_server_create_spec.rb +253 -25
- data/spec/unit/ec2_server_delete_spec.rb +139 -0
- metadata +128 -112
- data/.rspec +0 -2
- data/Gemfile.lock +0 -104
- data/README.rdoc +0 -87
@@ -63,6 +63,11 @@ class Chef
|
|
63
63
|
def run
|
64
64
|
|
65
65
|
validate!
|
66
|
+
if @name_args.empty? && config[:chef_node_name]
|
67
|
+
ui.info("no instance id is specific, trying to retrieve it from node name")
|
68
|
+
instance_id = fetch_instance_id(config[:chef_node_name])
|
69
|
+
@name_args << instance_id unless instance_id.nil?
|
70
|
+
end
|
66
71
|
|
67
72
|
@name_args.each do |instance_id|
|
68
73
|
|
@@ -75,6 +80,7 @@ class Chef
|
|
75
80
|
msg_pair("Region", connection.instance_variable_get(:@region))
|
76
81
|
msg_pair("Availability Zone", @server.availability_zone)
|
77
82
|
msg_pair("Security Groups", @server.groups.join(", "))
|
83
|
+
msg_pair("IAM Profile", iam_name_from_profile(@server.iam_instance_profile)) if @server.iam_instance_profile
|
78
84
|
msg_pair("SSH Key", @server.key_name)
|
79
85
|
msg_pair("Root Device Type", @server.root_device_type)
|
80
86
|
msg_pair("Public DNS Name", @server.dns_name)
|
@@ -90,19 +96,44 @@ class Chef
|
|
90
96
|
ui.warn("Deleted server #{@server.id}")
|
91
97
|
|
92
98
|
if config[:purge]
|
93
|
-
|
99
|
+
if config[:chef_node_name]
|
100
|
+
thing_to_delete = config[:chef_node_name]
|
101
|
+
else
|
102
|
+
thing_to_delete = fetch_node_name(instance_id)
|
103
|
+
end
|
94
104
|
destroy_item(Chef::Node, thing_to_delete, "node")
|
95
105
|
destroy_item(Chef::ApiClient, thing_to_delete, "client")
|
96
106
|
else
|
97
107
|
ui.warn("Corresponding node and client for the #{instance_id} server were not deleted and remain registered with the Chef Server")
|
98
108
|
end
|
99
|
-
|
100
109
|
rescue NoMethodError
|
101
110
|
ui.error("Could not locate server '#{instance_id}'. Please verify it was provisioned in the '#{locate_config_value(:region)}' region.")
|
102
111
|
end
|
103
112
|
end
|
104
113
|
end
|
105
114
|
|
115
|
+
def fetch_node_name(instance_id)
|
116
|
+
result = query.search(:node,"ec2_instance_id:#{instance_id}")
|
117
|
+
unless result.first.empty?
|
118
|
+
result.first.first.name
|
119
|
+
else
|
120
|
+
instance_id
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def fetch_instance_id(name)
|
125
|
+
result = query.search(:node,"name:#{name}")
|
126
|
+
unless result.first.empty?
|
127
|
+
node = result.first.first
|
128
|
+
if node.attribute?('ec2')
|
129
|
+
node['ec2']['instance_id']
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def query
|
135
|
+
@query ||= Chef::Search::Query.new
|
136
|
+
end
|
106
137
|
end
|
107
138
|
end
|
108
139
|
end
|
@@ -34,11 +34,64 @@ class Chef
|
|
34
34
|
:default => true,
|
35
35
|
:description => "Do not display name tag in output"
|
36
36
|
|
37
|
+
option :az,
|
38
|
+
:short => "-z",
|
39
|
+
:long => "--availability-zone",
|
40
|
+
:boolean => true,
|
41
|
+
:default => false,
|
42
|
+
:description => "Show availability zones"
|
43
|
+
|
37
44
|
option :tags,
|
38
45
|
:short => "-t TAG1,TAG2",
|
39
46
|
:long => "--tags TAG1,TAG2",
|
40
47
|
:description => "List of tags to output"
|
41
48
|
|
49
|
+
def fcolor(flavor)
|
50
|
+
case flavor
|
51
|
+
when "t1.micro"
|
52
|
+
fcolor = :blue
|
53
|
+
when "m1.small"
|
54
|
+
fcolor = :magenta
|
55
|
+
when "m1.medium"
|
56
|
+
fcolor = :cyan
|
57
|
+
when "m1.large"
|
58
|
+
fcolor = :green
|
59
|
+
when "m1.xlarge"
|
60
|
+
fcolor = :red
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def azcolor(az)
|
65
|
+
case az
|
66
|
+
when /a$/
|
67
|
+
color = :blue
|
68
|
+
when /b$/
|
69
|
+
color = :green
|
70
|
+
when /c$/
|
71
|
+
color = :red
|
72
|
+
when /d$/
|
73
|
+
color = :magenta
|
74
|
+
else
|
75
|
+
color = :cyan
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def groups_with_ids(groups)
|
80
|
+
groups.map{|g|
|
81
|
+
"#{g} (#{@group_id_hash[g]})"
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
def vpc_with_name(vpc_id)
|
86
|
+
this_vpc = @vpcs.select{|v| v.id == vpc_id }.first
|
87
|
+
if this_vpc.tags["Name"]
|
88
|
+
vpc_name = this_vpc.tags["Name"]
|
89
|
+
"#{vpc_name} (#{vpc_id})"
|
90
|
+
else
|
91
|
+
vpc_id
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
42
95
|
def run
|
43
96
|
$stdout.sync = true
|
44
97
|
|
@@ -54,6 +107,11 @@ class Chef
|
|
54
107
|
ui.color('Public IP', :bold),
|
55
108
|
ui.color('Private IP', :bold),
|
56
109
|
ui.color('Flavor', :bold),
|
110
|
+
|
111
|
+
if config[:az]
|
112
|
+
ui.color('AZ', :bold)
|
113
|
+
end,
|
114
|
+
|
57
115
|
ui.color('Image', :bold),
|
58
116
|
ui.color('SSH Key', :bold),
|
59
117
|
ui.color('Security Groups', :bold),
|
@@ -64,11 +122,16 @@ class Chef
|
|
64
122
|
end
|
65
123
|
end,
|
66
124
|
|
125
|
+
ui.color('IAM Profile', :bold),
|
67
126
|
ui.color('State', :bold)
|
68
127
|
].flatten.compact
|
69
128
|
|
70
129
|
output_column_count = server_list.length
|
71
130
|
|
131
|
+
if !config[:region]
|
132
|
+
ui.warn "No region was specified in knife.rb or as an argument. The default region, us-east-1, will be used:"
|
133
|
+
end
|
134
|
+
|
72
135
|
connection.servers.all.each do |server|
|
73
136
|
server_list << server.id.to_s
|
74
137
|
|
@@ -78,7 +141,19 @@ class Chef
|
|
78
141
|
|
79
142
|
server_list << server.public_ip_address.to_s
|
80
143
|
server_list << server.private_ip_address.to_s
|
81
|
-
|
144
|
+
|
145
|
+
server_list << ui.color(
|
146
|
+
server.flavor_id.to_s,
|
147
|
+
fcolor(server.flavor_id.to_s)
|
148
|
+
)
|
149
|
+
|
150
|
+
if config[:az]
|
151
|
+
server_list << ui.color(
|
152
|
+
server.availability_zone.to_s,
|
153
|
+
azcolor(server.availability_zone.to_s)
|
154
|
+
)
|
155
|
+
end
|
156
|
+
|
82
157
|
server_list << server.image_id.to_s
|
83
158
|
server_list << server.key_name.to_s
|
84
159
|
server_list << server.groups.join(", ")
|
@@ -89,6 +164,8 @@ class Chef
|
|
89
164
|
end
|
90
165
|
end
|
91
166
|
|
167
|
+
server_list << iam_name_from_profile(server.iam_instance_profile)
|
168
|
+
|
92
169
|
server_list << begin
|
93
170
|
state = server.state.to_s.downcase
|
94
171
|
case state
|
@@ -101,6 +178,7 @@ class Chef
|
|
101
178
|
end
|
102
179
|
end
|
103
180
|
end
|
181
|
+
|
104
182
|
puts ui.list(server_list, :uneven_columns_across, output_column_count)
|
105
183
|
|
106
184
|
end
|
data/lib/knife-ec2/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -19,12 +19,14 @@
|
|
19
19
|
require File.expand_path('../../spec_helper', __FILE__)
|
20
20
|
require 'fog'
|
21
21
|
require 'chef/knife/bootstrap'
|
22
|
+
require 'chef/knife/bootstrap_windows_winrm'
|
23
|
+
require 'chef/knife/bootstrap_windows_ssh'
|
22
24
|
|
23
25
|
describe Chef::Knife::Ec2ServerCreate do
|
24
26
|
before do
|
25
27
|
@knife_ec2_create = Chef::Knife::Ec2ServerCreate.new
|
26
28
|
@knife_ec2_create.initial_sleep_delay = 0
|
27
|
-
@knife_ec2_create.stub
|
29
|
+
@knife_ec2_create.stub(:tcp_test_ssh).and_return(true)
|
28
30
|
|
29
31
|
{
|
30
32
|
:image => 'image',
|
@@ -35,22 +37,23 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
35
37
|
Chef::Config[:knife][key] = value
|
36
38
|
end
|
37
39
|
|
38
|
-
@ec2_connection =
|
39
|
-
@ec2_connection.stub_chain(:tags).and_return
|
40
|
-
@ec2_connection.stub_chain(:images, :get).and_return
|
41
|
-
@ec2_connection.stub_chain(:addresses).and_return [
|
40
|
+
@ec2_connection = double(Fog::Compute::AWS)
|
41
|
+
@ec2_connection.stub_chain(:tags).and_return double('create', :create => true)
|
42
|
+
@ec2_connection.stub_chain(:images, :get).and_return double('ami', :root_device_type => 'not_ebs', :platform => 'linux')
|
43
|
+
@ec2_connection.stub_chain(:addresses).and_return [double('addesses', {
|
42
44
|
:domain => 'standard',
|
43
45
|
:public_ip => '111.111.111.111',
|
44
46
|
:server_id => nil,
|
45
47
|
:allocation_id => ''})]
|
46
48
|
|
47
49
|
|
48
|
-
@ec2_servers =
|
49
|
-
@new_ec2_server =
|
50
|
+
@ec2_servers = double()
|
51
|
+
@new_ec2_server = double()
|
50
52
|
|
51
53
|
@ec2_server_attribs = { :id => 'i-39382318',
|
52
54
|
:flavor_id => 'm1.small',
|
53
55
|
:image_id => 'ami-47241231',
|
56
|
+
:placement_group => 'some_placement_group',
|
54
57
|
:availability_zone => 'us-west-1',
|
55
58
|
:key_name => 'my_ssh_key',
|
56
59
|
:groups => ['group1', 'group2'],
|
@@ -62,7 +65,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
62
65
|
:root_device_type => 'not_ebs' }
|
63
66
|
|
64
67
|
@ec2_server_attribs.each_pair do |attrib, value|
|
65
|
-
@new_ec2_server.stub
|
68
|
+
@new_ec2_server.stub(attrib).and_return(value)
|
66
69
|
end
|
67
70
|
end
|
68
71
|
|
@@ -75,25 +78,38 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
75
78
|
@eip = "111.111.111.111"
|
76
79
|
Fog::Compute::AWS.should_receive(:new).and_return(@ec2_connection)
|
77
80
|
|
78
|
-
@knife_ec2_create.stub
|
79
|
-
@knife_ec2_create.stub
|
81
|
+
@knife_ec2_create.stub(:puts)
|
82
|
+
@knife_ec2_create.stub(:print)
|
80
83
|
@knife_ec2_create.config[:image] = '12345'
|
81
84
|
|
82
85
|
@bootstrap = Chef::Knife::Bootstrap.new
|
83
|
-
Chef::Knife::Bootstrap.stub
|
86
|
+
Chef::Knife::Bootstrap.stub(:new).and_return(@bootstrap)
|
84
87
|
@bootstrap.should_receive(:run)
|
85
88
|
end
|
86
89
|
|
90
|
+
it "defaults to a distro of 'chef-full' for a linux instance" do
|
91
|
+
@new_ec2_server.should_receive(:wait_for).and_return(true)
|
92
|
+
@knife_ec2_create.config[:distro] = @knife_ec2_create.options[:distro][:default]
|
93
|
+
@knife_ec2_create.run
|
94
|
+
@bootstrap.config[:distro].should == 'chef-full'
|
95
|
+
end
|
96
|
+
|
87
97
|
it "creates an EC2 instance and bootstraps it" do
|
88
98
|
@new_ec2_server.should_receive(:wait_for).and_return(true)
|
89
99
|
@knife_ec2_create.run
|
90
100
|
@knife_ec2_create.server.should_not == nil
|
91
101
|
end
|
92
102
|
|
103
|
+
it "should never invoke windows bootstrap for linux instance" do
|
104
|
+
@new_ec2_server.should_receive(:wait_for).and_return(true)
|
105
|
+
@knife_ec2_create.should_not_receive(:bootstrap_for_windows_node)
|
106
|
+
@knife_ec2_create.run
|
107
|
+
end
|
108
|
+
|
93
109
|
it "creates an EC2 instance, assigns existing EIP and bootstraps it" do
|
94
110
|
@knife_ec2_create.config[:associate_eip] = @eip
|
95
111
|
|
96
|
-
@new_ec2_server.stub
|
112
|
+
@new_ec2_server.stub(:public_ip_address).and_return(@eip)
|
97
113
|
@ec2_connection.should_receive(:associate_address).with(@ec2_server_attribs[:id], @eip, nil, '')
|
98
114
|
@new_ec2_server.should_receive(:wait_for).at_least(:twice).and_return(true)
|
99
115
|
|
@@ -111,16 +127,97 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
111
127
|
end
|
112
128
|
end
|
113
129
|
|
130
|
+
describe "run for EC2 Windows instance" do
|
131
|
+
before do
|
132
|
+
@ec2_servers.should_receive(:create).and_return(@new_ec2_server)
|
133
|
+
@ec2_connection.should_receive(:servers).and_return(@ec2_servers)
|
134
|
+
@ec2_connection.should_receive(:addresses)
|
135
|
+
|
136
|
+
Fog::Compute::AWS.should_receive(:new).and_return(@ec2_connection)
|
137
|
+
|
138
|
+
@knife_ec2_create.stub(:puts)
|
139
|
+
@knife_ec2_create.stub(:print)
|
140
|
+
@knife_ec2_create.config[:identity_file] = "~/.ssh/aws-key.pem"
|
141
|
+
@knife_ec2_create.config[:image] = '12345'
|
142
|
+
@knife_ec2_create.stub(:is_image_windows?).and_return(true)
|
143
|
+
@knife_ec2_create.stub(:tcp_test_winrm).and_return(true)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "bootstraps via the WinRM protocol" do
|
147
|
+
@knife_ec2_create.config[:winrm_password] = 'winrm-password'
|
148
|
+
@knife_ec2_create.config[:bootstrap_protocol] = 'winrm'
|
149
|
+
@bootstrap_winrm = Chef::Knife::BootstrapWindowsWinrm.new
|
150
|
+
Chef::Knife::BootstrapWindowsWinrm.stub(:new).and_return(@bootstrap_winrm)
|
151
|
+
@bootstrap_winrm.should_receive(:run)
|
152
|
+
@new_ec2_server.should_receive(:wait_for).and_return(true)
|
153
|
+
@knife_ec2_create.run
|
154
|
+
end
|
155
|
+
|
156
|
+
it "set default distro to windows-chef-client-msi for windows" do
|
157
|
+
@knife_ec2_create.config[:winrm_password] = 'winrm-password'
|
158
|
+
@knife_ec2_create.config[:bootstrap_protocol] = 'winrm'
|
159
|
+
@bootstrap_winrm = Chef::Knife::BootstrapWindowsWinrm.new
|
160
|
+
Chef::Knife::BootstrapWindowsWinrm.stub(:new).and_return(@bootstrap_winrm)
|
161
|
+
@bootstrap_winrm.should_receive(:run)
|
162
|
+
@new_ec2_server.should_receive(:wait_for).and_return(true)
|
163
|
+
@knife_ec2_create.run
|
164
|
+
@knife_ec2_create.config[:distro].should == "windows-chef-client-msi"
|
165
|
+
end
|
166
|
+
|
167
|
+
it "bootstraps via the SSH protocol" do
|
168
|
+
@knife_ec2_create.config[:bootstrap_protocol] = 'ssh'
|
169
|
+
bootstrap_win_ssh = Chef::Knife::BootstrapWindowsSsh.new
|
170
|
+
Chef::Knife::BootstrapWindowsSsh.stub(:new).and_return(bootstrap_win_ssh)
|
171
|
+
bootstrap_win_ssh.should_receive(:run)
|
172
|
+
@new_ec2_server.should_receive(:wait_for).and_return(true)
|
173
|
+
@knife_ec2_create.run
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should use configured SSH port" do
|
177
|
+
@knife_ec2_create.config[:bootstrap_protocol] = 'ssh'
|
178
|
+
@knife_ec2_create.config[:ssh_port] = 422
|
179
|
+
|
180
|
+
@knife_ec2_create.should_receive(:tcp_test_ssh).with('ec2-75.101.253.10.compute-1.amazonaws.com', 422).and_return(true)
|
181
|
+
|
182
|
+
bootstrap_win_ssh = Chef::Knife::BootstrapWindowsSsh.new
|
183
|
+
Chef::Knife::BootstrapWindowsSsh.stub(:new).and_return(bootstrap_win_ssh)
|
184
|
+
bootstrap_win_ssh.should_receive(:run)
|
185
|
+
@new_ec2_server.should_receive(:wait_for).and_return(true)
|
186
|
+
@knife_ec2_create.run
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should never invoke linux bootstrap" do
|
190
|
+
@knife_ec2_create.config[:bootstrap_protocol] = 'winrm'
|
191
|
+
@knife_ec2_create.stub(:windows_password).and_return("")
|
192
|
+
@knife_ec2_create.should_not_receive(:bootstrap_for_linux_node)
|
193
|
+
@new_ec2_server.should_receive(:wait_for).and_return(true)
|
194
|
+
@knife_ec2_create.stub(:bootstrap_for_windows_node).and_return double("bootstrap", :run => true)
|
195
|
+
@knife_ec2_create.run
|
196
|
+
end
|
197
|
+
|
198
|
+
it "waits for EC2 to generate password if not supplied" do
|
199
|
+
@knife_ec2_create.config[:bootstrap_protocol] = 'winrm'
|
200
|
+
@knife_ec2_create.config[:winrm_password] = nil
|
201
|
+
@knife_ec2_create.should_receive(:windows_password).and_return("")
|
202
|
+
@new_ec2_server.stub(:wait_for).and_return(true)
|
203
|
+
@knife_ec2_create.stub(:check_windows_password_available).and_return(true)
|
204
|
+
bootstrap_winrm = Chef::Knife::BootstrapWindowsWinrm.new
|
205
|
+
Chef::Knife::BootstrapWindowsWinrm.stub(:new).and_return(bootstrap_winrm)
|
206
|
+
bootstrap_winrm.should_receive(:run)
|
207
|
+
@knife_ec2_create.run
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
114
211
|
describe "when setting tags" do
|
115
212
|
before do
|
116
213
|
Fog::Compute::AWS.should_receive(:new).and_return(@ec2_connection)
|
117
|
-
@knife_ec2_create.stub
|
118
|
-
@ec2_connection.stub
|
214
|
+
@knife_ec2_create.stub(:bootstrap_for_linux_node).and_return double("bootstrap", :run => true)
|
215
|
+
@ec2_connection.stub(:servers).and_return(@ec2_servers)
|
119
216
|
@ec2_connection.should_receive(:addresses)
|
120
|
-
@new_ec2_server.stub
|
121
|
-
@ec2_servers.stub
|
122
|
-
@knife_ec2_create.stub
|
123
|
-
@knife_ec2_create.stub
|
217
|
+
@new_ec2_server.stub(:wait_for).and_return(true)
|
218
|
+
@ec2_servers.stub(:create).and_return(@new_ec2_server)
|
219
|
+
@knife_ec2_create.stub(:puts)
|
220
|
+
@knife_ec2_create.stub(:print)
|
124
221
|
end
|
125
222
|
|
126
223
|
it "sets the Name tag to the instance id by default" do
|
@@ -156,6 +253,41 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
156
253
|
|
157
254
|
end
|
158
255
|
|
256
|
+
# This shared examples group can be used to house specifications that
|
257
|
+
# are common to both the Linux and Windows bootstraping process. This
|
258
|
+
# would remove a lot of testing duplication that is currently present.
|
259
|
+
shared_examples "generic bootstrap configurations" do
|
260
|
+
context "data bag secret" do
|
261
|
+
before(:each) do
|
262
|
+
Chef::Config[:knife][:secret] = "sys-knife-secret"
|
263
|
+
end
|
264
|
+
|
265
|
+
it "uses the the knife configuration when no explicit value is provided" do
|
266
|
+
expect(bootstrap.config[:secret]).to eql("sys-knife-secret")
|
267
|
+
end
|
268
|
+
|
269
|
+
it "prefers using a provided value instead of the knife confiuration" do
|
270
|
+
subject.config[:secret] = "cli-provided-secret"
|
271
|
+
expect(bootstrap.config[:secret]).to eql("cli-provided-secret")
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
context "data bag secret file" do
|
276
|
+
before(:each) do
|
277
|
+
Chef::Config[:knife][:secret_file] = "sys-knife-secret-file"
|
278
|
+
end
|
279
|
+
|
280
|
+
it "uses the the knife configuration when no explicit value is provided" do
|
281
|
+
expect(bootstrap.config[:secret_file]).to eql("sys-knife-secret-file")
|
282
|
+
end
|
283
|
+
|
284
|
+
it "prefers using a provided value instead of the knife confiuration" do
|
285
|
+
subject.config[:secret_file] = "cli-provided-secret-file"
|
286
|
+
expect(bootstrap.config[:secret_file]).to eql("cli-provided-secret-file")
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
159
291
|
describe "when configuring the bootstrap process" do
|
160
292
|
before do
|
161
293
|
@knife_ec2_create.config[:ssh_user] = "ubuntu"
|
@@ -168,7 +300,12 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
168
300
|
@knife_ec2_create.config[:run_list] = ['role[base]']
|
169
301
|
@knife_ec2_create.config[:json_attributes] = "{'my_attributes':{'foo':'bar'}"
|
170
302
|
|
171
|
-
@bootstrap = @knife_ec2_create.
|
303
|
+
@bootstrap = @knife_ec2_create.bootstrap_for_linux_node(@new_ec2_server, @new_ec2_server.dns_name)
|
304
|
+
end
|
305
|
+
|
306
|
+
include_examples "generic bootstrap configurations" do
|
307
|
+
subject { @knife_ec2_create }
|
308
|
+
let(:bootstrap) { @knife_ec2_create.bootstrap_for_linux_node(@new_ec2_server, @new_ec2_server.dns_name) }
|
172
309
|
end
|
173
310
|
|
174
311
|
it "should set the bootstrap 'name argument' to the hostname of the EC2 server" do
|
@@ -206,7 +343,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
206
343
|
it "configures the bootstrap to use the EC2 server id if no explicit node name is set" do
|
207
344
|
@knife_ec2_create.config[:chef_node_name] = nil
|
208
345
|
|
209
|
-
bootstrap = @knife_ec2_create.
|
346
|
+
bootstrap = @knife_ec2_create.bootstrap_for_linux_node(@new_ec2_server, @new_ec2_server.dns_name)
|
210
347
|
bootstrap.config[:chef_node_name].should == @new_ec2_server.id
|
211
348
|
end
|
212
349
|
|
@@ -215,7 +352,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
215
352
|
|
216
353
|
@knife_ec2_create.config[:prerelease] = true
|
217
354
|
|
218
|
-
bootstrap = @knife_ec2_create.
|
355
|
+
bootstrap = @knife_ec2_create.bootstrap_for_linux_node(@new_ec2_server, @new_ec2_server.dns_name)
|
219
356
|
bootstrap.config[:prerelease].should be_true
|
220
357
|
end
|
221
358
|
|
@@ -235,11 +372,75 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
235
372
|
Chef::Config[:knife][:hints]["ec2"].should_not be_nil
|
236
373
|
end
|
237
374
|
end
|
375
|
+
describe "when configuring the winrm bootstrap process for windows" do
|
376
|
+
before do
|
377
|
+
@knife_ec2_create.stub(:fetch_server_fqdn).and_return("SERVERNAME")
|
378
|
+
@knife_ec2_create.config[:winrm_user] = "Administrator"
|
379
|
+
@knife_ec2_create.config[:winrm_password] = "password"
|
380
|
+
@knife_ec2_create.config[:winrm_port] = 12345
|
381
|
+
@knife_ec2_create.config[:winrm_transport] = 'ssl'
|
382
|
+
@knife_ec2_create.config[:kerberos_realm] = "realm"
|
383
|
+
@knife_ec2_create.config[:bootstrap_protocol] = 'winrm'
|
384
|
+
@knife_ec2_create.config[:kerberos_service] = "service"
|
385
|
+
@knife_ec2_create.config[:chef_node_name] = "blarf"
|
386
|
+
@knife_ec2_create.config[:template_file] = '~/.chef/templates/my-bootstrap.sh.erb'
|
387
|
+
@knife_ec2_create.config[:distro] = 'ubuntu-10.04-magic-sparkles'
|
388
|
+
@knife_ec2_create.config[:run_list] = ['role[base]']
|
389
|
+
@knife_ec2_create.config[:json_attributes] = "{'my_attributes':{'foo':'bar'}"
|
390
|
+
@bootstrap = @knife_ec2_create.bootstrap_for_windows_node(@new_ec2_server, @new_ec2_server.dns_name)
|
391
|
+
end
|
392
|
+
|
393
|
+
include_examples "generic bootstrap configurations" do
|
394
|
+
subject { @knife_ec2_create }
|
395
|
+
let(:bootstrap) { @knife_ec2_create.bootstrap_for_linux_node(@new_ec2_server, @new_ec2_server.dns_name) }
|
396
|
+
end
|
397
|
+
|
398
|
+
it "should set the winrm username correctly" do
|
399
|
+
@bootstrap.config[:winrm_user].should == @knife_ec2_create.config[:winrm_user]
|
400
|
+
end
|
401
|
+
it "should set the winrm password correctly" do
|
402
|
+
@bootstrap.config[:winrm_password].should == @knife_ec2_create.config[:winrm_password]
|
403
|
+
end
|
404
|
+
|
405
|
+
it "should set the winrm port correctly" do
|
406
|
+
@bootstrap.config[:winrm_port].should == @knife_ec2_create.config[:winrm_port]
|
407
|
+
end
|
408
|
+
|
409
|
+
it "should set the winrm transport layer correctly" do
|
410
|
+
@bootstrap.config[:winrm_transport].should == @knife_ec2_create.config[:winrm_transport]
|
411
|
+
end
|
412
|
+
|
413
|
+
it "should set the kerberos realm correctly" do
|
414
|
+
@bootstrap.config[:kerberos_realm].should == @knife_ec2_create.config[:kerberos_realm]
|
415
|
+
end
|
416
|
+
|
417
|
+
it "should set the kerberos service correctly" do
|
418
|
+
@bootstrap.config[:kerberos_service].should == @knife_ec2_create.config[:kerberos_service]
|
419
|
+
end
|
420
|
+
|
421
|
+
it "should set the bootstrap 'name argument' to the Windows/AD hostname of the EC2 server" do
|
422
|
+
@bootstrap.name_args.should == ["SERVERNAME"]
|
423
|
+
end
|
424
|
+
|
425
|
+
it "should set the bootstrap 'name argument' to the hostname of the EC2 server when AD/Kerberos is not used" do
|
426
|
+
@knife_ec2_create.config[:kerberos_realm] = nil
|
427
|
+
@bootstrap = @knife_ec2_create.bootstrap_for_windows_node(@new_ec2_server, @new_ec2_server.dns_name)
|
428
|
+
@bootstrap.name_args.should == ['ec2-75.101.253.10.compute-1.amazonaws.com']
|
429
|
+
end
|
430
|
+
|
431
|
+
it "should set the bootstrap 'first_boot_attributes' correctly" do
|
432
|
+
@bootstrap.config[:first_boot_attributes].should == "{'my_attributes':{'foo':'bar'}"
|
433
|
+
end
|
434
|
+
|
435
|
+
it "configures sets the bootstrap's run_list" do
|
436
|
+
@bootstrap.config[:run_list].should == ['role[base]']
|
437
|
+
end
|
438
|
+
end
|
238
439
|
|
239
440
|
describe "when validating the command-line parameters" do
|
240
441
|
before do
|
241
442
|
Fog::Compute::AWS.stub(:new).and_return(@ec2_connection)
|
242
|
-
@knife_ec2_create.ui.stub
|
443
|
+
@knife_ec2_create.ui.stub(:error)
|
243
444
|
end
|
244
445
|
|
245
446
|
it "disallows security group names when using a VPC" do
|
@@ -255,6 +456,13 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
255
456
|
|
256
457
|
lambda { @knife_ec2_create.validate! }.should raise_error SystemExit
|
257
458
|
end
|
459
|
+
|
460
|
+
it "disallows specifying credentials file and aws keys" do
|
461
|
+
Chef::Config[:knife][:aws_credential_file] = '/apple/pear'
|
462
|
+
File.stub(:read).and_return("AWSAccessKeyId=b\nAWSSecretKey=a")
|
463
|
+
|
464
|
+
lambda { @knife_ec2_create.validate! }.should raise_error SystemExit
|
465
|
+
end
|
258
466
|
end
|
259
467
|
|
260
468
|
describe "when creating the server definition" do
|
@@ -262,6 +470,13 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
262
470
|
Fog::Compute::AWS.stub(:new).and_return(@ec2_connection)
|
263
471
|
end
|
264
472
|
|
473
|
+
it "sets the specified placement_group" do
|
474
|
+
@knife_ec2_create.config[:placement_group] = ['some_placement_group']
|
475
|
+
server_def = @knife_ec2_create.create_server_def
|
476
|
+
|
477
|
+
server_def[:placement_group].should == ['some_placement_group']
|
478
|
+
end
|
479
|
+
|
265
480
|
it "sets the specified security group names" do
|
266
481
|
@knife_ec2_create.config[:security_groups] = ['groupname']
|
267
482
|
server_def = @knife_ec2_create.create_server_def
|
@@ -318,16 +533,29 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
318
533
|
server_def[:subnet_id].should == 'subnet-1a2b3c4d'
|
319
534
|
server_def[:private_ip_address].should == '10.0.0.10'
|
320
535
|
end
|
536
|
+
|
537
|
+
it "sets the IAM server role when one is specified" do
|
538
|
+
@knife_ec2_create.config[:iam_instance_profile] = ['iam-role']
|
539
|
+
server_def = @knife_ec2_create.create_server_def
|
540
|
+
|
541
|
+
server_def[:iam_instance_profile_name].should == ['iam-role']
|
542
|
+
end
|
543
|
+
|
544
|
+
it "doesn't set an IAM server role by default" do
|
545
|
+
server_def = @knife_ec2_create.create_server_def
|
546
|
+
|
547
|
+
server_def[:iam_instance_profile_name].should == nil
|
548
|
+
end
|
321
549
|
end
|
322
550
|
|
323
551
|
describe "ssh_connect_host" do
|
324
552
|
before(:each) do
|
325
|
-
@new_ec2_server.stub
|
553
|
+
@new_ec2_server.stub(
|
326
554
|
:dns_name => 'public_name',
|
327
555
|
:private_ip_address => 'private_ip',
|
328
556
|
:custom => 'custom'
|
329
557
|
)
|
330
|
-
@knife_ec2_create.stub
|
558
|
+
@knife_ec2_create.stub(:server => @new_ec2_server)
|
331
559
|
end
|
332
560
|
|
333
561
|
describe "by default" do
|
@@ -338,7 +566,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
338
566
|
|
339
567
|
describe "with vpc_mode?" do
|
340
568
|
it 'should use private ip' do
|
341
|
-
@knife_ec2_create.stub
|
569
|
+
@knife_ec2_create.stub(:vpc_mode? => true)
|
342
570
|
@knife_ec2_create.ssh_connect_host.should == 'private_ip'
|
343
571
|
end
|
344
572
|
|