Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #37144 - Use OS family for host details page packages tab #10881

Merged

Conversation

nadjaheitmann
Copy link
Contributor

What are the changes introduced in this pull request?

At the moment, the packages sub tab on the new host details page is shown based on the description of the operating system (e.g. checking whether it should load rpm or debs). The condition checks for various strings, but the description itself can be randomly assigned by the user. Hence, this is not a safe method to determine which OS was used.

Considerations taken when implementing this change?

We need to find an unchangeable attribute to test against for the content packages tabs which is the operatingsystem family.

What are the testing steps for this pull request?

Have a host with packages and some OS. Change OS name to something like "Test OS" --> Host packages should still be available.

@nadjaheitmann nadjaheitmann force-pushed the os_family_for_content_packages_tab branch from b04e8b0 to 6d7b6c2 Compare February 7, 2024 16:42
@nadjaheitmann
Copy link
Contributor Author

@jeremylenz We found a bug partly introduced in #10744, here is a proposed fix :) Test failure seems unrelated if I am not mistaken.

Copy link
Member

@jeremylenz jeremylenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @nadjaheitmann! Yes, I agree this should be addressed.

I see we're adding an additional API call here. There are a couple other ways this could be accomplished, without adding an API call.

  1. The host details response already includes operatingsystem_name and operatingsystem_id. We could add operatingsystem_family to that, either (a) via a Foreman code change so other plugins could take advantage; or (b) by extending it from Katello.
  2. The response also already includes facts. Foreman uses the distribution::name fact to determine the operating system's family. We could look at that fact here as well. (see https://github.com/theforeman/foreman/blob/e87de8d1a30aeba3da6d0cb2518d94aa450db55e/app/services/katello/rhsm_fact_parser.rb#L49-L51)

@nadjaheitmann
Copy link
Contributor Author

2. The response also already includes `facts`. Foreman uses the `distribution::name` fact to determine the operating system's family. We could look at that fact here as well.  (see https://github.com/theforeman/foreman/blob/e87de8d1a30aeba3da6d0cb2518d94aa450db55e/app/services/katello/rhsm_fact_parser.rb#L49-L51)

This was my first attempt. There is facts as part of the host details. What if the host is not managed by any config management system? Do we still have those facts? If you try accessing the distribution::name in facts hash it gives you an error as distribution::name is no valid JS syntax for hash keys.

1. The host details response already includes `operatingsystem_name` and `operatingsystem_id`. We could add `operatingsystem_family` to that, either (a) via a Foreman code change so other plugins could take advantage; or (b) by extending it from Katello.

I was actually looking into that one as well, but Host class does not have any attribute called operatingsystem_family and I don't know how to add it such that it could be exposed in the .rabl file for the API. Any hints?

This is why I finally came up with another API call.

@nadjaheitmann
Copy link
Contributor Author

nadjaheitmann commented Feb 7, 2024

Also, we need to test the operatingsystem's major version for module streams, so we would also need to expose that one. I agree it would be much simpler if it was part of one API response.

@jeremylenz
Copy link
Member

jeremylenz commented Feb 7, 2024

I was actually looking into that one as well, but Host class does not have any attribute called operatingsystem_family and I don't know how to add it such that it could be exposed in the .rabl file for the API. Any hints?

The problem is that the operatingsystems table doesn't actually have a family attribute; rather it's a column called type which is renamed to family.

You can see this by running

bundle exec rails db:schema:dump

and then look at the file db/structure.sql:

CREATE TABLE public.operatingsystems (
    id integer NOT NULL,
    major character varying(5) DEFAULT ''::character varying NOT NULL,
    name character varying(255) NOT NULL,
    minor character varying(16) DEFAULT ''::character varying NOT NULL,
    nameindicator character varying(3),
    created_at timestamp without time zone,
    updated_at timestamp without time zone,
    release_name character varying(255),
    type character varying(255),
    description character varying(255),
    password_hash character varying(255) DEFAULT 'SHA256'::character varying,
    title character varying(255)
);

So Rails doesn't add the operatingsystem_family convenience method like it did for name and id.

# app/models/operatingsystem.rb
def family
    self[:type]
  end

  def family=(value)
    self.type = value
  end

To add family to the rabl in Foreman, this would probably work:

# app/views/api/v2/hosts/main.json.rabl
node :operatingsystem_family do |host|
  host.operatingsystem.family
end

Or, to extend it from Katello, I think you could add the same to app/views/katello/api/v2/hosts/base.json.rabl

@nadjaheitmann
Copy link
Contributor Author

Thanks for the detailed explanation, much appreciated! Do you actually need the operating system family anywhere outside Katello?

@jeremylenz
Copy link
Member

If you're asking where the code should live, I'd be fine with keeping it in Katello.

@nadjaheitmann
Copy link
Contributor Author

nadjaheitmann commented Feb 7, 2024

Yeah, thanks. I don't get it work in Katello, though. It does not seem to load the app/views/katello/api/v2/hosts/base.json.rabl

No problem to edit the .rabl file directly in Foreman.

