Skip to content

Commit

Permalink
Support Foreman >= 3.9
Browse files Browse the repository at this point in the history
- migrate to settings DSL
- drop old Foreman version support
- switch to upstream CI
- switch to upstream rubocop
- add access permission test
  • Loading branch information
laugmanuel committed May 13, 2024
1 parent 56af16a commit f041c33
Show file tree
Hide file tree
Showing 73 changed files with 289 additions and 276 deletions.
105 changes: 28 additions & 77 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,84 +1,35 @@
name: CI
on: [push, pull_request]
env:
RAILS_ENV: test
DATABASE_URL: postgresql://postgres:@localhost/test
DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL: true
name: Ruby test

on:
pull_request:
push:
branches:
- master

concurrency:
group: ${{ github.ref_name }}-${{ github.workflow }}
cancel-in-progress: true

jobs:
rubocop:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
- name: Setup
run: |
gem install bundler
bundle install --jobs=3 --retry=3
- name: Run rubocop
run: bundle exec rubocop
uses: theforeman/actions/.github/workflows/rubocop.yml@v0
with:
command: bundle exec rubocop --parallel --format github

test:
runs-on: ubuntu-latest
name: Ruby
needs: rubocop
services:
postgres:
image: postgres:12.1
ports: ["5432:5432"]
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
strategy:
fail-fast: false
matrix:
foreman-core-branch: [3.0-stable, 3.1-stable, 3.2-stable, develop]
ruby-version: [2.7]
node-version: [12]
steps:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential libcurl4-openssl-dev libvirt-dev ruby-libvirt zlib1g-dev libpq-dev
- uses: actions/checkout@v2
with:
clean: false
repository: theforeman/foreman
ref: ${{ matrix.foreman-core-branch }}
fetch-depth: 0
- uses: actions/checkout@v2
with:
clean: false
path: foreman_dlm
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Setup Plugin
run: |
echo "gem 'foreman_dlm', path: './foreman_dlm'" > bundler.d/foreman_dlm.local.rb
gem install bundler
bundle config set without journald development console sqlite
bundle install --jobs=3 --retry=3
bundle exec rake db:create
bundle exec rake db:migrate
npm install
bundle exec rake webpack:compile
- name: Run plugin tests
uses: nick-fields/retry@v2
with:
max_attempts: 5
timeout_minutes: 30
command: |
bundle exec rake --trace test:foreman_dlm
bundle exec rake test TEST="test/unit/foreman/access_permissions_test.rb"
- name: Precompile plugin assets
run: |
bundle exec rake db:create
bundle exec rake db:migrate
bundle exec rake 'plugin:assets:precompile[foreman_dlm]'
env:
DATABASE_URL: postgresql://postgres:@localhost/production
RAILS_ENV: production
foreman:
- "develop"
- "3.10-stable"
- "3.9-stable"
uses: theforeman/actions/.github/workflows/foreman_plugin.yml@v0
with:
plugin: foreman_dlm
foreman_version: ${{ matrix.foreman }}
environment_variables: |
FOREMAN_VERSION=${{ matrix.foreman }}
DEBUG_JS_TEST=1
22 changes: 3 additions & 19 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
inherit_from: .rubocop_todo.yml

require:
- rubocop-rails
- rubocop-performance

AllCops:
TargetRubyVersion: 2.7
TargetRailsVersion: 5.1
NewCops: enable
Exclude:
- '*.spec'
- 'Rakefile'
- 'extras/**/*'
- 'locale/**/*'
- 'node_modules/**/*'
- 'vendor/bundle/**/*'
Rails:
Enabled: true
inherit_gem:
theforeman-rubocop:
- default.yml

# Don't enforce documentation
Style/Documentation:
Expand Down
48 changes: 0 additions & 48 deletions .rubocop_todo.yml

This file was deleted.

2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec
6 changes: 4 additions & 2 deletions Rakefile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env rake
# frozen_string_literal: true

begin
require 'bundler/setup'
rescue LoadError
Expand All @@ -20,7 +22,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_files.include('lib/**/*.rb')
end

APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)

Bundler::GemHelper.install_tasks

Expand All @@ -38,7 +40,7 @@ task default: :test
begin
require 'rubocop/rake_task'
RuboCop::RakeTask.new
rescue => _
rescue StandardError
puts 'Rubocop not loaded.'
end

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/api/v2/dlmlock_events_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Api
module V2
class DlmlockEventsController < V2::BaseController
Expand Down
25 changes: 14 additions & 11 deletions app/controllers/api/v2/dlmlocks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Api
module V2
class DlmlocksController < V2::BaseController
Expand Down Expand Up @@ -37,7 +39,8 @@ def index
error 404, 'Lock could not be found.'
param :id, String, :required => true, :desc => N_('Id or name of the DLM lock')

def show; end
def show
end

api :POST, '/dlmlocks', N_('Create a DLM lock')
param_group :dlmlock, :as => :create
Expand All @@ -52,7 +55,7 @@ def create
param_group :dlmlock

def update
process_response @dlmlock.update_attributes(dlmlocks_params)
process_response @dlmlock.update(dlmlocks_params)
end

api :DELETE, '/dlmlocks/:id/', N_('Delete a DLM lock')
Expand Down Expand Up @@ -133,16 +136,16 @@ def find_host
logger.info 'Denying access because no host could be detected.'
if User.current
render_error 'access_denied',
:status => :forbidden,
:locals => {
:details => 'You need to authenticate with a valid client cert. The DN has to match a known host.'
}
:status => :forbidden,
:locals => {
:details => 'You need to authenticate with a valid client cert. The DN has to match a known host.',
}
else
render_error 'unauthorized',
:status => :unauthorized,
:locals => {
:user_login => get_client_cert_hostname
}
:status => :unauthorized,
:locals => {
:user_login => get_client_cert_hostname,
}
end
end
true
Expand All @@ -163,7 +166,7 @@ def process_lock_resource_error(options = {})
deny_access
else
render_error 'precondition_failed', :status => :precondition_failed, :locals => {
:message => 'Precondition failed. Lock is in invalid state for this operation.'
:message => 'Precondition failed. Lock is in invalid state for this operation.',
}
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Foreman::Controller::Parameters::Dlmlocks
extend ActiveSupport::Concern

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ForemanDlm
module FindHostByClientCert
extend ActiveSupport::Concern
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/concerns/foreman_dlm/find_host_by_ip.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ForemanDlm
module FindHostByIp
extend ActiveSupport::Concern
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/concerns/foreman_dlm/update_checkin_time.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ForemanDlm
module UpdateCheckinTime
extend ActiveSupport::Concern
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/foreman_dlm/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ForemanDlm
class ApplicationController < ::ApplicationController
def resource_class
Expand Down
14 changes: 4 additions & 10 deletions app/controllers/foreman_dlm/dlmlocks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ForemanDlm
class DlmlocksController < ::ForemanDlm::ApplicationController
include ::Foreman::Controller::AutoCompleteSearch
Expand All @@ -9,7 +11,8 @@ def index
@dlmlocks = resource_base_search_and_page(:host)
end

def show; end
def show
end

def destroy
if @dlmlock.destroy
Expand Down Expand Up @@ -59,15 +62,6 @@ def model_of_controller
ForemanDlm::Dlmlock
end

# see https://projects.theforeman.org/issues/25976
# can be removed for Foreman 1.22+
def auto_complete_controller_name
current_version = Gem::Version.new(Foreman::Version.new.notag)
return '/foreman_dlm/dlmlocks' if current_version >= Gem::Version.new('1.20') && current_version < Gem::Version.new('1.22')

controller_name
end

private

def action_permission
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/foreman_dlm/dlmlock_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ForemanDlm
module DlmlockHelper
def dlmlock_status_icon_class(lock)
Expand Down
2 changes: 2 additions & 0 deletions app/jobs/foreman_dlm/refresh_dlmlock_status.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ForemanDlm
class RefreshDlmlockStatus < ApplicationJob
queue_as :refresh_dlmlock_status_queue
Expand Down
2 changes: 2 additions & 0 deletions app/models/concerns/foreman_dlm/dlm_facet_host_extensions.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ForemanDlm
module DlmFacetHostExtensions
extend ActiveSupport::Concern
Expand Down
2 changes: 2 additions & 0 deletions app/models/concerns/foreman_dlm/expirable.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ForemanDlm
module Expirable
extend ActiveSupport::Concern
Expand Down
18 changes: 10 additions & 8 deletions app/models/concerns/foreman_dlm/host_extensions.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
# frozen_string_literal: true

module ForemanDlm
module HostExtensions
extend ActiveSupport::Concern

included do
has_many :dlmlocks,
class_name: 'ForemanDlm::Dlmlock',
foreign_key: 'host_id',
dependent: :nullify,
inverse_of: :host
class_name: 'ForemanDlm::Dlmlock',
foreign_key: 'host_id',
dependent: :nullify,
inverse_of: :host

has_many :dlmlock_events,
class_name: 'ForemanDlm::DlmlockEvent',
foreign_key: 'host_id',
dependent: :destroy,
inverse_of: :host
class_name: 'ForemanDlm::DlmlockEvent',
foreign_key: 'host_id',
dependent: :destroy,
inverse_of: :host

define_model_callbacks :lock, :only => :after
define_model_callbacks :unlock, :only => :after
Expand Down
Loading

0 comments on commit f041c33

Please sign in to comment.