foremanctl deploy --certificate-cname - #21309
Conversation
Reviewer's GuideAdds an integration test that validates File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
|
||
|
|
||
| @pytest.mark.parametrize('module_sat_ready_rhel', ['default'], indirect=True) | ||
| def test_foremanctl_deploy_certificate_cname(module_sat_ready_rhel): |
There was a problem hiding this comment.
Could this test live in foremanctl ?
There was a problem hiding this comment.
Yop, I'm planning to add some more coverage there. Here, I'm planning to extend the workflow to cover the whole e2e test:
- Install satellite with cname
- Add another cname
--reset-cname
In the foremanctl repo, I'll test it as three separate cases.
ed4b864 to
c6cbe94
Compare
|
trigger: test-robottelo |
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- The test modifies /etc/hosts but never restores it, which can leak state into subsequent tests; consider using a context manager or fixture to add and then remove the CNAME entry after the test completes.
- The hardcoded certificate paths (/root/certificates/...) and curl URL path (/users/login) might change across environments; if possible, reuse existing helpers or configuration constants to avoid brittle assumptions in this integration test.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The test modifies /etc/hosts but never restores it, which can leak state into subsequent tests; consider using a context manager or fixture to add and then remove the CNAME entry after the test completes.
- The hardcoded certificate paths (/root/certificates/...) and curl URL path (/users/login) might change across environments; if possible, reuse existing helpers or configuration constants to avoid brittle assumptions in this integration test.
## Individual Comments
### Comment 1
<location path="tests/foreman/installer/test_install_foremanctl.py" line_range="192-201" />
<code_context>
+ satellite = module_sat_ready_rhel
+ cname = f'cname.{satellite.hostname}'
+
+ result = satellite.execute(
+ f'foremanctl deploy --certificate-cname {cname}',
+ timeout='10m',
+ )
+ assert result.status == 0, (
+ f'foremanctl deploy with --certificate-cname failed:\n{result.stderr}'
+ )
+
+ parameters_file = satellite.load_remote_yaml_file(FOREMANCTL_PARAMETERS_FILE)
+ assert cname in parameters_file.certificates_cnames
+
+ result = satellite.execute(
+ 'openssl x509 -in /root/certificates/certs/$(hostname -f).crt -noout -ext subjectAltName'
+ )
+ assert result.status == 0, f'Failed to read server certificate:\n{result.stderr}'
+ assert f'DNS:{cname}' in result.stdout, (
+ f'CNAME {cname} not found in server certificate SANs:\n{result.stdout}'
+ )
</code_context>
<issue_to_address>
**suggestion (testing):** Consider also asserting that the SAN output contains all mandatory names, not just the new CNAME.
Right now the test only asserts `DNS:{cname}` is present. To also guard against regressions where existing SAN entries are dropped (e.g. the original FQDN), consider asserting that the canonical hostname (e.g. `DNS:$(hostname -f)`) is still present in the SAN output as well.
Suggested implementation:
```python
3. The server certificate SAN includes DNS:<cname> and the canonical hostname (DNS:<hostname -f>)
```
```python
result = satellite.execute(
'openssl x509 -in /root/certificates/certs/$(hostname -f).crt -noout -ext subjectAltName'
)
assert result.status == 0, f'Failed to read server certificate:\n{result.stderr}'
san_output = result.stdout
assert f'DNS:{cname}' in san_output, (
f'CNAME {cname} not found in server certificate SANs:\n{san_output}'
)
assert f'DNS:{satellite.hostname}' in san_output, (
f'Canonical hostname {satellite.hostname} not found in server certificate SANs:\n{san_output}'
)
```
</issue_to_address>
### Comment 2
<location path="tests/foreman/installer/test_install_foremanctl.py" line_range="207-220" />
<code_context>
+ f'CNAME {cname} not found in server certificate SANs:\n{result.stdout}'
+ )
+
+ satellite.execute(
+ f'grep -q {cname} /etc/hosts '
+ f'|| echo "$(hostname -I | awk \'{{print $1}}\') {cname}" >> /etc/hosts'
</code_context>
<issue_to_address>
**suggestion (testing):** Avoid leaving persistent `/etc/hosts` modifications that may affect subsequent tests.
This test appends an entry to `/etc/hosts` without ever removing it, making the environment stateful across runs and potentially affecting other tests that depend on name resolution. Please either clean up the entry after the test (e.g., via `try/finally` or a fixture) or use a more isolated approach such as `curl --resolve` or a temporary hosts file. This will keep the test hermetic and avoid cross-test interference.
```suggestion
assert f'DNS:{cname}' in result.stdout, (
f'CNAME {cname} not found in server certificate SANs:\n{result.stdout}'
)
result = satellite.execute(
f'ip=$(hostname -I | awk \'{{print $1}}\'); '
f'curl -s -o /dev/null -w "%{{http_code}}" '
f'--resolve "{cname}:443:$ip" '
f'--cacert /root/certificates/certs/ca.crt '
f'https://{cname}/users/login'
)
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
PRT Result |
c6cbe94 to
bdb6de9
Compare
|
trigger: test-robottelo |
|
PRT Result |
Co-authored-by: Evgeni Golov <evgeni@golov.de>
fe77274 to
ae6eb3b
Compare
|
trigger: test-robottelo |
|
PRT Result |
* foremanctl deploy --certificate-cname --------- Co-authored-by: Evgeni Golov <evgeni@golov.de>
Problem Statement
Test for foremanctl deploy --certificate-cname
Solution
write the test 🤔 ?
Related Issues
theforeman/foremanctl#441
Summary by Sourcery
Tests: