Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[fixes #47095391] fix aws create race condition

* add resource_wait for security group to be created
  • Loading branch information...
commit aaa89610cad0d997cff733e015740fb87251b6e9 1 parent f14cb82
@Kaixiang Kaixiang authored
View
1  bosh_aws_bootstrap/lib/bosh_aws_bootstrap/vpc.rb
@@ -69,6 +69,7 @@ def create_security_groups(groups_specs)
groups_specs.each do |group_spec|
if group_name_available group_spec["name"]
security_group = @aws_vpc.security_groups.create(group_spec["name"])
+ Bosh::AwsCloud::ResourceWait.for_sgroup(sgroup: security_group, state: true)
group_spec["ingress"].each do |ingress|
range_match = ingress["ports"].to_s.match(/(\d+)\s*-\s*(\d+)/)
ports = range_match ? (range_match[1].to_i)..(range_match[2].to_i) : ingress["ports"].to_i
View
6 bosh_aws_bootstrap/spec/unit/vpc_spec.rb
@@ -172,6 +172,8 @@
security_groups.stub(:create).with("sg").and_return(security_group)
security_groups.stub(:each)
+ security_group.stub(:id)
+ security_group.should_receive(:exists?).and_return(true)
security_group.should_receive(:authorize_ingress).with(:tcp, 22, "1.2.3.0/24")
security_group.should_receive(:authorize_ingress).with(:tcp, 23, "1.2.4.0/24")
@@ -187,6 +189,8 @@
security_groups.stub(:create).with("sg").and_return(security_group)
security_groups.stub(:each)
+ security_group.stub(:id)
+ security_group.should_receive(:exists?).and_return(true)
security_group.should_receive(:authorize_ingress).with(:tcp, 5..60, "1.2.3.0/24")
ingress_rules = [
@@ -202,6 +206,8 @@
security_group.stub(:authorize_ingress).with(:tcp, 22, "1.2.3.0/24")
security_groups.stub(:create).with("sg").and_return(security_group)
security_groups.stub(:each).and_yield(existing_security_group)
+ security_group.stub(:id)
+ security_group.should_receive(:exists?).and_return(true)
existing_security_group.should_receive :delete
View
11 bosh_aws_cpi/lib/cloud/aws/resource_wait.rb
@@ -104,6 +104,17 @@ def self.for_subnet(args)
end
end
+ def self.for_sgroup(args)
+ sgroup = args.fetch(:sgroup) { raise ArgumentError, 'sgroup object required' }
+ target_state = args.fetch(:state) { raise ArgumentError, 'state symbol required' }
+ valid_states = [true, false]
+ validate_states(valid_states, target_state)
+
+ new.for_resource(resource: sgroup, target_state: true, state_method: :exists?) do |current_state|
+ current_state == target_state
+ end
+ end
+
def self.validate_states(valid_states, target_state)
unless valid_states.include?(target_state)
raise ArgumentError, "target state must be one of #{valid_states.join(', ')}, `#{target_state}' given"
Please sign in to comment.
Something went wrong with that request. Please try again.