Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improper alignment in "knife ec2 flavor list" command #490

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ knife ec2 ami list
### `knife ec2 server list`
Outputs a list of all servers in the currently configured AWS account. **Note, this shows all instances associated with the account, some of which may not be currently managed by the Chef server.**

### `knife ec2 flavor list`
Outputs a list of all instance types comprising varying combinations of CPU, memory, storage, and architecture capacity of the currently configured AWS account. **Note, this shows all instances type associated with the account.**

### `knife ec2 server delete`
Deletes an existing server in the currently configured AWS account. **By default, this does not delete the associated node and client objects from the Chef server. To do so, add the `--purge` flag**

Expand Down
19 changes: 14 additions & 5 deletions lib/chef/knife/ec2_flavor_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Ec2FlavorList < Knife
def run

validate!
custom_warnings!

flavor_list = [
ui.color('ID', :bold),
Expand All @@ -37,8 +38,16 @@ def run
ui.color('RAM', :bold),
ui.color('Disk', :bold),
ui.color('Cores', :bold)
]
flavors = connection.flavors.sort_by(&:id)
].flatten.compact

output_column_count = flavor_list.length

begin
flavors = connection.flavors.sort_by(&:id)
rescue Exception => api_error
raise api_error
end

if (config[:format] == 'summary')
flavors.each do |flavor|
flavor_list << flavor.id.to_s
Expand All @@ -48,10 +57,10 @@ def run
flavor_list << "#{flavor.disk.to_s} GB"
flavor_list << flavor.cores.to_s
end
puts ui.list(flavor_list, :columns_across, 6)
else
puts ui.list(flavor_list, :uneven_columns_across, output_column_count)
else
output(format_for_display(flavors))
end
end
end
end
end
Expand Down
17 changes: 14 additions & 3 deletions spec/unit/ec2_flavor_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
let(:ec2_connection) { double(Fog::Compute::AWS) }
before do
allow(knife_flavor_list).to receive(:connection).and_return(ec2_connection)
@flavor1 = double("flavor1", :name => "High-CPU Medium", :architecture => "32-bit-bit", :id => "c1.medium", :bits => "32-bit", :cores => "5", :disk => "1740.8 GB", :ram => "350 GB", :ebs_optimized_available => "false", :instance_store_volumes => "0")
@flavor1 = double("flavor1", :name => "High-CPU Medium", :architecture => "32", :id => "c1.medium", :bits => "32", :cores => "5", :ram => "1740.8", :disk => "350", :ebs_optimized_available => "false", :instance_store_volumes => "0")

allow(ec2_connection).to receive(:flavors).and_return([@flavor1])

Expand All @@ -39,18 +39,29 @@
knife_flavor_list.run
end

context 'when region is not specified' do
it 'shows warning that default region will be will be used' do
knife_flavor_list.config.delete(:region)
Chef::Config[:knife].delete(:region)
ec2_flavors = double(:sort_by => [])
allow(ec2_connection).to receive(:flavors).and_return(ec2_flavors)
allow(knife_flavor_list).to receive(:validate!)
expect(knife_flavor_list.ui).to receive(:warn).with("No region was specified in knife.rb or as an argument. The default region, us-east-1, will be used:")
knife_flavor_list.run
end
end

context '--format option' do
context 'when format=summary' do
before do
@output_s=["ID", "Name", "Architecture", "RAM", "Disk", "Cores", "c1.medium", "High-CPU Medium", "32-bit-bit", "350 GB", "1740.8 GB GB", "5"]
@output_s=["ID", "Name", "Architecture", "RAM", "Disk", "Cores", "c1.medium", "High-CPU Medium", "32-bit", "1740.8", "350 GB", "5"]
knife_flavor_list.config[:format] = 'summary'
allow(knife_flavor_list.ui).to receive(:warn)
allow(knife_flavor_list).to receive(:validate!)
end

it 'shows the output in summary format' do
expect(knife_flavor_list.ui).to receive(:list).with(@output_s,:columns_across,6)
expect(knife_flavor_list.ui).to receive(:list).with(@output_s, :uneven_columns_across, 6)
knife_flavor_list.run
end
end
Expand Down