From aca00ba0f6f69707bbb03942fe7c8456bbae931e Mon Sep 17 00:00:00 2001 From: Madhu Kanoor Date: Wed, 29 Nov 2017 16:02:32 -0500 Subject: [PATCH 1/3] Catalog Item type list is dependent on installed providers https://bugzilla.redhat.com/show_bug.cgi?id=1515371 Currently we display all catalog item types irrespective of what providers are installed in the appliance. This PR links the catalog items to different providers and sets the display attribute based on the presence of specific provider(s). This would be used by the UI to list the valid catalog item types --- app/models/manageiq/providers/base_manager.rb | 4 ++++ app/models/service_template.rb | 9 ++++++++ spec/models/service_template_spec.rb | 21 +++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/app/models/manageiq/providers/base_manager.rb b/app/models/manageiq/providers/base_manager.rb index f089139d6ee..8f963edb5f3 100644 --- a/app/models/manageiq/providers/base_manager.rb +++ b/app/models/manageiq/providers/base_manager.rb @@ -16,6 +16,10 @@ def ext_management_system self end + def supported_catalog_types + [] + end + def refresher self.class::Refresher end diff --git a/app/models/service_template.rb b/app/models/service_template.rb index d67929ae1d4..10a32bfc7ae 100644 --- a/app/models/service_template.rb +++ b/app/models/service_template.rb @@ -69,6 +69,15 @@ class ServiceTemplate < ApplicationRecord scope :with_existent_service_template_catalog_id, -> { where.not(:service_template_catalog_id => nil) } scope :displayed, -> { where(:display => true) } + def self.catalog_item_types + ci_types = Rbac.filtered(ExtManagementSystem.all).flat_map(&:supported_catalog_types).uniq + ci_types << 'generic_orchestration' if Rbac.filtered(OrchestrationTemplate).exists? + ci_types << 'generic' + CATALOG_ITEM_TYPES.each.with_object({}) do |(key, description), hash| + hash[key] = { :description => description, :display => ci_types.include?(key) } + end + end + def self.create_catalog_item(options, auth_user) transaction do create_from_options(options).tap do |service_template| diff --git a/spec/models/service_template_spec.rb b/spec/models/service_template_spec.rb index bde09b35321..542d2fadca2 100644 --- a/spec/models/service_template_spec.rb +++ b/spec/models/service_template_spec.rb @@ -776,6 +776,27 @@ expect { service_template.provision_request(user, arg1, arg2) }.to raise_error(RuntimeError) end end + + context "catalog_item_types" do + it "only returns generic with no providers" do + expect(ServiceTemplate.catalog_item_types).to match( + hash_including('amazon' => {:description => 'Amazon', :display => false}, + 'generic' => {:description => 'Generic', :display => true }) + ) + end + + it "returns orchestration template and generic" do + FactoryGirl.create(:orchestration_template) + expect(ServiceTemplate.catalog_item_types).to match( + hash_including('amazon' => { :description => 'Amazon', + :display => false }, + 'generic' => { :description => 'Generic', + :display => true }, + 'generic_orchestration' => { :description => 'Orchestration', + :display => true}) + ) + end + end end def add_and_save_service(p, c) From 0327cbb80654fe4d42b534627ffecf64f17a7e71 Mon Sep 17 00:00:00 2001 From: Madhu Kanoor Date: Fri, 8 Dec 2017 17:12:25 -0500 Subject: [PATCH 2/3] Added supported_catalog_types for embedded_ansible --- .../manageiq/providers/embedded_automation_manager.rb | 4 ++++ .../providers/embedded_ansible/automation_manager_spec.rb | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/app/models/manageiq/providers/embedded_automation_manager.rb b/app/models/manageiq/providers/embedded_automation_manager.rb index a63ef82b005..8e1b7ce033b 100644 --- a/app/models/manageiq/providers/embedded_automation_manager.rb +++ b/app/models/manageiq/providers/embedded_automation_manager.rb @@ -5,4 +5,8 @@ class ManageIQ::Providers::EmbeddedAutomationManager < ManageIQ::Providers::Auto require_nested :ConfigurationScriptSource require_nested :ConfiguredSystem require_nested :OrchestrationStack + + def supported_catalog_types + %w(generic_ansible_playbook) + end end diff --git a/spec/models/manageiq/providers/embedded_ansible/automation_manager_spec.rb b/spec/models/manageiq/providers/embedded_ansible/automation_manager_spec.rb index fe6caa53a1b..a6655f734d8 100644 --- a/spec/models/manageiq/providers/embedded_ansible/automation_manager_spec.rb +++ b/spec/models/manageiq/providers/embedded_ansible/automation_manager_spec.rb @@ -1,3 +1,11 @@ describe ManageIQ::Providers::EmbeddedAnsible::AutomationManager do it_behaves_like 'ansible automation_manager' + + context 'catalog types' do + let(:ems) { FactoryGirl.create(:embedded_automation_manager) } + + it "#supported_catalog_types" do + expect(ems.supported_catalog_types).to eq(%w(generic_ansible_playbook)) + end + end end From 32eef9e457bd302f06b211de200ef30f77dabce3 Mon Sep 17 00:00:00 2001 From: Madhu Kanoor Date: Mon, 11 Dec 2017 12:03:44 -0500 Subject: [PATCH 3/3] Changed uniq to Set.new --- app/models/service_template.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/service_template.rb b/app/models/service_template.rb index 10a32bfc7ae..1595374d7f6 100644 --- a/app/models/service_template.rb +++ b/app/models/service_template.rb @@ -70,9 +70,9 @@ class ServiceTemplate < ApplicationRecord scope :displayed, -> { where(:display => true) } def self.catalog_item_types - ci_types = Rbac.filtered(ExtManagementSystem.all).flat_map(&:supported_catalog_types).uniq - ci_types << 'generic_orchestration' if Rbac.filtered(OrchestrationTemplate).exists? - ci_types << 'generic' + ci_types = Set.new(Rbac.filtered(ExtManagementSystem.all).flat_map(&:supported_catalog_types)) + ci_types.add('generic_orchestration') if Rbac.filtered(OrchestrationTemplate).exists? + ci_types.add('generic') CATALOG_ITEM_TYPES.each.with_object({}) do |(key, description), hash| hash[key] = { :description => description, :display => ci_types.include?(key) } end