Skip to content

Commit

Permalink
Merge pull request #19343 from xlab-si/additional-resource-group-rela…
Browse files Browse the repository at this point in the history
…tionships

CloudNetwork, NetworkPort and SecurityGroup belong to a ResourceGroup
  • Loading branch information
agrare authored Oct 1, 2019
2 parents 644e5fb + e9e72f7 commit 1d73637
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/models/cloud_network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/models/network_port.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion app/models/resource_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions app/models/security_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions spec/models/resource_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 1d73637

Please sign in to comment.