foreman icon indicating copy to clipboard operation
foreman copied to clipboard

Fixes #38173 - Permit use of arrays for multiple timesources

Open jcpunk opened this issue 11 months ago • 11 comments

I'm unclear how best to test this.

My site offers multiple on site NTP servers on different names depending on location. This permits them to bring hosts down for maintenance without significant interruption.

jcpunk avatar Jan 29 '25 19:01 jcpunk

You can add the parameter to foreman/app/services/foreman/template_snapshot_service.rb

I'm not seeing where this has an existing test for when it is of type String. I'd expect for coverage and sanity it should check both String and Array types to make sure each kind works as expected.

Testwise, I'm not sure switching to is_a(String) seems to be on the safemode list?

jcpunk avatar Jun 10 '25 16:06 jcpunk

I'm unclear how best to test this.

In https://github.com/theforeman/foreman/pull/10605#pullrequestreview-3009592626 I described where we provide parameters. Then it runs through the snapshots and is validated.

In that PR I already felt the need for a "plain" (all defaults) host and then introduce another host with non-default values. Perhaps that's something you could look at, given how this code is non-trivial.

For this specific case I'd be tempted to not store the full snapshot but have a dedicated test with asserts. https://github.com/theforeman/foreman/commit/d7e1c39909cf365dcddf3b8ffff7b2c15c88377a can be another inspiration for that. You can see that in test/unit/foreman/templates we already have some template testing infrastructure.

ekohl avatar Jul 14 '25 11:07 ekohl

I've tried to add in test conditions. Per my usual behavior, RAILS_ENV=test bundle exec rails snapshots:generate provides a series of errors that make no sense to me.

RAILS_ENV=test bundle exec rails snapshots:generate
rails aborted!
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "settings" does not exist
LINE 1: SELECT "settings".* FROM "settings"
                                 ^
/data/app/registries/setting_registry.rb:183:in `load_values'
/data/app/registries/setting_registry.rb:161:in `load'
/data/lib/tasks/snapshots.rake:34:in `block (3 levels) in <main>'
/data/lib/tasks/snapshots.rake:33:in `block (2 levels) in <main>'
/data/bin/rails:9:in `<top (required)>'
/data/bin/spring:12:in `require'
/data/bin/spring:12:in `<top (required)>'

Caused by:
PG::UndefinedTable: ERROR:  relation "settings" does not exist
LINE 1: SELECT "settings".* FROM "settings"
                                 ^
/data/app/registries/setting_registry.rb:183:in `load_values'
/data/app/registries/setting_registry.rb:161:in `load'
/data/lib/tasks/snapshots.rake:34:in `block (3 levels) in <main>'
/data/lib/tasks/snapshots.rake:33:in `block (2 levels) in <main>'
/data/bin/rails:9:in `<top (required)>'
/data/bin/spring:12:in `require'
/data/bin/spring:12:in `<top (required)>'
Tasks: TOP => snapshots:generate
(See full trace by running task with --trace)

db:create and db:migrate are similarly erroring out.

jcpunk avatar Jul 14 '25 14:07 jcpunk

Patch rebased.

jcpunk avatar Aug 13 '25 17:08 jcpunk

The only one of these I actually use is anaconda.

I've attempted the other installer tweaks based on their online documentation.

jcpunk avatar Aug 13 '25 18:08 jcpunk

The template generation is producing an error on the ntp-server parameter test I added to RHEL. I have no idea how to fix that...

jcpunk avatar Aug 14 '25 14:08 jcpunk

I've tried to fix the testing again...

jcpunk avatar Aug 18 '25 15:08 jcpunk

Merged suggested change, squashed, and rebased off develop.

I'll rework the other if blocks.

I'm unsure if I've got something overall rational for junos since there is the server and boot-server bits and I've no experience with that product.

jcpunk avatar Sep 04 '25 14:09 jcpunk

hmmm

Safemode doesn't allow to access 'constant' on Array

jcpunk avatar Sep 04 '25 15:09 jcpunk

Oh that's annoying. Perhaps you can fake it and use host_param().respond_to?(:join) to determine if it's an array.

ekohl avatar Sep 04 '25 15:09 ekohl

Took a stab at fixing with the check for join.

I am staring at the error and not seeing I've done wrongly in the CI...

jcpunk avatar Sep 04 '25 16:09 jcpunk