foreman_bootdisk 13.0.0 → 14.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +4 -0
  3. data/README.md +3 -2
  4. data/app/controllers/foreman_bootdisk/api/v2/disks_controller.rb +11 -9
  5. data/app/controllers/foreman_bootdisk/api/v2/subnet_disks_controller.rb +37 -31
  6. data/app/controllers/foreman_bootdisk/disks_controller.rb +20 -19
  7. data/app/helpers/concerns/foreman_bootdisk/hosts_helper_ext.rb +86 -45
  8. data/app/lib/foreman_bootdisk/scope/bootdisk.rb +2 -0
  9. data/app/lib/foreman_bootdisk/scope/full_host_bootdisk.rb +15 -0
  10. data/app/models/concerns/foreman_bootdisk/compute_resources/vmware.rb +4 -2
  11. data/app/models/concerns/foreman_bootdisk/host_ext.rb +43 -31
  12. data/app/models/concerns/foreman_bootdisk/orchestration/compute.rb +14 -10
  13. data/app/models/setting/bootdisk.rb +28 -23
  14. data/app/services/foreman_bootdisk/iso_generator.rb +127 -104
  15. data/app/services/foreman_bootdisk/renderer.rb +16 -13
  16. data/config/routes.rb +15 -13
  17. data/config/routes/mount_engine.rb +3 -1
  18. data/db/migrate/20130914211030_create_host_bootdisk_template.rb +4 -4
  19. data/db/migrate/20130915104500_edit_host_bootdisk_template_multinic.rb +4 -4
  20. data/db/migrate/20130915133321_create_kickstart_bootdisk_template.rb +4 -4
  21. data/db/migrate/20130915201457_create_generic_host_bootdisk_template.rb +4 -4
  22. data/db/migrate/20131021095100_edit_host_bootdisk_template_dns_secondary.rb +4 -4
  23. data/db/migrate/20140522185700_change_templatekind_to_bootdisk.rb +16 -14
  24. data/db/migrate/20171009225200_remove_duplicate_bootdisk_templates.rb +4 -2
  25. data/db/seeds.d/50-bootdisk_templates.rb +24 -22
  26. data/lib/foreman_bootdisk.rb +2 -0
  27. data/lib/foreman_bootdisk/engine.rb +22 -33
  28. data/lib/foreman_bootdisk/version.rb +3 -1
  29. data/lib/tasks/bootdisk.rake +34 -17
  30. data/locale/gemspec.rb +3 -1
  31. data/test/functional/foreman_bootdisk/api/v2/disks_controller_test.rb +35 -33
  32. data/test/functional/foreman_bootdisk/api/v2/subnet_disks_controller_test.rb +9 -7
  33. data/test/functional/foreman_bootdisk/disks_controller_test.rb +27 -25
  34. data/test/models/host/managed_test.rb +17 -13
  35. data/test/test_plugin_helper.rb +9 -7
  36. data/test/unit/access_permissions_test.rb +2 -0
  37. data/test/unit/concerns/compute_resources/vmware_test.rb +67 -63
  38. data/test/unit/concerns/host_test.rb +54 -54
  39. data/test/unit/concerns/orchestration/compute_test.rb +41 -39
  40. data/test/unit/foreman_bootdisk/renderer_test.rb +3 -1
  41. data/test/unit/foreman_bootdisk/scope/bootdisk_test.rb +3 -1
  42. data/test/unit/foreman_bootdisk/scope/full_host_bootdisk_test.rb +30 -0
  43. data/test/unit/iso_generator_test.rb +57 -40
  44. metadata +19 -3
@@ -1,30 +1,32 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uri'
2
4
 
3
5
  module ForemanBootdisk
4
6
  class Renderer
5
7
  def generic_template_render(subnet = nil)
6
- if subnet.present?
7
- # rendering a subnet-level bootdisk requires tricking the renderer into thinking it has a
8
- # valid host, without a token, but with a tftp proxy
9
- host = Struct.new(:token, :provision_interface).new(
10
- nil,
11
- Struct.new(:subnet).new(subnet)
12
- )
13
- else
14
- host = Struct.new(:token, :subnet).new(nil, nil)
15
- end
8
+ host = if subnet.present?
9
+ # rendering a subnet-level bootdisk requires tricking the renderer into thinking it has a
10
+ # valid host, without a token, but with a tftp proxy
11
+ Struct.new(:token, :provision_interface).new(
12
+ nil,
13
+ Struct.new(:subnet).new(subnet)
14
+ )
15
+ else
16
+ Struct.new(:token, :subnet).new(nil, nil)
17
+ end
16
18
 
17
19
  render_template(template: generic_host_template, host: host)
18
20
  end
19
21
 
20
- def render_template(template: , host:)
22
+ def render_template(template:, host:, scope_class: renderer_scope)
21
23
  source = Foreman::Renderer.get_source(
22
24
  template: template,
23
25
  host: host
24
26
  )
25
27
  scope = Foreman::Renderer.get_scope(
26
28
  host: host,
27
- klass: renderer_scope
29
+ klass: scope_class
28
30
  )
29
31
  Foreman::Renderer.render(source, scope)
30
32
  end
@@ -36,8 +38,9 @@ module ForemanBootdisk
36
38
  end
37
39
 
38
40
  def generic_host_template
39
- template = ProvisioningTemplate.unscoped.find_by_name(Setting[:bootdisk_generic_host_template])
41
+ template = ProvisioningTemplate.unscoped.find_by(name: Setting[:bootdisk_generic_host_template])
40
42
  raise ::Foreman::Exception.new(N_('Unable to find template specified by %s setting'), 'bootdisk_generic_host_template') unless template
43
+
41
44
  template
42
45
  end
43
46
  end
@@ -1,20 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ForemanBootdisk::Engine.routes.draw do
2
- resources :disks, :only => [] do
3
- get 'generic', :on => :collection
4
- get 'help', :on => :collection
5
- constraints(:id => /[^\/]+/) do
6
- get 'hosts/:id', :on => :collection, :to => 'disks#host'
7
- get 'full_hosts/:id', :on => :collection, :to => 'disks#full_host'
8
- get 'subnet/:id', :on => :collection, :to => 'disks#subnet'
4
+ resources :disks, only: [] do
5
+ get 'generic', on: :collection
6
+ get 'help', on: :collection
7
+ constraints(id: %r{[^/]+}) do
8
+ get 'hosts/:id', on: :collection, to: 'disks#host'
9
+ get 'full_hosts/:id', on: :collection, to: 'disks#full_host'
10
+ get 'subnet/:id', on: :collection, to: 'disks#subnet'
9
11
  end
10
12
  end
11
13
 
12
- namespace :api, :defaults => {:format => 'json'} do
13
- scope "(:apiv)", :module => :v2, :defaults => {:apiv => 'v2'}, :apiv => /v1|v2/, :constraints => ApiConstraints.new(:version => 2, :default => true) do
14
- get 'generic', :to => 'disks#generic'
15
- constraints(:id => /[^\/]+/) do
16
- get 'hosts/:id', :to => 'disks#host'
17
- get 'subnets/:id', :to => 'subnet_disks#subnet'
14
+ namespace :api, defaults: { format: 'json' } do
15
+ scope '(:apiv)', module: :v2, defaults: { apiv: 'v2' }, apiv: /v1|v2/, constraints: ApiConstraints.new(version: 2, default: true) do
16
+ get 'generic', to: 'disks#generic'
17
+ constraints(id: %r{[^/]+}) do
18
+ get 'hosts/:id', to: 'disks#host'
19
+ get 'subnets/:id', to: 'subnet_disks#subnet'
18
20
  end
19
21
  end
20
22
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Foreman::Application.routes.draw do
2
- mount ForemanBootdisk::Engine, :at => "/bootdisk"
4
+ mount ForemanBootdisk::Engine, at: '/bootdisk'
3
5
  end
@@ -1,7 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateHostBootdiskTemplate < ActiveRecord::Migration[4.2]
2
- def self.up
3
- end
4
+ def self.up; end
4
5
 
