theforeman / foreman_expire_hosts

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

Fixes day calculation for grace_period #77

Closed laugmanuel closed 5 months ago

laugmanuel commented 6 months ago

I'm not sure if this bug existed all the time or if it is caused by Ruby changes.

See the following example:

[32] pry(main)> host.expired_on
=> Fri, 10 May 2024 22:00:00.000000000 UTC +00:00

[33] pry(main)> host.expired_on - Setting['notify1_days_before_host_expiry'].to_i
=> Fri, 10 May 2024 21:59:53.000000000 UTC +00:00

[34] pry(main)> host.expired_on - Setting['notify1_days_before_host_expiry'].to_i.days
=> Fri, 03 May 2024 22:00:00.000000000 UTC +00:00
laugmanuel commented 6 months ago

mind having a look @ekohl ?

ekohl commented 6 months ago

I wonder if expired_on used to be a Date and is now a Datetime. db/migrate/20230112104438_change_expired_on_type.rb at least changes the DB type, so that could be the cause. It was introduced in 5bf6333e553b8c938d5620516dd5d9f2cc33a23f which doesn't really describe the change.

In most places it's used there's some .to_date code so perhaps that should also be done here? I don't really know the codebase so hard to say what's right here.

laugmanuel commented 6 months ago

I wonder if expired_on used to be a Date and is now a Datetime. db/migrate/20230112104438_change_expired_on_type.rb at least changes the DB type, so that could be the cause. It was introduced in 5bf6333 which doesn't really describe the change.

This might be the reason behind the different behaviour. I also don't know any reason behind this. Maybe @kamils-iRonin ?

In most places it's used there's some .to_date code so perhaps that should also be done here? I don't really know the codebase so hard to say what's right here.

I've also added .to_date for the relevant line. However, being explicit with .days sounds like a valid way to me.

ekohl commented 6 months ago

I have a Python background. Explicit is good

laugmanuel commented 5 months ago

Who can have a final look at this? As far as I understand, expire hosts is currently somewhat broken due to this bug.