opsicle 2.12.3 → 2.12.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 508652e0801f35bc78c6e29e2b990a075b32db81
4
- data.tar.gz: a43909b2ff893db83f1cddca4624181e02a837c5
2
+ SHA256:
3
+ metadata.gz: 0d4b66a5b078018b67348b894fe8274491719348c5d24d3672ddaebdbd667d2e
4
+ data.tar.gz: c6928a8a60d29c02924287bba794a3c0f75767916610020d905119d8abb4b65e
5
5
  SHA512:
6
- metadata.gz: e068df9fe0e064989f92f3f5155644c5cf81c15afa6457641469e4bfae5b0bd3643d4a8ab78cb9c468fb8ce894808219fb3171d21db27a2169c8ea113f77554e
7
- data.tar.gz: 6f168db27328423daddb64558e92fb3e50d7135573535652279bdc2206ce3f5ae80751de767326f68ef8ad9e67d6aee318cfcc3ab00632b08ea5e5a4f40544af
6
+ metadata.gz: 71647e38b87fa0077864cc3f255e2edf1ee9c9be3a0a59f59d66bd2d1c7e3169d76a7a0f2c43a17836b8de6278ef554144fd8067c10d446d30e84835ac15a493
7
+ data.tar.gz: 5229246562d67aa4405589eb00fedecb72e0f94c3bf8274bc8bbd45e9e1e7190a812aa7c1765f2aebff6c81c53e20a740abdd077cfc27faf75cb0b700d572c9e
@@ -60,6 +60,7 @@ module Opsicle
60
60
  instances.each_with_index { |instance, index| puts "#{index.to_i + 1}) #{instance.status} - #{instance.hostname}" }
61
61
  instance_indices_string = @cli.ask("Which instances would you like to delete? (enter as a comma separated list)\n", String)
62
62
  instance_indices_list = instance_indices_string.split(/,\s*/)
63
+ check_for_valid_indices!(instance_indices_list, instances.count)
63
64
  instance_indices_list.map! { |instance_index| instance_index.to_i - 1 }
64
65
  instance_indices_list.each do |index|
65
66
  return_array << instances[index]
@@ -67,5 +68,14 @@ module Opsicle
67
68
  end
68
69
  return_array
69
70
  end
71
+
72
+ def check_for_valid_indices!(instance_indices_list, option_count)
73
+ valid_indices = 1..option_count
74
+
75
+ unless instance_indices_list.all?{ |i| valid_indices.include?(i.to_i) }
76
+ raise StandardError, "At least one of the indices passed is invalid. Please try again."
77
+ end
78
+ end
79
+ private :check_for_valid_indices!
70
80
  end
71
81
  end
@@ -60,6 +60,7 @@ module Opsicle
60
60
  instances.each_with_index { |instance, index| puts "#{index.to_i + 1}) #{instance.status} - #{instance.hostname}" }
61
61
  instance_indices_string = @cli.ask("Which instances would you like to stop? (enter as a comma separated list)\n", String)
62
62
  instance_indices_list = instance_indices_string.split(/,\s*/)
63
+ check_for_valid_indices!(instance_indices_list, instances.count)
63
64
  instance_indices_list.map! { |instance_index| instance_index.to_i - 1 }
64
65
  instance_indices_list.each do |index|
65
66
  return_array << instances[index]
@@ -67,5 +68,14 @@ module Opsicle
67
68
  end
68
69
  return_array
69
70
  end
71
+
72
+ def check_for_valid_indices!(instance_indices_list, option_count)
73
+ valid_indices = 1..option_count
74
+
75
+ unless instance_indices_list.all?{ |i| valid_indices.include?(i.to_i) }
76
+ raise StandardError, "At least one of the indices passed is invalid. Please try again."
77
+ end
78
+ end
79
+ private :check_for_valid_indices!
70
80
  end
71
81
  end
@@ -1,8 +1,8 @@
1
1
  class Opsicle::Ec2Adapter
2
2
  attr_reader :client
3
3
 
4
- def initialize(client)
5
- @client = client.ec2
4
+ def initialize(opsicle_client)
5
+ @client = opsicle_client.ec2
6
6
  end
7
7
 
8
8
  def get_subnets
@@ -75,7 +75,6 @@ module Opsicle
75
75
  new_hostname = auto_generated_hostname
76
76
  create_new_instance(new_hostname, instance_type, ami_id, agent_version, subnet_id)
77
77
  opsworks.start_instance(instance_id: new_instance_id)
78
- add_tags
79
78
  puts "\nNew instance is starting…"
80
79
  end
81
80
 
@@ -18,6 +18,7 @@ module Opsicle
18
18
  def which_instance_should_get_eip(moveable_eip)
19
19
  puts "\nHere are all of the instances in the current instance's layer:"
20
20
  instances = get_potential_target_instances(moveable_eip)
21
+ check_for_printable_items!(instances)
21
22
  print_potential_target_instances(instances)
22
23
  instance_index = ask_eip_question("What is your target instance?\n", instances)
23
24
  instances[instance_index].instance_id
@@ -40,9 +41,20 @@ module Opsicle
40
41
 
41
42
  def get_potential_target_instances(moveable_eip)
42
43
  instances = @opsworks_adapter.instances_by_layer(moveable_eip[:layer_id])
43
- instances.select { |instance| instance.elastic_ip.nil? && instance.auto_scaling_type.nil? }
44
+ instances.select do |instance|
45
+ instance.elastic_ip.nil? &&
46
+ instance.auto_scaling_type.nil? &&
47
+ instance.status == "online"
48
+ end
44
49
  end
45
50
  private :get_potential_target_instances
51
+
52
+ def check_for_printable_items!(instances)
53
+ if instances.empty? # instances is the list of instances that an eip can be moved to
54
+ raise StandardError, "You cannot move an EIP when there's only one instance running."
55
+ end
56
+ end
57
+ private :check_for_printable_items!
46
58
  end
47
59
  end
48
60
  end
@@ -1,3 +1,3 @@
1
1
  module Opsicle
2
- VERSION = "2.12.3"
2
+ VERSION = "2.12.5"
3
3
  end
@@ -3,79 +3,98 @@ require "opsicle"
3
3
  require 'gli'
4
4
  require "opsicle/user_profile"
5
5
 
6
- module Opsicle
7
- describe DeleteInstance do
8
- before do
9
- @instance1 = double('instance1', :hostname => 'example-hostname-01', :status => 'active',
10
- :ami_id => 'ami_id', :instance_type => 'instance_type',
11
- :agent_version => 'agent_version', :stack_id => 1234567890,
12
- :layer_ids => [12345, 67890], :auto_scaling_type => 'auto_scaling_type',
13
- :os => 'os', :ssh_key_name => 'ssh_key_name',
14
- :availability_zone => 'availability_zone', :virtualization_type => 'virtualization_type',
15
- :subnet_id => 'subnet_id', :architecture => 'architecture',
16
- :root_device_type => 'root_device_type', :install_updates_on_boot => 'install_updates_on_boot',
17
- :ebs_optimized => 'ebs_optimized', :tenancy => 'tenancy', :instance_id => 'some-id')
18
- @instance2 = double('instance2', :hostname => 'example-hostname-02', :status => 'active',
19
- :ami_id => 'ami_id', :instance_type => 'instance_type',
20
- :agent_version => 'agent_version', :stack_id => 1234567890,
21
- :layer_ids => [12345, 67890], :auto_scaling_type => 'auto_scaling_type',
22
- :os => 'os', :ssh_key_name => 'ssh_key_name',
23
- :availability_zone => 'availability_zone', :virtualization_type => 'virtualization_type',
24
- :subnet_id => 'subnet_id', :architecture => 'architecture',
25
- :root_device_type => 'root_device_type', :install_updates_on_boot => 'install_updates_on_boot',
26
- :ebs_optimized => 'ebs_optimized', :tenancy => 'tenancy', :instance_id => 'some-id')
27
- @instances = double('instances', :instances => [@instance1, @instance2])
28
- @layer1 = double('layer1', :name => 'layer-1', :layer_id => 12345, :instances => [@instance1, @instance2])
29
- @layer2 = double('layer2', :name => 'layer-2', :layer_id => 67890, :instances => [@instance1, @instance2])
30
- @layers = double('layers', :layers => [@layer1, @layer2])
31
- @new_instance = double('new_instance', :instance_id => 1029384756)
32
- @stack = double('stack', :vpc_id => "vpc-123456")
33
- @stacks = double('stacks', :stacks => [@stack])
34
- @opsworks = double('opsworks', :describe_instances => @instances, :describe_layers => @layers,
35
- :create_instance => @new_instance, :describe_stacks => @stacks,
36
- :start_instance => @new_instance)
37
- @ec2 = double('ec2')
38
- @config = double('config', :opsworks_config => {:stack_id => 1234567890})
39
- @client = double('client', :config => @config, :opsworks => @opsworks, :ec2 => @ec2)
40
- allow(@instances).to receive(:each_with_index)
41
- @agent_version_1 = double('agent_version', :version => '3434-20160316181345')
42
- @agent_version_2 = double('agent_version', :version => '3435-20160406115841')
43
- @agent_version_3 = double('agent_version', :version => '3436-20160418214624')
44
- @agent_versions = double('agent_versions', :agent_versions => [@agent_version_1, @agent_version_2, @agent_version_3])
45
- allow(@opsworks).to receive(:describe_agent_versions).and_return(@agent_versions)
46
- tag1 = double('tag', :value => 'Subnet', :key => 'Name')
47
- @tags = [tag1]
48
- @current_subnet = double('subnet', :tags => @tags, :availability_zone => 'us-east-1b')
49
- allow(Aws::EC2::Subnet).to receive(:new).and_return(@current_subnet)
50
- allow_any_instance_of(HighLine).to receive(:ask).with("Layer?\n", Integer).and_return(2)
51
- allow_any_instance_of(HighLine).to receive(:ask).with("Instances? (enter as a comma separated list)\n", String).and_return('2')
52
- allow_any_instance_of(HighLine).to receive(:ask).with("Do you wish to override this hostname?\n1) Yes\n2) No", Integer).and_return(2)
53
- allow_any_instance_of(HighLine).to receive(:ask).with("Please write in the new instance's hostname and press ENTER:").and_return('example-hostname')
54
- allow_any_instance_of(HighLine).to receive(:ask).with("Do you wish to override this AMI ID? By overriding, you are choosing to override the current AMI ID for all of the following instances you're cloning.\n1) Yes\n2) No", Integer).and_return(2)
55
- allow_any_instance_of(HighLine).to receive(:ask).with("Which AMI ID?\n", Integer).and_return(1)
56
- allow_any_instance_of(HighLine).to receive(:ask).with("Do you wish to override this agent version? By overriding, you are choosing to override the current agent version for all of the following instances you're cloning.\n1) Yes\n2) No", Integer).and_return(2)
57
- allow_any_instance_of(HighLine).to receive(:ask).with("Which agent version?\n", Integer).and_return(1)
58
- allow_any_instance_of(HighLine).to receive(:ask).with("Do you wish to override this instance type?\n1) Yes\n2) No", Integer).and_return(2)
59
- allow_any_instance_of(HighLine).to receive(:ask).with("Please write in the new instance type press ENTER:").and_return('t2.micro')
60
- allow_any_instance_of(HighLine).to receive(:ask).with("Do you wish to override this subnet ID? By overriding, you are choosing to override the current subnet ID for all of the following instances you're cloning.\n1) Yes\n2) No", Integer).and_return(2)
61
- allow_any_instance_of(HighLine).to receive(:ask).with("Which subnet ID?\n", Integer).and_return(1)
62
- allow_any_instance_of(HighLine).to receive(:ask).with("Do you wish to start this new instance?\n1) Yes\n2) No", Integer).and_return(1)
6
+ describe Opsicle::DeleteInstance do
7
+ let(:config) { double(:config, opsworks_config: {stack_id: "1234"}) }
8
+ let(:opsicle_client) { double(:client, config: config, opsworks: opsworks_client, ec2: ec2_client) }
9
+ let(:opsworks_stack) { double(:stack, id: "1234", vpc_id: "21") }
10
+ let(:layer1) { double(:layer, name: "layer1", layer_id: "123") }
11
+ let(:layer2) { double(:layer, name: "layer2", layer_id: "456") }
12
+
13
+ let(:instance1) do
14
+ double(:instance,
15
+ name: "instance1",
16
+ layer_ids: [ "456" ],
17
+ status: "stopped",
18
+ auto_scaling_type: nil,
19
+ instance_id: "123",
20
+ hostname: "instance1"
21
+ )
22
+ end
23
+
24
+ let(:opsworks_client) do
25
+ double(:opsworks_client,
26
+ associate_elastic_ip: true,
27
+ describe_stacks: double(stack: [ opsworks_stack ]),
28
+ describe_instances: double(instances: [ instance1 ])
29
+ )
30
+ end
31
+
32
+ let(:ec2_client) { double(:ec2_client) }
33
+
34
+ let(:opsworks_adapter) do
35
+ double(:opsworks_adapter,
36
+ client: opsworks_client,
37
+ stack: opsworks_stack,
38
+ layers: [ layer1, layer2 ],
39
+ instances_by_stack: [ instance1 ]
40
+ )
41
+ end
42
+
43
+ let(:ec2_adapter) do
44
+ double(:ec2_adapter,
45
+ client: ec2_client,
46
+ stack: opsworks_stack,
47
+ elastic_ips: []
48
+ )
49
+ end
50
+
51
+ before do
52
+ allow(Opsicle::Client).to receive(:new).with("staging").and_return(opsicle_client)
53
+ allow(Opsicle::OpsworksAdapter).to receive(:new).and_return(opsworks_adapter)
54
+ allow_any_instance_of(HighLine).to receive(:ask).with("Layer?\n", Integer).and_return(2)
55
+ end
56
+
57
+ subject { described_class.new("staging") }
58
+
59
+
60
+ describe "#execute" do
61
+ context "when everything works as expected" do
62
+ before do
63
+ allow_any_instance_of(HighLine).to receive(:ask).with("Which instances would you like to delete? (enter as a comma separated list)\n", String).and_return("1")
64
+ end
65
+
66
+ it "should properly ask to delete instances" do
67
+ expect(opsworks_adapter).to receive(:delete_instance).with("123")
68
+ subject.execute
69
+ end
63
70
  end
64
71
 
65
- subject{DeleteInstance.new("staging")}
72
+ context "when an improper value is passed in as something to delete" do
73
+ before do
74
+ allow_any_instance_of(HighLine).to receive(:ask).with("Which instances would you like to delete? (enter as a comma separated list)\n", String).and_return("-1")
75
+ end
66
76
 
67
- # context "#execute" do
68
- # it "lists deleteable instances" do
69
- # allow(subject).to receive("staging"){[@instance1]}
70
- # expect(@stack).to receive(:deleteable_instances)
71
- # subject.execute
72
- # end
73
- #
74
- # it "deletes the selected instance" do
75
- # allow(subject).to receive("staging"){[@instance1]}
76
- # expect(@opsworks).to receive(:delete_instance)
77
- # subject.execute
78
- # end
79
- # end
77
+ it "should properly ask to delete instances" do
78
+ expect{subject.execute}.to raise_error(StandardError)
79
+ end
80
+ end
81
+
82
+ context "when there are no deletable instances" do
83
+ let(:instance1) do
84
+ double(:instance,
85
+ name: "instance1",
86
+ layer_ids: [ "456" ],
87
+ status: "online",
88
+ auto_scaling_type: nil,
89
+ instance_id: "123",
90
+ hostname: "instance1"
91
+ )
92
+ end
93
+
94
+ it "should not delete any instances" do
95
+ expect(opsworks_adapter).not_to receive(:delete_instance)
96
+ subject.execute
97
+ end
98
+ end
80
99
  end
81
100
  end
@@ -0,0 +1,100 @@
1
+ require "spec_helper"
2
+ require "opsicle"
3
+ require 'gli'
4
+ require "opsicle/user_profile"
5
+
6
+ describe Opsicle::StopInstance do
7
+ let(:config) { double(:config, opsworks_config: {stack_id: "1234"}) }
8
+ let(:opsicle_client) { double(:client, config: config, opsworks: opsworks_client, ec2: ec2_client) }
9
+ let(:opsworks_stack) { double(:stack, id: "1234", vpc_id: "21") }
10
+ let(:layer1) { double(:layer, name: "layer1", layer_id: "123") }
11
+ let(:layer2) { double(:layer, name: "layer2", layer_id: "456") }
12
+
13
+ let(:instance1) do
14
+ double(:instance,
15
+ name: "instance1",
16
+ layer_ids: [ "456" ],
17
+ status: "online",
18
+ elastic_ip: nil,
19
+ instance_id: "123",
20
+ hostname: "instance1"
21
+ )
22
+ end
23
+
24
+ let(:opsworks_client) do
25
+ double(:opsworks_client,
26
+ associate_elastic_ip: true,
27
+ describe_stacks: double(stack: [ opsworks_stack ]),
28
+ describe_instances: double(instances: [ instance1 ])
29
+ )
30
+ end
31
+
32
+ let(:ec2_client) { double(:ec2_client) }
33
+
34
+ let(:opsworks_adapter) do
35
+ double(:opsworks_adapter,
36
+ client: opsworks_client,
37
+ stack: opsworks_stack,
38
+ layers: [ layer1, layer2 ],
39
+ instances_by_stack: [ instance1 ]
40
+ )
41
+ end
42
+
43
+ let(:ec2_adapter) do
44
+ double(:ec2_adapter,
45
+ client: ec2_client,
46
+ stack: opsworks_stack,
47
+ elastic_ips: []
48
+ )
49
+ end
50
+
51
+ before do
52
+ allow(Opsicle::Client).to receive(:new).with("staging").and_return(opsicle_client)
53
+ allow(Opsicle::OpsworksAdapter).to receive(:new).and_return(opsworks_adapter)
54
+ allow_any_instance_of(HighLine).to receive(:ask).with("Layer?\n", Integer).and_return(2)
55
+ end
56
+
57
+ subject { described_class.new("staging") }
58
+
59
+
60
+ describe "#execute" do
61
+ context "when everything works as expected" do
62
+ before do
63
+ allow_any_instance_of(HighLine).to receive(:ask).with("Which instances would you like to stop? (enter as a comma separated list)\n", String).and_return("1")
64
+ end
65
+
66
+ it "should properly ask to stop instances" do
67
+ expect(opsworks_adapter).to receive(:stop_instance).with("123")
68
+ subject.execute
69
+ end
70
+ end
71
+
72
+ context "when an improper value is passed in as something to stop" do
73
+ before do
74
+ allow_any_instance_of(HighLine).to receive(:ask).with("Which instances would you like to stop? (enter as a comma separated list)\n", String).and_return("-1")
75
+ end
76
+
77
+ it "should properly ask to stop instances" do
78
+ expect{subject.execute}.to raise_error(StandardError)
79
+ end
80
+ end
81
+
82
+ context "when there are no stoppable instances" do
83
+ let(:instance1) do
84
+ double(:instance,
85
+ name: "instance1",
86
+ layer_ids: [ "456" ],
87
+ status: "stopped",
88
+ elastic_ip: nil,
89
+ instance_id: "123",
90
+ hostname: "instance1"
91
+ )
92
+ end
93
+
94
+ it "should not stop any instances" do
95
+ expect(opsworks_adapter).not_to receive(:stop_instance)
96
+ subject.execute
97
+ end
98
+ end
99
+ end
100
+ end
@@ -66,5 +66,55 @@ describe Opsicle::Questionnaire::EipInquiry do
66
66
  it "should return a single instance" do
67
67
  expect(instance_response).to eq("instance-id")
68
68
  end
69
+
70
+ context "when there are no target instances" do
71
+ let(:online_instance_with_eip) do
72
+ double(:instance,
73
+ elastic_ip: true,
74
+ auto_scaling_type: nil,
75
+ status: "stopped",
76
+ hostname: "example",
77
+ instance_id: "instance-id"
78
+ )
79
+ end
80
+
81
+ let(:online_instance_without_eip) do
82
+ double(:instance,
83
+ elastic_ip: nil,
84
+ auto_scaling_type: nil,
85
+ status: "stopped",
86
+ hostname: "example",
87
+ instance_id: "instance-id"
88
+ )
89
+ end
90
+
91
+ let(:stopped_instance) do
92
+ double(:instance,
93
+ elastic_ip: nil,
94
+ auto_scaling_type: nil,
95
+ status: "stopped",
96
+ hostname: "example",
97
+ instance_id: "instance-id"
98
+ )
99
+ end
100
+
101
+ it "should raise an error" do
102
+ expect{subject.which_instance_should_get_eip(eip_info)}.to raise_error(StandardError)
103
+ end
104
+ end
105
+ end
106
+
107
+ describe "#check_for_printable_items" do
108
+ context "when there are instances" do
109
+ it "should not raise an error" do
110
+ expect(subject.send(:check_for_printable_items!, [ 1, 2, 3 ])).to eq(nil)
111
+ end
112
+ end
113
+
114
+ context "when there are no instances" do
115
+ it "should raise an error" do
116
+ expect{subject.send(:check_for_printable_items!, [])}.to raise_error(StandardError)
117
+ end
118
+ end
69
119
  end
70
120
  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: 2.12.3
4
+ version: 2.12.5
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: 2018-08-02 00:00:00.000000000 Z
12
+ date: 2019-01-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk
@@ -255,6 +255,7 @@ files:
255
255
  - spec/opsicle/commands/move_eip_spec.rb
256
256
  - spec/opsicle/commands/ssh_key_spec.rb
257
257
  - spec/opsicle/commands/ssh_spec.rb
258
+ - spec/opsicle/commands/stop_instance_spec.rb
258
259
  - spec/opsicle/commands/update_spec.rb
259
260
  - spec/opsicle/commands/user_profile_info_spec.rb
260
261
  - spec/opsicle/config_spec.rb
@@ -296,7 +297,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
296
297
  version: '0'
297
298
  requirements: []
298
299
  rubyforge_project:
299
- rubygems_version: 2.6.14
300
+ rubygems_version: 2.7.8
300
301
  signing_key:
301
302
  specification_version: 4
302
303
  summary: An opsworks specific abstraction on top of the aws sdk
@@ -323,6 +324,7 @@ test_files:
323
324
  - spec/opsicle/commands/list_spec.rb
324
325
  - spec/opsicle/commands/ssh_key_spec.rb
325
326
  - spec/opsicle/commands/update_spec.rb
327
+ - spec/opsicle/commands/stop_instance_spec.rb
326
328
  - spec/opsicle/commands/failure_log_spec.rb
327
329
  - spec/opsicle/commands/delete_instance_spec.rb
328
330
  - spec/opsicle/commands/move_eip_spec.rb