MovableInkAWS 0.3.4 → 0.3.5

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
  SHA256:
3
- metadata.gz: ffffe0e3ef8632871ef9a8645fab2a8072c85d8817e54cde4a8d4770c753b7f0
4
- data.tar.gz: d78f852f878caa5c95297b912abe05b34fe66e3fa9cc69d4954b7c917d6a4b3b
3
+ metadata.gz: f85b7a7cacd3d56c98e276a780730187b57d96beea4197e972858e093ff8b5b6
4
+ data.tar.gz: 0edf31bf91bbc3498f2336df122eaa70631b2e4d62c4b3dbc373365dea9b4209
5
5
  SHA512:
6
- metadata.gz: c959b4ed5ca462caf9361beb0ec318850e7a9f5de62ae4677fcea556ed062d31be68cdf98cde6f73a2fb6cf9139c9707cf9fb7003a57ee2e6c9d3d43a1ff417c
7
- data.tar.gz: 9d74aaee3fa45e84ae18fc7a2e837a494b866766feaf827f51dc0c782781ed1d3ce9b860492610d017a6d7c1fdda2a5e04137aba93afb0222098197b66fc424c
6
+ metadata.gz: 5834796db467a574a0ce7f9cb88c6bb1f6995ebb54292d543881c23884de2733ff41a1729fa49e0d40056e89959e49e84e6347bb1ecaaea1ee718f54ad039f3e
7
+ data.tar.gz: 8ced1573db88a51ded5905888e01bac2a606dbffb1811e2dbd9ea5c230872711febc0867f5ba4380c8fd45d7c51dc9f87c4e5064c9d1c5c10532e38b89e6642c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- MovableInkAWS (0.3.3)
4
+ MovableInkAWS (0.3.5)
5
5
  aws-sdk (= 2.11.240)
6
6
 
7
7
  GEM
@@ -44,33 +44,59 @@ module MovableInk
44
44
  end
45
45
  end
46
46
 
47
- def complete_lifecycle_action(lifecycle_hook_name:, auto_scaling_group_name:, lifecycle_action_token:)
48
- run_with_backoff do
49
- autoscaling.complete_lifecycle_action({
50
- lifecycle_hook_name: lifecycle_hook_name,
51
- auto_scaling_group_name: auto_scaling_group_name,
52
- lifecycle_action_token: lifecycle_action_token,
53
- lifecycle_action_result: 'CONTINUE'
54
- })
47
+ def complete_lifecycle_action(lifecycle_hook_name:, auto_scaling_group_name:, lifecycle_action_token: nil, instance_id: nil)
48
+ raise ArgumentError.new('lifecycle_action_token or instance_id required') if lifecycle_action_token.nil? && instance_id.nil?
49
+
50
+ if lifecycle_action_token
51
+ run_with_backoff do
52
+ autoscaling.complete_lifecycle_action({
53
+ lifecycle_hook_name: lifecycle_hook_name,
54
+ auto_scaling_group_name: auto_scaling_group_name,
55
+ lifecycle_action_token: lifecycle_action_token,
56
+ lifecycle_action_result: 'CONTINUE'
57
+ })
58
+ end
59
+ else
60
+ run_with_backoff do
61
+ autoscaling.complete_lifecycle_action({
62
+ instance_id: instance_id,
63
+ lifecycle_hook_name: lifecycle_hook_name,
64
+ auto_scaling_group_name: auto_scaling_group_name,
65
+ lifecycle_action_result: 'CONTINUE'
66
+ })
67
+ end
55
68
  end
56
69
  end
57
70
 
58
- def record_lifecycle_action_heartbeat(lifecycle_hook_name:, auto_scaling_group_name:, lifecycle_action_token:)
59
- run_with_backoff do
60
- autoscaling.record_lifecycle_action_heartbeat({
61
- lifecycle_hook_name: lifecycle_hook_name,
62
- auto_scaling_group_name: auto_scaling_group_name,
63
- lifecycle_action_token: lifecycle_action_token
64
- })
71
+ def record_lifecycle_action_heartbeat(lifecycle_hook_name:, auto_scaling_group_name:, lifecycle_action_token: nil, instance_id: nil)
72
+ raise ArgumentError.new('lifecycle_action_token or instance_id required') if lifecycle_action_token.nil? && instance_id.nil?
73
+
74
+ if lifecycle_action_token
75
+ run_with_backoff do
76
+ autoscaling.record_lifecycle_action_heartbeat({
77
+ lifecycle_hook_name: lifecycle_hook_name,
78
+ auto_scaling_group_name: auto_scaling_group_name,
79
+ lifecycle_action_token: lifecycle_action_token
80
+ })
81
+ end
82
+ else
83
+ run_with_backoff do
84
+ autoscaling.record_lifecycle_action_heartbeat({
85
+ instance_id: instance_id,
86
+ lifecycle_hook_name: lifecycle_hook_name,
87
+ auto_scaling_group_name: auto_scaling_group_name,
88
+ })
89
+ end
65
90
  end
66
91
  end
67
92
 
68
- def keep_instance_alive(lifecycle_hook_name:, auto_scaling_group_name:, lifecycle_action_token:)
93
+ def keep_instance_alive(lifecycle_hook_name:, auto_scaling_group_name:, lifecycle_action_token: nil, instance_id: nil)
69
94
  24.downto(1) do |hours|
70
95
  record_lifecycle_action_heartbeat(
71
96
  lifecycle_hook_name: lifecycle_hook_name,
72
97
  auto_scaling_group_name: auto_scaling_group_name,
73
- lifecycle_action_token: lifecycle_action_token
98
+ lifecycle_action_token: lifecycle_action_token,
99
+ instance_id: instance_id
74
100
  )
75
101
  sleep 3600
76
102
  end
@@ -11,21 +11,11 @@ module MovableInk
11
11
  end
12
12
 
13
13
  def load_mi_env
14
- run_with_backoff(quiet: true) do
15
- begin
16
- ec2.describe_tags(filters: [
17
- {
18
- name: 'resource-id',
19
- values: [instance_id]
20
- }
21
- ])
22
- .tags
23
- .detect { |tag| tag.key == 'mi:env' }
24
- .value
25
- rescue NoMethodError
26
- raise MovableInk::AWS::Errors::NoEnvironmentTagError
27
- end
28
- end
14
+ instance_tags
15
+ .detect { |tag| tag.key == 'mi:env' }
16
+ .value
17
+ rescue NoMethodError
18
+ raise MovableInk::AWS::Errors::NoEnvironmentTagError
29
19
  end
30
20
 
31
21
  def thopter_filter
@@ -81,6 +71,14 @@ module MovableInk
81
71
  end
82
72
  end
83
73
 
74
+ def instance_tags
75
+ @instance_tags ||= run_with_backoff(quiet: true) do
76
+ ec2.describe_tags({
77
+ filters: [{ name: 'resource-id', values: [instance_id] } ]
78
+ }).tags
79
+ end
80
+ end
81
+
84
82
  def private_ipv4
85
83
  @ipv4 ||= begin
86
84
  ipv4 = `ec2metadata --local-ipv4 2>/dev/null`.chomp
@@ -1,5 +1,5 @@
1
1
  module MovableInk
2
2
  class AWS
3
- VERSION = '0.3.4'
3
+ VERSION = '0.3.5'
4
4
  end
5
5
  end
@@ -10,7 +10,7 @@ describe MovableInk::AWS::Autoscaling do
10
10
  let(:create_tags_data) { ec2.stub_data(:create_tags, {}) }
11
11
  let(:delete_tags_data) { ec2.stub_data(:delete_tags, {}) }
12
12
 
13
- it "should mark an instance as unhealthy" do
13
+ it 'should mark an instance as unhealthy' do
14
14
  autoscaling.stub_responses(:set_instance_health, set_instance_health_data)
15
15
  allow(aws).to receive(:my_region).and_return('us-east-1')
16
16
  allow(aws).to receive(:instance_id).and_return('i-12345')
@@ -37,19 +37,76 @@ describe MovableInk::AWS::Autoscaling do
37
37
  expect(aws.delete_role_tag(role: 'some_role')).to eq(Aws::EmptyStructure.new)
38
38
  end
39
39
 
40
+ it 'raises an ArgumentError when instance_id and lifecycle_action_token are not provided' do
41
+ autoscaling.stub_responses(:complete_lifecycle_action, complete_lifecycle_action_data)
42
+ allow(aws).to receive(:my_region).and_return('us-east-1')
43
+ allow(aws).to receive(:autoscaling).and_return(autoscaling)
44
+ expect {
45
+ aws.complete_lifecycle_action(lifecycle_hook_name: 'hook', auto_scaling_group_name: 'group')
46
+ }.to raise_error(ArgumentError)
47
+ end
48
+
40
49
  it "should complete lifecycle actions" do
41
50
  autoscaling.stub_responses(:complete_lifecycle_action, complete_lifecycle_action_data)
42
51
  allow(aws).to receive(:my_region).and_return('us-east-1')
43
52
  allow(aws).to receive(:autoscaling).and_return(autoscaling)
44
53
 
54
+ expect(autoscaling).to receive(:complete_lifecycle_action).with({
55
+ lifecycle_action_result: 'CONTINUE',
56
+ lifecycle_action_token: 'token',
57
+ lifecycle_hook_name: 'hook',
58
+ auto_scaling_group_name: 'group',
59
+ }).and_call_original
45
60
  expect(aws.complete_lifecycle_action(lifecycle_hook_name: 'hook', auto_scaling_group_name: 'group', lifecycle_action_token: 'token')).to eq(Aws::EmptyStructure.new)
46
61
  end
47
62
 
48
- it "should record lifecycle action heartbeats" do
63
+ it 'allows passing the instance_id to complete a lifecycle action' do
64
+ autoscaling.stub_responses(:complete_lifecycle_action, complete_lifecycle_action_data)
65
+ allow(aws).to receive(:my_region).and_return('us-east-1')
66
+ allow(aws).to receive(:autoscaling).and_return(autoscaling)
67
+
68
+ expect(autoscaling).to receive(:complete_lifecycle_action).with({
69
+ lifecycle_action_result: 'CONTINUE',
70
+ lifecycle_hook_name: 'hook',
71
+ instance_id: 'i-987654321',
72
+ auto_scaling_group_name: 'group'
73
+ }).and_call_original
74
+ expect(aws.complete_lifecycle_action(lifecycle_hook_name: 'hook', auto_scaling_group_name: 'group', instance_id: 'i-987654321')).to eq(Aws::EmptyStructure.new)
75
+ end
76
+
77
+ it 'should record lifecycle action heartbeats' do
49
78
  autoscaling.stub_responses(:record_lifecycle_action_heartbeat, record_lifecycle_action_heartbeat_data)
50
79
  allow(aws).to receive(:my_region).and_return('us-east-1')
51
80
  allow(aws).to receive(:autoscaling).and_return(autoscaling)
52
81
 
82
+ expect(autoscaling).to receive(:record_lifecycle_action_heartbeat).with({
83
+ lifecycle_action_token: 'token',
84
+ lifecycle_hook_name: 'hook',
85
+ auto_scaling_group_name: 'group'
86
+ }).and_call_original
53
87
  expect(aws.record_lifecycle_action_heartbeat(lifecycle_hook_name: 'hook', auto_scaling_group_name: 'group', lifecycle_action_token: 'token')).to eq(Aws::EmptyStructure.new)
54
88
  end
89
+
90
+ it 'allows passing the instance_id to record lifecycle action heartbeats' do
91
+ autoscaling.stub_responses(:record_lifecycle_action_heartbeat, record_lifecycle_action_heartbeat_data)
92
+ allow(aws).to receive(:my_region).and_return('us-east-1')
93
+ allow(aws).to receive(:autoscaling).and_return(autoscaling)
94
+
95
+ expect(autoscaling).to receive(:record_lifecycle_action_heartbeat).with({
96
+ instance_id: 'i-987654321',
97
+ lifecycle_hook_name: 'hook',
98
+ auto_scaling_group_name: 'group'
99
+ }).and_call_original
100
+ expect(aws.record_lifecycle_action_heartbeat(lifecycle_hook_name: 'hook', auto_scaling_group_name: 'group', instance_id: 'i-987654321')).to eq(Aws::EmptyStructure.new)
101
+ end
102
+
103
+ it 'raises an ArgumentError when instance_id and lifecycle_action_token are not provided' do
104
+ autoscaling.stub_responses(:record_lifecycle_action_heartbeat, record_lifecycle_action_heartbeat_data)
105
+ allow(aws).to receive(:my_region).and_return('us-east-1')
106
+ allow(aws).to receive(:autoscaling).and_return(autoscaling)
107
+
108
+ expect {
109
+ aws.record_lifecycle_action_heartbeat(lifecycle_hook_name: 'hook', auto_scaling_group_name: 'group')
110
+ }.to raise_error(ArgumentError)
111
+ end
55
112
  end
data/spec/ec2_spec.rb CHANGED
@@ -47,6 +47,16 @@ describe MovableInk::AWS::EC2 do
47
47
  expect(aws.private_ipv4).to eq('10.0.0.1')
48
48
  end
49
49
 
50
+ context 'instance_tags' do
51
+ it 'returns the tags of the current instance' do
52
+ ec2.stub_responses(:describe_tags, tag_data)
53
+ allow(aws).to receive(:my_region).and_return('us-east-1')
54
+ allow(aws).to receive(:instance_id).and_return('i-12345')
55
+ allow(aws).to receive(:ec2).and_return(ec2)
56
+ expect(aws.instance_tags).to eq(tag_data.tags)
57
+ end
58
+ end
59
+
50
60
  context "thopter" do
51
61
  let(:thopter_data) { ec2.stub_data(:describe_instances, reservations: [
52
62
  instances: [
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: MovableInkAWS
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Chesler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-27 00:00:00.000000000 Z
11
+ date: 2019-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk