-
Notifications
You must be signed in to change notification settings - Fork 296
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 #35713 - Host details tab for Debian packages #10744
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Katello | ||
class HostDebPresenter < SimpleDelegator | ||
attr_accessor :installed_package, :upgradable_versions, :deb_id | ||
|
||
def initialize(installed_package, upgradable_versions, deb_id) | ||
@installed_package = installed_package | ||
@upgradable_versions = upgradable_versions | ||
@deb_id = deb_id | ||
super(@installed_package) | ||
end | ||
|
||
def self.with_latest(packages, host) | ||
upgradable_packages_map = ::Katello::Deb.installable_for_hosts([host]).select(:id, :name, :architecture, :version).order(version: :desc).group_by { |i| [i.name, i.architecture] } | ||
installed_packages_map = ::Katello::Deb.where(version: packages.map(&:version)).select(:id, :architecture, :name).group_by { |i| [i.name, i.architecture] } | ||
|
||
packages.map do |p| | ||
upgrades = upgradable_packages_map[[p.name, p.architecture]]&.pluck(:version) | ||
installed = installed_packages_map[[p.name, p.architecture]]&.first&.id | ||
HostDebPresenter.new(p, upgrades, installed) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require 'katello_test_helper' | ||
|
||
module Katello | ||
class HostDebPresenterTest < ActiveSupport::TestCase | ||
def setup | ||
@repo = katello_repositories(:debian_10_amd64_dev) | ||
@deb = katello_debs(:one_new) | ||
end | ||
|
||
let(:installed_deb) { Katello::InstalledDeb.create(name: 'uno', version: @deb.version, architecture: @deb.architecture) } | ||
let(:new_version) { '1.2' } | ||
|
||
test "deb with set upgradable_version" do | ||
presenter = HostDebPresenter.new(installed_deb, [new_version], @deb.id) | ||
|
||
assert_equal presenter.upgradable_versions, [new_version] | ||
assert_equal presenter.name, installed_deb.name | ||
assert_equal presenter.deb_id, @deb.id | ||
end | ||
|
||
test "with nil upgradable_version" do | ||
presenter = HostDebPresenter.new(installed_deb, nil, @deb.id) | ||
|
||
assert_nil presenter.upgradable_versions | ||
assert_equal presenter.name, installed_deb.name | ||
assert_equal presenter.deb_id, @deb.id | ||
end | ||
|
||
test "with_latest" do | ||
host = katello_content_facets(:content_facet_one).host | ||
host.content_facet.bound_repositories << @repo | ||
update = Katello::Deb.create(name: 'uno', pulp_id: 'uno-new-uuid', version: '1.2', architecture: 'amd64') | ||
::Katello::Deb.stubs(:installable_for_hosts).returns(Katello::Deb.where(id: update.id)) | ||
presenter = HostDebPresenter.with_latest([installed_deb], host).first | ||
|
||
assert_equal presenter.upgradable_versions, [new_version] | ||
assert_equal presenter.name, installed_deb.name | ||
assert_equal presenter.deb_id, @deb.id | ||
end | ||
|
||
test "with arch" do | ||
host = katello_content_facets(:content_facet_one).host | ||
host.content_facet.bound_repositories << @repo | ||
update = Katello::Deb.create(name: 'one', pulp_id: 'one-new-uuid', version: '1.2', architecture: 'noarch') | ||
::Katello::Deb.stubs(:installable_for_hosts).returns(Katello::Deb.where(id: update.id)) | ||
presenter = HostDebPresenter.with_latest([installed_deb], host).first | ||
|
||
assert_nil presenter.upgradable_versions | ||
assert_equal presenter.name, installed_deb.name | ||
assert_equal presenter.deb_id, @deb.id | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
webpack/components/extensions/HostDetails/Tabs/ContentTab/constants.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we could avoid adding a new method here, and just check
self.operatingsystem.family
withinpackage_names_for_job_template
instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeremylenz I think, it is a good idea and I have a added a commit on top of the actual commit for the host details page. However, rubocop does not like the changes. Not sure if I can make this any simpler.
[2024-01-05T09:07:35.947Z] Offenses:
[2024-01-05T09:07:35.947Z] /home/jenkins/workspace/katello-pr-test/app/models/katello/concerns/host_managed_extensions.rb:
541:7: C: Metrics/AbcSize: Assignment Branch Condition size for package_names_for_job_template is too high. [<9, 56, 21> 60.48/60]
[2024-01-05T09:07:35.947Z] def package_names_for_job_template(action:, search:, versions: nil) ...
[2024-01-05T09:07:35.947Z] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-01-05T09:07:35.947Z] /home/jenkins/workspace/katello-pr-test/app/models/katello/concerns/host_managed_extensions.rb:
541:7: C: Metrics/CyclomaticComplexity: Cyclomatic complexity for package_names_for_job_template is too high. [16/14]
[2024-01-05T09:07:35.947Z] def package_names_for_job_template(action:, search:, versions: nil) ...
[2024-01-05T09:07:35.947Z] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-01-05T09:07:35.947Z] /home/jenkins/workspace/katello-pr-test/app/models/katello/concerns/host_managed_extensions.rb:
541:7: C: Metrics/MethodLength: Method has too many lines. [34/30]
[2024-01-05T09:07:35.947Z] def package_names_for_job_template(action:, search:, versions: nil) ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nadjaheitmann Two options here. I would be fine with either one:
if / else
block to its own method. I would probably also do it as a case statement(case operatingsystem.family
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried option one, although I did not want to use a case statement. Seems safer to me to have Debian and everything else :)