-
Notifications
You must be signed in to change notification settings - Fork 127
container registry operations with DNS alias #20012
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
vijaysawant
wants to merge
1
commit into
SatelliteQE:master
Choose a base branch
from
vijaysawant:iamge_pull_using_dns_alias
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
container registry operations with DNS alias #20012
vijaysawant
wants to merge
1
commit into
SatelliteQE:master
from
vijaysawant:iamge_pull_using_dns_alias
Conversation
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
|
PRT Result
|
4b09009
to
bdd86c6
Compare
|
PRT Result
|
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.
Hey there - I've reviewed your changes - here's some feedback:
- You defined cleanup_org_and_product() but never added it as a request finalizer, so the created organization and product won’t be cleaned up after the test.
- Backing up and restoring /etc/hosts and settings.yaml by echoing their full contents is brittle—consider using a temp file or atomic copy/restore to preserve permissions and formatting.
- The test uses settings.server.admin_username and settings.server.admin_password without importing or injecting a settings fixture—please ensure the settings object is properly provided.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- You defined cleanup_org_and_product() but never added it as a request finalizer, so the created organization and product won’t be cleaned up after the test.
- Backing up and restoring /etc/hosts and settings.yaml by echoing their full contents is brittle—consider using a temp file or atomic copy/restore to preserve permissions and formatting.
- The test uses settings.server.admin_username and settings.server.admin_password without importing or injecting a settings fixture—please ensure the settings object is properly provided.
## Individual Comments
### Comment 1
<location> `tests/foreman/cli/test_container_management.py:609-612` </location>
<code_context>
+
+ # Step 1: Register Satellite with CDN (already done in setup)
+
+ # Step 2: Add DNS alias to /etc/hosts
+ original_hosts = target_sat.execute('cat /etc/hosts').stdout
+ hosts_entry = f"{target_sat.ip_addr} {alias_hostname}"
+
+ def add_hosts_entry():
+ result = target_sat.execute(f'echo "{hosts_entry}" >> /etc/hosts')
+ return result.status == 0
+
+ assert add_hosts_entry()
+
+ @request.addfinalizer
</code_context>
<issue_to_address>
**suggestion (testing):** Test does not verify /etc/hosts entry removal side effects.
Please add assertions to verify that, after restoring /etc/hosts, the alias is no longer resolvable and registry operations using the alias fail. This ensures proper cleanup and environment restoration.
```suggestion
@request.addfinalizer
def restore_hosts():
# Restore original /etc/hosts
target_sat.execute(f'echo "{original_hosts}" > /etc/hosts')
# Assert alias is no longer resolvable
alias_resolve = target_sat.execute(f'getent hosts {alias_hostname}')
assert alias_resolve.status != 0, f"Alias {alias_hostname} should not be resolvable after /etc/hosts restore"
# Attempt registry operation using alias and assert failure
registry_check = target_sat.execute(f'curl -sSf http://{alias_hostname}:5000/v2/_catalog')
assert registry_check.status != 0, f"Registry operation using alias {alias_hostname} should fail after /etc/hosts restore"
```
</issue_to_address>
### Comment 2
<location> `tests/foreman/cli/test_container_management.py:627-628` </location>
<code_context>
+ # Restore original /etc/hosts
+ target_sat.execute(f'echo "{original_hosts}" > /etc/hosts')
+
+ # Step 3: Configure foreman's settings.yaml to allow the DNS alias
+ settings_yaml_path = FOREMAN_CONFIG_SETTINGS_YAML
+ original_settings = target_sat.execute(f'cat {settings_yaml_path}').stdout
+
+ # Add host configuration to settings.yaml
+ host_config = f":hosts:\n - {alias_hostname}"
+
+ def update_settings():
+ result = target_sat.execute(f'echo "{host_config}" >> {settings_yaml_path}')
+ return result.status == 0
+
+ assert update_settings()
+
+ # Restart foreman service to apply settings
</code_context>
<issue_to_address>
**suggestion (testing):** No assertion for foreman service restart success.
Add an assertion after restarting the foreman service to confirm it is running and healthy before continuing with registry operations. This ensures configuration changes do not cause service startup failures.
```suggestion
# Restart foreman service to apply settings
restart_result = target_sat.execute('foreman-maintain service restart')
assert restart_result.status == 0, "Foreman service failed to restart"
# Confirm foreman service is running and healthy
health_result = target_sat.execute('systemctl is-active foreman')
assert health_result.stdout.strip() == "active", "Foreman service is not active after restart"
```
</issue_to_address>
### Comment 3
<location> `tests/foreman/cli/test_container_management.py:668-675` </location>
<code_context>
+ def logout():
+ target_sat.execute(f'podman logout {alias_hostname}')
+
+ # Step 6: Run podman push with the alias hostname using image ID
+ container_uri = f"{alias_hostname}/{org_label}/{product_label}/{repo_name}"
+ push_result = target_sat.execute(
+ f'podman push {busybox_image_id} {container_uri} --tls-verify=false'
+ )
+ assert push_result.status == 0
+
+ # Step 7: Run podman pull with the alias hostname
</code_context>
<issue_to_address>
**suggestion (testing):** No explicit check for UnsafeRedirectError absence.
Add assertions to verify that 'UnsafeRedirectError' is not present in the output of push and pull commands, in addition to checking exit status.
```suggestion
push_result = target_sat.execute(
f'podman push {busybox_image_id} {container_uri} --tls-verify=false'
)
assert push_result.status == 0
assert "UnsafeRedirectError" not in push_result.stdout
assert "UnsafeRedirectError" not in push_result.stderr
# Step 7: Run podman pull with the alias hostname
pull_result = target_sat.execute(f'podman pull {container_uri} --tls-verify=false')
assert pull_result.status == 0
assert "UnsafeRedirectError" not in pull_result.stdout
assert "UnsafeRedirectError" not in pull_result.stderr
```
</issue_to_address>
### Comment 4
<location> `tests/foreman/cli/test_container_management.py:645-648` </location>
<code_context>
</code_context>
<issue_to_address>
**issue (code-quality):** Avoid loops in tests. ([`no-loop-in-tests`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/Python/Default-Rules/no-loop-in-tests))
<details><summary>Explanation</summary>Avoid complex code, like loops, in test functions.
Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:
* loops
* conditionals
Some ways to fix this:
* Use parametrized tests to get rid of the loop.
* Move the complex logic into helpers.
* Move the complex part into pytest fixtures.
> Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.
Software Engineering at Google / [Don't Put Logic in Tests](https://abseil.io/resources/swe-book/html/ch12.html#donapostrophet_put_logic_in_tests)
</details>
</issue_to_address>
### Comment 5
<location> `tests/foreman/cli/test_container_management.py:646-648` </location>
<code_context>
</code_context>
<issue_to_address>
**issue (code-quality):** Avoid conditionals in tests. ([`no-conditionals-in-tests`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/Python/Default-Rules/no-conditionals-in-tests))
<details><summary>Explanation</summary>Avoid complex code, like conditionals, in test functions.
Google's software engineering guidelines says:
"Clear tests are trivially correct upon inspection"
To reach that avoid complex code in tests:
* loops
* conditionals
Some ways to fix this:
* Use parametrized tests to get rid of the loop.
* Move the complex logic into helpers.
* Move the complex part into pytest fixtures.
> Complexity is most often introduced in the form of logic. Logic is defined via the imperative parts of programming languages such as operators, loops, and conditionals. When a piece of code contains logic, you need to do a bit of mental computation to determine its result instead of just reading it off of the screen. It doesn't take much logic to make a test more difficult to reason about.
Software Engineering at Google / [Don't Put Logic in Tests](https://abseil.io/resources/swe-book/html/ch12.html#donapostrophet_put_logic_in_tests)
</details>
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
6.17.z
6.18.z
Introduced in or relating directly to Satellite 6.18
AutoMerge_Cherry_Picked
The cherrypicked PRs of master PR would be automerged if all checks passing
CherryPick
PR needs CherryPick to previous branches
PRT-Passed
Indicates that latest PRT run is passed for the PR
Stream
Introduced in or relating directly to Satellite Stream/Master
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.
Problem Statement
Test container registry operations with DNS alias, Automation coverage for SAT-36036.
Solution
Add a DNS alias to the environment by modifying /etc/hosts, Configure foreman's settings.yaml to allow the DNS alias and try podman push & pull commands
Related Issues
PRT test Cases example