Skip to content
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

[feature] Add presets #62

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

[feature] Add presets #62

wants to merge 11 commits into from

Conversation

Devansh3712
Copy link
Member

@Devansh3712 Devansh3712 commented Jun 17, 2024

Description

Presets allow users to save teuthology-suite command config with a custom name that can be used again.

This PR includes:

  • Create presets table using SQLModel and setup database migrations using alembic
  • Add presets service for ORM queries
  • Add endpoints for /presets route
  • Add fixtures to conftest.py
  • Add tests for /preset endpoints
  • Add limit for creating presets
  • Create a request body schema for PresetArgs

For testing this PR,

  • TEUTHOLOGY_API_SQLITE_URI should be added to the .env file using the format sqlite:////<path>
  • Containerized Setup: Run the start.sh script in teuthology/docs/docker-compose
  • Non-containerized Setup:
    • Create a virtual environment and install the dependencies
    • Run alembic upgrade head command to migrate the database

Workflow

The create, update and delete endpoints required a user to be logged in. Users can read any stored preset, but cannot modify or delete them.

Creating a Preset

  • A POST request to the endpoint /presets/add with the following request body:
{
    "username": "example",
    "name": "test",
    "suite": "teuthology:no-ceph",
    "cmd": "<SuiteArgs format for /suite endpoint>"
}
  • Returns the created preset data, along with a preset ID which can be used to modify the preset
  • A user can only store 10 presets at a time. If they want to delete their oldest preset and store the new one, append ?replace=true to the endpoint

Get a Preset

  • A GET request to the endpoint /presets?username=<github_username>&name=<preset_name>
  • Returns the preset in the following format if it exists:
{
    "id": 1,
    "username": "example",
    "name": "test",
    "suite": "teuthology:no-ceph",
    "cmd": "<SuiteArgs format for /suite endpoint>"
}

Get All Presets of a User

  • A GET request to the endpoint /presets/list?username=<github_username>
  • Returns a list of user's presets

Update a Preset

  • A PUTrequest to the endpoint /presets/edit/<preset_id> with the parameters that need to updated in the preset in the request body
  • Returns the updated preset contents

Delete a Preset

A DELETE request to the endpoint /presets/delete/<preset_id>

Pulpito-ng Integration

Most of the teuthology commands have default parameters, only some such as suite and branch need to be changed according to the user's need. On the frontend, we can present default values for the command parameters and users can change them accordingly. Once the parameter values are confirmed, they can be sent as a JSON request body to the presets/add endpoint.

A form can be used for taking the input values, along with a checkbox to set the replace query parameter to true, which will delete the user's oldest preset if their count of stored presets is 10.

Checklist

@Devansh3712 Devansh3712 self-assigned this Jun 17, 2024
@VallariAg VallariAg added enhancement Improving existing feature or logic gsoc-24 Related to GSoC 2024 teuthology project labels Jun 27, 2024
@VallariAg VallariAg linked an issue Jun 27, 2024 that may be closed by this pull request
@Devansh3712 Devansh3712 force-pushed the wip-devansh-presets branch 2 times, most recently from bba2469 to e33dcbb Compare July 3, 2024 16:14
@Devansh3712 Devansh3712 marked this pull request as ready for review July 3, 2024 16:21
@Devansh3712 Devansh3712 force-pushed the wip-devansh-presets branch 2 times, most recently from 1b08872 to 88ee986 Compare July 12, 2024 07:30
Signed-off-by: Devansh Singh <devanshamity@gmail.com>
Create presets service for database operations

Signed-off-by: Devansh Singh <devanshamity@gmail.com>
Create endpoints for presets

Signed-off-by: Devansh Singh <devanshamity@gmail.com>
Add fixtures to conftest.py for database session and FastAPI
TestClient

Signed-off-by: Devansh Singh <devanshamity@gmail.com>
Add unittests for /presets endpoint

Signed-off-by: Devansh Singh <devanshamity@gmail.com>
Signed-off-by: Devansh Singh <devanshamity@gmail.com>
Add TEUTHOLOGY_API_SQLITE_URI environment variable to tox.ini
and unit_tests.yaml

Signed-off-by: Devansh Singh <devanshamity@gmail.com>
Copy link
Member

@VallariAg VallariAg left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for adding a detailed PR description. It would also be helpful to add the setup instructions (for containerised and containerised) in README.

src/teuthology_api/models/presets.py Show resolved Hide resolved
src/teuthology_api/models/presets.py Outdated Show resolved Hide resolved
gh-actions/start.sh Show resolved Hide resolved
Added a limit on how many presets a user can store at
a time (currently 10)

Signed-off-by: Devansh Singh <devanshamity@gmail.com>
Added a schema for /add endpoint request body for validating
cmd attribute. Updated the cmd column datatype from string to
JSON for the Presets model.

Signed-off-by: Devansh Singh <devanshamity@gmail.com>
Signed-off-by: Devansh Singh <devanshamity@gmail.com>
Signed-off-by: Devansh Singh <devanshamity@gmail.com>
Copy link
Member

@VallariAg VallariAg left a comment

Choose a reason for hiding this comment

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

It's working great! Few things I noticed while testing the PR:

  1. Username should be case insensitive: if I someone has username JohnDoe, it should return their presets even if username is "johndoe". This is because github usernames are case-insensitive (both vallariag and VallariAg redirect to my profile).

  2. /edit: "cmd" should not be required. We can probably send requests to edit without changing cmd. Example, renaming a preset.

  3. /edit and /add: Because we have "--suite" inside the "cmd", I don't think we should be asking the user for that input again in request body with "suite".

{
  "name": "edit_test",
  "suite": "string",         <- this input can be removed 
   "cmd": { 
        "--dry-run": false,
        "--non-interactive": false, 
        "--suite": "string1"
    }
}

We can store/update suite column in our DB based on what is inside "cmd"'s "--suite". And return an error response if suite is missing.

Copy link
Member

@VallariAg VallariAg left a comment

Choose a reason for hiding this comment

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

I'm not sure about this:

In /presets/add, I tested with payload:

{
  "name": "test_defaults",
  "suite": "suite:test",
  "cmd": {
           "--ceph": "main",
        "--ceph-repo": "https://github.com/ceph/ceph-ci.git",
        "--machine-type": "testnode",
        "--num": "1",
        "--priority": "70",
        "--suite": "teuthology:no-ceph",
        "--suite-branch": "main",
        "--suite-repo": "https://github.com/ceph/ceph-ci.git",
        "--teuthology-branch": "",
        "--verbose": "1",
        "<config_yaml>": ["/teuthology/containerized_node.yaml"],
        "--owner": "example",
        "--sha1": "dda7c8f4d64b3b69a12734212f3b6b3dd1821349"
  }
}

But when I read this presets with GET /presets/, I get response:

{
  "id": 4,
  "name": "test_defaults",
  "cmd": {
    "dry_run": false,
    "non_interactive": false,
    "verbose": 1,
    "help": false,
    "arch": null,
    "ceph": "main",
    "ceph_repo": "https://github.com/ceph/ceph-ci.git",
    "distro": null,
    "distro_version": null,
    "email": null,
    "flavor": "default",
    "kernel": "distro",
    "machine_type": "testnode",
    "newest": "0",
    "rerun_status": false,
    "rerun_statuses": "fail,dead",
    "sha1": "dda7c8f4d64b3b69a12734212f3b6b3dd1821349",
    "sleep_before_teardown": "0",
    "suite": "teuthology:no-ceph",
    "suite_branch": "main",
    "suite_dir": null,
    "suite_relpath": "qa",
    "suite_repo": "https://github.com/ceph/ceph-ci.git",
    "teuthology_branch": "",
    "validate_sha1": "true",
    "wait": false,
    "config_yaml": [
      "/teuthology/containerized_node.yaml"
    ],
    "owner": "example",
    "num": "1",
    "priority": "70",
    "queue_backend": null,
    "rerun": null,
    "seed": "-1",
    "force_priority": false,
    "no_nested_subset": false,
    "job_threshold": "500",
    "archive_upload": null,
    "archive_upload_url": null,
    "throttle": null,
    "filter": null,
    "filter_out": null,
    "filter_all": null,
    "filter_fragments": "false",
    "subset": null,
    "timeout": "43200",
    "rocketchat": null,
    "limit": "0"
  },
  "suite": "suite:test",
  "username": "VallariAg"
}

This added the SuiteArg defaults and saved the presets with that. When user query this preset, they'll probably gonna see all the defaults and get confused by all these extra args.
Which makes me wonder if we don't set these defaults and let teuthology-api call teuthology.suite with only the args user set, would teuthology be able to run as expected? If we DO need to set defaults before calling teuthology, then we probably need to figure out how to use defaults for teuthology.suite but not save them in DB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improving existing feature or logic gsoc-24 Related to GSoC 2024 teuthology project
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

create presets db and endpoints
4 participants