chef-provisioning-aws 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66de7d20ac16f1c99866f9d4195f38586bfb667d
4
- data.tar.gz: 5cbae8b8fcc08af3538333bbf6bc29c96beb0f22
3
+ metadata.gz: 9a8ee86c530dd398dad4b925b119b8d88db9f55a
4
+ data.tar.gz: 367430b7e0cdee74064297461617a9545c9c1aa1
5
5
  SHA512:
6
- metadata.gz: 36907c00f23caf788569f528f6b12ad64afb4c316f02794dd05927c06e234b7271257d7d83c85f517c7bb370928507fe2616bb9379e5b161e48cdce50dc3fed6
7
- data.tar.gz: 616a2bcd0b104326714aa001462f042eedec30d06825b5e9556b6e326a03037833ddd4d79879183bd4b20a7335272140f253be91b380817acf4a2b13c4c298ae
6
+ metadata.gz: 76da770b34ea861319e125e2125aee36d61b2ce47ed333a26aceae6939576c5f498d054b9f84eff7f1ad46b7d7ca61e6f5cbb5c236742dd761697b8b25eb50f1
7
+ data.tar.gz: b0c8b49ae247b81214853e172b417c77ed40928da2903f6a4b79085bac2fb4cd91f108a827a9059d60259daa712b2084be4414dcd5202f1d37f1ce4649e98339
@@ -1,6 +1,10 @@
1
1
  require 'chef/provisioning/aws_driver/aws_provider'
2
2
 
3
3
  class Chef::Provider::AwsInstance < Chef::Provisioning::AWSDriver::AWSProvider
4
+ def create_aws_object(instance); end
5
+
6
+ def update_aws_object(instance); end
7
+
4
8
  def destroy_aws_object(instance)
5
9
  converge_by "delete instance #{new_resource} in VPC #{instance.vpc.id} in #{region}" do
6
10
  instance.delete
@@ -90,10 +90,10 @@ module AWSDriver
90
90
  actual_elb = elb.load_balancers.create(lb_spec.name, lb_options)
91
91
 
92
92
  lb_spec.reference = {
93
- 'driver_url' => driver_url,
94
93
  'driver_version' => Chef::Provisioning::AWSDriver::VERSION,
95
94
  'allocated_at' => Time.now.utc.to_s,
96
95
  }
96
+ lb_spec.driver_url = driver_url
97
97
  end
98
98
  else
99
99
  # Header gets printed the first time we make an update
@@ -335,11 +335,11 @@ module AWSDriver
335
335
  image = ec2.images.create(image_options.to_hash)
336
336
  image.add_tag('From-Instance', :value => image_options[:instance_id]) if image_options[:instance_id]
337
337
  image_spec.reference = {
338
- 'driver_url' => driver_url,
339
338
  'driver_version' => Chef::Provisioning::AWSDriver::VERSION,
340
339
  'image_id' => image.id,
341
340
  'allocated_at' => Time.now.to_i
342
341
  }
342
+ image_spec.driver_url = driver_url
343
343
  end
344
344
  end
345
345
  end
@@ -414,14 +414,15 @@ EOD
414
414
  sleep 5 while instance.status == :pending
415
415
  # TODO add other tags identifying user / node url (same as fog)
416
416
  instance.tags['Name'] = machine_spec.name
417
+ instance.source_dest_check = machine_options[:source_dest_check] if machine_options.has_key?(:source_dest_check)
417
418
  machine_spec.reference = {
418
- 'driver_url' => driver_url,
419
419
  'driver_version' => Chef::Provisioning::AWSDriver::VERSION,
420
420
  'allocated_at' => Time.now.utc.to_s,
421
421
  'host_node' => action_handler.host_node,
422
422
  'image_id' => bootstrap_options[:image_id],
423
423
  'instance_id' => instance.id
424
424
  }
425
+ machine_spec.driver_url = driver_url
425
426
  machine_spec.reference['key_name'] = bootstrap_options[:key_name] if bootstrap_options[:key_name]
426
427
  %w(is_windows ssh_username sudo use_private_ip_for_ssh ssh_gateway).each do |key|
427
428
  machine_spec.reference[key] = machine_options[key.to_sym] if machine_options[key.to_sym]
@@ -602,8 +603,8 @@ EOD
602
603
 
603
604
  def instance_for(machine_spec)
604
605
  if machine_spec.reference
605
- if machine_spec.reference['driver_url'] != driver_url
606
- raise "Switching a machine's driver from #{machine_spec.reference['driver_url']} to #{driver_url} is not currently supported! Use machine :destroy and then re-create the machine on the new driver."
606
+ if machine_spec.driver_url != driver_url
607
+ raise "Switching a machine's driver from #{machine_spec.driver_url} to #{driver_url} is not currently supported! Use machine :destroy and then re-create the machine on the new driver."
607
608
  end
608
609
  Chef::Resource::AwsInstance.get_aws_object(machine_spec.reference['instance_id'], driver: self, managed_entry_store: machine_spec.managed_entry_store, required: false)
609
610
  end
@@ -941,14 +942,15 @@ EOD
941
942
  machine_spec = machine_specs.pop
942
943
  machine_options = specs_and_options[machine_spec]
943
944
  machine_spec.reference = {
944
- 'driver_url' => driver_url,
945
945
  'driver_version' => Chef::Provisioning::AWSDriver::VERSION,
946
946
  'allocated_at' => Time.now.utc.to_s,
947
947
  'host_node' => action_handler.host_node,
948
948
  'image_id' => bootstrap_options[:image_id],
949
949
  'instance_id' => instance.id
950
950
  }
951
+ machine_spec.driver_url = driver_url
951
952
  instance.tags['Name'] = machine_spec.name
953
+ instance.source_dest_check = machine_options[:source_dest_check] if machine_options.has_key?(:source_dest_check)
952
954
  machine_spec.reference['key_name'] = bootstrap_options[:key_name] if bootstrap_options[:key_name]
953
955
  %w(is_windows ssh_username sudo use_private_ip_for_ssh ssh_gateway).each do |key|
954
956
  machine_spec.reference[key] = machine_options[key.to_sym] if machine_options[key.to_sym]
@@ -1,7 +1,7 @@
1
1
  class Chef
2
2
  module Provisioning
3
3
  module AWSDriver
4
- VERSION = '1.1.0'
4
+ VERSION = '1.1.1'
5
5
  end
6
6
  end
7
7
  end
@@ -12,6 +12,7 @@ module AWSSupport
12
12
  require 'chef/provisioning/aws_driver'
13
13
  require 'aws_support/matchers/create_an_aws_object'
14
14
  require 'aws_support/matchers/update_an_aws_object'
15
+ require 'aws_support/matchers/destroy_an_aws_object'
15
16
  require 'aws_support/delayed_stream'
16
17
  require 'chef/provisioning/aws_driver/resources'
17
18
  require 'aws_support/aws_resource_run_wrapper'
@@ -188,6 +189,10 @@ module AWSSupport
188
189
  define_method("create_an_#{resource_name}") do |name, expected_values={}|
189
190
  AWSSupport::Matchers::CreateAnAWSObject.new(self, resource_class, name, expected_values)
190
191
  end
192
+ define_method("destroy_an_#{resource_name}") do |name, expected_values={}|
193
+ AWSSupport::Matchers::DestroyAnAWSObject.new(self, resource_class, name)
194
+ end
195
+
191
196
  end
192
197
 
193
198
  def chef_config
@@ -0,0 +1,62 @@
1
+ require 'rspec/matchers'
2
+ require 'chef/provisioning'
3
+ require 'aws_support/deep_matcher'
4
+
5
+ module AWSSupport
6
+ module Matchers
7
+ class DestroyAnAWSObject
8
+ include RSpec::Matchers::Composable
9
+ include AWSSupport::DeepMatcher
10
+
11
+ def initialize(example, resource_class, name)
12
+ @example = example
13
+ @resource_class = resource_class
14
+ @name = name
15
+
16
+ # Grab the "before" value
17
+ resource = resource_class.new(name, nil)
18
+ resource.driver example.driver
19
+ resource.managed_entry_store Chef::Provisioning.chef_managed_entry_store
20
+ @had_initial_value = !resource.aws_object.nil?
21
+ end
22
+
23
+ attr_reader :example
24
+ attr_reader :resource_class
25
+ attr_reader :name
26
+ def resource_name
27
+ @resource_class.resource_name
28
+ end
29
+ attr_reader :had_initial_value
30
+
31
+ def match_failure_messages(recipe)
32
+ differences = []
33
+
34
+ if !had_initial_value
35
+ differences << "expected recipe to delete #{resource_name}[#{name}], but the AWS object did not exist before recipe ran!"
36
+ return differences
37
+ end
38
+
39
+ # Converge
40
+ begin
41
+ recipe.converge
42
+ rescue
43
+ differences += [ "error trying to delete #{resource_name}[#{name}]!\n#{($!.backtrace.map { |line| "- #{line}\n" } + [ recipe.output_for_failure_message ]).join("")}" ]
44
+ end
45
+
46
+ # Check whether the recipe caused an update or not
47
+ differences += match_values_failure_messages(example.be_updated, recipe, "recipe")
48
+
49
+ # Check for object existence and properties
50
+ resource = resource_class.new(name, nil)
51
+ resource.driver example.driver
52
+ resource.managed_entry_store Chef::Provisioning.chef_managed_entry_store
53
+ aws_object = resource.aws_object
54
+
55
+ # Check existence
56
+ differences << "#{resource_name}[#{name}] was not deleted!" unless aws_object.nil?
57
+
58
+ differences
59
+ end
60
+ end
61
+ end
62
+ end
@@ -17,6 +17,23 @@ describe Chef::Resource::AwsEbsVolume do
17
17
  ).and be_idempotent
18
18
  end
19
19
 
20
+ describe 'action :delete' do
21
+ with_converge {
22
+ aws_ebs_volume "test_volume" do
23
+ availability_zone 'a'
24
+ size 8
25
+ end
26
+ }
27
+ it "deletes the ebs volume" do
28
+ expect_recipe {
29
+ aws_ebs_volume "test_volume" do
30
+ action :destroy
31
+ end
32
+ }.to destroy_an_aws_ebs_volume('test_volume')
33
+ .and be_idempotent
34
+ end
35
+ end
36
+
20
37
  it "aws_ebs_volume 'test_volume_az' creates an ebs volume when provided proper full AZ" do
21
38
  expect_recipe {
22
39
  aws_ebs_volume "test_volume_az" do
@@ -26,6 +43,7 @@ describe Chef::Resource::AwsEbsVolume do
26
43
  }.to create_an_aws_ebs_volume('test_volume_az')
27
44
  .and be_idempotent
28
45
  end
46
+
29
47
  end
30
48
  end
31
49
  end
@@ -20,14 +20,17 @@ describe Chef::Resource::MachineBatch do
20
20
  machine_options bootstrap_options: {
21
21
  subnet_id: 'test_public_subnet',
22
22
  key_name: 'test_key_pair'
23
- }
23
+ }, source_dest_check: false
24
24
  action :allocate
25
25
  end
26
26
  end
27
27
  end
28
- }.to create_an_aws_instance('test_machine1'
29
- ).and create_an_aws_instance('test_machine2'
30
- ).and create_an_aws_instance('test_machine3'
28
+ }.to create_an_aws_instance('test_machine1',
29
+ source_dest_check: false
30
+ ).and create_an_aws_instance('test_machine2',
31
+ source_dest_check: false
32
+ ).and create_an_aws_instance('test_machine3',
33
+ source_dest_check: false
31
34
  ).and be_idempotent
32
35
  end
33
36
  end
@@ -12,6 +12,7 @@ describe Chef::Resource::Machine do
12
12
 
13
13
  purge_all
14
14
  setup_public_vpc
15
+
15
16
  it "machine with few options allocates a machine", :super_slow do
16
17
  expect_recipe {
17
18
  machine 'test_machine' do
@@ -37,6 +38,20 @@ describe Chef::Resource::Machine do
37
38
  }.to create_an_aws_instance('test_machine'
38
39
  ).and be_idempotent
39
40
  end
41
+
42
+ it "machine with source_dest_check false creates a machine with no source dest check", :super_slow do
43
+ expect_recipe {
44
+ machine 'test_machine' do
45
+ machine_options bootstrap_options: {
46
+ subnet_id: 'test_public_subnet',
47
+ key_name: 'test_key_pair'
48
+ }, source_dest_check: false
49
+ action :allocate
50
+ end
51
+ }.to create_an_aws_instance('test_machine',
52
+ source_dest_check: false
53
+ ).and be_idempotent
54
+ end
40
55
  end
41
56
 
42
57
  with_aws "Without a VPC" do
@@ -59,6 +74,19 @@ describe Chef::Resource::Machine do
59
74
  ).and create_an_aws_key_pair('test_key_pair'
60
75
  ).and be_idempotent
61
76
  end
77
+
78
+ # Tests https://github.com/chef/chef-provisioning-aws/issues/189
79
+ it "correctly finds the driver_url when switching between machine and aws_instance", :super_slow do
80
+ expect { recipe {
81
+ machine 'test-machine-driver' do
82
+ action :allocate
83
+ end
84
+ aws_instance 'test-machine-driver'
85
+ machine 'test-machine-driver' do
86
+ action :destroy
87
+ end
88
+ }.converge }.to_not raise_error
89
+ end
62
90
  end
63
91
  end
64
92
  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.1.0
4
+ version: 1.1.1
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-16 00:00:00.000000000 Z
11
+ date: 2015-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef
@@ -188,6 +188,7 @@ files:
188
188
  - spec/aws_support/deep_matcher/rspec_monkeypatches.rb
189
189
  - spec/aws_support/delayed_stream.rb
190
190
  - spec/aws_support/matchers/create_an_aws_object.rb
191
+ - spec/aws_support/matchers/destroy_an_aws_object.rb
191
192
  - spec/aws_support/matchers/update_an_aws_object.rb
192
193
  - spec/integration/aws_ebs_volume_spec.rb
193
194
  - spec/integration/aws_key_pair_spec.rb