5
- def self.down
6
- end
6
+ def self.down; end
7
7
  end
@@ -1,7 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class EditHostBootdiskTemplateMultinic < ActiveRecord::Migration[4.2]
2
- def self.up
3
- end
4
+ def self.up; end
4
5
 
5
- def self.down
6
- end
6
+ def self.down; end
7
7
  end
@@ -1,7 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateKickstartBootdiskTemplate < ActiveRecord::Migration[4.2]
2
- def self.up
3
- end
4
+ def self.up; end
4
5
 
5
- def self.down
6
- end
6
+ def self.down; end
7
7
  end
@@ -1,7 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateGenericHostBootdiskTemplate < ActiveRecord::Migration[4.2]
2
- def self.up
3
- end
4
+ def self.up; end
4
5
 
5
- def self.down
6
- end
6
+ def self.down; end
7
7
  end
@@ -1,7 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class EditHostBootdiskTemplateDnsSecondary < ActiveRecord::Migration[4.2]
2
- def self.up
3
- end
4
+ def self.up; end
4
5
 
5
- def self.down
6
- end
6
+ def self.down; end
7
7
  end
@@ -1,29 +1,31 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ChangeTemplatekindToBootdisk < ActiveRecord::Migration[4.2]
2
4
  class FakeConfigTemplate < ApplicationRecord
3
- if ActiveRecord::Base.connection.migration_context.get_all_versions.include?(20150514072626)
4
- self.table_name = 'templates'
5
- else
6
- self.table_name = 'config_templates'
7
- end
5
+ self.table_name = if ActiveRecord::Base.connection.migration_context.get_all_versions.include?(20_150_514_072_626)
6
+ 'templates'
7
+ else
8
+ 'config_templates'
9
+ end
8
10
  end
9
11
 
10
12
  def self.up
11
- kind = TemplateKind.where(:name => 'Bootdisk').first_or_create
13
+ kind = TemplateKind.where(name: 'Bootdisk').first_or_create
12
14
 
13
- tmpl_h = Setting.find_by_name('bootdisk_host_template').try(:value)
14
- tmpl_g = Setting.find_by_name('bootdisk_generic_host_template').try(:value)
15
+ tmpl_h = Setting.find_by(name: 'bootdisk_host_template').try(:value)
16
+ tmpl_g = Setting.find_by(name: 'bootdisk_generic_host_template').try(:value)
15
17
 
16
18
  (FakeConfigTemplate.unscoped.where('name LIKE ?', '%Boot disk%') |
17
- FakeConfigTemplate.unscoped.where(:name => [tmpl_h, tmpl_g].compact)).each do |tmpl|
19
+ FakeConfigTemplate.unscoped.where(name: [tmpl_h, tmpl_g].compact)).each do |tmpl|
18
20
  tmpl.update_attribute(:template_kind_id, kind.id)
19
21
  end
20
22
  end
21
23
 
22
24
  def self.down
23
- old_kind = TemplateKind.find_by_name('Bootdisk')
24
- new_kind = TemplateKind.find_by_name('iPXE')
25
- if old_kind.present? && new_kind.present?
26
- FakeConfigTemplate.unscoped.where(:template_kind_id => old_kind.id).update_all(:template_kind_id => new_kind.id)
27
- end
25
+ old_kind = TemplateKind.find_by(name: 'Bootdisk')
26
+ new_kind = TemplateKind.find_by(name: 'iPXE')
27
+ return unless old_kind.present? && new_kind.present?
28
+
29
+ FakeConfigTemplate.unscoped.where(template_kind_id: old_kind.id).update_all(template_kind_id: new_kind.id)
28
30
  end
29
31
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class RemoveDuplicateBootdiskTemplates < ActiveRecord::Migration[4.2]
2
4
  def up
3
5
  template_names = ['Boot disk iPXE - host', 'Boot disk iPXE - generic host']
4
6
  template_names.each do |template_name|
5
- duplicate_template_ids = ProvisioningTemplate.unscoped.where(:name => template_name, :locked => true).order(:created_at => :asc).pluck(:id).drop(1)
6
- ProvisioningTemplate.unscoped.where(:id => duplicate_template_ids).destroy_all if duplicate_template_ids.any?
7
+ duplicate_template_ids = ProvisioningTemplate.unscoped.where(name: template_name, locked: true).order(created_at: :asc).pluck(:id).drop(1)
8
+ ProvisioningTemplate.unscoped.where(id: duplicate_template_ids).destroy_all if duplicate_template_ids.any?
7
9
  end
8
10
  end
9
11
  end
@@ -1,4 +1,6 @@
1
- kind = TemplateKind.unscoped.where(:name => 'Bootdisk').first_or_create
1
+ # frozen_string_literal: true
2
+
3
+ kind = TemplateKind.unscoped.where(name: 'Bootdisk').first_or_create
2
4
 
3
5
  organizations = Organization.all
4
6
  locations = Location.all
@@ -6,41 +8,41 @@ created = []
6
8
 
7
9
  ProvisioningTemplate.without_auditing do
8
10
  content = File.read(File.join(ForemanBootdisk::Engine.root, 'app', 'views', 'foreman_bootdisk', 'host.erb'))
9
- created << 'Boot disk iPXE - host' unless ProvisioningTemplate.find_by_name('Boot disk iPXE - host')
10
- tmpl = ProvisioningTemplate.unscoped.where(:name => 'Boot disk iPXE - host').first_or_create do |template|
11
+ created << 'Boot disk iPXE - host' unless ProvisioningTemplate.find_by(name: 'Boot disk iPXE - host')
12
+ tmpl = ProvisioningTemplate.unscoped.where(name: 'Boot disk iPXE - host').first_or_create do |template|
11
13
  template.attributes = {
12
- :template_kind_id => kind.id,
13
- :snippet => false,
14
- :template => content
14
+ template_kind_id: kind.id,
15
+ snippet: false,
16
+ template: content
15
17
  }
16
18
  end
17
19
  tmpl.attributes = {
18
- :template => content,
19
- :default => true,
20
- :vendor => "Foreman boot disk",
20
+ template: content,
21
+ default: true,
22
+ vendor: 'Foreman boot disk'
21
23
  }
22
24
  tmpl.locked = true
23
- tmpl.save!(:validate => false) if tmpl.changes.present?
25
+ tmpl.save!(validate: false) if tmpl.changes.present?
24
26
 
25
27
  content = File.read(File.join(ForemanBootdisk::Engine.root, 'app', 'views', 'foreman_bootdisk', 'generic_host.erb'))
26
- created << 'Boot disk iPXE - generic host' unless ProvisioningTemplate.find_by_name('Boot disk iPXE - generic host')
27
- tmpl = ProvisioningTemplate.unscoped.where(:name => 'Boot disk iPXE - generic host').first_or_create do |template|
28
+ created << 'Boot disk iPXE - generic host' unless ProvisioningTemplate.find_by(name: 'Boot disk iPXE - generic host')
29
+ tmpl = ProvisioningTemplate.unscoped.where(name: 'Boot disk iPXE - generic host').first_or_create do |template|
28
30
  template.attributes = {
29
- :template_kind_id => kind.id,
30
- :snippet => false,
31
- :template => content
31
+ template_kind_id: kind.id,
32
+ snippet: false,
33
+ template: content
32
34
  }
33
35
  end
34
36
  tmpl.attributes = {
35
- :template => content,
36
- :default => true,
37
- :vendor => "Foreman boot disk",
37
+ template: content,
38
+ default: true,
39
+ vendor: 'Foreman boot disk'
38
40
  }
39
41
  tmpl.locked = true
40
- tmpl.save!(:validate => false) if tmpl.changes.present?
42
+ tmpl.save!(validate: false) if tmpl.changes.present?
41
43
 
42
- ProvisioningTemplate.unscoped.where(:name => created, :default => true).each do |tmpl|
43
- tmpl.organizations = organizations if SETTINGS[:organizations_enabled]
44
- tmpl.locations = locations if SETTINGS[:locations_enabled]
44
+ ProvisioningTemplate.unscoped.where(name: created, default: true).each do |template|
45
+ template.organizations = organizations if SETTINGS[:organizations_enabled]
46
+ template.locations = locations if SETTINGS[:locations_enabled]
45
47
  end
46
48
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'foreman_bootdisk/version'
2
4
  require 'foreman_bootdisk/engine'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'foreman_bootdisk'
2
4
  require 'fast_gettext'
3
5
  require 'gettext_i18n_rails'
@@ -15,49 +17,36 @@ module ForemanBootdisk
15
17
  app.routes_reloader.paths << "#{ForemanBootdisk::Engine.root}/config/routes/mount_engine.rb"
16
18
  end
17
19
 
18
- initializer 'foreman_bootdisk.load_default_settings', :before => :load_config_initializers do |app|
19
- require_dependency File.expand_path("../../../app/models/setting/bootdisk.rb", __FILE__) if (Setting.table_exists? rescue(false))
20
+ initializer 'foreman_bootdisk.load_default_settings', before: :load_config_initializers do |_app|
21
+ table_exists = begin
22
+ Setting.table_exists?
23
+ rescue StandardError
24
+ false
25
+ end
26
+ require_dependency File.expand_path('../../app/models/setting/bootdisk.rb', __dir__) if table_exists
20
27
  end
21
28
 
22
- initializer "foreman_bootdisk.load_app_instance_data" do |app|
29
+ initializer 'foreman_bootdisk.load_app_instance_data' do |app|
23
30
  ForemanBootdisk::Engine.paths['db/migrate'].existent.each do |path|
24
31
  app.config.paths['db/migrate'] << path
25
32
  end
26
33
  end
27
34
 
28
- initializer "foreman_bootdisk.apipie" do
35
+ initializer 'foreman_bootdisk.apipie' do
29
36
  Apipie.configuration.checksum_path += ['/bootdisk/api/']
30
37
  end
31
38
 
32
- # Precompile any JS or CSS files under app/assets/
33
- # If requiring files from each other, list them explicitly here to avoid precompiling the same
34
- # content twice.
35
- assets_to_precompile =
36
- Dir.chdir(root) do
37
- Dir['app/assets/javascripts/**/*', 'app/assets/stylesheets/**/*'].map do |f|
38
- f.split(File::SEPARATOR, 4).last
39
- end
40
- end
41
-
42
- initializer 'foreman_bootdisk.assets.precompile' do |app|
43
- app.config.assets.precompile += assets_to_precompile
44
- end
45
-
46
- initializer 'foreman_bootdisk.configure_assets', group: :assets do
47
- SETTINGS[:foreman_bootdisk] = { assets: { precompile: assets_to_precompile } }
48
- end
49
-
50
- initializer 'foreman_bootdisk.register_plugin', :before => :finisher_hook do |app|
39
+ initializer 'foreman_bootdisk.register_plugin', before: :finisher_hook do |_app|
51
40
  Foreman::Plugin.register :foreman_bootdisk do
52
- requires_foreman '>= 1.18'
41
+ requires_foreman '>= 1.20'
53
42
 
54
- security_block :bootdisk do |map|
55
- permission :download_bootdisk, {:'foreman_bootdisk/disks' => [:generic, :host, :full_host, :subnet, :help],
56
- :'foreman_bootdisk/api/v2/disks' => [:generic, :host],
57
- :'foreman_bootdisk/api/v2/subnet_disks' => [:subnet]}
43
+ security_block :bootdisk do |_map|
44
+ permission :download_bootdisk, 'foreman_bootdisk/disks': %i[generic host full_host subnet help],
45
+ 'foreman_bootdisk/api/v2/disks': %i[generic host],
46
+ 'foreman_bootdisk/api/v2/subnet_disks': [:subnet]
58
47
  end
59
48
 
60
- role "Boot disk access", [:download_bootdisk]
49
+ role 'Boot disk access', [:download_bootdisk]
61
50
 
62
51
  add_all_permissions_to_default_roles
63
52
 
@@ -68,8 +57,8 @@ module ForemanBootdisk
68
57
  end
69
58
  end
70
59
 
71
- initializer 'foreman_bootdisk.register_gettext', :after => :load_config_initializers do |app|
72
- locale_dir = File.join(File.expand_path('../../..', __FILE__), 'locale')
60
+ initializer 'foreman_bootdisk.register_gettext', after: :load_config_initializers do |_app|
61
+ locale_dir = File.join(File.expand_path('../..', __dir__), 'locale')
73
62
  locale_domain = 'foreman_bootdisk'
74
63
  Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
75
64
  end
@@ -80,8 +69,8 @@ module ForemanBootdisk
80
69
  Host::Managed.send(:include, ForemanBootdisk::Orchestration::Compute) if SETTINGS[:unattended]
81
70
  HostsHelper.send(:prepend, ForemanBootdisk::HostsHelperExt)
82
71
  Foreman::Model::Vmware.send(:prepend, ForemanBootdisk::ComputeResources::Vmware) if Foreman::Model::Vmware.available?
83
- rescue => e
84
- puts "#{ForemanBootdisk::ENGINE_NAME}: skipping engine hook (#{e.to_s})"
72
+ rescue StandardError => e
73
+ Rails.logger.warn "#{ForemanBootdisk::ENGINE_NAME}: skipping engine hook (#{e})"
85
74
  end
86
75
  end
87
76
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanBootdisk
2
- VERSION = '13.0.0'
4
+ VERSION = '14.0.0'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'date'
2
4
  require 'rake/testtask'
3
5
  require 'tmpdir'
@@ -15,12 +17,12 @@ namespace :bootdisk do
15
17
 
16
18
  namespace :generate do
17
19
  desc 'Generate a static boot disk for a specific host. NAME=fqdn, OUTPUT path'
18
- task :host => :environment do
20
+ task host: :environment do
19
21
  User.as_anonymous_admin do
20
- host = Host::Base.unscoped.find_by_name(ENV['NAME']) || raise("cannot find host '#{ENV['NAME']}', specify NAME=fqdn")
22
+ host = Host::Base.unscoped.find_by(name: ENV['NAME']) || raise("cannot find host '#{ENV['NAME']}', specify NAME=fqdn")
21
23
  tmpl = host.bootdisk_template_render
22
24
 
23
- ForemanBootdisk::ISOGenerator.generate(:ipxe => tmpl, :dir => outputdir) do |image|
25
+ ForemanBootdisk::ISOGenerator.generate(ipxe: tmpl, dir: outputdir) do |image|
24
26
  output = ENV['OUTPUT'] || File.join(outputdir, "#{host.name}.iso")
25
27
  FileUtils.mv image, output
26
28
  puts "Wrote #{output}"
@@ -29,10 +31,10 @@ namespace :bootdisk do
29
31
  end
30
32
 
31
33
  desc 'Generate a full boot disk for a specific host with the OS bootloader included. NAME=fqdn, OUTPUT path'
32
- task :full_host => :environment do
34
+ task full_host: :environment do
33
35
  User.as_anonymous_admin do
34
- host = Host::Base.unscoped.find_by_name(ENV['NAME']) || raise("cannot find host '#{ENV['NAME']}', specify NAME=fqdn")
35
- ForemanBootdisk::ISOGenerator.generate_full_host(host, :dir => outputdir) do |image|
36
+ host = Host::Base.unscoped.find_by(name: ENV['NAME']) || raise("cannot find host '#{ENV['NAME']}', specify NAME=fqdn")
37
+ ForemanBootdisk::ISOGenerator.generate_full_host(host, dir: outputdir) do |image|
36
38
  output = ENV['OUTPUT'] || File.join(outputdir, "#{host.name}_#{Date.today.strftime('%Y%m%d')}.iso")
37
39
  FileUtils.cp image, output
38
40
  puts "Wrote #{output}"
@@ -41,11 +43,11 @@ namespace :bootdisk do
41
43
  end
42
44
 
43
45
  desc 'Generate a generic boot disk. OUTPUT=path'
44
- task :generic => :environment do
46
+ task generic: :environment do
45
47
  User.as_anonymous_admin do
