Skip to content

Commit

Permalink
frontend, cli, python, backend, rpmbuild: Add priority=X to repo config
Browse files Browse the repository at this point in the history
This allows users to set priority of their repository via frontend
page or copr-cli. This priority value sets the `priority=X` value
in repo confid in /etc/yum.repos.d/_copr:*repo
  • Loading branch information
nikromen committed Jun 5, 2023
1 parent 700a02a commit 6619eae
Show file tree
Hide file tree
Showing 17 changed files with 98 additions and 4 deletions.
1 change: 1 addition & 0 deletions backend/copr_backend/background_worker_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ def _start_remote_build(self):
command += " --srpm --task-url {task_url} --detached"
else:
command += " --task-url {task_url} --chroot {chroot} --detached"

command = command.format(task_url=self.job.task_url,
chroot=self.job.chroot)

Expand Down
2 changes: 2 additions & 0 deletions backend/copr_backend/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def __init__(self, task_data, worker_opts):
self.results = None
self.appstream = None

self.repo_priority = None

# TODO: validate update data
for key, val in task_data.items():
key = str(key)
Expand Down
8 changes: 8 additions & 0 deletions cli/copr_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ def action_create(self, args):
appstream=ON_OFF_MAP[args.appstream],
runtime_dependencies=args.runtime_dependencies,
packit_forge_projects_allowed=args.packit_forge_projects_allowed,
repo_priority=args.repo_priority,
)

owner_part = username.replace('@', "g/")
Expand Down Expand Up @@ -514,6 +515,7 @@ def action_modify_project(self, args):
appstream=ON_OFF_MAP[args.appstream],
runtime_dependencies=args.runtime_dependencies,
packit_forge_projects_allowed=args.packit_forge_projects_allowed,
repo_priority=args.repo_priority,
)

@requires_api_auth
Expand Down Expand Up @@ -1174,6 +1176,9 @@ def setup_parser():
"created for you (as soon as they are available) as rawhide "
"chroot forks."))

parser_create.add_argument("--repo-priority", default=None,
help="Set the priority value of this repository")

create_and_modify_common_opts(parser_create)

parser_create.set_defaults(func="action_create")
Expand Down Expand Up @@ -1241,6 +1246,9 @@ def setup_parser():
"created for you (as soon as they are available) as rawhide "
"chroot forks."))

parser_modify.add_argument("--repo-priority", default=None,
help="Set the priority value of this repository")

create_and_modify_common_opts(parser_modify)

parser_modify.set_defaults(func="action_modify_project")
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 @@ -479,6 +479,7 @@ def test_create_project(config_from_file, project_proxy_add, capsys):
"appstream": False,
"runtime_dependencies": None,
"packit_forge_projects_allowed": None,
"repo_priority": None,
}
assert stdout == "New project was successfully created: http://copr/coprs/jdoe/foo/\n"

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
Add repo priority field
Revision ID: 7d9f6f921fa0
Revises: ba6ac0936bfb
Create Date: 2023-05-25 11:05:39.877208
"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '7d9f6f921fa0'
down_revision = 'ba6ac0936bfb'
branch_labels = None
depends_on = None


def upgrade():
op.add_column('copr', sa.Column('repo_priority', sa.Integer(), nullable=True))


def downgrade():
op.drop_column('copr', 'repo_priority')
2 changes: 2 additions & 0 deletions frontend/coprs_frontend/coprs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@


BANNER_LOCATION = "/var/lib/copr/data/banner-include.html"

DEFAULT_REPO_PRIORITY_VALUE = 99
13 changes: 13 additions & 0 deletions frontend/coprs_frontend/coprs/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from flask_wtf.file import FileRequired, FileField
from fnmatch import fnmatch

from coprs.constants import DEFAULT_REPO_PRIORITY_VALUE

try: # get rid of deprecation warning with newer flask_wtf
from flask_wtf import FlaskForm
except ImportError:
Expand Down Expand Up @@ -655,6 +657,17 @@ class CoprForm(BaseForm):
filters=[StringListFilter(), StripUrlSchemaListFilter()],
validators=[wtforms.validators.Optional()],)

repo_priority = wtforms.IntegerField(
"The priority value of this repository",
description="""If there is more than one package to install from (e.g. vim from
Fedora repo and Copr repo), the repo with lower priority is picked.""",
render_kw={"placeholder": "Optional - integer, e.g. 22"},
validators=[
wtforms.validators.Optional(),
wtforms.validators.NumberRange(min=1, max=DEFAULT_REPO_PRIORITY_VALUE)],
default=None,
)

@property
def errors(self):
"""
Expand Down
14 changes: 14 additions & 0 deletions frontend/coprs_frontend/coprs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,20 @@ class _CoprPublic(db.Model, helpers.Serializer):
# allowed to build in this Copr via Packit
packit_forge_projects_allowed = db.Column(db.Text)

# priority=NUMBER in repo configs
repo_priority = db.Column(db.Integer, nullable=True)

@validates("repo_priority")
def validate_repo_priority(self, _, value):
"""Checks whether priority value is correct"""
if value < 1:
raise ValueError("Repo priority can't be lower than 1")

if value > 99:
raise ValueError("Repo priority can't be higher than 99")

return value


class _CoprPrivate(db.Model, helpers.Serializer):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ <h3 class="panel-title">{{ counter('instructions') }}. Other options</h3>
placeholder='Optional',
info='Delete the project after the specfied period of time (empty = disabled)') }}

{{ render_field(form.repo_priority,
class="short-input-field",
placeholder='Optional',
info='Set the priority value of this repository. Defaults to 99.') }}

{{ render_field(form.isolation, placeholder='default') }}

{{ render_bootstrap_options(form) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def to_dict(copr):
"appstream": copr.appstream,
"packit_forge_projects_allowed": copr.packit_forge_projects_allowed_list,
"follow_fedora_branching": copr.follow_fedora_branching,
"repo_priority": copr.repo_priority,
}


Expand Down Expand Up @@ -162,6 +163,7 @@ def _form_field_repos(form_field):
runtime_dependencies=_form_field_repos(form.runtime_dependencies),
appstream=form.appstream.data,
packit_forge_projects_allowed=_form_field_repos(form.packit_forge_projects_allowed),
repo_priority=form.repo_priority.data,
)
db.session.commit()
except (DuplicateException,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def get_build_record(task, for_backend=False):
"isolation": task.build.isolation,
"fedora_review": task.build.copr.fedora_review,
"appstream": bool(task.build.appstream),
"repo_priority": task.build.copr.repo_priority
})

copr_chroot = CoprChrootsLogic.get_by_name_safe(task.build.copr, task.mock_chroot.name)
Expand Down
3 changes: 3 additions & 0 deletions frontend/coprs_frontend/coprs/views/coprs_ns/coprs_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ def copr_new(username=None, group_name=None):
isolation=form.isolation.data,
appstream=form.appstream.data,
packit_forge_projects_allowed=form.packit_forge_projects_allowed.data,
repo_priority=form.repo_priority.data
)

db.session.commit()
Expand Down Expand Up @@ -551,6 +552,8 @@ def process_copr_update(copr, form):
copr.isolation = form.isolation.data
copr.appstream = form.appstream.data
copr.packit_forge_projects_allowed = form.packit_forge_projects_allowed.data
copr.repo_priority = form.repo_priority.data

if flask.g.user.admin:
copr.auto_prune = form.auto_prune.data
else:
Expand Down
7 changes: 5 additions & 2 deletions frontend/coprs_frontend/tests/test_apiv3/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_update_copr_api3(self):
# testing method!
already_tested = set([
"delete_after", "build_enable_net", "auto_createrepo", "repos",
"runtime_dependencies", "packit_forge_projects_allowed"
"runtime_dependencies", "packit_forge_projects_allowed", "repo_priority"
])

# check non-trivial changes
Expand All @@ -91,6 +91,7 @@ def test_update_copr_api3(self):
assert old_data["auto_prune"] is True
assert old_data["follow_fedora_branching"] is True
assert old_data["packit_forge_projects_allowed"] == ""
assert old_data["repo_priority"] is None
self.api3.modify_project(
"test", delete_after_days=5, enable_net=True, devel_mode=True,
repos=["http://example/repo/", "http://another/"],
Expand All @@ -100,7 +101,8 @@ def test_update_copr_api3(self):
"https://github.com/packit/ogr",
"github.com/packit/requre",
"http://github.com/packit/packit"
]
],
repo_priority=13,
)
new_data = self._get_copr_id_data(1)
delete_after = datetime.datetime.now() + datetime.timedelta(days=5)
Expand All @@ -113,6 +115,7 @@ def test_update_copr_api3(self):
old_data["bootstrap"] = "default"
old_data["packit_forge_projects_allowed"] = "github.com/packit/ogr\ngithub.com/packit/requre\ngithub.com" \
"/packit/packit"
old_data["repo_priority"] = 13
assert old_data == new_data
old_data = new_data

Expand Down
8 changes: 6 additions & 2 deletions python/copr/v3/proxies/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def add(self, ownername, projectname, chroots, description=None, instructions=No
auto_prune=True, use_bootstrap_container=None, devel_mode=False,
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):
fedora_review=None, appstream=False, runtime_dependencies=None, packit_forge_projects_allowed=None,
repo_priority=None):
"""
Create a project
Expand Down Expand Up @@ -139,6 +140,7 @@ def add(self, ownername, projectname, chroots, description=None, instructions=No
"appstream": appstream,
"runtime_dependencies": runtime_dependencies,
"packit_forge_projects_allowed": packit_forge_projects_allowed,
"repo_priority": repo_priority,
}

_compat_use_bootstrap_container(data, use_bootstrap_container)
Expand All @@ -157,7 +159,8 @@ def edit(self, ownername, projectname, chroots=None, description=None, instructi
auto_prune=None, use_bootstrap_container=None, devel_mode=None,
delete_after_days=None, multilib=None, module_hotfixes=None,
bootstrap=None, bootstrap_image=None, isolation=None, follow_fedora_branching=None,
fedora_review=None, appstream=None, runtime_dependencies=None, packit_forge_projects_allowed=None):
fedora_review=None, appstream=None, runtime_dependencies=None, packit_forge_projects_allowed=None,
repo_priority=None):
"""
Edit a project
Expand Down Expand Up @@ -223,6 +226,7 @@ def edit(self, ownername, projectname, chroots=None, description=None, instructi
"appstream": appstream,
"runtime_dependencies": runtime_dependencies,
"packit_forge_projects_allowed": packit_forge_projects_allowed,
"repo_priority": repo_priority,
}

_compat_use_bootstrap_container(data, use_bootstrap_container)
Expand Down
3 changes: 3 additions & 0 deletions rpmbuild/copr_rpmbuild/builders/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def __init__(self, task, sourcedir, resultdir, config):
self.buildroot_pkgs = task.get("buildroot_pkgs")
self.enable_net = task.get("enable_net")
self.repos = task.get("repos")
if task.get("repos") and task.get("repo_priority") is not None:
self.repos["priority"] = task.get("repo_priority")

self.bootstrap = task.get("bootstrap")
self.bootstrap_image = task.get("bootstrap_image")
self.timeout = task.get("timeout", 3600)
Expand Down
3 changes: 3 additions & 0 deletions rpmbuild/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ def get_task(args, config, build_config_url_path=None, task_id=None):
if args.copr:
task['task_id'] = copr_chroot_to_task_id(args.copr, args.chroot)

if args.repo_priority:
task["repo_priority"] = args.repo_priority

return task


Expand Down
3 changes: 3 additions & 0 deletions rpmbuild/man/copr-rpmbuild.1.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ OPTIONS
--verbose::
Print debugging information.

--priority::
Set the priority of this copr repository.

--help::
Display help.

Expand Down

0 comments on commit 6619eae

Please sign in to comment.