-
Notifications
You must be signed in to change notification settings - Fork 23
RHELMISC 34338: Add client role support (DUT/SUT/Support/Master/Stress) #991
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
Open
elizashurov
wants to merge
3
commits into
HCK-CI:master
Choose a base branch
from
elizashurov:RHELMISC-34338
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ class HCKTest | |
| extend T::Sig | ||
| include Helper | ||
|
|
||
| attr_reader :config, :drivers, :platform, :extensions | ||
| attr_reader :config, :drivers, :platform, :extensions, :platform_clients | ||
|
|
||
| PLATFORMS_JSON_DIR = 'lib/engines/hcktest/platforms' | ||
| CONFIG_JSON = 'lib/engines/hcktest/hcktest.json' | ||
|
|
@@ -18,6 +18,16 @@ class HCKTest | |
| ENGINE_MODE = 'test' | ||
| AUTOHCK_RETRIES = 5 | ||
|
|
||
| # Maps platform roles to the HLK machine-set role names used in QueueTest. | ||
| HLK_ROLE_MAP = { | ||
| Models::ClientRole::Support => 'Support', | ||
| Models::ClientRole::Master => 'MC', | ||
| Models::ClientRole::Stress => 'SC' | ||
| }.freeze | ||
|
|
||
| # Roles that are the primary test target | ||
| PRIMARY_ROLES = [Models::ClientRole::Dut, Models::ClientRole::Sut].freeze | ||
|
|
||
| def initialize(project) | ||
| @project = project | ||
| @logger = project.logger | ||
|
|
@@ -28,6 +38,12 @@ def initialize(project) | |
| @extensions = find_extensions | ||
| prepare_extra_sw | ||
| validate_paths unless @driver_path.nil? | ||
| @platform_clients = build_platform_clients | ||
| end | ||
|
|
||
| sig { returns(PlatformClients) } | ||
| def build_platform_clients | ||
| PlatformClients.new(@project.engine_platform, logger: @logger) | ||
| end | ||
|
|
||
| def test_steps | ||
|
|
@@ -126,24 +142,31 @@ def find_extensions | |
| end | ||
|
|
||
| def target | ||
| if @project.options.test.svvp | ||
| { | ||
| 'name' => @clients.values[0].name, | ||
| 'type' => @svvp_info.type, | ||
| 'select_test_names' => @svvp_info.select_test_names, | ||
| 'sequence_test_names' => @svvp_info.sequence_test_names, | ||
| 'reject_test_names' => @svvp_info.reject_test_names | ||
| } | ||
| else | ||
| driver = drivers.first | ||
| { | ||
| 'name' => driver.name, | ||
| 'type' => driver.type, | ||
| 'select_test_names' => driver.select_test_names, | ||
| 'sequence_test_names' => [], | ||
| 'reject_test_names' => driver.reject_test_names | ||
| } | ||
| end | ||
| @project.options.test.svvp ? svvp_target : whql_target | ||
| end | ||
|
|
||
| def svvp_target | ||
| primary_entry = @platform_clients.primary_entry | ||
| raise InvalidConfigFile, 'SVVP platform is missing a sut client' if primary_entry.nil? | ||
|
|
||
| { | ||
| 'name' => primary_entry['name'], | ||
| 'type' => @svvp_info.type, | ||
| 'select_test_names' => @svvp_info.select_test_names, | ||
| 'sequence_test_names' => @svvp_info.sequence_test_names, | ||
| 'reject_test_names' => @svvp_info.reject_test_names | ||
| } | ||
| end | ||
|
|
||
| def whql_target | ||
| driver = drivers.first | ||
| { | ||
| 'name' => driver.name, | ||
| 'type' => driver.type, | ||
| 'select_test_names' => driver.select_test_names, | ||
| 'sequence_test_names' => [], | ||
| 'reject_test_names' => driver.reject_test_names | ||
| } | ||
| end | ||
|
|
||
| sig { params(logger: MultiLogger, options: CLI).returns(Models::HLKPlatform) } | ||
|
|
@@ -168,16 +191,17 @@ def run_studio(scope, run_opts = {}) | |
|
|
||
| def run_clients(scope, run_opts = {}) | ||
| @clients = {} | ||
| @project.engine_platform.clients.each_value do |client| | ||
| @clients[client.name] = @project.setup_manager.run_hck_client(scope, @studio, client.name, run_opts) | ||
| @platform_clients.entries.each { |client| start_client(scope, client, run_opts) } | ||
| raise InvalidConfigFile, 'Clients configuration for this platform is incorrect' if @clients.empty? | ||
| end | ||
|
|
||
| break if @project.options.test.svvp | ||
| break unless @drivers.any?(&:support) | ||
| end | ||
| return unless @clients.empty? | ||
| def start_client(scope, client, run_opts) | ||
| name = client['name'] | ||
| role = client['role'] | ||
| return if !PRIMARY_ROLES.include?(role) && [email protected] && @drivers.none?(&:support) | ||
|
|
||
| raise InvalidConfigFile, 'Clients configuration for \ | ||
| this platform is incorrect' | ||
| @logger.info("Starting client #{name} (role: #{role})") | ||
| @clients[name] = @project.setup_manager.run_hck_client(scope, @studio, name, run_opts) | ||
| end | ||
|
|
||
| def post_start_commands | ||
|
|
@@ -296,14 +320,16 @@ def pause_run | |
| end | ||
|
|
||
| def prepare_tests | ||
| client, support = @clients.values | ||
| client = primary_client | ||
| aux_clients = aux_clients_by_hlk_role | ||
|
|
||
| @tests = Tests.new(client, support, @project, client.target, @studio.tools) | ||
| @tests = Tests.new(client, @project, client.target, @studio.tools, aux_clients: aux_clients) | ||
|
|
||
| if client.target.nil? | ||
| raise EngineError, 'HLK test target is not defined' unless @project.options.test.manual | ||
|
|
||
| @project.logger.info('HLK test target is not defined, allow in manual mode') | ||
| return | ||
| end | ||
|
|
||
| @test_list = @tests.update_tests(log: true) | ||
|
|
@@ -434,5 +460,29 @@ def run | |
| def result_uploader_needed? | ||
| true | ||
| end | ||
|
|
||
| private | ||
|
|
||
| sig { returns(T::Hash[String, T::Array[HCKClient]]) } | ||
| def aux_clients_by_hlk_role | ||
| @platform_clients.entries | ||
| .reject { |e| PRIMARY_ROLES.include?(e['role']) } | ||
| .each_with_object({}) do |e, result| | ||
| hlk_role = HLK_ROLE_MAP[e['role']] | ||
| client = @clients[e['name']] | ||
| (result[hlk_role] ||= []) << client if hlk_role && client | ||
| end | ||
| end | ||
|
|
||
| sig { returns(HCKClient) } | ||
| def primary_client | ||
| entry = @platform_clients.primary_entry | ||
| raise InvalidConfigFile, 'Platform is missing a primary client (sut or dut)' if entry.nil? | ||
|
|
||
| client = @clients[entry['name']] | ||
| raise InvalidConfigFile, "Client #{entry['name']} was not started" if client.nil? | ||
|
|
||
| client | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or 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,117 @@ | ||
| # typed: true | ||
|
elizashurov marked this conversation as resolved.
|
||
| # frozen_string_literal: true | ||
|
|
||
| # AutoHCK module | ||
| module AutoHCK | ||
| # Reads client roles from a platform JSON and exposes helpers used by the engine. | ||
| class PlatformClients | ||
| extend T::Sig | ||
|
|
||
| ClientEntry = T.type_alias { T::Hash[String, T.untyped] } | ||
|
|
||
| # Allowed role sets for WHQL platforms. | ||
| WHQL_CONFIGURATIONS = [ | ||
| [Models::ClientRole::Dut], | ||
| [Models::ClientRole::Dut, Models::ClientRole::Support] | ||
| ].freeze | ||
|
|
||
| # Minimum roles required for SVVP. Extra stress clients are fine. | ||
| SVVP_REQUIRED_ROLES = [Models::ClientRole::Sut, Models::ClientRole::Master].freeze | ||
|
|
||
| # MC and SC join the pool but skip driver install and HLK target registration. | ||
| POOL_ONLY_ROLES = [Models::ClientRole::Master, Models::ClientRole::Stress].freeze | ||
|
|
||
| sig do | ||
| params( | ||
| platform: Models::HLKPlatform, | ||
| logger: T.any(MultiLogger, ::Logger) | ||
| ).void | ||
| end | ||
| def initialize(platform, logger:) | ||
| @logger = logger | ||
| @entries = build_entries(platform.clients) | ||
| validate! | ||
| end | ||
|
|
||
| # All clients in platform order. | ||
| attr_reader :entries | ||
|
|
||
| # Role for a given machine name. | ||
| sig { params(name: String).returns(Models::ClientRole) } | ||
| def role_for(name) | ||
| entry = @entries.find { |e| e['name'] == name } | ||
| raise InvalidConfigFile, "Unknown client #{name} in platform configuration" if entry.nil? | ||
|
|
||
| entry.fetch('role') | ||
| end | ||
|
|
||
| # First entry whose role matches (nil if not found). | ||
| sig { params(role: Models::ClientRole).returns(T.nilable(ClientEntry)) } | ||
| def entry_for_role(role) | ||
| @entries.find { |e| e['role'] == role } | ||
| end | ||
|
|
||
| # The primary client entry — SUT for SVVP, DUT for WHQL. | ||
| sig { returns(T.nilable(ClientEntry)) } | ||
| def primary_entry | ||
| entry_for_role(Models::ClientRole::Sut) || entry_for_role(Models::ClientRole::Dut) | ||
| end | ||
|
|
||
| sig { params(name: String).returns(T::Boolean) } | ||
| def pool_only?(name) | ||
| POOL_ONLY_ROLES.include?(role_for(name)) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| sig { params(clients: T::Hash[String, Models::HLKClient]).returns(T::Array[ClientEntry]) } | ||
| def build_entries(clients) | ||
| clients.map do |key, client| | ||
| client_hash = client.serialize | ||
| role = resolve_role(client_hash) | ||
| client_hash.merge('role' => role, '_key' => key) | ||
| end | ||
| end | ||
|
|
||
| sig { params(client: T::Hash[String, T.untyped]).returns(Models::ClientRole) } | ||
| def resolve_role(client) | ||
| raw_role = client['role'] | ||
|
|
||
| if raw_role.nil? || raw_role.to_s.strip.empty? | ||
| raise InvalidConfigFile, | ||
| "Client '#{client['name']}' is missing a 'role' field in the platform JSON." | ||
| end | ||
|
|
||
| Models::ClientRole.deserialize(raw_role.strip.downcase) | ||
| rescue KeyError | ||
| raise InvalidConfigFile, "Client '#{client['name']}' has unknown role #{raw_role.inspect}. " \ | ||
| "Expected one of: #{Models::ClientRole.values.join(', ')}" | ||
| end | ||
|
elizashurov marked this conversation as resolved.
|
||
|
|
||
| sig { void } | ||
| def validate! | ||
| roles = @entries.map { |e| e.fetch('role') } | ||
| return if valid_whql_configuration?(roles) || valid_svvp_configuration?(roles) | ||
|
|
||
| raise InvalidConfigFile, invalid_roles_message(roles) | ||
| end | ||
|
|
||
| sig { params(roles: T::Array[Models::ClientRole]).returns(T::Boolean) } | ||
| def valid_whql_configuration?(roles) | ||
| WHQL_CONFIGURATIONS.any? { |config| roles.sort_by(&:to_s) == config.sort_by(&:to_s) } | ||
| end | ||
|
|
||
| sig { params(roles: T::Array[Models::ClientRole]).returns(T::Boolean) } | ||
| def valid_svvp_configuration?(roles) | ||
| SVVP_REQUIRED_ROLES.all? { |role| roles.include?(role) } | ||
| end | ||
|
|
||
| sig { params(roles: T::Array[Models::ClientRole]).returns(String) } | ||
| def invalid_roles_message(roles) | ||
| role_list = roles.join(', ') | ||
| whql_list = WHQL_CONFIGURATIONS.map { |c| c.join(', ') }.join(' | ') | ||
| "Invalid platform client roles [#{role_list}]. " \ | ||
| "Expected WHQL (#{whql_list}) or SVVP (must include: #{SVVP_REQUIRED_ROLES.join(', ')})." | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| "clients": { | ||
| "c1": { | ||
| "name": "C1", | ||
| "role": "dut", | ||
| "winrm_port": 4002 | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| "clients": { | ||
| "c1": { | ||
| "name": "CL1", | ||
| "role": "dut", | ||
| "winrm_port": 4002 | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.