foreman_admin 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Gemfile +6 -0
- data/LICENSE +674 -0
- data/README.md +11 -0
- data/Rakefile +50 -0
- data/bin/foreman-admin +6 -0
- data/lib/foreman_admin.rb +15 -0
- data/lib/foreman_admin/backup.rb +13 -0
- data/lib/foreman_admin/command.rb +27 -0
- data/lib/foreman_admin/debug.rb +59 -0
- data/lib/foreman_admin/external_command.rb +26 -0
- data/lib/foreman_admin/main.rb +26 -0
- data/lib/foreman_admin/restore.rb +13 -0
- data/lib/foreman_admin/task_export.rb +21 -0
- data/lib/foreman_admin/update.rb +13 -0
- data/lib/foreman_admin/version.rb +7 -0
- data/test/backup_test.rb +17 -0
- data/test/command_test.rb +25 -0
- data/test/debug_test.rb +73 -0
- data/test/external_command_test.rb +26 -0
- data/test/fake-scripts/fake-foreman-debug +8 -0
- data/test/helper.rb +27 -0
- data/test/restore_test.rb +13 -0
- data/test/task_export_test.rb +25 -0
- data/test/update_test.rb +13 -0
- metadata +191 -0
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- encoding:utf-8 -*-
|
2
|
+
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'bundler/gem_tasks'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'rubocop/rake_task'
|
8
|
+
RuboCop::RakeTask.new
|
9
|
+
|
10
|
+
desc 'Run RuboCop style checker with xml output for Jenkins'
|
11
|
+
task 'rubocop:jenkins' do
|
12
|
+
system('bundle exec rubocop \
|
13
|
+
--require rubocop/formatter/checkstyle_formatter \
|
14
|
+
--format Rubocop::Formatter::CheckstyleFormatter \
|
15
|
+
--no-color --out rubocop.xml')
|
16
|
+
end
|
17
|
+
rescue LoadError
|
18
|
+
puts 'Rubocop not loaded.'
|
19
|
+
task :rubocop do
|
20
|
+
# do nothing
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
begin # TODO: remove begin-block once all i18n stuff is in place
|
25
|
+
|
26
|
+
namespace :gettext do
|
27
|
+
desc 'update pot file'
|
28
|
+
task :find do
|
29
|
+
require 'foreman-admin/version'
|
30
|
+
require 'foreman-admin/i18n'
|
31
|
+
require 'gettext/tools'
|
32
|
+
|
33
|
+
domain = ForemanAdmin::I18n::LocalDomain.new
|
34
|
+
GetText.update_potfiles(domain.domain_name,
|
35
|
+
domain.translated_files,
|
36
|
+
"#{domain.domain_name} #{ForemanAdmin.version}",
|
37
|
+
:po_root => domain.locale_dir)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
rescue => e
|
41
|
+
puts 'Error occuring during localization task'
|
42
|
+
puts e.message
|
43
|
+
end
|
44
|
+
|
45
|
+
Rake::TestTask.new do |t|
|
46
|
+
t.libs << 'test'
|
47
|
+
t.test_files = ['test/helper.rb']
|
48
|
+
end
|
49
|
+
|
50
|
+
task :default => [:test, :rubocop]
|
data/bin/foreman-admin
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
# dependencies
|
4
|
+
require 'clamp'
|
5
|
+
|
6
|
+
require 'foreman_admin/command'
|
7
|
+
require 'foreman_admin/external_command'
|
8
|
+
require 'foreman_admin/backup'
|
9
|
+
require 'foreman_admin/restore'
|
10
|
+
require 'foreman_admin/task_export'
|
11
|
+
require 'foreman_admin/update'
|
12
|
+
require 'foreman_admin/debug'
|
13
|
+
|
14
|
+
# main goes last
|
15
|
+
require 'foreman_admin/main'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module ForemanAdmin
|
4
|
+
class BackupCommand < ForemanAdmin::ExternalCommand
|
5
|
+
command_name 'backup'
|
6
|
+
description 'Backup your Foreman server'
|
7
|
+
external_invocation '/usr/sbin/foreman-backup'
|
8
|
+
|
9
|
+
# TODO: any options?
|
10
|
+
#
|
11
|
+
# or parameters?
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module ForemanAdmin
|
4
|
+
class Command < ::Clamp::Command
|
5
|
+
def self.command_name(name = nil)
|
6
|
+
@command_name = name if name
|
7
|
+
@command_name
|
8
|
+
end
|
9
|
+
|
10
|
+
def command_name
|
11
|
+
self.class.command_name
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.description(description = nil)
|
15
|
+
@description = description if description
|
16
|
+
@description
|
17
|
+
end
|
18
|
+
|
19
|
+
def description
|
20
|
+
self.class.description
|
21
|
+
end
|
22
|
+
|
23
|
+
def execute
|
24
|
+
# override me
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module ForemanAdmin
|
4
|
+
class DebugCommand < ForemanAdmin::ExternalCommand
|
5
|
+
UPLOAD_RESPONSE = 'Archive has been uploaded'
|
6
|
+
NO_UPLOAD_RESPONSE = 'Skipping archive upload'
|
7
|
+
|
8
|
+
command_name 'generate-debug'
|
9
|
+
description 'Create a foreman-debug tarball for debugging purposes'
|
10
|
+
external_invocation '/usr/sbin/foreman-debug'
|
11
|
+
|
12
|
+
option ['-d', '--directory'],
|
13
|
+
'DIR',
|
14
|
+
'Directory to place the tarball in (default: /tmp/foreman-XYZ)'
|
15
|
+
option ['-g', '--[no-]generic'],
|
16
|
+
:flag,
|
17
|
+
'Whether or not to include generic info (CPU, memory, firewall, etc)',
|
18
|
+
:default => true
|
19
|
+
option ['-a', '--[no-]tarball'],
|
20
|
+
:flag,
|
21
|
+
'Whether to generate a tarball from the resulting directory',
|
22
|
+
:default => true
|
23
|
+
option ['-m', '--max-lines'],
|
24
|
+
'LINES',
|
25
|
+
'Maximum lines to keep for each file (default: 5000)'
|
26
|
+
option ['-j', '--filter-program'],
|
27
|
+
'PROGRAM',
|
28
|
+
'Filter with provided program when creating a tarball'
|
29
|
+
option ['-p', '--password-patterns'],
|
30
|
+
:flag,
|
31
|
+
'Print password patterns being filtered out'
|
32
|
+
option ['-q', '--quiet'],
|
33
|
+
:flag,
|
34
|
+
'Quiet mode'
|
35
|
+
option ['-v', '--verbose'],
|
36
|
+
:flag,
|
37
|
+
'Verbose mode'
|
38
|
+
option ['-u', '--[no-]upload'],
|
39
|
+
:flag,
|
40
|
+
'Whether to upload archive to rsync://theforeman.org/debug-incoming',
|
41
|
+
:default => false
|
42
|
+
|
43
|
+
def external_command
|
44
|
+
args = []
|
45
|
+
args << '-d' << "'#{directory}'" if directory
|
46
|
+
args << '-g' unless generic?
|
47
|
+
args << '-a' unless tarball?
|
48
|
+
args << '-m' << max_lines if max_lines
|
49
|
+
args << '-j' << "'#{filter_program}'" if filter_program
|
50
|
+
args << '-p' if password_patterns?
|
51
|
+
args << '-q' if quiet?
|
52
|
+
args << '-v' if verbose?
|
53
|
+
args << '-u' if upload?
|
54
|
+
|
55
|
+
args.unshift(external_invocation)
|
56
|
+
args.join(' ')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module ForemanAdmin
|
4
|
+
class ExternalCommand < ForemanAdmin::Command
|
5
|
+
# The base command that will be executed externally.
|
6
|
+
# Think of this as ARGV[0] of what we're running externally.
|
7
|
+
def self.external_invocation(invocation = nil)
|
8
|
+
@external_invocation = invocation if invocation
|
9
|
+
@external_invocation
|
10
|
+
end
|
11
|
+
|
12
|
+
def external_invocation
|
13
|
+
self.class.external_invocation
|
14
|
+
end
|
15
|
+
|
16
|
+
# The exact assembled command that will be executed externally.
|
17
|
+
# Override this in a child class if you want it have logic.
|
18
|
+
def external_command
|
19
|
+
"#{external_invocation}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def execute
|
23
|
+
puts `#{external_command}`
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ForemanAdmin
|
2
|
+
class MainCommand < ForemanAdmin::Command
|
3
|
+
option '--version', :flag, 'Show version' do
|
4
|
+
puts "#{invocation_path} #{ForemanAdmin.version.version}"
|
5
|
+
exit
|
6
|
+
end
|
7
|
+
|
8
|
+
# TODO: uncomment once these external scripts are in place
|
9
|
+
|
10
|
+
# subcommand BackupCommand.command_name,
|
11
|
+
# BackupCommand.description,
|
12
|
+
# BackupCommand
|
13
|
+
# subcommand RestoreCommand.command_name,
|
14
|
+
# RestoreCommand.description,
|
15
|
+
# RestoreCommand
|
16
|
+
subcommand DebugCommand.command_name,
|
17
|
+
DebugCommand.description,
|
18
|
+
DebugCommand
|
19
|
+
subcommand TaskExportCommand.command_name,
|
20
|
+
TaskExportCommand.description,
|
21
|
+
TaskExportCommand
|
22
|
+
# subcommand UpdateCommand.command_name,
|
23
|
+
# UpdateCommand.description,
|
24
|
+
# UpdateCommand
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module ForemanAdmin
|
4
|
+
class RestoreCommand < ForemanAdmin::ExternalCommand
|
5
|
+
command_name 'restore'
|
6
|
+
description 'Restore your Foreman server'
|
7
|
+
external_invocation '/usr/sbin/foreman-restore'
|
8
|
+
|
9
|
+
# TODO: any options?
|
10
|
+
#
|
11
|
+
# or parameters?
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module ForemanAdmin
|
4
|
+
class TaskExportCommand < ForemanAdmin::ExternalCommand
|
5
|
+
command_name 'export-tasks'
|
6
|
+
description "Export a file containing Foreman's task data (default: only incomplete tasks are exported)"
|
7
|
+
external_invocation '/usr/sbin/foreman-rake foreman_tasks:export_tasks'
|
8
|
+
|
9
|
+
option ['--all'], :flag, 'Export all tasks (Note: this could take some time)'
|
10
|
+
option ['--export-file'], 'FILENAME', 'Specify the filename.tar.gz archive to export tasks into'
|
11
|
+
|
12
|
+
def external_command
|
13
|
+
args = []
|
14
|
+
args << 'tasks=all' if all?
|
15
|
+
args << "export=#{export_file}" if export_file
|
16
|
+
|
17
|
+
args.unshift(external_invocation)
|
18
|
+
args.join(' ')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module ForemanAdmin
|
4
|
+
class UpdateCommand < ForemanAdmin::ExternalCommand
|
5
|
+
command_name 'update'
|
6
|
+
description 'Update your Foreman server'
|
7
|
+
external_invocation '/usb/sbin/foreman-update fancy-style'
|
8
|
+
|
9
|
+
# TODO: any options?
|
10
|
+
#
|
11
|
+
# or parameters?
|
12
|
+
end
|
13
|
+
end
|
data/test/backup_test.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module ForemanAdmin
|
2
|
+
class BackupCommandTest < MiniTest::Unit::TestCase
|
3
|
+
include ForemanAdminTestHelpers
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@command = BackupCommand.new('')
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
@command = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_external_command
|
14
|
+
assert_equal(@command.external_command, '/usr/sbin/foreman-backup')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module ForemanAdmin
|
2
|
+
class CommandTest < MiniTest::Unit::TestCase
|
3
|
+
def setup
|
4
|
+
@command = Command.new('')
|
5
|
+
end
|
6
|
+
|
7
|
+
def teardown
|
8
|
+
@command = nil
|
9
|
+
Command.command_name(nil)
|
10
|
+
Command.description(nil)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_command_name
|
14
|
+
Command.command_name('foobar')
|
15
|
+
|
16
|
+
assert_equal(@command.command_name, 'foobar')
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_description
|
20
|
+
Command.description("this command is called 'foobar'")
|
21
|
+
|
22
|
+
assert_equal(@command.description, "this command is called 'foobar'")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/test/debug_test.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
module ForemanAdmin
|
2
|
+
class DebugCommandTest < MiniTest::Unit::TestCase
|
3
|
+
include ForemanAdminTestHelpers
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@command = DebugCommand.new('')
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
@command = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_option_directory
|
14
|
+
@command.directory = '/tmp/solid_snake'
|
15
|
+
|
16
|
+
assert_includes_option(@command, "-d '/tmp/solid_snake'")
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_option_skip_generic
|
20
|
+
@command.generic = false
|
21
|
+
|
22
|
+
assert_includes_option(@command, '-g')
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_option_no_tarball
|
26
|
+
@command.tarball = false
|
27
|
+
|
28
|
+
assert_includes_option(@command, '-a')
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_option_tarball
|
32
|
+
@command.tarball = true
|
33
|
+
|
34
|
+
refute_includes_option(@command, '-a')
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_option_max_lines
|
38
|
+
@command.max_lines = 9001
|
39
|
+
|
40
|
+
assert_includes_option(@command, '-m 9001')
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_option_filter_program
|
44
|
+
@command.filter_program = '/usr/bin/super-awesome-filter-program'
|
45
|
+
|
46
|
+
assert_includes_option(@command, "-j '/usr/bin/super-awesome-filter-program'")
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_option_passwd_patterns
|
50
|
+
@command.password_patterns = true
|
51
|
+
|
52
|
+
assert_includes_option(@command, '-p')
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_option_quiet
|
56
|
+
@command.quiet = true
|
57
|
+
|
58
|
+
assert_includes_option(@command, '-q')
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_option_verbose
|
62
|
+
@command.verbose = true
|
63
|
+
|
64
|
+
assert_includes_option(@command, '-v')
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_option_upload
|
68
|
+
@command.upload = true
|
69
|
+
|
70
|
+
assert_includes_option(@command, '-u')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ForemanAdmin
|
2
|
+
class ExternalCommandTest < MiniTest::Unit::TestCase
|
3
|
+
include ForemanAdminTestHelpers
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@command = ExternalCommand.new('')
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
@command = nil
|
11
|
+
ExternalCommand.external_invocation(nil)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_external_invocation
|
15
|
+
ExternalCommand.external_invocation('figlet')
|
16
|
+
|
17
|
+
assert_equal(@command.external_invocation, 'figlet')
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_external_command
|
21
|
+
ExternalCommand.external_invocation('figlet')
|
22
|
+
|
23
|
+
assert_equal(@command.external_command, 'figlet')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|