Skip to content

Commit

Permalink
frontend, python, cli: allow admins to set storage for new projects
Browse files Browse the repository at this point in the history
See #2533

This will be useful for beaker tests where we can now add basic tests
for every supported storage.
  • Loading branch information
FrostyX authored and praiskup committed Sep 11, 2024
1 parent ad36b8b commit 14faa50
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 7 deletions.
8 changes: 8 additions & 0 deletions cli/copr_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ def action_create(self, args):
runtime_dependencies=args.runtime_dependencies,
packit_forge_projects_allowed=args.packit_forge_projects_allowed,
repo_priority=args.repo_priority,
storage=args.storage,
)

owner_part = username.replace('@', "g/")
Expand Down Expand Up @@ -1192,6 +1193,13 @@ def setup_parser():
help=("Use the priority=<INT> config option for repositories in this "
"project, see man dnf.conf(5) for more info."))

parser_create.add_argument(
"--storage",
choices=["backend", "pulp"],
help=("What storage should be used for this project. "
"This option can only be specified by a COPR admin.")
)

create_and_modify_common_opts(parser_create)

parser_create.set_defaults(func="action_create")
Expand Down
2 changes: 2 additions & 0 deletions cli/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ def test_create_project(config_from_file, project_proxy_add, capsys):
"runtime_dependencies": None,
"packit_forge_projects_allowed": None,
"repo_priority": None,
"storage": None,
}
assert stdout == "New project was successfully created: http://copr/coprs/jdoe/foo/\n"

Expand Down Expand Up @@ -577,6 +578,7 @@ def test_create_multilib_project(config_from_file, project_proxy_add, capsys):
"runtime_dependencies": None,
"packit_forge_projects_allowed": None,
"repo_priority": None,
"storage": None,
}
assert stdout == "New project was successfully created: http://copr/coprs/jdoe/foo/\n"

Expand Down
6 changes: 6 additions & 0 deletions frontend/coprs_frontend/coprs/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,12 @@ class CoprForm(BaseForm):
default=None,
)

storage = wtforms.SelectField(
"Admin only - what storage should be used for this project",
choices=[(x, x) for x in ["backend", "pulp"]],
validators=[wtforms.validators.Optional()],
)

@property
def errors(self):
"""
Expand Down
8 changes: 6 additions & 2 deletions frontend/coprs_frontend/coprs/logic/coprs_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def get_multiple_fulltext(cls, fulltext=None, projectname=None,
def add(cls, user, name, selected_chroots, repos=None, description=None,
instructions=None, check_for_duplicates=False, group=None, persistent=False,
auto_prune=True, bootstrap=None, follow_fedora_branching=False, isolation=None,
appstream=False, **kwargs):
appstream=False, storage=None, **kwargs):

if not flask.g.user.admin and flask.g.user != user:
msg = ("You were authorized as '{0}' user without permissions to access "
Expand All @@ -300,6 +300,10 @@ def add(cls, user, name, selected_chroots, repos=None, description=None,
if not flask.g.user.admin and not auto_prune:
raise exceptions.NonAdminCannotDisableAutoPrunning()

if not flask.g.user.admin and storage:
raise exceptions.AccessRestricted("Non-admin cannot set storage")
storage = StorageEnum(storage or app.config["DEFAULT_STORAGE"])

# form validation checks for duplicates
cls.new(user, name, group, check_for_duplicates=check_for_duplicates)

Expand All @@ -315,7 +319,7 @@ def add(cls, user, name, selected_chroots, repos=None, description=None,
isolation=isolation,
follow_fedora_branching=follow_fedora_branching,
appstream=appstream,
storage=StorageEnum(app.config["DEFAULT_STORAGE"]),
storage=storage,
**kwargs)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ def _form_field_repos(form_field):
form.packit_forge_projects_allowed
),
repo_priority=form.repo_priority.data,
storage=form.storage.data,
)
db.session.commit()
except (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,13 @@ class _ProjectGetAddFields:
description="Build and project is immune against deletion",
)
additional_repos: List = fields.additional_repos
storage: String = String(
description=(
"Admin only - what storage should be used for this project. "
"Possible values are 'backend' or 'pulp'."
),
)



@dataclass
Expand Down
5 changes: 1 addition & 4 deletions frontend/coprs_frontend/tests/test_apiv3/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import pytest

from copr_common.enums import StorageEnum
from coprs.models import User, Copr

from tests.coprs_test_case import CoprsTestCase, TransactionDecorator
Expand Down Expand Up @@ -153,8 +152,6 @@ def test_update_copr_api3(self):
}, {
}, {
"appstream": True,
}, {
"storage": StorageEnum("backend"),
}]

for setup in easy_changes:
Expand All @@ -168,7 +165,7 @@ def test_update_copr_api3(self):
"created_on", "deleted", "scm_api_auth_json", "scm_api_type",
"scm_repo_url", "id", "name", "user_id", "group_id",
"webhook_secret", "forked_from_id", "latest_indexed_data_update",
"copr_id", "persistent", "playground",
"copr_id", "persistent", "playground", "storage",
]:
should_test.remove(item)

Expand Down
4 changes: 3 additions & 1 deletion python/copr/v3/proxies/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def add(self, ownername, projectname, chroots, description=None, instructions=No
delete_after_days=None, multilib=False, module_hotfixes=False,
bootstrap=None, bootstrap_image=None, isolation=None, follow_fedora_branching=True,
fedora_review=None, appstream=False, runtime_dependencies=None, packit_forge_projects_allowed=None,
repo_priority=None, exist_ok=False):
repo_priority=None, exist_ok=False, storage=None):
"""
Create a project
Expand Down Expand Up @@ -110,6 +110,7 @@ def add(self, ownername, projectname, chroots, description=None, instructions=No
enabled together with this project repository.
:param list packit_forge_projects_allowed: List of forge projects that
will be allowed to build in the project via Packit
:param str storage: Admin only - What storage should be used for this project
:return: Munch
"""
endpoint = "/project/add/{ownername}"
Expand Down Expand Up @@ -142,6 +143,7 @@ def add(self, ownername, projectname, chroots, description=None, instructions=No
"runtime_dependencies": runtime_dependencies,
"packit_forge_projects_allowed": packit_forge_projects_allowed,
"repo_priority": repo_priority,
"storage": storage,
}

_compat_use_bootstrap_container(data, use_bootstrap_container)
Expand Down

0 comments on commit 14faa50

Please sign in to comment.