Skip to content

Commit

Permalink
Fixes #22995 - update for recent Foreman compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ares committed Mar 27, 2018
1 parent b23e13a commit 4a9e485
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def show
param :id, :identifier, :required => true
def deploy_script
respond_to do |format|
format.text { render :text => @config.virt_who_bash_script }
format.sh { render :text => @config.virt_who_bash_script }
format.text { send_data @config.virt_who_bash_script, :filename => "deploy_virt_who_config_#{@config.id}.sh", :type => 'text/x-shellscript', :disposition => :attachment }
format.sh { send_data @config.virt_who_bash_script, :filename => "deploy_virt_who_config_#{@config.id}.sh", :type => 'text/x-shellscript', :disposition => :attachment }
format.json
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/foreman_virt_who_configure/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class Config < ActiveRecord::Base
# We keep both params permitted for compatibility with 1.11
:listing_mode, :filtering_mode
]
include Authorizable
audited :except => [ :hypervisor_password, :last_report_at, :out_of_date_at ]
include Authorizable
validates_lengths_from_database

UNLIMITED = 0
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20170102152649_create_service_users.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateServiceUsers < ActiveRecord::Migration
class CreateServiceUsers < ActiveRecord::Migration[4.2]
def change
create_table :foreman_virt_who_configure_service_users do |t|
t.string :encrypted_password, :null => false
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20170102152650_create_configs.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateConfigs < ActiveRecord::Migration
class CreateConfigs < ActiveRecord::Migration[4.2]
def change
create_table :foreman_virt_who_configure_configs do |t|
t.integer :interval, :default => 60, :null => true
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20170102152751_add_lab_attrs_to_config.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddLabAttrsToConfig < ActiveRecord::Migration
class AddLabAttrsToConfig < ActiveRecord::Migration[4.2]
def change
add_column :foreman_virt_who_configure_configs, :debug, :boolean, :default => false, :null => true
add_column :foreman_virt_who_configure_configs, :hypervisor_type, :string, :null => true
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20170102152851_add_satellite_url_to_config.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddSatelliteUrlToConfig < ActiveRecord::Migration
class AddSatelliteUrlToConfig < ActiveRecord::Migration[4.2]
def change
add_column :foreman_virt_who_configure_configs, :satellite_url, :string, :null => true
end
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20170215152851_change_default_interval.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ChangeDefaultInterval < ActiveRecord::Migration
class ChangeDefaultInterval < ActiveRecord::Migration[4.2]
def up
change_column :foreman_virt_who_configure_configs, :interval, :integer, :default => 120
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddProxyAndNoProxyToConfig < ActiveRecord::Migration
class AddProxyAndNoProxyToConfig < ActiveRecord::Migration[4.2]
def up
add_column :foreman_virt_who_configure_configs, :proxy, :string
add_column :foreman_virt_who_configure_configs, :no_proxy, :string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddLastReportInfoToConfig < ActiveRecord::Migration
class AddLastReportInfoToConfig < ActiveRecord::Migration[4.2]
def change
add_column :foreman_virt_who_configure_configs, :last_report_at, :datetime
add_column :foreman_virt_who_configure_configs, :out_of_date_at, :datetime
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20170407152851_add_name_to_config.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddNameToConfig < ActiveRecord::Migration
class AddNameToConfig < ActiveRecord::Migration[4.2]
def change
add_column :foreman_virt_who_configure_configs, :name, :string, :null => false, :default => ''
end
Expand Down
22 changes: 11 additions & 11 deletions test/functional/api/v2/configs_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ForemanVirtWhoConfigure::Api::V2::ConfigsControllerTest < ActionController
end

test "should get index" do
get :index, {}, set_session_user
get :index, :params => {}, :session => set_session_user
response = ActiveSupport::JSON.decode(@response.body)
assert_not response['results'].empty?
assert_response :success
Expand Down Expand Up @@ -59,7 +59,7 @@ class ForemanVirtWhoConfigure::Api::V2::ConfigsControllerTest < ActionController
end

test "should get show for new config" do
get :show, { :id => @new_config.to_param }, set_session_user
get :show, :params => { :id => @new_config.to_param }, :session => set_session_user
response = ActiveSupport::JSON.decode(@response.body)

assert_equal 'my vmware', response['name']
Expand All @@ -84,7 +84,7 @@ class ForemanVirtWhoConfigure::Api::V2::ConfigsControllerTest < ActionController
end

test "should get show for ok config" do
get :show, { :id => @ok_config.to_param }, set_session_user
get :show, :params => { :id => @ok_config.to_param }, :session => set_session_user
response = ActiveSupport::JSON.decode(@response.body)

assert_equal 'ok', response['status']
Expand All @@ -94,7 +94,7 @@ class ForemanVirtWhoConfigure::Api::V2::ConfigsControllerTest < ActionController
end

test "should get show for out of date config" do
get :show, { :id => @out_of_date_config.to_param }, set_session_user
get :show, :params => { :id => @out_of_date_config.to_param }, :session => set_session_user
response = ActiveSupport::JSON.decode(@response.body)

assert_equal 'out_of_date', response['status']
Expand All @@ -104,23 +104,23 @@ class ForemanVirtWhoConfigure::Api::V2::ConfigsControllerTest < ActionController
end

test "should get deploy script for config" do
get :deploy_script, { :id => @out_of_date_config.to_param }, set_session_user
get :deploy_script, :params => { :id => @out_of_date_config.to_param }, :session => set_session_user
response = ActiveSupport::JSON.decode(@response.body)

assert_response :success
assert_equal @out_of_date_config.virt_who_config_script(:bash_script), response['virt_who_config_script']
end

test "should get deploy script for plain/text format" do
get :deploy_script, { :id => @out_of_date_config.to_param, :format => 'txt' }, set_session_user
get :deploy_script, :params => { :id => @out_of_date_config.to_param }, :session => set_session_user, :format => :txt
response = @response.body

assert_response :success
assert_equal @out_of_date_config.virt_who_config_script(:bash_script), response
end

test "should get deploy script for shell script format" do
get :deploy_script, { :id => @out_of_date_config.to_param, :format => 'sh' }, set_session_user
get :deploy_script, :params => { :id => @out_of_date_config.to_param }, :session => set_session_user, :format => :sh
response = @response.body

assert_response :success
Expand All @@ -129,7 +129,7 @@ class ForemanVirtWhoConfigure::Api::V2::ConfigsControllerTest < ActionController

test "should create the config" do
org = FactoryBot.create(:organization)
post :create, { :foreman_virt_who_configure_config => { :name => 'my new config',
post :create, :params => { :foreman_virt_who_configure_config => { :name => 'my new config',
:interval => 240,
:filtering_mode => ForemanVirtWhoConfigure::Config::BLACKLIST,
:blacklist => ' a,b ',
Expand All @@ -141,7 +141,7 @@ class ForemanVirtWhoConfigure::Api::V2::ConfigsControllerTest < ActionController
:debug => true,
:satellite_url => "foreman.example.com",
:organization_id => org.id }
}, set_session_user
}, :session => set_session_user

assert_response :success

Expand All @@ -161,7 +161,7 @@ class ForemanVirtWhoConfigure::Api::V2::ConfigsControllerTest < ActionController
end

test "should update the config" do
put :update, { :id => @ok_config.to_param, :foreman_virt_who_configure_config => { :name => 'updated', :interval => 240, :hypervisor_password => 'new_pass' } }, set_session_user
put :update, :params => { :id => @ok_config.to_param, :foreman_virt_who_configure_config => { :name => 'updated', :interval => 240, :hypervisor_password => 'new_pass' } }, :session => set_session_user
assert_response :success
@ok_config.reload
assert_equal 'updated', @ok_config.name
Expand All @@ -170,7 +170,7 @@ class ForemanVirtWhoConfigure::Api::V2::ConfigsControllerTest < ActionController
end

test "should destroy the config" do
delete :destroy, { :id => @ok_config.to_param }, set_session_user
delete :destroy, :params => { :id => @ok_config.to_param }, :session => set_session_user
assert_response :success

assert_empty ForemanVirtWhoConfigure::Config.where(:id => @ok_config.id).all
Expand Down

0 comments on commit 4a9e485

Please sign in to comment.