opsicle 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/opsicle +9 -0
- data/lib/opsicle/commands.rb +1 -0
- data/lib/opsicle/commands/failure_log.rb +65 -0
- data/lib/opsicle/stack.rb +4 -0
- data/lib/opsicle/version.rb +1 -1
- data/spec/opsicle/commands/failure_log_spec.rb +102 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7c60c0212ad5626778f928fec737322f86a5a6f
|
4
|
+
data.tar.gz: c0a6568a58e989b40f014326d457a776ea421ead
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50e99858c9decebd5a3159b79b1c76863b40c78bdb997b48e180c98ff94536317e558c1b83264fbd6b7eb0ac2b1fc1fa093c506f5743a655c07805d20c8c51b5
|
7
|
+
data.tar.gz: 15191e53bd2bed9c7c6d11fd3a1b9c5f856c82264365675c1f0dca810de0a287324037123115517ef1cb9a3762a3fa0043757ab98faf7265495123bb183cd364
|
data/bin/opsicle
CHANGED
@@ -51,6 +51,15 @@ command 'legacy-credential-converter' do |c|
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
desc "Get most recent failure log for a stack"
|
55
|
+
arg_name '<environment>'
|
56
|
+
command 'failure-log' do |c|
|
57
|
+
c.action do |global_options, options, args|
|
58
|
+
raise ArgumentError, 'You must specify an environment' unless args.first
|
59
|
+
Opsicle::FailureLog.new(args.first).execute
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
54
63
|
desc "Deploy your current app to the given environment stack"
|
55
64
|
arg_name '<environment>'
|
56
65
|
command :deploy do |c|
|
data/lib/opsicle/commands.rb
CHANGED
@@ -0,0 +1,65 @@
|
|
1
|
+
module Opsicle
|
2
|
+
class FailureLog
|
3
|
+
attr_reader :client, :stack
|
4
|
+
|
5
|
+
def initialize(environment)
|
6
|
+
@environment = environment
|
7
|
+
@client = Client.new(environment)
|
8
|
+
@stack = Opsicle::Stack.new(@client)
|
9
|
+
end
|
10
|
+
|
11
|
+
def execute
|
12
|
+
puts "Getting most recent failure log..."
|
13
|
+
|
14
|
+
fetch
|
15
|
+
end
|
16
|
+
|
17
|
+
def fetch
|
18
|
+
failed_deployments = fetch_failed_deployments
|
19
|
+
|
20
|
+
unless failed_deployments.empty?
|
21
|
+
failed_deployment_id = failed_deployments.first.deployment_id
|
22
|
+
failed_deployments_instances = failed_deployments.first.instance_ids
|
23
|
+
|
24
|
+
involved_instance_id = fetch_instance_id(failed_deployments_instances)
|
25
|
+
|
26
|
+
target_failed_command = fetch_target_command(involved_instance_id, failed_deployment_id)
|
27
|
+
log_url = target_failed_command.first.log_url
|
28
|
+
|
29
|
+
system("open", log_url) if log_url
|
30
|
+
puts "Unable to find a url to open." unless log_url
|
31
|
+
else
|
32
|
+
puts "No failed deployments in available history."
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def fetch_failed_deployments
|
37
|
+
deployments = @client.opsworks.describe_deployments(stack_id: @stack.stack_id).deployments
|
38
|
+
deployments.select{ |deploy| deploy.status.eql? "failed" }
|
39
|
+
end
|
40
|
+
|
41
|
+
def fetch_instance_id(failed_deployments_instances)
|
42
|
+
involved_instances = @client.opsworks.describe_instances(instance_ids: failed_deployments_instances).instances
|
43
|
+
choice = select_instance(involved_instances)
|
44
|
+
involved_instances[choice-1].instance_id
|
45
|
+
end
|
46
|
+
|
47
|
+
def fetch_target_command(involved_instance_id, failed_deployment_id)
|
48
|
+
command_list = @client.opsworks.describe_commands(instance_id: involved_instance_id)[:commands]
|
49
|
+
command_list.select{ |command| command.deployment_id == failed_deployment_id }
|
50
|
+
end
|
51
|
+
|
52
|
+
def select_instance(instance_list)
|
53
|
+
if instance_list.length == 1
|
54
|
+
choice = 1
|
55
|
+
else
|
56
|
+
Output.say "Choose an Opsworks instance:"
|
57
|
+
instance_list.each_with_index do |instance, index|
|
58
|
+
Output.say "#{index+1}) #{instance[:hostname]}"
|
59
|
+
end
|
60
|
+
choice = Output.ask("? ", Integer) { |q| q.in = 1..instance_list.length }
|
61
|
+
end
|
62
|
+
return choice
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/opsicle/stack.rb
CHANGED
data/lib/opsicle/version.rb
CHANGED
@@ -0,0 +1,102 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "opsicle"
|
3
|
+
|
4
|
+
module Opsicle
|
5
|
+
describe FailureLog do
|
6
|
+
before do
|
7
|
+
@instance = double('instance', instance_id: 123456)
|
8
|
+
@instances = double('instances', instances: [@instance])
|
9
|
+
@deploy1 = double('deploy', status: "failed", deployment_id: 678903, instance_ids: [123456])
|
10
|
+
@deploy2 = double('deploy', status: "failed", deployment_id: 294172, instance_ids: [123456])
|
11
|
+
@deployments = double('deployments', deployments: [@deploy1, @deploy2])
|
12
|
+
@command1 = double('command', log_url: 'http://example1.com', deployment_id: 678903)
|
13
|
+
@command2 = double('command', log_url: 'http://example2.com', deployment_id: 294172)
|
14
|
+
@commands = {:commands => [@command1, @command2]}
|
15
|
+
@stack = double('stack', stack_id: '12345')
|
16
|
+
@opsworks_client = double('opsworks_client', describe_deployments: @deployments,
|
17
|
+
describe_instances: @instances,
|
18
|
+
describe_commands: @commands)
|
19
|
+
@client = double('client', opsworks: @opsworks_client)
|
20
|
+
allow(Client).to receive(:new).and_return(@client)
|
21
|
+
allow(Opsicle::Stack).to receive(:new).and_return(@stack)
|
22
|
+
@log = FailureLog.new('environment')
|
23
|
+
allow(@log).to receive(:system).and_return(true)
|
24
|
+
end
|
25
|
+
|
26
|
+
context '#fetch' do
|
27
|
+
it "should initialize a new FailureLog" do
|
28
|
+
expect(Client).to receive(:new)
|
29
|
+
expect(Opsicle::Stack).to receive(:new)
|
30
|
+
FailureLog.new('environment')
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should get the deployment id of the first failed deploy" do
|
34
|
+
expect(@deploy1).to receive(:deployment_id)
|
35
|
+
@log.fetch
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should get the instance ids of the first failed deploy" do
|
39
|
+
expect(@deploy1).to receive(:instance_ids)
|
40
|
+
@log.fetch
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should get the log_url of the first target command" do
|
44
|
+
expect(@command1).to receive(:log_url)
|
45
|
+
@log.fetch
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should open a recent failure log" do
|
49
|
+
expect(@log).to receive(:system).and_return(true)
|
50
|
+
@log.fetch
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context '#fetch_failed_deployments' do
|
55
|
+
it "should grab deployments from opsworks" do
|
56
|
+
expect(@opsworks_client).to receive(:describe_deployments)
|
57
|
+
@log.fetch_failed_deployments
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should grab deployments from opsworks's deployments" do
|
61
|
+
expect(@deployments).to receive(:deployments)
|
62
|
+
@log.fetch_failed_deployments
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should question the status of each deployment" do
|
66
|
+
expect(@deploy1).to receive(:status)
|
67
|
+
expect(@deploy2).to receive(:status)
|
68
|
+
@log.fetch_failed_deployments
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context '#fetch_instance_id' do
|
73
|
+
it "should grab instances from opsworks" do
|
74
|
+
expect(@opsworks_client).to receive(:describe_instances)
|
75
|
+
@log.fetch_instance_id([123456])
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should grab instances from opsworks's instances" do
|
79
|
+
expect(@instances).to receive(:instances)
|
80
|
+
@log.fetch_instance_id([123456])
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should get the instance_id of the selected instance" do
|
84
|
+
expect(@instance).to receive(:instance_id)
|
85
|
+
@log.fetch_instance_id([123456])
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context '#fetch_target_command' do
|
90
|
+
it "should grab commands from opsworks" do
|
91
|
+
expect(@opsworks_client).to receive(:describe_commands)
|
92
|
+
@log.fetch_target_command(123456, 678903)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should get the deployment id of each command" do
|
96
|
+
expect(@command1).to receive(:deployment_id)
|
97
|
+
expect(@command2).to receive(:deployment_id)
|
98
|
+
@log.fetch_target_command(123456, 678903)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opsicle
|
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
|
- Andy Fleener
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-07-
|
12
|
+
date: 2016-07-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-sdk
|
@@ -195,6 +195,7 @@ files:
|
|
195
195
|
- lib/opsicle/commands/chef_update.rb
|
196
196
|
- lib/opsicle/commands/deploy.rb
|
197
197
|
- lib/opsicle/commands/execute_recipes.rb
|
198
|
+
- lib/opsicle/commands/failure_log.rb
|
198
199
|
- lib/opsicle/commands/legacy_credential_converter.rb
|
199
200
|
- lib/opsicle/commands/list.rb
|
200
201
|
- lib/opsicle/commands/list_instances.rb
|
@@ -233,6 +234,7 @@ files:
|
|
233
234
|
- spec/opsicle/commands/chef_update_spec.rb
|
234
235
|
- spec/opsicle/commands/deploy_spec.rb
|
235
236
|
- spec/opsicle/commands/execute_recipes_spec.rb
|
237
|
+
- spec/opsicle/commands/failure_log_spec.rb
|
236
238
|
- spec/opsicle/commands/list_instances_spec.rb
|
237
239
|
- spec/opsicle/commands/list_spec.rb
|
238
240
|
- spec/opsicle/commands/ssh_key_spec.rb
|
@@ -281,6 +283,7 @@ test_files:
|
|
281
283
|
- spec/opsicle/commands/chef_update_spec.rb
|
282
284
|
- spec/opsicle/commands/deploy_spec.rb
|
283
285
|
- spec/opsicle/commands/execute_recipes_spec.rb
|
286
|
+
- spec/opsicle/commands/failure_log_spec.rb
|
284
287
|
- spec/opsicle/commands/list_instances_spec.rb
|
285
288
|
- spec/opsicle/commands/list_spec.rb
|
286
289
|
- spec/opsicle/commands/ssh_key_spec.rb
|