diff --git a/app/models/cloud_network.rb b/app/models/cloud_network.rb index 0cfcedf45af..3066e74a63b 100644 --- a/app/models/cloud_network.rb +++ b/app/models/cloud_network.rb @@ -9,6 +9,7 @@ class CloudNetwork < ApplicationRecord belongs_to :ext_management_system, :foreign_key => :ems_id, :class_name => "ManageIQ::Providers::NetworkManager" belongs_to :cloud_tenant belongs_to :orchestration_stack + belongs_to :resource_group has_many :cloud_subnets, :dependent => :destroy has_many :network_routers, -> { distinct }, :through => :cloud_subnets diff --git a/app/models/network_port.rb b/app/models/network_port.rb index 89897b63373..06ca1ebe10c 100644 --- a/app/models/network_port.rb +++ b/app/models/network_port.rb @@ -6,6 +6,7 @@ class NetworkPort < ApplicationRecord belongs_to :ext_management_system, :foreign_key => :ems_id, :class_name => "ManageIQ::Providers::NetworkManager" belongs_to :cloud_tenant belongs_to :device, :polymorphic => true + belongs_to :resource_group has_many :network_port_security_groups, :dependent => :destroy has_many :security_groups, :through => :network_port_security_groups diff --git a/app/models/resource_group.rb b/app/models/resource_group.rb index 8c7a20aa8f6..b34f15351ca 100644 --- a/app/models/resource_group.rb +++ b/app/models/resource_group.rb @@ -5,6 +5,10 @@ class ResourceGroup < ApplicationRecord has_many :vm_or_templates # Rely on default scopes to get expected information - has_many :vms, :class_name => 'Vm' + has_many :vms, :class_name => 'Vm', :dependent => :nullify has_many :templates, :class_name => 'MiqTemplate' + + has_many :cloud_networks, :dependent => :nullify + has_many :network_ports, :dependent => :nullify + has_many :security_groups, :dependent => :nullify end diff --git a/app/models/security_group.rb b/app/models/security_group.rb index 661ee364a12..48562fce73d 100644 --- a/app/models/security_group.rb +++ b/app/models/security_group.rb @@ -13,6 +13,7 @@ class SecurityGroup < ApplicationRecord belongs_to :network_group belongs_to :cloud_subnet belongs_to :network_router + belongs_to :resource_group has_many :firewall_rules, :as => :resource, :dependent => :destroy has_many :network_port_security_groups, :dependent => :destroy diff --git a/spec/models/resource_group_spec.rb b/spec/models/resource_group_spec.rb index 7df7c58874e..50d08fbced2 100644 --- a/spec/models/resource_group_spec.rb +++ b/spec/models/resource_group_spec.rb @@ -26,6 +26,9 @@ before do @vm = FactoryBot.create(:vm_google, :template => false, :resource_group => resource_group) @template = FactoryBot.create(:template_google, :template => true, :resource_group => resource_group) + @cloud_network = FactoryBot.create(:cloud_network, :resource_group => resource_group) + @network_port = FactoryBot.create(:network_port, :resource_group => resource_group) + @security_group = FactoryBot.create(:security_group, :resource_group => resource_group) end it "returns the expected results for vms" do @@ -42,5 +45,17 @@ expect(resource_group.vm_or_templates).to include(@template) expect(resource_group.vm_or_templates).to include(@vm) end + + it "returns the expected results for cloud_networks" do + expect(resource_group.cloud_networks).to include(@cloud_network) + end + + it "returns the expected results for network_ports" do + expect(resource_group.network_ports).to include(@network_port) + end + + it "returns the expected results for security_groups" do + expect(resource_group.security_groups).to include(@security_group) + end end end