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

Refactor refresh new target to use save_ems_inventory #14247

Merged
merged 14 commits into from
Jun 16, 2017

Conversation

agrare
Copy link
Member

@agrare agrare commented Mar 9, 2017

By adding the ability for save_ems_inventory to work with a nil target we can delete the specialized save_new_target method which only worked for RHEV VMs and replace it with the general save_ems_inventory method.

Now any links that the caller wants to be made can be made, and any linked inventory that doesn't exist will be created just like a normal save_inventory would, so we can get rid of the specific calls to find or create linked inventory here

cluster = EmsCluster.find_by(:ems_ref => cluster_hash[:ems_ref], :ems_id => ems.id)
if cluster.nil?
rp = ems.resource_pools.create!(rp_hash)
cluster = ems.clusters.create!(cluster_hash)
cluster.add_resource_pool(rp)
cluster.save!

@miq-bot
Copy link
Member

miq-bot commented Mar 9, 2017

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

@agrare agrare force-pushed the refactor_refresh_new_target branch from 055482f to 0de059d Compare March 9, 2017 17:59
@agrare agrare force-pushed the refactor_refresh_new_target branch 2 times, most recently from 7d1e5a1 to addf634 Compare March 9, 2017 18:11
@agrare
Copy link
Member Author

agrare commented Mar 9, 2017

@Fryguy this replaces save_new_target with generic save_ems_inventory for refresh_new_target, what do you think of the mode parameter to control the disconnects? I think it would be cleaner to not do target = ems if target.nil? everywhere but that could have some nasty side-effects if a caller is relying on that.

@miq-bot
Copy link
Member

miq-bot commented Mar 16, 2017

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

@Fryguy
Copy link
Member

Fryguy commented Mar 20, 2017

@Fryguy this replaces save_new_target with generic save_ems_inventory for refresh_new_target, what do you think of the mode parameter to control the disconnects? I think it would be cleaner to not do target = ems if target.nil? everywhere but that could have some nasty side-effects if a caller is relying on that.

It feels quite invasive, so I'm not sure. I can't see any other way to accomplish what you are trying to do though, so I'm good with it.

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.

Looks great, from what I understand :)

TODO: need to rework the RHEV EventParser.parse_new_target to return the correct hash format

so, only RHV is using this currently anyway, right? Could we trigger them to produce a spec for their use case in order to have this PR here failing? I think their refresh_new_target would fail with this merged, right?

@@ -1,5 +1,5 @@
module EmsRefresh::SaveInventory
def save_ems_inventory(ems, hashes, target = nil)
def save_ems_inventory(ems, hashes, target = nil, mode = :refresh)
Copy link
Member

Choose a reason for hiding this comment

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

how about a new method e.g. save_ems_inventory_no_disconnect which just calls save_ems_inventory with a mode other than :refresh. This would save you from a 4-ary method signature like

save_ems_inventory(ems, target_hash, nil, :refresh_new_target)

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea :) I'll give that a try, should clean this up a lot

@agrare
Copy link
Member Author

agrare commented Apr 6, 2017

so, only RHV is using this currently anyway, right?

I'm planning on using it for #14460 as well

Could we trigger them to produce a spec for their use case in order to have this PR here failing

YES! I'm planning on adding a RHEV save_new_target spec using one of their events

I think their refresh_new_target would fail with this merged, right?

Correct this cannot be merged until we update their event parser to work with this format

@miq-bot
Copy link
Member

miq-bot commented Apr 6, 2017

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

@agrare
Copy link
Member Author

agrare commented Apr 18, 2017

Here is the associated ovirt PR ManageIQ/manageiq-providers-ovirt#13
I'll add the tests for the ovirt event parser there, just need the RHV team to get an event hash

@agrare agrare force-pushed the refactor_refresh_new_target branch 4 times, most recently from 2907054 to dae48ee Compare April 19, 2017 13:49
@agrare agrare changed the title [WIP] Refactor refresh new target to use save_ems_inventory Refactor refresh new target to use save_ems_inventory May 10, 2017
@agrare agrare removed the wip label May 10, 2017
@chessbyte
Copy link
Member

@blomquisg bump

def save_resource_pools_inventory(ems, hashes, target = nil)
target = ems if target.nil?
def save_resource_pools_inventory(ems, hashes, target = nil, disconnect = true)
target = ems if target.nil? && disconnect
Copy link
Contributor

Choose a reason for hiding this comment

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

Why && disconnect here and not elsewhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because the disconnect logic for resource pools is more complex than the normal if target == ems then :use_association else []
The target has to be nil if disconnect is true so that we don't hit this case. I had to do the same for hosts and vms because their disconnect logic is special.

@durandom
Copy link
Member

durandom commented Jun 7, 2017

@agrare seems vmware doesnt have parse_new_target?!

@agrare
Copy link
Member Author

agrare commented Jun 7, 2017

@agrare agrare force-pushed the refactor_refresh_new_target branch from 40fbcf2 to 4a451ff Compare June 7, 2017 13:29
Copy link
Member

@blomquisg blomquisg left a comment

Choose a reason for hiding this comment

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

One small quibble on a method name. Otherwise, I can understand what's going on here, which is saying quite a bit :)

dc = Datacenter.find_by(:ems_ref => dc_hash[:ems_ref], :ems_id => ems.id)
dc.add_cluster(cluster)
dc.save!
def disconnect_using_association(ems, target, disconnect = true)
Copy link
Member

Choose a reason for hiding this comment

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

The method name makes it sound like it's going to do the disconnect.

What about:

  • calculate_disconnects
  • determine_disconnects
  • find_disconnects (but that has an AR overlap)

Something like that?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm good point, how about determine_deletes_using_association? Most callers set deletes = ... so deletes might be better than disconnects anyway.

@agrare agrare force-pushed the refactor_refresh_new_target branch from 4a451ff to bf433bb Compare June 14, 2017 18:04
@miq-bot
Copy link
Member

miq-bot commented Jun 14, 2017

Checked commits agrare/manageiq@4444d75~...bf433bb with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
11 files checked, 0 offenses detected
Everything looks fine. 👍

@Fryguy Fryguy merged commit d00fbdb into ManageIQ:master Jun 16, 2017
@Fryguy Fryguy added this to the Sprint 63 Ending Jun 19, 2017 milestone Jun 16, 2017
@agrare agrare deleted the refactor_refresh_new_target branch June 16, 2017 17:12
agrare added a commit to agrare/manageiq-providers-vmware that referenced this pull request Jun 19, 2017
Now that ManageIQ/manageiq#14247 is merged we
can enable the refresh_new_target test for the vmware refresher
agrare added a commit to agrare/manageiq-providers-vmware that referenced this pull request Jun 19, 2017
After ManageIQ/manageiq#14247 was merged there
are no more callers of obj_update_to_hash so it can be removed
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