Skip to content

Commit

Permalink
Ensure root device lookup picks the exact match if it exists
Browse files Browse the repository at this point in the history
- This handles a theoretical case where both `/dev/sda` and `/dev/sda1` are listed
  in block devices, we want to choose the exact match

[#134734789](https://www.pivotaltracker.com/story/show/134734789)
  • Loading branch information
ljfranklin committed Nov 23, 2016
1 parent a3fc87f commit e898fee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/bosh_aws_cpi/lib/cloud/aws/block_device_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,17 @@ def default_root_disk_mapping

def root_device_name
if @root_device_name
# covers two cases:
# 1. root and block device match exactly
# 2. root is a partition and block device is the entire device
# e.g. root == /dev/sda1 and block device == /dev/sda
block_device_to_override = (@ami_block_device_names || {}).find do |name|
# covers two cases:
# 1. root and block device match exactly
# 2. root is a partition and block device is the entire device
# e.g. root == /dev/sda1 and block device == /dev/sda
@root_device_name == name
end
block_device_to_override ||= (@ami_block_device_names || {}).find do |name|
@root_device_name.start_with?(name)
end

return block_device_to_override if block_device_to_override
end

Expand Down
2 changes: 1 addition & 1 deletion src/bosh_aws_cpi/spec/unit/instance_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ module Bosh::AwsCloud
stemcell_id => instance_double('AWS::EC2::Image',
block_devices: block_devices,
root_device_name: 'fake-image-root-device',
block_device_mappings: { 'fake-image-root-device': {} },
block_device_mappings: { 'fake-image-root-device' => {} },
virtualization_type: :hvm
)
})
Expand Down

0 comments on commit e898fee

Please sign in to comment.