chef-provisioning-aws 1.0.4 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +18 -0
- data/Rakefile +5 -0
- data/lib/chef/provider/aws_ebs_volume.rb +14 -4
- data/lib/chef/provider/aws_image.rb +31 -0
- data/lib/chef/provider/aws_instance.rb +14 -0
- data/lib/chef/provider/aws_load_balancer.rb +9 -0
- data/lib/chef/provider/aws_network_interface.rb +209 -0
- data/lib/chef/provider/aws_security_group.rb +9 -4
- data/lib/chef/provider/aws_subnet.rb +16 -1
- data/lib/chef/provider/aws_vpc.rb +16 -0
- data/lib/chef/provisioning/aws_driver/aws_provider.rb +44 -0
- data/lib/chef/provisioning/aws_driver/aws_resource.rb +1 -1
- data/lib/chef/provisioning/aws_driver/driver.rb +6 -5
- data/lib/chef/provisioning/aws_driver/version.rb +1 -1
- data/lib/chef/resource/aws_image.rb +1 -2
- data/lib/chef/resource/aws_instance.rb +1 -2
- data/lib/chef/resource/aws_load_balancer.rb +1 -1
- data/lib/chef/resource/aws_network_interface.rb +23 -5
- data/lib/chef/resource/aws_vpc.rb +0 -8
- data/spec/aws_support.rb +235 -0
- data/spec/aws_support/aws_resource_run_wrapper.rb +45 -0
- data/spec/aws_support/deep_matcher.rb +40 -0
- data/spec/aws_support/deep_matcher/fuzzy_match_objects.rb +57 -0
- data/spec/aws_support/deep_matcher/match_values_failure_messages.rb +145 -0
- data/spec/aws_support/deep_matcher/matchable_array.rb +24 -0
- data/spec/aws_support/deep_matcher/matchable_object.rb +25 -0
- data/spec/aws_support/deep_matcher/rspec_monkeypatches.rb +25 -0
- data/spec/aws_support/delayed_stream.rb +41 -0
- data/spec/aws_support/matchers/create_an_aws_object.rb +60 -0
- data/spec/aws_support/matchers/update_an_aws_object.rb +66 -0
- data/spec/integration/aws_ebs_volume_spec.rb +31 -0
- data/spec/integration/aws_key_pair_spec.rb +21 -0
- data/spec/integration/aws_route_table_spec.rb +40 -0
- data/spec/integration/aws_security_group_spec.rb +7 -5
- data/spec/integration/aws_subnet_spec.rb +56 -0
- data/spec/integration/aws_vpc_spec.rb +109 -0
- data/spec/integration/machine_batch_spec.rb +36 -0
- data/spec/integration/machine_image_spec.rb +49 -0
- data/spec/integration/machine_spec.rb +64 -0
- data/spec/spec_helper.rb +8 -2
- data/spec/unit/aws_driver/credentials_spec.rb +54 -0
- metadata +27 -5
- data/spec/support/aws_support.rb +0 -211
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# Bring in the RSpec monkeypatch before we do *anything*, so that builtin matchers
|
2
|
+
# will get the module. Not strictly necessary, but cleaner that way.
|
3
|
+
require 'aws_support/deep_matcher/rspec_monkeypatches'
|
4
|
+
|
1
5
|
require 'chef/mixin/shell_out'
|
2
6
|
require 'chef/dsl/recipe'
|
3
7
|
require 'chef/provisioning'
|
@@ -5,17 +9,19 @@ require 'chef/provisioning/aws_driver'
|
|
5
9
|
require 'chef/platform'
|
6
10
|
require 'chef/run_context'
|
7
11
|
require 'chef/event_dispatch/dispatcher'
|
8
|
-
require '
|
12
|
+
require 'aws_support'
|
13
|
+
require 'rspec'
|
9
14
|
|
10
15
|
RSpec.configure do |rspec|
|
11
16
|
rspec.run_all_when_everything_filtered = true
|
12
17
|
rspec.filter_run :focus
|
18
|
+
rspec.filter_run_excluding :super_slow => true
|
13
19
|
# rspec.order = 'random'
|
14
20
|
rspec.expect_with(:rspec) { |c| c.syntax = :expect }
|
15
21
|
# rspec.before { allow($stdout).to receive(:write) }
|
16
22
|
end
|
17
23
|
|
18
24
|
#Chef::Log.level = :debug
|
25
|
+
Chef::Config[:log_level] = :warn
|
19
26
|
|
20
|
-
#AWS.stub!
|
21
27
|
require 'cheffish/rspec/matchers'
|
@@ -72,6 +72,28 @@ describe Chef::Provisioning::AWSDriver::Credentials do
|
|
72
72
|
@ini
|
73
73
|
end
|
74
74
|
|
75
|
+
let(:enterprise_config_ini_file) do
|
76
|
+
@ini ||= begin
|
77
|
+
ini = Tempfile.new('enterprise_config_ini')
|
78
|
+
ini.write(
|
79
|
+
['[profile enterprise]',
|
80
|
+
'region = us-west-2',
|
81
|
+
'aws_access_key_id = AKIAENTERPRISEKEY',
|
82
|
+
'aws_secret_access_key = enterprisesecretaccesskey',
|
83
|
+
'aws_session_token = MIIEpAIBAAKCAQEAth95Ci0sdvK222gG2wZEeBXZXeTIynOqJT1fcRnZ/dqVsoUm',
|
84
|
+
'proxy_uri = https://user:password@my.proxy:443/path?query',
|
85
|
+
'[profile work_iam]',
|
86
|
+
'region = us-east-1',
|
87
|
+
'aws_access_key_id = AKIAWORKIAMKEY',
|
88
|
+
'aws_secret_access_key = workiamsecretaccesskey'
|
89
|
+
].join("\n")
|
90
|
+
)
|
91
|
+
ini.rewind
|
92
|
+
ini
|
93
|
+
end
|
94
|
+
@ini
|
95
|
+
end
|
96
|
+
|
75
97
|
context 'unified config ini file' do
|
76
98
|
%w(work_iam personal).each do |profile|
|
77
99
|
it "loads the '#{profile}' profile from a unified config file" do
|
@@ -93,6 +115,37 @@ describe Chef::Provisioning::AWSDriver::Credentials do
|
|
93
115
|
end
|
94
116
|
end
|
95
117
|
|
118
|
+
context 'enterprise config ini file' do
|
119
|
+
let(:credentials) { described_class.new }
|
120
|
+
%w(work_iam enterprise).each do |profile|
|
121
|
+
it "loads the '#{profile}' profile from a enterprise config file" do
|
122
|
+
ENV['AWS_DEFAULT_PROFILE'] = profile
|
123
|
+
ENV['AWS_CREDENTIAL_FILE'] = nil
|
124
|
+
ENV['AWS_CONFIG_FILE'] = enterprise_config_ini_file.path
|
125
|
+
allow(File)
|
126
|
+
.to receive(:file?)
|
127
|
+
.with(File.expand_path('~/.aws/credentials'))
|
128
|
+
.and_return(false)
|
129
|
+
allow(File)
|
130
|
+
.to receive(:file?)
|
131
|
+
.with(File.expand_path(enterprise_config_ini_file.path))
|
132
|
+
.and_return(true)
|
133
|
+
|
134
|
+
if profile.eql?('enterprise')
|
135
|
+
expect(credentials[profile][:proxy_uri])
|
136
|
+
.to eq('https://user:password@my.proxy:443/path?query')
|
137
|
+
expect(credentials[profile][:aws_session_token])
|
138
|
+
.to eq('MIIEpAIBAAKCAQEAth95Ci0sdvK222gG2wZEeBXZXeTIynOqJT1fcRnZ/dqVsoUm')
|
139
|
+
else
|
140
|
+
expect(credentials[profile][:proxy_uri])
|
141
|
+
.to eq(nil)
|
142
|
+
expect(credentials[profile][:aws_session_token])
|
143
|
+
.to eq(nil)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
96
149
|
context 'separate config and credential ini files' do
|
97
150
|
%w(work_iam personal).each do |profile|
|
98
151
|
it "loads the '#{profile}' profile from a separate config files" do
|
@@ -105,5 +158,6 @@ describe Chef::Provisioning::AWSDriver::Credentials do
|
|
105
158
|
end
|
106
159
|
end
|
107
160
|
end
|
161
|
+
|
108
162
|
end
|
109
163
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-provisioning-aws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Ewart
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 1.59.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 1.59.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: retryable
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,8 +137,12 @@ files:
|
|
137
137
|
- lib/chef/provider/aws_dhcp_options.rb
|
138
138
|
- lib/chef/provider/aws_ebs_volume.rb
|
139
139
|
- lib/chef/provider/aws_eip_address.rb
|
140
|
+
- lib/chef/provider/aws_image.rb
|
141
|
+
- lib/chef/provider/aws_instance.rb
|
140
142
|
- lib/chef/provider/aws_key_pair.rb
|
141
143
|
- lib/chef/provider/aws_launch_configuration.rb
|
144
|
+
- lib/chef/provider/aws_load_balancer.rb
|
145
|
+
- lib/chef/provider/aws_network_interface.rb
|
142
146
|
- lib/chef/provider/aws_route_table.rb
|
143
147
|
- lib/chef/provider/aws_s3_bucket.rb
|
144
148
|
- lib/chef/provider/aws_security_group.rb
|
@@ -174,9 +178,27 @@ files:
|
|
174
178
|
- lib/chef/resource/aws_sqs_queue.rb
|
175
179
|
- lib/chef/resource/aws_subnet.rb
|
176
180
|
- lib/chef/resource/aws_vpc.rb
|
181
|
+
- spec/aws_support.rb
|
182
|
+
- spec/aws_support/aws_resource_run_wrapper.rb
|
183
|
+
- spec/aws_support/deep_matcher.rb
|
184
|
+
- spec/aws_support/deep_matcher/fuzzy_match_objects.rb
|
185
|
+
- spec/aws_support/deep_matcher/match_values_failure_messages.rb
|
186
|
+
- spec/aws_support/deep_matcher/matchable_array.rb
|
187
|
+
- spec/aws_support/deep_matcher/matchable_object.rb
|
188
|
+
- spec/aws_support/deep_matcher/rspec_monkeypatches.rb
|
189
|
+
- spec/aws_support/delayed_stream.rb
|
190
|
+
- spec/aws_support/matchers/create_an_aws_object.rb
|
191
|
+
- spec/aws_support/matchers/update_an_aws_object.rb
|
192
|
+
- spec/integration/aws_ebs_volume_spec.rb
|
193
|
+
- spec/integration/aws_key_pair_spec.rb
|
194
|
+
- spec/integration/aws_route_table_spec.rb
|
177
195
|
- spec/integration/aws_security_group_spec.rb
|
196
|
+
- spec/integration/aws_subnet_spec.rb
|
197
|
+
- spec/integration/aws_vpc_spec.rb
|
198
|
+
- spec/integration/machine_batch_spec.rb
|
199
|
+
- spec/integration/machine_image_spec.rb
|
200
|
+
- spec/integration/machine_spec.rb
|
178
201
|
- spec/spec_helper.rb
|
179
|
-
- spec/support/aws_support.rb
|
180
202
|
- spec/unit/aws_driver/credentials_spec.rb
|
181
203
|
homepage: https://github.com/opscode/chef-provisioning-aws
|
182
204
|
licenses: []
|
data/spec/support/aws_support.rb
DELETED
@@ -1,211 +0,0 @@
|
|
1
|
-
require 'cheffish/rspec/chef_run_support'
|
2
|
-
require 'cheffish/rspec/recipe_run_wrapper'
|
3
|
-
require 'chef/provisioning/aws_driver'
|
4
|
-
|
5
|
-
module AWSSupport
|
6
|
-
def self.extended(other)
|
7
|
-
other.extend Cheffish::RSpec::ChefRunSupport
|
8
|
-
end
|
9
|
-
|
10
|
-
def with_aws(description, *tags, &block)
|
11
|
-
if ENV['AWS_TEST_DRIVER']
|
12
|
-
aws_driver = Chef::Provisioning.driver_for_url(ENV['AWS_TEST_DRIVER'])
|
13
|
-
else
|
14
|
-
tags << { skip: "AWS_TEST_DRIVER not set ... cannot run AWS test. Set AWS_TEST_DRIVER=aws or aws:profile:region to run tests that hit AWS" }
|
15
|
-
end
|
16
|
-
|
17
|
-
context description, *tags do
|
18
|
-
extend WithAWSClassMethods
|
19
|
-
include WithAWSInstanceMethods
|
20
|
-
|
21
|
-
@@driver = aws_driver
|
22
|
-
def self.driver
|
23
|
-
@@driver
|
24
|
-
end
|
25
|
-
|
26
|
-
module_eval(&block)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
module WithAWSClassMethods
|
31
|
-
def chef_config
|
32
|
-
{ driver: driver }
|
33
|
-
end
|
34
|
-
|
35
|
-
instance_eval do
|
36
|
-
#
|
37
|
-
# Create a context-level method for each AWS resource:
|
38
|
-
#
|
39
|
-
# with_aws do
|
40
|
-
# context 'mycontext' do
|
41
|
-
# aws_vpc 'myvpc' do
|
42
|
-
# ...
|
43
|
-
# end
|
44
|
-
# end
|
45
|
-
# end
|
46
|
-
#
|
47
|
-
# Creates the AWS thing when the first example in the context runs.
|
48
|
-
# Destroys it after the last example in the context runs. Objects created
|
49
|
-
# in the order declared, and destroyed in reverse order.
|
50
|
-
#
|
51
|
-
Chef::Provisioning::AWSDriver::Resources.constants.each do |resource_class|
|
52
|
-
resource_class = Chef::Provisioning::AWSDriver::Resources.const_get(resource_class)
|
53
|
-
# def aws_vpc(name, &block)
|
54
|
-
define_method(resource_class.resource_name) do |name, &block|
|
55
|
-
# def myvpc
|
56
|
-
# @@myvpc
|
57
|
-
# end
|
58
|
-
instance_eval do
|
59
|
-
define_method(name) { class_variable_get(:"@@#{name}") }
|
60
|
-
end
|
61
|
-
module_eval do
|
62
|
-
define_method(name) { self.class.class_variable_get(:"@@#{name}") }
|
63
|
-
end
|
64
|
-
|
65
|
-
resource = nil
|
66
|
-
|
67
|
-
before :context do
|
68
|
-
resource = AWSResourceRunWrapper.new(self, resource_class.resource_name, name, &block)
|
69
|
-
# @myvpc = resource
|
70
|
-
begin
|
71
|
-
self.class.class_variable_set(:"@@#{name}", resource.resource)
|
72
|
-
rescue NameError
|
73
|
-
end
|
74
|
-
resource.converge
|
75
|
-
end
|
76
|
-
|
77
|
-
after :context do
|
78
|
-
resource.destroy if resource
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
module WithAWSInstanceMethods
|
86
|
-
def self.included(context)
|
87
|
-
context.module_eval do
|
88
|
-
# Destroy any objects we know got created during the test
|
89
|
-
after :example do
|
90
|
-
created_during_test.reverse_each do |resource_name, name|
|
91
|
-
(recipe do
|
92
|
-
public_send(resource_name, name) do
|
93
|
-
action :destroy
|
94
|
-
end
|
95
|
-
end).converge
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def chef_config
|
102
|
-
{ driver: driver }
|
103
|
-
end
|
104
|
-
|
105
|
-
def created_during_test
|
106
|
-
@created_during_test ||= []
|
107
|
-
end
|
108
|
-
|
109
|
-
def default_vpc
|
110
|
-
@default_vpc ||= driver.ec2.vpcs.filter('isDefault', 'true').first
|
111
|
-
end
|
112
|
-
|
113
|
-
def driver
|
114
|
-
self.class.driver
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
class AWSResourceRunWrapper < Cheffish::RSpec::RecipeRunWrapper
|
119
|
-
def initialize(rspec_context, resource_type, name, &properties)
|
120
|
-
super(rspec_context.chef_config) do
|
121
|
-
public_send(resource_type, name, &properties)
|
122
|
-
end
|
123
|
-
@rspec_context = rspec_context
|
124
|
-
@resource_type = resource_type
|
125
|
-
@name = name
|
126
|
-
@properties = properties
|
127
|
-
end
|
128
|
-
|
129
|
-
attr_reader :rspec_context
|
130
|
-
attr_reader :resource_type
|
131
|
-
attr_reader :name
|
132
|
-
|
133
|
-
def resource
|
134
|
-
resources.first
|
135
|
-
end
|
136
|
-
|
137
|
-
def to_s
|
138
|
-
"#{resource_type}[#{name}]"
|
139
|
-
end
|
140
|
-
|
141
|
-
def destroy
|
142
|
-
resource_type = self.resource_type
|
143
|
-
name = self.name
|
144
|
-
rspec_context.run_recipe do
|
145
|
-
public_send(resource_type, name) do
|
146
|
-
action :destroy
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
def aws_object
|
152
|
-
resource.aws_object
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
|
158
|
-
#
|
159
|
-
# Matchers for:
|
160
|
-
#
|
161
|
-
# - create_an_aws_security_group
|
162
|
-
# - create_an_aws_vpc
|
163
|
-
# etc.
|
164
|
-
#
|
165
|
-
# Checks if the object got created, then deletes the object at the end of the test.
|
166
|
-
#
|
167
|
-
Chef::Provisioning::AWSDriver::Resources.constants.each do |resource_class|
|
168
|
-
resource_class = Chef::Provisioning::AWSDriver::Resources.const_get(resource_class)
|
169
|
-
|
170
|
-
RSpec::Matchers.define :"create_an_#{resource_class.resource_name}" do |name, expected_properties|
|
171
|
-
match do |recipe|
|
172
|
-
@recipe = recipe
|
173
|
-
|
174
|
-
# Converge
|
175
|
-
recipe.converge
|
176
|
-
expect(recipe).to be_updated
|
177
|
-
|
178
|
-
resource = resource_class.new(name, nil)
|
179
|
-
resource.driver driver
|
180
|
-
resource.managed_entry_store Chef::Provisioning.chef_managed_entry_store
|
181
|
-
aws_object = resource.aws_object
|
182
|
-
|
183
|
-
# Check existence and properties
|
184
|
-
if aws_object.nil?
|
185
|
-
raise "#{resource.to_s} succeeded but was not created!"
|
186
|
-
end
|
187
|
-
|
188
|
-
created_during_test << [ resource_class.resource_name, name ]
|
189
|
-
|
190
|
-
# Check to see if properties have the expected values
|
191
|
-
@differences = {}
|
192
|
-
expected_properties.each do |name, value|
|
193
|
-
aws_value = aws_object.public_send(name)
|
194
|
-
if !(aws_value === expected_properties[name])
|
195
|
-
@differences[name] = aws_value
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
@differences.empty?
|
200
|
-
end
|
201
|
-
|
202
|
-
failure_message {
|
203
|
-
message = "#{@recipe} created an AWS object with unexpected values:\n"
|
204
|
-
@differences.each do |name, value|
|
205
|
-
message << "- expected #{name} to match #{expected_properties[name].inspect}, but the actual value was #{value.inspect}\n"
|
206
|
-
end
|
207
|
-
message << @recipe.output_for_failure_message
|
208
|
-
message
|
209
|
-
}
|
210
|
-
end
|
211
|
-
end
|