Last active
April 22, 2018 12:41
-
-
Save timogoebel/783d746a524964d8d81a8b7a828969a0 to your computer and use it in GitHub Desktop.
0001-fixes-23335-normalize-scsi-attributes-in-rails-5.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From 10c1cbe954d037afdd626f5b1d47715c3746c5e4 Mon Sep 17 00:00:00 2001 | |
| From: Timo Goebel <mail@timogoebel.name> | |
| Date: Sun, 22 Apr 2018 12:48:23 +0200 | |
| Subject: [PATCH] fixes #23335 - normalize scsi attributes in rails 5 | |
| (cherry picked from commit 66ddc34a0a8c4d08c47394895e222fb6ef06e1b6) | |
| --- | |
| .../concerns/foreman/controller/parameters/host.rb | 6 +++++- | |
| app/controllers/hosts_controller.rb | 8 -------- | |
| test/controllers/concerns/parameters/host_test.rb | 15 +++++++++++++-- | |
| 3 files changed, 18 insertions(+), 11 deletions(-) | |
| diff --git a/app/controllers/concerns/foreman/controller/parameters/host.rb b/app/controllers/concerns/foreman/controller/parameters/host.rb | |
| index 88664c943..ca60b5aa9 100644 | |
| --- a/app/controllers/concerns/foreman/controller/parameters/host.rb | |
| +++ b/app/controllers/concerns/foreman/controller/parameters/host.rb | |
| @@ -32,7 +32,11 @@ module Foreman::Controller::Parameters::Host | |
| def host_params(top_level_hash = controller_name.singularize) | |
| keep_param(params, top_level_hash, :compute_attributes) do | |
| - self.class.host_params_filter.filter_params(params, parameter_filter_context, top_level_hash) | |
| + self.class.host_params_filter.filter_params(params, parameter_filter_context, top_level_hash).tap do |normalized| | |
| + if parameter_filter_context.ui? && normalized["compute_attributes"] && normalized["compute_attributes"]["scsi_controllers"] | |
| + normalize_scsi_attributes(normalized["compute_attributes"]) | |
| + end | |
| + end | |
| end | |
| end | |
| end | |
| diff --git a/app/controllers/hosts_controller.rb b/app/controllers/hosts_controller.rb | |
| index dedfc201d..70bdc2fbb 100644 | |
| --- a/app/controllers/hosts_controller.rb | |
| +++ b/app/controllers/hosts_controller.rb | |
| @@ -9,7 +9,6 @@ class HostsController < ApplicationController | |
| include Foreman::Controller::HostFormCommon | |
| include Foreman::Controller::Puppet::HostsControllerExtensions | |
| include Foreman::Controller::CsvResponder | |
| - include Foreman::Controller::NormalizeScsiAttributes | |
| include Foreman::Controller::ConsoleCommon | |
| SEARCHABLE_ACTIONS= %w[index active errors out_of_sync pending disabled ] | |
| @@ -40,7 +39,6 @@ class HostsController < ApplicationController | |
| before_action :set_host_type, :only => [:update] | |
| before_action :find_multiple, :only => MULTIPLE_ACTIONS | |
| before_action :validate_power_action, :only => :update_multiple_power_state | |
| - before_action :normalize_vm_attributes, :only => [:create, :update, :process_taxonomy] | |
| helper :hosts, :reports, :interfaces | |
| @@ -901,10 +899,4 @@ class HostsController < ApplicationController | |
| def csv_columns | |
| [:name, :operatingsystem, :environment, :compute_resource_or_model, :hostgroup, :last_report] | |
| end | |
| - | |
| - def normalize_vm_attributes | |
| - if host_params["compute_attributes"] && host_params["compute_attributes"]["scsi_controllers"] | |
| - normalize_scsi_attributes(host_params["compute_attributes"]) | |
| - end | |
| - end | |
| end | |
| diff --git a/test/controllers/concerns/parameters/host_test.rb b/test/controllers/concerns/parameters/host_test.rb | |
| index 54edbf535..5d9e26c3a 100644 | |
| --- a/test/controllers/concerns/parameters/host_test.rb | |
| +++ b/test/controllers/concerns/parameters/host_test.rb | |
| @@ -10,7 +10,7 @@ class HostParametersTest < ActiveSupport::TestCase | |
| test "passes through :compute_attributes hash untouched" do | |
| inner_params = {:name => 'test.example.com', :compute_attributes => {:foo => 'bar', :memory => 2}} | |
| expects(:params).at_least_once.returns(ActionController::Parameters.new(:host => inner_params)) | |
| - expects(:parameter_filter_context).returns(context) | |
| + expects(:parameter_filter_context).at_least_once.returns(context) | |
| filtered = host_params | |
| assert_equal 'test.example.com', filtered['name'] | |
| @@ -20,11 +20,22 @@ class HostParametersTest < ActiveSupport::TestCase | |
| test "correctly passes through :interfaces_attributes :compute_attributes hash" do | |
| inner_params = {:name => 'test.example.com', :interfaces_attributes => [{:name => 'abc', :compute_attributes => {:type => 'awesome', :network => 'superawesome'}}]} | |
| expects(:params).at_least_once.returns(ActionController::Parameters.new(:host => inner_params)) | |
| - expects(:parameter_filter_context).returns(ui_context) | |
| + expects(:parameter_filter_context).at_least_once.returns(ui_context) | |
| filtered = host_params | |
| assert_equal 'test.example.com', filtered['name'] | |
| assert_equal 'abc', filtered['interfaces_attributes'][0][:name] | |
| assert_equal({'type' => 'awesome', 'network' => 'superawesome'}, filtered['interfaces_attributes'][0]['compute_attributes'].to_h) | |
| end | |
| + | |
| + test 'normalizes json scsi attributes' do | |
| + inner_params = {:name => 'test.example.com', :compute_attributes => {"scsi_controllers"=>"{\"scsiControllers\":[{\"type\":\"VirtualLsiLogicController\",\"key\":1000}],\"volumes\":[{\"thin\":true,\"name\":\"Hard disk\",\"mode\":\"persistent\",\"controllerKey\":1000,\"size\":10485760,\"sizeGb\":10,\"storagePod\":\"Example-Pod\"}]}"}} | |
| + expects(:params).at_least_once.returns(ActionController::Parameters.new(:host => inner_params)) | |
| + expects(:parameter_filter_context).at_least_once.returns(ui_context) | |
| + filtered = host_params | |
| + | |
| + assert_equal 'test.example.com', filtered['name'] | |
| + assert_equal [{"type"=>"VirtualLsiLogicController", "key"=>1000}], filtered['compute_attributes']['scsi_controllers'] | |
| + assert_equal({"0"=>{"thin"=>true, "name"=>"Hard disk", "mode"=>"persistent", "controller_key"=>1000, "size"=>10485760, "size_gb"=>10, "storage_pod"=>"Example-Pod"}}, filtered['compute_attributes']['volumes_attributes']) | |
| + end | |
| end | |
| -- | |
| 2.16.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment