Skip to content

Commit

Permalink
add eligible for vm provisioning method
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Demichev committed Mar 16, 2018
1 parent cfc0678 commit d7adcea
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ def validate_cloud_network(field, values, dlg, fld, value)
validate_placement(field, values, dlg, fld, value)
end

def allowed_cloud_networks(_options = {})
return {} unless (src = provider_or_tenant_object)
targets = get_targets_for_source(src, :cloud_filter, CloudNetwork, 'all_cloud_networks')
targets = filter_cloud_networks(targets)
allowed_ci(:cloud_network, [:availability_zone], targets.map(&:id))
end

private

def dialog_name_from_automate(message = 'get_dialog_name')
Expand All @@ -94,4 +101,10 @@ def dialog_name_from_automate(message = 'get_dialog_name')
def self.provider_model
ManageIQ::Providers::Openstack::CloudManager
end

def filter_cloud_networks(networks)
networks.select do |cloud_network|
cloud_network.cloud_subnets.any?
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,18 @@

context "availability_zone_to_cloud_network" do
it "has one when it should" do
FactoryGirl.create(:cloud_network_google, :ext_management_system => provider.network_manager)
subnet = FactoryGirl.create(:cloud_subnet_openstack)
FactoryGirl.create(:cloud_network_openstack, :ext_management_system => provider.network_manager, :cloud_subnets => [subnet])

expect(workflow.allowed_cloud_networks.size).to eq(1)
end

it "filters cloud networks without subnets" do
FactoryGirl.create(:cloud_network_openstack, :ext_management_system => provider.network_manager)

expect(workflow.allowed_cloud_networks.size).to eq(0)
end

it "has none when it should" do
expect(workflow.allowed_cloud_networks.size).to eq(0)
end
Expand All @@ -287,24 +294,34 @@

context "cloud networks" do
before do
subnet1 = FactoryGirl.create(:cloud_subnet_openstack)
subnet2 = FactoryGirl.create(:cloud_subnet_openstack)
subnet3 = FactoryGirl.create(:cloud_subnet_openstack)
subnet4 = FactoryGirl.create(:cloud_subnet_openstack)
subnet5 = FactoryGirl.create(:cloud_subnet_openstack)
@cn1 = FactoryGirl.create(:cloud_network_private_openstack,
:cloud_tenant => @ct1,
:ext_management_system => provider.network_manager)
:ext_management_system => provider.network_manager,
:cloud_subnets => [subnet1])
@cn2 = FactoryGirl.create(:cloud_network_private_openstack,
:cloud_tenant => @ct2,
:ext_management_system => provider.network_manager)
:ext_management_system => provider.network_manager,
:cloud_subnets => [subnet2])
@cn3 = FactoryGirl.create(:cloud_network_public_openstack,
:cloud_tenant => @ct2,
:ext_management_system => provider.network_manager)
:ext_management_system => provider.network_manager,
:cloud_subnets => [subnet3])

@cn_shared = FactoryGirl.create(:cloud_network_private_openstack,
:shared => true,
:cloud_tenant => @ct2,
:ext_management_system => provider.network_manager)
:ext_management_system => provider.network_manager,
:cloud_subnets => [subnet4])
@cn_public_shared = FactoryGirl.create(:cloud_network_public_openstack,
:shared => true,
:cloud_tenant => @ct2,
:ext_management_system => provider.network_manager)
:ext_management_system => provider.network_manager,
:cloud_subnets => [subnet5])
end

it "#allowed_cloud_networks with tenant selected" do
Expand Down

0 comments on commit d7adcea

Please sign in to comment.