46
48
  tmpl = ForemanBootdisk::Renderer.new.generic_template_render
47
49
 
48
- ForemanBootdisk::ISOGenerator.generate(:ipxe => tmpl, :dir => outputdir) do |image|
50
+ ForemanBootdisk::ISOGenerator.generate(ipxe: tmpl, dir: outputdir) do |image|
49
51
  output = ENV['OUTPUT'] || File.join(outputdir, "bootdisk_#{URI.parse(Setting[:foreman_url]).host}.iso")
50
52
  FileUtils.cp image, output
51
53
  puts "Wrote #{output}"
@@ -54,12 +56,12 @@ namespace :bootdisk do
54
56
  end
55
57
 
56
58
  desc 'Generate a subnet disk for a specific subnet. NAME=subnet, OUTPUT=path'
57
- task :subnet => :environment do
59
+ task subnet: :environment do
58
60
  User.as_anonymous_admin do
59
- subnet = Subnet.unscoped.find_by_name(ENV['NAME']) || raise("cannot find subnet '#{ENV['NAME']}', specify NAME=subnet")
60
- subnet.tftp || raise(::Foreman::Exception.new(N_("TFTP feature not enabled for subnet %s"), subnet.name))
61
+ subnet = Subnet.unscoped.find_by(name: ENV['NAME']) || raise("cannot find subnet '#{ENV['NAME']}', specify NAME=subnet")
62
+ subnet.tftp || raise(::Foreman::Exception.new(N_('TFTP feature not enabled for subnet %s'), subnet.name))
61
63
  tmpl = ForemanBootdisk::Renderer.new.generic_template_render(subnet)
62
- ForemanBootdisk::ISOGenerator.generate(:ipxe => tmpl, :dir => outputdir) do |image|
64
+ ForemanBootdisk::ISOGenerator.generate(ipxe: tmpl, dir: outputdir) do |image|
63
65
  output = ENV['OUTPUT'] || File.join(outputdir, "bootdisk_subnet_#{subnet.name}.iso")
64
66
  FileUtils.cp image, output
65
67
  puts "Wrote #{output}"
@@ -71,10 +73,10 @@ end
71
73
 
72
74
  # Tests
73
75
  namespace :test do
74
- desc "Test foreman_bootdisk"
76
+ desc 'Test foreman_bootdisk'
75
77
  Rake::TestTask.new(:foreman_bootdisk) do |t|
76
78
  test_dir = File.join(File.dirname(__FILE__), '../..', 'test')
77
- t.libs << ["test",test_dir]
79
+ t.libs << ['test', test_dir]
78
80
  t.pattern = "#{test_dir}/**/*_test.rb"
79
81
  t.verbose = true
80
82
  t.warning = false
@@ -83,7 +85,22 @@ end
83
85
 
84
86
  Rake::Task[:test].enhance ['test:foreman_bootdisk']
85
87
 
86
- load 'tasks/jenkins.rake'
87
- if Rake::Task.task_defined?(:'jenkins:unit')
88
- Rake::Task["jenkins:unit"].enhance ['test:foreman_bootdisk']
88
+ namespace :foreman_bootdisk do
89
+ task :rubocop do
90
+ begin
91
+ require 'rubocop/rake_task'
92
+ RuboCop::RakeTask.new(:rubocop_foreman_bootdisk) do |task|
93
+ task.patterns = ["#{ForemanBootdisk::Engine.root}/app/**/*.rb",
94
+ "#{ForemanBootdisk::Engine.root}/lib/**/*.rb",
95
+ "#{ForemanBootdisk::Engine.root}/test/**/*.rb"]
96
+ end
97
+ rescue StandardError
98
+ puts 'Rubocop not loaded.'
99
+ end
100
+
101
+ Rake::Task['rubocop_foreman_bootdisk'].invoke
102
+ end
89
103
  end
104
+
105
+ load 'tasks/jenkins.rake'
106
+ Rake::Task['jenkins:unit'].enhance ['test:foreman_bootdisk', 'foreman_bootdisk:rubocop'] if Rake::Task.task_defined?(:'jenkins:unit')