Skip to content

Commit

Permalink
Merge pull request #19 from rightscale-cookbooks/st_15_01_pool_valid_…
Browse files Browse the repository at this point in the history
…device_names_for_aws

St 15 01 pool valid device names for aws
  • Loading branch information
Lopaka Delp committed Jan 14, 2015
2 parents 889c244 + 20ddd7d commit 873261d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ rightscale_volume Cookbook CHANGELOG

This file is used to list changes made in each version of the rightscale_volume cookbook.

v1.2.6
------

- On AWS, determine next volume device name based on AWS UserGuide.

v1.2.5
------

Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ group :integration do
gem 'strainer', '~> 3.3.0'
gem 'chefspec', '~> 3.4.0'
gem 'rspec', '~> 2.14.1'
gem 'ohai', '~> 7.4.0'
gem 'travis-lint'
end
33 changes: 18 additions & 15 deletions libraries/provider_rightscale_volume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -814,17 +814,29 @@ def get_next_device(exclusions = [])

"#{controller_type}(#{avail_controller_id}:#{avail_node_id})"

else
elsif node['cloud']['provider'] == 'ec2'

# Get the list of currently used devices
partitions = get_current_devices

# AWS uses xvd as the device type in /proc/partitions
# Root device is /dev/hda on HVM images, but volumes are xvd in /proc/partitions,
# but can be referenced as sd also (mount shows sd) - PS
device_type = 'xvd'

# The AWS EBS documentation recommends using /dev/sd[f-p] for attaching volumes.
#
# http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-attaching-volume.html
#
if node['cloud']['provider'] == "ec2" && partitions.last =~ /^\/dev\/(s|xv)d[a-d][0-9]*$/
partitions << "/dev/#{$1}de"
end
device_letter = ('f'..'p').find { |letter| !partitions.include?("/dev/#{device_type}#{letter}") && !exclusions.include?("/dev/#{device_type}#{letter}") }

raise 'No device names available' unless device_letter

"/dev/#{device_type}#{device_letter}"

else

# Get the list of currently used devices
partitions = get_current_devices

# The current devices are in the form of sda, hda, xvda, etc.
if partitions.first =~ /^\/dev\/([a-z]+d)[a-z]+$/
Expand All @@ -837,16 +849,7 @@ def get_next_device(exclusions = [])

last_device_letter_in_use = $1

if node['cloud']['provider'] == 'ec2' && device_type == 'hd'
# This is probably HVM
hvm = true
# Root device is /dev/hda on HVM images, but volumes are xvd in /proc/partitions,
# but can be referenced as sd also (mount shows sd) - PS
device_type.sub!('hd','xvd')
end

# This is a HVM image, need to start at xvdf at least
letters = hvm ? (['e', last_device_letter_in_use].max .. 'zzz') : (last_device_letter_in_use .. 'zzz')
letters = last_device_letter_in_use .. 'zzz'

# Get the device letter next to the last device letter in use
device_letter = letters.select { |letter| letter != letters.first && !exclusions.include?(letter) }.first
Expand Down
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
license 'Apache 2.0'
description 'Provides a resource to manage volumes on any cloud RightScale supports.'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '1.2.5'
version '1.2.6'

recipe "rightscale_volume::default", "Default recipe for installing required packages/gems."
4 changes: 2 additions & 2 deletions spec/unit_test/provider_rightscale_volume_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -774,9 +774,9 @@ def create_test_volume_type(name, id, size, href)
context "when the cloud provider is ec2" do
it "should not return the device as anything between (s|xv|h)da and (s|xv|h)de" do
node.set['cloud']['provider'] = 'ec2'
provider.stub(:get_current_devices).and_return(['/dev/sda', '/dev/sdb'])
provider.stub(:get_current_devices).and_return(['/dev/xvda', '/dev/xvdb'])
device = provider.send(:get_next_device)
device.should == '/dev/sdf'
device.should == '/dev/xvdf'
end

it "should not return the device as anything between xvda and xvde if the instance is of HVM type" do
Expand Down

0 comments on commit 873261d

Please sign in to comment.