Skip to content

test: add MaaS subscription tests#1238

Merged
dbasunag merged 6 commits intoopendatahub-io:mainfrom
SB159:feature/maas-subscription-additional-test
Mar 17, 2026
Merged

test: add MaaS subscription tests#1238
dbasunag merged 6 commits intoopendatahub-io:mainfrom
SB159:feature/maas-subscription-additional-test

Conversation

@SB159
Copy link
Copy Markdown
Contributor

@SB159 SB159 commented Mar 17, 2026

Pull Request

Summary

Some additional MaaS subscription tests.

Related Issues

  • Fixes:
  • JIRA:

How it has been tested

  • Locally
  • Jenkins

Additional Requirements

  • If this PR introduces a new test image, did you create a PR to mirror it in disconnected environment?
  • If this PR introduces new marker(s)/adds a new component, was relevant ticket created to update relevant Jenkins job?

Summary by CodeRabbit

  • Tests
    • Added integration tests covering MaaS subscription access: verifies 403 responses when multiple matching subscriptions exist without an explicit subscription header, and when an actor’s token is not present in the model authorization policy.
    • Added new test fixtures to support scenarios with multiple subscriptions and actor-specific subscription setup.

@github-actions
Copy link
Copy Markdown

The following are automatically added/executed:

  • PR size label.
  • Run pre-commit
  • Run tox
  • Add PR author as the PR assignee
  • Build image based on the PR

Available user actions:

  • To mark a PR as WIP, add /wip in a comment. To remove it from the PR comment /wip cancel to the PR.
  • To block merging of a PR, add /hold in a comment. To un-block merging of PR comment /hold cancel.
  • To mark a PR as approved, add /lgtm in a comment. To remove, add /lgtm cancel.
    lgtm label removed on each new commit push.
  • To mark PR as verified comment /verified to the PR, to un-verify comment /verified cancel to the PR.
    verified label removed on each new commit push.
  • To Cherry-pick a merged PR /cherry-pick <target_branch_name> to the PR. If <target_branch_name> is valid,
    and the current PR is merged, a cherry-picked PR would be created and linked to the current PR.
  • To build and push image to quay, add /build-push-pr-image in a comment. This would create an image with tag
    pr-<pr_number> to quay repository. This image tag, however would be deleted on PR merge or close action.
Supported labels

{'/hold', '/lgtm', '/wip', '/verified', '/cherry-pick', '/build-push-pr-image'}

Signed-off-by: Swati Mukund Bagal <sbagal@redhat.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 17, 2026

📝 Walkthrough

Walkthrough

Adds three pytest artifacts: two new integration tests checking MaaS subscription authorization failure modes (ambiguous subscription without header; actor not in MaaSAuthPolicy), and two fixtures supporting multi-subscription and actor-scoped premium subscription provisioning.

Changes

Cohort / File(s) Summary
New integration tests
tests/model_serving/maas_billing/maas_subscription/test_multiple_subscriptions_no_header.py, tests/model_serving/maas_billing/maas_subscription/test_subscription_without_auth_policy.py
Added two test classes and test methods asserting 403 responses for (1) multiple matching subscriptions when request omits x-maas-subscription header, and (2) a valid subscription where the actor token is not listed in the model's MaaSAuthPolicy. Tests use shared helpers (chat_payload_for_url, poll_expected_status) and logging.
Test fixtures
tests/model_serving/maas_billing/maas_subscription/conftest.py
Added second_free_subscription and free_actor_premium_subscription pytest fixtures that provision additional MaaSSubscription resources and wait for them to be Ready, enabling the above test scenarios.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is largely incomplete. It provides minimal detail ('Some additional MaaS subscription tests') without explaining what scenarios the tests cover, their purpose, or security/functionality implications. Only local testing is marked; Jenkins testing is unchecked. Expand the summary to describe the specific test scenarios (e.g., 403 responses for missing headers or unauthorized actors). Clarify test coverage goals and explain Jenkins testing status or requirements.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'test: add MaaS subscription tests' accurately summarizes the main change—adding new MaaS subscription test files—and is specific and concise.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@SB159 SB159 force-pushed the feature/maas-subscription-additional-test branch from cf6fed5 to 13889f4 Compare March 17, 2026 18:18
Copy link
Copy Markdown
Contributor

@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.

🧹 Nitpick comments (3)
tests/model_serving/maas_billing/maas_subscription/test_multiple_subscriptions_no_header.py (2)

17-45: Redundant fixture declaration.

maas_subscription_tinyllama_free is listed in both usefixtures (line 25) and as a test parameter (line 42). Since you need the fixture value (used on line 76), remove it from usefixtures and keep only the parameter.

Proposed fix
 `@pytest.mark.usefixtures`(
     "maas_unprivileged_model_namespace",
     "maas_subscription_controller_enabled_latest",
     "maas_gateway_api",
     "maas_api_gateway_reachable",
     "maas_inference_service_tinyllama_free",
     "maas_model_tinyllama_free",
     "maas_auth_policy_tinyllama_free",
-    "maas_subscription_tinyllama_free",
 )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@tests/model_serving/maas_billing/maas_subscription/test_multiple_subscriptions_no_header.py`
around lines 17 - 45, The maas_subscription_tinyllama_free fixture is
redundantly declared both in the class-level pytest.mark.usefixtures and as a
test parameter in TestMultipleSubscriptionsNoHeader; remove
maas_subscription_tinyllama_free from the usefixtures decorator (leave it only
as the test function parameter in
test_multiple_matching_subscriptions_no_header_gets_403) so the test receives
the fixture value correctly when referenced later in the test.

55-55: Dead code.

This line assigns to _ (throwaway), but you actually use maas_subscription_tinyllama_free.name on line 76. Remove the no-op.

Proposed fix
-        _ = maas_subscription_tinyllama_free
-
         with create_maas_subscription(
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@tests/model_serving/maas_billing/maas_subscription/test_multiple_subscriptions_no_header.py`
at line 55, Remove the dead no-op assignment to `_`—delete the line that does "_
= maas_subscription_tinyllama_free" so the fixture/variable
maas_subscription_tinyllama_free remains available for later use (e.g.,
accessing maas_subscription_tinyllama_free.name in the test). Ensure no other
unused throwaway assignments remain for that fixture.
tests/model_serving/maas_billing/maas_subscription/test_subscription_without_auth_policy.py (1)

19-45: Redundant fixture declaration.

Same issue as the other test file: maas_subscription_tinyllama_premium is in both usefixtures (line 27) and as a test parameter (line 44). Remove from usefixtures.

Proposed fix
 `@pytest.mark.usefixtures`(
     "maas_unprivileged_model_namespace",
     "maas_subscription_controller_enabled_latest",
     "maas_gateway_api",
     "maas_api_gateway_reachable",
     "maas_inference_service_tinyllama_premium",
     "maas_model_tinyllama_premium",
     "maas_auth_policy_tinyllama_premium",
-    "maas_subscription_tinyllama_premium",
 )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@tests/model_serving/maas_billing/maas_subscription/test_subscription_without_auth_policy.py`
around lines 19 - 45, The test declares the fixture
maas_subscription_tinyllama_premium twice (in the class-level
pytest.mark.usefixtures list and again as a test function parameter) causing
redundancy; edit the class TestSubscriptionWithoutAuthPolicy to remove
maas_subscription_tinyllama_premium from the usefixtures(...) list so the
fixture is provided only via the test method parameter (leave the test signature
and other fixtures intact).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@tests/model_serving/maas_billing/maas_subscription/test_multiple_subscriptions_no_header.py`:
- Around line 17-45: The maas_subscription_tinyllama_free fixture is redundantly
declared both in the class-level pytest.mark.usefixtures and as a test parameter
in TestMultipleSubscriptionsNoHeader; remove maas_subscription_tinyllama_free
from the usefixtures decorator (leave it only as the test function parameter in
test_multiple_matching_subscriptions_no_header_gets_403) so the test receives
the fixture value correctly when referenced later in the test.
- Line 55: Remove the dead no-op assignment to `_`—delete the line that does "_
= maas_subscription_tinyllama_free" so the fixture/variable
maas_subscription_tinyllama_free remains available for later use (e.g.,
accessing maas_subscription_tinyllama_free.name in the test). Ensure no other
unused throwaway assignments remain for that fixture.

In
`@tests/model_serving/maas_billing/maas_subscription/test_subscription_without_auth_policy.py`:
- Around line 19-45: The test declares the fixture
maas_subscription_tinyllama_premium twice (in the class-level
pytest.mark.usefixtures list and again as a test function parameter) causing
redundancy; edit the class TestSubscriptionWithoutAuthPolicy to remove
maas_subscription_tinyllama_premium from the usefixtures(...) list so the
fixture is provided only via the test method parameter (leave the test signature
and other fixtures intact).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: f46ef53a-96e9-4bc5-8be1-3f16d50d27ac

📥 Commits

Reviewing files that changed from the base of the PR and between 6237646 and 7673cbb.

📒 Files selected for processing (2)
  • tests/model_serving/maas_billing/maas_subscription/test_multiple_subscriptions_no_header.py
  • tests/model_serving/maas_billing/maas_subscription/test_subscription_without_auth_policy.py

SB159 added 2 commits March 17, 2026 14:01
Signed-off-by: Swati Mukund Bagal <sbagal@redhat.com>
Signed-off-by: Swati Mukund Bagal <sbagal@redhat.com>
Copy link
Copy Markdown
Contributor

@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.

🧹 Nitpick comments (1)
tests/model_serving/maas_billing/maas_subscription/conftest.py (1)

573-616: Generate unique subscription names here, and keep the ambiguity case symmetric.

Line 576 and Line 607 hard-code function-scoped cluster resource names, which is brittle on reruns, parallel workers, or delayed cleanup. Line 582 also sets priority=5 even though the baseline free subscription in this file uses priority=0, so the “multiple matching subscriptions” setup is no longer clearly modeling two equally eligible subscriptions. Use generate_random_name() for both names and match the baseline priority in second_free_subscription.

Suggested change
     with create_maas_subscription(
         admin_client=admin_client,
         subscription_namespace=maas_subscription_tinyllama_free.namespace,
-        subscription_name="e2e-second-free-subscription",
+        subscription_name=f"e2e-second-free-subscription-{generate_random_name()}",
         owner_group_name=maas_free_group,
         model_name=maas_model_tinyllama_free.name,
         model_namespace=maas_model_tinyllama_free.namespace,
         tokens_per_minute=500,
         window="1m",
-        priority=5,
+        priority=0,
         teardown=True,
         wait_for_resource=True,
     ) as second_subscription:
@@
     with create_maas_subscription(
         admin_client=admin_client,
         subscription_namespace=maas_subscription_tinyllama_premium.namespace,
-        subscription_name="e2e-free-actor-premium-sub",
+        subscription_name=f"e2e-free-actor-premium-sub-{generate_random_name()}",
         owner_group_name="system:authenticated",
         model_name=maas_model_tinyllama_premium.name,
         model_namespace=maas_model_tinyllama_premium.namespace,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/model_serving/maas_billing/maas_subscription/conftest.py` around lines
573 - 616, Replace the hard-coded subscription names and mismatched priority by
generating unique names and using the same priority as the baseline free
subscription: call generate_random_name() when constructing the
subscription_name for both the second free subscription (created in the with
create_maas_subscription(...) as second_subscription block) and the
free_actor_premium_subscription (the with create_maas_subscription(...) as
sub_for_free_actor block), and change priority=5 in the second_free_subscription
creation to priority=0 to match the baseline; keep all other arguments and
teardown/wait_for_resource behavior unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/model_serving/maas_billing/maas_subscription/conftest.py`:
- Around line 573-616: Replace the hard-coded subscription names and mismatched
priority by generating unique names and using the same priority as the baseline
free subscription: call generate_random_name() when constructing the
subscription_name for both the second free subscription (created in the with
create_maas_subscription(...) as second_subscription block) and the
free_actor_premium_subscription (the with create_maas_subscription(...) as
sub_for_free_actor block), and change priority=5 in the second_free_subscription
creation to priority=0 to match the baseline; keep all other arguments and
teardown/wait_for_resource behavior unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 3e16d4e3-729f-43ef-81f7-ab41e021d8ad

📥 Commits

Reviewing files that changed from the base of the PR and between 7673cbb and c24c6a7.

📒 Files selected for processing (3)
  • tests/model_serving/maas_billing/maas_subscription/conftest.py
  • tests/model_serving/maas_billing/maas_subscription/test_multiple_subscriptions_no_header.py
  • tests/model_serving/maas_billing/maas_subscription/test_subscription_without_auth_policy.py

Copy link
Copy Markdown
Contributor

@kami619 kami619 left a comment

Choose a reason for hiding this comment

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

lgtm

@dbasunag dbasunag merged commit 73cc4d5 into opendatahub-io:main Mar 17, 2026
10 checks passed
@github-actions
Copy link
Copy Markdown

Status of building tag latest: success.
Status of pushing tag latest to image registry: success.

ssaleem-rh pushed a commit to ssaleem-rh/opendatahub-tests that referenced this pull request Mar 23, 2026
* test: add MaaS subscription tests

Signed-off-by: Swati Mukund Bagal <sbagal@redhat.com>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* address review comments

Signed-off-by: Swati Mukund Bagal <sbagal@redhat.com>

* address review comments

Signed-off-by: Swati Mukund Bagal <sbagal@redhat.com>

---------

Signed-off-by: Swati Mukund Bagal <sbagal@redhat.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Debarati Basu-Nag <dbasunag@redhat.com>
Signed-off-by: Shehan Saleem <ssaleem@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants