From aafbe00828eeaafd6992e770c0586c2244c185ce Mon Sep 17 00:00:00 2001 From: nofaralfasi Date: Wed, 20 Jul 2022 15:03:02 +0300 Subject: [PATCH] Fixes #35256 - migrate bootdisk templates to Foreman --- db/seeds.d/50-bootdisk_templates.rb | 32 ------------------- lib/foreman_bootdisk/engine.rb | 1 - .../static_fixtures}/generic_efi_host.erb | 0 .../static_fixtures}/generic_host.erb | 0 .../static_fixtures}/generic_static_host.erb | 0 .../static_fixtures}/host.erb | 0 test/test_plugin_helper.rb | 5 ++- 7 files changed, 4 insertions(+), 34 deletions(-) delete mode 100644 db/seeds.d/50-bootdisk_templates.rb rename {app/views/foreman_bootdisk => test/static_fixtures}/generic_efi_host.erb (100%) rename {app/views/foreman_bootdisk => test/static_fixtures}/generic_host.erb (100%) rename {app/views/foreman_bootdisk => test/static_fixtures}/generic_static_host.erb (100%) rename {app/views/foreman_bootdisk => test/static_fixtures}/host.erb (100%) diff --git a/db/seeds.d/50-bootdisk_templates.rb b/db/seeds.d/50-bootdisk_templates.rb deleted file mode 100644 index f9280c2e..00000000 --- a/db/seeds.d/50-bootdisk_templates.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -def read_bootdisk_template(filename) - File.read(File.join(ForemanBootdisk::Engine.root, 'app', 'views', 'foreman_bootdisk', filename)) -end - -def ensure_bootdisk_template(name, content) - kind = TemplateKind.unscoped.where(name: 'Bootdisk').first_or_create - tmpl = ProvisioningTemplate.unscoped.where(name: name).first_or_create do |template| - template.attributes = { - template_kind_id: kind.id, - snippet: false, - template: content - } - end - tmpl.attributes = { - template: content, - default: true, - vendor: "Foreman boot disk" - } - tmpl.locked = true - tmpl.organizations = Organization.unscoped.all if SETTINGS[:organizations_enabled] - tmpl.locations = Location.unscoped.all if SETTINGS[:locations_enabled] - tmpl.save!(validate: false) if tmpl.changes.present? -end - -ProvisioningTemplate.without_auditing do - ensure_bootdisk_template("Boot disk iPXE - host", read_bootdisk_template("host.erb")) - ensure_bootdisk_template("Boot disk iPXE - generic host", read_bootdisk_template("generic_host.erb")) - ensure_bootdisk_template("Boot disk Grub2 EFI - generic host", read_bootdisk_template("generic_efi_host.erb")) - ensure_bootdisk_template("Boot disk iPXE - generic static host", read_bootdisk_template("generic_static_host.erb")) -end diff --git a/lib/foreman_bootdisk/engine.rb b/lib/foreman_bootdisk/engine.rb index 654f771c..0ce77186 100644 --- a/lib/foreman_bootdisk/engine.rb +++ b/lib/foreman_bootdisk/engine.rb @@ -49,7 +49,6 @@ class Engine < ::Rails::Engine "#{ForemanBootdisk::Engine.root}/app/lib/foreman_bootdisk/scope/*.rb" ] provision_method 'bootdisk', N_('Boot disk based') - template_labels 'Bootdisk' => N_('Boot disk embedded template') allowed_template_helpers :bootdisk_chain_url, :bootdisk_raise extend_page "subnets/index" do |cx| diff --git a/app/views/foreman_bootdisk/generic_efi_host.erb b/test/static_fixtures/generic_efi_host.erb similarity index 100% rename from app/views/foreman_bootdisk/generic_efi_host.erb rename to test/static_fixtures/generic_efi_host.erb diff --git a/app/views/foreman_bootdisk/generic_host.erb b/test/static_fixtures/generic_host.erb similarity index 100% rename from app/views/foreman_bootdisk/generic_host.erb rename to test/static_fixtures/generic_host.erb diff --git a/app/views/foreman_bootdisk/generic_static_host.erb b/test/static_fixtures/generic_static_host.erb similarity index 100% rename from app/views/foreman_bootdisk/generic_static_host.erb rename to test/static_fixtures/generic_static_host.erb diff --git a/app/views/foreman_bootdisk/host.erb b/test/static_fixtures/host.erb similarity index 100% rename from app/views/foreman_bootdisk/host.erb rename to test/static_fixtures/host.erb diff --git a/test/test_plugin_helper.rb b/test/test_plugin_helper.rb index 11671077..776d994b 100644 --- a/test/test_plugin_helper.rb +++ b/test/test_plugin_helper.rb @@ -29,7 +29,10 @@ def setup_routes end def setup_templates - load File.join(File.dirname(__FILE__), '..', 'db', 'seeds.d', '50-bootdisk_templates.rb') + FactoryBot.create(:provisioning_template, :name => "Boot disk Grub2 EFI - generic host", :template => File.read(File.expand_path(File.join("..", "static_fixtures", "generic_efi_host.erb"), __FILE__))) + FactoryBot.create(:provisioning_template, :name => "Boot disk iPXE - generic host", :template => File.read(File.expand_path(File.join("..", "static_fixtures", "generic_host.erb"), __FILE__))) + FactoryBot.create(:provisioning_template, :name => "Boot disk iPXE - generic static host", :template => File.read(File.expand_path(File.join("..", "static_fixtures", "generic_static_host.erb"), __FILE__))) + FactoryBot.create(:provisioning_template, :name => "Boot disk iPXE - host", :template => File.read(File.expand_path(File.join("..", "static_fixtures", "host.erb"), __FILE__))) end def setup_referer