foreman_omaha 3.0.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -1
  3. data/app/controllers/api/v2/omaha_groups_controller.rb +2 -0
  4. data/app/controllers/api/v2/omaha_reports_controller.rb +2 -0
  5. data/app/controllers/omaha_groups_controller.rb +2 -0
  6. data/app/controllers/omaha_hosts_controller.rb +2 -0
  7. data/app/controllers/omaha_reports_controller.rb +2 -0
  8. data/app/graphql/types/omaha_group.rb +15 -0
  9. data/app/graphql/types/omaha_report.rb +15 -0
  10. data/app/graphql/types/omaha_report_status_enum.rb +9 -0
  11. data/app/helpers/concerns/foreman_omaha/hosts_helper_extensions.rb +2 -0
  12. data/app/helpers/foreman_omaha/application_helper.rb +2 -0
  13. data/app/helpers/foreman_omaha/omaha_groups_helper.rb +2 -0
  14. data/app/helpers/omaha_hosts_helper.rb +2 -0
  15. data/app/helpers/omaha_reports_helper.rb +2 -0
  16. data/app/lib/foreman_omaha/renderer/scope/macros/omaha.rb +2 -0
  17. data/app/models/concerns/foreman_omaha/host_extensions.rb +3 -1
  18. data/app/models/concerns/foreman_omaha/omaha_facet_host_extensions.rb +2 -0
  19. data/app/models/foreman_omaha/fact_name.rb +2 -0
  20. data/app/models/foreman_omaha/omaha_facet.rb +2 -0
  21. data/app/models/foreman_omaha/omaha_group.rb +4 -0
  22. data/app/models/foreman_omaha/omaha_report.rb +4 -0
  23. data/app/models/host_status/omaha_status.rb +2 -0
  24. data/app/services/foreman_omaha/charts/oem_distribution.rb +2 -0
  25. data/app/services/foreman_omaha/charts/status_distribution.rb +2 -0
  26. data/app/services/foreman_omaha/charts/version_distribution.rb +2 -0
  27. data/app/services/foreman_omaha/container_linux_config_transpiler.rb +2 -0
  28. data/app/services/foreman_omaha/fact_importer.rb +2 -0
  29. data/app/services/foreman_omaha/fact_parser.rb +11 -3
  30. data/app/services/foreman_omaha/group_version_breakdown.rb +2 -0
  31. data/app/services/foreman_omaha/omaha_report_importer.rb +2 -0
  32. data/app/services/foreman_omaha/status_mapper.rb +2 -2
  33. data/app/views/api/v2/omaha_groups/base.json.rabl +2 -0
  34. data/app/views/api/v2/omaha_groups/index.json.rabl +2 -0
  35. data/app/views/api/v2/omaha_groups/main.json.rabl +2 -0
  36. data/app/views/api/v2/omaha_groups/show.json.rabl +2 -0
  37. data/app/views/api/v2/omaha_reports/base.json.rabl +2 -0
  38. data/app/views/api/v2/omaha_reports/create.json.rabl +2 -0
  39. data/app/views/api/v2/omaha_reports/index.json.rabl +2 -0
  40. data/app/views/api/v2/omaha_reports/main.json.rabl +2 -0
  41. data/app/views/api/v2/omaha_reports/show.json.rabl +2 -0
  42. data/app/views/api/v2/omaha_reports/update.json.rabl +2 -0
  43. data/app/views/foreman_omaha/api/v2/omaha_facets/base.json.rabl +2 -0
  44. data/app/views/foreman_omaha/api/v2/omaha_facets/base_with_root.json.rabl +2 -0
  45. data/app/views/foreman_omaha/api/v2/omaha_facets/show.json.rabl +2 -0
  46. data/app/views/omaha_reports/_list.html.erb +1 -1
  47. data/config/routes.rb +2 -0
  48. data/db/migrate/20160812083100_add_omaha_fields_to_reports.foreman_omaha.rb +2 -0
  49. data/db/migrate/20171101204100_create_omaha_facets.foreman_omaha.rb +2 -0
  50. data/db/seeds.d/200_omaha_groups.rb +2 -0
  51. data/db/seeds.d/60_omaha_proxy_feature.rb +2 -0
  52. data/lib/foreman_omaha.rb +2 -0
  53. data/lib/foreman_omaha/engine.rb +24 -8
  54. data/lib/foreman_omaha/version.rb +3 -1
  55. data/lib/tasks/foreman_omaha_tasks.rake +2 -0
  56. data/locale/gemspec.rb +2 -0
  57. data/test/factories/feature.rb +3 -1
  58. data/test/factories/foreman_omaha_factories.rb +8 -6
  59. data/test/factories/host.rb +19 -4
  60. data/test/factories/smart_proxy.rb +2 -0
  61. data/test/functional/api/v2/omaha_groups_controller_test.rb +2 -0
  62. data/test/functional/api/v2/omaha_reports_controller_test.rb +3 -1
  63. data/test/functional/omaha_groups_controller_test.rb +2 -0
  64. data/test/functional/omaha_hosts_controller_test.rb +2 -0
  65. data/test/functional/omaha_reports_controller_test.rb +2 -0
  66. data/test/graphql/queries/host_query_extensions_test.rb +41 -0
  67. data/test/graphql/queries/omaha_group_query_test.rb +51 -0
  68. data/test/graphql/queries/omaha_groups_query_test.rb +47 -0
  69. data/test/graphql/queries/omaha_report_query_test.rb +44 -0
  70. data/test/graphql/queries/omaha_reports_query_test.rb +47 -0
  71. data/test/test_plugin_helper.rb +2 -0
  72. data/test/unit/charts/oem_distribution_test.rb +2 -0
  73. data/test/unit/charts/status_distribution_test.rb +2 -0
  74. data/test/unit/charts/version_distribution_test.rb +2 -0
  75. data/test/unit/group_version_breakdown_test.rb +2 -0
  76. data/test/unit/host_status/omaha_status_test.rb +4 -2
  77. data/test/unit/host_test.rb +2 -0
  78. data/test/unit/omaha_fact_parser_test.rb +45 -11
  79. data/test/unit/omaha_report_test.rb +2 -0
  80. data/test/unit/renderer_test.rb +2 -0
  81. metadata +62 -7
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddOmahaFieldsToReports < ActiveRecord::Migration[4.2]
2
4
  def change
3
5
  add_column :reports, :omaha_version, :string
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreateOmahaFacets < ActiveRecord::Migration[4.2]
2
4
  def change
3
5
  create_table :omaha_groups do |t|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  default_groups = %w[Alpha Beta Stable]
2
4
 
3
5
  default_groups.each do |group|
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  f = Feature.where(:name => 'Omaha').first_or_create
2
4
  raise "Unable to create proxy feature: #{format_errors f}" if f.nil? || f.errors.any?
data/lib/foreman_omaha.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'foreman_omaha/engine'
2
4
 
3
5
  module ForemanOmaha
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'jquery-matchheight-rails'
2
4
 
3
5
  module ForemanOmaha
@@ -9,6 +11,7 @@ module ForemanOmaha
9
11
  config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
10
12
  config.autoload_paths += Dir["#{config.root}/app/services"]
11
13
  config.autoload_paths += Dir["#{config.root}/app/lib"]
14
+ config.autoload_paths += Dir["#{config.root}/app/graphql"]
12
15
 
13
16
  # Add any db migrations
14
17
  initializer 'foreman_omaha.load_app_instance_data' do |app|
@@ -19,7 +22,7 @@ module ForemanOmaha
19
22
 
20
23
  initializer 'foreman_omaha.register_plugin', :before => :finisher_hook do |_app|
21
24
  Foreman::Plugin.register :foreman_omaha do
22
- requires_foreman '>= 1.20'
25
+ requires_foreman '>= 1.24'
23
26
 
24
27
  apipie_documented_controllers ["#{ForemanOmaha::Engine.root}/app/controllers/api/v2/*.rb"]
25
28
 
@@ -49,9 +52,11 @@ module ForemanOmaha
49
52
  end
50
53
 
51
54
  role 'Omaha reports viewer',
52
- [:view_omaha_reports]
55
+ [:view_omaha_reports],
56
+ 'Role granting permissions to view Omaha reports.'
53
57
  role 'Omaha reports manager',
54
- [:view_omaha_reports, :destroy_omaha_reports, :upload_omaha_reports]
58
+ [:view_omaha_reports, :destroy_omaha_reports, :upload_omaha_reports],
59
+ 'Role granting permissions to manage Omaha reports.'
55
60
 
56
61
  # add menu entry
57
62
  menu :top_menu, :omaha_reports,
@@ -87,10 +92,21 @@ module ForemanOmaha
87
92
  :onlyif => proc { |host| host.omaha_facet }
88
93
  end
89
94
 
90
- add_controller_action_scope(HostsController, :index) { |base_scope| base_scope.includes(:omaha_facet) }
95
+ add_controller_action_scope('HostsController', :index) { |base_scope| base_scope.includes(:omaha_facet) }
91
96
 
92
97
  # add renderer extensions
93
98
  allowed_template_helpers :transpile_container_linux_config
99
+
100
+ # graphql extensions
101
+ extend_graphql_type type: Types::Host do
102
+ has_many :omaha_reports, Types::OmahaReport
103
+ end
104
+
105
+ register_graphql_query_field :omaha_group, '::Types::OmahaGroup', :record_field
106
+ register_graphql_query_field :omaha_groups, '::Types::OmahaGroup', :collection_field
107
+
108
+ register_graphql_query_field :omaha_report, '::Types::OmahaReport', :record_field
109
+ register_graphql_query_field :omaha_reports, '::Types::OmahaReport', :collection_field
94
110
  end
95
111
 
96
112
  # Extend built in permissions
@@ -106,10 +122,10 @@ module ForemanOmaha
106
122
  ::FactImporter.register_fact_importer(:foreman_omaha, ForemanOmaha::FactImporter)
107
123
  ::FactParser.register_fact_parser(:foreman_omaha, ForemanOmaha::FactParser)
108
124
 
109
- Host::Managed.send(:include, ForemanOmaha::HostExtensions)
110
- Host::Managed.send(:include, ForemanOmaha::OmahaFacetHostExtensions)
111
- HostsHelper.send(:include, ForemanOmaha::HostsHelperExtensions)
112
- Foreman::Renderer::Scope::Base.send(:include, ForemanOmaha::Renderer::Scope::Macros::Omaha)
125
+ ::Host::Managed.include(ForemanOmaha::HostExtensions)
126
+ ::Host::Managed.include(ForemanOmaha::OmahaFacetHostExtensions)
127
+ ::HostsHelper.include(ForemanOmaha::HostsHelperExtensions)
128
+ ::Foreman::Renderer::Scope::Base.include(ForemanOmaha::Renderer::Scope::Macros::Omaha)
113
129
  rescue StandardError => e
114
130
  Rails.logger.warn "ForemanOmaha: skipping engine hook (#{e})"
115
131
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanOmaha
2
- VERSION = '3.0.0'.freeze
4
+ VERSION = '4.0.0'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Tasks
2
4
  namespace :foreman_omaha do
3
5
  namespace :example do
data/locale/gemspec.rb CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Matches foreman_omaha.gemspec
2
4
  _('This plug-in adds support for the Omaha procotol to The Foreman. It allows you to better manage and update your CoreOS servers.')
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryBot.modify do
2
4
  factory :feature do
3
5
  trait :omaha do
4
- name 'Omaha'
6
+ name { 'Omaha' }
5
7
  end
6
8
  end
7
9
  end
@@ -1,18 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryBot.define do
2
4
  factory :omaha_report, :class => 'ForemanOmaha::OmahaReport' do
3
5
  host
4
6
  sequence(:reported_at) { |n| n.minutes.ago }
5
- status 1
6
- omaha_version '1068.9.0'
7
- type 'ForemanOmaha::OmahaReport'
7
+ status { 1 }
8
+ omaha_version { '1068.9.0' }
9
+ type { 'ForemanOmaha::OmahaReport' }
8
10
  end
9
11
 
10
12
  factory :omaha_facet, :class => 'ForemanOmaha::OmahaFacet' do
11
13
  sequence(:last_report) { |n| n.minutes.ago }
12
- version '1068.9.0'
13
- oem 'rackspace'
14
+ version { '1068.9.0' }
15
+ oem { 'rackspace' }
14
16
  sequence(:machineid) { SecureRandom.hex }
15
- status 1
17
+ status { 1 }
16
18
  host
17
19
  omaha_group
18
20
  end
@@ -1,13 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryBot.modify do
2
4
  factory :host do
3
5
  trait :with_omaha_facet do
4
6
  association :omaha_facet, :factory => :omaha_facet, :strategy => :build
5
7
 
6
8
  transient do
7
- omaha_status 1
8
- omaha_version '1068.9.0'
9
- omaha_oem 'rackspace'
10
- omaha_group nil
9
+ omaha_status { 1 }
10
+ omaha_version { '1068.9.0' }
11
+ omaha_oem { 'rackspace' }
12
+ omaha_group { nil }
11
13
  end
12
14
 
13
15
  after(:build) do |host, evaluator|
@@ -17,5 +19,18 @@ FactoryBot.modify do
17
19
  host.omaha_facet.omaha_group = evaluator.omaha_group if evaluator.omaha_group.present?
18
20
  end
19
21
  end
22
+
23
+ trait :with_omaha_reports do
24
+ with_omaha_facet
25
+ transient do
26
+ omaha_report_count { 5 }
27
+ end
28
+ after(:create) do |host, evaluator|
29
+ evaluator.omaha_report_count.times do |i|
30
+ FactoryBot.create(:omaha_report, host: host, reported_at: (evaluator.omaha_report_count - i).minutes.ago)
31
+ end
32
+ host.omaha_facet.update_attribute(:last_report, host.omaha_reports.last.reported_at) # rubocop:disable Rails/SkipsModelValidations
33
+ end
34
+ end
20
35
  end
21
36
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryBot.modify do
2
4
  factory :smart_proxy do
3
5
  trait :omaha do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class Api::V2::OmahaGroupsControllerTest < ActionController::TestCase
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  class Api::V2::OmahaReportsControllerTest < ActionController::TestCase
@@ -53,7 +55,7 @@ class Api::V2::OmahaReportsControllerTest < ActionController::TestCase
53
55
  assert_response :success
54
56
  assert_not_nil assigns(:omaha_reports)
55
57
  reports = ActiveSupport::JSON.decode(@response.body)
56
- assert reports['results'].empty?
58
+ assert_empty reports['results']
57
59
  assert_equal 0, reports['results'].count
58
60
  end
59
61
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class OmahaGroupsControllerTest < ActionController::TestCase
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class OmahaHostsControllerTest < ActionController::TestCase
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_plugin_helper'
2
4
 
3
5
  class OmahaReportsControllerTest < ActionController::TestCase
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_plugin_helper'
4
+
5
+ module Queries
6
+ class HostQueryExtensionsTest < GraphQLQueryTestCase
7
+ let(:query) do
8
+ <<-GRAPHQL
9
+ query (
10
+ $id: String!
11
+ ) {
12
+ host(id: $id) {
13
+ id
14
+ omahaReports {
15
+ totalCount
16
+ edges {
17
+ node {
18
+ id
19
+ }
20
+ }
21
+ }
22
+ }
23
+ }
24
+ GRAPHQL
25
+ end
26
+
27
+ let(:host) do
28
+ FactoryBot.create(:host, :managed, :with_omaha_reports)
29
+ end
30
+ let(:global_id) { Foreman::GlobalId.encode('Host', host.id) }
31
+ let(:variables) { { id: Foreman::GlobalId.encode('Host', host.id) } }
32
+ let(:data) { result['data']['host'] }
33
+
34
+ test 'fetching host attributes with omaha extensions' do
35
+ assert_empty result['errors']
36
+ assert_equal global_id, data['id']
37
+
38
+ assert_collection host.omaha_reports, data['omahaReports']
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_plugin_helper'
4
+
5
+ module Queries
6
+ class OmahaGroupQueryTest < GraphQLQueryTestCase
7
+ let(:query) do
8
+ <<-GRAPHQL
9
+ query omahaGroupQuery (
10
+ $id: String!
11
+ ) {
12
+ omahaGroup(id: $id) {
13
+ id
14
+ name
15
+ uuid
16
+ createdAt
17
+ updatedAt
18
+ hosts {
19
+ totalCount
20
+ edges {
21
+ node {
22
+ id
23
+ }
24
+ }
25
+ }
26
+ }
27
+ }
28
+ GRAPHQL
29
+ end
30
+
31
+ let(:omaha_group) { FactoryBot.create(:omaha_group) }
32
+ let(:global_id) { Foreman::GlobalId.for(omaha_group) }
33
+ let(:variables) { { id: global_id } }
34
+ let(:data) { result['data']['omahaGroup'] }
35
+
36
+ test 'fetching omaha group attributes' do
37
+ FactoryBot.create(:host, :managed, :with_omaha_facet, omaha_group: omaha_group)
38
+
39
+ assert_empty result['errors']
40
+ assert_not_nil data
41
+
42
+ assert_equal global_id, data['id']
43
+ assert_equal omaha_group.created_at.utc.iso8601, data['createdAt']
44
+ assert_equal omaha_group.updated_at.utc.iso8601, data['updatedAt']
45
+ assert_equal omaha_group.name, data['name']
46
+ assert_equal omaha_group.uuid, data['uuid']
47
+
48
+ assert_collection omaha_group.hosts, data['hosts'], type_name: 'Host'
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_plugin_helper'
4
+
5
+ module Queries
6
+ class OmahaGroupsQueryTest < GraphQLQueryTestCase
7
+ let(:query) do
8
+ <<-GRAPHQL
9
+ query omahaGroupsQuery {
10
+ omahaGroups {
11
+ totalCount
12
+ pageInfo {
13
+ startCursor
14
+ endCursor
15
+ hasNextPage
16
+ hasPreviousPage
17
+ }
18
+ edges {
19
+ cursor
20
+ node {
21
+ id
22
+ name
23
+ uuid
24
+ }
25
+ }
26
+ }
27
+ }
28
+ GRAPHQL
29
+ end
30
+
31
+ let(:data) { result['data']['omahaGroups'] }
32
+
33
+ setup do
34
+ FactoryBot.create_list(:omaha_group, 2)
35
+ end
36
+
37
+ test 'fetching models attributes' do
38
+ assert_empty result['errors']
39
+
40
+ expected_count = ForemanOmaha::OmahaGroup.count
41
+
42
+ assert_not_equal 0, expected_count
43
+ assert_equal expected_count, data['totalCount']
44
+ assert_equal expected_count, data['edges'].count
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_plugin_helper'
4
+
5
+ module Queries
6
+ class OmahaReportQueryTest < GraphQLQueryTestCase
7
+ let(:query) do
8
+ <<-GRAPHQL
9
+ query omahaReportQuery (
10
+ $id: String!
11
+ ) {
12
+ omahaReport(id: $id) {
13
+ id
14
+ status
15
+ omahaVersion
16
+ createdAt
17
+ updatedAt
18
+ host {
19
+ id
20
+ }
21
+ }
22
+ }
23
+ GRAPHQL
24
+ end
25
+
26
+ let(:omaha_report) { FactoryBot.create(:omaha_report) }
27
+ let(:global_id) { Foreman::GlobalId.for(omaha_report) }
28
+ let(:variables) { { id: global_id } }
29
+ let(:data) { result['data']['omahaReport'] }
30
+
31
+ test 'fetching omaha report attributes' do
32
+ assert_empty result['errors']
33
+ assert_not_nil data
34
+
35
+ assert_equal global_id, data['id']
36
+ assert_equal omaha_report.created_at.utc.iso8601, data['createdAt']
37
+ assert_equal omaha_report.updated_at.utc.iso8601, data['updatedAt']
38
+ assert_equal omaha_report.status, data['status']
39
+ assert_equal omaha_report.omaha_version, data['omahaVersion']
40
+
41
+ assert_record omaha_report.host, data['host']
42
+ end
43
+ end
44
+ end