knife-ec2 0.11.0.rc.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.travis.yml +5 -1
- data/CHANGELOG.md +3 -2
- data/DOC_CHANGES.md +17 -4
- data/README.md +30 -15
- data/RELEASE_NOTES.md +1 -1
- data/Rakefile +6 -7
- data/knife-ec2.gemspec +8 -10
- data/lib/chef/knife/ec2_base.rb +6 -0
- data/lib/chef/knife/ec2_server_create.rb +162 -28
- data/lib/chef/knife/ec2_server_delete.rb +17 -16
- data/lib/chef/knife/s3_source.rb +12 -2
- data/lib/knife-ec2/version.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/ec2_server_create_spec.rb +437 -235
- data/spec/unit/ec2_server_delete_spec.rb +45 -43
- data/spec/unit/s3_source_spec.rb +40 -18
- metadata +16 -29
@@ -25,7 +25,7 @@ describe Chef::Knife::Ec2ServerDelete do
|
|
25
25
|
before(:each) do
|
26
26
|
{
|
27
27
|
:image => 'image',
|
28
|
-
:
|
28
|
+
:ssh_key_name => 'ssh_key_name',
|
29
29
|
:aws_access_key_id => 'aws_access_key_id',
|
30
30
|
:aws_secret_access_key => 'aws_secret_access_key'
|
31
31
|
}.each do |key, value|
|
@@ -40,98 +40,100 @@ describe Chef::Knife::Ec2ServerDelete do
|
|
40
40
|
:groups => ['group1', 'group2'],
|
41
41
|
:security_group_ids => ['sg-00aa11bb'],
|
42
42
|
:dns_name => 'ec2-75.101.253.10.compute-1.amazonaws.com',
|
43
|
-
:iam_instance_profile => {},
|
43
|
+
:iam_instance_profile => {},
|
44
44
|
:public_ip_address => '75.101.253.10',
|
45
45
|
:private_dns_name => 'ip-10-251-75-20.ec2.internal',
|
46
46
|
:private_ip_address => '10.251.75.20',
|
47
|
-
:root_device_type => 'not_ebs'
|
47
|
+
:root_device_type => 'not_ebs',
|
48
|
+
:tags => {'Name' => 'foo'}
|
49
|
+
}
|
48
50
|
@knife_ec2_delete = Chef::Knife::Ec2ServerDelete.new
|
49
51
|
@ec2_servers = double()
|
50
|
-
@knife_ec2_delete.ui.
|
51
|
-
@knife_ec2_delete.
|
52
|
+
allow(@knife_ec2_delete.ui).to receive(:confirm)
|
53
|
+
allow(@knife_ec2_delete).to receive(:msg_pair)
|
52
54
|
@ec2_server = double(@ec2_server_attribs)
|
53
55
|
@ec2_connection = double(Fog::Compute::AWS)
|
54
|
-
@ec2_connection.
|
55
|
-
@knife_ec2_delete.ui.
|
56
|
+
allow(@ec2_connection).to receive(:servers).and_return(@ec2_servers)
|
57
|
+
allow(@knife_ec2_delete.ui).to receive(:warn)
|
56
58
|
end
|
57
59
|
|
58
60
|
it "should invoke validate!" do
|
59
61
|
knife_ec2_delete = Chef::Knife::Ec2ServerDelete.new
|
60
|
-
knife_ec2_delete.
|
62
|
+
expect(knife_ec2_delete).to receive(:validate!)
|
61
63
|
knife_ec2_delete.run
|
62
64
|
end
|
63
65
|
|
64
66
|
it "should use invoke fog api to delete instance if instance id is passed" do
|
65
|
-
@ec2_servers.
|
66
|
-
Fog::Compute::AWS.
|
67
|
+
expect(@ec2_servers).to receive(:get).with('foo').and_return(@ec2_server)
|
68
|
+
expect(Fog::Compute::AWS).to receive(:new).and_return(@ec2_connection)
|
67
69
|
@knife_ec2_delete.name_args = ['foo']
|
68
|
-
@knife_ec2_delete.
|
69
|
-
@ec2_server.
|
70
|
+
expect(@knife_ec2_delete).to receive(:validate!)
|
71
|
+
expect(@ec2_server).to receive(:destroy)
|
70
72
|
@knife_ec2_delete.run
|
71
73
|
end
|
72
74
|
|
73
75
|
it "should use node_name to figure out instance id if not specified explicitly" do
|
74
|
-
@ec2_servers.
|
75
|
-
Fog::Compute::AWS.
|
76
|
-
@knife_ec2_delete.
|
77
|
-
@ec2_server.
|
76
|
+
expect(@ec2_servers).to receive(:get).with('foo').and_return(@ec2_server)
|
77
|
+
expect(Fog::Compute::AWS).to receive(:new).and_return(@ec2_connection)
|
78
|
+
expect(@knife_ec2_delete).to receive(:validate!)
|
79
|
+
expect(@ec2_server).to receive(:destroy)
|
78
80
|
@knife_ec2_delete.config[:purge] = false
|
79
81
|
@knife_ec2_delete.config[:chef_node_name] = 'baz'
|
80
82
|
double_node = double(Chef::Node)
|
81
|
-
double_node.
|
82
|
-
double_node.
|
83
|
+
expect(double_node).to receive(:attribute?).with('ec2').and_return(true)
|
84
|
+
expect(double_node).to receive(:[]).with('ec2').and_return('instance_id'=>'foo')
|
83
85
|
double_search = double(Chef::Search::Query)
|
84
|
-
double_search.
|
85
|
-
Chef::Search::Query.
|
86
|
+
expect(double_search).to receive(:search).with(:node,"name:baz").and_return([[double_node],nil,nil])
|
87
|
+
expect(Chef::Search::Query).to receive(:new).and_return(double_search)
|
86
88
|
@knife_ec2_delete.name_args = []
|
87
89
|
@knife_ec2_delete.run
|
88
90
|
end
|
89
91
|
|
90
92
|
describe "when --purge is passed" do
|
91
93
|
it "should use the node name if its set" do
|
92
|
-
@ec2_servers.
|
93
|
-
Fog::Compute::AWS.
|
94
|
+
expect(@ec2_servers).to receive(:get).with('foo').and_return(@ec2_server)
|
95
|
+
expect(Fog::Compute::AWS).to receive(:new).and_return(@ec2_connection)
|
94
96
|
@knife_ec2_delete.name_args = ['foo']
|
95
|
-
@knife_ec2_delete.
|
96
|
-
@ec2_server.
|
97
|
+
expect(@knife_ec2_delete).to receive(:validate!)
|
98
|
+
expect(@ec2_server).to receive(:destroy)
|
97
99
|
@knife_ec2_delete.config[:purge] = true
|
98
100
|
@knife_ec2_delete.config[:chef_node_name] = 'baz'
|
99
|
-
Chef::Node.
|
100
|
-
Chef::ApiClient.
|
101
|
+
expect(Chef::Node).to receive(:load).with('baz').and_return(double(:destroy=>true))
|
102
|
+
expect(Chef::ApiClient).to receive(:load).with('baz').and_return(double(:destroy=>true))
|
101
103
|
@knife_ec2_delete.run
|
102
104
|
end
|
103
105
|
|
104
106
|
it "should search for the node name using the instance id when node name is not specified" do
|
105
|
-
@ec2_servers.
|
106
|
-
Fog::Compute::AWS.
|
107
|
+
expect(@ec2_servers).to receive(:get).with('i-foo').and_return(@ec2_server)
|
108
|
+
expect(Fog::Compute::AWS).to receive(:new).and_return(@ec2_connection)
|
107
109
|
@knife_ec2_delete.name_args = ['i-foo']
|
108
|
-
@knife_ec2_delete.
|
109
|
-
@ec2_server.
|
110
|
+
expect(@knife_ec2_delete).to receive(:validate!)
|
111
|
+
expect(@ec2_server).to receive(:destroy)
|
110
112
|
@knife_ec2_delete.config[:purge] = true
|
111
113
|
@knife_ec2_delete.config[:chef_node_name] = nil
|
112
114
|
double_search = double(Chef::Search::Query)
|
113
115
|
double_node = double(Chef::Node)
|
114
|
-
double_node.
|
115
|
-
Chef::Node.
|
116
|
-
Chef::ApiClient.
|
117
|
-
double_search.
|
118
|
-
Chef::Search::Query.
|
116
|
+
expect(double_node).to receive(:name).and_return("baz")
|
117
|
+
expect(Chef::Node).to receive(:load).with('baz').and_return(double(:destroy=>true))
|
118
|
+
expect(Chef::ApiClient).to receive(:load).with('baz').and_return(double(:destroy=>true))
|
119
|
+
expect(double_search).to receive(:search).with(:node,"ec2_instance_id:i-foo").and_return([[double_node],nil,nil])
|
120
|
+
expect(Chef::Search::Query).to receive(:new).and_return(double_search)
|
119
121
|
@knife_ec2_delete.run
|
120
122
|
end
|
121
123
|
|
122
124
|
it "should use the instance id if search does not return anything" do
|
123
|
-
@ec2_servers.
|
124
|
-
Fog::Compute::AWS.
|
125
|
+
expect(@ec2_servers).to receive(:get).with('i-foo').and_return(@ec2_server)
|
126
|
+
expect(Fog::Compute::AWS).to receive(:new).and_return(@ec2_connection)
|
125
127
|
@knife_ec2_delete.name_args = ['i-foo']
|
126
|
-
@knife_ec2_delete.
|
127
|
-
@ec2_server.
|
128
|
+
expect(@knife_ec2_delete).to receive(:validate!)
|
129
|
+
expect(@ec2_server).to receive(:destroy)
|
128
130
|
@knife_ec2_delete.config[:purge] = true
|
129
131
|
@knife_ec2_delete.config[:chef_node_name] = nil
|
130
|
-
Chef::Node.
|
131
|
-
Chef::ApiClient.
|
132
|
+
expect(Chef::Node).to receive(:load).with('i-foo').and_return(double(:destroy=>true))
|
133
|
+
expect(Chef::ApiClient).to receive(:load).with('i-foo').and_return(double(:destroy=>true))
|
132
134
|
double_search = double(Chef::Search::Query)
|
133
|
-
double_search.
|
134
|
-
Chef::Search::Query.
|
135
|
+
expect(double_search).to receive(:search).with(:node,"ec2_instance_id:i-foo").and_return([[],nil,nil])
|
136
|
+
expect(Chef::Search::Query).to receive(:new).and_return(double_search)
|
135
137
|
@knife_ec2_delete.run
|
136
138
|
end
|
137
139
|
end
|
data/spec/unit/s3_source_spec.rb
CHANGED
@@ -3,8 +3,8 @@ require 'fog'
|
|
3
3
|
|
4
4
|
describe Chef::Knife::S3Source do
|
5
5
|
before(:each) do
|
6
|
-
@bucket_name = '
|
7
|
-
@test_file_path = 'path/
|
6
|
+
@bucket_name = 'mybucket'
|
7
|
+
@test_file_path = 'path/file.pem'
|
8
8
|
@test_file_content = "TEST CONTENT\n"
|
9
9
|
|
10
10
|
Fog.mock!
|
@@ -27,27 +27,49 @@ describe Chef::Knife::S3Source do
|
|
27
27
|
|
28
28
|
@s3_connection = double(Fog::Storage::AWS)
|
29
29
|
@s3_source = Chef::Knife::S3Source.new
|
30
|
-
|
31
|
-
@s3_source.url = "s3://#{@bucket_name}/#{@test_file_path}"
|
32
30
|
end
|
33
31
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
context "for http URL format" do
|
33
|
+
it 'converts URI to path with leading / removed' do
|
34
|
+
@s3_source.url = "http://s3.amazonaws.com/#{@bucket_name}/#{@test_file_path}"
|
35
|
+
@s3_source.instance_eval { path }
|
36
|
+
expect(@s3_source.instance_eval { path }).to eq(@test_file_path)
|
37
|
+
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
it 'correctly retrieves the bucket name from the URI' do
|
40
|
+
@s3_source.url = "http://s3.amazonaws.com/#{@bucket_name}/#{@test_file_path}"
|
41
|
+
@s3_source.instance_eval { bucket }
|
42
|
+
expect(@s3_source.instance_eval { bucket }).to eq(@bucket_name)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'gets back the correct bucket contents' do
|
46
|
+
@s3_source.url = "http://s3.amazonaws.com/#{@bucket_name}/#{@test_file_path}"
|
47
|
+
expect(@s3_source.body).to eq(@test_file_content)
|
48
|
+
end
|
43
49
|
|
44
|
-
|
45
|
-
|
50
|
+
it 'gets back a bucket object with bucket_obj' do
|
51
|
+
@s3_source.url = "http://s3.amazonaws.com/#{@bucket_name}/#{@test_file_path}"
|
52
|
+
@s3_source.instance_eval { bucket_obj }
|
53
|
+
expect(@s3_source.instance_eval { bucket_obj }).to be_kind_of(Fog::Storage::AWS::Directory)
|
54
|
+
end
|
46
55
|
end
|
47
56
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
57
|
+
context "for s3 URL format" do
|
58
|
+
it 'correctly retrieves the bucket name from the URI' do
|
59
|
+
@s3_source.url = "s3://#{@bucket_name}/#{@test_file_path}"
|
60
|
+
@s3_source.instance_eval { bucket }
|
61
|
+
expect(@s3_source.instance_eval { bucket }).to eq(@bucket_name)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'gets back the correct bucket contents' do
|
65
|
+
@s3_source.url = "s3://#{@bucket_name}/#{@test_file_path}"
|
66
|
+
expect(@s3_source.body).to eq(@test_file_content)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'gets back a bucket object with bucket_obj' do
|
70
|
+
@s3_source.url = "s3://#{@bucket_name}/#{@test_file_path}"
|
71
|
+
@s3_source.instance_eval { bucket_obj }
|
72
|
+
expect(@s3_source.instance_eval { bucket_obj }).to be_kind_of(Fog::Storage::AWS::Directory)
|
73
|
+
end
|
52
74
|
end
|
53
75
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-ec2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.0
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Jacob
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-08-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fog
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 1.
|
20
|
+
version: 1.29.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 1.
|
27
|
+
version: 1.29.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: knife-windows
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -40,53 +40,39 @@ dependencies:
|
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: 0.8.2
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
|
-
name:
|
43
|
+
name: chef
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
49
|
-
type: :development
|
50
|
-
prerelease: false
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - "~>"
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: '2.0'
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
|
-
name: chef
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
48
|
+
version: '12.0'
|
60
49
|
- - ">="
|
61
50
|
- !ruby/object:Gem::Version
|
62
|
-
version:
|
63
|
-
- - "<"
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
version: '12'
|
51
|
+
version: 12.2.1
|
66
52
|
type: :development
|
67
53
|
prerelease: false
|
68
54
|
version_requirements: !ruby/object:Gem::Requirement
|
69
55
|
requirements:
|
70
|
-
- - "
|
56
|
+
- - "~>"
|
71
57
|
- !ruby/object:Gem::Version
|
72
|
-
version:
|
73
|
-
- - "
|
58
|
+
version: '12.0'
|
59
|
+
- - ">="
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
61
|
+
version: 12.2.1
|
76
62
|
- !ruby/object:Gem::Dependency
|
77
63
|
name: rspec
|
78
64
|
requirement: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
66
|
- - "~>"
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
68
|
+
version: '3.0'
|
83
69
|
type: :development
|
84
70
|
prerelease: false
|
85
71
|
version_requirements: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
73
|
- - "~>"
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
75
|
+
version: '3.0'
|
90
76
|
- !ruby/object:Gem::Dependency
|
91
77
|
name: rake
|
92
78
|
requirement: !ruby/object:Gem::Requirement
|
@@ -162,9 +148,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
162
148
|
version: '0'
|
163
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
150
|
requirements:
|
165
|
-
- - "
|
151
|
+
- - ">="
|
166
152
|
- !ruby/object:Gem::Version
|
167
|
-
version:
|
153
|
+
version: '0'
|
168
154
|
requirements: []
|
169
155
|
rubyforge_project:
|
170
156
|
rubygems_version: 2.4.4
|
@@ -177,3 +163,4 @@ test_files:
|
|
177
163
|
- spec/unit/ec2_server_delete_spec.rb
|
178
164
|
- spec/unit/s3_source_deps_spec.rb
|
179
165
|
- spec/unit/s3_source_spec.rb
|
166
|
+
has_rdoc:
|