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

Set the location property of managed disks to ensure disk saving #143

Merged
merged 1 commit into from
Oct 24, 2017

Conversation

bronaghs
Copy link

@bronaghs bronaghs commented Oct 20, 2017

This fixes a bug where managed disks are saved to the database when a provider is first added but are deleted upon subsequent refreshes of the same provider.

Background

The saving of instance disks involves creating an array of disks already associated with the VM from the previous refresh, and one by one, each disk is removed as it is saved. What is left is old disks that no longer exist on the VM and will be deleted.
This array of pre-existing disks is created from the VM.disks association which is then indexed using the TypedIndex class.
This indexing uses the location property of a disk as a key. If the location is missing, as is the case with managed disks, that disk will no longer be associated with the instance, will remain in the array of pre-existing disks and will eventually be deleted, see here and here.

Steps to reproduce

  • Add an Azure provider - Make sure at lease one VM has managed data disks.
  • Note the managed disks are saved to the DB
  • Refresh the same provider
  • Note the managed data disk was deleted.

After this PR is merged, the managed data disks will persist after a second refresh.

https://bugzilla.redhat.com/show_bug.cgi?id=1503866

@@ -308,6 +308,7 @@ def populate_hardware_hash_with_disks(hardware_disks_array, instance)
disk_size = disk.respond_to?(:disk_size_gb) ? disk.disk_size_gb * 1.gigabyte : 0
disk_name = disk.name
disk_location = disk.try(:vhd).try(:uri)
disk_location = disk.try(:vhd).try(:uri) || disk.try(:managed_disk).try(:id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you mean to drop the previous line?

@bronaghs
Copy link
Author

@djberg96 - yes.

@djberg96
Copy link
Collaborator

Just thinking out loud here, we run the refresh 2.times right now within the specs, so I'm surprised the current specs didn't pick it up. Were we just not looking for that in particular?

@bronaghs
Copy link
Author

bronaghs commented Oct 23, 2017

@djberg96 - The reason why the spec passes is because the problem only arises when there are 2 or more managed disks on an instance.

@djberg96
Copy link
Collaborator

@bronaghs oh, good catch!

@bronaghs bronaghs changed the title [WIP] Set the location property of managed disks to ensure disk saving Set the location property of managed disks to ensure disk saving Oct 24, 2017
@bronaghs bronaghs added fine/yes and removed wip labels Oct 24, 2017
@miq-bot
Copy link
Member

miq-bot commented Oct 24, 2017

Checked commit bronaghs@e9ff1bc with ruby 2.3.3, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 0 offenses detected
Everything looks fine. 👍

@chessbyte
Copy link
Member

Looks good to me! 👍

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.

👍

@@ -307,7 +307,7 @@ def populate_hardware_hash_with_disks(hardware_disks_array, instance)
data_disks.each do |disk|
disk_size = disk.respond_to?(:disk_size_gb) ? disk.disk_size_gb * 1.gigabyte : 0
disk_name = disk.name
disk_location = disk.try(:vhd).try(:uri)
disk_location = disk.try(:vhd).try(:uri) || disk.try(:managed_disk).try(:id)
Copy link
Member

Choose a reason for hiding this comment

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

|| will get naughty if the first method exists but returns an empty string...
We had that problem 3 times in amazon.

But I guess the azure sdk does a better job here :)

@durandom durandom merged commit 9f0acf6 into ManageIQ:master Oct 24, 2017
@durandom durandom added this to the Sprint 72 Ending Oct 30, 2017 milestone Oct 24, 2017
@bronaghs bronaghs deleted the save_managed_disks branch October 24, 2017 18:42
@simaishi
Copy link
Contributor

@bronaghs Please create a Fine PR for this. Spec files are conflicting a lot, so it's better that gets resolved by you.

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.

7 participants