foreman_omaha 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +619 -0
- data/README.md +51 -0
- data/Rakefile +47 -0
- data/app/assets/images/Omaha.png +0 -0
- data/app/controllers/api/v2/omaha_reports_controller.rb +86 -0
- data/app/controllers/omaha_reports_controller.rb +57 -0
- data/app/helpers/concerns/foreman_omaha/hosts_helper_extensions.rb +15 -0
- data/app/helpers/omaha_reports_helper.rb +28 -0
- data/app/models/concerns/foreman_omaha/host_extensions.rb +11 -0
- data/app/models/foreman_omaha/fact_name.rb +7 -0
- data/app/models/foreman_omaha/omaha_report.rb +54 -0
- data/app/models/host_status/omaha_status.rb +44 -0
- data/app/services/foreman_omaha/fact_importer.rb +11 -0
- data/app/services/foreman_omaha/fact_parser.rb +32 -0
- data/app/services/foreman_omaha/omaha_report_importer.rb +28 -0
- data/app/views/api/v2/omaha_reports/base.json.rabl +3 -0
- data/app/views/api/v2/omaha_reports/create.json.rabl +3 -0
- data/app/views/api/v2/omaha_reports/index.json.rabl +3 -0
- data/app/views/api/v2/omaha_reports/main.json.rabl +5 -0
- data/app/views/api/v2/omaha_reports/show.json.rabl +3 -0
- data/app/views/api/v2/omaha_reports/update.json.rabl +3 -0
- data/app/views/omaha_reports/_details.html.erb +28 -0
- data/app/views/omaha_reports/_list.html.erb +34 -0
- data/app/views/omaha_reports/index.html.erb +2 -0
- data/app/views/omaha_reports/show.html.erb +21 -0
- data/app/views/omaha_reports/welcome.html.erb +14 -0
- data/config/routes.rb +29 -0
- data/db/migrate/20160812083100_add_omaha_fields_to_reports.foreman_omaha.rb +5 -0
- data/db/seeds.d/60_omaha_proxy_feature.rb +2 -0
- data/lib/foreman_omaha/engine.rb +78 -0
- data/lib/foreman_omaha/version.rb +3 -0
- data/lib/foreman_omaha.rb +4 -0
- data/lib/tasks/foreman_omaha_tasks.rake +45 -0
- data/locale/Makefile +60 -0
- data/locale/en/foreman_omaha.po +19 -0
- data/locale/foreman_omaha.pot +19 -0
- data/locale/gemspec.rb +2 -0
- data/test/factories/feature.rb +7 -0
- data/test/factories/foreman_omaha_factories.rb +9 -0
- data/test/factories/smart_proxy.rb +7 -0
- data/test/functional/api/v2/omaha_reports_controller_test.rb +122 -0
- data/test/functional/omaha_reports_controller_test.rb +54 -0
- data/test/test_plugin_helper.rb +22 -0
- data/test/unit/omaha_report_test.rb +86 -0
- metadata +125 -0
@@ -0,0 +1,78 @@
|
|
1
|
+
module ForemanOmaha
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
engine_name 'foreman_omaha'
|
4
|
+
|
5
|
+
config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]
|
6
|
+
config.autoload_paths += Dir["#{config.root}/app/helpers/concerns"]
|
7
|
+
config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
|
8
|
+
config.autoload_paths += Dir["#{config.root}/app/services"]
|
9
|
+
|
10
|
+
# Add any db migrations
|
11
|
+
initializer 'foreman_omaha.load_app_instance_data' do |app|
|
12
|
+
ForemanOmaha::Engine.paths['db/migrate'].existent.each do |path|
|
13
|
+
app.config.paths['db/migrate'] << path
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
initializer 'foreman_omaha.register_plugin', :before => :finisher_hook do |_app|
|
18
|
+
Foreman::Plugin.register :foreman_omaha do
|
19
|
+
requires_foreman '>= 1.12'
|
20
|
+
|
21
|
+
apipie_documented_controllers ["#{ForemanOmaha::Engine.root}/app/controllers/api/v2/*.rb"]
|
22
|
+
|
23
|
+
register_custom_status HostStatus::OmahaStatus
|
24
|
+
|
25
|
+
# Add permissions
|
26
|
+
security_block :foreman_omaha do
|
27
|
+
permission :view_omaha_reports, :omaha_reports => [:index, :show, :auto_complete_search],
|
28
|
+
:'api/v2/omaha_reports' => [:index, :show, :last]
|
29
|
+
permission :destroy_omaha_reports, :omaha_reports => [:destroy],
|
30
|
+
:'api/v2/config_reports' => [:destroy]
|
31
|
+
permission :upload_omaha_reports, :omaha_reports => [:create],
|
32
|
+
:'api/v2/omaha_reports' => [:create]
|
33
|
+
end
|
34
|
+
|
35
|
+
role 'Omaha reports viewer',
|
36
|
+
[:view_omaha_reports]
|
37
|
+
role 'Omaha reports manager',
|
38
|
+
[:view_omaha_reports, :destroy_omaha_reports, :upload_omaha_reports]
|
39
|
+
|
40
|
+
# add menu entry
|
41
|
+
menu :top_menu, :omaha_reports,
|
42
|
+
:url_hash => { controller: :omaha_reports, action: :index },
|
43
|
+
:caption => N_('Omaha reports'),
|
44
|
+
:parent => :monitor_menu,
|
45
|
+
after: :reports
|
46
|
+
end
|
47
|
+
|
48
|
+
if respond_to?(:hosts_controller_action_scope)
|
49
|
+
hosts_controller_action_scope(:index) { |base_scope| base_scope.includes(:last_omaha_report_object) }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Include concerns in this config.to_prepare block
|
54
|
+
config.to_prepare do
|
55
|
+
begin
|
56
|
+
::FactImporter.register_fact_importer(:foreman_omaha, ForemanOmaha::FactImporter)
|
57
|
+
::FactParser.register_fact_parser(:foreman_omaha, ForemanOmaha::FactParser)
|
58
|
+
|
59
|
+
Host::Managed.send(:include, ForemanOmaha::HostExtensions)
|
60
|
+
HostsHelper.send(:include, ForemanOmaha::HostsHelperExtensions)
|
61
|
+
rescue => e
|
62
|
+
Rails.logger.warn "ForemanOmaha: skipping engine hook (#{e})"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
rake_tasks do
|
67
|
+
Rake::Task['db:seed'].enhance do
|
68
|
+
ForemanOmaha::Engine.load_seed
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
initializer 'foreman_omaha.register_gettext', after: :load_config_initializers do |_app|
|
73
|
+
locale_dir = File.join(File.expand_path('../../..', __FILE__), 'locale')
|
74
|
+
locale_domain = 'foreman_omaha'
|
75
|
+
Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# Tasks
|
2
|
+
namespace :foreman_omaha do
|
3
|
+
namespace :example do
|
4
|
+
desc 'Example Task'
|
5
|
+
task task: :environment do
|
6
|
+
# Task goes here
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# Tests
|
12
|
+
namespace :test do
|
13
|
+
desc 'Test ForemanOmaha'
|
14
|
+
Rake::TestTask.new(:foreman_omaha) do |t|
|
15
|
+
test_dir = File.join(File.dirname(__FILE__), '../..', 'test')
|
16
|
+
t.libs << ['test', test_dir]
|
17
|
+
t.pattern = "#{test_dir}/**/*_test.rb"
|
18
|
+
t.verbose = true
|
19
|
+
t.warning = false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
namespace :foreman_omaha do
|
24
|
+
task :rubocop do
|
25
|
+
begin
|
26
|
+
require 'rubocop/rake_task'
|
27
|
+
RuboCop::RakeTask.new(:rubocop_foreman_omaha) do |task|
|
28
|
+
task.patterns = ["#{ForemanOmaha::Engine.root}/app/**/*.rb",
|
29
|
+
"#{ForemanOmaha::Engine.root}/lib/**/*.rb",
|
30
|
+
"#{ForemanOmaha::Engine.root}/test/**/*.rb"]
|
31
|
+
end
|
32
|
+
rescue
|
33
|
+
puts 'Rubocop not loaded.'
|
34
|
+
end
|
35
|
+
|
36
|
+
Rake::Task['rubocop_foreman_omaha'].invoke
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
Rake::Task[:test].enhance ['test:foreman_omaha']
|
41
|
+
|
42
|
+
load 'tasks/jenkins.rake'
|
43
|
+
if Rake::Task.task_defined?(:'jenkins:unit')
|
44
|
+
Rake::Task['jenkins:unit'].enhance ['test:foreman_omaha', 'foreman_omaha:rubocop']
|
45
|
+
end
|
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_omaha
|
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_omaha
|
2
|
+
#
|
3
|
+
# This file is distributed under the same license as foreman_omaha.
|
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_omaha
|
2
|
+
#
|
3
|
+
# This file is distributed under the same license as foreman_omaha.
|
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,122 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Api::V2::OmahaReportsControllerTest < ActionController::TestCase
|
4
|
+
test 'create valid' do
|
5
|
+
post :create, { :omaha_report => create_report }, set_session_user
|
6
|
+
assert_response :success
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'create invalid' do
|
10
|
+
post :create, { :omaha_report => ['not a hash', 'throw an error'] }, set_session_user
|
11
|
+
assert_response :unprocessable_entity
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'should get index' do
|
15
|
+
FactoryGirl.create(:omaha_report)
|
16
|
+
get :index, {}
|
17
|
+
assert_response :success
|
18
|
+
assert_not_nil assigns(:omaha_reports)
|
19
|
+
reports = ActiveSupport::JSON.decode(@response.body)
|
20
|
+
assert !reports['results'].empty?
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'should show individual record' do
|
24
|
+
report = FactoryGirl.create(:omaha_report)
|
25
|
+
get :show, :id => report.to_param
|
26
|
+
assert_response :success
|
27
|
+
show_response = ActiveSupport::JSON.decode(@response.body)
|
28
|
+
assert !show_response.empty?
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'should destroy report' do
|
32
|
+
report = FactoryGirl.create(:omaha_report)
|
33
|
+
assert_difference('ForemanOmaha::OmahaReport.count', -1) do
|
34
|
+
delete :destroy, :id => report.to_param
|
35
|
+
end
|
36
|
+
assert_response :success
|
37
|
+
refute Report.find_by_id(report.id)
|
38
|
+
end
|
39
|
+
|
40
|
+
test 'should get reports for given host only' do
|
41
|
+
report = FactoryGirl.create(:omaha_report)
|
42
|
+
get :index, :host_id => report.host.to_param
|
43
|
+
assert_response :success
|
44
|
+
assert_not_nil assigns(:omaha_reports)
|
45
|
+
reports = ActiveSupport::JSON.decode(@response.body)
|
46
|
+
assert !reports['results'].empty?
|
47
|
+
assert_equal 1, reports['results'].count
|
48
|
+
end
|
49
|
+
|
50
|
+
test 'should return empty result for host with no reports' do
|
51
|
+
host = FactoryGirl.create(:host)
|
52
|
+
get :index, :host_id => host.to_param
|
53
|
+
assert_response :success
|
54
|
+
assert_not_nil assigns(:omaha_reports)
|
55
|
+
reports = ActiveSupport::JSON.decode(@response.body)
|
56
|
+
assert reports['results'].empty?
|
57
|
+
assert_equal 0, reports['results'].count
|
58
|
+
end
|
59
|
+
|
60
|
+
test 'should get last report' do
|
61
|
+
reports = FactoryGirl.create_list(:omaha_report, 5)
|
62
|
+
get :last, set_session_user
|
63
|
+
assert_response :success
|
64
|
+
assert_not_nil assigns(:omaha_report)
|
65
|
+
report = ActiveSupport::JSON.decode(@response.body)
|
66
|
+
assert !report.empty?
|
67
|
+
assert_equal reports.last, ForemanOmaha::OmahaReport.find(report['id'])
|
68
|
+
end
|
69
|
+
|
70
|
+
test 'should get last report for given host only' do
|
71
|
+
main_report = FactoryGirl.create(:omaha_report)
|
72
|
+
FactoryGirl.create_list(:omaha_report, 5)
|
73
|
+
get :last, { :host_id => main_report.host.to_param }, set_session_user
|
74
|
+
assert_response :success
|
75
|
+
assert_not_nil assigns(:omaha_report)
|
76
|
+
report = ActiveSupport::JSON.decode(@response.body)
|
77
|
+
assert !report.empty?
|
78
|
+
assert_equal main_report, ForemanOmaha::OmahaReport.find(report['id'])
|
79
|
+
end
|
80
|
+
|
81
|
+
test 'should give error if no last report for given host' do
|
82
|
+
host = FactoryGirl.create(:host)
|
83
|
+
get :last, :host_id => host.to_param
|
84
|
+
assert_response :not_found
|
85
|
+
end
|
86
|
+
|
87
|
+
test 'cannot view the last report without hosts view permission' do
|
88
|
+
setup_user('view', 'omaha_reports')
|
89
|
+
report = FactoryGirl.create(:report)
|
90
|
+
get :last, { :host_id => report.host.id }, set_session_user.merge(:user => User.current.id)
|
91
|
+
assert_response :not_found
|
92
|
+
end
|
93
|
+
|
94
|
+
describe 'unpriveliged user' do
|
95
|
+
def setup
|
96
|
+
User.current = users(:one)
|
97
|
+
end
|
98
|
+
|
99
|
+
test 'hosts with a registered smart proxy on should create a report successfully' do
|
100
|
+
Setting[:restrict_registered_smart_proxies] = true
|
101
|
+
Setting[:require_ssl_smart_proxies] = false
|
102
|
+
|
103
|
+
proxy = FactoryGirl.create(:smart_proxy, :omaha)
|
104
|
+
host = URI.parse(proxy.url).host
|
105
|
+
Resolv.any_instance.stubs(:getnames).returns([host])
|
106
|
+
post :create, :omaha_report => create_report
|
107
|
+
assert_equal proxy, @controller.detected_proxy
|
108
|
+
assert_response :created
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
def create_report
|
115
|
+
{
|
116
|
+
'host' => 'test.example.com',
|
117
|
+
'status' => 'downloading',
|
118
|
+
'omaha_version' => '1068.9.0',
|
119
|
+
'reported_at' => Time.now.utc.to_s
|
120
|
+
}
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class OmahaReportsControllerTest < ActionController::TestCase
|
4
|
+
test '#index' do
|
5
|
+
FactoryGirl.create(:omaha_report)
|
6
|
+
get :index, {}, set_session_user
|
7
|
+
assert_response :success
|
8
|
+
assert_not_nil assigns('omaha_reports')
|
9
|
+
assert_template 'index'
|
10
|
+
end
|
11
|
+
|
12
|
+
test '#show' do
|
13
|
+
report = FactoryGirl.create(:omaha_report)
|
14
|
+
get :show, { :id => report.id }, set_session_user
|
15
|
+
assert_template 'show'
|
16
|
+
end
|
17
|
+
|
18
|
+
test '404 on #show when id is blank' do
|
19
|
+
get :show, { :id => ' ' }, set_session_user
|
20
|
+
assert_response :missing
|
21
|
+
assert_template 'common/404'
|
22
|
+
end
|
23
|
+
|
24
|
+
test '#show last' do
|
25
|
+
FactoryGirl.create(:omaha_report)
|
26
|
+
get :show, { :id => 'last' }, set_session_user
|
27
|
+
assert_template 'show'
|
28
|
+
end
|
29
|
+
|
30
|
+
test '404 on #show last when no reports available' do
|
31
|
+
get :show, { :id => 'last', :host_id => FactoryGirl.create(:host) }, set_session_user
|
32
|
+
assert_response :missing
|
33
|
+
assert_template 'common/404'
|
34
|
+
end
|
35
|
+
|
36
|
+
test '#show last report for host' do
|
37
|
+
report = FactoryGirl.create(:omaha_report)
|
38
|
+
get :show, { :id => 'last', :host_id => report.host.to_param }, set_session_user
|
39
|
+
assert_template 'show'
|
40
|
+
end
|
41
|
+
|
42
|
+
test 'render 404 when #show invalid report for a host is requested' do
|
43
|
+
get :show, { :id => 'last', :host_id => 'blalala.domain.com' }, set_session_user
|
44
|
+
assert_response :missing
|
45
|
+
assert_template 'common/404'
|
46
|
+
end
|
47
|
+
|
48
|
+
test '#destroy' do
|
49
|
+
report = FactoryGirl.create(:omaha_report)
|
50
|
+
delete :destroy, { :id => report }, set_session_user
|
51
|
+
assert_redirected_to omaha_reports_url
|
52
|
+
assert !ConfigReport.exists?(report.id)
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,22 @@
|
|
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
|
+
module Minitest
|
13
|
+
class Spec
|
14
|
+
before :each do
|
15
|
+
DatabaseCleaner.start
|
16
|
+
end
|
17
|
+
|
18
|
+
after :each do
|
19
|
+
DatabaseCleaner.clean
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class OmahaReportTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
User.current = User.find_by_login 'admin'
|
6
|
+
@report = FactoryGirl.create(:omaha_report)
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'status' do
|
10
|
+
test 'should be complete' do
|
11
|
+
@report.status = 'complete'
|
12
|
+
assert_equal 'complete', @report.status
|
13
|
+
assert_equal 'Complete', @report.to_label
|
14
|
+
end
|
15
|
+
|
16
|
+
test 'should be downloading' do
|
17
|
+
@report.status = 'downloading'
|
18
|
+
assert_equal 'downloading', @report.status
|
19
|
+
assert_equal 'Downloading', @report.to_label
|
20
|
+
end
|
21
|
+
|
22
|
+
test 'should be downloaded' do
|
23
|
+
@report.status = 'downloaded'
|
24
|
+
assert_equal 'downloaded', @report.status
|
25
|
+
assert_equal 'Downloaded', @report.to_label
|
26
|
+
end
|
27
|
+
|
28
|
+
test 'should be installed' do
|
29
|
+
@report.status = 'installed'
|
30
|
+
assert_equal 'installed', @report.status
|
31
|
+
assert_equal 'Installed', @report.to_label
|
32
|
+
end
|
33
|
+
|
34
|
+
test 'should be installed' do
|
35
|
+
@report.status = 'instance_hold'
|
36
|
+
assert_equal 'instance_hold', @report.status
|
37
|
+
assert_equal 'Instance Hold', @report.to_label
|
38
|
+
end
|
39
|
+
|
40
|
+
test 'should be error' do
|
41
|
+
@report.status = 'error'
|
42
|
+
assert_equal 'error', @report.status
|
43
|
+
assert_equal 'Error', @report.to_label
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'operatingsystem' do
|
48
|
+
test 'should get operatingsystem' do
|
49
|
+
os = FactoryGirl.create(:coreos, :major => '1068', :minor => '9.0')
|
50
|
+
assert_equal os, @report.operatingsystem
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'should parse major, minor' do
|
54
|
+
assert_equal '1068', @report.osmajor
|
55
|
+
assert_equal '9.0', @report.osminor
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context '#import' do
|
60
|
+
test 'should import a report' do
|
61
|
+
host = FactoryGirl.create(:host)
|
62
|
+
report = {
|
63
|
+
'host' => host.name,
|
64
|
+
'status' => 'downloading',
|
65
|
+
'omaha_version' => '1068.9.0',
|
66
|
+
'reported_at' => Time.now.utc.to_s
|
67
|
+
}
|
68
|
+
assert_difference('ForemanOmaha::OmahaReport.count') do
|
69
|
+
ForemanOmaha::OmahaReport.import(report)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
test 'should not import a report with invalid value' do
|
74
|
+
host = FactoryGirl.create(:host)
|
75
|
+
report = {
|
76
|
+
'host' => host.name,
|
77
|
+
'status' => 'invalid',
|
78
|
+
'omaha_version' => '1068.9.0',
|
79
|
+
'reported_at' => Time.now.utc.to_s
|
80
|
+
}
|
81
|
+
assert_raise ArgumentError do
|
82
|
+
ForemanOmaha::OmahaReport.import(report)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: foreman_omaha
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Timo Goebel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-14 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'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
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: This plug-in adds support for the Omaha procotol to The Foreman. It allows
|
42
|
+
you to better manage and update your CoreOS servers.
|
43
|
+
email:
|
44
|
+
- mail@timogoebel.name
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- LICENSE
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- app/assets/images/Omaha.png
|
53
|
+
- app/controllers/api/v2/omaha_reports_controller.rb
|
54
|
+
- app/controllers/omaha_reports_controller.rb
|
55
|
+
- app/helpers/concerns/foreman_omaha/hosts_helper_extensions.rb
|
56
|
+
- app/helpers/omaha_reports_helper.rb
|
57
|
+
- app/models/concerns/foreman_omaha/host_extensions.rb
|
58
|
+
- app/models/foreman_omaha/fact_name.rb
|
59
|
+
- app/models/foreman_omaha/omaha_report.rb
|
60
|
+
- app/models/host_status/omaha_status.rb
|
61
|
+
- app/services/foreman_omaha/fact_importer.rb
|
62
|
+
- app/services/foreman_omaha/fact_parser.rb
|
63
|
+
- app/services/foreman_omaha/omaha_report_importer.rb
|
64
|
+
- app/views/api/v2/omaha_reports/base.json.rabl
|
65
|
+
- app/views/api/v2/omaha_reports/create.json.rabl
|
66
|
+
- app/views/api/v2/omaha_reports/index.json.rabl
|
67
|
+
- app/views/api/v2/omaha_reports/main.json.rabl
|
68
|
+
- app/views/api/v2/omaha_reports/show.json.rabl
|
69
|
+
- app/views/api/v2/omaha_reports/update.json.rabl
|
70
|
+
- app/views/omaha_reports/_details.html.erb
|
71
|
+
- app/views/omaha_reports/_list.html.erb
|
72
|
+
- app/views/omaha_reports/index.html.erb
|
73
|
+
- app/views/omaha_reports/show.html.erb
|
74
|
+
- app/views/omaha_reports/welcome.html.erb
|
75
|
+
- config/routes.rb
|
76
|
+
- db/migrate/20160812083100_add_omaha_fields_to_reports.foreman_omaha.rb
|
77
|
+
- db/seeds.d/60_omaha_proxy_feature.rb
|
78
|
+
- lib/foreman_omaha.rb
|
79
|
+
- lib/foreman_omaha/engine.rb
|
80
|
+
- lib/foreman_omaha/version.rb
|
81
|
+
- lib/tasks/foreman_omaha_tasks.rake
|
82
|
+
- locale/Makefile
|
83
|
+
- locale/en/foreman_omaha.po
|
84
|
+
- locale/foreman_omaha.pot
|
85
|
+
- locale/gemspec.rb
|
86
|
+
- test/factories/feature.rb
|
87
|
+
- test/factories/foreman_omaha_factories.rb
|
88
|
+
- test/factories/smart_proxy.rb
|
89
|
+
- test/functional/api/v2/omaha_reports_controller_test.rb
|
90
|
+
- test/functional/omaha_reports_controller_test.rb
|
91
|
+
- test/test_plugin_helper.rb
|
92
|
+
- test/unit/omaha_report_test.rb
|
93
|
+
homepage: http://github.com/theforeman/foreman_omaha
|
94
|
+
licenses:
|
95
|
+
- GPL-3
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.4.5
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: This plug-in adds support for the Omaha procotol to The Foreman.
|
117
|
+
test_files:
|
118
|
+
- test/factories/feature.rb
|
119
|
+
- test/factories/foreman_omaha_factories.rb
|
120
|
+
- test/factories/smart_proxy.rb
|
121
|
+
- test/functional/api/v2/omaha_reports_controller_test.rb
|
122
|
+
- test/functional/omaha_reports_controller_test.rb
|
123
|
+
- test/test_plugin_helper.rb
|
124
|
+
- test/unit/omaha_report_test.rb
|
125
|
+
has_rdoc:
|