theforeman / foreman_expire_hosts

Foreman plugin for limiting host lifetime
GNU General Public License v3.0
5 stars 12 forks source link

Invalid expiration date upon multiple hosts expiration date change #61

Closed vladimirsafronov1251 closed 4 years ago

vladimirsafronov1251 commented 4 years ago

Hello, after upgrade Foreman to 1.24.3 and foreman_expire_hosts plugin to 7.0.0 we cannot update expiration date of hosts with "select action" button and getting "Invalid expiration date!" error. Change of expiration date from host's properties is working as usual.

In logs we got only following with loglevel=debug:

2020-06-02T15:31:25 [I|app|3718ea40] Started POST "/expired_hosts/select_multiple_expiration" for 10.101.186.18 at 2020-06-02 15:31:25 +0300 2020-06-02T15:31:25 [I|app|3718ea40] Processing by HostsController#select_multiple_expiration as HTML 2020-06-02T15:31:25 [I|app|3718ea40] Parameters: {"host_ids"=>["35", "38"]} 2020-06-02T15:31:25 [D|tax|3718ea40] Current location set to SANDBOX/CDT 2020-06-02T15:31:25 [D|tax|3718ea40] Current organization set to Default Organization 2020-06-02T15:31:25 [I|app|3718ea40] Rendering /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_expire_hosts-7.0.0/app/views/hosts/select_multiple_expiration.html.erb within layouts/application 2020-06-02T15:31:25 [I|app|3718ea40] Rendered hosts/_selected_hosts.html.erb (217.4ms) 2020-06-02T15:31:25 [I|app|3718ea40] Rendered /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_expire_hosts-7.0.0/app/views/hosts/select_multiple_expiration.html.erb within layouts/application (649.3ms) 2020-06-02T15:31:25 [I|app|3718ea40] Rendered layouts/_application_content.html.erb (2.0ms) 2020-06-02T15:31:25 [I|app|3718ea40] Rendering layouts/base.html.erb 2020-06-02T15:31:25 [I|app|3718ea40] Rendered layouts/base.html.erb (39.6ms) 2020-06-02T15:31:25 [I|app|3718ea40] Completed 200 OK in 738ms (Views: 687.2ms | ActiveRecord: 18.7ms) 2020-06-02T15:31:37 [I|app|3eb5a718] Started POST "/expired_hosts/update_multiple_expiration?host_ids%5B%5D=35&host_ids%5B%5D=38" for 10.101.186.18 at 2020-06-02 15:31:37 +0300 2020-06-02T15:31:37 [I|app|3eb5a718] Processing by HostsController#update_multiple_expiration as HTML 2020-06-02T15:31:37 [I|app|3eb5a718] Parameters: {"utf8"=>"✓", "authenticity_token"=>"", "host"=>{"expired_on(1i)"=>"2021", "expired_on(2i)"=>"1", "expired_on(3i)"=>"1"}, "host_ids"=>["35", "38"]} 2020-06-02T15:31:37 [D|tax|3eb5a718] Current location set to SANDBOX/CDT 2020-06-02T15:31:37 [D|tax|3eb5a718] Current organization set to Default Organization 2020-06-02T15:31:37 [I|app|3eb5a718] Redirected to https://10.101.106.14/hosts 2020-06-02T15:31:37 [I|app|3eb5a718] Filter chain halted as :validate_multiple_expiration rendered or redirected 2020-06-02T15:31:37 [I|app|3eb5a718] Completed 302 Found in 11ms (ActiveRecord: 1.7ms)

vladimirsafronov1251 commented 4 years ago

Seems that passing not reversed array to Date.new fixes the problem, but this was not intensively tested and might break another things.

https://github.com/theforeman/foreman_expire_hosts/blob/5f25fc9d469122f2333d0e5fbcea18491aa02681/app/controllers/concerns/foreman_expire_hosts/host_controller_extensions.rb#L59

change to Date.new(*expiration_date_arr) unless expiration_date_arr.all?(&:zero?) fixes this issue