foreman_omaha 0.0.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +5 -2
- data/app/assets/javascripts/foreman_omaha/application.js +1 -0
- data/app/assets/stylesheets/foreman_omaha/version_breakdown.scss +13 -0
- data/app/controllers/api/v2/omaha_groups_controller.rb +29 -0
- data/app/controllers/api/v2/omaha_reports_controller.rb +9 -7
- data/app/controllers/omaha_groups_controller.rb +28 -0
- data/app/controllers/omaha_hosts_controller.rb +42 -0
- data/app/controllers/omaha_reports_controller.rb +0 -11
- data/app/helpers/concerns/foreman_omaha/hosts_helper_extensions.rb +15 -6
- data/app/helpers/foreman_omaha/application_helper.rb +7 -0
- data/app/helpers/foreman_omaha/omaha_groups_helper.rb +52 -0
- data/app/helpers/omaha_hosts_helper.rb +43 -0
- data/app/models/concerns/foreman_omaha/host_extensions.rb +16 -2
- data/app/models/concerns/foreman_omaha/omaha_facet_host_extensions.rb +23 -0
- data/app/models/foreman_omaha/omaha_facet.rb +40 -0
- data/app/models/foreman_omaha/omaha_group.rb +34 -0
- data/app/models/foreman_omaha/omaha_report.rb +13 -21
- data/app/models/host_status/omaha_status.rb +6 -16
- data/app/services/foreman_omaha/charts/oem_distribution.rb +24 -0
- data/app/services/foreman_omaha/charts/status_distribution.rb +57 -0
- data/app/services/foreman_omaha/charts/version_distribution.rb +24 -0
- data/app/services/foreman_omaha/container_linux_config_transpiler.rb +33 -0
- data/app/services/foreman_omaha/fact_parser.rb +19 -3
- data/app/services/foreman_omaha/group_version_breakdown.rb +30 -0
- data/app/services/foreman_omaha/omaha_report_importer.rb +52 -3
- data/app/services/foreman_omaha/renderer_methods.rb +7 -0
- data/app/services/foreman_omaha/status_mapper.rb +53 -0
- data/app/views/api/v2/omaha_groups/base.json.rabl +3 -0
- data/app/views/api/v2/omaha_groups/index.json.rabl +3 -0
- data/app/views/api/v2/omaha_groups/main.json.rabl +5 -0
- data/app/views/api/v2/omaha_groups/show.json.rabl +3 -0
- data/app/views/application/foreman_omaha/_toolbar.html.erb +11 -0
- data/app/views/foreman_omaha/api/v2/omaha_facets/base.json.rabl +5 -0
- data/app/views/foreman_omaha/api/v2/omaha_facets/base_with_root.json.rabl +3 -0
- data/app/views/foreman_omaha/api/v2/omaha_facets/show.json.rabl +3 -0
- data/app/views/hosts/_omaha_tab.html.erb +29 -0
- data/app/views/omaha_groups/index.html.erb +34 -0
- data/app/views/omaha_groups/show.html.erb +196 -0
- data/app/views/omaha_hosts/index.html.erb +51 -0
- data/app/views/omaha_hosts/welcome.html.erb +12 -0
- data/app/views/omaha_reports/_details.html.erb +5 -3
- data/app/views/omaha_reports/_list.html.erb +2 -2
- data/app/views/omaha_reports/show.html.erb +1 -1
- data/app/views/omaha_reports/welcome.html.erb +1 -1
- data/config/routes.rb +14 -1
- data/db/migrate/20160812083100_add_omaha_fields_to_reports.foreman_omaha.rb +1 -1
- data/db/migrate/20171101204100_create_omaha_facets.foreman_omaha.rb +22 -0
- data/db/seeds.d/200_omaha_groups.rb +6 -0
- data/lib/foreman_omaha/engine.rb +74 -21
- data/lib/foreman_omaha/version.rb +1 -1
- data/lib/tasks/foreman_omaha_tasks.rake +2 -4
- data/test/factories/feature.rb +1 -1
- data/test/factories/foreman_omaha_factories.rb +16 -1
- data/test/factories/host.rb +21 -0
- data/test/factories/smart_proxy.rb +1 -1
- data/test/functional/api/v2/omaha_groups_controller_test.rb +32 -0
- data/test/functional/api/v2/omaha_reports_controller_test.rb +24 -24
- data/test/functional/omaha_groups_controller_test.rb +18 -0
- data/test/functional/omaha_hosts_controller_test.rb +11 -0
- data/test/functional/omaha_reports_controller_test.rb +13 -13
- data/test/test_plugin_helper.rb +3 -3
- data/test/unit/charts/oem_distribution_test.rb +26 -0
- data/test/unit/charts/status_distribution_test.rb +28 -0
- data/test/unit/charts/version_distribution_test.rb +28 -0
- data/test/unit/group_version_breakdown_test.rb +65 -0
- data/test/unit/host_status/omaha_status_test.rb +19 -0
- data/test/unit/host_test.rb +55 -0
- data/test/unit/omaha_fact_parser_test.rb +77 -0
- data/test/unit/omaha_report_test.rb +63 -17
- data/test/unit/renderer_test.rb +21 -0
- metadata +80 -9
@@ -2,52 +2,52 @@ require 'test_plugin_helper'
|
|
2
2
|
|
3
3
|
class OmahaReportsControllerTest < ActionController::TestCase
|
4
4
|
test '#index' do
|
5
|
-
|
6
|
-
get :index,
|
5
|
+
FactoryBot.create(:omaha_report)
|
6
|
+
get :index, session: set_session_user
|
7
7
|
assert_response :success
|
8
8
|
assert_not_nil assigns('omaha_reports')
|
9
9
|
assert_template 'index'
|
10
10
|
end
|
11
11
|
|
12
12
|
test '#show' do
|
13
|
-
report =
|
14
|
-
get :show, { :id => report.id }, set_session_user
|
13
|
+
report = FactoryBot.create(:omaha_report)
|
14
|
+
get :show, params: { :id => report.id }, session: set_session_user
|
15
15
|
assert_template 'show'
|
16
16
|
end
|
17
17
|
|
18
18
|
test '404 on #show when id is blank' do
|
19
|
-
get :show, { :id => ' ' }, set_session_user
|
19
|
+
get :show, params: { :id => ' ' }, session: set_session_user
|
20
20
|
assert_response :missing
|
21
21
|
assert_template 'common/404'
|
22
22
|
end
|
23
23
|
|
24
24
|
test '#show last' do
|
25
|
-
|
26
|
-
get :show, { :id => 'last' }, set_session_user
|
25
|
+
FactoryBot.create(:omaha_report)
|
26
|
+
get :show, params: { :id => 'last' }, session: set_session_user
|
27
27
|
assert_template 'show'
|
28
28
|
end
|
29
29
|
|
30
30
|
test '404 on #show last when no reports available' do
|
31
|
-
get :show, { :id => 'last', :host_id =>
|
31
|
+
get :show, params: { :id => 'last', :host_id => FactoryBot.create(:host) }, session: set_session_user
|
32
32
|
assert_response :missing
|
33
33
|
assert_template 'common/404'
|
34
34
|
end
|
35
35
|
|
36
36
|
test '#show last report for host' do
|
37
|
-
report =
|
38
|
-
get :show, { :id => 'last', :host_id => report.host.to_param }, set_session_user
|
37
|
+
report = FactoryBot.create(:omaha_report)
|
38
|
+
get :show, params: { :id => 'last', :host_id => report.host.to_param }, session: set_session_user
|
39
39
|
assert_template 'show'
|
40
40
|
end
|
41
41
|
|
42
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
|
43
|
+
get :show, params: { :id => 'last', :host_id => 'blalala.domain.com' }, session: set_session_user
|
44
44
|
assert_response :missing
|
45
45
|
assert_template 'common/404'
|
46
46
|
end
|
47
47
|
|
48
48
|
test '#destroy' do
|
49
|
-
report =
|
50
|
-
delete :destroy, { :id => report }, set_session_user
|
49
|
+
report = FactoryBot.create(:omaha_report)
|
50
|
+
delete :destroy, params: { :id => report }, session: set_session_user
|
51
51
|
assert_redirected_to omaha_reports_url
|
52
52
|
assert !ConfigReport.exists?(report.id)
|
53
53
|
end
|
data/test/test_plugin_helper.rb
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
require 'test_helper'
|
3
3
|
require 'database_cleaner'
|
4
4
|
|
5
|
-
# Add plugin to
|
6
|
-
|
7
|
-
|
5
|
+
# Add plugin to FactoryBot's paths
|
6
|
+
FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
|
7
|
+
FactoryBot.reload
|
8
8
|
|
9
9
|
# Foreman's setup doesn't handle cleaning up for Minitest::Spec
|
10
10
|
DatabaseCleaner.strategy = :transaction
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
module ForemanOmaha
|
4
|
+
module Charts
|
5
|
+
class OemDistribitionTest < ActiveSupport::TestCase
|
6
|
+
setup do
|
7
|
+
User.current = FactoryBot.create(:user, :admin)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:oem_distribition_chart) { ForemanOmaha::Charts::OemDistribution.new }
|
11
|
+
|
12
|
+
context 'with hosts' do
|
13
|
+
setup do
|
14
|
+
FactoryBot.create_list(:host, 5, :with_omaha_facet)
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'calculates the oem distribution' do
|
18
|
+
expected = [
|
19
|
+
{ :label => 'rackspace', :data => 5 }
|
20
|
+
]
|
21
|
+
assert_equal(expected, oem_distribition_chart.to_chart_data.sort_by { |e| e[:label] })
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
module ForemanOmaha
|
4
|
+
module Charts
|
5
|
+
class StatusDistribitionTest < ActiveSupport::TestCase
|
6
|
+
setup do
|
7
|
+
User.current = FactoryBot.create(:user, :admin)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:status_distribition_chart) { ForemanOmaha::Charts::StatusDistribution.new }
|
11
|
+
|
12
|
+
context 'with hosts' do
|
13
|
+
setup do
|
14
|
+
FactoryBot.create_list(:host, 5, :with_omaha_facet)
|
15
|
+
FactoryBot.create_list(:host, 3, :with_omaha_facet, :omaha_status => 2)
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'calculates the status distribution' do
|
19
|
+
expected = [
|
20
|
+
{ :label => 'Complete', :data => 5, :color => '#89A54E' },
|
21
|
+
{ :label => 'Downloading', :data => 3, :color => '#3D96AE' }
|
22
|
+
]
|
23
|
+
assert_equal(expected, status_distribition_chart.to_chart_data.sort_by { |e| e[:label] })
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
module ForemanOmaha
|
4
|
+
module Charts
|
5
|
+
class VersionDistribitionTest < ActiveSupport::TestCase
|
6
|
+
setup do
|
7
|
+
User.current = FactoryBot.create(:user, :admin)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:version_distribition_chart) { ForemanOmaha::Charts::VersionDistribution.new }
|
11
|
+
|
12
|
+
context 'with hosts' do
|
13
|
+
setup do
|
14
|
+
FactoryBot.create_list(:host, 5, :with_omaha_facet)
|
15
|
+
FactoryBot.create_list(:host, 7, :with_omaha_facet, :omaha_version => '1465.7.0')
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'calculates the version distribution' do
|
19
|
+
expected = [
|
20
|
+
{ :label => '1068.9.0', :data => 5 },
|
21
|
+
{ :label => '1465.7.0', :data => 7 }
|
22
|
+
]
|
23
|
+
assert_equal(expected, version_distribition_chart.to_chart_data.sort_by { |e| e[:label] })
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class CurrentVersionBreakdownTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
User.current = FactoryBot.create(:user, :admin)
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:stable_group) { FactoryBot.create(:omaha_group, :uuid => 'stable', :name => 'Stable') }
|
9
|
+
let(:beta_group) { FactoryBot.create(:omaha_group, :uuid => 'beta', :name => 'Beta') }
|
10
|
+
let(:group_version_breakdown) { ForemanOmaha::GroupVersionBreakdown.new(:omaha_group => stable_group) }
|
11
|
+
let(:stable_releases) { ['1520.6.0', '1520.5.0', '1465.8.0'] }
|
12
|
+
let(:beta_coreos) { create_coreos_os('1576.3.0', 'beta') }
|
13
|
+
|
14
|
+
context 'with hosts' do
|
15
|
+
setup do
|
16
|
+
oslist = stable_releases.map do |release|
|
17
|
+
create_coreos_os(release)
|
18
|
+
end
|
19
|
+
FactoryBot.create_list(
|
20
|
+
:host, 2, :managed, :with_omaha_facet,
|
21
|
+
:omaha_version => oslist.first.release,
|
22
|
+
:omaha_group => stable_group,
|
23
|
+
:operatingsystem => oslist.first
|
24
|
+
)
|
25
|
+
FactoryBot.create(
|
26
|
+
:host, :managed, :with_omaha_facet,
|
27
|
+
:omaha_version => oslist.last.release,
|
28
|
+
:omaha_group => stable_group,
|
29
|
+
:operatingsystem => oslist.last
|
30
|
+
)
|
31
|
+
FactoryBot.create(
|
32
|
+
:host, :managed, :with_omaha_facet,
|
33
|
+
:omaha_version => beta_coreos.release,
|
34
|
+
:omaha_group => beta_group,
|
35
|
+
:operatingsystem => beta_coreos
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
test 'counts host in stable group' do
|
40
|
+
assert_equal 3, group_version_breakdown.facets.count
|
41
|
+
end
|
42
|
+
|
43
|
+
test 'calculates a version breakdown' do
|
44
|
+
expected = [
|
45
|
+
{ :version => '1520.6.0', :count => 2, :percentage => 66.67 },
|
46
|
+
{ :version => '1465.8.0', :count => 1, :percentage => 33.33 }
|
47
|
+
]
|
48
|
+
assert_equal expected, group_version_breakdown.version_breakdown
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def create_coreos_os(version, channel = 'stable')
|
55
|
+
semver = Gem::Version.new(version)
|
56
|
+
FactoryBot.create(
|
57
|
+
:coreos,
|
58
|
+
:with_associations,
|
59
|
+
:major => semver.segments.first,
|
60
|
+
:minor => semver.segments.last(2).join('.'),
|
61
|
+
:release_name => channel,
|
62
|
+
:title => "CoreOS #{version}"
|
63
|
+
)
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class OmahaStatusTest < ActiveSupport::TestCase
|
4
|
+
let(:host) { FactoryBot.build_stubbed(:host, :with_omaha_facet) }
|
5
|
+
let(:status) { HostStatus::OmahaStatus.new }
|
6
|
+
|
7
|
+
setup do
|
8
|
+
User.current = FactoryBot.create(:user, :admin)
|
9
|
+
status.host = host
|
10
|
+
end
|
11
|
+
|
12
|
+
test '#relevant? is only for hosts with an omaha facet' do
|
13
|
+
assert_equal true, status.relevant?
|
14
|
+
|
15
|
+
status.host = FactoryBot.build_stubbed(:host)
|
16
|
+
|
17
|
+
assert_equal false, status.relevant?
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class HostTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
User.current = FactoryBot.create(:user, :admin)
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'scoped search' do
|
9
|
+
setup do
|
10
|
+
@host = FactoryBot.create(:host, :with_omaha_facet)
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'search by last_report' do
|
14
|
+
hosts = Host.search_for('last_omaha_report = Today')
|
15
|
+
assert_includes hosts, @host
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'search by machineid' do
|
19
|
+
hosts = Host.search_for("omaha_machineid = #{@host.omaha_facet.machineid}")
|
20
|
+
assert_includes hosts, @host
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'search by version' do
|
24
|
+
hosts = Host.search_for("omaha_version = #{@host.omaha_facet.version}")
|
25
|
+
assert_includes hosts, @host
|
26
|
+
end
|
27
|
+
|
28
|
+
test 'search by oem' do
|
29
|
+
hosts = Host.search_for("omaha_oem = #{@host.omaha_facet.oem}")
|
30
|
+
assert_includes hosts, @host
|
31
|
+
end
|
32
|
+
|
33
|
+
test 'search by status' do
|
34
|
+
hosts = Host.search_for("omaha_status = #{@host.omaha_facet.status}")
|
35
|
+
assert_includes hosts, @host
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'search by omaha_group' do
|
39
|
+
hosts = Host.search_for("omaha_group = \"#{@host.omaha_facet.omaha_group.name}\"")
|
40
|
+
assert_includes hosts, @host
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'host rebuild' do
|
45
|
+
let(:host) { FactoryBot.create(:host, :managed, :with_omaha_facet) }
|
46
|
+
|
47
|
+
test 'clears the omaha facet' do
|
48
|
+
assert host.omaha_facet
|
49
|
+
host.build = true
|
50
|
+
assert_valid host
|
51
|
+
assert host.save
|
52
|
+
refute host.reload.omaha_facet
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class OmahaFactsParserTest < ActiveSupport::TestCase
|
4
|
+
setup do
|
5
|
+
User.current = users(:admin)
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:facts) do
|
9
|
+
{
|
10
|
+
'appid' => 'e96281a6-d1af-4bde-9a0a-97b76e56dc57',
|
11
|
+
'version' => '1068.9.0',
|
12
|
+
'track' => 'stable',
|
13
|
+
'board' => 'amd64-usr',
|
14
|
+
'alephversion' => '1010.5.0',
|
15
|
+
'oemversion' => '',
|
16
|
+
'oem' => '',
|
17
|
+
'platform' => 'CoreOS',
|
18
|
+
'osmajor' => '1068',
|
19
|
+
'osminor' => '9.0',
|
20
|
+
'ipaddress' => '127.0.0.1',
|
21
|
+
'ipaddress6' => '',
|
22
|
+
'hostname' => 'client.example.com'
|
23
|
+
}
|
24
|
+
end
|
25
|
+
let(:importer) { ::ForemanOmaha::FactParser.new(facts) }
|
26
|
+
|
27
|
+
context '#architecture' do
|
28
|
+
let(:architecture) { importer.architecture }
|
29
|
+
|
30
|
+
test 'should return an Architecture' do
|
31
|
+
assert_kind_of Architecture, architecture
|
32
|
+
assert_equal Architecture.find_by(name: 'x86_64'), architecture
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context '#operatingsystem' do
|
37
|
+
let(:os) { importer.operatingsystem }
|
38
|
+
|
39
|
+
test 'should return an OS with correct params' do
|
40
|
+
assert_kind_of Operatingsystem, os
|
41
|
+
assert_equal '1068', os.major
|
42
|
+
assert_equal '9.0', os.minor
|
43
|
+
assert_equal 'CoreOS', os.name
|
44
|
+
assert_equal 'CoreOS 1068.9.0', os.description
|
45
|
+
assert_equal 'stable', os.release_name
|
46
|
+
assert_empty os.ptables
|
47
|
+
assert_empty os.media
|
48
|
+
assert_empty os.os_default_templates
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'with old versions' do
|
52
|
+
setup do
|
53
|
+
FactoryBot.create(:coreos,
|
54
|
+
:with_associations,
|
55
|
+
:with_os_defaults,
|
56
|
+
:major => '899',
|
57
|
+
:minor => '17.0',
|
58
|
+
:title => 'CoreOS 899.17.0')
|
59
|
+
@previous = FactoryBot.create(:coreos,
|
60
|
+
:with_associations,
|
61
|
+
:with_os_defaults,
|
62
|
+
:major => '1010',
|
63
|
+
:minor => '5.0',
|
64
|
+
:title => 'CoreOS 1010.5.0')
|
65
|
+
end
|
66
|
+
|
67
|
+
test 'should copy attributes from previous os version' do
|
68
|
+
assert_equal '1068', os.major
|
69
|
+
assert_equal '9.0', os.minor
|
70
|
+
assert_equal @previous.ptables, os.ptables
|
71
|
+
assert_equal @previous.architectures, os.architectures
|
72
|
+
assert_equal @previous.media, os.media
|
73
|
+
assert_equal @previous.os_default_templates, os.os_default_templates
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -2,11 +2,11 @@ require 'test_plugin_helper'
|
|
2
2
|
|
3
3
|
class OmahaReportTest < ActiveSupport::TestCase
|
4
4
|
setup do
|
5
|
-
User.current =
|
5
|
+
User.current = FactoryBot.create(:user, :admin)
|
6
6
|
end
|
7
7
|
|
8
8
|
context 'status' do
|
9
|
-
let(:report) {
|
9
|
+
let(:report) { FactoryBot.build(:omaha_report) }
|
10
10
|
|
11
11
|
test 'should be complete' do
|
12
12
|
report.status = 'complete'
|
@@ -46,8 +46,8 @@ class OmahaReportTest < ActiveSupport::TestCase
|
|
46
46
|
end
|
47
47
|
|
48
48
|
context 'operatingsystem' do
|
49
|
-
let(:os) {
|
50
|
-
let(:report) {
|
49
|
+
let(:os) { FactoryBot.create(:coreos, :major => '1068', :minor => '9.0') }
|
50
|
+
let(:report) { FactoryBot.create(:omaha_report) }
|
51
51
|
|
52
52
|
test 'should get operatingsystem' do
|
53
53
|
assert_equal os, report.operatingsystem
|
@@ -60,30 +60,76 @@ class OmahaReportTest < ActiveSupport::TestCase
|
|
60
60
|
end
|
61
61
|
|
62
62
|
context '#import' do
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
let(:host) { FactoryBot.create(:host) }
|
64
|
+
let(:group) { FactoryBot.create(:omaha_group, :name => 'Stable', :uuid => 'stable') }
|
65
|
+
let(:report_data) do
|
66
|
+
{
|
66
67
|
'host' => host.name,
|
67
68
|
'status' => 'downloading',
|
68
|
-
'omaha_version' => '
|
69
|
+
'omaha_version' => '494.5.0',
|
70
|
+
'omaha_group' => 'stable',
|
71
|
+
'machineid' => '8e9450f47a4c47adbfe48b946e201c84',
|
72
|
+
'oem' => 'rackspace',
|
69
73
|
'reported_at' => Time.now.utc.to_s
|
70
74
|
}
|
75
|
+
end
|
76
|
+
|
77
|
+
test 'should import a report' do
|
71
78
|
assert_difference('ForemanOmaha::OmahaReport.count') do
|
72
|
-
ForemanOmaha::OmahaReport.import(
|
79
|
+
ForemanOmaha::OmahaReport.import(report_data)
|
73
80
|
end
|
74
81
|
end
|
75
82
|
|
76
83
|
test 'should not import a report with invalid value' do
|
77
|
-
|
78
|
-
report = {
|
79
|
-
'host' => host.name,
|
80
|
-
'status' => 'invalid',
|
81
|
-
'omaha_version' => '1068.9.0',
|
82
|
-
'reported_at' => Time.now.utc.to_s
|
83
|
-
}
|
84
|
+
report_data['status'] = 'invalid'
|
84
85
|
assert_raise ArgumentError do
|
85
|
-
ForemanOmaha::OmahaReport.import(
|
86
|
+
ForemanOmaha::OmahaReport.import(report_data)
|
86
87
|
end
|
87
88
|
end
|
89
|
+
|
90
|
+
test 'should create host omaha facet' do
|
91
|
+
assert_nil host.omaha_facet
|
92
|
+
assert_not_nil group
|
93
|
+
ForemanOmaha::OmahaReport.import(report_data)
|
94
|
+
facet = host.reload.omaha_facet
|
95
|
+
assert_not_nil facet
|
96
|
+
assert_equal host, facet.host
|
97
|
+
assert_equal report_data['reported_at'].to_date, facet.last_report.to_date
|
98
|
+
assert_equal report_data['status'], facet.status
|
99
|
+
assert_equal report_data['machineid'], facet.machineid
|
100
|
+
assert_equal report_data['oem'], facet.oem
|
101
|
+
assert_equal report_data['omaha_version'], facet.version
|
102
|
+
assert_equal group, facet.omaha_group
|
103
|
+
end
|
104
|
+
|
105
|
+
test 'should update host omaha facet' do
|
106
|
+
assert_not_nil group
|
107
|
+
ForemanOmaha::OmahaReport.import(report_data)
|
108
|
+
time = Time.now.advance(seconds: 10).utc.to_s
|
109
|
+
new_report = report_data.merge(
|
110
|
+
'status' => 'complete',
|
111
|
+
'reported_at' => time,
|
112
|
+
'omaha_version' => '1068.9.0'
|
113
|
+
).except('host')
|
114
|
+
ForemanOmaha::OmahaReport.import(new_report)
|
115
|
+
facet = host.reload.omaha_facet
|
116
|
+
assert_not_nil facet
|
117
|
+
assert_equal host, facet.host
|
118
|
+
assert_equal time.to_date, facet.last_report.to_date
|
119
|
+
assert_equal 'complete', facet.status
|
120
|
+
assert_equal new_report['machineid'], facet.machineid
|
121
|
+
assert_equal 'rackspace', facet.oem
|
122
|
+
assert_equal '1068.9.0', facet.version
|
123
|
+
assert_equal group, facet.omaha_group
|
124
|
+
end
|
125
|
+
|
126
|
+
test 'should detect omaha group by os version' do
|
127
|
+
assert_not_nil group
|
128
|
+
FactoryBot.create(:coreos)
|
129
|
+
ForemanOmaha::OmahaReport.import(report_data.except('omaha_group'))
|
130
|
+
facet = host.reload.omaha_facet
|
131
|
+
assert_not_nil facet
|
132
|
+
assert_equal group, facet.omaha_group
|
133
|
+
end
|
88
134
|
end
|
89
135
|
end
|