forked from Katello/katello
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #29554 - Katello Applicability host processing queue (Katello#8717
- Loading branch information
Showing
13 changed files
with
161 additions
and
56 deletions.
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,4 @@ | ||
module Katello | ||
class HostQueueElement < Katello::Model | ||
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,21 @@ | ||
module Katello | ||
class ApplicableHostQueue | ||
def self.batch_size | ||
::Setting::Content.find_by(name: "applicability_batch_size").value | ||
end | ||
|
||
def self.queue_depth | ||
::Katello::HostQueueElement.all.size | ||
end | ||
|
||
def self.push_host(host_id) | ||
HostQueueElement.create!({ host_id: host_id }) | ||
end | ||
|
||
def self.pop_hosts(amount = self.batch_size) | ||
queue = HostQueueElement.group(:host_id).select("MIN(created_at) as created_at, host_id").limit(amount) | ||
HostQueueElement.where(host_id: queue.map(&:host_id)).delete_all | ||
queue | ||
end | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
db/migrate/20200511204005_create_katello_host_queue_elements.rb
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,12 @@ | ||
class CreateKatelloHostQueueElements < ActiveRecord::Migration[6.0] | ||
def up | ||
create_table :katello_host_queue_elements do |t| | ||
t.integer :host_id | ||
t.column :created_at, :datetime | ||
end | ||
end | ||
|
||
def down | ||
drop_table :katello_host_queue_elements | ||
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
36 changes: 0 additions & 36 deletions
36
test/actions/katello/applicability/generate_host_list_applicability_test.rb
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
test/actions/katello/applicability/repository_regenerate_applicability_test.rb
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,34 @@ | ||
require 'katello_test_helper' | ||
|
||
module ::Actions::Katello::Applicability::Repository | ||
class RepositoryRegenerateApplicabilityTest < ActiveSupport::TestCase | ||
include Dynflow::Testing | ||
include Support::Actions::Fixtures | ||
include FactoryBot::Syntax::Methods | ||
|
||
before :all do | ||
User.current = users(:admin) | ||
@host = FactoryBot.build(:host, :with_content, :with_subscription, :content_view => katello_content_views(:library_dev_view), | ||
:lifecycle_environment => katello_environments(:library)) | ||
@host.save! | ||
@repo = katello_repositories(:fedora_17_x86_64_duplicate) | ||
SETTINGS[:katello][:katello_applicability] = true | ||
end | ||
|
||
after :all do | ||
SETTINGS[:katello][:katello_applicability] = false | ||
end | ||
|
||
describe 'Repository Regenerate Applicability using Katello Applicability' do | ||
let(:action_class) { ::Actions::Katello::Applicability::Repository::Regenerate } | ||
|
||
it 'runs' do | ||
Katello::Repository.any_instance.stubs(:hosts_with_applicability).returns([@host]) | ||
Katello::ApplicableHostQueue.expects(:push_host).with(@host.id) | ||
Katello::EventQueue.expects(:push_event).with(::Katello::Events::GenerateHostApplicability::EVENT_TYPE, 0) | ||
|
||
ForemanTasks.sync_task(action_class, :repo_id => @repo.id) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require 'katello_test_helper' | ||
|
||
module Katello | ||
class ApplicableHostQueueTest < ActiveSupport::TestCase | ||
def setup | ||
::Setting::Content.find_by(name: "applicability_batch_size").update(value: 50) | ||
end | ||
|
||
def test_pop_nothing | ||
assert_equal [], ApplicableHostQueue.pop_hosts | ||
end | ||
|
||
def test_pop_1_host | ||
ApplicableHostQueue.push_host(999) | ||
popped_hosts = ApplicableHostQueue.pop_hosts | ||
|
||
assert_equal [999], popped_hosts.map(&:host_id).sort | ||
end | ||
|
||
def test_pop_5_hosts | ||
5.times { |i| ApplicableHostQueue.push_host(i) } | ||
popped_hosts = ApplicableHostQueue.pop_hosts | ||
|
||
assert_equal [0, 1, 2, 3, 4], popped_hosts.map(&:host_id).sort | ||
end | ||
|
||
def test_pop_batch_size_only | ||
::Setting::Content.find_by(name: "applicability_batch_size").update(value: 3) | ||
5.times { |i| ApplicableHostQueue.push_host(i) } | ||
popped_hosts = ApplicableHostQueue.pop_hosts | ||
|
||
assert_equal 3, popped_hosts.to_a.size | ||
end | ||
|
||
def test_pop_duplicate_hosts | ||
5.times { |i| ApplicableHostQueue.push_host(i) } | ||
5.times { |i| ApplicableHostQueue.push_host(i) } | ||
popped_hosts = ApplicableHostQueue.pop_hosts | ||
|
||
assert_equal [0, 1, 2, 3, 4], popped_hosts.map(&:host_id).sort | ||
end | ||
|
||
def test_queue_depth | ||
3.times { |i| ApplicableHostQueue.push_host(i) } | ||
|
||
assert_equal 3, ApplicableHostQueue.queue_depth | ||
end | ||
end | ||
end |