Closed ohgaryoh closed 1 year ago
It's probably due to this commit. Thanks for reporting.
It's probably due to this commit. Thanks for reporting.
Great, thank you for looking into this. Is there anything I can do on my end or wait until an update is pushed out?
You could revert that commit on your system for now until there is a fix.
Found the file: /usr/share/gems/gems/foreman_puppet-5.1.2/app/views/foreman_puppet/puppetclasses/_selected_classes.html.erb
edited it to the previous commit, restarted services and it is working now. Thank you for your help!
@ekohl Do you have any idea how to fix this properly?
My feeling is that there's too much logic in the template, so first unwrap it. What follows is a written down version of my thought process.
So the code:
That's very long, so take the relevant bit:
'unavailable' unless klass.environments.include?(obj.environment.present? ? obj.environment : @environment)
My first step would be to extract that:
<%-
class_in_environment = klass.environments.include?(obj.environment.present? ? obj.environment : @environment)
-%>
<%= content_tag :li, id: "selected_puppetclass_#{klass.id}", class: [dom_class(klass, 'selected'), cycle('even', 'odd'), ('unavailable' unless class_in_environment)] do %>
This hasn't changed any functionality, but it's easier to modify. I chose a multi line block since it's easier to modify later.
Then I want to understand where it's called: https://github.com/theforeman/foreman_puppet/blob/936b4688eea4eaf562296f24a1eb11c61b11e74b/app/views/foreman_puppet/puppetclasses/_class_selection.html.erb#L13-L22
There we see we can look at the resource type and there already is an exception for the config group resource type. You can probably use this. I don't think config groups really are linked to an environment so I'm not sure what the logic should be. You can probably revert to using @environment
when the resource type is :config_group
, which would likely prevent crashes. However, I'm not sure @environment
is even set. It's not passed as a local so it may always be nil
. I'd also check that.
Does that help?
@ekohl Makes sense, thank you a lot! I will take a closer look at this.
A quick hack would be to just wrap environment in try, e.g. this seems to do the trick
<%= content_tag :li, id: "selected_puppetclass_#{klass.id}", class: [dom_class(klass, 'selected'), cycle('even', 'odd'), ('unavailable' unless klass.environments.include?(obj.try(:environment).present? ? obj.try(:environment) : @environment))] do %>
That would make this partial compatible with also object that are not linked to the environment, which I think was the original logic of this condition.
If that works, isn't obj.try(:environment).presence || @environment
the same? Or at least the second .try
is redundant because we already know it responds to .environment
, so obj.try(:environment).present? ? obj.environment : @environment)
.
When selecting a config group under Configure > Config Groups the following error message is shown:
undefined method `environment’ for #ForemanPuppet::ConfigGroup:0x00005585340b0e50
Foreman and Proxy versions: 3.5.3
Foreman and Proxy plugin versions:
foreman-tasks 7.1.1 foreman_ansible 10.4.2 foreman_discovery 22.0.2 foreman_openscap 6.0.0 foreman_puppet 5.1.2 foreman_remote_execution 8.2.0 katello 4.7.5 Distribution and version:
Rocky 8.8
Other relevant data: We have recently restored a new Rocky 8 server with the Forman/Katello backup of our Centos 7 sever which ran F 3.3 and K 4.5 using foreman backup and restore, so that we can be on a supported OS and Foreman/Katello version. We are able to use the hammer shell to make changes to our config groups. This is an issue that has shown up and would like help resolving it.
I have posted this on the support forum on Foreman and it was suggested that I open a request here as well.
From foreman-rake errors:fetch_log request_id=084acb5d command:
Foreman version: 3.5.3 Plugins:
Thank you for the help in advance