diff --git a/CHANGELOG.md b/CHANGELOG.md index aebdd7d..1826283 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ------ diff --git a/Gemfile b/Gemfile index 44a282b..227d3a8 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/libraries/provider_rightscale_volume.rb b/libraries/provider_rightscale_volume.rb index 4d71e9e..bbb5c17 100644 --- a/libraries/provider_rightscale_volume.rb +++ b/libraries/provider_rightscale_volume.rb @@ -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]+$/ @@ -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 diff --git a/metadata.rb b/metadata.rb index d2a0aa7..ee0a830 100644 --- a/metadata.rb +++ b/metadata.rb @@ -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." diff --git a/spec/unit_test/provider_rightscale_volume_spec.rb b/spec/unit_test/provider_rightscale_volume_spec.rb index fee2833..7fff822 100644 --- a/spec/unit_test/provider_rightscale_volume_spec.rb +++ b/spec/unit_test/provider_rightscale_volume_spec.rb @@ -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