Skip to content

Expose obsah_state_path variable#86

Merged
evgeni merged 1 commit into
theforeman:masterfrom
stejskalleos:ls/obsah_state_dir
Aug 21, 2025
Merged

Expose obsah_state_path variable#86
evgeni merged 1 commit into
theforeman:masterfrom
stejskalleos:ls/obsah_state_dir

Conversation

@stejskalleos
Copy link
Copy Markdown
Contributor

No description provided.

Comment thread obsah/__init__.py Outdated
@evgeni
Copy link
Copy Markdown
Member

evgeni commented Aug 21, 2025

CI is unhappy, as it asserts the set variables, and you changed that. But otherwise LGTM

@evgeni evgeni changed the title Expose obsah_state_dir variable Expose obsah_state_path variable Aug 21, 2025
@evgeni
Copy link
Copy Markdown
Member

evgeni commented Aug 21, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Aug 21, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@stejskalleos
Copy link
Copy Markdown
Contributor Author

🍏

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Aug 21, 2025

Walkthrough

The change introduces a new extra-vars entry obsah_state_path in generate_ansible_args within obsah/init.py, setting it from args.playbook.application_config.state_path(). This value is serialized into the Ansible command line JSON variables. Corresponding tests in tests/test_obsah.py are updated to expect an added -e '{"obsah_state_path": "/var/lib/obsah"}' across various CLI scenarios. No public interfaces or exported declarations are altered.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
obsah/__init__.py (1)

395-406: Confirm precedence: generated JSON -e overrides user-supplied -e.

Because extra_vars are appended first (Lines 397-399) and the JSON-serialized variables are appended after (Lines 405-406), any obsah_state_path provided via -e (key=value/JSON/@file) will be overridden by the generated value. This mirrors the current policy that CLI-exposed vars beat -e, but it’s worth double-checking that this is intentional for obsah_state_path too.

If you prefer user -e to be able to override, invert the order of assembling -e arguments:

-    for extra_var in getattr(args, 'extra_vars', []):
-        ansible_args.extend(["-e", extra_var])
-    ...
-    if variables:
-        ansible_args.extend(["-e", json.dumps(variables, sort_keys=True)])
+    if variables:
+        ansible_args.extend(["-e", json.dumps(variables, sort_keys=True)])
+    for extra_var in getattr(args, 'extra_vars', []):
+        ansible_args.extend(["-e", extra_var])

If the current precedence is desired, consider adding a short comment noting that the generated -e is appended last to intentionally win over user-supplied -e for consistent behavior.

tests/test_obsah.py (1)

93-118: Tests updated appropriately; consider hardening against env/formatting and asserting precedence.

Nice coverage of all CLI permutations with the added obsah_state_path expectation. To reduce flakiness and make intent explicit:

  • Control OBSAH_STATE in tests to avoid environment leakage (CI or dev shells setting OBSAH_STATE would break expectations).
  • Prefer asserting the parsed JSON content over exact string formatting to avoid brittleness if separators/sort options change.
  • Add a focused test that validates the intended precedence between user -e and the generated obsah_state_path.

Example additions (outside this hunk):

# Add at module scope to stabilize environment for all tests
import os, json
import pytest

@pytest.fixture(autouse=True)
def _ensure_default_state_path(monkeypatch):
    # Ensure tests don't inherit an external OBSAH_STATE
    monkeypatch.delenv('OBSAH_STATE', raising=False)

def test_state_path_from_env_overrides_default(playbooks_path, parser, monkeypatch):
    monkeypatch.setenv('OBSAH_STATE', '/tmp/obsah')
    args = parser.parse_args(['setup'])
    ansible_args = obsah.generate_ansible_args('inventory.yml', args, parser.obsah_arguments)
    assert ansible_args[-2] == '-e'
    payload = json.loads(ansible_args[-1])
    assert payload['obsah_state_path'] == '/tmp/obsah'

def test_obsah_state_path_precedence_over_user_extra_vars(playbooks_path, parser):
    # User tries to override via -e, generated JSON should win with current ordering
    args = parser.parse_args(['setup', '-e', 'obsah_state_path=/should/not/win'])
    ansible_args = obsah.generate_ansible_args('inventory.yml', args, parser.obsah_arguments)
    # The last -e is the generated JSON; verify its value prevails
    assert ansible_args[-2] == '-e'
    payload = json.loads(ansible_args[-1])
    assert payload['obsah_state_path'] == '/var/lib/obsah'

If you decide to allow user -e to override (by reordering as suggested in init.py), flip the last assertion accordingly and add a complementary test for JSON-style -e too.

I can wire these tests into the suite and adjust expectations if you choose the other precedence policy. Want me to push an updated test patch?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ef8e816 and 52d3adb.

📒 Files selected for processing (2)
  • obsah/__init__.py (1 hunks)
  • tests/test_obsah.py (1 hunks)
🔇 Additional comments (1)
obsah/__init__.py (1)

401-404: LGTM: exposing obsah_state_path is clear and consistent.

Using variables['obsah_state_path'] = args.playbook.application_config.state_path() reads cleanly, matches the existing ApplicationConfig API, and aligns with the prior naming feedback. Tests appear updated accordingly.

@evgeni evgeni merged commit f6d871f into theforeman:master Aug 21, 2025
8 checks passed
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.

2 participants