foreman_omaha 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d8c9488f648e7425b5ba2acf08a407e653a670247f2d2f0d1e523ed5269f5ca
4
- data.tar.gz: 340dae98a746ac79888fb44cb939545bf971e97941034d6edeb0aee250b97a28
3
+ metadata.gz: 421a748a9a01373e725254764e8ec0eec455da8db499a948d46de2215b9378bf
4
+ data.tar.gz: 893fd2401152eba58c412e5e87900d9d246fc6f0849f091e94172ea740f32dc8
5
5
  SHA512:
6
- metadata.gz: accbd7e167c73ed028e36f493fe740cc3a1df3ae175c55c278288d5db23c194ce24b0adbbc37d21c1044a32d0ab3c41a43c656d40c70b079d3ae4d140394fdc8
7
- data.tar.gz: 837d798f8867213463f2140b70c20e76b16f21ea88cba53b687547bcde42a41fe02c45ab1f12c91970c3e8f4a87be52912f1f213b96f1bda6f8da2b7e18f5176
6
+ metadata.gz: '09028f73bcf73132903dfe8318befca2428178f01b9b83138fed7d431a7b51eda6b4268ca3d6cc3851871587391fabd45c7b54c35ee802c2532c970867c25cda'
7
+ data.tar.gz: 5e5cc0bb9cda50abe5bb9cec5d04ac46711403465928a9fda8e6e8b32fe0d9ab05d6bec380d9077fbf3ee16567ae3fffa3c08186f2ead2ca3e1c2d5c4d0ec2a2
data/README.md CHANGED
@@ -11,6 +11,7 @@ Foreman core already supports deploying CoreOS hosts and is great for on-premise
11
11
  | >= 1.12 | ~> 0.0 |
12
12
  | >= 1.17 | ~> 1.0 |
13
13
  | >= 1.18 | ~> 2.0 |
14
+ | >= 1.20 | ~> 3.0 |
14
15
 
15
16
  ## Installation
16
17
 
@@ -14,11 +14,12 @@ class OmahaHostsController < ApplicationController
14
14
  end
15
15
 
16
16
  def welcome
17
- if begin
18
- resource_base.first.nil?
19
- rescue StandardError
20
- false
21
- end
17
+ has_entries = begin
18
+ resource_base.first.nil?
19
+ rescue StandardError
20
+ false
21
+ end
22
+ if has_entries
22
23
  @welcome = true
23
24
  render :welcome
24
25
  end
@@ -0,0 +1,13 @@
1
+ module ForemanOmaha
2
+ module Renderer
3
+ module Scope
4
+ module Macros
5
+ module Omaha
6
+ def transpile_container_linux_config(input)
7
+ ForemanOmaha::ContainerLinuxConfigTranspiler.new(input).run!
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -19,6 +19,7 @@ module ForemanOmaha
19
19
 
20
20
  def clear_omaha_facet_on_build
21
21
  return unless respond_to?(:old) && old && build? && !old.build?
22
+
22
23
  clear_omaha_facet
23
24
  end
24
25
  end
@@ -17,7 +17,7 @@ module ForemanOmaha
17
17
  :installed => 4, :instance_hold => 5, :error => 6
18
18
  }
19
19
 
20
- scoped_search :on => :name, :relation => :omaha_group, :complete_value => true, :rename => :omaha_group
20
+ scoped_search :on => :name, :relation => :omaha_group, :complete_value => true, :rename => :omaha_group, :only_explicit => true
21
21
  end
22
22
  end
23
23
  end
@@ -23,11 +23,13 @@ module ForemanOmaha
23
23
 
24
24
  def major
25
25
  return unless version
26
+
26
27
  version.split('.').first
27
28
  end
28
29
 
29
30
  def minor
30
31
  return unless version
32
+
31
33
  version.split('.').last(2).join('.')
32
34
  end
33
35
 
@@ -21,6 +21,7 @@ module ForemanOmaha
21
21
 
22
22
  def operatingsystem
23
23
  return if omaha_version.blank?
24
+
24
25
  args = { :type => 'Coreos', :major => osmajor, :minor => osminor }
25
26
  Operatingsystem.find_by(args)
26
27
  end
@@ -6,11 +6,13 @@ module HostStatus
6
6
 
7
7
  def to_status(_options = {})
8
8
  return ::ForemanOmaha::OmahaFacet.statuses[:unknown] unless relevant?
9
+
9
10
  ::ForemanOmaha::OmahaFacet.statuses[host.omaha_facet.status]
10
11
  end
11
12
 
12
13
  def to_global(_options = {})
13
14
  return ::ForemanOmaha::OmahaFacet.statuses[:unknown] unless relevant?
15
+
14
16
  case host.omaha_facet.status.to_sym
15
17
  when :complete, :downloaded, :downloading, :installed
16
18
  HostStatus::Global::OK
@@ -15,6 +15,7 @@ module ForemanOmaha
15
15
  check_transpiler
16
16
  transpile
17
17
  raise TranspileError, "Could not transpile container linux config to ignition: #{errors}" unless status.success?
18
+
18
19
  output
19
20
  end
20
21
 
@@ -34,15 +34,16 @@ module ForemanOmaha
34
34
  def create_coreos_version(attrs)
35
35
  previous_version = previous_coreos_version
36
36
  return Coreos.create!(attrs) unless previous_coreos_version
37
+
37
38
  os = previous_version.deep_clone(
38
- :include => [:ptables, :media, :os_default_templates, :architectures]
39
+ :include => [:ptables, :media, :os_default_templates, :architectures, :provisioning_templates]
39
40
  )
40
41
  os.update(attrs)
41
42
  os
42
43
  end
43
44
 
44
45
  def previous_coreos_version
45
- Coreos.all.sort_by { |os| Gem::Version.new(os.release) }.last
46
+ Coreos.all.max_by { |os| Gem::Version.new(os.release) }
46
47
  end
47
48
  end
48
49
  end
@@ -24,6 +24,7 @@ module ForemanOmaha
24
24
 
25
25
  def percentage(count)
26
26
  return 0 if count.zero? || facets.count.zero?
27
+
27
28
  (count.to_f * 100 / facets.count).round(2)
28
29
  end
29
30
  end
@@ -19,6 +19,7 @@ module ForemanOmaha
19
19
  def create_report_and_logs
20
20
  super
21
21
  return report unless report.persisted?
22
+
22
23
  report.omaha_version = omaha_version
23
24
  report.save
24
25
  update_omaha_facet!
@@ -31,6 +32,7 @@ module ForemanOmaha
31
32
 
32
33
  def update_omaha_facet!
33
34
  return unless omaha_facet.last_report.nil? || omaha_facet.last_report.utc < time
35
+
34
36
  omaha_facet.update(
35
37
  :last_report => time,
36
38
  :status => report_status,
@@ -71,6 +73,7 @@ module ForemanOmaha
71
73
  minor = version.segments.last(2).join('.')
72
74
  os = Coreos.find_by(:major => major, :minor => minor)
73
75
  return unless os
76
+
74
77
  ForemanOmaha::OmahaGroup.find_by(:uuid => os.release_name)
75
78
  end
76
79
  end
@@ -1,6 +1,17 @@
1
1
  <% javascript 'foreman_omaha/application' %>
2
2
  <% javascript 'charts' %>
3
3
  <% title @omaha_group.name %>
4
+ <%= breadcrumbs(
5
+ items: [
6
+ {
7
+ caption: _('Omaha Groups'),
8
+ url: (url_for(hash_for_omaha_groups_path) if authorized_for(hash_for_omaha_groups_path))
9
+ },
10
+ {
11
+ caption: @omaha_group.name
12
+ }
13
+ ]
14
+ ) %>
4
15
  <div class="container-fluid container-cards-pf">
5
16
  <!-- status cards -->
6
17
  <div class="row row-cards-pf">
@@ -8,6 +8,7 @@ module ForemanOmaha
8
8
  config.autoload_paths += Dir["#{config.root}/app/helpers/concerns"]
9
9
  config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
10
10
  config.autoload_paths += Dir["#{config.root}/app/services"]
11
+ config.autoload_paths += Dir["#{config.root}/app/lib"]
11
12
 
12
13
  # Add any db migrations
13
14
  initializer 'foreman_omaha.load_app_instance_data' do |app|
@@ -18,7 +19,7 @@ module ForemanOmaha
18
19
 
19
20
  initializer 'foreman_omaha.register_plugin', :before => :finisher_hook do |_app|
20
21
  Foreman::Plugin.register :foreman_omaha do
21
- requires_foreman '>= 1.18'
22
+ requires_foreman '>= 1.20'
22
23
 
23
24
  apipie_documented_controllers ["#{ForemanOmaha::Engine.root}/app/controllers/api/v2/*.rb"]
24
25
 
@@ -90,7 +91,6 @@ module ForemanOmaha
90
91
 
91
92
  # add renderer extensions
92
93
  allowed_template_helpers :transpile_container_linux_config
93
- extend_template_helpers ForemanOmaha::RendererMethods
94
94
  end
95
95
 
96
96
  # Extend built in permissions
@@ -109,6 +109,7 @@ module ForemanOmaha
109
109
  Host::Managed.send(:include, ForemanOmaha::HostExtensions)
110
110
  Host::Managed.send(:include, ForemanOmaha::OmahaFacetHostExtensions)
111
111
  HostsHelper.send(:include, ForemanOmaha::HostsHelperExtensions)
112
+ Foreman::Renderer::Scope::Base.send(:include, ForemanOmaha::Renderer::Scope::Macros::Omaha)
112
113
  rescue StandardError => e
113
114
  Rails.logger.warn "ForemanOmaha: skipping engine hook (#{e})"
114
115
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanOmaha
2
- VERSION = '2.0.0'.freeze
2
+ VERSION = '3.0.0'.freeze
3
3
  end
@@ -23,7 +23,7 @@ class Api::V2::OmahaGroupsControllerTest < ActionController::TestCase
23
23
  get :show, params: { :id => omaha_group.to_param }
24
24
  assert_response :success
25
25
  body = ActiveSupport::JSON.decode(@response.body)
26
- refute_empty body
26
+ assert_not_empty body
27
27
  assert_equal omaha_group.id, body['id']
28
28
  assert_equal omaha_group.name, body['name']
29
29
  assert_equal omaha_group.uuid, body['uuid']
@@ -17,7 +17,7 @@ class Api::V2::OmahaReportsControllerTest < ActionController::TestCase
17
17
  assert_response :success
18
18
  assert_not_nil assigns(:omaha_reports)
19
19
  reports = ActiveSupport::JSON.decode(@response.body)
20
- assert !reports['results'].empty?
20
+ assert_not reports['results'].empty?
21
21
  end
22
22
 
23
23
  test 'should show individual record' do
@@ -25,7 +25,7 @@ class Api::V2::OmahaReportsControllerTest < ActionController::TestCase
25
25
  get :show, params: { :id => report.to_param }
26
26
  assert_response :success
27
27
  show_response = ActiveSupport::JSON.decode(@response.body)
28
- assert !show_response.empty?
28
+ assert_not show_response.empty?
29
29
  end
30
30
 
31
31
  test 'should destroy report' do
@@ -34,7 +34,7 @@ class Api::V2::OmahaReportsControllerTest < ActionController::TestCase
34
34
  delete :destroy, params: { :id => report.to_param }
35
35
  end
36
36
  assert_response :success
37
- refute Report.find_by(id: report.id)
37
+ assert_not Report.find_by(id: report.id)
38
38
  end
39
39
 
40
40
  test 'should get reports for given host only' do
@@ -43,7 +43,7 @@ class Api::V2::OmahaReportsControllerTest < ActionController::TestCase
43
43
  assert_response :success
44
44
  assert_not_nil assigns(:omaha_reports)
45
45
  reports = ActiveSupport::JSON.decode(@response.body)
46
- assert !reports['results'].empty?
46
+ assert_not reports['results'].empty?
47
47
  assert_equal 1, reports['results'].count
48
48
  end
49
49
 
@@ -63,7 +63,7 @@ class Api::V2::OmahaReportsControllerTest < ActionController::TestCase
63
63
  assert_response :success
64
64
  assert_not_nil assigns(:omaha_report)
65
65
  report = ActiveSupport::JSON.decode(@response.body)
66
- assert !report.empty?
66
+ assert_not report.empty?
67
67
  assert_equal reports.last, ForemanOmaha::OmahaReport.find(report['id'])
68
68
  end
69
69
 
@@ -74,7 +74,7 @@ class Api::V2::OmahaReportsControllerTest < ActionController::TestCase
74
74
  assert_response :success
75
75
  assert_not_nil assigns(:omaha_report)
76
76
  report = ActiveSupport::JSON.decode(@response.body)
77
- assert !report.empty?
77
+ assert_not report.empty?
78
78
  assert_equal main_report, ForemanOmaha::OmahaReport.find(report['id'])
79
79
  end
80
80
 
@@ -49,6 +49,6 @@ class OmahaReportsControllerTest < ActionController::TestCase
49
49
  report = FactoryBot.create(:omaha_report)
50
50
  delete :destroy, params: { :id => report }, session: set_session_user
51
51
  assert_redirected_to omaha_reports_url
52
- assert !ConfigReport.exists?(report.id)
52
+ assert_not ConfigReport.exists?(report.id)
53
53
  end
54
54
  end
@@ -49,7 +49,7 @@ class HostTest < ActiveSupport::TestCase
49
49
  host.build = true
50
50
  assert_valid host
51
51
  assert host.save
52
- refute host.reload.omaha_facet
52
+ assert_not host.reload.omaha_facet
53
53
  end
54
54
  end
55
55
  end
@@ -51,14 +51,12 @@ class OmahaFactsParserTest < ActiveSupport::TestCase
51
51
  context 'with old versions' do
52
52
  setup do
53
53
  FactoryBot.create(:coreos,
54
- :with_associations,
55
- :with_os_defaults,
56
54
  :major => '899',
57
55
  :minor => '17.0',
58
56
  :title => 'CoreOS 899.17.0')
59
57
  @previous = FactoryBot.create(:coreos,
60
58
  :with_associations,
61
- :with_os_defaults,
59
+ :with_provision,
62
60
  :major => '1010',
63
61
  :minor => '5.0',
64
62
  :title => 'CoreOS 1010.5.0')
@@ -70,7 +68,9 @@ class OmahaFactsParserTest < ActiveSupport::TestCase
70
68
  assert_equal @previous.ptables, os.ptables
71
69
  assert_equal @previous.architectures, os.architectures
72
70
  assert_equal @previous.media, os.media
73
- assert_equal @previous.os_default_templates, os.os_default_templates
71
+ assert_equal @previous.os_default_templates.map(&:provisioning_template), os.os_default_templates.map(&:provisioning_template)
72
+ assert_equal @previous.os_default_templates.map(&:template_kind), os.os_default_templates.map(&:template_kind)
73
+ assert_equal @previous.provisioning_templates, os.provisioning_templates
74
74
  end
75
75
  end
76
76
  end
@@ -2,20 +2,30 @@ require 'test_plugin_helper'
2
2
 
3
3
  module ForemanOmaha
4
4
  class RendererTest < ActiveSupport::TestCase
5
- class DummyRenderer
6
- attr_accessor :host
5
+ let(:host) { FactoryBot.create(:host) }
6
+ let(:template) { OpenStruct.new(name: 'abc', template: "<%= transpile_container_linux_config('---') %>") }
7
+ let(:source) { Foreman::Renderer::Source::Database.new(template) }
8
+ let(:scope) { Foreman::Renderer::Scope::Base.new(host: host, source: source) }
9
+ let(:expected) { '{"ignition":{"config":{},"timeouts":{},"version":"2.1.0"},"networkd":{},"passwd":{},"storage":{},"systemd":{}}' }
7
10
 
8
- include Foreman::Renderer
9
- include ForemanOmaha::RendererMethods
11
+ setup do
12
+ ForemanOmaha::ContainerLinuxConfigTranspiler.any_instance.stubs(:run!).returns(expected)
10
13
  end
11
14
 
12
- let(:renderer) { DummyRenderer.new }
15
+ context 'with safe mode renderer' do
16
+ let(:renderer) { Foreman::Renderer::SafeModeRenderer }
13
17
 
14
- test 'should transpile a container linux config' do
15
- expected = '{"ignition":{"config":{},"timeouts":{},"version":"2.1.0"},"networkd":{},"passwd":{},"storage":{},"systemd":{}}'
16
- ForemanOmaha::ContainerLinuxConfigTranspiler.any_instance.stubs(:run!).returns(expected)
17
- transpiled = renderer.transpile_container_linux_config('---')
18
- assert_equal expected, transpiled
18
+ test 'should transpile a container linux config' do
19
+ assert_equal expected, renderer.render(source, scope)
20
+ end
21
+ end
22
+
23
+ context 'with unsafe mode renderer' do
24
+ let(:renderer) { Foreman::Renderer::UnsafeModeRenderer }
25
+
26
+ test 'should transpile a container linux config' do
27
+ assert_equal expected, renderer.render(source, scope)
28
+ end
19
29
  end
20
30
  end
21
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_omaha
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timo Goebel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-29 00:00:00.000000000 Z
11
+ date: 2018-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jquery-matchheight-rails
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 0.54.0
47
+ version: 0.59.2
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 0.54.0
54
+ version: 0.59.2
55
55
  description: This plug-in adds support for the Omaha procotol to The Foreman. It allows
56
56
  you to better manage and update your CoreOS servers.
57
57
  email:
@@ -76,6 +76,7 @@ files:
76
76
  - app/helpers/foreman_omaha/omaha_groups_helper.rb
77
77
  - app/helpers/omaha_hosts_helper.rb
78
78
  - app/helpers/omaha_reports_helper.rb
79
+ - app/lib/foreman_omaha/renderer/scope/macros/omaha.rb
79
80
  - app/models/concerns/foreman_omaha/host_extensions.rb
80
81
  - app/models/concerns/foreman_omaha/omaha_facet_host_extensions.rb
81
82
  - app/models/foreman_omaha/fact_name.rb
@@ -91,7 +92,6 @@ files:
91
92
  - app/services/foreman_omaha/fact_parser.rb
92
93
  - app/services/foreman_omaha/group_version_breakdown.rb
93
94
  - app/services/foreman_omaha/omaha_report_importer.rb
94
- - app/services/foreman_omaha/renderer_methods.rb
95
95
  - app/services/foreman_omaha/status_mapper.rb
96
96
  - app/views/api/v2/omaha_groups/base.json.rabl
97
97
  - app/views/api/v2/omaha_groups/index.json.rabl
@@ -1,7 +0,0 @@
1
- module ForemanOmaha
2
- module RendererMethods
3
- def transpile_container_linux_config(input)
4
- ForemanOmaha::ContainerLinuxConfigTranspiler.new(input).run!
5
- end
6
- end
7
- end