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

Targeted refresh workaround for events that don't identify objects #323

Merged
merged 1 commit into from
Aug 14, 2018

Conversation

mansam
Copy link
Contributor

@mansam mansam commented Jul 24, 2018

@@ -309,7 +311,7 @@ def infer_related_vm_ems_refs_db!

all_stacks.each { |s| add_simple_target!(:orchestration_stacks, s.ems_ref, :tenant_id => s.cloud_tenant.ems_ref) }
vm.cloud_networks.collect(&:ems_ref).compact.each { |ems_ref| add_simple_target!(:cloud_networks, ems_ref) }
vm.floating_ips.collect(&:address).compact.each { |address| add_simple_target!(:floating_ips, address) }
vm.floating_ips.collect(&:ems_ref).compact.each { |address| add_simple_target!(:floating_ips, address) }
Copy link
Contributor

Choose a reason for hiding this comment

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

probably rename also the other address to ems_ref

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@cloud_volume_backups = targets_by_association(:cloud_volume_backups).collect do |target|
scoped_get_backup(target.manager_ref[:ems_ref], target.options[:tenant_id])
end.compact
@cloud_volume_backups = cinder_service.handled_list(:list_backups_detailed, {:__request_body_index => "backups"}, cinder_admin?)
Copy link
Contributor

Choose a reason for hiding this comment

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

we will need specs for this, I think this way it would lead to duplication of existing cloud_volume_backups

I think what we could do to make this work on persistor could be switching :targeted => true/false. Given references will be [nil] or [], then targeted => true will not update or delete anything, since the targeted query will not return any records. With :targeted => false, we will do a full refresh of the cloud_volume_backups IC.

Same for the key_pairs. But lets do specs to verify this will work.

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'll write specs to make sure this behaves correctly. Why do you suspect it would result in duplicated objects?

Copy link
Contributor

Choose a reason for hiding this comment

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

so the targeted refresh takes the references and it builds a query, so it would be:

CloudVolumeBackups.where(:ems_ref => references(...))

So if this returns always [], the refresh will create anything built by the parser. In this case that would be all cloud_volume_backups are created again. While the correct behavior should be that the query returns the existing ones, and we just update them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, gotcha

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Local testing as well as my new specs suggest that this duplication does not occur.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

builder.add_properties(:targeted => false) doesn't make a difference. I'm not sure why resource is being set conditionally, I think that happened during the builder refactor. I'll investigate that later. And it's fine to call TargetedCollection's key pair method, I just was mistakenly believing I'd see a different call when targeted => false

Copy link
Contributor

Choose a reason for hiding this comment

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

right, targeted => false should only change how we look at db. With targeted => true, we do ems.key_pairs.where(references(:vms)) with false we do ``````ems.key_pairs```

So with false it loads all key_pairs and it will delete those you will not .build in parser. While with true, it just loads the ones you've built, so it will just update.

Copy link
Contributor

Choose a reason for hiding this comment

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

in the spec, try also ems.key_pairs, since there might be the bug with :resource being nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't seem to make a difference either way, though I'm continuing to investigate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Ladas Nevermind me, the spec wasn't written properly. >.>

@mansam mansam force-pushed the targeted-refresh-workaround branch 4 times, most recently from 65bc98a to eaa3e81 Compare July 31, 2018 20:52
@@ -123,9 +123,10 @@ def add_key_pairs(extra_properties = {})
add_collection(cloud, :key_pairs, extra_properties) do |builder|
builder.add_properties(
:model_class => ManageIQ::Providers::Openstack::CloudManager::AuthKeyPair,
# targeted refresh workaround-- always refresh the whole keypair collection
:targeted => false
Copy link
Contributor

@Ladas Ladas Aug 1, 2018

Choose a reason for hiding this comment

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

I think we still need to conditionalize this , it should copy what we do in https://github.com/ManageIQ/manageiq-providers-openstack/pull/323/files#diff-0698b10bec7e7c31e8eabb30dc507213R140

So we fetch all entities only if there is something in references.


Now, it the references would be blank, we would delete all keypairs

@mansam mansam force-pushed the targeted-refresh-workaround branch from eaa3e81 to fe65bab Compare August 1, 2018 15:23
else
builder.add_default_values(:ems_id => manager.id)
end
# targeted refresh workaround-- always refresh the whole backup collection
Copy link
Contributor

Choose a reason for hiding this comment

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

I would probably write here why:

``Because OpenStack doesn't give us UUIDs of changed volume_backups, we just get an event that one of them changed```

Btw. is this a bug? :-D It's like super unhelpful event. :-) Or does it use ID we don't recognize?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call on the improved comment. I'm not sure whether this is officially a bug, but it is a really unhelpful event. There are some other IDs present like the request ID, but nothing that helps us as far as I know.

Copy link
Contributor

@Ladas Ladas 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 👍

Just a nit for a better comment, so we remember why we do this :-)

@mansam mansam force-pushed the targeted-refresh-workaround branch from fe65bab to 8ef539e Compare August 1, 2018 16:19
@miq-bot
Copy link
Member

miq-bot commented Aug 6, 2018

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

@mansam mansam force-pushed the targeted-refresh-workaround branch from 8ef539e to 90f75d0 Compare August 6, 2018 17:03
@miq-bot
Copy link
Member

miq-bot commented Aug 6, 2018

Checked commit mansam@90f75d0 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
8 files checked, 0 offenses detected
Everything looks fine. 🍪

@miq-bot
Copy link
Member

miq-bot commented Aug 6, 2018

Some comments on commit mansam@90f75d0

spec/models/manageiq/providers/openstack/cloud_manager/stubbed_refresher_spec.rb

  • ⚠️ - 196 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 197 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 198 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 199 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.
  • ⚠️ - 200 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.

@aufi
Copy link
Member

aufi commented Aug 14, 2018

Looks good! Merging.

@aufi aufi merged commit 85f4226 into ManageIQ:master Aug 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants