bosh_aws_registry 0.2.1 → 0.2.2

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.
@@ -31,7 +31,7 @@ module Bosh::AwsRegistry
31
31
  # check will be performed to see if it instance id
32
32
  # actually has this IP address according to EC2.
33
33
  def read_settings(instance_id, remote_ip = nil)
34
- check_instance_ip(remote_ip, instance_id) if remote_ip
34
+ check_instance_ips(remote_ip, instance_id) if remote_ip
35
35
 
36
36
  get_instance(instance_id).settings
37
37
  end
@@ -42,12 +42,13 @@ module Bosh::AwsRegistry
42
42
 
43
43
  private
44
44
 
45
- def check_instance_ip(ip, instance_id)
45
+ def check_instance_ips(ip, instance_id)
46
46
  return if ip == "127.0.0.1"
47
- actual_ip = instance_private_ip(instance_id)
48
- unless ip == actual_ip
47
+ actual_ips = instance_ips(instance_id)
48
+ unless actual_ips.include?(ip)
49
49
  raise InstanceError, "Instance IP mismatch, expected IP is " \
50
- "`%s', actual IP is `%s'" % [ ip, actual_ip ]
50
+ "`%s', actual IP(s): `%s'" %
51
+ [ ip, actual_ips.join(", ") ]
51
52
  end
52
53
  end
53
54
 
@@ -61,8 +62,14 @@ module Bosh::AwsRegistry
61
62
  instance
62
63
  end
63
64
 
64
- def instance_private_ip(instance_id)
65
- @ec2.instances[instance_id].private_ip_address
65
+ # Get the list of IPs belonging to this instance
66
+ def instance_ips(instance_id)
67
+ instance = @ec2.instances[instance_id]
68
+ ips = [instance.private_ip_address, instance.public_ip_address]
69
+ if instance.has_elastic_ip?
70
+ ips << instance.elastic_ip.public_ip
71
+ end
72
+ ips
66
73
  rescue AWS::Errors::Base => e
67
74
  raise Bosh::AwsRegistry::AwsError, "AWS error: #{e}"
68
75
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Bosh
4
4
  module AwsRegistry
5
- VERSION = "0.2.1"
5
+ VERSION = "0.2.2"
6
6
  end
7
7
  end
@@ -17,30 +17,44 @@ describe Bosh::AwsRegistry::InstanceManager do
17
17
  Bosh::AwsRegistry::Models::AwsInstance.create(params)
18
18
  end
19
19
 
20
- def actual_ip_is(ip)
20
+ def actual_ip_is(public_ip, private_ip, eip=nil)
21
21
  instances = mock("instances")
22
22
  instance = mock("instance")
23
+ if eip
24
+ elastic_ip = mock("elastic_ip", :public_ip => eip)
25
+ instance.should_receive(:has_elastic_ip?).and_return(true)
26
+ instance.should_receive(:elastic_ip).and_return(elastic_ip)
27
+ else
28
+ instance.should_receive(:has_elastic_ip?).and_return(false)
29
+ end
23
30
  @ec2.should_receive(:instances).and_return(instances)
24
31
  instances.should_receive(:[]).with("foo").and_return(instance)
25
- instance.should_receive(:private_ip_address).and_return(ip)
32
+ instance.should_receive(:private_ip_address).and_return(public_ip)
33
+ instance.should_receive(:public_ip_address).and_return(private_ip)
26
34
  end
27
35
 
28
36
  describe "reading settings" do
29
37
  it "returns settings after verifying IP address" do
30
38
  create_instance(:instance_id => "foo", :settings => "bar")
31
- actual_ip_is("10.0.0.1")
39
+ actual_ip_is("10.0.0.1", "10.0.1.1")
32
40
  manager.read_settings("foo", "10.0.0.1").should == "bar"
33
41
  end
34
42
 
43
+ it "returns settings after verifying elastic IP address" do
44
+ create_instance(:instance_id => "foo", :settings => "bar")
45
+ actual_ip_is("10.0.0.1", "10.0.1.1", "10.0.3.1")
46
+ manager.read_settings("foo", "10.0.3.1").should == "bar"
47
+ end
48
+
35
49
  it "raises an error if IP cannot be verified" do
36
50
  create_instance(:instance_id => "foo", :settings => "bar")
37
- actual_ip_is("10.0.0.2")
51
+ actual_ip_is("10.0.0.1", "10.0.1.1")
38
52
 
39
53
  expect {
40
- manager.read_settings("foo", "10.0.0.1")
54
+ manager.read_settings("foo", "10.0.3.1")
41
55
  }.to raise_error(Bosh::AwsRegistry::InstanceError,
42
- "Instance IP mismatch, expected IP is `10.0.0.1', " \
43
- "actual IP is `10.0.0.2'")
56
+ "Instance IP mismatch, expected IP is `10.0.3.1', " \
57
+ "actual IP(s): `10.0.0.1, 10.0.1.1'")
44
58
  end
45
59
 
46
60
  it "doesn't check remote IP if it's not provided" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bosh_aws_registry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-12 00:00:00.000000000 Z
12
+ date: 2012-08-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sequel
@@ -132,7 +132,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  segments:
134
134
  - 0
135
- hash: -3082160961986360018
135
+ hash: -294461121857325008
136
136
  required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  none: false
138
138
  requirements:
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  version: '0'
142
142
  segments:
143
143
  - 0
144
- hash: -3082160961986360018
144
+ hash: -294461121857325008
145
145
  requirements: []
146
146
  rubyforge_project:
147
147
  rubygems_version: 1.8.24