Skip to content

Commit

Permalink
Add tests for Foreman 2.3 up to 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
laugmanuel committed Feb 28, 2022
1 parent f230261 commit 9655358
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 33 deletions.
28 changes: 20 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.5
ruby-version: 2.7
- name: Setup
run: |
gem install bundler
Expand All @@ -30,21 +30,29 @@ jobs:
strategy:
fail-fast: false
matrix:
foreman-core-branch: [2.0-stable, 2.1-stable, develop]
ruby-version: [2.5, 2.6]
node-version: [10]
foreman-core-branch: [2.3-stable, 2.4-stable, 2.5-stable, 3.0-stable, 3.1-stable, 3.2-stable, develop]
ruby-version: [2.6, 2.7]
node-version: [12]
steps:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install build-essential libcurl4-openssl-dev libvirt-dev ruby-libvirt zlib1g-dev libpq-dev
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: Apply patches for Foreman < 3.0
if: ${{ contains(fromJson('["2.3-stable", "2.4-stable", "2.5-stable"]'), matrix.foreman-core-branch) }}
run: |
git cherry-pick -n bad15051387b21563ffc0843a60f9dccfb2d3e17 # pin rdoc to use psych < 4.0.0
git cherry-pick -n f5a3dd2dedb569a0e6c5e8bb311c1da75906fc4f # use webpack-dev-server-without-h2
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
Expand All @@ -64,9 +72,13 @@ jobs:
npm install
bundle exec rake webpack:compile
- name: Run plugin tests
run: |
bundle exec rake test:foreman_dlm
bundle exec rake test TEST="test/unit/foreman/access_permissions_test.rb"
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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ locale/*/*.po.time_stamp
locale/*/*.pox

Gemfile.lock
.ruby-version
17 changes: 13 additions & 4 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
inherit_from: .rubocop_todo.yml

require:
- rubocop-rails
- rubocop-performance

AllCops:
TargetRubyVersion: 2.2
TargetRubyVersion: 2.7
TargetRailsVersion: 5.1
NewCops: enable
Exclude:
- '*.spec'
- 'Rakefile'

- 'extras/**/*'
- 'locale/**/*'
- 'node_modules/**/*'
- 'vendor/bundle/**/*'
Rails:
Enabled: true

Expand All @@ -15,7 +25,7 @@ Style/Documentation:
Metrics/MethodLength:
Max: 40

Metrics/LineLength:
Layout/LineLength:
Max: 190

Style/WordArray:
Expand Down Expand Up @@ -51,7 +61,6 @@ Performance/FixedSize:
- 'test/**/*'

Metrics/BlockLength:
ExcludedMethods: ['describe', 'context']
Exclude:
- 'config/routes.rb'
- 'lib/foreman_dlm/engine.rb'
Expand Down
128 changes: 128 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2022-02-23 12:58:32 UTC using RuboCop version 1.10.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include.
# Include: **/*.gemspec
Gemspec/OrderedDependencies:
Exclude:
- 'foreman_dlm.gemspec'

# Offense count: 1
# Configuration parameters: Include.
# Include: **/*.gemspec
Gemspec/RequiredRubyVersion:
Exclude:
- 'foreman_dlm.gemspec'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleAlignWith, Severity.
# SupportedStylesAlignWith: start_of_line, begin
Layout/BeginEndAlignment:
Exclude:
- 'lib/foreman_dlm/engine.rb'

# Offense count: 2
# Cop supports --auto-correct.
Layout/ClosingHeredocIndentation:
Exclude:
- 'app/controllers/api/v2/dlmlocks_controller.rb'

# Offense count: 11
# Cop supports --auto-correct.
Layout/EmptyLineAfterGuardClause:
Exclude:
- 'app/controllers/api/v2/dlmlock_events_controller.rb'
- 'app/controllers/api/v2/dlmlocks_controller.rb'
- 'app/controllers/concerns/foreman_dlm/update_checkin_time.rb'
- 'app/controllers/foreman_dlm/dlmlocks_controller.rb'
- 'app/helpers/foreman_dlm/dlmlock_helper.rb'
- 'app/models/concerns/foreman_dlm/expirable.rb'
- 'app/models/concerns/foreman_dlm/host_extensions.rb'
- 'app/models/concerns/foreman_dlm/host_monitoring_extensions.rb'
- 'app/models/foreman_dlm/dlmlock.rb'

# Offense count: 1
# Cop supports --auto-correct.
Layout/RescueEnsureAlignment:
Exclude:
- 'lib/foreman_dlm/engine.rb'

# Offense count: 4
# Cop supports --auto-correct.
Lint/SendWithMixinArgument:
Exclude:
- 'lib/foreman_dlm/engine.rb'

# Offense count: 1
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: at, by, db, id, in, io, ip, of, on, os, pp, to
Naming/MethodParameterName:
Exclude:
- 'app/models/foreman_dlm/dlmlock.rb'

# Offense count: 1
# Cop supports --auto-correct.
Performance/StringInclude:
Exclude:
- 'test/controllers/hosts_controller_test.rb'

# Offense count: 1
# Cop supports --auto-correct.
Rails/ActiveRecordAliases:
Exclude:
- 'app/controllers/api/v2/dlmlocks_controller.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: Include.
# Include: **/Rakefile, **/*.rake
Rails/RakeEnvironment:
Exclude:
- 'lib/tasks/foreman_dlm_tasks.rake'

# Offense count: 1
# Cop supports --auto-correct.
Rails/RedundantForeignKey:
Exclude:
- 'app/models/foreman_dlm/dlmlock.rb'

# Offense count: 19
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, Include.
# SupportedStyles: assert_not, refute
# Include: **/test/**/*
Rails/RefuteMethods:
Exclude:
- 'test/controllers/api/v2/dlmlocks_controller_test.rb'
- 'test/controllers/foreman_dlm/dlmlocks_test.rb'
- 'test/models/foreman_dlm/dlmlock_test.rb'
- 'test/models/host_managed_test.rb'
- 'test/models/host_status/dlmlock_status_test.rb'

# Offense count: 2
# Cop supports --auto-correct.
Style/ExpandPathArguments:
Exclude:
- 'foreman_dlm.gemspec'
- 'lib/foreman_dlm/engine.rb'

# Offense count: 67
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Style/FrozenStringLiteralComment:
Enabled: false

# Offense count: 1
# Cop supports --auto-correct.
Style/RedundantBegin:
Exclude:
- 'lib/foreman_dlm/engine.rb'
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ With this plugin servers can acquire a lock in Foreman to ensure only one server
| --------------- | -------------- |
| >= 1.15 | ~> 0.1 |
| >= 1.17 | ~> 1.0 |
| >= 2.3 | ~> 2.0 |

## Installation

Expand All @@ -34,6 +35,7 @@ Use the HTTP method `GET` to show a lock, `PUT` to acquire a lock and `DELETE` t
Foreman will respond with the HTTP status code `200 OK` if the action was successful and `412 Precondition Failed` if the lock could not be acquired or release. This may happen, if the lock is taken by another host.

To process the HTTP status code in a bash script, you can do something like this:

```
curl --write-out %{http_code} -H 'Content-Type: application/json' -sS -o /dev/null -X PUT --key $(puppet config print hostprivkey) --cert $(puppet config print hostcert) https://foreman.example.com/api/dlmlocks/test/lock
```
Expand All @@ -59,17 +61,19 @@ $ brew link curl --force
```

After that `curl --version` changes from

```
$ curl --version
curl 7.54.0 (x86_64-apple-darwin16.0) libcurl/7.54.0 SecureTransport zlib/1.2.8
```

to

```
$ curl --version
curl 7.56.1 (x86_64-apple-darwin16.7.0) libcurl/7.56.1 OpenSSL/1.0.2m zlib/1.2.8
```


## Contributing

Fork and send a Pull Request. Thanks!
Expand All @@ -85,9 +89,8 @@ the Free Software Foundation, either version 3 of the License, or

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

along with this program. If not, see <http://www.gnu.org/licenses/>.
9 changes: 8 additions & 1 deletion foreman_dlm.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ Gem::Specification.new do |s|
s.files = Dir['{app,config,db,lib,locale}/**/*', 'contrib/systemd/*'] + ['LICENSE', 'Rakefile', 'README.md']
s.test_files = Dir['test/**/*']

s.metadata = {
'rubygems_mfa_required' => 'true',
'is_foreman_plugin' => 'true'
}

s.add_development_dependency 'rdoc'
s.add_development_dependency 'rubocop', '0.52.1'
s.add_development_dependency 'rubocop', '~> 1.25.0'
s.add_development_dependency 'rubocop-rails', '~> 2.9.1'
s.add_development_dependency 'rubocop-performance', '~> 1.13.0'
end
2 changes: 1 addition & 1 deletion lib/foreman_dlm/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Engine < ::Rails::Engine

initializer 'foreman_dlm.register_plugin', :before => :finisher_hook do |_app|
Foreman::Plugin.register :foreman_dlm do
requires_foreman '>= 2.0'
requires_foreman '>= 2.3'

apipie_documented_controllers ["#{ForemanDlm::Engine.root}/app/controllers/api/v2/*.rb"]

Expand Down
5 changes: 3 additions & 2 deletions test/integration/foreman_dlm/dlmlocks_test.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# frozen_string_literal: true

require 'integration_test_plugin_helper'
require 'test_plugin_helper'
require 'integration_test_helper'

class DlmlocksTest < IntegrationTestWithJavascript
setup do
Setting::Dlm.load_defaults
User.current = users(:admin)
Setting::Dlm.load_defaults
end

test 'the index page works' do
Expand Down
13 changes: 0 additions & 13 deletions test/integration_test_plugin_helper.rb

This file was deleted.

4 changes: 4 additions & 0 deletions test/test_plugin_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@

# Add plugin to FactoryBot's paths
FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')

# Add factories of external plugin dependencies
FactoryBot.definition_file_paths << "#{ForemanMonitoring::Engine.root}/test/factories" if ForemanDlm.with_monitoring?

# Reload factory paths
FactoryBot.reload

0 comments on commit 9655358

Please sign in to comment.