Fix query db in containerized envs - #22140
Conversation
Reviewer's GuideRefactors tests and host database helpers to use a new, install-method-aware query_db helper instead of manually invoking psql via shell, adding support for containerized Satellite (foremanctl/podman) deployments and slightly tightening some test assertions. Sequence diagram for query_db behavior by install methodsequenceDiagram
participant Caller
participant Host
participant _execute_db_query
participant SystemExecute as execute
Caller->>Host: query_db(query, db, output_format)
Host->>Host: [install_method is FOREMANCTL]
alt install_method is FOREMANCTL
Host->>Host: build base_cmd podman exec postgresql psql -U foreman -d db
else install_method is not FOREMANCTL
Host->>Host: build base_cmd sudo -u postgres psql -d db
end
Host->>_execute_db_query: _execute_db_query(cmd)
_execute_db_query->>SystemExecute: execute(cmd)
SystemExecute-->>_execute_db_query: result
alt result.status != 0
_execute_db_query->>Caller: raise CLIReturnCodeError
else result.status == 0
_execute_db_query-->>Host: result
Host-->>Caller: formatted query result
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider moving
from robottelo.enums import InstallMethodto the module level instead of importing insidequery_db, to avoid repeated imports and make dependencies clearer. - The
podman exec postgresql psql -U foreman -d {db}base command inquery_dbassumes a specific container name and user; if these differ across environments, you may want to derive them from configuration orinstall_methodmetadata rather than hard-coding.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider moving `from robottelo.enums import InstallMethod` to the module level instead of importing inside `query_db`, to avoid repeated imports and make dependencies clearer.
- The `podman exec postgresql psql -U foreman -d {db}` base command in `query_db` assumes a specific container name and user; if these differ across environments, you may want to derive them from configuration or `install_method` metadata rather than hard-coding.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
|
PRT Result |
|
Could you please add related Jira link into description? |
|
|
PRT Result |
|
|
PRT Result |
vsedmik
left a comment
There was a problem hiding this comment.
Looks good to me, PRT passed, pending proposal from Gaurav.
LadislavVasina1
left a comment
There was a problem hiding this comment.
ACK, pending comments
3808d51 to
9223dcc
Compare
|
|
PRT Result |
|
|
PRT Result |
|
|
PRT Result |
|
Taking look at failures now. Wasnt aware that was a |
|
@Gauravtalreja1 Can you also take a look at the failure they seem unrelated to the |
Problem Statement
fix the
query_dbfunction to support, containerized Satellite env where psql runs in separate container.SAT-47278
Solution
Update
_execute_db_queryfunction to check install method. This will change the base cmd that is ran when running sql queries.PRT test Cases example
Summary by Sourcery
Update database query helper to support different Satellite installation methods and refactor tests to use it consistently instead of ad‑hoc psql shell commands.
Bug Fixes:
Enhancements:
Tests: