Skip to content

Commit

Permalink
Merge pull request #535 from rh-dluong/make-flavors-available-for-bundle
Browse files Browse the repository at this point in the history
Support flavors for catalog bundles with Orchestration
  • Loading branch information
gmcculloug authored May 20, 2019
2 parents 7381eda + e8c56cf commit 2eb7cfd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ def main

private

def orchestration_manager_from_bundle(service)
service.service_templates.detect(&:orchestration_manager).try(:orchestration_manager) if service.respond_to?(:service_templates)
end

def fetch_list_data
service = @handle.root.attributes["service_template"] || @handle.root.attributes["service"]
flavors = service.try(:orchestration_manager).try(:flavors)

orch_mgr = service.try(:orchestration_manager) || orchestration_manager_from_bundle(service)
flavors = orch_mgr.try(:flavors)
flavor_list = {}
flavors.each { |f| flavor_list[f.name] = f.name } if flavors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
end
end

let(:default_desc) { "<select>" }
let(:flavor1) { FactoryBot.create(:flavor, :name => 'flavor1') }
let(:flavor2) { FactoryBot.create(:flavor, :name => 'flavor2') }
let(:ems) { FactoryBot.create(:ems_openstack, :flavors => [flavor1, flavor2]) }
let(:svc_model_flavor1) { MiqAeMethodService::MiqAeServiceFlavor.find(flavor1.id) }
let(:svc_model_flavor2) { MiqAeMethodService::MiqAeServiceFlavor.find(flavor2.id) }
let(:svc_model_orchestration_manager) { MiqAeMethodService::MiqAeServiceExtManagementSystem.find(ems.id) }
let(:svc_model_service) { root_hash["service_template"] || root_hash["service"] }

shared_examples_for "#having only default value" do
let(:default_desc_blank) { "<none>" }

Expand All @@ -25,27 +34,6 @@
end

shared_examples_for "#having all flavors" do |service_type|
let(:default_desc) { "<select>" }
let(:flavor1) { FactoryBot.create(:flavor, :name => 'flavor1') }
let(:flavor2) { FactoryBot.create(:flavor, :name => 'flavor2') }
let(:ems) { FactoryBot.create(:ems_openstack, :flavors => [flavor1, flavor2]) }

let(:svc_model_flavor1) do
MiqAeMethodService::MiqAeServiceFlavor.find(flavor1.id)
end

let(:svc_model_flavor2) do
MiqAeMethodService::MiqAeServiceFlavor.find(flavor2.id)
end

let(:svc_model_orchestration_manager) do
MiqAeMethodService::MiqAeServiceExtManagementSystem.find(ems.id)
end

let(:svc_model_service) do
root_hash["service_template"] || root_hash["service"]
end

it "finds all the flavors and populates the list" do
allow(ae_service.root).to receive(:attributes)
.and_return(service_type => svc_model_service)
Expand Down Expand Up @@ -92,6 +80,37 @@

it_behaves_like "#having only default value"
end

context 'bundled service' do
let(:service_template) do
FactoryBot.create(:service_template_orchestration)
end

let(:service_template_child) do
FactoryBot.create(:service_template_orchestration, :orchestration_manager => ems)
end

before do
service_template.add_resource!(service_template_child)
end

it "finds all the flavors and populates the list" do
allow(ae_service.root).to receive(:attributes)
.and_return("service_template" => svc_model_service)
allow(svc_model_service).to receive(:orchestration_manager)
.and_return(nil)
allow(svc_model_orchestration_manager).to receive(:flavors)
.and_return([svc_model_flavor1, svc_model_flavor2])
described_class.new(ae_service).main

expect(ae_service["values"]).to include(
nil => default_desc,
flavor1.name => flavor1.name,
flavor2.name => flavor2.name
)
expect(ae_service["default_value"]).to be_nil
end
end
end

context "workspace has orchestration service" do
Expand Down

0 comments on commit 2eb7cfd

Please sign in to comment.