-
Notifications
You must be signed in to change notification settings - Fork 897
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
Limit CloudTenants' related VMs to the non-archived ones #15329
Conversation
app/models/cloud_tenant.rb
Outdated
@@ -158,4 +158,8 @@ def self.post_refresh_ems(ems_id, _) | |||
def self.tenant_joins_clause(scope) | |||
scope.includes(:source_tenant).includes(:ext_management_system) | |||
end | |||
|
|||
def active_vms | |||
vms.where.not(:ems_id => nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should have in VmOrTemplate
scope :active, -> { where.not(:ems_id => nil) }
then here:
has_many :active_vms, -> {active}, :foreign_key => :cloud_tenant_id, :class_name => "Vm"
88f2d4e
to
870fc28
Compare
app/models/cloud_tenant.rb
Outdated
@@ -14,6 +14,7 @@ class CloudTenant < ApplicationRecord | |||
has_many :network_routers | |||
has_many :vms | |||
has_many :vms_and_templates | |||
has_many :active_vms, -> { active }, :foreign_key => :cloud_tenant_id, :class_name => "Vm" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be that we just need has_many :vms, -> { active }
it's consistent with the behavior elsewhere, where we delete e.g. availability_zone_id. Seems like we've forgot to delete the cloud_tenant_id here. So has_mane :vms, -> { active }
is equivalent to having cloud_tenant_id deleted, but it's cleaner because we can keep the foreign key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but it might break existing reports relying on that relation
870fc28
to
5116d71
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
- reports are not affected because we have no reports based on cloud tenants
- it can affect API
call for example:
http://localhost:3000/api/cloud_tenants/1000000000002\?attributes\=vms
- but is is probably ok
restart ci |
5116d71
to
0f49153
Compare
0f49153
to
8ea6c77
Compare
Checked commit skateman@8ea6c77 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great 👍
@miq-bot assign @blomquisg |
Limit CloudTenants' related VMs to the non-archived ones (cherry picked from commit 9e19b17) https://bugzilla.redhat.com/show_bug.cgi?id=1461596
Fine backport details:
|
When archiving a cloud instance, its cloud tenant value does not get nullified. This causes the cloud topology screen to render unwanted archived VMs. This method filters out the archived VMs and I'm planning to use it in the topology service.
https://bugzilla.redhat.com/show_bug.cgi?id=1456031