Skip to content

Add auto_sign option to configure_puppet() - #22221

Draft
lpramuk wants to merge 1 commit into
SatelliteQE:masterfrom
lpramuk:add-puppet-autosign-entry
Draft

Add auto_sign option to configure_puppet()#22221
lpramuk wants to merge 1 commit into
SatelliteQE:masterfrom
lpramuk:add-puppet-autosign-entry

Conversation

@lpramuk

@lpramuk lpramuk commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds auto_sign=False parameter to configure_puppet() — when True, creates an autosign entry via nailgun_smart_proxy.add_autosign_entry() instead of manually signing the certificate
  • Switches proxy_host from plain Host to Capsule to get access to nailgun_smart_proxy
  • Adds error handling and logging on certificate sign failure (was previously silent)
  • Extends the docstring with missing parameter descriptions

Test plan

  • Verify configure_puppet() without auto_sign still manually signs the cert as before
  • Verify configure_puppet(auto_sign=True) creates an autosign entry instead

🤖 Generated with Claude Code

Summary by Sourcery

Add optional automatic Puppet certificate signing support when configuring Puppet on a host.

New Features:

  • Add an auto_sign option to configure_puppet to allow creating an autosign entry instead of manual certificate signing.

Enhancements:

  • Switch proxy host handling from a generic Host to a Capsule to leverage smart proxy capabilities and improve integration.
  • Add error handling and logging when Puppet certificate signing on the capsule fails.
  • Expand configure_puppet docstring to document existing and new parameters.

@lpramuk
lpramuk requested a review from a team as a code owner July 22, 2026 17:37
@sourcery-ai

sourcery-ai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds an auto_sign option to configure_puppet(), switches proxy host from Host to Capsule to leverage smart proxy APIs, and improves error handling and documentation around Puppet certificate signing.

Sequence diagram for configure_puppet auto_sign behavior

sequenceDiagram
    participant ContentHost
    participant Capsule
    participant NailgunSmartProxy

    ContentHost->>ContentHost: execute('/opt/puppetlabs/bin/puppet agent -t')
    ContentHost->>Capsule: Capsule(hostname, ipv6)
    alt auto_sign True
        ContentHost->>NailgunSmartProxy: add_autosign_entry(cert_name)
    else auto_sign False
        ContentHost->>Capsule: execute('puppetserver ca sign --certname cert_name')
        alt [sign command failed]
            ContentHost->>Capsule: execute('tail -2 /var/log/puppetlabs/puppetserver/puppetserver.log')
            ContentHost->>ContentHost: raise ContentHostError
        end
    end
    opt run_agent True
        ContentHost->>ContentHost: execute('/opt/puppetlabs/bin/puppet agent -t')
    end
Loading

File-Level Changes

Change Details Files
Add auto_sign option and behavior to configure_puppet() for Puppet certificate handling.
  • Extend configure_puppet() signature with an auto_sign parameter defaulting to False
  • Document run_agent, use_openvox, and auto_sign parameters in the configure_puppet() docstring
  • When auto_sign is True, create an autosign entry via the capsule smart proxy instead of manually signing the certificate
  • When auto_sign is False, retain manual puppetserver ca sign behavior
robottelo/hosts.py
Use Capsule instead of Host for the proxy to access smart proxy capabilities and improve error handling on certificate signing.
  • Change proxy_host construction from Host to Capsule to gain access to nailgun_smart_proxy
  • Capture the result of the puppetserver ca sign command and check its status
  • On certificate sign failure, tail the puppetserver log for context and raise ContentHostError with a descriptive message
robottelo/hosts.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues, and left some high level feedback:

  • When auto_sign=True, the agent run happens before the autosign entry is created, which may prevent the CSR from being auto-signed; consider adding the autosign entry before the first puppet agent invocation.
  • The new error path tails the puppetserver log but discards the content; consider including relevant log or command output in the ContentHostError message to aid debugging.
  • The Capsule substitution for Host changes the type of proxy_host; please confirm that all methods used here (execute, nailgun_smart_proxy) behave consistently and add error handling around add_autosign_entry similar to the manual sign path.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- When `auto_sign=True`, the agent run happens before the autosign entry is created, which may prevent the CSR from being auto-signed; consider adding the autosign entry before the first puppet agent invocation.
- The new error path tails the puppetserver log but discards the content; consider including relevant log or command output in the `ContentHostError` message to aid debugging.
- The `Capsule` substitution for `Host` changes the type of `proxy_host`; please confirm that all methods used here (`execute`, `nailgun_smart_proxy`) behave consistently and add error handling around `add_autosign_entry` similar to the manual sign path.

## Individual Comments

### Comment 1
<location path="robottelo/hosts.py" line_range="1070-1074" />
<code_context>
         # sat6 under the capsule --> certificates or on capsule via cli "puppetserver
         # ca list", so that we sign it.
         self.execute('/opt/puppetlabs/bin/puppet agent -t')
-        proxy_host = Host(hostname=proxy_hostname, ipv6=self.network_type == NetworkType.IPV6)
-        proxy_host.execute(f'puppetserver ca sign --certname {cert_name}')
+
+        proxy_host = Capsule(hostname=proxy_hostname, ipv6=self.network_type == NetworkType.IPV6)
+        if auto_sign:
+            proxy_host.nailgun_smart_proxy.add_autosign_entry(cert_name)
+        else:
+            result = proxy_host.execute(f'puppetserver ca sign --certname {cert_name}')
</code_context>
<issue_to_address>
**issue (bug_risk):** Auto-sign entry is added after the agent run, which may be too late to affect the current CSR.

Because the agent run (which submits the CSR) happens before the auto-sign entry is added, this run may still require manual signing and only future runs benefit from auto-sign. When `auto_sign` is enabled, add the auto-sign entry on the capsule before invoking `puppet agent -t` so the current CSR is signed automatically.
</issue_to_address>

### Comment 2
<location path="robottelo/hosts.py" line_range="1072-1075" />
<code_context>
+        if auto_sign:
+            proxy_host.nailgun_smart_proxy.add_autosign_entry(cert_name)
+        else:
+            result = proxy_host.execute(f'puppetserver ca sign --certname {cert_name}')
+            if result.status:
+                proxy_host.execute('tail -2 /var/log/puppetlabs/puppetserver/puppetserver.log')
+                raise ContentHostError(
+                    f'Failed to sign the puppet certificate on the capsule {proxy_hostname}'
+                )

</code_context>
<issue_to_address>
**suggestion:** Error handling for certificate signing could expose more context from the failing command.

Right now the raised `ContentHostError` only reports the capsule hostname. Consider including `result.stderr` (and/or `stdout`) in the exception message so callers can see the underlying `puppetserver ca sign` failure reason without having to check external logs, which will simplify debugging in automated runs.

```suggestion
        proxy_host = Capsule(hostname=proxy_hostname, ipv6=self.network_type == NetworkType.IPV6)
        if auto_sign:
            proxy_host.nailgun_smart_proxy.add_autosign_entry(cert_name)
        else:
            result = proxy_host.execute(f'puppetserver ca sign --certname {cert_name}')
            if result.status:
                proxy_host.execute('tail -2 /var/log/puppetlabs/puppetserver/puppetserver.log')
                raise ContentHostError(
                    f'Failed to sign the puppet certificate on the capsule {proxy_hostname}. '
                    f'stderr: {result.stderr!r}, stdout: {result.stdout!r}'
                )
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread robottelo/hosts.py
Comment on lines 1070 to +1074
self.execute('/opt/puppetlabs/bin/puppet agent -t')
proxy_host = Host(hostname=proxy_hostname, ipv6=self.network_type == NetworkType.IPV6)
proxy_host.execute(f'puppetserver ca sign --certname {cert_name}')

proxy_host = Capsule(hostname=proxy_hostname, ipv6=self.network_type == NetworkType.IPV6)
if auto_sign:
proxy_host.nailgun_smart_proxy.add_autosign_entry(cert_name)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Auto-sign entry is added after the agent run, which may be too late to affect the current CSR.

Because the agent run (which submits the CSR) happens before the auto-sign entry is added, this run may still require manual signing and only future runs benefit from auto-sign. When auto_sign is enabled, add the auto-sign entry on the capsule before invoking puppet agent -t so the current CSR is signed automatically.

Comment thread robottelo/hosts.py
Comment on lines +1072 to +1075
proxy_host = Capsule(hostname=proxy_hostname, ipv6=self.network_type == NetworkType.IPV6)
if auto_sign:
proxy_host.nailgun_smart_proxy.add_autosign_entry(cert_name)
else:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Error handling for certificate signing could expose more context from the failing command.

Right now the raised ContentHostError only reports the capsule hostname. Consider including result.stderr (and/or stdout) in the exception message so callers can see the underlying puppetserver ca sign failure reason without having to check external logs, which will simplify debugging in automated runs.

Suggested change
proxy_host = Capsule(hostname=proxy_hostname, ipv6=self.network_type == NetworkType.IPV6)
if auto_sign:
proxy_host.nailgun_smart_proxy.add_autosign_entry(cert_name)
else:
proxy_host = Capsule(hostname=proxy_hostname, ipv6=self.network_type == NetworkType.IPV6)
if auto_sign:
proxy_host.nailgun_smart_proxy.add_autosign_entry(cert_name)
else:
result = proxy_host.execute(f'puppetserver ca sign --certname {cert_name}')
if result.status:
proxy_host.execute('tail -2 /var/log/puppetlabs/puppetserver/puppetserver.log')
raise ContentHostError(
f'Failed to sign the puppet certificate on the capsule {proxy_hostname}. '
f'stderr: {result.stderr!r}, stdout: {result.stdout!r}'
)

@lpramuk
lpramuk marked this pull request as draft July 22, 2026 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant