Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/js_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: JavaScript Testing

on:
pull_request:
push:
branches:
- 'main'

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

jobs:
test:
name: JavaScript
uses: theforeman/actions/.github/workflows/foreman_plugin_js.yml@v0
with:
plugin: foreman_opennebula
26 changes: 26 additions & 0 deletions .github/workflows/ruby_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
name: Ruby Testing

on:
pull_request:
push:
branches:
- 'main'

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

jobs:
rubocop:
name: Rubocop
uses: theforeman/actions/.github/workflows/rubocop.yml@v0
with:
command: bundle exec rubocop --parallel --format github

ruby:
name: Ruby
needs: rubocop
uses: theforeman/actions/.github/workflows/foreman_plugin.yml@v0
with:
plugin: foreman_opennebula
85 changes: 18 additions & 67 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,99 +1,50 @@
require:
- rubocop-performance
- rubocop-rails
- rubocop-minitest
inherit_gem:
theforeman-rubocop:
- lenient.yml

AllCops:
TargetRubyVersion: 2.7
TargetRailsVersion: 6.0
Exclude:
- 'node_modules/**/*'

Layout/ArgumentAlignment:
EnforcedStyle: with_fixed_indentation
IndentationWidth: 2

Layout/HashAlignment:
Enabled: false

Layout/EmptyLineAfterGuardClause:
Metrics:
Enabled: false

Layout/LineLength:
Enabled: 111 # TODO: discuss and set this

Rails:
Enabled: true

Style/Alias:
EnforcedStyle: prefer_alias_method
Naming/AccessorMethodName:
Exclude:
- 'app/models/concerns/fog_extensions/open_nebula/flavor.rb'
- 'app/models/concerns/foreman_opennebula/key_pair_compute_resource.rb'

# Don't enforce documentation
Style/Documentation:
Naming/MethodParameterName:
Enabled: false

# Don't enforce frozen string literals
Style/FrozenStringLiteralComment:
Enabled: false
Rails/Blank:
UnlessPresent: false

# Support both ruby19 and hash_rockets
Style/HashSyntax:
Rails/DynamicFindBy:
Enabled: false

Style/RaiseArgs:
Rails/InverseOf:
Enabled: false

Style/FormatString:
EnforcedStyle: percent
Enabled: false

Style/FormatStringToken:
EnforcedStyle: template

Style/StringConcatenation:
Exclude:
- app/models/concerns/fog_extensions/opennebula/flavor.rb

Style/SymbolArray:
Enabled: false

Style/RescueStandardError:
Style/FrozenStringLiteralComment:
Enabled: false

Style/IfUnlessModifier:
Enabled: false

Metrics:
Enabled: false

Naming/AccessorMethodName:
Enabled: false

Naming/RescuedExceptionsVariableName:
Enabled: false

Layout/MultilineOperationIndentation:
Enabled: false

Layout/SpaceInsideHashLiteralBraces:
Enabled: false

Lint/UnusedBlockArgument:
Enabled: false

Rails/Blank:
Enabled: false

Rails/RakeEnvironment:
Enabled: false

Rails/DynamicFindBy:
Enabled: false

Rails/IndexWith:
Style/RaiseArgs:
Enabled: false

Rails/InverseOf:
Style/RescueStandardError:
Enabled: false

Naming/MethodParameterName:
Style/SymbolArray:
Enabled: false
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ task default: :test
begin
require 'rubocop/rake_task'
RuboCop::RakeTask.new
rescue => _
rescue LoadError
puts 'Rubocop not loaded.'
end

Expand Down
2 changes: 0 additions & 2 deletions app/models/concerns/fog_extensions/open_nebula/flavor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module Flavor
attribute :template_id
attribute :topology

# rubocop:disable Style/StringConcatenation
def to_s
'' + get_cpu \
+ get_vcpu \
Expand All @@ -34,7 +33,6 @@ def to_s
+ get_template_id \
+ get_topology
end
# rubocop:enable Style/StringConcatenation

def get_cpu_model
return '' unless attributes[:cpu_model]
Expand Down
4 changes: 2 additions & 2 deletions app/models/concerns/fog_extensions/open_nebula/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def user_template
!standard_attributes.include?(name)
end
user_attributes.map do |name, value|
OpenStruct.new({:name => name, :value => value})
OpenStruct.new({ :name => name, :value => value })
end
end

Expand Down Expand Up @@ -138,7 +138,7 @@ def vm_description
:cpu => cpu,
:vcpu => vcpu,
:memory => number_to_human_size(memory.to_i.megabytes),
:disk => number_to_human_size(disk_size.to_i.megabytes)
:disk => number_to_human_size(disk_size.to_i.megabytes),
}
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def setup_key_pair
key = SSHKey.generate(comment: "foreman-#{id}#{Foreman.uuid}")
opennebula_user = available_users.detect { |u| u.name == user }
opennebula_user.add_element('TEMPLATE',
'SSH_PRIVATE_KEY' => key.private_key,
'SSH_PUBLIC_KEY' => key.ssh_public_key)
'SSH_PRIVATE_KEY' => key.private_key,
'SSH_PUBLIC_KEY' => key.ssh_public_key)
template_str = opennebula_user.template_str
opennebula_user.update(template_str)
KeyPair.create! :name => key.comment, :compute_resource_id => id,
Expand Down
13 changes: 6 additions & 7 deletions app/models/foreman_opennebula/opennebula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def available_users
end

def create_vm(args = {})
vm_attrs = {:name => args[:name]}
vm_attrs = { :name => args[:name] }
vm_attrs[:flavor] = flavors.get(args[:template_id])
vm_attrs[:flavor].template_id = args[:template_id]
vm_attrs[:flavor].cpu = args[:cpu] if args[:cpu].present?
Expand All @@ -88,9 +88,7 @@ def create_vm(args = {})
end

vm_attrs[:flavor].nic = args[:interfaces_attributes].map do |_, attrs|
nic = {
:vnet => networks.get(attrs[:vnet])
}
nic = { :vnet => networks.get(attrs[:vnet]) }
nic[:ip] = attrs['ip'] if args['provision_method'] == 'image' && attrs['ip'].present?
if vm_attrs[:flavor].nic_default.present?
vm_attrs[:flavor].nic_default.each do |param, value|
Expand All @@ -101,10 +99,11 @@ def create_vm(args = {})
end

if args[:scheduler_hint_filter].present? && args[:scheduler_hint_data].present?
if args[:scheduler_hint_filter] == 'Cluster'
case args[:scheduler_hint_filter]
when 'Cluster'
cluster = available_clusters.detect { |c| c.id == args[:scheduler_hint_data].to_i }
vm_attrs[:flavor].sched_requirements = "CLUSTER_ID = #{cluster.id}"
elsif args[:scheduler_hint_filter] == 'Host'
when 'Host'
host = available_hosts.detect { |h| h.id == args[:scheduler_hint_data].to_i }
vm_attrs[:flavor].sched_requirements = "ID = #{host.id}"
else
Expand All @@ -121,7 +120,7 @@ def create_vm(args = {})
attribute[:name].present? && attribute[:_delete].empty?
end
vm_attrs[:flavor].user_variables = user_template_attributes.reduce({}) do |user_variables, attribute|
user_variables.merge({attribute[:name] => attribute[:value]})
user_variables.merge({ attribute[:name] => attribute[:value] })
end
end

Expand Down
5 changes: 1 addition & 4 deletions foreman_opennebula.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ Gem::Specification.new do |spec|

spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rdoc', '~> 6.4'
spec.add_development_dependency 'rubocop', '~> 1.36'
spec.add_development_dependency 'rubocop-minitest', '~> 0.38'
spec.add_development_dependency 'rubocop-performance', '~> 1.26'
spec.add_development_dependency 'rubocop-rails', '~> 2.33', '>= 2.33.3'
spec.add_development_dependency 'theforeman-rubocop', '~> 0.1.2'

spec.add_runtime_dependency 'fog-opennebula', '~> 0.0'
spec.add_dependency 'deface', '~> 1.9'
Expand Down
35 changes: 35 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const { foremanLocation, foremanRelativePath } = require('@theforeman/find-foreman')
const foremanReactRelative = 'webpack/assets/javascripts/react_app';
const foremanFull = foremanLocation();
const foremanReactFull = foremanRelativePath(foremanReactRelative);

// Jest configuration
module.exports = {
testURL: 'http://localhost/',
setupFiles: [
'./webpack/test_setup.js',
],
setupFilesAfterEnv: [
'./webpack/global_test_setup.js',
'@testing-library/jest-dom'
],
testPathIgnorePatterns: [
'/node_modules/',
'<rootDir>/foreman/',
'<rootDir>/.+fixtures.+',
'<rootDir>/engines',
],
moduleDirectories: [
`${foremanFull}/node_modules`,
`${foremanFull}/node_modules/@theforeman/vendor-core/node_modules`,
'node_modules',
'webpack/test-utils',
],
modulePathIgnorePatterns: [
'<rootDir>/foreman/',
],
moduleNameMapper: {
'^.+\\.(css|scss)$': 'identity-obj-proxy',
'^foremanReact(.*)$': `${foremanReactFull}/$1`,
},
};
17 changes: 0 additions & 17 deletions lib/tasks/foreman_opennebula_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,6 @@ namespace :test do
end
end

namespace :foreman_opennebula do
task :rubocop do
begin
require 'rubocop/rake_task'
RuboCop::RakeTask.new(:rubocop_foreman_opennebula) do |task|
task.patterns = ["#{ForemanOpennebula::Engine.root}/app/**/*.rb",
"#{ForemanOpennebula::Engine.root}/lib/**/*.rb",
"#{ForemanOpennebula::Engine.root}/test/**/*.rb"]
end
rescue
puts 'Rubocop not loaded.'
end

Rake::Task['rubocop_foreman_opennebula'].invoke
end
end

Rake::Task[:test].enhance ['test:foreman_opennebula']

load 'tasks/jenkins.rake'
Expand Down
30 changes: 23 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,34 @@
"main": "./webpack/index.js",
"scripts": {
"lint": "tfm-lint --plugin -d /webpack",
"test": "tfm-test --plugin",
"test": "tfm-test --config jest.config.js",
"test:watch": "tfm-test --plugin --watchAll",
"test:current": "tfm-test --plugin --watch",
"publish-coverage": "tfm-publish-coverage"
"publish-coverage": "tfm-publish-coverage",
"create-react-component": "yo react-domain"
},
"repository": {
"type": "git",
"url": "https://github.com/theforeman/foreman_opennebula.git"
"url": "git+https://github.com/theforeman/foreman_opennebula.git"
},
"author": {
"name": "Vitaly Pyslar",
"email": "[email protected]"
"peerDependencies": {
"@theforeman/vendor": ">= 6.0.0"
},
"license": "ISC"
"dependencies": {
"react-intl": "^2.8.0"
},
"devDependencies": {
"@babel/core": "^7.7.0",
"@sheerun/mutationobserver-shim": "^0.3.3",
"@theforeman/builder": "^6.0.0",
"@theforeman/eslint-plugin-foreman": "6.0.0",
"@theforeman/find-foreman": "^4.8.0",
"@theforeman/test": "^8.0.0",
"@theforeman/vendor-dev": "^6.0.0",
"babel-eslint": "^10.0.3",
"eslint": "^6.7.2",
"prettier": "^1.19.1",
"stylelint-config-standard": "^18.0.0",
"stylelint": "^9.3.0"
}
}
8 changes: 6 additions & 2 deletions test/factories/foreman_opennebula_factories.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
FactoryBot.define do
factory :host do
name 'foreman_opennebula'
trait :opennebula do
provider { 'OpenNebula' }
url { 'http://one.example.com:2633/RPC2' }
user { 'oneadmin' }
password { 'secret' }
after(:build) { |cr| cr.stubs(:connect) }
end
end
3 changes: 3 additions & 0 deletions webpack/__tests__/foreman_opennebula.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test('dummy test', () => {
expect(true).toBe(true);
});
Loading