opsicle 2.12.2 → 2.12.3

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
2
  SHA1:
3
- metadata.gz: 6c6b93ef64ca7f88eab52c8ee74dcaf62118e685
4
- data.tar.gz: 9394c8f6bd05cf4488389d61c01009cdd21bd35e
3
+ metadata.gz: 508652e0801f35bc78c6e29e2b990a075b32db81
4
+ data.tar.gz: a43909b2ff893db83f1cddca4624181e02a837c5
5
5
  SHA512:
6
- metadata.gz: 0de83bd629358a9ab0a6855f0232e5b6cd246f02084ec75606218e28cb1737f97fde7477c067931a3df9c1d290b98c7d3ec23348398a070798a4e9c521011ece
7
- data.tar.gz: 1a3c871b0cb9564f62c000a474b16a5719d49b421510b3f69b884f22161700c8eb4e85894c4a06fdf54a97fd021e6ceb3acab0b6969c3e53c412ad65bea858cc
6
+ metadata.gz: e068df9fe0e064989f92f3f5155644c5cf81c15afa6457641469e4bfae5b0bd3643d4a8ab78cb9c468fb8ce894808219fb3171d21db27a2169c8ea113f77554e
7
+ data.tar.gz: 6f168db27328423daddb64558e92fb3e50d7135573535652279bdc2206ce3f5ae80751de767326f68ef8ad9e67d6aee318cfcc3ab00632b08ea5e5a4f40544af
@@ -14,7 +14,7 @@ module Opsicle
14
14
  @ec2_adapter = Ec2Adapter.new(@client)
15
15
  @opsworks_adapter = OpsworksAdapter.new(@client)
16
16
  stack_id = @client.config.opsworks_config[:stack_id]
17
- @stack = ManageableStack.new(stack_id, @opsworks_adapter.client)
17
+ @stack = ManageableStack.new(stack_id, @opsworks_adapter)
18
18
  @cli = HighLine.new
19
19
  end
20
20
 
@@ -32,7 +32,7 @@ module Opsicle
32
32
 
33
33
  def select_layer
34
34
  puts "\nLayers:\n"
35
- ops_layers = @opsworks_adapter.get_layers(@stack.id)
35
+ ops_layers = @opsworks_adapter.layers(@stack.id)
36
36
 
37
37
  layers = []
38
38
  ops_layers.each do |layer|
@@ -14,7 +14,7 @@ module Opsicle
14
14
  @ec2_adapter = Ec2Adapter.new(@client)
15
15
  @opsworks_adapter = OpsworksAdapter.new(@client)
16
16
  stack_id = @client.config.opsworks_config[:stack_id]
17
- @stack = ManageableStack.new(stack_id, @opsworks_adapter.client)
17
+ @stack = ManageableStack.new(stack_id, @opsworks_adapter)
18
18
  @cli = HighLine.new
19
19
  end
20
20
 
@@ -38,7 +38,7 @@ module Opsicle
38
38
 
39
39
  def select_layer
40
40
  puts "\nLayers:\n"
41
- ops_layers = @opsworks_adapter.get_layers(@stack.id)
41
+ ops_layers = @opsworks_adapter.layers(@stack.id)
42
42
 
43
43
  layers = []
44
44
  ops_layers.each do |layer|
@@ -14,7 +14,7 @@ module Opsicle
14
14
  @ec2_adapter = Ec2Adapter.new(@client)
15
15
  @opsworks_adapter = OpsworksAdapter.new(@client)
16
16
  stack_id = @client.config.opsworks_config[:stack_id]
17
- @stack = ManageableStack.new(stack_id, @opsworks_adapter.client)
17
+ @stack = ManageableStack.new(stack_id, @opsworks_adapter)
18
18
  @cli = HighLine.new
19
19
  end
20
20
 
@@ -33,7 +33,7 @@ module Opsicle
33
33
 
34
34
  def select_layer
35
35
  puts "\nLayers:\n"
36
- ops_layers = @opsworks_adapter.get_layers(@stack.id)
36
+ ops_layers = @opsworks_adapter.layers(@stack.id)
37
37
 
38
38
  layers = []
39
39
  ops_layers.each do |layer|
@@ -14,7 +14,7 @@ module Opsicle
14
14
  @ec2_adapter = Ec2Adapter.new(@client)
15
15
  @opsworks_adapter = OpsworksAdapter.new(@client)
16
16
  stack_id = @client.config.opsworks_config[:stack_id]
17
- @stack = ManageableStack.new(stack_id, @opsworks_adapter.client)
17
+ @stack = ManageableStack.new(stack_id, @opsworks_adapter)
18
18
  @cli = HighLine.new
19
19
  end
20
20
 
@@ -38,7 +38,7 @@ module Opsicle
38
38
 
39
39
  def select_layer
40
40
  puts "\nLayers:\n"
41
- ops_layers = @opsworks_adapter.get_layers(@stack.id)
41
+ ops_layers = @opsworks_adapter.layers(@stack.id)
42
42
 
43
43
  layers = []
44
44
  ops_layers.each do |layer|
@@ -4,21 +4,37 @@ require "opsicle/opsworks_adapter"
4
4
  require "opsicle/manageable_layer"
5
5
  require "opsicle/manageable_instance"
6
6
  require "opsicle/manageable_stack"
7
+ require "opsicle/questionnaire/eip_inquiry"
7
8
 
8
9
  module Opsicle
9
10
  class MoveEip
10
11
 
11
12
  def initialize(environment)
12
13
  @client = Client.new(environment)
13
- @opsworks_adpater = OpsworksAdapter.new(@client)
14
+ @opsworks_adapter = OpsworksAdapter.new(@client)
14
15
  stack_id = @client.config.opsworks_config[:stack_id]
15
16
  @cli = HighLine.new
16
- @stack = ManageableStack.new(stack_id, @opsworks_adpater.client, @cli)
17
+ @stack = ManageableStack.new(stack_id, @opsworks_adapter, @cli)
18
+
19
+ @eip_inquiry = Questionnaire::EipInquiry.new(
20
+ opsworks_adapter: @opsworks_adapter,
21
+ highline_client: @cli
22
+ )
17
23
  end
18
24
 
19
25
  def execute(options={})
20
26
  puts "Stack ID = #{@stack.id}"
21
- @stack.move_eip
27
+ moved_values = move_eip
28
+ puts "\nEIP #{moved_values[:ip_address]} was moved to instance #{moved_values[:target_instance_id]}"
29
+ end
30
+
31
+ def move_eip
32
+ eip_information = @stack.eips
33
+ moveable_eip = @eip_inquiry.which_eip_should_move(eip_information)
34
+ target_instance_id = @eip_inquiry.which_instance_should_get_eip(moveable_eip)
35
+ @stack.transfer_eip(moveable_eip, target_instance_id)
36
+ { ip_address: moveable_eip[:ip_address], target_instance_id: target_instance_id }
22
37
  end
38
+ private :move_eip
23
39
  end
24
40
  end
@@ -14,7 +14,7 @@ module Opsicle
14
14
  @ec2_adapter = Ec2Adapter.new(@client)
15
15
  @opsworks_adapter = OpsworksAdapter.new(@client)
16
16
  stack_id = @client.config.opsworks_config[:stack_id]
17
- @stack = ManageableStack.new(stack_id, @opsworks_adapter.client)
17
+ @stack = ManageableStack.new(stack_id, @opsworks_adapter)
18
18
  @cli = HighLine.new
19
19
  end
20
20
 
@@ -38,7 +38,7 @@ module Opsicle
38
38
 
39
39
  def select_layer
40
40
  puts "\nLayers:\n"
41
- ops_layers = @opsworks_adapter.get_layers(@stack.id)
41
+ ops_layers = @opsworks_adapter.layers(@stack.id)
42
42
 
43
43
  layers = []
44
44
  ops_layers.each do |layer|
@@ -1,34 +1,28 @@
1
1
  module Opsicle
2
2
  class ManageableStack
3
- attr_accessor :id, :opsworks, :stack, :vpc_id, :eips, :cli
3
+ attr_accessor :id, :opsworks_adapter, :stack, :vpc_id, :eips, :cli
4
4
 
5
- def initialize(stack_id, opsworks, cli=nil)
5
+ STOPPABLE_STATES = %w(start_failed stop_failed online running_setup setup_failed booting rebooting)
6
+
7
+ def initialize(stack_id, opsworks_adapter, cli=nil)
6
8
  self.id = stack_id
7
- self.opsworks = opsworks
9
+ self.opsworks_adapter = opsworks_adapter
8
10
  self.cli = cli
9
- self.stack = get_stack
11
+ self.stack = @opsworks_adapter.stack(id)
10
12
  self.vpc_id = self.stack.vpc_id
11
- self.eips = nil
12
- end
13
-
14
- def get_stack
15
- @opsworks.describe_stacks({ :stack_ids => [self.id.to_s] }).stacks.first
16
- end
17
-
18
- def get_eips
19
- self.eips = @opsworks.describe_elastic_ips(stack_id: self.id.to_s).elastic_ips
20
13
  end
21
14
 
22
- def gather_eip_information
15
+ def eips
16
+ eips = @opsworks_adapter.elastic_ips(id)
23
17
  eip_information = []
24
18
 
25
- @eips.each do |eip|
19
+ eips.each do |eip|
26
20
  next unless eip.instance_id
27
21
  instance_id = eip.instance_id
28
- instance = @opsworks.describe_instances(instance_ids: [instance_id]).instances.first
22
+ instance = @opsworks_adapter.instance(instance_id)
29
23
  instance_name = instance.hostname
30
24
  layer_id = instance.layer_ids.first
31
- layer = @opsworks.describe_layers(layer_ids: [layer_id]).layers.first
25
+ layer = @opsworks_adapter.layer(layer_id)
32
26
  layer_name = layer.name
33
27
  eip_information << { eip: eip, ip_address: eip.ip, instance_name: instance_name, layer_id: layer_id }
34
28
  end
@@ -36,49 +30,28 @@ module Opsicle
36
30
  eip_information
37
31
  end
38
32
 
39
- def ask_which_eip_to_move(eip_information)
40
- puts "\nHere are all of the EIPs for this stack:"
41
- eip_information.each_with_index { |h, index| puts "#{index.to_i + 1}) #{h[:ip_address]} connected to #{h[:instance_name]}" }
42
- eip_index = @cli.ask("Which EIP would you like to move?\n", Integer) { |q| q.in = 1..eip_information.length.to_i } - 1
43
- eip_information[eip_index]
44
- end
45
-
46
- def ask_which_target_instance(moveable_eip)
47
- puts "\nHere are all of the instances in the current instance's layer:"
48
- instances = @opsworks.describe_instances(layer_id: moveable_eip[:layer_id]).instances
49
- instances = instances.select { |instance| instance.elastic_ip.nil? && instance.auto_scaling_type.nil? }
50
- instances.each_with_index { |instance, index| puts "#{index.to_i + 1}) #{instance.status} - #{instance.hostname}" }
51
- instance_index = @cli.ask("What is your target instance?\n", Integer) { |q| q.in = 1..instances.length.to_i } - 1
52
- instances[instance_index].instance_id
53
- end
54
-
55
33
  def transfer_eip(moveable_eip, target_instance_id)
56
- @opsworks.associate_elastic_ip({ elastic_ip: moveable_eip[:ip_address], instance_id: target_instance_id })
57
- puts "\nEIP #{moveable_eip[:ip_address]} was moved to instance #{target_instance_id}"
58
- end
59
-
60
- def move_eip
61
- get_eips
62
- eip_information = gather_eip_information
63
- moveable_eip = ask_which_eip_to_move(eip_information)
64
- target_instance_id = ask_which_target_instance(moveable_eip)
65
- transfer_eip(moveable_eip, target_instance_id)
34
+ @opsworks_adapter.associate_elastic_ip(moveable_eip[:ip_address], target_instance_id)
66
35
  end
67
36
 
68
37
  def instances
69
- @opsworks.describe_instances(stack_id: self.id).instances
38
+ @opsworks_adapter.instances_by_stack(id)
70
39
  end
71
40
 
72
41
  def deleteable_instances(layer)
73
- instances.select{ |instance| instance.auto_scaling_type.nil? && instance.status == "stopped" && instance.layer_ids.include?(layer.layer_id) }
74
- end
75
-
76
- def stoppable_states
77
- %w(start_failed stop_failed online running_setup setup_failed booting rebooting)
42
+ instances.select do |instance|
43
+ instance.auto_scaling_type.nil? &&
44
+ instance.status == "stopped" &&
45
+ instance.layer_ids.include?(layer.layer_id)
46
+ end
78
47
  end
79
48
 
80
49
  def stoppable_instances(layer)
81
- instances.select{ |instance| instance.elastic_ip.nil? && stoppable_states.include?(instance.status) && instance.layer_ids.include?(layer.layer_id) }
50
+ instances.select do |instance|
51
+ instance.elastic_ip.nil? &&
52
+ STOPPABLE_STATES.include?(instance.status) &&
53
+ instance.layer_ids.include?(layer.layer_id)
54
+ end
82
55
  end
83
56
  end
84
57
  end
@@ -1,14 +1,45 @@
1
1
  class Opsicle::OpsworksAdapter
2
2
  attr_reader :client
3
3
 
4
- def initialize(client)
5
- @client = client.opsworks
4
+ def initialize(opsicle_client)
5
+ @client = opsicle_client.opsworks
6
6
  end
7
7
 
8
- def get_layers(stack_id)
8
+ def stack(stack_id)
9
+ client.describe_stacks(stack_ids: [ stack_id ]).stacks.first
10
+ end
11
+
12
+ def layers(stack_id)
9
13
  client.describe_layers(stack_id: stack_id).layers
10
14
  end
11
15
 
16
+ def layer(layer_id)
17
+ client.describe_layers(layer_ids: [ layer_id ]).layers.first
18
+ end
19
+
20
+ def instances_by_stack(stack_id)
21
+ client.describe_instances(stack_id: stack_id).instances
22
+ end
23
+
24
+ def instances_by_layer(layer_id)
25
+ client.describe_instances(layer_id: layer_id).instances
26
+ end
27
+
28
+ def instance(instance_id)
29
+ client.describe_instances(instance_ids: [ instance_id ]).instances.first
30
+ end
31
+
32
+ def elastic_ips(stack_id)
33
+ client.describe_elastic_ips(stack_id: stack_id).elastic_ips
34
+ end
35
+
36
+ def associate_elastic_ip(elastic_ip, target_instance_id)
37
+ client.associate_elastic_ip(
38
+ elastic_ip: elastic_ip,
39
+ instance_id: target_instance_id
40
+ )
41
+ end
42
+
12
43
  def start_instance(instance_id)
13
44
  client.start_instance(instance_id: instance_id)
14
45
  end
@@ -0,0 +1,48 @@
1
+ module Opsicle
2
+ module Questionnaire
3
+ class EipInquiry
4
+ attr_accessor :opsworks_adapter, :cli
5
+
6
+ def initialize(options)
7
+ self.opsworks_adapter = options[:opsworks_adapter]
8
+ self.cli = options[:highline_client]
9
+ end
10
+
11
+ def which_eip_should_move(eip_information)
12
+ puts "\nHere are all of the EIPs for this stack:"
13
+ print_current_eips(eip_information)
14
+ eip_index = ask_eip_question("Which EIP would you like to move?\n", eip_information)
15
+ eip_information[eip_index]
16
+ end
17
+
18
+ def which_instance_should_get_eip(moveable_eip)
19
+ puts "\nHere are all of the instances in the current instance's layer:"
20
+ instances = get_potential_target_instances(moveable_eip)
21
+ print_potential_target_instances(instances)
22
+ instance_index = ask_eip_question("What is your target instance?\n", instances)
23
+ instances[instance_index].instance_id
24
+ end
25
+
26
+ def ask_eip_question(prompt, choices)
27
+ @cli.ask(prompt, Integer) { |q| q.in = 1..choices.length.to_i } - 1
28
+ end
29
+ private :ask_eip_question
30
+
31
+ def print_current_eips(eip_information)
32
+ eip_information.each_with_index { |eip, index| puts "#{index.to_i + 1}) #{eip[:ip_address]} connected to #{eip[:instance_name]}" }
33
+ end
34
+ private :print_current_eips
35
+
36
+ def print_potential_target_instances(instances)
37
+ instances.each_with_index { |instance, index| puts "#{index.to_i + 1}) #{instance.status} - #{instance.hostname}" }
38
+ end
39
+ private :print_potential_target_instances
40
+
41
+ def get_potential_target_instances(moveable_eip)
42
+ instances = @opsworks_adapter.instances_by_layer(moveable_eip[:layer_id])
43
+ instances.select { |instance| instance.elastic_ip.nil? && instance.auto_scaling_type.nil? }
44
+ end
45
+ private :get_potential_target_instances
46
+ end
47
+ end
48
+ end
@@ -1,3 +1,3 @@
1
1
  module Opsicle
2
- VERSION = "2.12.2"
2
+ VERSION = "2.12.3"
3
3
  end
@@ -0,0 +1,47 @@
1
+ describe Opsicle::MoveEip do
2
+ let(:old_eip) { 'old_eip' }
3
+ let(:target_instance) { 'target_instance' }
4
+ let(:opsworks_eip) { double(:eip, ip: "123", instance_id: "1234") }
5
+ let(:opsworks_stack) { double(:stack, id: "1234", vpc_id: "21") }
6
+ let(:config) { double(:config, opsworks_config: {stack_id: "123"}) }
7
+ let(:opsicle_client) { double(:client, config: config, opsworks: opsworks_client) }
8
+
9
+ let(:opsworks_client) do
10
+ double(:opsworks_client,
11
+ associate_elastic_ip: true,
12
+ describe_stacks: double(stack: [opsworks_stack])
13
+ )
14
+ end
15
+
16
+ let(:opsworks_adapter) do
17
+ double(:opsworks_adapter,
18
+ client: opsworks_client,
19
+ stack: opsworks_stack,
20
+ elastic_ips: [opsworks_eip, opsworks_eip],
21
+ instance: double(hostname: 'hostname', layer_ids: ['layer_id']),
22
+ layer: double(name: 'layer_name')
23
+ )
24
+ end
25
+
26
+ let(:eip_inquiry) do
27
+ double(:eip_inquiry,
28
+ which_eip_should_move: { ip_address: old_eip },
29
+ which_instance_should_get_eip: target_instance
30
+ )
31
+ end
32
+
33
+ before do
34
+ allow(Opsicle::Client).to receive(:new).with("staging").and_return(opsicle_client)
35
+ allow(Opsicle::OpsworksAdapter).to receive(:new).and_return(opsworks_adapter)
36
+ allow(Opsicle::Questionnaire::EipInquiry).to receive(:new).and_return(eip_inquiry)
37
+ end
38
+
39
+ subject { described_class.new("staging") }
40
+
41
+ describe "#execute" do
42
+ it "should make an API call to opsworks to change the EIP" do
43
+ expect(opsworks_adapter).to receive(:associate_elastic_ip).with(old_eip, target_instance)
44
+ subject.execute
45
+ end
46
+ end
47
+ end
@@ -1,23 +1,96 @@
1
- require "spec_helper"
2
- require "opsicle"
3
- require 'gli'
4
- require "opsicle/user_profile"
5
-
6
- module Opsicle
7
- describe ManageableStack do
8
- before do
9
- @stack = double('stack', :vpc_id => 'vpc-123456')
10
- @stacks = double('stacks', :stacks => [@stack])
11
- @opsworks = double('opsworks', :describe_stacks => @stacks)
1
+ describe Opsicle::ManageableStack do
2
+ let(:deleteable_instance) do
3
+ double(:deleteable_instance,
4
+ auto_scaling_type: nil,
5
+ status: "stopped",
6
+ layer_ids: ["456"],
7
+ elastic_ip: nil,
8
+ hostname: "example-hostname"
9
+ )
10
+ end
11
+
12
+ let(:stoppable_instance) do
13
+ double(:stoppable_instance,
14
+ elastic_ip: nil,
15
+ status: "start_failed",
16
+ layer_ids: ["456"],
17
+ auto_scaling_type: nil
18
+ )
19
+ end
20
+
21
+ let(:stack) { double(:stack, vpc_id: "id") }
22
+
23
+ let(:layer) do
24
+ double(:layer,
25
+ layer_id: "456",
26
+ name: "layername"
27
+ )
28
+ end
29
+
30
+ let(:eip) do
31
+ double(:eip,
32
+ instance_id: "123",
33
+ ip: "ip-123",
34
+ )
35
+ end
36
+
37
+ let(:client) { double(:client, opsworks: aws_opsworks_client) }
38
+
39
+ let(:aws_opsworks_client) do
40
+ double(:aws_opsworks_client,
41
+ describe_stacks: double(:stacks, stacks: [stack]),
42
+ describe_layers: double(:layers, layers: [layer]),
43
+ describe_instances: double(:instances, instances: [deleteable_instance, stoppable_instance]),
44
+ describe_elastic_ips: double(:eips, elastic_ips: [eip]),
45
+ associate_elastic_ip: :associated_eip,
46
+ start_instance: :started,
47
+ stop_instance: :stopped,
48
+ delete_instance: :deleted
49
+ )
50
+ end
51
+
52
+ let(:opsworks_adapter) { Opsicle::OpsworksAdapter.new(client) }
53
+ let(:stack_id) { '123' }
54
+
55
+ subject { described_class.new(stack_id, opsworks_adapter) }
56
+
57
+ describe "#eips" do
58
+ let(:eips) { subject.eips }
59
+
60
+ it "should properly find and format EIPs" do
61
+ expect(eips).to eq([{eip: eip, ip_address: "ip-123", instance_name: "example-hostname", layer_id: "456"}])
12
62
  end
63
+ end
64
+
65
+ describe "#transfer_eip" do
66
+ let(:transfer) { subject.transfer_eip({ip_address: true}, "target_instance_id") }
67
+
68
+ it "should properly transfer the EIP" do
69
+ expect(transfer).to eq(:associated_eip)
70
+ end
71
+ end
72
+
73
+ describe "#instances" do
74
+ let(:instances) { subject.instances }
75
+
76
+ it "should properly gather a list of instances" do
77
+ expect(instances).to eq([deleteable_instance, stoppable_instance])
78
+ end
79
+ end
80
+
81
+ describe "#deleteable_instances" do
82
+ let(:instances) { subject.deleteable_instances(layer) }
83
+
84
+ it "should look for any instances that are deleteable" do
85
+ expect(instances).to eq([deleteable_instance])
86
+ end
87
+ end
88
+
89
+ describe "#stoppable_instances" do
90
+ let(:instances) { subject.stoppable_instances(layer) }
13
91
 
14
- context "#get_stack" do
15
- it "should gather opsworks instances for that layer" do
16
- stack = ManageableStack.new(12345, @opsworks)
17
- expect(@opsworks).to receive(:describe_stacks).and_return(@stacks)
18
- expect(@stacks).to receive(:stacks)
19
- stack.get_stack
20
- end
92
+ it "should look for any instances that are stoppable" do
93
+ expect(instances).to eq([stoppable_instance])
21
94
  end
22
95
  end
23
96
  end
@@ -1,7 +1,11 @@
1
1
  describe Opsicle::OpsworksAdapter do
2
2
  let(:aws_opsworks_client) do
3
3
  double(:aws_opsworks_client,
4
- describe_layers: double(:layers, layers: []),
4
+ describe_stacks: double(:stacks, stacks: [:stack_one]),
5
+ describe_layers: double(:layers, layers: [:layer_one]),
6
+ describe_instances: double(:instances, instances: [:instance_one]),
7
+ describe_elastic_ips: double(:eips, elastic_ips: []),
8
+ associate_elastic_ip: :associated_eip,
5
9
  start_instance: :started,
6
10
  stop_instance: :stopped,
7
11
  delete_instance: :deleted
@@ -11,11 +15,67 @@ describe Opsicle::OpsworksAdapter do
11
15
 
12
16
  subject { described_class.new(client) }
13
17
 
14
- describe "#get_layers" do
15
- let(:get_layers) { subject.get_layers(:stack_id) }
18
+ describe "#stack" do
19
+ let(:stack) { subject.stack(:stack_id) }
20
+
21
+ it "should return the stack in question" do
22
+ expect(stack).to eq(:stack_one)
23
+ end
24
+ end
25
+
26
+ describe "#layers" do
27
+ let(:layers) { subject.layers(:stack_id) }
16
28
 
17
29
  it "should gather an array of layers for this opsworks client" do
18
- expect(get_layers).to be_empty
30
+ expect(layers).to eq([:layer_one])
31
+ end
32
+ end
33
+
34
+ describe "#layer" do
35
+ let (:layer) { subject.layer(:layer_id) }
36
+
37
+ it "should get the layer in question" do
38
+ expect(layer).to eq(:layer_one)
39
+ end
40
+ end
41
+
42
+ describe "#instances_by_stack" do
43
+ let (:instances) { subject.instances_by_stack(:stack_id) }
44
+
45
+ it "should get a list of instances in the stack" do
46
+ expect(instances).to eq([:instance_one])
47
+ end
48
+ end
49
+
50
+ describe "#instances_by_layer" do
51
+ let (:instances) { subject.instances_by_layer(:layer_id) }
52
+
53
+ it "should get a list of instances in the_layer" do
54
+ expect(instances).to eq([:instance_one])
55
+ end
56
+ end
57
+
58
+ describe "#instance" do
59
+ let (:instance) { subject.instance(:instance_id) }
60
+
61
+ it "should get the instance in question" do
62
+ expect(instance).to eq(:instance_one)
63
+ end
64
+ end
65
+
66
+ describe "#elastic_ips" do
67
+ let (:eips) { subject.elastic_ips(:stack_id) }
68
+
69
+ it "should get a list of the EIPs in the stack" do
70
+ expect(eips).to be_empty
71
+ end
72
+ end
73
+
74
+ describe "#associate_elastic_ip" do
75
+ let (:associated) { subject.associate_elastic_ip(:eip, :target_instance_id) }
76
+
77
+ it "should get a list of the EIPs in the stack" do
78
+ expect(associated).to be(:associated_eip)
19
79
  end
20
80
  end
21
81
 
@@ -0,0 +1,70 @@
1
+ describe Opsicle::Questionnaire::EipInquiry do
2
+ let(:cli) { double(:cli, ask: 1) }
3
+
4
+ let(:online_instance_with_eip) do
5
+ double(:instance,
6
+ elastic_ip: true,
7
+ auto_scaling_type: nil,
8
+ status: "online",
9
+ hostname: "example",
10
+ instance_id: "instance-id"
11
+ )
12
+ end
13
+
14
+ let(:online_instance_without_eip) do
15
+ double(:instance,
16
+ elastic_ip: nil,
17
+ auto_scaling_type: nil,
18
+ status: "online",
19
+ hostname: "example",
20
+ instance_id: "instance-id"
21
+ )
22
+ end
23
+
24
+ let(:stopped_instance) do
25
+ double(:instance,
26
+ elastic_ip: nil,
27
+ auto_scaling_type: nil,
28
+ status: "stopped",
29
+ hostname: "example",
30
+ instance_id: "instance-id"
31
+ )
32
+ end
33
+
34
+ let(:client) { double(:client, opsworks: aws_opsworks_client) }
35
+
36
+ let(:aws_opsworks_client) do
37
+ double(:aws_opsworks_client,
38
+ describe_instances: double(:instances, instances: [online_instance_with_eip, online_instance_without_eip, stopped_instance])
39
+ )
40
+ end
41
+
42
+ let(:opsworks_adapter) { Opsicle::OpsworksAdapter.new(client) }
43
+
44
+ let(:eip_info) do
45
+ { eip: true, ip_address: "ip-123", instance_name: "example-hostname", layer_id: "id1" }
46
+ end
47
+
48
+ subject { described_class.new(opsworks_adapter: opsworks_adapter, highline_client: cli) }
49
+
50
+ describe "#which_eip_should_move" do
51
+ let(:eip_response) { subject.which_eip_should_move([eip_info]) }
52
+
53
+ it "should ask the user a question" do
54
+ expect(cli).to receive(:ask)
55
+ subject.which_eip_should_move([eip_info])
56
+ end
57
+
58
+ it "should return the EIP to move" do
59
+ expect(eip_response).to eq(eip_info)
60
+ end
61
+ end
62
+
63
+ describe "#which_instance_should_get_eip" do
64
+ let(:instance_response) { subject.which_instance_should_get_eip(eip_info) }
65
+
66
+ it "should return a single instance" do
67
+ expect(instance_response).to eq("instance-id")
68
+ end
69
+ end
70
+ end
@@ -15,4 +15,5 @@ RSpec.configure do |config|
15
15
  # the seed, which is printed after each run.
16
16
  # --seed 1234
17
17
  config.order = 'random'
18
+ config.filter_run focus: true
18
19
  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.2
4
+ version: 2.12.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Fleener
@@ -238,6 +238,7 @@ files:
238
238
  - lib/opsicle/monitor/translatable.rb
239
239
  - lib/opsicle/opsworks_adapter.rb
240
240
  - lib/opsicle/output.rb
241
+ - lib/opsicle/questionnaire/eip_inquiry.rb
241
242
  - lib/opsicle/s3_bucket.rb
242
243
  - lib/opsicle/stack.rb
243
244
  - lib/opsicle/user_profile.rb
@@ -251,6 +252,7 @@ files:
251
252
  - spec/opsicle/commands/failure_log_spec.rb
252
253
  - spec/opsicle/commands/list_instances_spec.rb
253
254
  - spec/opsicle/commands/list_spec.rb
255
+ - spec/opsicle/commands/move_eip_spec.rb
254
256
  - spec/opsicle/commands/ssh_key_spec.rb
255
257
  - spec/opsicle/commands/ssh_spec.rb
256
258
  - spec/opsicle/commands/update_spec.rb
@@ -270,6 +272,7 @@ files:
270
272
  - spec/opsicle/monitor/subpanel_spec.rb
271
273
  - spec/opsicle/opsworks_adapter_spec.rb
272
274
  - spec/opsicle/output_spec.rb
275
+ - spec/opsicle/questionnaire/eip_inquiry_spec.rb
273
276
  - spec/opsicle/s3_bucket_spec.rb
274
277
  - spec/opsicle/user_profile_spec.rb
275
278
  - spec/spec_helper.rb
@@ -311,6 +314,7 @@ test_files:
311
314
  - spec/opsicle/manageable_stack_spec.rb
312
315
  - spec/opsicle/s3_bucket_spec.rb
313
316
  - spec/opsicle/manageable_layer_spec.rb
317
+ - spec/opsicle/questionnaire/eip_inquiry_spec.rb
314
318
  - spec/opsicle/opsworks_adapter_spec.rb
315
319
  - spec/opsicle/ec2_adapter_spec.rb
316
320
  - spec/opsicle/commands/deploy_spec.rb
@@ -321,6 +325,7 @@ test_files:
321
325
  - spec/opsicle/commands/update_spec.rb
322
326
  - spec/opsicle/commands/failure_log_spec.rb
323
327
  - spec/opsicle/commands/delete_instance_spec.rb
328
+ - spec/opsicle/commands/move_eip_spec.rb
324
329
  - spec/opsicle/commands/list_instances_spec.rb
325
330
  - spec/opsicle/commands/execute_recipes_spec.rb
326
331
  - spec/opsicle/commands/ssh_spec.rb