foreman_rescue 0.1.0
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 +7 -0
- data/LICENSE +619 -0
- data/README.md +30 -0
- data/Rakefile +47 -0
- data/app/controllers/foreman_rescue/hosts_controller.rb +43 -0
- data/app/helpers/concerns/foreman_rescue/hosts_helper_extensions.rb +23 -0
- data/app/models/concerns/foreman_rescue/host_extensions.rb +32 -0
- data/app/models/concerns/foreman_rescue/orchestration/tftp.rb +50 -0
- data/app/models/setting/rescue.rb +43 -0
- data/app/views/foreman_rescue/hosts/rescue.html.erb +68 -0
- data/config/routes.rb +11 -0
- data/db/migrate/20170901131321_add_rescue_mode_to_host.foreman_rescue.rb +5 -0
- data/lib/foreman_rescue.rb +4 -0
- data/lib/foreman_rescue/engine.rb +53 -0
- data/lib/foreman_rescue/version.rb +3 -0
- data/lib/tasks/foreman_rescue_tasks.rake +37 -0
- data/locale/Makefile +60 -0
- data/locale/en/foreman_rescue.po +19 -0
- data/locale/foreman_rescue.pot +19 -0
- data/locale/gemspec.rb +2 -0
- data/test/factories/host.rb +7 -0
- data/test/functional/hosts_controller_test.rb +121 -0
- data/test/test_plugin_helper.rb +24 -0
- data/test/unit/host_test.rb +80 -0
- metadata +99 -0
data/locale/Makefile
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
#
|
2
|
+
# Makefile for PO merging and MO generation. More info in the README.
|
3
|
+
#
|
4
|
+
# make all-mo (default) - generate MO files
|
5
|
+
# make check - check translations using translate-tool
|
6
|
+
# make tx-update - download and merge translations from Transifex
|
7
|
+
# make clean - clean everything
|
8
|
+
#
|
9
|
+
DOMAIN = foreman_rescue
|
10
|
+
VERSION = $(shell ruby -e 'require "rubygems";spec = Gem::Specification::load(Dir.glob("../*.gemspec")[0]);puts spec.version')
|
11
|
+
POTFILE = $(DOMAIN).pot
|
12
|
+
MOFILE = $(DOMAIN).mo
|
13
|
+
POFILES = $(shell find . -name '$(DOMAIN).po')
|
14
|
+
MOFILES = $(patsubst %.po,%.mo,$(POFILES))
|
15
|
+
POXFILES = $(patsubst %.po,%.pox,$(POFILES))
|
16
|
+
EDITFILES = $(patsubst %.po,%.edit.po,$(POFILES))
|
17
|
+
|
18
|
+
%.mo: %.po
|
19
|
+
mkdir -p $(shell dirname $@)/LC_MESSAGES
|
20
|
+
msgfmt -o $(shell dirname $@)/LC_MESSAGES/$(MOFILE) $<
|
21
|
+
|
22
|
+
# Generate MO files from PO files
|
23
|
+
all-mo: $(MOFILES)
|
24
|
+
|
25
|
+
# Check for malformed strings
|
26
|
+
%.pox: %.po
|
27
|
+
msgfmt -c $<
|
28
|
+
pofilter --nofuzzy -t variables -t blank -t urls -t emails -t long -t newlines \
|
29
|
+
-t endwhitespace -t endpunc -t puncspacing -t options -t printf -t validchars --gnome $< > $@
|
30
|
+
cat $@
|
31
|
+
! grep -q msgid $@
|
32
|
+
|
33
|
+
%.edit.po:
|
34
|
+
touch $@
|
35
|
+
|
36
|
+
check: $(POXFILES)
|
37
|
+
|
38
|
+
# Unify duplicate translations
|
39
|
+
uniq-po:
|
40
|
+
for f in $(shell find ./ -name "*.po") ; do \
|
41
|
+
msguniq $$f -o $$f ; \
|
42
|
+
done
|
43
|
+
|
44
|
+
tx-pull: $(EDITFILES)
|
45
|
+
tx pull -f
|
46
|
+
for f in $(EDITFILES) ; do \
|
47
|
+
sed -i 's/^\("Project-Id-Version: \).*$$/\1$(DOMAIN) $(VERSION)\\n"/' $$f; \
|
48
|
+
done
|
49
|
+
|
50
|
+
tx-update: tx-pull
|
51
|
+
@echo
|
52
|
+
@echo Run rake plugin:gettext[$(DOMAIN)] from the Foreman installation, then make -C locale mo-files to finish
|
53
|
+
@echo
|
54
|
+
|
55
|
+
mo-files: $(MOFILES)
|
56
|
+
git add $(POFILES) $(POTFILE) ../locale/*/LC_MESSAGES
|
57
|
+
git commit -m "i18n - pulling from tx"
|
58
|
+
@echo
|
59
|
+
@echo Changes commited!
|
60
|
+
@echo
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# foreman_rescue
|
2
|
+
#
|
3
|
+
# This file is distributed under the same license as foreman_rescue.
|
4
|
+
#
|
5
|
+
#, fuzzy
|
6
|
+
msgid ""
|
7
|
+
msgstr ""
|
8
|
+
"Project-Id-Version: version 0.0.1\n"
|
9
|
+
"Report-Msgid-Bugs-To: \n"
|
10
|
+
"POT-Creation-Date: 2014-08-20 08:46+0100\n"
|
11
|
+
"PO-Revision-Date: 2014-08-20 08:54+0100\n"
|
12
|
+
"Last-Translator: Foreman Team <foreman-dev@googlegroups.com>\n"
|
13
|
+
"Language-Team: Foreman Team <foreman-dev@googlegroups.com>\n"
|
14
|
+
"Language: \n"
|
15
|
+
"MIME-Version: 1.0\n"
|
16
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
17
|
+
"Content-Transfer-Encoding: 8bit\n"
|
18
|
+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
19
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# foreman_rescue
|
2
|
+
#
|
3
|
+
# This file is distributed under the same license as foreman_rescue.
|
4
|
+
#
|
5
|
+
#, fuzzy
|
6
|
+
msgid ""
|
7
|
+
msgstr ""
|
8
|
+
"Project-Id-Version: version 0.0.1\n"
|
9
|
+
"Report-Msgid-Bugs-To: \n"
|
10
|
+
"POT-Creation-Date: 2014-08-20 08:46+0100\n"
|
11
|
+
"PO-Revision-Date: 2014-08-20 08:46+0100\n"
|
12
|
+
"Last-Translator: Foreman Team <foreman-dev@googlegroups.com>\n"
|
13
|
+
"Language-Team: Foreman Team <foreman-dev@googlegroups.com>\n"
|
14
|
+
"Language: \n"
|
15
|
+
"MIME-Version: 1.0\n"
|
16
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
17
|
+
"Content-Transfer-Encoding: 8bit\n"
|
18
|
+
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
|
19
|
+
|
data/locale/gemspec.rb
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
module ForemanRescue
|
4
|
+
class HostsControllerTest < ::ActionController::TestCase
|
5
|
+
setup do
|
6
|
+
User.current = FactoryGirl.create(:user, :admin)
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:host) { FactoryGirl.create(:host, :managed) }
|
10
|
+
|
11
|
+
describe '#set_rescue' do
|
12
|
+
setup do
|
13
|
+
@request.env['HTTP_REFERER'] = hosts_path
|
14
|
+
end
|
15
|
+
|
16
|
+
teardown do
|
17
|
+
@request.env['HTTP_REFERER'] = ''
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when host is not saved' do
|
21
|
+
test 'the flash should inform it' do
|
22
|
+
Host::Managed.any_instance.expects(:set_rescue).returns(false)
|
23
|
+
put :set_rescue, { :id => host.name }, set_session_user
|
24
|
+
assert_response :found
|
25
|
+
assert_redirected_to hosts_path
|
26
|
+
assert flash[:error] =~ /Failed to enable #{host} for rescue system/
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'when host is saved' do
|
31
|
+
setup do
|
32
|
+
Host::Managed.any_instance.expects(:set_rescue).returns(true)
|
33
|
+
end
|
34
|
+
|
35
|
+
test 'the flash should inform it' do
|
36
|
+
put :set_rescue, { :id => host.name }, set_session_user
|
37
|
+
assert_response :found
|
38
|
+
assert_redirected_to hosts_path
|
39
|
+
assert_equal "Enabled #{host} for rescue system on next boot.", flash[:notice]
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when reboot is requested' do
|
43
|
+
let(:power_mock) { mock('power') }
|
44
|
+
|
45
|
+
setup do
|
46
|
+
Host::Managed.any_instance.stubs(:power).returns(power_mock)
|
47
|
+
end
|
48
|
+
|
49
|
+
test 'the flash should inform it' do
|
50
|
+
power_mock.stubs(:reset).returns(true)
|
51
|
+
put :set_rescue, { :id => host.name, :host => { :rescue_mode => '1' } }, set_session_user
|
52
|
+
assert_response :found
|
53
|
+
assert_redirected_to hosts_path
|
54
|
+
assert_equal "Enabled #{host} for reboot into rescue system.", flash[:notice]
|
55
|
+
end
|
56
|
+
|
57
|
+
test 'with failed reboot, the flash should inform it' do
|
58
|
+
power_mock.stubs(:reset).returns(false)
|
59
|
+
put :set_rescue, { :id => host.name, :host => { :rescue_mode => '1' } }, set_session_user
|
60
|
+
host.power.reset
|
61
|
+
assert_response :found
|
62
|
+
assert_redirected_to hosts_path
|
63
|
+
assert_equal "Enabled #{host} for boot into rescue system on next boot, but failed to power cycle the host.", flash[:notice]
|
64
|
+
end
|
65
|
+
|
66
|
+
test 'reboot raised exception, the flash should inform it' do
|
67
|
+
power_mock.stubs(:reset).raises(Foreman::Exception)
|
68
|
+
put :set_rescue, { :id => host.name, :host => { :rescue_mode => '1' } }, set_session_user
|
69
|
+
assert_response :found
|
70
|
+
assert_redirected_to hosts_path
|
71
|
+
assert_equal "Enabled #{host} for rescue system on next boot.", flash[:notice]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#cancel_rescue' do
|
78
|
+
setup do
|
79
|
+
@request.env['HTTP_REFERER'] = hosts_path
|
80
|
+
end
|
81
|
+
|
82
|
+
teardown do
|
83
|
+
@request.env['HTTP_REFERER'] = ''
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'when host is saved' do
|
87
|
+
setup do
|
88
|
+
Host::Managed.any_instance.expects(:cancel_rescue).returns(true)
|
89
|
+
end
|
90
|
+
|
91
|
+
test 'the flash should inform it' do
|
92
|
+
put :cancel_rescue, { :id => host.name }, set_session_user
|
93
|
+
assert_response :found
|
94
|
+
assert_redirected_to hosts_path
|
95
|
+
assert_equal "Canceled booting into rescue system for #{host}.", flash[:notice]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'when host is not saved' do
|
100
|
+
setup do
|
101
|
+
Host::Managed.any_instance.expects(:cancel_rescue).returns(false)
|
102
|
+
end
|
103
|
+
|
104
|
+
test 'the flash should inform it' do
|
105
|
+
put :cancel_rescue, { :id => host.name }, set_session_user
|
106
|
+
assert_response :found
|
107
|
+
assert_redirected_to hosts_path
|
108
|
+
assert_includes flash[:error], "Failed to cancel booting into rescue system for #{host}"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe '#rescue' do
|
114
|
+
test 'renders page' do
|
115
|
+
get :rescue, { :id => host.name }, set_session_user
|
116
|
+
assert_response :success
|
117
|
+
assert_template 'foreman_rescue/hosts/rescue'
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# This calls the main test_helper in Foreman-core
|
2
|
+
require 'test_helper'
|
3
|
+
require 'database_cleaner'
|
4
|
+
|
5
|
+
# Add plugin to FactoryGirl's paths
|
6
|
+
FactoryGirl.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
|
7
|
+
FactoryGirl.reload
|
8
|
+
|
9
|
+
# Foreman's setup doesn't handle cleaning up for Minitest::Spec
|
10
|
+
DatabaseCleaner.strategy = :transaction
|
11
|
+
|
12
|
+
def setup_settings
|
13
|
+
Setting::Rescue.load_defaults
|
14
|
+
end
|
15
|
+
|
16
|
+
class Minitest::Spec
|
17
|
+
before :each do
|
18
|
+
DatabaseCleaner.start
|
19
|
+
end
|
20
|
+
|
21
|
+
after :each do
|
22
|
+
DatabaseCleaner.clean
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class HostTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
User.current = FactoryGirl.build(:user, :admin)
|
6
|
+
setup_settings
|
7
|
+
disable_orchestration
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'a host with tftp orchestration' do
|
11
|
+
let(:organization) { FactoryGirl.create(:organization) }
|
12
|
+
let(:tax_location) { FactoryGirl.create(:location) }
|
13
|
+
let(:template) do
|
14
|
+
FactoryGirl.create(
|
15
|
+
:provisioning_template,
|
16
|
+
:template_kind => TemplateKind.find_by_name('PXELinux'),
|
17
|
+
:locations => [tax_location],
|
18
|
+
:organizations => [organization]
|
19
|
+
)
|
20
|
+
end
|
21
|
+
let(:os) do
|
22
|
+
FactoryGirl.create(
|
23
|
+
:operatingsystem,
|
24
|
+
:with_os_defaults,
|
25
|
+
:with_associations,
|
26
|
+
:family => 'Redhat',
|
27
|
+
:provisioning_templates => [template]
|
28
|
+
)
|
29
|
+
end
|
30
|
+
let(:host) do
|
31
|
+
FactoryGirl.create(
|
32
|
+
:host,
|
33
|
+
:managed,
|
34
|
+
:with_tftp_orchestration,
|
35
|
+
:operatingsystem => os,
|
36
|
+
:pxe_loader => 'PXELinux BIOS',
|
37
|
+
:organization => organization,
|
38
|
+
:location => tax_location
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'with rescue mode enabled' do
|
43
|
+
setup do
|
44
|
+
host.queue.clear
|
45
|
+
host.rescue_mode = true
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'should queue tftp update' do
|
49
|
+
assert_valid host
|
50
|
+
tasks = host.queue.all.map(&:name)
|
51
|
+
assert_includes tasks, "Deploy TFTP PXEGrub2 config for #{host}"
|
52
|
+
assert_includes tasks, "Deploy TFTP PXELinux config for #{host}"
|
53
|
+
assert_includes tasks, "Deploy TFTP PXEGrub config for #{host}"
|
54
|
+
assert_equal 3, tasks.size
|
55
|
+
end
|
56
|
+
|
57
|
+
test 'should deploy rescue template' do
|
58
|
+
Setting['rescue_pxelinux_tftp_template'] = template.name
|
59
|
+
ProxyAPI::TFTP.any_instance.expects(:set).with('PXELinux', host.mac, :pxeconfig => template.template).once
|
60
|
+
host.stubs(:skip_orchestration?).returns(false) # Enable orchestration
|
61
|
+
assert host.save
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'rescue mode tftp remplate rendering' do
|
67
|
+
let(:host) { FactoryGirl.build(:host, :managed, :rescue_mode) }
|
68
|
+
let(:template) do
|
69
|
+
FactoryGirl.create(:provisioning_template, :name => 'my template',
|
70
|
+
:template => 'test content',
|
71
|
+
:template_kind => template_kinds(:pxelinux))
|
72
|
+
end
|
73
|
+
|
74
|
+
test 'renders tftp template' do
|
75
|
+
Setting['rescue_pxelinux_tftp_template'] = template.name
|
76
|
+
rendered = host.primary_interface.send(:rescue_mode_pxe_render, 'PXELinux')
|
77
|
+
assert_equal template.template, rendered
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: foreman_rescue
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Timo Goebel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubocop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.49.1
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.49.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Foreman Plugin to provide the ability to boot a host into a rescue system.
|
42
|
+
email:
|
43
|
+
- timo.goebel@dm.de
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- LICENSE
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- app/controllers/foreman_rescue/hosts_controller.rb
|
52
|
+
- app/helpers/concerns/foreman_rescue/hosts_helper_extensions.rb
|
53
|
+
- app/models/concerns/foreman_rescue/host_extensions.rb
|
54
|
+
- app/models/concerns/foreman_rescue/orchestration/tftp.rb
|
55
|
+
- app/models/setting/rescue.rb
|
56
|
+
- app/views/foreman_rescue/hosts/rescue.html.erb
|
57
|
+
- config/routes.rb
|
58
|
+
- db/migrate/20170901131321_add_rescue_mode_to_host.foreman_rescue.rb
|
59
|
+
- lib/foreman_rescue.rb
|
60
|
+
- lib/foreman_rescue/engine.rb
|
61
|
+
- lib/foreman_rescue/version.rb
|
62
|
+
- lib/tasks/foreman_rescue_tasks.rake
|
63
|
+
- locale/Makefile
|
64
|
+
- locale/en/foreman_rescue.po
|
65
|
+
- locale/foreman_rescue.pot
|
66
|
+
- locale/gemspec.rb
|
67
|
+
- test/factories/host.rb
|
68
|
+
- test/functional/hosts_controller_test.rb
|
69
|
+
- test/test_plugin_helper.rb
|
70
|
+
- test/unit/host_test.rb
|
71
|
+
homepage: https://github.com/dm-drogeriemarkt/foreman_rescue
|
72
|
+
licenses:
|
73
|
+
- GPL-3.0
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.7.3
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Provides the ability to boot a host into a rescue system.
|
95
|
+
test_files:
|
96
|
+
- test/unit/host_test.rb
|
97
|
+
- test/factories/host.rb
|
98
|
+
- test/test_plugin_helper.rb
|
99
|
+
- test/functional/hosts_controller_test.rb
|