knife-ec2 0.18.2 → 0.19.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.expeditor/config.yml +13 -16
- data/.github/CODEOWNERS +4 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +14 -0
- data/.gitignore +0 -1
- data/.rspec +2 -0
- data/.rubocop.yml +30 -0
- data/.travis.yml +10 -17
- data/CHANGELOG.md +29 -7
- data/DOC_CHANGES.md +2 -12
- data/Gemfile +26 -2
- data/README.md +72 -75
- data/RELEASE_NOTES.md +10 -0
- data/Rakefile +25 -26
- data/VERSION +1 -1
- data/knife-ec2.gemspec +13 -20
- data/lib/chef/knife/ec2_ami_list.rb +31 -34
- data/lib/chef/knife/ec2_base.rb +137 -94
- data/lib/chef/knife/ec2_flavor_list.rb +12 -13
- data/lib/chef/knife/ec2_server_create.rb +440 -461
- data/lib/chef/knife/ec2_server_delete.rb +43 -41
- data/lib/chef/knife/ec2_server_list.rb +31 -28
- data/lib/chef/knife/s3_source.rb +22 -3
- data/lib/knife-ec2/version.rb +2 -2
- data/spec/spec_helper.rb +10 -11
- data/spec/unit/ec2_ami_list_spec.rb +297 -297
- data/spec/unit/ec2_flavor_list_spec.rb +18 -18
- data/spec/unit/ec2_server_create_spec.rb +952 -951
- data/spec/unit/ec2_server_delete_spec.rb +60 -61
- data/spec/unit/ec2_server_list_spec.rb +28 -28
- data/spec/unit/s3_source_deps_spec.rb +7 -7
- data/spec/unit/s3_source_spec.rb +17 -17
- metadata +26 -79
- data/CONTRIBUTING.md +0 -245
@@ -13,24 +13,24 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
#
|
15
15
|
|
16
|
-
require File.expand_path(
|
17
|
-
require
|
16
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
17
|
+
require "fog/aws"
|
18
18
|
|
19
19
|
describe Chef::Knife::Ec2FlavorList do
|
20
20
|
|
21
|
-
describe
|
21
|
+
describe "#run" do
|
22
22
|
let(:knife_flavor_list) { Chef::Knife::Ec2FlavorList.new }
|
23
23
|
let(:ec2_connection) { double(Fog::Compute::AWS) }
|
24
24
|
before do
|
25
25
|
allow(knife_flavor_list).to receive(:connection).and_return(ec2_connection)
|
26
|
-
@flavor1 = double("flavor1", :
|
26
|
+
@flavor1 = double("flavor1", name: "High-CPU Medium", architecture: "32", id: "c1.medium", bits: "32", cores: "5", ram: "1740.8", disk: "350", ebs_optimized_available: "false", instance_store_volumes: "0")
|
27
27
|
|
28
28
|
allow(ec2_connection).to receive(:flavors).and_return([@flavor1])
|
29
29
|
|
30
30
|
end
|
31
31
|
|
32
|
-
it
|
33
|
-
ec2_flavors = double(:
|
32
|
+
it "invokes validate!" do
|
33
|
+
ec2_flavors = double(sort_by: [])
|
34
34
|
|
35
35
|
allow(ec2_connection).to receive(:flavors).and_return(ec2_flavors)
|
36
36
|
allow(knife_flavor_list.ui).to receive(:warn)
|
@@ -38,11 +38,11 @@ describe Chef::Knife::Ec2FlavorList do
|
|
38
38
|
knife_flavor_list.run
|
39
39
|
end
|
40
40
|
|
41
|
-
context
|
42
|
-
it
|
41
|
+
context "when region is not specified" do
|
42
|
+
it "shows warning that default region will be will be used" do
|
43
43
|
knife_flavor_list.config.delete(:region)
|
44
44
|
Chef::Config[:knife].delete(:region)
|
45
|
-
ec2_flavors = double(:
|
45
|
+
ec2_flavors = double(sort_by: [])
|
46
46
|
allow(ec2_connection).to receive(:flavors).and_return(ec2_flavors)
|
47
47
|
allow(knife_flavor_list).to receive(:validate!)
|
48
48
|
expect(knife_flavor_list.ui).to receive(:warn).with("No region was specified in knife.rb or as an argument. The default region, us-east-1, will be used:")
|
@@ -50,28 +50,28 @@ describe Chef::Knife::Ec2FlavorList do
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
context
|
54
|
-
context
|
53
|
+
context "--format option" do
|
54
|
+
context "when format=summary" do
|
55
55
|
before do
|
56
|
-
@output_s=["ID", "Name", "Architecture", "RAM", "Disk", "Cores", "c1.medium", "High-CPU Medium", "32-bit", "1740.8", "350 GB", "5"]
|
57
|
-
knife_flavor_list.config[:format] =
|
56
|
+
@output_s = ["ID", "Name", "Architecture", "RAM", "Disk", "Cores", "c1.medium", "High-CPU Medium", "32-bit", "1740.8", "350 GB", "5"]
|
57
|
+
knife_flavor_list.config[:format] = "summary"
|
58
58
|
allow(knife_flavor_list.ui).to receive(:warn)
|
59
59
|
allow(knife_flavor_list).to receive(:validate!)
|
60
60
|
end
|
61
61
|
|
62
|
-
it
|
62
|
+
it "shows the output in summary format" do
|
63
63
|
expect(knife_flavor_list.ui).to receive(:list).with(@output_s, :uneven_columns_across, 6)
|
64
64
|
knife_flavor_list.run
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
context
|
68
|
+
context "when format=json" do
|
69
69
|
before do
|
70
|
-
knife_flavor_list.config[:format] =
|
70
|
+
knife_flavor_list.config[:format] = "json"
|
71
71
|
allow(knife_flavor_list.ui).to receive(:warn)
|
72
72
|
end
|
73
73
|
|
74
|
-
it
|
74
|
+
it "shows the output in json format" do
|
75
75
|
allow(ec2_connection).to receive(:flavors).and_return([])
|
76
76
|
allow(knife_flavor_list).to receive(:validate!)
|
77
77
|
allow(knife_flavor_list).to receive(:format_for_display)
|
@@ -80,5 +80,5 @@ describe Chef::Knife::Ec2FlavorList do
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
83
|
-
end
|
83
|
+
end
|
84
84
|
end
|
@@ -16,14 +16,15 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
require File.expand_path(
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
19
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
20
|
+
require "net/ssh/proxy/http"
|
21
|
+
require "net/ssh/proxy/command"
|
22
|
+
require "net/ssh/gateway"
|
23
|
+
require "fog/aws"
|
24
|
+
require "chef/knife/bootstrap"
|
25
|
+
require "chef/knife/bootstrap_windows_winrm"
|
26
|
+
require "chef/knife/bootstrap_windows_ssh"
|
27
|
+
require "chef/util/path_helper"
|
27
28
|
|
28
29
|
describe Chef::Knife::Ec2ServerCreate do
|
29
30
|
let(:knife_ec2_create) { Chef::Knife::Ec2ServerCreate.new }
|
@@ -34,65 +35,67 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
34
35
|
let(:spot_requests) { double }
|
35
36
|
let(:new_spot_request) { double }
|
36
37
|
|
37
|
-
let(:ec2_server_attribs)
|
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
|
-
|
38
|
+
let(:ec2_server_attribs) do
|
39
|
+
{ id: "i-39382318",
|
40
|
+
flavor_id: "m1.small",
|
41
|
+
image_id: "ami-47241231",
|
42
|
+
placement_group: "some_placement_group",
|
43
|
+
availability_zone: "us-west-1",
|
44
|
+
key_name: "my_ssh_key",
|
45
|
+
groups: %w{group1 group2},
|
46
|
+
security_group_ids: ["sg-00aa11bb"],
|
47
|
+
dns_name: "ec2-75.101.253.10.compute-1.amazonaws.com",
|
48
|
+
public_ip_address: "75.101.253.10",
|
49
|
+
private_dns_name: "ip-10-251-75-20.ec2.internal",
|
50
|
+
private_ip_address: "10.251.75.20",
|
51
|
+
root_device_type: "not_ebs",
|
52
|
+
block_device_mapping: [{ "volumeId" => "456" }] } end
|
53
|
+
|
54
|
+
let (:server) { double(id: "i-123" ) }
|
55
|
+
|
56
|
+
let(:spot_request_attribs) do
|
57
|
+
{ id: "test_spot_request_id",
|
58
|
+
price: 0.001,
|
59
|
+
request_type: "persistent",
|
60
|
+
created_at: "2015-07-14 09:53:11 UTC",
|
61
|
+
instance_count: nil,
|
62
|
+
instance_id: "test_spot_instance_id",
|
63
|
+
state: "open",
|
64
|
+
key_name: "ssh_key_name",
|
65
|
+
availability_zone: nil,
|
66
|
+
flavor_id: "m1.small",
|
67
|
+
image_id: "image" } end
|
68
|
+
|
69
|
+
let(:my_vpc) { "vpc-12345678" }
|
67
70
|
|
68
71
|
before(:each) do
|
69
72
|
knife_ec2_create.initial_sleep_delay = 0
|
70
73
|
allow(knife_ec2_create).to receive(:tcp_test_ssh).and_return(true)
|
71
74
|
|
72
75
|
{
|
73
|
-
:
|
74
|
-
:
|
75
|
-
:
|
76
|
-
:
|
77
|
-
:
|
78
|
-
|
76
|
+
image: "image",
|
77
|
+
ssh_key_name: "ssh_key_name",
|
78
|
+
aws_access_key_id: "aws_access_key_id",
|
79
|
+
aws_secret_access_key: "aws_secret_access_key",
|
80
|
+
network_interfaces: ["eni-12345678",
|
81
|
+
"eni-87654321"],
|
79
82
|
}.each do |key, value|
|
80
83
|
Chef::Config[:knife][key] = value
|
81
84
|
end
|
82
85
|
|
83
|
-
allow(ec2_connection).to receive(:tags).and_return double(
|
84
|
-
allow(ec2_connection).to receive(:volume_tags).and_return double(
|
85
|
-
allow(ec2_connection).to receive_message_chain(:images, :get).and_return double(
|
86
|
-
allow(ec2_connection).to receive(:addresses).and_return [double(
|
87
|
-
:
|
88
|
-
:
|
89
|
-
:
|
90
|
-
:
|
86
|
+
allow(ec2_connection).to receive(:tags).and_return double("create", create: true)
|
87
|
+
allow(ec2_connection).to receive(:volume_tags).and_return double("create", create: true)
|
88
|
+
allow(ec2_connection).to receive_message_chain(:images, :get).and_return double("ami", root_device_type: "not_ebs", platform: "linux")
|
89
|
+
allow(ec2_connection).to receive(:addresses).and_return [double("addesses", {
|
90
|
+
domain: "standard",
|
91
|
+
public_ip: "111.111.111.111",
|
92
|
+
server_id: nil,
|
93
|
+
allocation_id: "" })]
|
91
94
|
|
92
95
|
allow(ec2_connection).to receive(:subnets).and_return [@subnet_1, @subnet_2]
|
93
96
|
allow(ec2_connection).to receive_message_chain(:network_interfaces, :all).and_return [
|
94
|
-
double(
|
95
|
-
double(
|
97
|
+
double("network_interfaces", network_interface_id: "eni-12345678"),
|
98
|
+
double("network_interfaces", network_interface_id: "eni-87654321")
|
96
99
|
]
|
97
100
|
|
98
101
|
ec2_server_attribs.each_pair do |attrib, value|
|
@@ -106,8 +109,8 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
106
109
|
@bootstrap = Chef::Knife::Bootstrap.new
|
107
110
|
allow(Chef::Knife::Bootstrap).to receive(:new).and_return(@bootstrap)
|
108
111
|
|
109
|
-
@validation_key_url =
|
110
|
-
@validation_key_file =
|
112
|
+
@validation_key_url = "s3://bucket/foo/bar"
|
113
|
+
@validation_key_file = "/tmp/a_good_temp_file"
|
111
114
|
@validation_key_body = "TEST VALIDATION KEY\n"
|
112
115
|
@vpc_id = "vpc-1a2b3c4d"
|
113
116
|
@vpc_security_group_ids = ["sg-1a2b3c4d"]
|
@@ -117,25 +120,25 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
117
120
|
before do
|
118
121
|
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
119
122
|
knife_ec2_create.config[:spot_price] = 0.001
|
120
|
-
knife_ec2_create.config[:spot_request_type] =
|
123
|
+
knife_ec2_create.config[:spot_request_type] = "persistent"
|
121
124
|
allow(knife_ec2_create).to receive(:puts)
|
122
125
|
allow(knife_ec2_create).to receive(:msg_pair)
|
123
|
-
allow(knife_ec2_create.ui).to receive(:color).and_return(
|
126
|
+
allow(knife_ec2_create.ui).to receive(:color).and_return("")
|
124
127
|
allow(knife_ec2_create).to receive(:confirm)
|
125
128
|
@spot_instance_server_def = {
|
126
|
-
:
|
127
|
-
:
|
128
|
-
:
|
129
|
-
:
|
130
|
-
:
|
131
|
-
:
|
132
|
-
:
|
133
|
-
:
|
134
|
-
:
|
135
|
-
:
|
136
|
-
:
|
137
|
-
:
|
138
|
-
:
|
129
|
+
image_id: "image",
|
130
|
+
groups: nil,
|
131
|
+
flavor_id: nil,
|
132
|
+
key_name: "ssh_key_name",
|
133
|
+
availability_zone: nil,
|
134
|
+
security_group_ids: nil,
|
135
|
+
price: 0.001,
|
136
|
+
request_type: "persistent",
|
137
|
+
placement_group: nil,
|
138
|
+
iam_instance_profile_name: nil,
|
139
|
+
ebs_optimized: "false",
|
140
|
+
instance_initiated_shutdown_behavior: nil,
|
141
|
+
chef_tag: nil,
|
139
142
|
}
|
140
143
|
allow(@bootstrap).to receive(:run)
|
141
144
|
end
|
@@ -152,7 +155,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
152
155
|
:get).with(new_spot_request.instance_id).and_return(new_ec2_server)
|
153
156
|
allow(new_ec2_server).to receive(:wait_for).and_return(true)
|
154
157
|
knife_ec2_create.run
|
155
|
-
expect(new_spot_request.request_type).to eq(
|
158
|
+
expect(new_spot_request.request_type).to eq("persistent")
|
156
159
|
end
|
157
160
|
|
158
161
|
it "successfully creates a new spot instance" do
|
@@ -178,59 +181,59 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
178
181
|
knife_ec2_create.run
|
179
182
|
end
|
180
183
|
|
181
|
-
context
|
182
|
-
context
|
183
|
-
context
|
184
|
+
context "spot-wait-mode option" do
|
185
|
+
context "when spot-price is not given" do
|
186
|
+
context "spot-wait-mode option is not given" do
|
184
187
|
before do
|
185
188
|
knife_ec2_create.config.delete(:spot_price)
|
186
189
|
end
|
187
190
|
|
188
|
-
it
|
191
|
+
it "does not raise error" do
|
189
192
|
expect(knife_ec2_create.ui).to_not receive(:error).with(
|
190
|
-
|
193
|
+
"spot-wait-mode option requires that a spot-price option is set."
|
191
194
|
)
|
192
195
|
expect { knife_ec2_create.validate! }.to_not raise_error
|
193
196
|
end
|
194
197
|
end
|
195
198
|
|
196
|
-
context
|
199
|
+
context "spot-wait-mode option is given" do
|
197
200
|
before do
|
198
201
|
knife_ec2_create.config.delete(:spot_price)
|
199
|
-
knife_ec2_create.config[:spot_wait_mode] =
|
202
|
+
knife_ec2_create.config[:spot_wait_mode] = "wait"
|
200
203
|
end
|
201
204
|
|
202
|
-
it
|
205
|
+
it "raises error" do
|
203
206
|
expect(knife_ec2_create.ui).to receive(:error).with(
|
204
|
-
|
207
|
+
"spot-wait-mode option requires that a spot-price option is set."
|
205
208
|
)
|
206
209
|
expect { knife_ec2_create.validate! }.to raise_error(SystemExit)
|
207
210
|
end
|
208
211
|
end
|
209
212
|
end
|
210
213
|
|
211
|
-
context
|
212
|
-
context
|
214
|
+
context "when spot-price is given" do
|
215
|
+
context "spot-wait-mode option is not given" do
|
213
216
|
before do
|
214
217
|
knife_ec2_create.config[:spot_price] = 0.001
|
215
218
|
end
|
216
219
|
|
217
|
-
it
|
220
|
+
it "does not raise error" do
|
218
221
|
expect(knife_ec2_create.ui).to_not receive(:error).with(
|
219
|
-
|
222
|
+
"spot-wait-mode option requires that a spot-price option is set."
|
220
223
|
)
|
221
224
|
expect { knife_ec2_create.validate! }.to_not raise_error
|
222
225
|
end
|
223
226
|
end
|
224
227
|
|
225
|
-
context
|
228
|
+
context "spot-wait-mode option is given" do
|
226
229
|
before do
|
227
230
|
knife_ec2_create.config[:spot_price] = 0.001
|
228
|
-
knife_ec2_create.config[:spot_wait_mode] =
|
231
|
+
knife_ec2_create.config[:spot_wait_mode] = "exit"
|
229
232
|
end
|
230
233
|
|
231
|
-
it
|
234
|
+
it "does not raise error" do
|
232
235
|
expect(knife_ec2_create.ui).to_not receive(:error).with(
|
233
|
-
|
236
|
+
"spot-wait-mode option requires that a spot-price option is set."
|
234
237
|
)
|
235
238
|
expect { knife_ec2_create.validate! }.to_not raise_error
|
236
239
|
end
|
@@ -250,17 +253,10 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
250
253
|
|
251
254
|
allow(knife_ec2_create).to receive(:puts)
|
252
255
|
allow(knife_ec2_create).to receive(:print)
|
253
|
-
knife_ec2_create.config[:image] =
|
256
|
+
knife_ec2_create.config[:image] = "12345"
|
254
257
|
expect(@bootstrap).to receive(:run)
|
255
258
|
end
|
256
259
|
|
257
|
-
it "defaults to a distro of 'chef-full' for a linux instance" do
|
258
|
-
expect(new_ec2_server).to receive(:wait_for).and_return(true)
|
259
|
-
knife_ec2_create.config[:distro] = knife_ec2_create.options[:distro][:default]
|
260
|
-
expect(knife_ec2_create).to receive(:default_bootstrap_template).and_return('chef-full')
|
261
|
-
knife_ec2_create.run
|
262
|
-
end
|
263
|
-
|
264
260
|
it "creates an EC2 instance and bootstraps it" do
|
265
261
|
expect(new_ec2_server).to receive(:wait_for).and_return(true)
|
266
262
|
expect(knife_ec2_create).to receive(:ssh_override_winrm)
|
@@ -325,7 +321,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
325
321
|
knife_ec2_create.config[:associate_eip] = @eip
|
326
322
|
|
327
323
|
allow(new_ec2_server).to receive(:public_ip_address).and_return(@eip)
|
328
|
-
expect(ec2_connection).to receive(:associate_address).with(ec2_server_attribs[:id], @eip, nil,
|
324
|
+
expect(ec2_connection).to receive(:associate_address).with(ec2_server_attribs[:id], @eip, nil, "")
|
329
325
|
expect(new_ec2_server).to receive(:wait_for).at_least(:twice).and_return(true)
|
330
326
|
|
331
327
|
knife_ec2_create.run
|
@@ -352,14 +348,14 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
352
348
|
knife_ec2_create.run
|
353
349
|
end
|
354
350
|
|
355
|
-
it
|
351
|
+
it "actually writes to the validation key tempfile" do
|
356
352
|
expect(new_ec2_server).to receive(:wait_for).and_return(true)
|
357
353
|
Chef::Config[:knife][:validation_key_url] = @validation_key_url
|
358
354
|
knife_ec2_create.config[:validation_key_url] = @validation_key_url
|
359
355
|
|
360
356
|
allow(knife_ec2_create).to receive_message_chain(:validation_key_tmpfile, :path).and_return(@validation_key_file)
|
361
357
|
allow(Chef::Knife::S3Source).to receive(:fetch).with(@validation_key_url).and_return(@validation_key_body)
|
362
|
-
expect(File).to receive(:open).with(@validation_key_file,
|
358
|
+
expect(File).to receive(:open).with(@validation_key_file, "w")
|
363
359
|
knife_ec2_create.run
|
364
360
|
end
|
365
361
|
end
|
@@ -375,14 +371,14 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
375
371
|
allow(knife_ec2_create).to receive(:puts)
|
376
372
|
allow(knife_ec2_create).to receive(:print)
|
377
373
|
knife_ec2_create.config[:identity_file] = "~/.ssh/aws-key.pem"
|
378
|
-
knife_ec2_create.config[:image] =
|
374
|
+
knife_ec2_create.config[:image] = "12345"
|
379
375
|
allow(knife_ec2_create).to receive(:is_image_windows?).and_return(true)
|
380
376
|
allow(knife_ec2_create).to receive(:tcp_test_winrm).and_return(true)
|
381
377
|
end
|
382
378
|
|
383
379
|
it "bootstraps via the WinRM protocol" do
|
384
|
-
knife_ec2_create.config[:winrm_password] =
|
385
|
-
knife_ec2_create.config[:bootstrap_protocol] =
|
380
|
+
knife_ec2_create.config[:winrm_password] = "winrm-password"
|
381
|
+
knife_ec2_create.config[:bootstrap_protocol] = "winrm"
|
386
382
|
@bootstrap_winrm = Chef::Knife::BootstrapWindowsWinrm.new
|
387
383
|
allow(Chef::Knife::BootstrapWindowsWinrm).to receive(:new).and_return(@bootstrap_winrm)
|
388
384
|
expect(@bootstrap_winrm).to receive(:run)
|
@@ -391,20 +387,8 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
391
387
|
knife_ec2_create.run
|
392
388
|
end
|
393
389
|
|
394
|
-
it "set default distro to windows-chef-client-msi for windows" do
|
395
|
-
knife_ec2_create.config[:winrm_password] = 'winrm-password'
|
396
|
-
knife_ec2_create.config[:bootstrap_protocol] = 'winrm'
|
397
|
-
@bootstrap_winrm = Chef::Knife::BootstrapWindowsWinrm.new
|
398
|
-
allow(Chef::Knife::BootstrapWindowsWinrm).to receive(:new).and_return(@bootstrap_winrm)
|
399
|
-
expect(@bootstrap_winrm).to receive(:run)
|
400
|
-
expect(new_ec2_server).to receive(:wait_for).and_return(true)
|
401
|
-
allow(knife_ec2_create).to receive(:is_image_windows?).and_return(true)
|
402
|
-
expect(knife_ec2_create).to receive(:default_bootstrap_template).and_return("windows-chef-client-msi")
|
403
|
-
knife_ec2_create.run
|
404
|
-
end
|
405
|
-
|
406
390
|
it "bootstraps via the SSH protocol" do
|
407
|
-
knife_ec2_create.config[:bootstrap_protocol] =
|
391
|
+
knife_ec2_create.config[:bootstrap_protocol] = "ssh"
|
408
392
|
bootstrap_win_ssh = Chef::Knife::BootstrapWindowsSsh.new
|
409
393
|
allow(Chef::Knife::BootstrapWindowsSsh).to receive(:new).and_return(bootstrap_win_ssh)
|
410
394
|
expect(bootstrap_win_ssh).to receive(:run)
|
@@ -414,10 +398,10 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
414
398
|
end
|
415
399
|
|
416
400
|
it "should use configured SSH port" do
|
417
|
-
knife_ec2_create.config[:bootstrap_protocol] =
|
401
|
+
knife_ec2_create.config[:bootstrap_protocol] = "ssh"
|
418
402
|
knife_ec2_create.config[:ssh_port] = 422
|
419
403
|
|
420
|
-
expect(knife_ec2_create).to receive(:tcp_test_ssh).with(
|
404
|
+
expect(knife_ec2_create).to receive(:tcp_test_ssh).with("ec2-75.101.253.10.compute-1.amazonaws.com", 422).and_return(true)
|
421
405
|
|
422
406
|
bootstrap_win_ssh = Chef::Knife::BootstrapWindowsSsh.new
|
423
407
|
allow(Chef::Knife::BootstrapWindowsSsh).to receive(:new).and_return(bootstrap_win_ssh)
|
@@ -427,16 +411,16 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
427
411
|
end
|
428
412
|
|
429
413
|
it "should never invoke linux bootstrap" do
|
430
|
-
knife_ec2_create.config[:bootstrap_protocol] =
|
414
|
+
knife_ec2_create.config[:bootstrap_protocol] = "winrm"
|
431
415
|
allow(knife_ec2_create).to receive(:windows_password).and_return("")
|
432
416
|
expect(knife_ec2_create).not_to receive(:bootstrap_for_linux_node)
|
433
417
|
expect(new_ec2_server).to receive(:wait_for).and_return(true)
|
434
|
-
allow(knife_ec2_create).to receive(:bootstrap_for_windows_node).and_return double("bootstrap", :
|
418
|
+
allow(knife_ec2_create).to receive(:bootstrap_for_windows_node).and_return double("bootstrap", run: true)
|
435
419
|
knife_ec2_create.run
|
436
420
|
end
|
437
421
|
|
438
422
|
it "waits for EC2 to generate password if not supplied" do
|
439
|
-
knife_ec2_create.config[:bootstrap_protocol] =
|
423
|
+
knife_ec2_create.config[:bootstrap_protocol] = "winrm"
|
440
424
|
knife_ec2_create.config[:winrm_password] = nil
|
441
425
|
expect(knife_ec2_create).to receive(:windows_password).and_return("")
|
442
426
|
allow(new_ec2_server).to receive(:wait_for).and_return(true)
|
@@ -451,7 +435,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
451
435
|
describe "when setting tags" do
|
452
436
|
before do
|
453
437
|
expect(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
454
|
-
allow(knife_ec2_create).to receive(:bootstrap_for_linux_node).and_return double("bootstrap", :
|
438
|
+
allow(knife_ec2_create).to receive(:bootstrap_for_linux_node).and_return double("bootstrap", run: true)
|
455
439
|
allow(ec2_connection).to receive(:servers).and_return(ec2_servers)
|
456
440
|
expect(ec2_connection).to receive(:addresses)
|
457
441
|
allow(new_ec2_server).to receive(:wait_for).and_return(true)
|
@@ -463,57 +447,57 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
463
447
|
end
|
464
448
|
|
465
449
|
it "sets the Name tag to the instance id by default" do
|
466
|
-
expect(ec2_connection.tags).to receive(:create).with(:
|
467
|
-
|
468
|
-
|
450
|
+
expect(ec2_connection.tags).to receive(:create).with(key: "Name",
|
451
|
+
value: new_ec2_server.id,
|
452
|
+
resource_id: new_ec2_server.id)
|
469
453
|
knife_ec2_create.run
|
470
454
|
end
|
471
455
|
|
472
456
|
it "sets the Name tag to the chef_node_name when given" do
|
473
457
|
knife_ec2_create.config[:chef_node_name] = "wombat"
|
474
|
-
expect(ec2_connection.tags).to receive(:create).with(:
|
475
|
-
|
476
|
-
|
458
|
+
expect(ec2_connection.tags).to receive(:create).with(key: "Name",
|
459
|
+
value: "wombat",
|
460
|
+
resource_id: new_ec2_server.id)
|
477
461
|
knife_ec2_create.run
|
478
462
|
end
|
479
463
|
|
480
464
|
it "sets the Name tag to the specified name when given --aws-tag Name=NAME" do
|
481
465
|
knife_ec2_create.config[:aws_tag] = ["Name=bobcat"]
|
482
|
-
expect(ec2_connection.tags).to receive(:create).with(:
|
483
|
-
|
484
|
-
|
466
|
+
expect(ec2_connection.tags).to receive(:create).with(key: "Name",
|
467
|
+
value: "bobcat",
|
468
|
+
resource_id: new_ec2_server.id)
|
485
469
|
knife_ec2_create.run
|
486
470
|
end
|
487
471
|
|
488
472
|
it "sets arbitrary aws tags" do
|
489
473
|
knife_ec2_create.config[:aws_tag] = ["foo=bar"]
|
490
|
-
expect(ec2_connection.tags).to receive(:create).with(:
|
491
|
-
|
492
|
-
|
474
|
+
expect(ec2_connection.tags).to receive(:create).with(key: "foo",
|
475
|
+
value: "bar",
|
476
|
+
resource_id: new_ec2_server.id)
|
493
477
|
knife_ec2_create.run
|
494
478
|
end
|
495
479
|
|
496
480
|
it "sets the Name tag to the specified name when given --tags Name=NAME" do
|
497
481
|
knife_ec2_create.config[:tags] = ["Name=bobcat"]
|
498
|
-
expect(ec2_connection.tags).to receive(:create).with(:
|
499
|
-
|
500
|
-
|
482
|
+
expect(ec2_connection.tags).to receive(:create).with(key: "Name",
|
483
|
+
value: "bobcat",
|
484
|
+
resource_id: new_ec2_server.id)
|
501
485
|
knife_ec2_create.run
|
502
486
|
end
|
503
487
|
|
504
488
|
it "sets arbitrary tags" do
|
505
489
|
knife_ec2_create.config[:tags] = ["foo=bar"]
|
506
|
-
expect(ec2_connection.tags).to receive(:create).with(:
|
507
|
-
|
508
|
-
|
490
|
+
expect(ec2_connection.tags).to receive(:create).with(key: "foo",
|
491
|
+
value: "bar",
|
492
|
+
resource_id: new_ec2_server.id)
|
509
493
|
knife_ec2_create.run
|
510
494
|
end
|
511
495
|
|
512
496
|
it 'raises deprecated warning "[DEPRECATED] --tags option is deprecated. Use --aws-tag option instead."' do
|
513
497
|
knife_ec2_create.config[:tags] = ["foo=bar"]
|
514
|
-
expect(ec2_connection.tags).to receive(:create).with(:
|
515
|
-
|
516
|
-
|
498
|
+
expect(ec2_connection.tags).to receive(:create).with(key: "foo",
|
499
|
+
value: "bar",
|
500
|
+
resource_id: new_ec2_server.id)
|
517
501
|
expect(knife_ec2_create.ui).to receive(:warn).with("[DEPRECATED] --tags option is deprecated. Use --aws-tag option instead.").exactly(2).times
|
518
502
|
knife_ec2_create.validate!
|
519
503
|
knife_ec2_create.run
|
@@ -523,7 +507,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
523
507
|
describe "when setting volume tags" do
|
524
508
|
before do
|
525
509
|
expect(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
526
|
-
allow(knife_ec2_create).to receive(:bootstrap_for_linux_node).and_return double("bootstrap", :
|
510
|
+
allow(knife_ec2_create).to receive(:bootstrap_for_linux_node).and_return double("bootstrap", run: true)
|
527
511
|
allow(ec2_connection).to receive(:servers).and_return(ec2_servers)
|
528
512
|
allow(ec2_servers).to receive(:create).and_return(new_ec2_server)
|
529
513
|
allow(new_ec2_server).to receive(:wait_for).and_return(true)
|
@@ -532,9 +516,9 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
532
516
|
|
533
517
|
it "sets the volume tags as specified when given --volume-tags Key=Value" do
|
534
518
|
knife_ec2_create.config[:volume_tags] = ["VolumeTagKey=TestVolumeTagValue"]
|
535
|
-
expect(ec2_connection.tags).to receive(:create).with(:
|
536
|
-
|
537
|
-
|
519
|
+
expect(ec2_connection.tags).to receive(:create).with(key: "VolumeTagKey",
|
520
|
+
value: "TestVolumeTagValue",
|
521
|
+
resource_id: new_ec2_server.block_device_mapping.first["volumeId"])
|
538
522
|
knife_ec2_create.run
|
539
523
|
end
|
540
524
|
end
|
@@ -548,7 +532,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
548
532
|
Chef::Config[:knife][:secret] = "sys-knife-secret"
|
549
533
|
end
|
550
534
|
|
551
|
-
|
535
|
+
it "uses the the knife configuration when no explicit value is provided" do
|
552
536
|
expect(bootstrap.config[:secret]).to eql("sys-knife-secret")
|
553
537
|
end
|
554
538
|
|
@@ -581,40 +565,39 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
581
565
|
end
|
582
566
|
end
|
583
567
|
|
584
|
-
context
|
568
|
+
context "S3-based secret" do
|
585
569
|
before(:each) do
|
586
570
|
Chef::Config[:knife][:s3_secret] =
|
587
|
-
|
571
|
+
"s3://test.bucket/folder/encrypted_data_bag_secret"
|
588
572
|
@secret_content = "TEST DATA BAG SECRET\n"
|
589
573
|
allow(knife_ec2_create).to receive(:s3_secret).and_return(@secret_content)
|
590
574
|
end
|
591
575
|
|
592
|
-
it
|
576
|
+
it "sets the secret to the expected test string" do
|
593
577
|
expect(bootstrap.config[:secret]).to eql(@secret_content)
|
594
578
|
end
|
595
579
|
end
|
596
580
|
end
|
597
581
|
|
598
|
-
describe
|
582
|
+
describe "S3 secret test cases" do
|
599
583
|
before do
|
600
584
|
Chef::Config[:knife][:s3_secret] =
|
601
|
-
|
602
|
-
knife_ec2_create.config[:distro] = 'ubuntu-10.04-magic-sparkles'
|
585
|
+
"s3://test.bucket/folder/encrypted_data_bag_secret"
|
603
586
|
@secret_content = "TEST DATA BAG SECRET\n"
|
604
587
|
allow(knife_ec2_create).to receive(:s3_secret).and_return(@secret_content)
|
605
588
|
allow(Chef::Knife).to receive(:Bootstrap)
|
606
589
|
@bootstrap = knife_ec2_create.bootstrap_for_linux_node(new_ec2_server, new_ec2_server.dns_name)
|
607
590
|
end
|
608
591
|
|
609
|
-
context
|
610
|
-
it
|
592
|
+
context "when s3 secret option is passed" do
|
593
|
+
it "sets the s3 secret value to cl_secret key" do
|
611
594
|
knife_ec2_create.bootstrap_common_params(@bootstrap)
|
612
595
|
expect(Chef::Config[:knife][:cl_secret]).to eql(@secret_content)
|
613
596
|
end
|
614
597
|
end
|
615
598
|
|
616
|
-
context
|
617
|
-
it
|
599
|
+
context "when s3 secret option is not passed" do
|
600
|
+
it "sets the cl_secret value to nil" do
|
618
601
|
Chef::Config[:knife].delete(:s3_secret)
|
619
602
|
Chef::Config[:knife].delete(:cl_secret)
|
620
603
|
knife_ec2_create.bootstrap_common_params(@bootstrap)
|
@@ -681,19 +664,16 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
681
664
|
|
682
665
|
describe "when configuring the bootstrap process" do
|
683
666
|
before do
|
684
|
-
allow(knife_ec2_create).to receive(:evaluate_node_name).and_return(
|
667
|
+
allow(knife_ec2_create).to receive(:evaluate_node_name).and_return("blarf")
|
685
668
|
knife_ec2_create.config[:ssh_user] = "ubuntu"
|
686
669
|
knife_ec2_create.config[:identity_file] = "~/.ssh/aws-key.pem"
|
687
670
|
knife_ec2_create.config[:ssh_port] = 22
|
688
|
-
knife_ec2_create.config[:ssh_gateway] =
|
671
|
+
knife_ec2_create.config[:ssh_gateway] = "bastion.host.com"
|
689
672
|
knife_ec2_create.config[:chef_node_name] = "blarf"
|
690
|
-
knife_ec2_create.config[:
|
691
|
-
knife_ec2_create.config[:distro] = 'ubuntu-10.04-magic-sparkles'
|
692
|
-
knife_ec2_create.config[:run_list] = ['role[base]']
|
673
|
+
knife_ec2_create.config[:run_list] = ["role[base]"]
|
693
674
|
knife_ec2_create.config[:first_boot_attributes] = "{'my_attributes':{'foo':'bar'}"
|
694
675
|
knife_ec2_create.config[:first_boot_attributes_from_file] = "{'my_attributes':{'foo':'bar'}"
|
695
676
|
|
696
|
-
|
697
677
|
@bootstrap = knife_ec2_create.bootstrap_for_linux_node(new_ec2_server, new_ec2_server.dns_name)
|
698
678
|
end
|
699
679
|
|
@@ -703,7 +683,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
703
683
|
end
|
704
684
|
|
705
685
|
it "should set the bootstrap 'name argument' to the hostname of the EC2 server" do
|
706
|
-
expect(@bootstrap.name_args).to eq([
|
686
|
+
expect(@bootstrap.name_args).to eq(["ec2-75.101.253.10.compute-1.amazonaws.com"])
|
707
687
|
end
|
708
688
|
|
709
689
|
it "should set the bootstrap 'first_boot_attributes' correctly" do
|
@@ -715,15 +695,15 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
715
695
|
end
|
716
696
|
|
717
697
|
it "configures sets the bootstrap's run_list" do
|
718
|
-
expect(@bootstrap.config[:run_list]).to eq([
|
698
|
+
expect(@bootstrap.config[:run_list]).to eq(["role[base]"])
|
719
699
|
end
|
720
700
|
|
721
701
|
it "configures the bootstrap to use the correct ssh_user login" do
|
722
|
-
expect(@bootstrap.config[:ssh_user]).to eq(
|
702
|
+
expect(@bootstrap.config[:ssh_user]).to eq("ubuntu")
|
723
703
|
end
|
724
704
|
|
725
705
|
it "configures the bootstrap to use the correct ssh_gateway host" do
|
726
|
-
expect(@bootstrap.config[:ssh_gateway]).to eq(
|
706
|
+
expect(@bootstrap.config[:ssh_gateway]).to eq("bastion.host.com")
|
727
707
|
end
|
728
708
|
|
729
709
|
it "configures the bootstrap to use the correct ssh identity file" do
|
@@ -735,7 +715,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
735
715
|
end
|
736
716
|
|
737
717
|
it "configures the bootstrap to use the configured node name if provided" do
|
738
|
-
expect(@bootstrap.config[:chef_node_name]).to eq(
|
718
|
+
expect(@bootstrap.config[:chef_node_name]).to eq("blarf")
|
739
719
|
end
|
740
720
|
|
741
721
|
it "configures the bootstrap to use the EC2 server id if no explicit node name is set" do
|
@@ -754,18 +734,10 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
754
734
|
expect(bootstrap.config[:prerelease]).to eq(true)
|
755
735
|
end
|
756
736
|
|
757
|
-
it "configures the bootstrap to use the desired distro-specific bootstrap script" do
|
758
|
-
expect(@bootstrap.config[:distro]).to eq('ubuntu-10.04-magic-sparkles')
|
759
|
-
end
|
760
|
-
|
761
737
|
it "configures the bootstrap to use sudo" do
|
762
738
|
expect(@bootstrap.config[:use_sudo]).to eq(true)
|
763
739
|
end
|
764
740
|
|
765
|
-
it "configured the bootstrap to use the desired template" do
|
766
|
-
expect(@bootstrap.config[:template_file]).to eq('~/.chef/templates/my-bootstrap.sh.erb')
|
767
|
-
end
|
768
|
-
|
769
741
|
it "configured the bootstrap to set an ec2 hint (via Chef::Config)" do
|
770
742
|
expect(Chef::Config[:knife][:hints]["ec2"]).not_to be_nil
|
771
743
|
end
|
@@ -778,8 +750,8 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
778
750
|
knife_ec2_create.config[:ssh_password] = "password"
|
779
751
|
knife_ec2_create.config[:ssh_port] = 22
|
780
752
|
knife_ec2_create.config[:forward_agent] = true
|
781
|
-
knife_ec2_create.config[:bootstrap_protocol] =
|
782
|
-
knife_ec2_create.config[:image] =
|
753
|
+
knife_ec2_create.config[:bootstrap_protocol] = "ssh"
|
754
|
+
knife_ec2_create.config[:image] = "12345"
|
783
755
|
allow(knife_ec2_create).to receive(:is_image_windows?).and_return(true)
|
784
756
|
@bootstrap = knife_ec2_create.bootstrap_for_windows_node(new_ec2_server, new_ec2_server.dns_name)
|
785
757
|
end
|
@@ -796,21 +768,19 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
796
768
|
knife_ec2_create.config[:winrm_user] = "Administrator"
|
797
769
|
knife_ec2_create.config[:winrm_password] = "password"
|
798
770
|
knife_ec2_create.config[:winrm_port] = 12345
|
799
|
-
knife_ec2_create.config[:winrm_transport] =
|
771
|
+
knife_ec2_create.config[:winrm_transport] = "ssl"
|
800
772
|
knife_ec2_create.config[:kerberos_realm] = "realm"
|
801
|
-
knife_ec2_create.config[:bootstrap_protocol] =
|
773
|
+
knife_ec2_create.config[:bootstrap_protocol] = "winrm"
|
802
774
|
knife_ec2_create.config[:kerberos_service] = "service"
|
803
775
|
knife_ec2_create.config[:chef_node_name] = "blarf"
|
804
|
-
knife_ec2_create.config[:
|
805
|
-
knife_ec2_create.config[:distro] = 'ubuntu-10.04-magic-sparkles'
|
806
|
-
knife_ec2_create.config[:run_list] = ['role[base]']
|
776
|
+
knife_ec2_create.config[:run_list] = ["role[base]"]
|
807
777
|
knife_ec2_create.config[:first_boot_attributes] = "{'my_attributes':{'foo':'bar'}"
|
808
|
-
knife_ec2_create.config[:winrm_ssl_verify_mode] =
|
809
|
-
knife_ec2_create.config[:msi_url] =
|
778
|
+
knife_ec2_create.config[:winrm_ssl_verify_mode] = "verify_peer"
|
779
|
+
knife_ec2_create.config[:msi_url] = "https://opscode-omnibus-packages.s3.amazonaws.com/windows/2008r2/x86_64/chef-client-12.3.0-1.msi"
|
810
780
|
knife_ec2_create.config[:install_as_service] = true
|
811
781
|
knife_ec2_create.config[:session_timeout] = "90"
|
812
782
|
@bootstrap = knife_ec2_create.bootstrap_for_windows_node(new_ec2_server, new_ec2_server.dns_name)
|
813
|
-
|
783
|
+
end
|
814
784
|
|
815
785
|
include_examples "generic bootstrap configurations" do
|
816
786
|
subject { knife_ec2_create }
|
@@ -847,7 +817,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
847
817
|
it "should set the bootstrap 'name argument' to the hostname of the EC2 server when AD/Kerberos is not used" do
|
848
818
|
knife_ec2_create.config[:kerberos_realm] = nil
|
849
819
|
@bootstrap = knife_ec2_create.bootstrap_for_windows_node(new_ec2_server, new_ec2_server.dns_name)
|
850
|
-
expect(@bootstrap.name_args).to eq([
|
820
|
+
expect(@bootstrap.name_args).to eq(["ec2-75.101.253.10.compute-1.amazonaws.com"])
|
851
821
|
end
|
852
822
|
|
853
823
|
it "should set the bootstrap 'first_boot_attributes' correctly" do
|
@@ -859,7 +829,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
859
829
|
end
|
860
830
|
|
861
831
|
it "should set the bootstrap 'msi_url' correctly" do
|
862
|
-
expect(@bootstrap.config[:msi_url]).to eq(
|
832
|
+
expect(@bootstrap.config[:msi_url]).to eq("https://opscode-omnibus-packages.s3.amazonaws.com/windows/2008r2/x86_64/chef-client-12.3.0-1.msi")
|
863
833
|
end
|
864
834
|
|
865
835
|
it "should set the bootstrap 'install_as_service' correctly" do
|
@@ -871,7 +841,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
871
841
|
end
|
872
842
|
|
873
843
|
it "configures sets the bootstrap's run_list" do
|
874
|
-
expect(@bootstrap.config[:run_list]).to eq([
|
844
|
+
expect(@bootstrap.config[:run_list]).to eq(["role[base]"])
|
875
845
|
end
|
876
846
|
|
877
847
|
it "configures auth_timeout for bootstrap to default to 25 minutes" do
|
@@ -883,7 +853,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
883
853
|
bootstrap = knife_ec2_create.bootstrap_for_windows_node(new_ec2_server, new_ec2_server.dns_name)
|
884
854
|
expect(bootstrap.config[:auth_timeout]).to eq(5)
|
885
855
|
end
|
886
|
-
|
856
|
+
end
|
887
857
|
|
888
858
|
describe "when validating the command-line parameters" do
|
889
859
|
before do
|
@@ -897,46 +867,48 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
897
867
|
Chef::Config[:knife].delete(:aws_access_key_id)
|
898
868
|
Chef::Config[:knife].delete(:aws_secret_access_key)
|
899
869
|
|
900
|
-
|
901
|
-
|
902
|
-
@
|
870
|
+
allow(File).to receive(:exist?).with("/apple/pear").and_return(true)
|
871
|
+
Chef::Config[:knife][:aws_credential_file] = "/apple/pear"
|
872
|
+
@access_key_id = "access_key_id"
|
873
|
+
@secret_key = "secret_key"
|
903
874
|
end
|
904
875
|
|
905
876
|
it "reads UNIX Line endings" do
|
906
|
-
allow(File).to receive(:read)
|
907
|
-
and_return("AWSAccessKeyId=#{@access_key_id}\nAWSSecretKey=#{@secret_key}")
|
877
|
+
allow(File).to receive(:read)
|
878
|
+
.and_return("AWSAccessKeyId=#{@access_key_id}\nAWSSecretKey=#{@secret_key}")
|
908
879
|
knife_ec2_create.validate!
|
909
880
|
expect(Chef::Config[:knife][:aws_access_key_id]).to eq(@access_key_id)
|
910
881
|
expect(Chef::Config[:knife][:aws_secret_access_key]).to eq(@secret_key)
|
911
882
|
end
|
912
883
|
|
913
884
|
it "reads DOS Line endings" do
|
914
|
-
allow(File).to receive(:read)
|
915
|
-
and_return("AWSAccessKeyId=#{@access_key_id}\r\nAWSSecretKey=#{@secret_key}")
|
885
|
+
allow(File).to receive(:read)
|
886
|
+
.and_return("AWSAccessKeyId=#{@access_key_id}\r\nAWSSecretKey=#{@secret_key}")
|
916
887
|
knife_ec2_create.validate!
|
917
888
|
expect(Chef::Config[:knife][:aws_access_key_id]).to eq(@access_key_id)
|
918
889
|
expect(Chef::Config[:knife][:aws_secret_access_key]).to eq(@secret_key)
|
919
890
|
end
|
891
|
+
|
920
892
|
it "reads UNIX Line endings for new format" do
|
921
|
-
allow(File).to receive(:read)
|
922
|
-
and_return("[default]\naws_access_key_id=#{@access_key_id}\naws_secret_access_key=#{@secret_key}")
|
893
|
+
allow(File).to receive(:read)
|
894
|
+
.and_return("[default]\naws_access_key_id=#{@access_key_id}\naws_secret_access_key=#{@secret_key}")
|
923
895
|
knife_ec2_create.validate!
|
924
896
|
expect(Chef::Config[:knife][:aws_access_key_id]).to eq(@access_key_id)
|
925
897
|
expect(Chef::Config[:knife][:aws_secret_access_key]).to eq(@secret_key)
|
926
898
|
end
|
927
899
|
|
928
900
|
it "reads DOS Line endings for new format" do
|
929
|
-
allow(File).to receive(:read)
|
930
|
-
and_return("[default]\naws_access_key_id=#{@access_key_id}\r\naws_secret_access_key=#{@secret_key}")
|
901
|
+
allow(File).to receive(:read)
|
902
|
+
.and_return("[default]\naws_access_key_id=#{@access_key_id}\r\naws_secret_access_key=#{@secret_key}")
|
931
903
|
knife_ec2_create.validate!
|
932
904
|
expect(Chef::Config[:knife][:aws_access_key_id]).to eq(@access_key_id)
|
933
905
|
expect(Chef::Config[:knife][:aws_secret_access_key]).to eq(@secret_key)
|
934
906
|
end
|
935
907
|
|
936
908
|
it "loads the correct profile" do
|
937
|
-
Chef::Config[:knife][:aws_profile] =
|
938
|
-
allow(File).to receive(:read)
|
939
|
-
and_return("[default]\naws_access_key_id=TESTKEY\r\naws_secret_access_key=TESTSECRET\n\n[other]\naws_access_key_id=#{@access_key_id}\r\naws_secret_access_key=#{@secret_key}")
|
909
|
+
Chef::Config[:knife][:aws_profile] = "other"
|
910
|
+
allow(File).to receive(:read)
|
911
|
+
.and_return("[default]\naws_access_key_id=TESTKEY\r\naws_secret_access_key=TESTSECRET\n\n[other]\naws_access_key_id=#{@access_key_id}\r\naws_secret_access_key=#{@secret_key}")
|
940
912
|
knife_ec2_create.validate!
|
941
913
|
expect(Chef::Config[:knife][:aws_access_key_id]).to eq(@access_key_id)
|
942
914
|
expect(Chef::Config[:knife][:aws_secret_access_key]).to eq(@secret_key)
|
@@ -944,66 +916,82 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
944
916
|
|
945
917
|
context "when invalid --aws-profile is given" do
|
946
918
|
it "raises exception" do
|
947
|
-
Chef::Config[:knife][:aws_profile] =
|
919
|
+
Chef::Config[:knife][:aws_profile] = "xyz"
|
948
920
|
allow(File).to receive(:read).and_return("[default]\naws_access_key_id=TESTKEY\r\naws_secret_access_key=TESTSECRET")
|
949
|
-
expect{ knife_ec2_create.validate! }.to raise_error("The provided --aws-profile 'xyz' is invalid.")
|
921
|
+
expect { knife_ec2_create.validate! }.to raise_error("The provided --aws-profile 'xyz' is invalid.")
|
950
922
|
end
|
951
923
|
end
|
952
|
-
end
|
953
924
|
|
925
|
+
context "when non-existent --aws_credential_file is given" do
|
926
|
+
it "raises exception" do
|
927
|
+
Chef::Config[:knife][:aws_credential_file] = "/foo/bar"
|
928
|
+
allow(File).to receive(:exist?).and_return(false)
|
929
|
+
expect { knife_ec2_create.validate! }.to raise_error("The provided --aws_credential_file (/foo/bar) cannot be found on disk.")
|
930
|
+
end
|
931
|
+
end
|
932
|
+
end
|
954
933
|
|
955
934
|
describe "when reading aws_config_file" do
|
956
935
|
before do
|
957
|
-
Chef::Config[:knife][:aws_config_file] =
|
958
|
-
|
936
|
+
Chef::Config[:knife][:aws_config_file] = "/apple/pear"
|
937
|
+
allow(File).to receive(:exist?).with("/apple/pear").and_return(true)
|
938
|
+
@region = "region"
|
959
939
|
end
|
960
940
|
|
961
941
|
it "reads UNIX Line endings" do
|
962
|
-
allow(File).to receive(:read)
|
963
|
-
and_return("[default]\r\nregion=#{@region}")
|
942
|
+
allow(File).to receive(:read)
|
943
|
+
.and_return("[default]\r\nregion=#{@region}")
|
964
944
|
knife_ec2_create.validate!
|
965
945
|
expect(Chef::Config[:knife][:region]).to eq(@region)
|
966
946
|
end
|
967
947
|
|
968
948
|
it "reads DOS Line endings" do
|
969
|
-
allow(File).to receive(:read)
|
970
|
-
and_return("[default]\r\nregion=#{@region}")
|
949
|
+
allow(File).to receive(:read)
|
950
|
+
.and_return("[default]\r\nregion=#{@region}")
|
971
951
|
knife_ec2_create.validate!
|
972
952
|
expect(Chef::Config[:knife][:region]).to eq(@region)
|
973
953
|
end
|
974
954
|
it "reads UNIX Line endings for new format" do
|
975
|
-
|
976
|
-
|
955
|
+
allow(File).to receive(:read)
|
956
|
+
.and_return("[default]\nregion=#{@region}")
|
977
957
|
knife_ec2_create.validate!
|
978
958
|
expect(Chef::Config[:knife][:region]).to eq(@region)
|
979
959
|
end
|
980
960
|
|
981
961
|
it "reads DOS Line endings for new format" do
|
982
|
-
|
983
|
-
|
962
|
+
allow(File).to receive(:read)
|
963
|
+
.and_return("[default]\nregion=#{@region}")
|
984
964
|
knife_ec2_create.validate!
|
985
965
|
expect(Chef::Config[:knife][:region]).to eq(@region)
|
986
966
|
end
|
987
967
|
|
988
968
|
it "loads the correct profile" do
|
989
|
-
Chef::Config[:knife][:aws_profile] =
|
990
|
-
allow(File).to receive(:read)
|
991
|
-
and_return("[default]\nregion=TESTREGION\n\n[profile other]\nregion=#{@region}")
|
969
|
+
Chef::Config[:knife][:aws_profile] = "other"
|
970
|
+
allow(File).to receive(:read)
|
971
|
+
.and_return("[default]\nregion=TESTREGION\n\n[profile other]\nregion=#{@region}")
|
992
972
|
knife_ec2_create.validate!
|
993
973
|
expect(Chef::Config[:knife][:region]).to eq(@region)
|
994
974
|
end
|
995
975
|
|
996
976
|
context "when invalid --aws-profile is given" do
|
997
977
|
it "raises exception" do
|
998
|
-
Chef::Config[:knife][:aws_profile] =
|
978
|
+
Chef::Config[:knife][:aws_profile] = "xyz"
|
999
979
|
allow(File).to receive(:read).and_return("[default]\nregion=TESTREGION")
|
1000
|
-
expect{ knife_ec2_create.validate! }.to raise_error("The provided --aws-profile 'profile xyz' is invalid.")
|
980
|
+
expect { knife_ec2_create.validate! }.to raise_error("The provided --aws-profile 'profile xyz' is invalid.")
|
981
|
+
end
|
982
|
+
end
|
983
|
+
|
984
|
+
context "when non-existent --aws_config_file is given" do
|
985
|
+
it "raises exception" do
|
986
|
+
Chef::Config[:knife][:aws_config_file] = "/foo/bar"
|
987
|
+
allow(File).to receive(:exist?).and_return(false)
|
988
|
+
expect { knife_ec2_create.validate! }.to raise_error("The provided --aws_config_file (/foo/bar) cannot be found on disk.")
|
1001
989
|
end
|
1002
990
|
end
|
1003
991
|
|
1004
992
|
context "when aws_profile is passed a 'default' from CLI or knife.rb file" do
|
1005
|
-
it
|
1006
|
-
Chef::Config[:knife][:aws_profile] =
|
993
|
+
it "loads the default profile successfully" do
|
994
|
+
Chef::Config[:knife][:aws_profile] = "default"
|
1007
995
|
allow(File).to receive(:read).and_return("[default]\nregion=#{@region}\n\n[profile other]\nregion=TESTREGION")
|
1008
996
|
knife_ec2_create.validate!
|
1009
997
|
expect(Chef::Config[:knife][:region]).to eq(@region)
|
@@ -1011,13 +999,13 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1011
999
|
end
|
1012
1000
|
end
|
1013
1001
|
|
1014
|
-
it
|
1015
|
-
Chef::Config[:knife][:validation_key_url] =
|
1016
|
-
expect(knife_ec2_create.validation_key_path).to eq(
|
1002
|
+
it "understands that file:// validation key URIs are just paths" do
|
1003
|
+
Chef::Config[:knife][:validation_key_url] = "file:///foo/bar"
|
1004
|
+
expect(knife_ec2_create.validation_key_path).to eq("/foo/bar")
|
1017
1005
|
end
|
1018
1006
|
|
1019
|
-
it
|
1020
|
-
|
1007
|
+
it "returns a path to a tmp file when presented with a URI for the " \
|
1008
|
+
"validation key" do
|
1021
1009
|
Chef::Config[:knife][:validation_key_url] = @validation_key_url
|
1022
1010
|
|
1023
1011
|
allow(knife_ec2_create).to receive_message_chain(:validation_key_tmpfile, :path).and_return(@validation_key_file)
|
@@ -1027,43 +1015,44 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1027
1015
|
|
1028
1016
|
it "disallows security group names when using a VPC" do
|
1029
1017
|
knife_ec2_create.config[:subnet_id] = @subnet_1_id
|
1030
|
-
knife_ec2_create.config[:security_group_ids] =
|
1031
|
-
knife_ec2_create.config[:security_groups] =
|
1018
|
+
knife_ec2_create.config[:security_group_ids] = "sg-aabbccdd"
|
1019
|
+
knife_ec2_create.config[:security_groups] = "groupname"
|
1032
1020
|
|
1033
1021
|
allow(ec2_connection).to receive_message_chain(:subnets, :get).with(@subnet_1_id).and_return(@subnet_1)
|
1034
1022
|
|
1035
1023
|
expect { knife_ec2_create.validate! }.to raise_error(SystemExit)
|
1036
1024
|
end
|
1037
1025
|
|
1038
|
-
it
|
1039
|
-
knife_ec2_create.config[:network_interfaces] = [
|
1026
|
+
it "disallows invalid network interface ids" do
|
1027
|
+
knife_ec2_create.config[:network_interfaces] = ["INVALID_ID"]
|
1040
1028
|
|
1041
1029
|
expect { knife_ec2_create.validate! }.to raise_error(SystemExit)
|
1042
1030
|
end
|
1043
1031
|
|
1044
|
-
it
|
1032
|
+
it "disallows network interfaces not in the right VPC" do
|
1045
1033
|
knife_ec2_create.config[:subnet_id] = @subnet_1_id
|
1046
|
-
knife_ec2_create.config[:security_group_ids] =
|
1047
|
-
knife_ec2_create.config[:security_groups] =
|
1034
|
+
knife_ec2_create.config[:security_group_ids] = "sg-aabbccdd"
|
1035
|
+
knife_ec2_create.config[:security_groups] = "groupname"
|
1048
1036
|
|
1049
1037
|
allow(ec2_connection).to receive_message_chain(:subnets, :get).with(@subnet_1_id).and_return(@subnet_1)
|
1050
1038
|
|
1051
1039
|
allow(ec2_connection).to receive_message_chain(:network_interfaces, :all).and_return [
|
1052
|
-
double(
|
1053
|
-
double(
|
1040
|
+
double("network_interfaces", network_interface_id: "eni-12345678", vpc_id: "another_vpc"),
|
1041
|
+
double("network_interfaces", network_interface_id: "eni-87654321", vpc_id: my_vpc)
|
1054
1042
|
]
|
1055
1043
|
|
1056
1044
|
expect { knife_ec2_create.validate! }.to raise_error SystemExit
|
1057
1045
|
end
|
1058
1046
|
|
1059
1047
|
it "disallows private ips when not using a VPC" do
|
1060
|
-
knife_ec2_create.config[:private_ip_address] =
|
1048
|
+
knife_ec2_create.config[:private_ip_address] = "10.0.0.10"
|
1061
1049
|
|
1062
1050
|
expect { knife_ec2_create.validate! }.to raise_error SystemExit
|
1063
1051
|
end
|
1064
1052
|
|
1065
1053
|
it "disallows specifying credentials file and aws keys" do
|
1066
|
-
Chef::Config[:knife][:aws_credential_file] =
|
1054
|
+
Chef::Config[:knife][:aws_credential_file] = "/apple/pear"
|
1055
|
+
allow(File).to receive(:exist?).with("/apple/pear").and_return(true)
|
1067
1056
|
allow(File).to receive(:read).and_return("AWSAccessKeyId=b\nAWSSecretKey=a")
|
1068
1057
|
|
1069
1058
|
expect { knife_ec2_create.validate! }.to raise_error SystemExit
|
@@ -1084,7 +1073,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1084
1073
|
end
|
1085
1074
|
|
1086
1075
|
it "disallows ClassicLink with VPC" do
|
1087
|
-
knife_ec2_create.config[:subnet_id] =
|
1076
|
+
knife_ec2_create.config[:subnet_id] = "subnet-1a2b3c4d"
|
1088
1077
|
knife_ec2_create.config[:classic_link_vpc_id] = @vpc_id
|
1089
1078
|
knife_ec2_create.config[:classic_link_vpc_security_group_ids] = @vpc_security_group_ids
|
1090
1079
|
|
@@ -1109,14 +1098,14 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1109
1098
|
|
1110
1099
|
it "disallows ebs volume type if its other than 'io1' or 'gp2' or 'standard'" do
|
1111
1100
|
knife_ec2_create.config[:ebs_provisioned_iops] = "123"
|
1112
|
-
knife_ec2_create.config[:ebs_volume_type] =
|
1101
|
+
knife_ec2_create.config[:ebs_volume_type] = "invalid"
|
1113
1102
|
|
1114
1103
|
expect { knife_ec2_create.validate! }.to raise_error SystemExit
|
1115
1104
|
end
|
1116
1105
|
|
1117
1106
|
it "disallows 'io1' ebs volume type when not using ebs provisioned iops" do
|
1118
1107
|
knife_ec2_create.config[:ebs_provisioned_iops] = nil
|
1119
|
-
knife_ec2_create.config[:ebs_volume_type] =
|
1108
|
+
knife_ec2_create.config[:ebs_volume_type] = "io1"
|
1120
1109
|
|
1121
1110
|
expect { knife_ec2_create.validate! }.to raise_error SystemExit
|
1122
1111
|
end
|
@@ -1140,7 +1129,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1140
1129
|
|
1141
1130
|
it "raise error if invalid ebs_size specified for 'standard' VolumeType" do
|
1142
1131
|
knife_ec2_create.config[:ebs_size] = "1055"
|
1143
|
-
knife_ec2_create.config[:ebs_volume_type] =
|
1132
|
+
knife_ec2_create.config[:ebs_volume_type] = "standard"
|
1144
1133
|
knife_ec2_create.config[:flavor] = "m3.medium"
|
1145
1134
|
knife_ec2_create.config[:ebs_encrypted] = true
|
1146
1135
|
expect(knife_ec2_create.ui).to receive(:error).with(" --ebs-size should be in between 1-1024 for 'standard' ebs volume type.")
|
@@ -1149,7 +1138,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1149
1138
|
|
1150
1139
|
it "raise error on invalid ebs_size specified for 'gp2' VolumeType" do
|
1151
1140
|
knife_ec2_create.config[:ebs_size] = "16500"
|
1152
|
-
knife_ec2_create.config[:ebs_volume_type] =
|
1141
|
+
knife_ec2_create.config[:ebs_volume_type] = "gp2"
|
1153
1142
|
knife_ec2_create.config[:flavor] = "m3.medium"
|
1154
1143
|
knife_ec2_create.config[:ebs_encrypted] = true
|
1155
1144
|
expect(knife_ec2_create.ui).to receive(:error).with(" --ebs-size should be in between 1-16384 for 'gp2' ebs volume type.")
|
@@ -1159,7 +1148,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1159
1148
|
it "raise error on invalid ebs_size specified for 'io1' VolumeType" do
|
1160
1149
|
knife_ec2_create.config[:ebs_size] = "3"
|
1161
1150
|
knife_ec2_create.config[:ebs_provisioned_iops] = "200"
|
1162
|
-
knife_ec2_create.config[:ebs_volume_type] =
|
1151
|
+
knife_ec2_create.config[:ebs_volume_type] = "io1"
|
1163
1152
|
knife_ec2_create.config[:flavor] = "m3.medium"
|
1164
1153
|
knife_ec2_create.config[:ebs_encrypted] = true
|
1165
1154
|
expect(knife_ec2_create.ui).to receive(:error).with(" --ebs-size should be in between 4-16384 for 'io1' ebs volume type.")
|
@@ -1169,23 +1158,35 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1169
1158
|
end
|
1170
1159
|
|
1171
1160
|
describe "when creating the connection" do
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1161
|
+
before(:each) do
|
1162
|
+
Chef::Config[:knife].delete(:aws_access_key_id)
|
1163
|
+
Chef::Config[:knife].delete(:aws_secret_access_key)
|
1164
|
+
end
|
1165
|
+
|
1166
|
+
describe "when no keys or credential file is specified" do
|
1167
|
+
it "it loads credentials from the default credentials file" do
|
1168
|
+
default_cred_file = Chef::Util::PathHelper.home(".aws", "credentials")
|
1169
|
+
allow(File).to receive(:exist?).and_call_original
|
1170
|
+
allow(File).to receive(:exist?).with(default_cred_file).and_return(true)
|
1171
|
+
allow(File).to receive(:read).with(default_cred_file).and_return("[default]\naws_access_key_id=abc\naws_secret_access_key=abc")
|
1172
|
+
expect(Fog::Compute::AWS).to receive(:new).with(hash_including(aws_access_key_id: "abc", aws_secret_access_key: "abc")).and_return(ec2_connection)
|
1173
|
+
knife_ec2_create.validate!
|
1174
|
+
knife_ec2_create.connection
|
1176
1175
|
end
|
1176
|
+
end
|
1177
1177
|
|
1178
|
+
describe "when use_iam_profile is true" do
|
1178
1179
|
it "creates a connection without access keys" do
|
1179
1180
|
knife_ec2_create.config[:use_iam_profile] = true
|
1180
|
-
expect(Fog::Compute::AWS).to receive(:new).with(hash_including(:
|
1181
|
+
expect(Fog::Compute::AWS).to receive(:new).with(hash_including(use_iam_profile: true)).and_return(ec2_connection)
|
1181
1182
|
knife_ec2_create.connection
|
1182
1183
|
end
|
1183
1184
|
end
|
1184
1185
|
|
1185
1186
|
describe "when aws_session_token is present" do
|
1186
1187
|
it "creates a connection using the session token" do
|
1187
|
-
knife_ec2_create.config[:aws_session_token] =
|
1188
|
-
expect(Fog::Compute::AWS).to receive(:new).with(hash_including(:
|
1188
|
+
knife_ec2_create.config[:aws_session_token] = "session-token"
|
1189
|
+
expect(Fog::Compute::AWS).to receive(:new).with(hash_including(aws_session_token: "session-token")).and_return(ec2_connection)
|
1189
1190
|
knife_ec2_create.connection
|
1190
1191
|
end
|
1191
1192
|
end
|
@@ -1197,24 +1198,24 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1197
1198
|
end
|
1198
1199
|
|
1199
1200
|
it "sets the specified placement_group" do
|
1200
|
-
knife_ec2_create.config[:placement_group] = [
|
1201
|
+
knife_ec2_create.config[:placement_group] = ["some_placement_group"]
|
1201
1202
|
server_def = knife_ec2_create.create_server_def
|
1202
1203
|
|
1203
|
-
expect(server_def[:placement_group]).to eq([
|
1204
|
+
expect(server_def[:placement_group]).to eq(["some_placement_group"])
|
1204
1205
|
end
|
1205
1206
|
|
1206
1207
|
it "sets the specified security group names" do
|
1207
|
-
knife_ec2_create.config[:security_groups] = [
|
1208
|
+
knife_ec2_create.config[:security_groups] = ["groupname"]
|
1208
1209
|
server_def = knife_ec2_create.create_server_def
|
1209
1210
|
|
1210
|
-
expect(server_def[:groups]).to eq([
|
1211
|
+
expect(server_def[:groups]).to eq(["groupname"])
|
1211
1212
|
end
|
1212
1213
|
|
1213
1214
|
it "sets the specified security group ids" do
|
1214
|
-
knife_ec2_create.config[:security_group_ids] = [
|
1215
|
+
knife_ec2_create.config[:security_group_ids] = ["sg-aabbccdd", "sg-3764sdss", "sg-aab343ytre"]
|
1215
1216
|
server_def = knife_ec2_create.create_server_def
|
1216
1217
|
|
1217
|
-
expect(server_def[:security_group_ids]).to eq([
|
1218
|
+
expect(server_def[:security_group_ids]).to eq(["sg-aabbccdd", "sg-3764sdss", "sg-aab343ytre"])
|
1218
1219
|
end
|
1219
1220
|
|
1220
1221
|
it "sets the image id from CLI arguments over knife config" do
|
@@ -1252,19 +1253,19 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1252
1253
|
end
|
1253
1254
|
|
1254
1255
|
it "sets the specified private ip address" do
|
1255
|
-
knife_ec2_create.config[:subnet_id] =
|
1256
|
-
knife_ec2_create.config[:private_ip_address] =
|
1256
|
+
knife_ec2_create.config[:subnet_id] = "subnet-1a2b3c4d"
|
1257
|
+
knife_ec2_create.config[:private_ip_address] = "10.0.0.10"
|
1257
1258
|
server_def = knife_ec2_create.create_server_def
|
1258
1259
|
|
1259
|
-
expect(server_def[:subnet_id]).to eq(
|
1260
|
-
expect(server_def[:private_ip_address]).to eq(
|
1260
|
+
expect(server_def[:subnet_id]).to eq("subnet-1a2b3c4d")
|
1261
|
+
expect(server_def[:private_ip_address]).to eq("10.0.0.10")
|
1261
1262
|
end
|
1262
1263
|
|
1263
1264
|
it "sets the IAM server role when one is specified" do
|
1264
|
-
knife_ec2_create.config[:iam_instance_profile] = [
|
1265
|
+
knife_ec2_create.config[:iam_instance_profile] = ["iam-role"]
|
1265
1266
|
server_def = knife_ec2_create.create_server_def
|
1266
1267
|
|
1267
|
-
expect(server_def[:iam_instance_profile_name]).to eq([
|
1268
|
+
expect(server_def[:iam_instance_profile_name]).to eq(["iam-role"])
|
1268
1269
|
end
|
1269
1270
|
|
1270
1271
|
it "doesn't set an IAM server role by default" do
|
@@ -1279,90 +1280,90 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1279
1280
|
expect(server_def[:use_iam_profile]).to eq(nil)
|
1280
1281
|
end
|
1281
1282
|
|
1282
|
-
it
|
1283
|
+
it "Set Tenancy Dedicated when both VPC mode and Flag is True" do
|
1283
1284
|
knife_ec2_create.config[:dedicated_instance] = true
|
1284
|
-
allow(knife_ec2_create).to receive_messages(
|
1285
|
+
allow(knife_ec2_create).to receive_messages(vpc_mode?: true)
|
1285
1286
|
server_def = knife_ec2_create.create_server_def
|
1286
1287
|
expect(server_def[:tenancy]).to eq("dedicated")
|
1287
1288
|
end
|
1288
1289
|
|
1289
|
-
it
|
1290
|
+
it "Tenancy should be default with no vpc mode even is specified" do
|
1290
1291
|
knife_ec2_create.config[:dedicated_instance] = true
|
1291
1292
|
server_def = knife_ec2_create.create_server_def
|
1292
1293
|
expect(server_def[:tenancy]).to eq(nil)
|
1293
1294
|
end
|
1294
1295
|
|
1295
|
-
it
|
1296
|
-
allow(knife_ec2_create).to receive_messages(
|
1296
|
+
it "Tenancy should be default with vpc but not requested" do
|
1297
|
+
allow(knife_ec2_create).to receive_messages(vpc_mode?: true)
|
1297
1298
|
server_def = knife_ec2_create.create_server_def
|
1298
1299
|
expect(server_def[:tenancy]).to eq(nil)
|
1299
1300
|
end
|
1300
1301
|
|
1301
1302
|
it "sets associate_public_ip to true if specified and in vpc_mode" do
|
1302
|
-
knife_ec2_create.config[:subnet_id] =
|
1303
|
+
knife_ec2_create.config[:subnet_id] = "subnet-1a2b3c4d"
|
1303
1304
|
knife_ec2_create.config[:associate_public_ip] = true
|
1304
1305
|
server_def = knife_ec2_create.create_server_def
|
1305
1306
|
|
1306
|
-
expect(server_def[:subnet_id]).to eq(
|
1307
|
+
expect(server_def[:subnet_id]).to eq("subnet-1a2b3c4d")
|
1307
1308
|
expect(server_def[:associate_public_ip]).to eq(true)
|
1308
1309
|
end
|
1309
1310
|
|
1310
1311
|
it "sets the spot price" do
|
1311
|
-
knife_ec2_create.config[:spot_price] =
|
1312
|
+
knife_ec2_create.config[:spot_price] = "1.99"
|
1312
1313
|
server_def = knife_ec2_create.create_server_def
|
1313
1314
|
|
1314
|
-
expect(server_def[:price]).to eq(
|
1315
|
+
expect(server_def[:price]).to eq("1.99")
|
1315
1316
|
end
|
1316
1317
|
|
1317
1318
|
it "sets the spot instance request type as persistent" do
|
1318
|
-
knife_ec2_create.config[:spot_request_type] =
|
1319
|
+
knife_ec2_create.config[:spot_request_type] = "persistent"
|
1319
1320
|
server_def = knife_ec2_create.create_server_def
|
1320
1321
|
|
1321
|
-
expect(server_def[:request_type]).to eq(
|
1322
|
+
expect(server_def[:request_type]).to eq("persistent")
|
1322
1323
|
end
|
1323
1324
|
|
1324
1325
|
it "sets the spot instance request type as one-time" do
|
1325
|
-
knife_ec2_create.config[:spot_request_type] =
|
1326
|
+
knife_ec2_create.config[:spot_request_type] = "one-time"
|
1326
1327
|
server_def = knife_ec2_create.create_server_def
|
1327
1328
|
|
1328
|
-
expect(server_def[:request_type]).to eq(
|
1329
|
+
expect(server_def[:request_type]).to eq("one-time")
|
1329
1330
|
end
|
1330
1331
|
|
1331
1332
|
context "when using ebs volume type and ebs provisioned iops rate options" do
|
1332
1333
|
before do
|
1333
1334
|
allow(knife_ec2_create).to receive_message_chain(:ami, :root_device_type).and_return("ebs")
|
1334
|
-
allow(knife_ec2_create).to receive_message_chain(:ami, :block_device_mapping).and_return([{"iops" => 123}])
|
1335
|
+
allow(knife_ec2_create).to receive_message_chain(:ami, :block_device_mapping).and_return([{ "iops" => 123 }])
|
1335
1336
|
allow(knife_ec2_create).to receive(:msg)
|
1336
1337
|
allow(knife_ec2_create).to receive(:puts)
|
1337
1338
|
end
|
1338
1339
|
|
1339
1340
|
it "sets the specified 'standard' ebs volume type" do
|
1340
|
-
knife_ec2_create.config[:ebs_volume_type] =
|
1341
|
+
knife_ec2_create.config[:ebs_volume_type] = "standard"
|
1341
1342
|
server_def = knife_ec2_create.create_server_def
|
1342
1343
|
|
1343
|
-
expect(server_def[:block_device_mapping].first[
|
1344
|
+
expect(server_def[:block_device_mapping].first["Ebs.VolumeType"]).to eq("standard")
|
1344
1345
|
end
|
1345
1346
|
|
1346
1347
|
it "sets the specified 'io1' ebs volume type" do
|
1347
|
-
knife_ec2_create.config[:ebs_volume_type] =
|
1348
|
+
knife_ec2_create.config[:ebs_volume_type] = "io1"
|
1348
1349
|
server_def = knife_ec2_create.create_server_def
|
1349
1350
|
|
1350
|
-
expect(server_def[:block_device_mapping].first[
|
1351
|
+
expect(server_def[:block_device_mapping].first["Ebs.VolumeType"]).to eq("io1")
|
1351
1352
|
end
|
1352
1353
|
|
1353
1354
|
it "sets the specified 'gp2' ebs volume type" do
|
1354
|
-
knife_ec2_create.config[:ebs_volume_type] =
|
1355
|
+
knife_ec2_create.config[:ebs_volume_type] = "gp2"
|
1355
1356
|
server_def = knife_ec2_create.create_server_def
|
1356
1357
|
|
1357
|
-
expect(server_def[:block_device_mapping].first[
|
1358
|
+
expect(server_def[:block_device_mapping].first["Ebs.VolumeType"]).to eq("gp2")
|
1358
1359
|
end
|
1359
1360
|
|
1360
1361
|
it "sets the specified ebs provisioned iops rate" do
|
1361
|
-
knife_ec2_create.config[:ebs_provisioned_iops] =
|
1362
|
-
knife_ec2_create.config[:ebs_volume_type] =
|
1362
|
+
knife_ec2_create.config[:ebs_provisioned_iops] = "1234"
|
1363
|
+
knife_ec2_create.config[:ebs_volume_type] = "io1"
|
1363
1364
|
server_def = knife_ec2_create.create_server_def
|
1364
1365
|
|
1365
|
-
expect(server_def[:block_device_mapping].first[
|
1366
|
+
expect(server_def[:block_device_mapping].first["Ebs.Iops"]).to eq("1234")
|
1366
1367
|
end
|
1367
1368
|
|
1368
1369
|
it "disallows non integer ebs provisioned iops rate" do
|
@@ -1372,17 +1373,17 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1372
1373
|
end
|
1373
1374
|
|
1374
1375
|
it "sets the iops rate from ami" do
|
1375
|
-
knife_ec2_create.config[:ebs_volume_type] =
|
1376
|
+
knife_ec2_create.config[:ebs_volume_type] = "io1"
|
1376
1377
|
server_def = knife_ec2_create.create_server_def
|
1377
1378
|
|
1378
|
-
expect(server_def[:block_device_mapping].first[
|
1379
|
+
expect(server_def[:block_device_mapping].first["Ebs.Iops"]).to eq("123")
|
1379
1380
|
end
|
1380
1381
|
end
|
1381
1382
|
end
|
1382
1383
|
|
1383
1384
|
describe "wait_for_sshd" do
|
1384
|
-
let(:gateway) {
|
1385
|
-
let(:hostname) {
|
1385
|
+
let(:gateway) { "test.gateway.com" }
|
1386
|
+
let(:hostname) { "test.host.com" }
|
1386
1387
|
|
1387
1388
|
it "should wait for tunnelled ssh if a ssh gateway is provided" do
|
1388
1389
|
allow(knife_ec2_create).to receive(:get_ssh_gateway_for).and_return(gateway)
|
@@ -1399,11 +1400,11 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1399
1400
|
end
|
1400
1401
|
|
1401
1402
|
describe "get_ssh_gateway_for" do
|
1402
|
-
let(:gateway) {
|
1403
|
-
let(:hostname) {
|
1403
|
+
let(:gateway) { "test.gateway.com" }
|
1404
|
+
let(:hostname) { "test.host.com" }
|
1404
1405
|
|
1405
1406
|
it "should give precedence to the ssh gateway specified in the knife configuration" do
|
1406
|
-
allow(Net::SSH::Config).to receive(:for).and_return(:
|
1407
|
+
allow(Net::SSH::Config).to receive(:for).and_return(proxy: Net::SSH::Proxy::Command.new("ssh some.other.gateway.com nc %h %p"))
|
1407
1408
|
knife_ec2_create.config[:ssh_gateway] = gateway
|
1408
1409
|
expect(knife_ec2_create.get_ssh_gateway_for(hostname)).to eq(gateway)
|
1409
1410
|
end
|
@@ -1411,22 +1412,22 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1411
1412
|
it "should return the ssh gateway specified in the ssh configuration even if the config option is not set" do
|
1412
1413
|
# This should already be false, but test this explicitly for regression
|
1413
1414
|
knife_ec2_create.config[:ssh_gateway] = false
|
1414
|
-
allow(Net::SSH::Config).to receive(:for).and_return(:
|
1415
|
+
allow(Net::SSH::Config).to receive(:for).and_return(proxy: Net::SSH::Proxy::Command.new("ssh #{gateway} nc %h %p"))
|
1415
1416
|
expect(knife_ec2_create.get_ssh_gateway_for(hostname)).to eq(gateway)
|
1416
1417
|
end
|
1417
1418
|
|
1418
1419
|
it "should return nil if the ssh gateway cannot be parsed from the ssh proxy command" do
|
1419
|
-
allow(Net::SSH::Config).to receive(:for).and_return(:
|
1420
|
+
allow(Net::SSH::Config).to receive(:for).and_return(proxy: Net::SSH::Proxy::Command.new("cannot parse host"))
|
1420
1421
|
expect(knife_ec2_create.get_ssh_gateway_for(hostname)).to be_nil
|
1421
1422
|
end
|
1422
1423
|
|
1423
1424
|
it "should return nil if the ssh proxy is not a proxy command" do
|
1424
|
-
allow(Net::SSH::Config).to receive(:for).and_return(:
|
1425
|
+
allow(Net::SSH::Config).to receive(:for).and_return(proxy: Net::SSH::Proxy::HTTP.new("httphost.com"))
|
1425
1426
|
expect(knife_ec2_create.get_ssh_gateway_for(hostname)).to be_nil
|
1426
1427
|
end
|
1427
1428
|
|
1428
1429
|
it "returns nil if the ssh config has no proxy" do
|
1429
|
-
allow(Net::SSH::Config).to receive(:for).and_return(:
|
1430
|
+
allow(Net::SSH::Config).to receive(:for).and_return(user: "darius")
|
1430
1431
|
expect(knife_ec2_create.get_ssh_gateway_for(hostname)).to be_nil
|
1431
1432
|
end
|
1432
1433
|
|
@@ -1434,21 +1435,21 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1434
1435
|
|
1435
1436
|
describe "#subnet_public_ip_on_launch?" do
|
1436
1437
|
before do
|
1437
|
-
allow(new_ec2_server).to receive_messages(:
|
1438
|
-
allow(knife_ec2_create).to receive_messages(:
|
1438
|
+
allow(new_ec2_server).to receive_messages(subnet_id: "subnet-1a2b3c4d")
|
1439
|
+
allow(knife_ec2_create).to receive_messages(server: new_ec2_server)
|
1439
1440
|
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
1440
1441
|
end
|
1441
1442
|
|
1442
1443
|
context "when auto_assign_public_ip is enabled" do
|
1443
1444
|
it "returns true" do
|
1444
|
-
allow(ec2_connection).to receive_message_chain(:subnets, :get).and_return double( :
|
1445
|
+
allow(ec2_connection).to receive_message_chain(:subnets, :get).and_return double( map_public_ip_on_launch: true )
|
1445
1446
|
expect(knife_ec2_create.subnet_public_ip_on_launch?).to eq(true)
|
1446
1447
|
end
|
1447
1448
|
end
|
1448
1449
|
|
1449
1450
|
context "when auto_assign_public_ip is disabled" do
|
1450
1451
|
it "returns false" do
|
1451
|
-
allow(ec2_connection).to receive_message_chain(:subnets, :get).and_return double( :
|
1452
|
+
allow(ec2_connection).to receive_message_chain(:subnets, :get).and_return double( map_public_ip_on_launch: false )
|
1452
1453
|
expect(knife_ec2_create.subnet_public_ip_on_launch?).to eq(false)
|
1453
1454
|
end
|
1454
1455
|
end
|
@@ -1457,78 +1458,78 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1457
1458
|
describe "ssh_connect_host" do
|
1458
1459
|
before(:each) do
|
1459
1460
|
allow(new_ec2_server).to receive_messages(
|
1460
|
-
:
|
1461
|
-
:
|
1462
|
-
:
|
1463
|
-
:
|
1464
|
-
:
|
1461
|
+
dns_name: "public.example.org",
|
1462
|
+
private_ip_address: "192.168.1.100",
|
1463
|
+
custom: "custom",
|
1464
|
+
public_ip_address: "111.111.111.111",
|
1465
|
+
subnet_id: "subnet-1a2b3c4d"
|
1465
1466
|
)
|
1466
|
-
allow(knife_ec2_create).to receive_messages(:
|
1467
|
+
allow(knife_ec2_create).to receive_messages(server: new_ec2_server)
|
1467
1468
|
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
1468
1469
|
end
|
1469
1470
|
|
1470
1471
|
describe "by default" do
|
1471
|
-
it
|
1472
|
-
expect(knife_ec2_create.ssh_connect_host).to eq(
|
1472
|
+
it "should use public dns name" do
|
1473
|
+
expect(knife_ec2_create.ssh_connect_host).to eq("public.example.org")
|
1473
1474
|
end
|
1474
1475
|
end
|
1475
1476
|
|
1476
1477
|
describe "when dns name not exist" do
|
1477
|
-
it
|
1478
|
+
it "should use public_ip_address " do
|
1478
1479
|
allow(new_ec2_server).to receive(:dns_name).and_return(nil)
|
1479
|
-
expect(knife_ec2_create.ssh_connect_host).to eq(
|
1480
|
+
expect(knife_ec2_create.ssh_connect_host).to eq("111.111.111.111")
|
1480
1481
|
end
|
1481
1482
|
end
|
1482
1483
|
|
1483
1484
|
context "when vpc_mode? is true" do
|
1484
1485
|
before do
|
1485
|
-
allow(knife_ec2_create).to receive_messages(
|
1486
|
+
allow(knife_ec2_create).to receive_messages(vpc_mode?: true)
|
1486
1487
|
end
|
1487
1488
|
|
1488
1489
|
context "subnet_public_ip_on_launch? is true" do
|
1489
1490
|
it "uses the dns_name or public_ip_address" do
|
1490
|
-
allow(ec2_connection).to receive_message_chain(:subnets, :get).and_return double( :
|
1491
|
+
allow(ec2_connection).to receive_message_chain(:subnets, :get).and_return double( map_public_ip_on_launch: true )
|
1491
1492
|
expect(knife_ec2_create.subnet_public_ip_on_launch?).to eq(true)
|
1492
|
-
expect(knife_ec2_create.ssh_connect_host).to eq(
|
1493
|
+
expect(knife_ec2_create.ssh_connect_host).to eq("public.example.org")
|
1493
1494
|
end
|
1494
1495
|
end
|
1495
1496
|
|
1496
1497
|
context "--associate-public-ip is specified" do
|
1497
1498
|
it "uses the dns_name or public_ip_address" do
|
1498
1499
|
knife_ec2_create.config[:associate_public_ip] = true
|
1499
|
-
allow(ec2_connection).to receive_message_chain(:subnets, :get).and_return double( :
|
1500
|
-
expect(knife_ec2_create.ssh_connect_host).to eq(
|
1500
|
+
allow(ec2_connection).to receive_message_chain(:subnets, :get).and_return double( map_public_ip_on_launch: false )
|
1501
|
+
expect(knife_ec2_create.ssh_connect_host).to eq("public.example.org")
|
1501
1502
|
end
|
1502
1503
|
end
|
1503
1504
|
|
1504
1505
|
context "--associate-eip is specified" do
|
1505
1506
|
it "uses the dns_name or public_ip_address" do
|
1506
|
-
knife_ec2_create.config[:associate_eip] =
|
1507
|
-
allow(ec2_connection).to receive_message_chain(:subnets, :get).and_return double( :
|
1508
|
-
expect(knife_ec2_create.ssh_connect_host).to eq(
|
1507
|
+
knife_ec2_create.config[:associate_eip] = "111.111.111.111"
|
1508
|
+
allow(ec2_connection).to receive_message_chain(:subnets, :get).and_return double( map_public_ip_on_launch: false )
|
1509
|
+
expect(knife_ec2_create.ssh_connect_host).to eq("public.example.org")
|
1509
1510
|
end
|
1510
1511
|
end
|
1511
1512
|
|
1512
1513
|
context "with no other ip flags" do
|
1513
|
-
it
|
1514
|
-
allow(ec2_connection).to receive_message_chain(:subnets, :get).and_return double( :
|
1515
|
-
expect(knife_ec2_create.ssh_connect_host).to eq(
|
1514
|
+
it "uses private_ip_address" do
|
1515
|
+
allow(ec2_connection).to receive_message_chain(:subnets, :get).and_return double( map_public_ip_on_launch: false )
|
1516
|
+
expect(knife_ec2_create.ssh_connect_host).to eq("192.168.1.100")
|
1516
1517
|
end
|
1517
1518
|
end
|
1518
1519
|
end
|
1519
1520
|
|
1520
1521
|
describe "with custom server attribute" do
|
1521
|
-
it
|
1522
|
-
knife_ec2_create.config[:server_connect_attribute] =
|
1523
|
-
expect(knife_ec2_create.ssh_connect_host).to eq(
|
1522
|
+
it "should use custom server attribute" do
|
1523
|
+
knife_ec2_create.config[:server_connect_attribute] = "custom"
|
1524
|
+
expect(knife_ec2_create.ssh_connect_host).to eq("custom")
|
1524
1525
|
end
|
1525
1526
|
end
|
1526
1527
|
end
|
1527
1528
|
|
1528
1529
|
describe "tunnel_test_ssh" do
|
1529
|
-
let(:gateway_host) {
|
1530
|
-
let(:gateway) { double(
|
1531
|
-
let(:hostname) {
|
1530
|
+
let(:gateway_host) { "test.gateway.com" }
|
1531
|
+
let(:gateway) { double("gateway") }
|
1532
|
+
let(:hostname) { "test.host.com" }
|
1532
1533
|
let(:local_port) { 23 }
|
1533
1534
|
|
1534
1535
|
before(:each) do
|
@@ -1538,56 +1539,56 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1538
1539
|
it "should test ssh through a gateway" do
|
1539
1540
|
knife_ec2_create.config[:ssh_port] = 22
|
1540
1541
|
expect(gateway).to receive(:open).with(hostname, 22).and_yield(local_port)
|
1541
|
-
expect(knife_ec2_create).to receive(:tcp_test_ssh).with(
|
1542
|
+
expect(knife_ec2_create).to receive(:tcp_test_ssh).with("localhost", local_port).and_return(true)
|
1542
1543
|
expect(knife_ec2_create.tunnel_test_ssh(gateway_host, hostname)).to eq(true)
|
1543
1544
|
end
|
1544
1545
|
end
|
1545
1546
|
|
1546
1547
|
describe "configure_ssh_gateway" do
|
1547
|
-
let(:gateway_host) {
|
1548
|
-
let(:gateway_user) {
|
1548
|
+
let(:gateway_host) { "test.gateway.com" }
|
1549
|
+
let(:gateway_user) { "gateway_user" }
|
1549
1550
|
|
1550
1551
|
it "configures a ssh gateway with no user and the default port when the SSH Config is empty" do
|
1551
1552
|
allow(Net::SSH::Config).to receive(:for).and_return({})
|
1552
|
-
expect(Net::SSH::Gateway).to receive(:new).with(gateway_host, nil, :
|
1553
|
+
expect(Net::SSH::Gateway).to receive(:new).with(gateway_host, nil, port: 22)
|
1553
1554
|
knife_ec2_create.configure_ssh_gateway(gateway_host)
|
1554
1555
|
end
|
1555
1556
|
|
1556
1557
|
it "configures a ssh gateway with the user specified in the SSH Config" do
|
1557
|
-
allow(Net::SSH::Config).to receive(:for).and_return({ :
|
1558
|
-
expect(Net::SSH::Gateway).to receive(:new).with(gateway_host, gateway_user, :
|
1558
|
+
allow(Net::SSH::Config).to receive(:for).and_return({ user: gateway_user })
|
1559
|
+
expect(Net::SSH::Gateway).to receive(:new).with(gateway_host, gateway_user, port: 22)
|
1559
1560
|
knife_ec2_create.configure_ssh_gateway(gateway_host)
|
1560
1561
|
end
|
1561
1562
|
|
1562
1563
|
it "configures a ssh gateway with the user specified in the ssh gateway string" do
|
1563
|
-
allow(Net::SSH::Config).to receive(:for).and_return({ :
|
1564
|
-
expect(Net::SSH::Gateway).to receive(:new).with(gateway_host,
|
1564
|
+
allow(Net::SSH::Config).to receive(:for).and_return({ user: gateway_user })
|
1565
|
+
expect(Net::SSH::Gateway).to receive(:new).with(gateway_host, "override_user", port: 22)
|
1565
1566
|
knife_ec2_create.configure_ssh_gateway("override_user@#{gateway_host}")
|
1566
1567
|
end
|
1567
1568
|
|
1568
1569
|
it "configures a ssh gateway with the port specified in the ssh gateway string" do
|
1569
1570
|
allow(Net::SSH::Config).to receive(:for).and_return({})
|
1570
|
-
expect(Net::SSH::Gateway).to receive(:new).with(gateway_host, nil, :
|
1571
|
+
expect(Net::SSH::Gateway).to receive(:new).with(gateway_host, nil, port: "24")
|
1571
1572
|
knife_ec2_create.configure_ssh_gateway("#{gateway_host}:24")
|
1572
1573
|
end
|
1573
1574
|
|
1574
1575
|
it "configures a ssh gateway with the keys specified in the SSH Config" do
|
1575
|
-
allow(Net::SSH::Config).to receive(:for).and_return({ :
|
1576
|
-
expect(Net::SSH::Gateway).to receive(:new).with(gateway_host, nil, :
|
1576
|
+
allow(Net::SSH::Config).to receive(:for).and_return({ keys: ["configuredkey"] })
|
1577
|
+
expect(Net::SSH::Gateway).to receive(:new).with(gateway_host, nil, port: 22, keys: ["configuredkey"])
|
1577
1578
|
knife_ec2_create.configure_ssh_gateway(gateway_host)
|
1578
1579
|
end
|
1579
1580
|
|
1580
1581
|
it "configures the ssh gateway with the key specified on the knife config / command line" do
|
1581
1582
|
knife_ec2_create.config[:ssh_gateway_identity] = "/home/fireman/.ssh/gateway.pem"
|
1582
|
-
#Net::SSH::Config.stub(:for).and_return({ :keys => ['configuredkey'] })
|
1583
|
-
expect(Net::SSH::Gateway).to receive(:new).with(gateway_host, nil, :
|
1583
|
+
# Net::SSH::Config.stub(:for).and_return({ :keys => ['configuredkey'] })
|
1584
|
+
expect(Net::SSH::Gateway).to receive(:new).with(gateway_host, nil, port: 22, keys: ["/home/fireman/.ssh/gateway.pem"])
|
1584
1585
|
knife_ec2_create.configure_ssh_gateway(gateway_host)
|
1585
1586
|
end
|
1586
1587
|
|
1587
1588
|
it "prefers the knife config over the ssh config for the gateway keys" do
|
1588
1589
|
knife_ec2_create.config[:ssh_gateway_identity] = "/home/fireman/.ssh/gateway.pem"
|
1589
|
-
allow(Net::SSH::Config).to receive(:for).and_return({ :
|
1590
|
-
expect(Net::SSH::Gateway).to receive(:new).with(gateway_host, nil, :
|
1590
|
+
allow(Net::SSH::Config).to receive(:for).and_return({ keys: ["not_this_key_dude"] })
|
1591
|
+
expect(Net::SSH::Gateway).to receive(:new).with(gateway_host, nil, port: 22, keys: ["/home/fireman/.ssh/gateway.pem"])
|
1591
1592
|
knife_ec2_create.configure_ssh_gateway(gateway_host)
|
1592
1593
|
end
|
1593
1594
|
end
|
@@ -1599,7 +1600,7 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1599
1600
|
allow(TCPSocket).to receive(:new).and_return(StringIO.new("SSH-2.0-OpenSSH_6.1p1 Debian-4"))
|
1600
1601
|
allow(IO).to receive(:select).and_return(true)
|
1601
1602
|
expect(knife_ec2_create).to receive(:tcp_test_ssh).and_yield.and_return(true)
|
1602
|
-
knife_ec2_create.tcp_test_ssh("blackhole.ninja", 22) {nil}
|
1603
|
+
knife_ec2_create.tcp_test_ssh("blackhole.ninja", 22) { nil }
|
1603
1604
|
end
|
1604
1605
|
|
1605
1606
|
it "should return false if we do not get an ssh header" do
|
@@ -1617,212 +1618,212 @@ describe Chef::Knife::Ec2ServerCreate do
|
|
1617
1618
|
end
|
1618
1619
|
end
|
1619
1620
|
|
1620
|
-
describe
|
1621
|
+
describe "ssl_config_user_data" do
|
1621
1622
|
before do
|
1622
1623
|
knife_ec2_create.config[:winrm_password] = "ec2@123"
|
1623
1624
|
end
|
1624
1625
|
|
1625
|
-
context
|
1626
|
+
context "For domain user" do
|
1626
1627
|
before do
|
1627
1628
|
knife_ec2_create.config[:winrm_user] = "domain\\ec2"
|
1628
|
-
@ssl_config_data =
|
1629
|
-
|
1630
|
-
If (-Not (Get-Service WinRM | Where-Object {$_.status -eq "Running"})) {
|
1631
|
-
|
1632
|
-
}
|
1633
|
-
If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b" -Quiet) {
|
1634
|
-
|
1635
|
-
}
|
1636
|
-
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
1637
|
-
If (-Not $vm_name) {
|
1638
|
-
|
1639
|
-
}
|
1640
|
-
|
1641
|
-
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
1642
|
-
$name.Encode("CN=$vm_name", 0)
|
1643
|
-
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
1644
|
-
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
1645
|
-
$key.KeySpec = 1
|
1646
|
-
$key.Length = 2048
|
1647
|
-
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
1648
|
-
$key.MachineContext = 1
|
1649
|
-
$key.Create()
|
1650
|
-
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
1651
|
-
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
1652
|
-
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
1653
|
-
$ekuoids.add($serverauthoid)
|
1654
|
-
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
1655
|
-
$ekuext.InitializeEncode($ekuoids)
|
1656
|
-
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
1657
|
-
$cert.InitializeFromPrivateKey(2, $key, "")
|
1658
|
-
$cert.Subject = $name
|
1659
|
-
$cert.Issuer = $cert.Subject
|
1660
|
-
$cert.NotBefore = get-date
|
1661
|
-
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
1662
|
-
$cert.X509Extensions.Add($ekuext)
|
1663
|
-
$cert.Encode()
|
1664
|
-
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
1665
|
-
$enrollment.InitializeFromRequest($cert)
|
1666
|
-
$certdata = $enrollment.CreateRequest(0)
|
1667
|
-
$enrollment.InstallResponse(2, $certdata, 0, "")
|
1668
|
-
|
1669
|
-
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1670
|
-
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
1671
|
-
iex $create_listener_cmd
|
1672
|
-
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
1629
|
+
@ssl_config_data = <<~EOH
|
1630
|
+
|
1631
|
+
If (-Not (Get-Service WinRM | Where-Object {$_.status -eq "Running"})) {
|
1632
|
+
winrm quickconfig -q
|
1633
|
+
}
|
1634
|
+
If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b" -Quiet) {
|
1635
|
+
winrm delete winrm/config/listener?Address=*+Transport=HTTP
|
1636
|
+
}
|
1637
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
1638
|
+
If (-Not $vm_name) {
|
1639
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
1640
|
+
}
|
1641
|
+
|
1642
|
+
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
1643
|
+
$name.Encode("CN=$vm_name", 0)
|
1644
|
+
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
1645
|
+
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
1646
|
+
$key.KeySpec = 1
|
1647
|
+
$key.Length = 2048
|
1648
|
+
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
1649
|
+
$key.MachineContext = 1
|
1650
|
+
$key.Create()
|
1651
|
+
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
1652
|
+
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
1653
|
+
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
1654
|
+
$ekuoids.add($serverauthoid)
|
1655
|
+
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
1656
|
+
$ekuext.InitializeEncode($ekuoids)
|
1657
|
+
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
1658
|
+
$cert.InitializeFromPrivateKey(2, $key, "")
|
1659
|
+
$cert.Subject = $name
|
1660
|
+
$cert.Issuer = $cert.Subject
|
1661
|
+
$cert.NotBefore = get-date
|
1662
|
+
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
1663
|
+
$cert.X509Extensions.Add($ekuext)
|
1664
|
+
$cert.Encode()
|
1665
|
+
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
1666
|
+
$enrollment.InitializeFromRequest($cert)
|
1667
|
+
$certdata = $enrollment.CreateRequest(0)
|
1668
|
+
$enrollment.InstallResponse(2, $certdata, 0, "")
|
1669
|
+
|
1670
|
+
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1671
|
+
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
1672
|
+
iex $create_listener_cmd
|
1673
|
+
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
1673
1674
|
EOH
|
1674
1675
|
end
|
1675
1676
|
|
1676
|
-
it
|
1677
|
+
it "gets ssl config user data" do
|
1677
1678
|
expect(knife_ec2_create.ssl_config_user_data).to be == @ssl_config_data
|
1678
1679
|
end
|
1679
1680
|
end
|
1680
1681
|
|
1681
|
-
context
|
1682
|
+
context "For local user" do
|
1682
1683
|
before do
|
1683
1684
|
knife_ec2_create.config[:winrm_user] = ".\\ec2"
|
1684
|
-
@ssl_config_data =
|
1685
|
-
net user /add ec2 ec2@123 ;
|
1686
|
-
net localgroup Administrators /add ec2;
|
1687
|
-
|
1688
|
-
If (-Not (Get-Service WinRM | Where-Object {$_.status -eq "Running"})) {
|
1689
|
-
|
1690
|
-
}
|
1691
|
-
If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b" -Quiet) {
|
1692
|
-
|
1693
|
-
}
|
1694
|
-
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
1695
|
-
If (-Not $vm_name) {
|
1696
|
-
|
1697
|
-
}
|
1698
|
-
|
1699
|
-
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
1700
|
-
$name.Encode("CN=$vm_name", 0)
|
1701
|
-
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
1702
|
-
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
1703
|
-
$key.KeySpec = 1
|
1704
|
-
$key.Length = 2048
|
1705
|
-
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
1706
|
-
$key.MachineContext = 1
|
1707
|
-
$key.Create()
|
1708
|
-
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
1709
|
-
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
1710
|
-
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
1711
|
-
$ekuoids.add($serverauthoid)
|
1712
|
-
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
1713
|
-
$ekuext.InitializeEncode($ekuoids)
|
1714
|
-
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
1715
|
-
$cert.InitializeFromPrivateKey(2, $key, "")
|
1716
|
-
$cert.Subject = $name
|
1717
|
-
$cert.Issuer = $cert.Subject
|
1718
|
-
$cert.NotBefore = get-date
|
1719
|
-
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
1720
|
-
$cert.X509Extensions.Add($ekuext)
|
1721
|
-
$cert.Encode()
|
1722
|
-
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
1723
|
-
$enrollment.InitializeFromRequest($cert)
|
1724
|
-
$certdata = $enrollment.CreateRequest(0)
|
1725
|
-
$enrollment.InstallResponse(2, $certdata, 0, "")
|
1726
|
-
|
1727
|
-
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1728
|
-
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
1729
|
-
iex $create_listener_cmd
|
1730
|
-
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
1685
|
+
@ssl_config_data = <<~EOH
|
1686
|
+
net user /add ec2 ec2@123 ;
|
1687
|
+
net localgroup Administrators /add ec2;
|
1688
|
+
|
1689
|
+
If (-Not (Get-Service WinRM | Where-Object {$_.status -eq "Running"})) {
|
1690
|
+
winrm quickconfig -q
|
1691
|
+
}
|
1692
|
+
If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b" -Quiet) {
|
1693
|
+
winrm delete winrm/config/listener?Address=*+Transport=HTTP
|
1694
|
+
}
|
1695
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
1696
|
+
If (-Not $vm_name) {
|
1697
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
1698
|
+
}
|
1699
|
+
|
1700
|
+
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
1701
|
+
$name.Encode("CN=$vm_name", 0)
|
1702
|
+
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
1703
|
+
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
1704
|
+
$key.KeySpec = 1
|
1705
|
+
$key.Length = 2048
|
1706
|
+
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
1707
|
+
$key.MachineContext = 1
|
1708
|
+
$key.Create()
|
1709
|
+
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
1710
|
+
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
1711
|
+
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
1712
|
+
$ekuoids.add($serverauthoid)
|
1713
|
+
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
1714
|
+
$ekuext.InitializeEncode($ekuoids)
|
1715
|
+
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
1716
|
+
$cert.InitializeFromPrivateKey(2, $key, "")
|
1717
|
+
$cert.Subject = $name
|
1718
|
+
$cert.Issuer = $cert.Subject
|
1719
|
+
$cert.NotBefore = get-date
|
1720
|
+
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
1721
|
+
$cert.X509Extensions.Add($ekuext)
|
1722
|
+
$cert.Encode()
|
1723
|
+
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
1724
|
+
$enrollment.InitializeFromRequest($cert)
|
1725
|
+
$certdata = $enrollment.CreateRequest(0)
|
1726
|
+
$enrollment.InstallResponse(2, $certdata, 0, "")
|
1727
|
+
|
1728
|
+
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1729
|
+
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
1730
|
+
iex $create_listener_cmd
|
1731
|
+
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
1731
1732
|
EOH
|
1732
1733
|
|
1733
1734
|
end
|
1734
1735
|
|
1735
|
-
it
|
1736
|
+
it "gets ssl config user data" do
|
1736
1737
|
expect(knife_ec2_create.ssl_config_user_data).to be == @ssl_config_data
|
1737
1738
|
end
|
1738
1739
|
end
|
1739
1740
|
end
|
1740
1741
|
|
1741
|
-
describe
|
1742
|
+
describe "ssl_config_data_already_exist?" do
|
1742
1743
|
|
1743
1744
|
before(:each) do
|
1744
|
-
@user_user_data =
|
1745
|
+
@user_user_data = "user_user_data.ps1"
|
1745
1746
|
knife_ec2_create.config[:winrm_user] = "domain\\ec2"
|
1746
1747
|
knife_ec2_create.config[:winrm_password] = "ec2@123"
|
1747
1748
|
knife_ec2_create.config[:aws_user_data] = @user_user_data
|
1748
1749
|
end
|
1749
1750
|
|
1750
|
-
context
|
1751
|
+
context "ssl config data does not exist in user supplied user_data" do
|
1751
1752
|
before do
|
1752
|
-
File.open(@user_user_data,"w+") do |f|
|
1753
|
-
f.write
|
1754
|
-
user_command_1\\\\user_command_2\\\\user_command_3
|
1755
|
-
user_command_4
|
1753
|
+
File.open(@user_user_data, "w+") do |f|
|
1754
|
+
f.write <<~EOH
|
1755
|
+
user_command_1\\\\user_command_2\\\\user_command_3
|
1756
|
+
user_command_4
|
1756
1757
|
EOH
|
1757
1758
|
end
|
1758
1759
|
end
|
1759
1760
|
|
1760
|
-
it
|
1761
|
+
it "returns false" do
|
1761
1762
|
expect(knife_ec2_create.ssl_config_data_already_exist?).to eq(false)
|
1762
1763
|
end
|
1763
1764
|
end
|
1764
1765
|
|
1765
|
-
context
|
1766
|
+
context "ssl config data already exist in user supplied user_data" do
|
1766
1767
|
before do
|
1767
|
-
File.open(@user_user_data,"w+") do |f|
|
1768
|
-
f.write
|
1769
|
-
user_command_1
|
1770
|
-
user_command_2
|
1771
|
-
|
1772
|
-
<powershell>
|
1773
|
-
|
1774
|
-
If (-Not (Get-Service WinRM | Where-Object {$_.status -eq "Running"})) {
|
1775
|
-
|
1776
|
-
}
|
1777
|
-
If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b" -Quiet) {
|
1778
|
-
|
1779
|
-
}
|
1780
|
-
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
1781
|
-
If (-Not $vm_name) {
|
1782
|
-
|
1783
|
-
}
|
1784
|
-
|
1785
|
-
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
1786
|
-
$name.Encode("CN=$vm_name", 0)
|
1787
|
-
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
1788
|
-
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
1789
|
-
$key.KeySpec = 1
|
1790
|
-
$key.Length = 2048
|
1791
|
-
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
1792
|
-
$key.MachineContext = 1
|
1793
|
-
$key.Create()
|
1794
|
-
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
1795
|
-
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
1796
|
-
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
1797
|
-
$ekuoids.add($serverauthoid)
|
1798
|
-
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
1799
|
-
$ekuext.InitializeEncode($ekuoids)
|
1800
|
-
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
1801
|
-
$cert.InitializeFromPrivateKey(2, $key, "")
|
1802
|
-
$cert.Subject = $name
|
1803
|
-
$cert.Issuer = $cert.Subject
|
1804
|
-
$cert.NotBefore = get-date
|
1805
|
-
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
1806
|
-
$cert.X509Extensions.Add($ekuext)
|
1807
|
-
$cert.Encode()
|
1808
|
-
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
1809
|
-
$enrollment.InitializeFromRequest($cert)
|
1810
|
-
$certdata = $enrollment.CreateRequest(0)
|
1811
|
-
$enrollment.InstallResponse(2, $certdata, 0, "")
|
1812
|
-
|
1813
|
-
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1814
|
-
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
1815
|
-
iex $create_listener_cmd
|
1816
|
-
|
1817
|
-
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
1818
|
-
|
1819
|
-
</powershell>
|
1768
|
+
File.open(@user_user_data, "w+") do |f|
|
1769
|
+
f.write <<~EOH
|
1770
|
+
user_command_1
|
1771
|
+
user_command_2
|
1772
|
+
|
1773
|
+
<powershell>
|
1774
|
+
|
1775
|
+
If (-Not (Get-Service WinRM | Where-Object {$_.status -eq "Running"})) {
|
1776
|
+
winrm quickconfig -q
|
1777
|
+
}
|
1778
|
+
If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b" -Quiet) {
|
1779
|
+
winrm delete winrm/config/listener?Address=*+Transport=HTTP
|
1780
|
+
}
|
1781
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
1782
|
+
If (-Not $vm_name) {
|
1783
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
1784
|
+
}
|
1785
|
+
|
1786
|
+
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
1787
|
+
$name.Encode("CN=$vm_name", 0)
|
1788
|
+
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
1789
|
+
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
1790
|
+
$key.KeySpec = 1
|
1791
|
+
$key.Length = 2048
|
1792
|
+
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
1793
|
+
$key.MachineContext = 1
|
1794
|
+
$key.Create()
|
1795
|
+
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
1796
|
+
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
1797
|
+
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
1798
|
+
$ekuoids.add($serverauthoid)
|
1799
|
+
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
1800
|
+
$ekuext.InitializeEncode($ekuoids)
|
1801
|
+
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
1802
|
+
$cert.InitializeFromPrivateKey(2, $key, "")
|
1803
|
+
$cert.Subject = $name
|
1804
|
+
$cert.Issuer = $cert.Subject
|
1805
|
+
$cert.NotBefore = get-date
|
1806
|
+
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
1807
|
+
$cert.X509Extensions.Add($ekuext)
|
1808
|
+
$cert.Encode()
|
1809
|
+
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
1810
|
+
$enrollment.InitializeFromRequest($cert)
|
1811
|
+
$certdata = $enrollment.CreateRequest(0)
|
1812
|
+
$enrollment.InstallResponse(2, $certdata, 0, "")
|
1813
|
+
|
1814
|
+
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1815
|
+
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
1816
|
+
iex $create_listener_cmd
|
1817
|
+
|
1818
|
+
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
1819
|
+
|
1820
|
+
</powershell>
|
1820
1821
|
|
1821
1822
|
EOH
|
1822
1823
|
end
|
1823
1824
|
end
|
1824
1825
|
|
1825
|
-
it
|
1826
|
+
it "returns false" do
|
1826
1827
|
expect(knife_ec2_create.ssl_config_data_already_exist?).to eq(false)
|
1827
1828
|
end
|
1828
1829
|
end
|
@@ -1833,7 +1834,7 @@ netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Local
|
|
1833
1834
|
end
|
1834
1835
|
end
|
1835
1836
|
|
1836
|
-
describe
|
1837
|
+
describe "attach ssl config into user data when transport is ssl" do
|
1837
1838
|
before(:each) do
|
1838
1839
|
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
1839
1840
|
Chef::Config[:knife][:ssh_key_name] = "mykey"
|
@@ -1844,72 +1845,72 @@ netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Local
|
|
1844
1845
|
knife_ec2_create.config[:winrm_password] = "ec2@123"
|
1845
1846
|
end
|
1846
1847
|
|
1847
|
-
context
|
1848
|
+
context "when user_data script provided by user contains only <script> section" do
|
1848
1849
|
before do
|
1849
|
-
@user_user_data =
|
1850
|
-
File.open(@user_user_data,"w+") do |f|
|
1851
|
-
f.write
|
1852
|
-
<script>
|
1850
|
+
@user_user_data = "user_user_data.ps1"
|
1851
|
+
File.open(@user_user_data, "w+") do |f|
|
1852
|
+
f.write <<~EOH
|
1853
|
+
<script>
|
1853
1854
|
|
1854
|
-
ipconfig > c:\\ipconfig_data.txt
|
1855
|
+
ipconfig > c:\\ipconfig_data.txt
|
1855
1856
|
|
1856
|
-
</script>
|
1857
|
+
</script>
|
1857
1858
|
EOH
|
1858
1859
|
end
|
1859
|
-
@server_def_user_data =
|
1860
|
-
<script>
|
1861
|
-
|
1862
|
-
ipconfig > c:\\ipconfig_data.txt
|
1863
|
-
|
1864
|
-
</script>
|
1865
|
-
|
1866
|
-
|
1867
|
-
<powershell>
|
1868
|
-
|
1869
|
-
If (-Not (Get-Service WinRM | Where-Object {$_.status -eq "Running"})) {
|
1870
|
-
|
1871
|
-
}
|
1872
|
-
If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b" -Quiet) {
|
1873
|
-
|
1874
|
-
}
|
1875
|
-
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
1876
|
-
If (-Not $vm_name) {
|
1877
|
-
|
1878
|
-
}
|
1879
|
-
|
1880
|
-
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
1881
|
-
$name.Encode("CN=$vm_name", 0)
|
1882
|
-
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
1883
|
-
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
1884
|
-
$key.KeySpec = 1
|
1885
|
-
$key.Length = 2048
|
1886
|
-
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
1887
|
-
$key.MachineContext = 1
|
1888
|
-
$key.Create()
|
1889
|
-
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
1890
|
-
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
1891
|
-
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
1892
|
-
$ekuoids.add($serverauthoid)
|
1893
|
-
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
1894
|
-
$ekuext.InitializeEncode($ekuoids)
|
1895
|
-
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
1896
|
-
$cert.InitializeFromPrivateKey(2, $key, "")
|
1897
|
-
$cert.Subject = $name
|
1898
|
-
$cert.Issuer = $cert.Subject
|
1899
|
-
$cert.NotBefore = get-date
|
1900
|
-
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
1901
|
-
$cert.X509Extensions.Add($ekuext)
|
1902
|
-
$cert.Encode()
|
1903
|
-
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
1904
|
-
$enrollment.InitializeFromRequest($cert)
|
1905
|
-
$certdata = $enrollment.CreateRequest(0)
|
1906
|
-
$enrollment.InstallResponse(2, $certdata, 0, "")
|
1907
|
-
|
1908
|
-
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1909
|
-
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
1910
|
-
iex $create_listener_cmd
|
1911
|
-
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
1912
|
-
</powershell>
|
1860
|
+
@server_def_user_data = <<~EOH
|
1861
|
+
<script>
|
1862
|
+
|
1863
|
+
ipconfig > c:\\ipconfig_data.txt
|
1864
|
+
|
1865
|
+
</script>
|
1866
|
+
|
1867
|
+
|
1868
|
+
<powershell>
|
1869
|
+
|
1870
|
+
If (-Not (Get-Service WinRM | Where-Object {$_.status -eq "Running"})) {
|
1871
|
+
winrm quickconfig -q
|
1872
|
+
}
|
1873
|
+
If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b" -Quiet) {
|
1874
|
+
winrm delete winrm/config/listener?Address=*+Transport=HTTP
|
1875
|
+
}
|
1876
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
1877
|
+
If (-Not $vm_name) {
|
1878
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
1879
|
+
}
|
1880
|
+
|
1881
|
+
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
1882
|
+
$name.Encode("CN=$vm_name", 0)
|
1883
|
+
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
1884
|
+
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
1885
|
+
$key.KeySpec = 1
|
1886
|
+
$key.Length = 2048
|
1887
|
+
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
1888
|
+
$key.MachineContext = 1
|
1889
|
+
$key.Create()
|
1890
|
+
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
1891
|
+
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
1892
|
+
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
1893
|
+
$ekuoids.add($serverauthoid)
|
1894
|
+
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
1895
|
+
$ekuext.InitializeEncode($ekuoids)
|
1896
|
+
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
1897
|
+
$cert.InitializeFromPrivateKey(2, $key, "")
|
1898
|
+
$cert.Subject = $name
|
1899
|
+
$cert.Issuer = $cert.Subject
|
1900
|
+
$cert.NotBefore = get-date
|
1901
|
+
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
1902
|
+
$cert.X509Extensions.Add($ekuext)
|
1903
|
+
$cert.Encode()
|
1904
|
+
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
1905
|
+
$enrollment.InitializeFromRequest($cert)
|
1906
|
+
$certdata = $enrollment.CreateRequest(0)
|
1907
|
+
$enrollment.InstallResponse(2, $certdata, 0, "")
|
1908
|
+
|
1909
|
+
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1910
|
+
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
1911
|
+
iex $create_listener_cmd
|
1912
|
+
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
1913
|
+
</powershell>
|
1913
1914
|
EOH
|
1914
1915
|
knife_ec2_create.config[:aws_user_data] = @user_user_data
|
1915
1916
|
end
|
@@ -1926,66 +1927,66 @@ netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Local
|
|
1926
1927
|
end
|
1927
1928
|
end
|
1928
1929
|
|
1929
|
-
context
|
1930
|
+
context "when user_data script provided by user contains <powershell> section" do
|
1930
1931
|
before do
|
1931
|
-
@user_user_data =
|
1932
|
-
File.open(@user_user_data,"w+") do |f|
|
1933
|
-
f.write
|
1934
|
-
<powershell>
|
1932
|
+
@user_user_data = "user_user_data.ps1"
|
1933
|
+
File.open(@user_user_data, "w+") do |f|
|
1934
|
+
f.write <<~EOH
|
1935
|
+
<powershell>
|
1935
1936
|
|
1936
|
-
Get-DscLocalConfigurationManager > c:\\dsc_data.txt
|
1937
|
-
</powershell>
|
1937
|
+
Get-DscLocalConfigurationManager > c:\\dsc_data.txt
|
1938
|
+
</powershell>
|
1938
1939
|
EOH
|
1939
1940
|
end
|
1940
|
-
@server_def_user_data =
|
1941
|
-
<powershell>
|
1942
|
-
|
1943
|
-
Get-DscLocalConfigurationManager > c:\\dsc_data.txt
|
1944
|
-
|
1945
|
-
If (-Not (Get-Service WinRM | Where-Object {$_.status -eq "Running"})) {
|
1946
|
-
|
1947
|
-
}
|
1948
|
-
If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b" -Quiet) {
|
1949
|
-
|
1950
|
-
}
|
1951
|
-
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
1952
|
-
If (-Not $vm_name) {
|
1953
|
-
|
1954
|
-
}
|
1955
|
-
|
1956
|
-
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
1957
|
-
$name.Encode("CN=$vm_name", 0)
|
1958
|
-
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
1959
|
-
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
1960
|
-
$key.KeySpec = 1
|
1961
|
-
$key.Length = 2048
|
1962
|
-
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
1963
|
-
$key.MachineContext = 1
|
1964
|
-
$key.Create()
|
1965
|
-
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
1966
|
-
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
1967
|
-
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
1968
|
-
$ekuoids.add($serverauthoid)
|
1969
|
-
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
1970
|
-
$ekuext.InitializeEncode($ekuoids)
|
1971
|
-
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
1972
|
-
$cert.InitializeFromPrivateKey(2, $key, "")
|
1973
|
-
$cert.Subject = $name
|
1974
|
-
$cert.Issuer = $cert.Subject
|
1975
|
-
$cert.NotBefore = get-date
|
1976
|
-
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
1977
|
-
$cert.X509Extensions.Add($ekuext)
|
1978
|
-
$cert.Encode()
|
1979
|
-
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
1980
|
-
$enrollment.InitializeFromRequest($cert)
|
1981
|
-
$certdata = $enrollment.CreateRequest(0)
|
1982
|
-
$enrollment.InstallResponse(2, $certdata, 0, "")
|
1983
|
-
|
1984
|
-
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1985
|
-
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
1986
|
-
iex $create_listener_cmd
|
1987
|
-
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
1988
|
-
</powershell>
|
1941
|
+
@server_def_user_data = <<~EOH
|
1942
|
+
<powershell>
|
1943
|
+
|
1944
|
+
Get-DscLocalConfigurationManager > c:\\dsc_data.txt
|
1945
|
+
|
1946
|
+
If (-Not (Get-Service WinRM | Where-Object {$_.status -eq "Running"})) {
|
1947
|
+
winrm quickconfig -q
|
1948
|
+
}
|
1949
|
+
If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b" -Quiet) {
|
1950
|
+
winrm delete winrm/config/listener?Address=*+Transport=HTTP
|
1951
|
+
}
|
1952
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
1953
|
+
If (-Not $vm_name) {
|
1954
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
1955
|
+
}
|
1956
|
+
|
1957
|
+
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
1958
|
+
$name.Encode("CN=$vm_name", 0)
|
1959
|
+
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
1960
|
+
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
1961
|
+
$key.KeySpec = 1
|
1962
|
+
$key.Length = 2048
|
1963
|
+
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
1964
|
+
$key.MachineContext = 1
|
1965
|
+
$key.Create()
|
1966
|
+
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
1967
|
+
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
1968
|
+
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
1969
|
+
$ekuoids.add($serverauthoid)
|
1970
|
+
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
1971
|
+
$ekuext.InitializeEncode($ekuoids)
|
1972
|
+
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
1973
|
+
$cert.InitializeFromPrivateKey(2, $key, "")
|
1974
|
+
$cert.Subject = $name
|
1975
|
+
$cert.Issuer = $cert.Subject
|
1976
|
+
$cert.NotBefore = get-date
|
1977
|
+
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
1978
|
+
$cert.X509Extensions.Add($ekuext)
|
1979
|
+
$cert.Encode()
|
1980
|
+
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
1981
|
+
$enrollment.InitializeFromRequest($cert)
|
1982
|
+
$certdata = $enrollment.CreateRequest(0)
|
1983
|
+
$enrollment.InstallResponse(2, $certdata, 0, "")
|
1984
|
+
|
1985
|
+
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
1986
|
+
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
1987
|
+
iex $create_listener_cmd
|
1988
|
+
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
1989
|
+
</powershell>
|
1989
1990
|
EOH
|
1990
1991
|
knife_ec2_create.config[:aws_user_data] = @user_user_data
|
1991
1992
|
end
|
@@ -2002,110 +2003,110 @@ netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Local
|
|
2002
2003
|
end
|
2003
2004
|
end
|
2004
2005
|
|
2005
|
-
context
|
2006
|
+
context "when user_data script provided by user already contains ssl config code" do
|
2006
2007
|
before do
|
2007
|
-
@user_user_data =
|
2008
|
-
File.open(@user_user_data,"w+") do |f|
|
2009
|
-
f.write
|
2010
|
-
<powershell>
|
2011
|
-
|
2012
|
-
Get-DscLocalConfigurationManager > c:\\dsc_data.txt
|
2013
|
-
|
2014
|
-
If (-Not (Get-Service WinRM | Where-Object {$_.status -eq "Running"})) {
|
2015
|
-
|
2016
|
-
}
|
2017
|
-
If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b" -Quiet) {
|
2018
|
-
|
2019
|
-
}
|
2020
|
-
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
2021
|
-
If (-Not $vm_name) {
|
2022
|
-
|
2023
|
-
}
|
2024
|
-
|
2025
|
-
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
2026
|
-
$name.Encode("CN=$vm_name", 0)
|
2027
|
-
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
2028
|
-
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
2029
|
-
$key.KeySpec = 1
|
2030
|
-
$key.Length = 2048
|
2031
|
-
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
2032
|
-
$key.MachineContext = 1
|
2033
|
-
$key.Create()
|
2034
|
-
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
2035
|
-
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
2036
|
-
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
2037
|
-
$ekuoids.add($serverauthoid)
|
2038
|
-
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
2039
|
-
$ekuext.InitializeEncode($ekuoids)
|
2040
|
-
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
2041
|
-
$cert.InitializeFromPrivateKey(2, $key, "")
|
2042
|
-
$cert.Subject = $name
|
2043
|
-
$cert.Issuer = $cert.Subject
|
2044
|
-
$cert.NotBefore = get-date
|
2045
|
-
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
2046
|
-
$cert.X509Extensions.Add($ekuext)
|
2047
|
-
$cert.Encode()
|
2048
|
-
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
2049
|
-
$enrollment.InitializeFromRequest($cert)
|
2050
|
-
$certdata = $enrollment.CreateRequest(0)
|
2051
|
-
$enrollment.InstallResponse(2, $certdata, 0, "")
|
2052
|
-
|
2053
|
-
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
2054
|
-
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
2055
|
-
iex $create_listener_cmd
|
2056
|
-
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
2057
|
-
</powershell>
|
2008
|
+
@user_user_data = "user_user_data.ps1"
|
2009
|
+
File.open(@user_user_data, "w+") do |f|
|
2010
|
+
f.write <<~EOH
|
2011
|
+
<powershell>
|
2012
|
+
|
2013
|
+
Get-DscLocalConfigurationManager > c:\\dsc_data.txt
|
2014
|
+
|
2015
|
+
If (-Not (Get-Service WinRM | Where-Object {$_.status -eq "Running"})) {
|
2016
|
+
winrm quickconfig -q
|
2017
|
+
}
|
2018
|
+
If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b" -Quiet) {
|
2019
|
+
winrm delete winrm/config/listener?Address=*+Transport=HTTP
|
2020
|
+
}
|
2021
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
2022
|
+
If (-Not $vm_name) {
|
2023
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
2024
|
+
}
|
2025
|
+
|
2026
|
+
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
2027
|
+
$name.Encode("CN=$vm_name", 0)
|
2028
|
+
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
2029
|
+
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
2030
|
+
$key.KeySpec = 1
|
2031
|
+
$key.Length = 2048
|
2032
|
+
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
2033
|
+
$key.MachineContext = 1
|
2034
|
+
$key.Create()
|
2035
|
+
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
2036
|
+
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
2037
|
+
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
2038
|
+
$ekuoids.add($serverauthoid)
|
2039
|
+
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
2040
|
+
$ekuext.InitializeEncode($ekuoids)
|
2041
|
+
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
2042
|
+
$cert.InitializeFromPrivateKey(2, $key, "")
|
2043
|
+
$cert.Subject = $name
|
2044
|
+
$cert.Issuer = $cert.Subject
|
2045
|
+
$cert.NotBefore = get-date
|
2046
|
+
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
2047
|
+
$cert.X509Extensions.Add($ekuext)
|
2048
|
+
$cert.Encode()
|
2049
|
+
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
2050
|
+
$enrollment.InitializeFromRequest($cert)
|
2051
|
+
$certdata = $enrollment.CreateRequest(0)
|
2052
|
+
$enrollment.InstallResponse(2, $certdata, 0, "")
|
2053
|
+
|
2054
|
+
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
2055
|
+
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
2056
|
+
iex $create_listener_cmd
|
2057
|
+
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
2058
|
+
</powershell>
|
2058
2059
|
EOH
|
2059
2060
|
end
|
2060
|
-
@server_def_user_data =
|
2061
|
-
<powershell>
|
2062
|
-
|
2063
|
-
Get-DscLocalConfigurationManager > c:\\dsc_data.txt
|
2064
|
-
|
2065
|
-
If (-Not (Get-Service WinRM | Where-Object {$_.status -eq "Running"})) {
|
2066
|
-
|
2067
|
-
}
|
2068
|
-
If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b" -Quiet) {
|
2069
|
-
|
2070
|
-
}
|
2071
|
-
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
2072
|
-
If (-Not $vm_name) {
|
2073
|
-
|
2074
|
-
}
|
2075
|
-
|
2076
|
-
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
2077
|
-
$name.Encode("CN=$vm_name", 0)
|
2078
|
-
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
2079
|
-
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
2080
|
-
$key.KeySpec = 1
|
2081
|
-
$key.Length = 2048
|
2082
|
-
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
2083
|
-
$key.MachineContext = 1
|
2084
|
-
$key.Create()
|
2085
|
-
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
2086
|
-
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
2087
|
-
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
2088
|
-
$ekuoids.add($serverauthoid)
|
2089
|
-
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
2090
|
-
$ekuext.InitializeEncode($ekuoids)
|
2091
|
-
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
2092
|
-
$cert.InitializeFromPrivateKey(2, $key, "")
|
2093
|
-
$cert.Subject = $name
|
2094
|
-
$cert.Issuer = $cert.Subject
|
2095
|
-
$cert.NotBefore = get-date
|
2096
|
-
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
2097
|
-
$cert.X509Extensions.Add($ekuext)
|
2098
|
-
$cert.Encode()
|
2099
|
-
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
2100
|
-
$enrollment.InitializeFromRequest($cert)
|
2101
|
-
$certdata = $enrollment.CreateRequest(0)
|
2102
|
-
$enrollment.InstallResponse(2, $certdata, 0, "")
|
2103
|
-
|
2104
|
-
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
2105
|
-
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
2106
|
-
iex $create_listener_cmd
|
2107
|
-
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
2108
|
-
</powershell>
|
2061
|
+
@server_def_user_data = <<~EOH
|
2062
|
+
<powershell>
|
2063
|
+
|
2064
|
+
Get-DscLocalConfigurationManager > c:\\dsc_data.txt
|
2065
|
+
|
2066
|
+
If (-Not (Get-Service WinRM | Where-Object {$_.status -eq "Running"})) {
|
2067
|
+
winrm quickconfig -q
|
2068
|
+
}
|
2069
|
+
If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b" -Quiet) {
|
2070
|
+
winrm delete winrm/config/listener?Address=*+Transport=HTTP
|
2071
|
+
}
|
2072
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
2073
|
+
If (-Not $vm_name) {
|
2074
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
2075
|
+
}
|
2076
|
+
|
2077
|
+
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
2078
|
+
$name.Encode("CN=$vm_name", 0)
|
2079
|
+
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
2080
|
+
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
2081
|
+
$key.KeySpec = 1
|
2082
|
+
$key.Length = 2048
|
2083
|
+
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
2084
|
+
$key.MachineContext = 1
|
2085
|
+
$key.Create()
|
2086
|
+
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
2087
|
+
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
2088
|
+
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
2089
|
+
$ekuoids.add($serverauthoid)
|
2090
|
+
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
2091
|
+
$ekuext.InitializeEncode($ekuoids)
|
2092
|
+
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
2093
|
+
$cert.InitializeFromPrivateKey(2, $key, "")
|
2094
|
+
$cert.Subject = $name
|
2095
|
+
$cert.Issuer = $cert.Subject
|
2096
|
+
$cert.NotBefore = get-date
|
2097
|
+
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
2098
|
+
$cert.X509Extensions.Add($ekuext)
|
2099
|
+
$cert.Encode()
|
2100
|
+
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
2101
|
+
$enrollment.InitializeFromRequest($cert)
|
2102
|
+
$certdata = $enrollment.CreateRequest(0)
|
2103
|
+
$enrollment.InstallResponse(2, $certdata, 0, "")
|
2104
|
+
|
2105
|
+
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
2106
|
+
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
2107
|
+
iex $create_listener_cmd
|
2108
|
+
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
2109
|
+
</powershell>
|
2109
2110
|
EOH
|
2110
2111
|
knife_ec2_create.config[:aws_user_data] = @user_user_data
|
2111
2112
|
end
|
@@ -2122,20 +2123,20 @@ netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Local
|
|
2122
2123
|
end
|
2123
2124
|
end
|
2124
2125
|
|
2125
|
-
context
|
2126
|
+
context "when user_data script provided by user has invalid syntax" do
|
2126
2127
|
before do
|
2127
|
-
@user_user_data =
|
2128
|
-
File.open(@user_user_data,"w+") do |f|
|
2129
|
-
f.write
|
2130
|
-
<powershell>
|
2128
|
+
@user_user_data = "user_user_data.ps1"
|
2129
|
+
File.open(@user_user_data, "w+") do |f|
|
2130
|
+
f.write <<~EOH
|
2131
|
+
<powershell>
|
2131
2132
|
|
2132
|
-
Get-DscLocalConfigurationManager > c:\\dsc_data.txt
|
2133
|
+
Get-DscLocalConfigurationManager > c:\\dsc_data.txt
|
2133
2134
|
|
2134
|
-
<script>
|
2135
|
+
<script>
|
2135
2136
|
|
2136
|
-
ipconfig > c:\\ipconfig_data.txt
|
2137
|
+
ipconfig > c:\\ipconfig_data.txt
|
2137
2138
|
|
2138
|
-
</script>
|
2139
|
+
</script>
|
2139
2140
|
EOH
|
2140
2141
|
end
|
2141
2142
|
knife_ec2_create.config[:aws_user_data] = @user_user_data
|
@@ -2152,78 +2153,78 @@ ipconfig > c:\\ipconfig_data.txt
|
|
2152
2153
|
end
|
2153
2154
|
end
|
2154
2155
|
|
2155
|
-
context
|
2156
|
+
context "when user_data script provided by user has <powershell> and <script> tag sections" do
|
2156
2157
|
before do
|
2157
|
-
@user_user_data =
|
2158
|
-
File.open(@user_user_data,"w+") do |f|
|
2159
|
-
f.write
|
2160
|
-
<powershell>
|
2158
|
+
@user_user_data = "user_user_data.ps1"
|
2159
|
+
File.open(@user_user_data, "w+") do |f|
|
2160
|
+
f.write <<~EOH
|
2161
|
+
<powershell>
|
2161
2162
|
|
2162
|
-
Get-DscLocalConfigurationManager > c:\\dsc_data.txt
|
2163
|
+
Get-DscLocalConfigurationManager > c:\\dsc_data.txt
|
2163
2164
|
|
2164
|
-
</powershell>
|
2165
|
-
<script>
|
2165
|
+
</powershell>
|
2166
|
+
<script>
|
2166
2167
|
|
2167
|
-
ipconfig > c:\\ipconfig_data.txt
|
2168
|
+
ipconfig > c:\\ipconfig_data.txt
|
2168
2169
|
|
2169
|
-
</script>
|
2170
|
+
</script>
|
2170
2171
|
EOH
|
2171
2172
|
end
|
2172
|
-
@server_def_user_data =
|
2173
|
-
<powershell>
|
2174
|
-
|
2175
|
-
Get-DscLocalConfigurationManager > c:\\dsc_data.txt
|
2176
|
-
|
2177
|
-
|
2178
|
-
If (-Not (Get-Service WinRM | Where-Object {$_.status -eq "Running"})) {
|
2179
|
-
|
2180
|
-
}
|
2181
|
-
If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b" -Quiet) {
|
2182
|
-
|
2183
|
-
}
|
2184
|
-
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
2185
|
-
If (-Not $vm_name) {
|
2186
|
-
|
2187
|
-
}
|
2188
|
-
|
2189
|
-
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
2190
|
-
$name.Encode("CN=$vm_name", 0)
|
2191
|
-
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
2192
|
-
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
2193
|
-
$key.KeySpec = 1
|
2194
|
-
$key.Length = 2048
|
2195
|
-
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
2196
|
-
$key.MachineContext = 1
|
2197
|
-
$key.Create()
|
2198
|
-
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
2199
|
-
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
2200
|
-
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
2201
|
-
$ekuoids.add($serverauthoid)
|
2202
|
-
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
2203
|
-
$ekuext.InitializeEncode($ekuoids)
|
2204
|
-
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
2205
|
-
$cert.InitializeFromPrivateKey(2, $key, "")
|
2206
|
-
$cert.Subject = $name
|
2207
|
-
$cert.Issuer = $cert.Subject
|
2208
|
-
$cert.NotBefore = get-date
|
2209
|
-
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
2210
|
-
$cert.X509Extensions.Add($ekuext)
|
2211
|
-
$cert.Encode()
|
2212
|
-
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
2213
|
-
$enrollment.InitializeFromRequest($cert)
|
2214
|
-
$certdata = $enrollment.CreateRequest(0)
|
2215
|
-
$enrollment.InstallResponse(2, $certdata, 0, "")
|
2216
|
-
|
2217
|
-
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
2218
|
-
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
2219
|
-
iex $create_listener_cmd
|
2220
|
-
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
2221
|
-
</powershell>
|
2222
|
-
<script>
|
2223
|
-
|
2224
|
-
ipconfig > c:\\ipconfig_data.txt
|
2225
|
-
|
2226
|
-
</script>
|
2173
|
+
@server_def_user_data = <<~EOH
|
2174
|
+
<powershell>
|
2175
|
+
|
2176
|
+
Get-DscLocalConfigurationManager > c:\\dsc_data.txt
|
2177
|
+
|
2178
|
+
|
2179
|
+
If (-Not (Get-Service WinRM | Where-Object {$_.status -eq "Running"})) {
|
2180
|
+
winrm quickconfig -q
|
2181
|
+
}
|
2182
|
+
If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b" -Quiet) {
|
2183
|
+
winrm delete winrm/config/listener?Address=*+Transport=HTTP
|
2184
|
+
}
|
2185
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
2186
|
+
If (-Not $vm_name) {
|
2187
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
2188
|
+
}
|
2189
|
+
|
2190
|
+
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
2191
|
+
$name.Encode("CN=$vm_name", 0)
|
2192
|
+
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
2193
|
+
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
2194
|
+
$key.KeySpec = 1
|
2195
|
+
$key.Length = 2048
|
2196
|
+
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
2197
|
+
$key.MachineContext = 1
|
2198
|
+
$key.Create()
|
2199
|
+
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
2200
|
+
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
2201
|
+
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
2202
|
+
$ekuoids.add($serverauthoid)
|
2203
|
+
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
2204
|
+
$ekuext.InitializeEncode($ekuoids)
|
2205
|
+
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
2206
|
+
$cert.InitializeFromPrivateKey(2, $key, "")
|
2207
|
+
$cert.Subject = $name
|
2208
|
+
$cert.Issuer = $cert.Subject
|
2209
|
+
$cert.NotBefore = get-date
|
2210
|
+
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
2211
|
+
$cert.X509Extensions.Add($ekuext)
|
2212
|
+
$cert.Encode()
|
2213
|
+
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
2214
|
+
$enrollment.InitializeFromRequest($cert)
|
2215
|
+
$certdata = $enrollment.CreateRequest(0)
|
2216
|
+
$enrollment.InstallResponse(2, $certdata, 0, "")
|
2217
|
+
|
2218
|
+
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
2219
|
+
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
2220
|
+
iex $create_listener_cmd
|
2221
|
+
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
2222
|
+
</powershell>
|
2223
|
+
<script>
|
2224
|
+
|
2225
|
+
ipconfig > c:\\ipconfig_data.txt
|
2226
|
+
|
2227
|
+
</script>
|
2227
2228
|
EOH
|
2228
2229
|
knife_ec2_create.config[:aws_user_data] = @user_user_data
|
2229
2230
|
end
|
@@ -2242,53 +2243,53 @@ ipconfig > c:\\ipconfig_data.txt
|
|
2242
2243
|
|
2243
2244
|
context "when user_data is not supplied by user on cli" do
|
2244
2245
|
before do
|
2245
|
-
@server_def_user_data =
|
2246
|
-
<powershell>
|
2247
|
-
|
2248
|
-
If (-Not (Get-Service WinRM | Where-Object {$_.status -eq "Running"})) {
|
2249
|
-
|
2250
|
-
}
|
2251
|
-
If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b" -Quiet) {
|
2252
|
-
|
2253
|
-
}
|
2254
|
-
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
2255
|
-
If (-Not $vm_name) {
|
2256
|
-
|
2257
|
-
}
|
2258
|
-
|
2259
|
-
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
2260
|
-
$name.Encode("CN=$vm_name", 0)
|
2261
|
-
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
2262
|
-
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
2263
|
-
$key.KeySpec = 1
|
2264
|
-
$key.Length = 2048
|
2265
|
-
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
2266
|
-
$key.MachineContext = 1
|
2267
|
-
$key.Create()
|
2268
|
-
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
2269
|
-
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
2270
|
-
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
2271
|
-
$ekuoids.add($serverauthoid)
|
2272
|
-
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
2273
|
-
$ekuext.InitializeEncode($ekuoids)
|
2274
|
-
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
2275
|
-
$cert.InitializeFromPrivateKey(2, $key, "")
|
2276
|
-
$cert.Subject = $name
|
2277
|
-
$cert.Issuer = $cert.Subject
|
2278
|
-
$cert.NotBefore = get-date
|
2279
|
-
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
2280
|
-
$cert.X509Extensions.Add($ekuext)
|
2281
|
-
$cert.Encode()
|
2282
|
-
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
2283
|
-
$enrollment.InitializeFromRequest($cert)
|
2284
|
-
$certdata = $enrollment.CreateRequest(0)
|
2285
|
-
$enrollment.InstallResponse(2, $certdata, 0, "")
|
2286
|
-
|
2287
|
-
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
2288
|
-
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
2289
|
-
iex $create_listener_cmd
|
2290
|
-
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
2291
|
-
</powershell>
|
2246
|
+
@server_def_user_data = <<~EOH
|
2247
|
+
<powershell>
|
2248
|
+
|
2249
|
+
If (-Not (Get-Service WinRM | Where-Object {$_.status -eq "Running"})) {
|
2250
|
+
winrm quickconfig -q
|
2251
|
+
}
|
2252
|
+
If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b" -Quiet) {
|
2253
|
+
winrm delete winrm/config/listener?Address=*+Transport=HTTP
|
2254
|
+
}
|
2255
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
|
2256
|
+
If (-Not $vm_name) {
|
2257
|
+
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
|
2258
|
+
}
|
2259
|
+
|
2260
|
+
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
|
2261
|
+
$name.Encode("CN=$vm_name", 0)
|
2262
|
+
$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
|
2263
|
+
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
|
2264
|
+
$key.KeySpec = 1
|
2265
|
+
$key.Length = 2048
|
2266
|
+
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
|
2267
|
+
$key.MachineContext = 1
|
2268
|
+
$key.Create()
|
2269
|
+
$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
|
2270
|
+
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
|
2271
|
+
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
|
2272
|
+
$ekuoids.add($serverauthoid)
|
2273
|
+
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
|
2274
|
+
$ekuext.InitializeEncode($ekuoids)
|
2275
|
+
$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
|
2276
|
+
$cert.InitializeFromPrivateKey(2, $key, "")
|
2277
|
+
$cert.Subject = $name
|
2278
|
+
$cert.Issuer = $cert.Subject
|
2279
|
+
$cert.NotBefore = get-date
|
2280
|
+
$cert.NotAfter = $cert.NotBefore.AddYears(10)
|
2281
|
+
$cert.X509Extensions.Add($ekuext)
|
2282
|
+
$cert.Encode()
|
2283
|
+
$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
|
2284
|
+
$enrollment.InitializeFromRequest($cert)
|
2285
|
+
$certdata = $enrollment.CreateRequest(0)
|
2286
|
+
$enrollment.InstallResponse(2, $certdata, 0, "")
|
2287
|
+
|
2288
|
+
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
|
2289
|
+
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
|
2290
|
+
iex $create_listener_cmd
|
2291
|
+
netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Localport=5986 remoteport=any action=allow localip=any remoteip=any profile=any enable=yes
|
2292
|
+
</powershell>
|
2292
2293
|
EOH
|
2293
2294
|
end
|
2294
2295
|
|
@@ -2302,32 +2303,32 @@ netsh advfirewall firewall add rule name="WinRM HTTPS" protocol=TCP dir=in Local
|
|
2302
2303
|
context "when user has specified --no-create-ssl-listener along with his/her own user_data on cli" do
|
2303
2304
|
before do
|
2304
2305
|
knife_ec2_create.config[:create_ssl_listener] = false
|
2305
|
-
@user_user_data =
|
2306
|
-
File.open(@user_user_data,"w+") do |f|
|
2307
|
-
f.write
|
2308
|
-
<powershell>
|
2306
|
+
@user_user_data = "user_user_data.ps1"
|
2307
|
+
File.open(@user_user_data, "w+") do |f|
|
2308
|
+
f.write <<~EOH
|
2309
|
+
<powershell>
|
2309
2310
|
|
2310
|
-
Get-DscLocalConfigurationManager > c:\\dsc_data.txt
|
2311
|
+
Get-DscLocalConfigurationManager > c:\\dsc_data.txt
|
2311
2312
|
|
2312
|
-
</powershell>
|
2313
|
-
<script>
|
2313
|
+
</powershell>
|
2314
|
+
<script>
|
2314
2315
|
|
2315
|
-
ipconfig > c:\\ipconfig_data.txt
|
2316
|
+
ipconfig > c:\\ipconfig_data.txt
|
2316
2317
|
|
2317
|
-
</script>
|
2318
|
+
</script>
|
2318
2319
|
EOH
|
2319
2320
|
end
|
2320
|
-
@server_def_user_data =
|
2321
|
-
<powershell>
|
2321
|
+
@server_def_user_data = <<~EOH
|
2322
|
+
<powershell>
|
2322
2323
|
|
2323
|
-
Get-DscLocalConfigurationManager > c:\\dsc_data.txt
|
2324
|
+
Get-DscLocalConfigurationManager > c:\\dsc_data.txt
|
2324
2325
|
|
2325
|
-
</powershell>
|
2326
|
-
<script>
|
2326
|
+
</powershell>
|
2327
|
+
<script>
|
2327
2328
|
|
2328
|
-
ipconfig > c:\\ipconfig_data.txt
|
2329
|
+
ipconfig > c:\\ipconfig_data.txt
|
2329
2330
|
|
2330
|
-
</script>
|
2331
|
+
</script>
|
2331
2332
|
EOH
|
2332
2333
|
knife_ec2_create.config[:aws_user_data] = @user_user_data
|
2333
2334
|
end
|
@@ -2375,25 +2376,25 @@ ipconfig > c:\\ipconfig_data.txt
|
|
2375
2376
|
|
2376
2377
|
context "when user_data is supplied on cli" do
|
2377
2378
|
before do
|
2378
|
-
@user_user_data =
|
2379
|
-
File.open(@user_user_data,"w+") do |f|
|
2380
|
-
f.write
|
2381
|
-
<script>
|
2379
|
+
@user_user_data = "user_user_data.ps1"
|
2380
|
+
File.open(@user_user_data, "w+") do |f|
|
2381
|
+
f.write <<~EOH
|
2382
|
+
<script>
|
2382
2383
|
|
2383
|
-
ipconfig > c:\\ipconfig_data.txt
|
2384
|
-
netstat > c:\\netstat_data.txt
|
2384
|
+
ipconfig > c:\\ipconfig_data.txt
|
2385
|
+
netstat > c:\\netstat_data.txt
|
2385
2386
|
|
2386
|
-
</script>
|
2387
|
+
</script>
|
2387
2388
|
EOH
|
2388
2389
|
end
|
2389
2390
|
knife_ec2_create.config[:aws_user_data] = @user_user_data
|
2390
|
-
@server_def_user_data =
|
2391
|
-
<script>
|
2391
|
+
@server_def_user_data = <<~EOH
|
2392
|
+
<script>
|
2392
2393
|
|
2393
|
-
ipconfig > c:\\ipconfig_data.txt
|
2394
|
-
netstat > c:\\netstat_data.txt
|
2394
|
+
ipconfig > c:\\ipconfig_data.txt
|
2395
|
+
netstat > c:\\netstat_data.txt
|
2395
2396
|
|
2396
|
-
</script>
|
2397
|
+
</script>
|
2397
2398
|
EOH
|
2398
2399
|
end
|
2399
2400
|
|
@@ -2428,9 +2429,9 @@ netstat > c:\\netstat_data.txt
|
|
2428
2429
|
end
|
2429
2430
|
end
|
2430
2431
|
|
2431
|
-
describe
|
2432
|
-
context
|
2433
|
-
context
|
2432
|
+
describe "disable_api_termination option" do
|
2433
|
+
context "spot instance" do
|
2434
|
+
context "disable_api_termination is not passed on CLI or in knife config" do
|
2434
2435
|
before do
|
2435
2436
|
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
2436
2437
|
knife_ec2_create.config[:spot_price] = 0.001
|
@@ -2438,7 +2439,7 @@ netstat > c:\\netstat_data.txt
|
|
2438
2439
|
|
2439
2440
|
it "does not set disable_api_termination option in server_def" do
|
2440
2441
|
server_def = knife_ec2_create.create_server_def
|
2441
|
-
expect(server_def[:disable_api_termination]).to
|
2442
|
+
expect(server_def[:disable_api_termination]).to be_nil
|
2442
2443
|
end
|
2443
2444
|
|
2444
2445
|
it "does not raise error" do
|
@@ -2449,7 +2450,7 @@ netstat > c:\\netstat_data.txt
|
|
2449
2450
|
end
|
2450
2451
|
end
|
2451
2452
|
|
2452
|
-
context
|
2453
|
+
context "disable_api_termination is passed on CLI" do
|
2453
2454
|
before do
|
2454
2455
|
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
2455
2456
|
knife_ec2_create.config[:spot_price] = 0.001
|
@@ -2464,7 +2465,7 @@ netstat > c:\\netstat_data.txt
|
|
2464
2465
|
end
|
2465
2466
|
end
|
2466
2467
|
|
2467
|
-
context
|
2468
|
+
context "disable_api_termination is passed in knife config" do
|
2468
2469
|
before do
|
2469
2470
|
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
2470
2471
|
knife_ec2_create.config[:spot_price] = 0.001
|
@@ -2480,8 +2481,8 @@ netstat > c:\\netstat_data.txt
|
|
2480
2481
|
end
|
2481
2482
|
end
|
2482
2483
|
|
2483
|
-
context
|
2484
|
-
context
|
2484
|
+
context "non-spot instance" do
|
2485
|
+
context "when disable_api_termination option is not passed on the CLI or in the knife config" do
|
2485
2486
|
before do
|
2486
2487
|
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
2487
2488
|
end
|
@@ -2539,115 +2540,115 @@ netstat > c:\\netstat_data.txt
|
|
2539
2540
|
end
|
2540
2541
|
end
|
2541
2542
|
|
2542
|
-
describe
|
2543
|
+
describe "--security-group-ids option" do
|
2543
2544
|
before do
|
2544
2545
|
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
2545
2546
|
end
|
2546
2547
|
|
2547
|
-
context
|
2548
|
-
let(:ec2_server_create) { Chef::Knife::Ec2ServerCreate.new([
|
2549
|
-
it
|
2548
|
+
context "when comma seprated values are provided from cli" do
|
2549
|
+
let(:ec2_server_create) { Chef::Knife::Ec2ServerCreate.new(["--security-group-ids", "sg-aabbccdd,sg-3764sdss,sg-00aa11bb"]) }
|
2550
|
+
it "creates array of security group ids" do
|
2550
2551
|
server_def = ec2_server_create.create_server_def
|
2551
|
-
expect(server_def[:security_group_ids]).to eq([
|
2552
|
+
expect(server_def[:security_group_ids]).to eq(["sg-aabbccdd", "sg-3764sdss", "sg-00aa11bb"])
|
2552
2553
|
end
|
2553
2554
|
end
|
2554
2555
|
|
2555
|
-
context
|
2556
|
-
let(:ec2_server_create) { Chef::Knife::Ec2ServerCreate.new([
|
2557
|
-
it
|
2556
|
+
context "when mulitple values provided from cli for e.g. --security-group-ids sg-aab343ytr --security-group-ids sg-3764sdss" do
|
2557
|
+
let(:ec2_server_create) { Chef::Knife::Ec2ServerCreate.new(["--security-group-ids", "sg-aab343ytr", "--security-group-ids", "sg-3764sdss"]) }
|
2558
|
+
it "creates array of security group ids" do
|
2558
2559
|
server_def = ec2_server_create.create_server_def
|
2559
|
-
expect(server_def[:security_group_ids]).to eq([
|
2560
|
+
expect(server_def[:security_group_ids]).to eq(["sg-aab343ytr", "sg-3764sdss"])
|
2560
2561
|
end
|
2561
2562
|
end
|
2562
2563
|
|
2563
|
-
context
|
2564
|
-
it
|
2565
|
-
Chef::Config[:knife][:security_group_ids] =
|
2564
|
+
context "when comma seprated input is provided from knife.rb" do
|
2565
|
+
it "raises error" do
|
2566
|
+
Chef::Config[:knife][:security_group_ids] = "sg-aabbccdd, sg-3764sdss, sg-00aa11bb"
|
2566
2567
|
expect { knife_ec2_create.validate! }.to raise_error(SystemExit)
|
2567
2568
|
end
|
2568
2569
|
end
|
2569
2570
|
|
2570
|
-
context
|
2571
|
-
it
|
2572
|
-
Chef::Config[:knife][:security_group_ids] = [
|
2571
|
+
context "when security group ids array is provided from knife.rb" do
|
2572
|
+
it "allows --security-group-ids set from an array in knife.rb" do
|
2573
|
+
Chef::Config[:knife][:security_group_ids] = ["sg-aabbccdd", "sg-3764sdss", "sg-00aa11bb"]
|
2573
2574
|
expect { knife_ec2_create.validate! }.to_not raise_error(SystemExit)
|
2574
2575
|
end
|
2575
2576
|
end
|
2576
2577
|
end
|
2577
2578
|
|
2578
|
-
describe
|
2579
|
+
describe "--security-group-id option" do
|
2579
2580
|
before do
|
2580
2581
|
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
2581
2582
|
end
|
2582
2583
|
|
2583
|
-
context
|
2584
|
-
let(:ec2_server_create) { Chef::Knife::Ec2ServerCreate.new([
|
2585
|
-
it
|
2584
|
+
context "when mulitple values provided from cli for e.g. -g sg-aab343ytr -g sg-3764sdss" do
|
2585
|
+
let(:ec2_server_create) { Chef::Knife::Ec2ServerCreate.new(["-g", "sg-aab343ytr", "-g", "sg-3764sdss"]) }
|
2586
|
+
it "creates array of security group ids" do
|
2586
2587
|
server_def = ec2_server_create.create_server_def
|
2587
|
-
expect(server_def[:security_group_ids]).to eq([
|
2588
|
+
expect(server_def[:security_group_ids]).to eq(["sg-aab343ytr", "sg-3764sdss"])
|
2588
2589
|
end
|
2589
2590
|
end
|
2590
2591
|
|
2591
|
-
context
|
2592
|
-
let(:ec2_server_create) { Chef::Knife::Ec2ServerCreate.new([
|
2593
|
-
it
|
2592
|
+
context "when single value provided from cli for e.g. --security-group-id 3764sdss" do
|
2593
|
+
let(:ec2_server_create) { Chef::Knife::Ec2ServerCreate.new(["--security-group-id", "sg-aab343ytr"]) }
|
2594
|
+
it "creates array of security group ids" do
|
2594
2595
|
server_def = ec2_server_create.create_server_def
|
2595
|
-
expect(server_def[:security_group_ids]).to eq([
|
2596
|
+
expect(server_def[:security_group_ids]).to eq(["sg-aab343ytr"])
|
2596
2597
|
end
|
2597
2598
|
end
|
2598
2599
|
end
|
2599
2600
|
|
2600
|
-
describe
|
2601
|
+
describe "--chef-tag option" do
|
2601
2602
|
before do
|
2602
2603
|
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
2603
2604
|
end
|
2604
2605
|
|
2605
2606
|
context 'when mulitple values provided from cli for e.g. --chef-tag "foo" --chef-tag "bar"' do
|
2606
|
-
let(:ec2_server_create) { Chef::Knife::Ec2ServerCreate.new([
|
2607
|
-
it
|
2607
|
+
let(:ec2_server_create) { Chef::Knife::Ec2ServerCreate.new(["--chef-tag", "foo", "--chef-tag", "bar"]) }
|
2608
|
+
it "creates array of chef tag" do
|
2608
2609
|
server_def = ec2_server_create.create_server_def
|
2609
|
-
expect(server_def[:chef_tag]).to eq(
|
2610
|
+
expect(server_def[:chef_tag]).to eq(%w{foo bar})
|
2610
2611
|
end
|
2611
2612
|
end
|
2612
2613
|
|
2613
|
-
context
|
2614
|
-
let(:ec2_server_create) { Chef::Knife::Ec2ServerCreate.new([
|
2615
|
-
it
|
2614
|
+
context "when single value provided from cli for e.g. --chef-tag foo" do
|
2615
|
+
let(:ec2_server_create) { Chef::Knife::Ec2ServerCreate.new(["--chef-tag", "foo"]) }
|
2616
|
+
it "creates array of chef tag" do
|
2616
2617
|
server_def = ec2_server_create.create_server_def
|
2617
|
-
expect(server_def[:chef_tag]).to eq([
|
2618
|
+
expect(server_def[:chef_tag]).to eq(["foo"])
|
2618
2619
|
end
|
2619
2620
|
end
|
2620
2621
|
end
|
2621
2622
|
|
2622
|
-
describe
|
2623
|
+
describe "--aws-tag option" do
|
2623
2624
|
before do
|
2624
2625
|
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
2625
2626
|
end
|
2626
2627
|
|
2627
2628
|
context 'when mulitple values provided from cli for e.g. --aws-tag "foo=bar" --aws-tag "foo1=bar1"' do
|
2628
|
-
let(:ec2_server_create) { Chef::Knife::Ec2ServerCreate.new([
|
2629
|
-
it
|
2629
|
+
let(:ec2_server_create) { Chef::Knife::Ec2ServerCreate.new(["--aws-tag", "foo=bar", "--aws-tag", "foo1=bar1"]) }
|
2630
|
+
it "creates array of aws tag" do
|
2630
2631
|
server_def = ec2_server_create.config
|
2631
|
-
expect(server_def[:aws_tag]).to eq([
|
2632
|
+
expect(server_def[:aws_tag]).to eq(["foo=bar", "foo1=bar1"])
|
2632
2633
|
end
|
2633
2634
|
end
|
2634
2635
|
|
2635
|
-
context
|
2636
|
-
let(:ec2_server_create) { Chef::Knife::Ec2ServerCreate.new([
|
2637
|
-
it
|
2636
|
+
context "when single value provided from cli for e.g. --aws-tag foo=bar" do
|
2637
|
+
let(:ec2_server_create) { Chef::Knife::Ec2ServerCreate.new(["--aws-tag", "foo=bar"]) }
|
2638
|
+
it "creates array of aws tag" do
|
2638
2639
|
server_def = ec2_server_create.config
|
2639
|
-
expect(server_def[:aws_tag]).to eq([
|
2640
|
+
expect(server_def[:aws_tag]).to eq(["foo=bar"])
|
2640
2641
|
end
|
2641
2642
|
end
|
2642
2643
|
end
|
2643
2644
|
|
2644
|
-
describe
|
2645
|
+
describe "--tag-node-in-chef option" do
|
2645
2646
|
before do
|
2646
2647
|
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
2647
2648
|
end
|
2648
2649
|
|
2649
|
-
context
|
2650
|
-
let(:ec2_server_create) { Chef::Knife::Ec2ServerCreate.new([
|
2650
|
+
context "when provided from cli for e.g. --tag-node-in-chef" do
|
2651
|
+
let(:ec2_server_create) { Chef::Knife::Ec2ServerCreate.new(["--tag-node-in-chef"]) }
|
2651
2652
|
it 'raises deprecated warning "[DEPRECATED] --tag-node-in-chef option is deprecated. Use --chef-tag option instead."' do
|
2652
2653
|
expect(ec2_server_create.ui).to receive(:warn).with("[DEPRECATED] --tag-node-in-chef option is deprecated. Use --chef-tag option instead.")
|
2653
2654
|
ec2_server_create.validate!
|
@@ -2655,73 +2656,73 @@ netstat > c:\\netstat_data.txt
|
|
2655
2656
|
end
|
2656
2657
|
end
|
2657
2658
|
|
2658
|
-
describe
|
2659
|
+
describe "evaluate_node_name" do
|
2659
2660
|
before do
|
2660
2661
|
knife_ec2_create.instance_variable_set(:@server, server)
|
2661
2662
|
end
|
2662
2663
|
|
2663
|
-
context
|
2664
|
-
it
|
2664
|
+
context "when ec2 server attributes are not passed in node name" do
|
2665
|
+
it "returns the node name unchanged" do
|
2665
2666
|
expect(knife_ec2_create.evaluate_node_name("Test")).to eq("Test")
|
2666
2667
|
end
|
2667
2668
|
end
|
2668
2669
|
|
2669
|
-
|
2670
|
-
it
|
2670
|
+
context "when %s is passed in the node name" do
|
2671
|
+
it "returns evaluated node name" do
|
2671
2672
|
expect(knife_ec2_create.evaluate_node_name("Test-%s")).to eq("Test-i-123")
|
2672
2673
|
end
|
2673
2674
|
end
|
2674
2675
|
end
|
2675
2676
|
|
2676
|
-
describe
|
2677
|
+
describe "Handle password greater than 14 characters" do
|
2677
2678
|
before do
|
2678
2679
|
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
2679
2680
|
knife_ec2_create.config[:winrm_user] = "domain\\ec2"
|
2680
2681
|
knife_ec2_create.config[:winrm_password] = "LongPassword@123"
|
2681
2682
|
end
|
2682
2683
|
|
2683
|
-
|
2684
|
+
context "when user enters Y after prompt" do
|
2684
2685
|
before do
|
2685
|
-
allow(STDIN).to receive_message_chain(:gets, :
|
2686
|
+
allow(STDIN).to receive_message_chain(:gets, chomp: "Y")
|
2686
2687
|
end
|
2687
|
-
it
|
2688
|
-
expect(knife_ec2_create.ui).to receive(:warn).with(
|
2688
|
+
it "user addition command is executed forcefully" do
|
2689
|
+
expect(knife_ec2_create.ui).to receive(:warn).with("The password provided is longer than 14 characters. Computers with Windows prior to Windows 2000 will not be able to use this account. Do you want to continue this operation? (Y/N):")
|
2689
2690
|
knife_ec2_create.validate!
|
2690
2691
|
expect(knife_ec2_create.instance_variable_get(:@allow_long_password)).to eq ("/yes")
|
2691
2692
|
end
|
2692
2693
|
end
|
2693
2694
|
|
2694
|
-
context
|
2695
|
+
context "when user enters n after prompt" do
|
2695
2696
|
before do
|
2696
|
-
allow(STDIN).to receive_message_chain(:gets, :
|
2697
|
+
allow(STDIN).to receive_message_chain(:gets, chomp: "N")
|
2697
2698
|
end
|
2698
|
-
it
|
2699
|
-
expect(knife_ec2_create.ui).to receive(:warn).with(
|
2700
|
-
expect{ knife_ec2_create.validate! }.to raise_error("Exiting as operation with password greater than 14 characters not accepted")
|
2699
|
+
it "operation exits" do
|
2700
|
+
expect(knife_ec2_create.ui).to receive(:warn).with("The password provided is longer than 14 characters. Computers with Windows prior to Windows 2000 will not be able to use this account. Do you want to continue this operation? (Y/N):")
|
2701
|
+
expect { knife_ec2_create.validate! }.to raise_error("Exiting as operation with password greater than 14 characters not accepted")
|
2701
2702
|
end
|
2702
2703
|
end
|
2703
2704
|
|
2704
|
-
context
|
2705
|
+
context "when user enters xyz instead of (Y/N) after prompt" do
|
2705
2706
|
before do
|
2706
|
-
allow(STDIN).to receive_message_chain(:gets, :
|
2707
|
+
allow(STDIN).to receive_message_chain(:gets, chomp: "xyz")
|
2707
2708
|
end
|
2708
|
-
it
|
2709
|
-
expect(knife_ec2_create.ui).to receive(:warn).with(
|
2710
|
-
expect{ knife_ec2_create.validate! }.to raise_error("The input provided is incorrect.")
|
2709
|
+
it "operation exits" do
|
2710
|
+
expect(knife_ec2_create.ui).to receive(:warn).with("The password provided is longer than 14 characters. Computers with Windows prior to Windows 2000 will not be able to use this account. Do you want to continue this operation? (Y/N):")
|
2711
|
+
expect { knife_ec2_create.validate! }.to raise_error("The input provided is incorrect.")
|
2711
2712
|
end
|
2712
2713
|
end
|
2713
2714
|
|
2714
2715
|
end
|
2715
|
-
describe
|
2716
|
+
describe "--primary_eni option" do
|
2716
2717
|
before do
|
2717
2718
|
allow(Fog::Compute::AWS).to receive(:new).and_return(ec2_connection)
|
2718
2719
|
end
|
2719
2720
|
|
2720
|
-
context
|
2721
|
-
let(:ec2_server_create) { Chef::Knife::Ec2ServerCreate.new([
|
2722
|
-
it
|
2721
|
+
context "when a preexisting eni is specified eg. eni-12345678 use that eni for device index 0" do
|
2722
|
+
let(:ec2_server_create) { Chef::Knife::Ec2ServerCreate.new(["--primary-eni", "eni-12345678"]) }
|
2723
|
+
it "provides a network_interfaces list of hashes with on element for the primary interface" do
|
2723
2724
|
server_def = ec2_server_create.create_server_def
|
2724
|
-
expect(server_def[:network_interfaces]).to eq([{:
|
2725
|
+
expect(server_def[:network_interfaces]).to eq([{ NetworkInterfaceId: "eni-12345678", DeviceIndex: "0" }])
|
2725
2726
|
end
|
2726
2727
|
end
|
2727
2728
|
end
|