foreman_bootdisk 4.0.1 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1efb079d68935777825c7c979322ded482808c4a
4
- data.tar.gz: a01ad93b9680558aac5234bc7f9b1545076a22c6
3
+ metadata.gz: f47f571066b7c564c077c4aaa714c6e0ce3fc74e
4
+ data.tar.gz: 683ef371d2cb265cf2d8b54beecf54645a49603c
5
5
  SHA512:
6
- metadata.gz: 2866d33e1fdf7dfd4280aa0ddcc2306172e495a9a253eed2b889b030bce787209e0f5491546c95c6a39452fee6e1e468877b9ba335b1645b85f73c4e8d1c0a0e
7
- data.tar.gz: be89f39658774049af6d8f62126e573b0f69bcedee8913a0d3caa35575a5d95f77a98495cbd694a06b69b414e3c91bba0bd1ec5d516dcb5bfb89c0cb0503b36e
6
+ metadata.gz: c8a7aa167e18ad4741ee04dd68cd0a70bcf4b195697bcccc10b8d7132eff40adae3589f84f385e1f9e8eef7f38e84c6d26be29714a66fa9d883853b711387317
7
+ data.tar.gz: 8e5a186803695d0f4c0ca5e2229742c4614eb13e7e23dbf767eb5697a7f258a10ae783f39edc7d21e27fe3dcb73accaacfa8dea1fcd0ad938e4fe1c6dea02abb
data/CHANGES.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## v4.0.2
4
+ * fix controller compatibility with Foreman 1.7
5
+ * fix foreman_url error when building generic ISO
6
+ * add functional tests
7
+ * fix seed idempotency test
8
+
3
9
  ## v4.0.1
4
10
  * rake task accepts a dir for the output path, and falls back to a temporary
5
11
  directory if the cwd is not writable (#7370)
@@ -10,7 +10,7 @@ module ForemanBootdisk
10
10
  api_base_url "/bootdisk/api"
11
11
  end
12
12
 
13
- before_filter :find_host, :only => :host
13
+ before_filter :find_resource, :only => :host
14
14
  skip_after_filter :log_response_body
15
15
 
16
16
  # no-op, but required for apipie documentation
@@ -44,23 +44,8 @@ module ForemanBootdisk
44
44
 
45
45
  private
46
46
 
47
- def action_permission
48
- case params[:action]
49
- when 'generic'
50
- :download
51
- when 'host'
52
- :view
53
- else
54
- super
55
- end
56
- end
57
-
58
- def find_host
59
- find_resource('hosts')
60
- end
61
-
62
- def resource_class
63
- Host::Managed
47
+ def resource_scope
48
+ Host::Managed.authorized('view_hosts')
64
49
  end
65
50
  end
66
51
  end
@@ -11,7 +11,7 @@ module ForemanBootdisk
11
11
  end
12
12
 
13
13
  tmpl = ConfigTemplate.find_by_name(Setting[:bootdisk_generic_host_template]) || raise(::Foreman::Exception.new(N_('Unable to find template specified by %s setting'), 'bootdisk_generic_host_template'))
14
- @host = Struct.new(:token).new(nil)
14
+ @host = Struct.new(:token, :subnet).new(nil, nil)
15
15
  unattended_render(tmpl.template)
16
16
  end
17
17
 
@@ -2,24 +2,32 @@ kind = TemplateKind.find_or_create_by_name('Bootdisk')
2
2
 
3
3
  ConfigTemplate.without_auditing do
4
4
  content = File.read(File.join(ForemanBootdisk::Engine.root, 'app', 'views', 'foreman_bootdisk', 'host.erb'))
5
- ConfigTemplate.find_or_create_by_name(
5
+ tmpl = ConfigTemplate.find_or_create_by_name(
6
6
  :name => 'Boot disk iPXE - host',
7
7
  :template_kind_id => kind.id,
8
8
  :snippet => false,
9
9
  :template => content
10
- ).update_attributes(:template => content,
11
- :default => true,
12
- :vendor => "Foreman boot disk",
13
- :locked => true)
10
+ )
11
+ tmpl.attributes = {
12
+ :template => content,
13
+ :default => true,
14
+ :vendor => "Foreman boot disk",
15
+ :locked => true
16
+ }
17
+ tmpl.save!(:validate => false) if tmpl.changes.present?
14
18
 
15
19
  content = File.read(File.join(ForemanBootdisk::Engine.root, 'app', 'views', 'foreman_bootdisk', 'generic_host.erb'))
16
- ConfigTemplate.find_or_create_by_name(
20
+ tmpl = ConfigTemplate.find_or_create_by_name(
17
21
  :name => 'Boot disk iPXE - generic host',
18
22
  :template_kind_id => kind.id,
19
23
  :snippet => false,
20
24
  :template => content
21
- ).update_attributes(:template => content,
22
- :default => true,
23
- :vendor => "Foreman boot disk",
24
- :locked => true)
25
+ )
26
+ tmpl.attributes = {
27
+ :template => content,
28
+ :default => true,
29
+ :vendor => "Foreman boot disk",
30
+ :locked => true
31
+ }
32
+ tmpl.save!(:validate => false) if tmpl.changes.present?
25
33
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanBootdisk
2
- VERSION = '4.0.1'
2
+ VERSION = '4.0.2'
3
3
  end
@@ -47,3 +47,25 @@ namespace :bootdisk do
47
47
  end
48
48
  end
49
49
  end
50
+
51
+ # Tests
52
+ namespace :test do
53
+ desc "Test foreman_bootdisk"
54
+ Rake::TestTask.new(:foreman_bootdisk) do |t|
55
+ test_dir = File.join(File.dirname(__FILE__), '../..', 'test')
56
+ t.libs << ["test",test_dir]
57
+ t.pattern = "#{test_dir}/**/*_test.rb"
58
+ t.verbose = true
59
+ end
60
+ end
61
+
62
+ Rake::Task[:test].enhance do
63
+ Rake::Task['test:foreman_bootdisk'].invoke
64
+ end
65
+
66
+ load 'tasks/jenkins.rake'
67
+ if Rake::Task.task_defined?(:'jenkins:unit')
68
+ Rake::Task["jenkins:unit"].enhance do
69
+ Rake::Task['test:foreman_bootdisk'].invoke
70
+ end
71
+ end
@@ -0,0 +1,33 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class ForemanBootdisk::Api::V2::DisksControllerTest < ActionController::TestCase
4
+ setup :setup_bootdisk
5
+
6
+ test "should generate generic image" do
7
+ ForemanBootdisk::ISOGenerator.expects(:generate).with(has_entry(:ipxe => regexp_matches(/generic host template/))).yields("temp ISO")
8
+ File.expects(:read).with("temp ISO").returns("ISO image")
9
+ get :generic, {}
10
+ assert_response :success
11
+ assert_equal "ISO image", @response.body
12
+ end
13
+
14
+ describe "#host" do
15
+ setup :setup_host
16
+
17
+ test "should generate host image" do
18
+ ForemanBootdisk::ISOGenerator.expects(:generate).with(has_entry(:ipxe => regexp_matches(/host template/))).yields("temp ISO")
19
+ File.expects(:read).with("temp ISO").returns("ISO image")
20
+ get :host, {:id => @host.name}
21
+ assert_response :success
22
+ assert_equal "ISO image", @response.body
23
+ end
24
+
25
+ test "should generate full host image" do
26
+ ForemanBootdisk::ISOGenerator.expects(:generate_full_host).with(@host).yields("temp ISO")
27
+ File.expects(:read).with("temp ISO").returns("ISO image")
28
+ get :host, {:id => @host.name, :full => true}
29
+ assert_response :success
30
+ assert_equal "ISO image", @response.body
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,38 @@
1
+ require 'test_plugin_helper'
2
+
3
+ class ForemanBootdisk::DisksControllerTest < ActionController::TestCase
4
+ setup :setup_bootdisk
5
+
6
+ test "should generate generic image" do
7
+ ForemanBootdisk::ISOGenerator.expects(:generate).with(has_entry(:ipxe => regexp_matches(/generic host template/))).yields("temp ISO")
8
+ File.expects(:read).with("temp ISO").returns("ISO image")
9
+ get :generic, {}, set_session_user
10
+ assert_response :success
11
+ assert_equal "ISO image", @response.body
12
+ end
13
+
14
+ describe "#host" do
15
+ setup :setup_host
16
+
17
+ test "should generate host image" do
18
+ ForemanBootdisk::ISOGenerator.expects(:generate).with(has_entry(:ipxe => regexp_matches(/host template/))).yields("temp ISO")
19
+ File.expects(:read).with("temp ISO").returns("ISO image")
20
+ get :host, {:id => @host.name}, set_session_user
21
+ assert_response :success
22
+ assert_equal "ISO image", @response.body
23
+ end
24
+
25
+ test "should generate full host image" do
26
+ ForemanBootdisk::ISOGenerator.expects(:generate_full_host).with(@host).yields("temp ISO")
27
+ File.expects(:read).with("temp ISO").returns("ISO image")
28
+ get :full_host, {:id => @host.name}, set_session_user
29
+ assert_response :success
30
+ assert_equal "ISO image", @response.body
31
+ end
32
+ end
33
+
34
+ test "should render help" do
35
+ get :help, {}, set_session_user
36
+ assert_response :success
37
+ end
38
+ end
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ class ActionController::TestCase
4
+ def setup_bootdisk
5
+ setup_routes
6
+ setup_settings
7
+ setup_templates
8
+ end
9
+
10
+ def setup_routes
11
+ @routes = ForemanBootdisk::Engine.routes
12
+ end
13
+
14
+ def setup_settings
15
+ Setting::Bootdisk.load_defaults
16
+ end
17
+
18
+ def setup_templates
19
+ load File.join(File.dirname(__FILE__), '..', 'db', 'seeds.d', '50-bootdisk_templates.rb')
20
+ end
21
+
22
+ def setup_host
23
+ subnet = FactoryGirl.create(:subnet, :gateway => '10.0.1.254', :dns_primary => '8.8.8.8')
24
+ @host = FactoryGirl.create(:host, :subnet => subnet)
25
+ end
26
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_bootdisk
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.1
4
+ version: 4.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominic Cleal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-17 00:00:00.000000000 Z
11
+ date: 2014-11-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Plugin for Foreman that creates iPXE-based boot disks to provision hosts
14
14
  without the need for PXE infrastructure.
@@ -24,7 +24,6 @@ files:
24
24
  - CHANGES.md
25
25
  - LICENSE
26
26
  - README.md
27
- - Rakefile
28
27
  - app/controllers/concerns/foreman_bootdisk/unattended_controller_ext.rb
29
28
  - app/controllers/foreman_bootdisk/api/v2/disks_controller.rb
30
29
  - app/controllers/foreman_bootdisk/disks_controller.rb
@@ -79,6 +78,9 @@ files:
79
78
  - locale/zh_CN/foreman_bootdisk.po
80
79
  - locale/zh_TW/LC_MESSAGES/foreman_bootdisk.mo
81
80
  - locale/zh_TW/foreman_bootdisk.po
81
+ - test/functional/foreman_bootdisk/api/v2/disks_controller_test.rb
82
+ - test/functional/foreman_bootdisk/disks_controller_test.rb
83
+ - test/test_plugin_helper.rb
82
84
  homepage: http://github.com/theforeman/foreman_bootdisk
83
85
  licenses:
84
86
  - GPL-3
data/Rakefile DELETED
@@ -1,105 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'rake'
5
- require 'fileutils'
6
-
7
- task :default => :test
8
-
9
- PLUGIN_NAME = "bootdisk"
10
- ENGINE_DIR = File.expand_path('..', __FILE__)
11
- FOREMAN_DIR = '.foreman_app'
12
-
13
- ENV['TEXTDOMAIN'] = PLUGIN_NAME
14
- import "#{FOREMAN_DIR}/Rakefile" if File.exists? "#{FOREMAN_DIR}/Rakefile"
15
-
16
- namespace :setup do
17
- desc "Download latest foreman core devel source and install dependencies"
18
- task :foreman_prepare do
19
- foreman_repo = 'https://github.com/theforeman/foreman.git'
20
- foreman_gemfile = File.join(FOREMAN_DIR, "Gemfile")
21
- unless File.exists?(foreman_gemfile)
22
- puts "Foreman source code is not present at #{FOREMAN_DIR}"
23
- puts "Downloading latest Foreman development branch into #{FOREMAN_DIR}..."
24
- FileUtils.mkdir_p(FOREMAN_DIR)
25
-
26
- unless system("git clone --depth 1 #{foreman_repo} #{FOREMAN_DIR}")
27
- puts "Error while getting latest Foreman code from #{foreman_repo} into #{FOREMAN_DIR}"
28
- fail
29
- end
30
- end
31
-
32
- settings_file = "#{FOREMAN_DIR}/config/settings.yaml"
33
- unless File.exists?(settings_file)
34
- puts 'Preparing settings file'
35
- FileUtils.copy("#{settings_file}.example", settings_file)
36
- end
37
-
38
- db_file = "#{FOREMAN_DIR}/config/database.yml"
39
- unless File.exists?(db_file)
40
- puts 'Preparing database file'
41
- FileUtils.copy("#{db_file}.example", db_file)
42
- end
43
-
44
- ["#{ENGINE_DIR}/.bundle/config", "#{FOREMAN_DIR}/.bundle/config"].each do |bundle_file|
45
- unless File.exists?(bundle_file)
46
- FileUtils.mkdir_p(File.dirname(bundle_file))
47
- puts 'Preparing bundler configuration'
48
- File.open(bundle_file, 'w') { |f| f << <<FILE }
49
- ---
50
- BUNDLE_WITHOUT: console:development:fog:gce:jsonp:libvirt:mysql:mysql2:ovirt:postgresql:vmware
51
- FILE
52
- end
53
- end
54
-
55
- local_gemfile = "#{FOREMAN_DIR}/bundler.d/Gemfile.local.rb"
56
- unless File.exist?(local_gemfile)
57
- File.open(local_gemfile, 'w') { |f| f << <<GEMFILE }
58
- gem "facter"
59
- GEMFILE
60
- end
61
-
62
- puts 'Installing dependencies...'
63
- unless system('bundle install')
64
- fail
65
- end
66
- end
67
-
68
- task :db_prepare do
69
- unless File.exists?(FOREMAN_DIR)
70
- puts <<MESSAGE
71
- Foreman source code not prepared. Run
72
-
73
- rake setup:foreman_prepare
74
-
75
- to download foreman source and its dependencies
76
- MESSAGE
77
- fail
78
- end
79
-
80
- # once we are Ruby19 only, switch to block variant of cd
81
- pwd = FileUtils.pwd
82
- FileUtils.cd(FOREMAN_DIR)
83
- unless system('bundle exec rake db:test:prepare RAILS_ENV=test')
84
- puts "Migrating database first"
85
- system('bundle exec rake db:migrate db:schema:dump') || fail
86
- end
87
- FileUtils.cd(pwd)
88
- end
89
-
90
- task :all => [:foreman_prepare, :db_prepare]
91
- end
92
-
93
- namespace :test do
94
- task :set_loadpath do
95
- %w[lib test].each do |dir|
96
- $:.unshift(File.expand_path(dir, ENGINE_DIR))
97
- end
98
- end
99
-
100
- task :all => ['setup:db_prepare', 'test:set_loadpath'] do
101
- Dir.glob('test/**/*_test.rb') { |f| require f.sub('test/','') unless f.include? '.foreman_app/' }
102
- end
103
- end
104
-
105
- task :test => 'test:all'