@jeremylenz
Copy link
Member

def show
@render_template = 'katello/api/v2/hostgroups_extensions/show'
render @render_template
end
end

Hm, maybe you'll need to add something similar to that ^, but in hosts_controller_extensions

@jeremylenz
Copy link
Member

Another thing to try is extend_rabl_template. Seems like foreman_remote_execution does this:

https://github.com/theforeman/foreman_remote_execution/blob/e97021ca4417d737f6d60a7586efd786413041db/lib/foreman_remote_execution/engine.rb#L274-L278

@nadjaheitmann
Copy link
Contributor Author

def show
@render_template = 'katello/api/v2/hostgroups_extensions/show'
render @render_template
end
end

Hm, maybe you'll need to add something similar to that ^, but in hosts_controller_extensions

This actually overrides the original template.

Another thing to try is extend_rabl_template. Seems like foreman_remote_execution does this:

This seems to do the trick, thanks!

@nadjaheitmann nadjaheitmann force-pushed the os_family_for_content_packages_tab branch 2 times, most recently from 40ffd80 to d9fdf3d Compare February 7, 2024 22:30
@nadjaheitmann
Copy link
Contributor Author

@jeremylenz Looks much better doesn't it :)

Copy link
Member

@jeremylenz jeremylenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking much better 😄

Also tested it and it's working well.

Just a couple small suggestions

@@ -1,9 +1,19 @@
object @resource
object @host
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
object @host

This seems to not be needed

Comment on lines 9 to 14
node :operatingsystem_family do |host|
host.operatingsystem.family
end

node :operatingsystem_major do |host|
host.operatingsystem.major
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to work also..

Suggested change
node :operatingsystem_family do |host|
host.operatingsystem.family
end
node :operatingsystem_major do |host|
host.operatingsystem.major
end
node :operatingsystem_family do
@resource.operatingsystem.family
end
node :operatingsystem_major do
@resource.operatingsystem.major
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, fixed

@nadjaheitmann nadjaheitmann force-pushed the os_family_for_content_packages_tab branch from d9fdf3d to 7a9c083 Compare February 8, 2024 14:25
@jeremylenz
Copy link
Member

Once #10884 is merged let's see how the tests look. LGTM pending green tests. 👍

@jeremylenz
Copy link
Member

[test katello]

@nadjaheitmann nadjaheitmann force-pushed the os_family_for_content_packages_tab branch 2 times, most recently from 17c7939 to b068b4b Compare February 11, 2024 22:04
@nadjaheitmann
Copy link
Contributor Author

[2024-02-11T22:26:17.378Z] Error:
[2024-02-11T22:26:17.378Z] Katello::Api::Rhsm::CandlepinDynflowProxyControllerIntegrationTest#test_0001_params are not parsed in the controller:
[2024-02-11T22:26:17.378Z] Errno::ENOENT: No such file or directory @ rb_sysopen - /home/jenkins/workspace/katello-pr-test/foreman/test/fixtures/hosts.yml
[2024-02-11T22:26:17.378Z] test/test_helper.rb:77:in `before_setup'

Looks like a fixture cannot be found in foreman itself. Any idea how to fix this?

@nadjaheitmann nadjaheitmann force-pushed the os_family_for_content_packages_tab branch from b068b4b to 6ec24ad Compare February 12, 2024 21:05
@jeremylenz
Copy link
Member

Looks like a fixture cannot be found in foreman itself. Any idea how to fix this?

I don't even see how fixtures are being used -- that test uses FactoryBot, anyway. See if a rebase fixes it maybe? 🤔

@nadjaheitmann nadjaheitmann force-pushed the os_family_for_content_packages_tab branch from 6ec24ad to fed0b38 Compare February 13, 2024 07:55
@nadjaheitmann
Copy link
Contributor Author

nadjaheitmann commented Feb 13, 2024

Now the katello test is green, it was one commit I have added - seems fishy... New failure though, which I assume is not related:

Failure:
Actions::Pulp3::CopyAllUnitsDockerRepositoryTest#test_exclusion_docker_filters [katello/test/actions/pulp3/orchestration/copy_all_units_test.rb:89]
Minitest::Assertion: Expected: ["musl", "glibc"]
Actual: ["glibc", "musl"]

@jeremylenz
Copy link
Member

I re-ran that check and it's green now. Was just an array ordering failure that we get intermittently. ✔️

@jeremylenz
Copy link
Member

The React failure is unrelated

Copy link
Member

@jeremylenz jeremylenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well

thanks @nadjaheitmann !

Will merge once we get the React failures sorted.

@jeremylenz jeremylenz merged commit f14f58e into Katello:master Feb 14, 2024
12 of 15 checks passed
@nadjaheitmann nadjaheitmann deleted the os_family_for_content_packages_tab branch February 14, 2024 19:33
sbernhard pushed a commit to ATIX-AG/katello that referenced this pull request Feb 29, 2024
sbernhard pushed a commit to ATIX-AG/katello that referenced this pull request Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants