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

Enable dynamic cloud volume modifications #177

Merged
merged 1 commit into from
Mar 20, 2017

Conversation

gberginc
Copy link
Contributor

Recently Amazon introduced a capability to modify existing cloud volumes
on the fly. Depending on the volume type size, volume type and IOPS can
be modified without detaching the volume first.

This patch enhances the existing update_volume method that previously
allowed changing only the name of the volume by using the new method
#modify_volume from the aws-sdk gem. The patch also adds a set of
tests verifying different possible options passed to the
update_volume.

Depends on #176 (requires newer aws-sdk gem).

@miq-bot add_label enhancement

@@ -13,7 +13,7 @@ Gem::Specification.new do |s|

s.files = Dir["{app,config.lib}/**/*"]

s.add_dependency("aws-sdk", ["~>2.6.14"])
s.add_dependency("aws-sdk", ["~>2.7.8"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you put this in a separate PR - for backporting reasons...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, it's already in #176 👍

@miq-bot
Copy link
Member

miq-bot commented Mar 15, 2017

This pull request is not mergeable. Please rebase and repush.

@gberginc
Copy link
Contributor Author

Since #176 was just merged, I rebased it and removed the gem version bump from this one.

it "is allowed when :name is provided" do
# Name is set via AWS tags so stub the create_tags.
expect_any_instance_of(Aws::EC2::Volume).to receive(:create_tags).with(
:tags => [{:key => "Name", :value => "new_name"}]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can also stub this. add the api calls to with_aws_stubbed below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible, but only to some degree. I wanted to ensure that specific arguments are used as well as check whether the call is made or not (if name is given, it must be called, if it's not given, it should not be called).

What I could do is ignore input parameters to create_tags and then use an exception in the stub to ensure it doesn't get called. I'll have a look.

with_provider_object do |volume|
volume.create_tags(:tags => [{:key => "Name", :value => options[:name]}])
end
res = nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does any caller really care about the return value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not completely sure. Perhaps I just misunderstood what's needed.

modify_opts = {}
if volume_type != 'standard'
modify_opts[:volume_type] = options[:volume_type] if options[:volume_type] && options[:volume_type] != 'standard'
modify_opts[:size] = options[:size] if options[:size] && options[:size] != (size / 1_073_741_824)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something like 1.gigabyte ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, alternative check would be ... && options[:size].gigabyte == size. Database stores the size in bytes, but the :size in options must be in gigabytes.

@gberginc gberginc force-pushed the enable_modify_volume branch 2 times, most recently from 28aa126 to d586e19 Compare March 16, 2017 20:33
@miq-bot
Copy link
Member

miq-bot commented Mar 16, 2017

Checked commit gberginc@d586e19 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
3 files checked, 0 offenses detected
Everything looks good. ⭐

@gberginc
Copy link
Contributor Author

@durandom I've updated the change:

  • use stubs for all tests: in these stubs I have explicitly set exceptions for the calls for which I'd like to ensure they are not called (for example, when :name is not given, it should not call create_tags, so I set the stubbed response to failed to ensure exception is thrown in case the call is made)
  • use gigabyte instead of that ugly number
  • ignore return value of update_volume - it really doesn't seem like it's used somewhere

Copy link
Member

@durandom durandom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gberginc awesome second iteration 👏

besides the options question great

modify_opts = {}
if volume_type != 'standard'
modify_opts[:volume_type] = options[:volume_type] if options[:volume_type] && options[:volume_type] != 'standard'
modify_opts[:size] = options[:size] if options[:size] && options[:size].gigabytes != size
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where does options[:size] come from? Maybe do Integer(options[:size]) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@durandom Thanks for spotting this. So far value of options[:size] came from the UI where I tested only with valid values, however it could also come from API or automate which means that it could in fact be invalid. I added two more tests to ensure that valid and invalid strings work properly with the updated function.

Recently Amazon introduced a capability to modify existing cloud volumes
on the fly. Depending on the volume type size, volume type and IOPS can
be modified without detaching the volume first.

This patch enhances the existing `update_volume` method that previously
allowed changing only the name of the volume by using the new method
`#modify_volume` from the aws-sdk gem. The patch also adds a set of
tests verifying different possible options passed to the
`update_volume`.
@Ladas
Copy link
Contributor

Ladas commented Mar 20, 2017

looks great, very nice specs 👍

@Ladas Ladas added this to the Sprint 57 Ending Mar 27, 2017 milestone Mar 20, 2017
@Ladas Ladas self-assigned this Mar 20, 2017
@Ladas Ladas merged commit 11b9393 into ManageIQ:master Mar 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants