[copr] master: [frontend][rhbz:#1279199] Internet access always enabled when building from CLI (b0833c3)
by vgologuz@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit b0833c31223654e0c3bff6f3f02a188a8e79069f
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Thu Nov 12 16:39:57 2015 +0100
[frontend][rhbz:#1279199] Internet access always enabled when building from CLI
>---------------------------------------------------------------
.../coprs_frontend/coprs/logic/builds_logic.py | 10 +-
.../coprs/rest_api/resources/build.py | 3 +-
.../coprs/views/api_ns/api_general.py | 79 ++++++--------------
3 files changed, 30 insertions(+), 62 deletions(-)
diff --git a/frontend/coprs_frontend/coprs/logic/builds_logic.py b/frontend/coprs_frontend/coprs/logic/builds_logic.py
index ae4dbbe..ed6aa04 100644
--- a/frontend/coprs_frontend/coprs/logic/builds_logic.py
+++ b/frontend/coprs_frontend/coprs/logic/builds_logic.py
@@ -208,7 +208,7 @@ class BuildsLogic(object):
chroots=chroots,
source_type=source_build.source_type,
source_json=source_build.source_json,
- enable_net=build_options.get("enabled_net", True),
+ enable_net=build_options.get("enabled_net", source_build.enable_net),
git_hashes=git_hashes,
skip_import=skip_import)
@@ -251,7 +251,7 @@ class BuildsLogic(object):
chroots=chroots,
source_type=source_type,
source_json=source_json,
- enable_net=build_options.get("enabled_net", True))
+ enable_net=build_options.get("enabled_net", copr.build_enable_net))
if user.proven:
if "timeout" in build_options:
@@ -292,7 +292,7 @@ class BuildsLogic(object):
chroots=chroots,
source_type=source_type,
source_json=source_json,
- enable_net=build_options.get("enabled_net", True))
+ enable_net=build_options.get("enabled_net", copr.build_enable_net))
if user.proven:
if "timeout" in build_options:
@@ -333,7 +333,7 @@ class BuildsLogic(object):
chroots=chroots,
source_type=source_type,
source_json=source_json,
- enable_net=build_options.get("enabled_net", True))
+ enable_net=build_options.get("enabled_net", copr.build_enable_net))
if user.proven:
if "timeout" in build_options:
@@ -379,7 +379,7 @@ class BuildsLogic(object):
chroots=chroots,
source_type=source_type,
source_json=source_json,
- enable_net=build_options.get("enabled_net", True))
+ enable_net=build_options.get("enabled_net", copr.build_enable_net))
if user.proven:
if "timeout" in build_options:
diff --git a/frontend/coprs_frontend/coprs/rest_api/resources/build.py b/frontend/coprs_frontend/coprs/rest_api/resources/build.py
index 42b7355..8736f1e 100644
--- a/frontend/coprs_frontend/coprs/rest_api/resources/build.py
+++ b/frontend/coprs_frontend/coprs/rest_api/resources/build.py
@@ -74,7 +74,8 @@ class BuildListR(Resource):
},
}
- def handle_post_json(self, req):
+ @staticmethod
+ def handle_post_json(req):
"""
:return: if of the created build or raise Exception
"""
diff --git a/frontend/coprs_frontend/coprs/views/api_ns/api_general.py b/frontend/coprs_frontend/coprs/views/api_ns/api_general.py
index fc15cbe..7c2352c 100644
--- a/frontend/coprs_frontend/coprs/views/api_ns/api_general.py
+++ b/frontend/coprs_frontend/coprs/views/api_ns/api_general.py
@@ -16,6 +16,7 @@ from coprs import forms
from coprs import helpers
from coprs.helpers import fix_protocol_for_backend
from coprs.logic.api_logic import MonitorWrapper
+from coprs.logic.builds_logic import BuildsLogic
from coprs.logic.complex_logic import ComplexLogic
from coprs.logic.users_logic import UsersLogic
@@ -281,30 +282,25 @@ def copr_new_build(copr):
# we're checking authorization above for now
# and also creating separate build for each package
pkgs = form.pkgs.data.split("\n")
- ids = []
- chroots = []
- for chroot in copr.active_chroots:
- if chroot.name in form.selected_chroots:
- chroots.append(chroot)
+ ids = []
for pkg in pkgs:
- # create json describing the build source
- source_type = helpers.BuildSourceEnum("srpm_link")
- source_json = json.dumps({"url": pkg})
-
- build = builds_logic.BuildsLogic.add(
- user=flask.g.user,
- pkgs=pkg,
- copr=copr,
- chroots=chroots,
- source_type=source_type,
- source_json=source_json)
-
- if flask.g.user.proven:
- build.memory_reqs = form.memory_reqs.data
- build.timeout = form.timeout.data
+ try:
+ build = BuildsLogic.create_new_from_url(
+ flask.g.user, copr,
+ srpm_url=pkg,
+ chroot_names=form.selected_chroots,
+ )
+ db.session.commit()
+ except ActionInProgressException as err:
+ db.session.rollback()
+
+ raise LegacyApiError("Cannot create new build due to: {}".format(err))
+ except InsufficientRightsException as err:
+ db.session.rollback()
+ raise LegacyApiError("User {} cannot create build in project {}: {}"
+ .format(flask.g.user.username, copr.full_name, err))
- db.session.commit()
ids.append(build.id)
output = {"output": "ok",
@@ -330,49 +326,20 @@ def copr_new_build_upload(copr):
if not form.validate_on_submit():
raise LegacyApiError("Invalid request: bad request parameters")
- tmp = tempfile.mkdtemp(dir=app.config["SRPM_STORAGE_DIR"])
- tmp_name = os.path.basename(tmp)
filename = secure_filename(form.pkgs.data.filename)
- file_path = os.path.join(tmp, filename)
- form.pkgs.data.save(file_path)
-
- # make the pkg public
- pkg_url = "https://{hostname}/tmp/{tmp_dir}/{srpm}".format(
- hostname=app.config["PUBLIC_COPR_HOSTNAME"],
- tmp_dir=tmp_name,
- srpm=filename)
-
- # check which chroots we need
- chroots = []
- for chroot in copr.active_chroots:
- if chroot.name in form.selected_chroots:
- chroots.append(chroot)
-
- # create json describing the build source
- source_type = helpers.BuildSourceEnum("srpm_upload")
- source_json = json.dumps({"tmp": tmp_name,
- "pkg": filename})
# create a new build
try:
- build = builds_logic.BuildsLogic.add(
- user=flask.g.user,
- pkgs=pkg_url,
- copr=copr,
- chroots=chroots,
- source_type=source_type,
- source_json=source_json,
- enable_net=form.enable_net.data)
-
- if flask.g.user.proven:
- build.memory_reqs = form.memory_reqs.data
- build.timeout = form.timeout.data
+ build = BuildsLogic.create_new_from_upload(
+ flask.g.user, copr,
+ f_uploader=lambda path: form.pkgs.data.save(path),
+ orig_filename=filename,
+ chroot_names=form.selected_chroots,
+ )
db.session.commit()
except (ActionInProgressException, InsufficientRightsException) as e:
- db.session.rollback()
- shutil.rmtree(tmp)
raise LegacyApiError("Invalid request: {}".format(e))
output = {"output": "ok",
8 years, 6 months
[copr] master: 1280416 - do not use @ in repo id (23341d4)
by Miroslav Suchý
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 23341d412ac2ad1c40fd5ac2d9eeecd9c21cbd57
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Thu Nov 12 15:16:32 2015 +0100
1280416 - do not use @ in repo id
>---------------------------------------------------------------
frontend/coprs_frontend/coprs/models.py | 7 +++++++
.../coprs_frontend/coprs/templates/coprs/copr.repo | 2 +-
2 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/frontend/coprs_frontend/coprs/models.py b/frontend/coprs_frontend/coprs/models.py
index 1e05bb8..86ec82f 100644
--- a/frontend/coprs_frontend/coprs/models.py
+++ b/frontend/coprs_frontend/coprs/models.py
@@ -308,6 +308,13 @@ class Copr(db.Model, helpers.Serializer):
else:
return "{}-{}".format(self.owner.username, self.name)
+ @property
+ def repo_id(self):
+ if self.is_a_group_project:
+ return "group_{}-{}".format(self.group.name, self.name)
+ else:
+ return "{}-{}".format(self.owner.username, self.name)
+
def to_dict(self, private=False, show_builds=True, show_chroots=True):
result = {}
for key in ["id", "name", "description", "instructions"]:
diff --git a/frontend/coprs_frontend/coprs/templates/coprs/copr.repo b/frontend/coprs_frontend/coprs/templates/coprs/copr.repo
index eafc6d6..4197b58 100644
--- a/frontend/coprs_frontend/coprs/templates/coprs/copr.repo
+++ b/frontend/coprs_frontend/coprs/templates/coprs/copr.repo
@@ -1,4 +1,4 @@
-[{{ copr.repo_name }}]
+[{{ copr.repo_id }}]
name=Copr repo for {{ copr.name }} owned by {{ copr.owner.name }}
baseurl={{ url | fix_url_https_backend }}
skip_if_unavailable=True
8 years, 6 months
[copr] master: [frontend] Validate group name and access right during the group activation. (b42e0e5)
by vgologuz@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit b42e0e5fe9c121dbf3987686de0b71380a993822
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Thu Nov 12 15:34:27 2015 +0100
[frontend] Validate group name and access right during the group activation.
>---------------------------------------------------------------
frontend/copr-frontend.spec | 2 -
frontend/coprs_frontend/coprs/exceptions.py | 83 ++++++++++----------
frontend/coprs_frontend/coprs/forms.py | 23 +++++-
frontend/coprs_frontend/coprs/logic/users_logic.py | 5 +
.../coprs/templates/{404.html => _error.html} | 9 ++-
.../coprs/templates/groups/activate_fas_group.html | 2 +-
.../coprs/views/coprs_ns/__init__.py | 14 +++-
.../coprs/views/groups_ns/__init__.py | 13 +++
.../coprs/views/groups_ns/groups_general.py | 11 +++-
frontend/coprs_frontend/coprs/views/misc.py | 19 ++++-
frontend/coprs_frontend/tests/coprs_test_case.py | 13 +++
.../test_views/test_coprs_ns/test_coprs_general.py | 6 +-
.../test_groups_ns/test_groups_general.py | 66 ++++++++++++++++
frontend/requirements.txt | 4 +-
frontend/{run_tests.sh => run3_tests.sh} | 0
frontend/run_tests.sh | 2 +-
16 files changed, 217 insertions(+), 55 deletions(-)
diff --git a/frontend/copr-frontend.spec b/frontend/copr-frontend.spec
index a0176f7..7e384da 100644
--- a/frontend/copr-frontend.spec
+++ b/frontend/copr-frontend.spec
@@ -93,7 +93,6 @@ BuildRequires: redis
BuildRequires: python-dateutil
BuildRequires: pytest
BuildRequires: yum
-BuildRequires: python-flexmock
BuildRequires: python-mock
BuildRequires: python-decorator
BuildRequires: python-markdown
@@ -119,7 +118,6 @@ Requires: python3-wtforms
Requires: python3-flask-wtf
Requires: python3-flask-restful
Requires: python3-marshmallow
-Requires: python3-flexmock
# Not packaged yet:
# Requires: python3-flask-openid # https://bugzilla.redhat.com/show_bug.cgi?id=1010810
diff --git a/frontend/coprs_frontend/coprs/exceptions.py b/frontend/coprs_frontend/coprs/exceptions.py
index 57c6fff..483c4f7 100644
--- a/frontend/coprs_frontend/coprs/exceptions.py
+++ b/frontend/coprs_frontend/coprs/exceptions.py
@@ -1,43 +1,3 @@
-class ArgumentMissingException(BaseException):
- pass
-
-
-class MalformedArgumentException(ValueError):
- pass
-
-
-class NotFoundException(BaseException):
- pass
-
-
-class DuplicateException(BaseException):
- pass
-
-
-class InsufficientRightsException(BaseException):
- pass
-
-
-class RequestCannotBeExecuted(Exception):
- pass
-
-
-class ActionInProgressException(BaseException):
-
- def __init__(self, msg, action):
- self.msg = msg
- self.action = action
-
- def __unicode__(self):
- return self.formatted_msg()
-
- def __str__(self):
- return self.__unicode__()
-
- def formatted_msg(self):
- return self.msg.format(action=self.action)
-
-
class CoprHttpException(Exception):
_default = "Generic copr exception"
@@ -67,7 +27,50 @@ class AccessRestricted(CoprHttpException):
_code = 403
+class BadRequest(CoprHttpException):
+
+ _default = "Bad request to the server"
+ _code = 400
+
+
class LegacyApiError(CoprHttpException):
_default = "API error"
_code = 500
+
+
+class MalformedArgumentException(ValueError):
+ pass
+
+
+class NotFoundException(ObjectNotFound):
+ pass
+
+
+class DuplicateException(BadRequest):
+ pass
+
+
+InsufficientRightsException = AccessRestricted
+
+
+class RequestCannotBeExecuted(CoprHttpException):
+ pass
+
+
+class ActionInProgressException(CoprHttpException):
+
+ def __init__(self, msg, action):
+ self.msg = msg
+ self.action = action
+
+ def __unicode__(self):
+ return self.formatted_msg()
+
+ def __str__(self):
+ return self.__unicode__()
+
+ def formatted_msg(self):
+ return self.msg.format(action=self.action)
+
+
diff --git a/frontend/coprs_frontend/coprs/forms.py b/frontend/coprs_frontend/coprs/forms.py
index 03e7b28..a7269e3 100644
--- a/frontend/coprs_frontend/coprs/forms.py
+++ b/frontend/coprs_frontend/coprs/forms.py
@@ -11,6 +11,7 @@ from coprs import constants
from coprs import helpers
from coprs import models
from coprs.logic.coprs_logic import CoprsLogic
+from coprs.logic.users_logic import UsersLogic
class UrlListValidator(object):
@@ -648,7 +649,27 @@ class AdminPlaygroundSearchForm(wtf.Form):
project = wtforms.TextField("Project")
+class GroupUniqueNameValidator(object):
+
+ def __init__(self, message=None):
+ if not message:
+ message = "Group with the alias '{}' already exists."
+ self.message = message
+
+ def __call__(self, form, field):
+ if UsersLogic.group_alias_exists(field.data):
+ raise wtforms.ValidationError(self.message.format(field.data))
+
+
class ActivateFasGroupForm(wtf.Form):
- name = wtforms.StringField()
+ name = wtforms.StringField(
+ validators=[
+ wtforms.validators.Regexp(
+ re.compile(r"^[\w.-]+$"),
+ message="Name must contain only letters,"
+ "digits, underscores, dashes and dots."),
+ GroupUniqueNameValidator()
+ ]
+ )
diff --git a/frontend/coprs_frontend/coprs/logic/users_logic.py b/frontend/coprs_frontend/coprs/logic/users_logic.py
index 6249b2b..1f23b17 100644
--- a/frontend/coprs_frontend/coprs/logic/users_logic.py
+++ b/frontend/coprs_frontend/coprs/logic/users_logic.py
@@ -48,6 +48,11 @@ class UsersLogic(object):
return Group.query.filter(Group.name == name)
@classmethod
+ def group_alias_exists(cls, name):
+ query = cls.get_group_by_alias(name)
+ return query.count() != 0
+
+ @classmethod
def get_group_by_fas_name(cls, fas_name):
return Group.query.filter(Group.fas_name == fas_name)
diff --git a/frontend/coprs_frontend/coprs/templates/404.html b/frontend/coprs_frontend/coprs/templates/_error.html
similarity index 62%
copy from frontend/coprs_frontend/coprs/templates/404.html
copy to frontend/coprs_frontend/coprs/templates/_error.html
index ac78409..60e875e 100644
--- a/frontend/coprs_frontend/coprs/templates/404.html
+++ b/frontend/coprs_frontend/coprs/templates/_error.html
@@ -2,10 +2,15 @@
{% block title %}Not Found{% endblock %}
{% block header %}Not Found!{% endblock %}
{% block body %}
- <h1> Error 404: Not Found </h1>
+ <h1> Error {{ error_code }}
+ {% if error_title %}
+ : {{ error_title }}
+ {% endif %}
+
+ </h1>
{% if message %}
{{ message }}
{% else %}
- The thing you're looking for does not exist.
+ Something went wrong
{% endif %}
{% endblock %}
diff --git a/frontend/coprs_frontend/coprs/templates/groups/activate_fas_group.html b/frontend/coprs_frontend/coprs/templates/groups/activate_fas_group.html
index 39debed..15cb5f2 100644
--- a/frontend/coprs_frontend/coprs/templates/groups/activate_fas_group.html
+++ b/frontend/coprs_frontend/coprs/templates/groups/activate_fas_group.html
@@ -10,7 +10,7 @@
{% block body %}
<h3>
- Activate FAS group <strong>" "</strong> in the Copr.
+ Activate FAS group <strong>"{{ fas_group }}"</strong> in the Copr.
</h3>
<p>Please choose wisely! The name can not be changed later. And the active group can not be deactivated.</p>
diff --git a/frontend/coprs_frontend/coprs/views/coprs_ns/__init__.py b/frontend/coprs_frontend/coprs/views/coprs_ns/__init__.py
index 877f30f..f9bf00f 100644
--- a/frontend/coprs_frontend/coprs/views/coprs_ns/__init__.py
+++ b/frontend/coprs_frontend/coprs/views/coprs_ns/__init__.py
@@ -2,8 +2,8 @@
import flask
-from coprs.views.misc import page_not_found, access_restricted
-from coprs.exceptions import ObjectNotFound, AccessRestricted
+from coprs.views.misc import page_not_found, access_restricted, bad_request_handler, server_error_handler
+from coprs.exceptions import ObjectNotFound, AccessRestricted, BadRequest, CoprHttpException
coprs_ns = flask.Blueprint("coprs_ns", __name__, url_prefix="/coprs")
@@ -16,3 +16,13 @@ def handle_404(error):
@coprs_ns.errorhandler(AccessRestricted)
def handle_403(error):
return access_restricted(error.message)
+
+
+(a)coprs_ns.errorhandler(BadRequest)
+def handle_400(error):
+ return bad_request_handler(error.message)
+
+
+(a)coprs_ns.errorhandler(CoprHttpException)
+def handle_500(error):
+ return server_error_handler(error.message)
diff --git a/frontend/coprs_frontend/coprs/views/groups_ns/__init__.py b/frontend/coprs_frontend/coprs/views/groups_ns/__init__.py
index 88d5e20..64ba92e 100644
--- a/frontend/coprs_frontend/coprs/views/groups_ns/__init__.py
+++ b/frontend/coprs_frontend/coprs/views/groups_ns/__init__.py
@@ -2,4 +2,17 @@
import flask
+from coprs.views.misc import page_not_found, access_restricted
+from coprs.exceptions import ObjectNotFound, AccessRestricted
+
groups_ns = flask.Blueprint("groups_ns", __name__, url_prefix="/groups")
+
+
+(a)groups_ns.errorhandler(ObjectNotFound)
+def handle_404(error):
+ return page_not_found(error.message)
+
+
+(a)groups_ns.errorhandler(AccessRestricted)
+def handle_403(error):
+ return access_restricted(error.message)
diff --git a/frontend/coprs_frontend/coprs/views/groups_ns/groups_general.py b/frontend/coprs_frontend/coprs/views/groups_ns/groups_general.py
index 78fd456..89caa0a 100644
--- a/frontend/coprs_frontend/coprs/views/groups_ns/groups_general.py
+++ b/frontend/coprs_frontend/coprs/views/groups_ns/groups_general.py
@@ -2,6 +2,7 @@
import flask
from flask import render_template, session, url_for
+from coprs.exceptions import InsufficientRightsException
from coprs.forms import ActivateFasGroupForm
from coprs.helpers import Paginator
from coprs.logic.complex_logic import ComplexLogic
@@ -24,6 +25,12 @@ def activate_group(fas_group):
flask.flash("This group is blacklisted and cannot be added.")
return flask.redirect(url_for(
"groups_ns.list_user_groups"))
+
+ if fas_group not in flask.g.user.user_teams:
+ raise InsufficientRightsException(
+ "User '{}' doesn't have access to fas group {}"
+ .format(flask.g.user.username, fas_group))
+
alias = form.name.data
group = UsersLogic.get_group_by_fas_name_or_create(
fas_group, alias)
@@ -41,7 +48,9 @@ def activate_group(fas_group):
else:
return flask.render_template(
"groups/activate_fas_group.html",
- form=form, user=flask.g.user,
+ fas_group=fas_group,
+ form=form,
+ user=flask.g.user,
)
diff --git a/frontend/coprs_frontend/coprs/views/misc.py b/frontend/coprs_frontend/coprs/views/misc.py
index 54ed912..88f3a2f 100644
--- a/frontend/coprs_frontend/coprs/views/misc.py
+++ b/frontend/coprs_frontend/coprs/views/misc.py
@@ -1,7 +1,7 @@
import base64
import datetime
import functools
-from functools import wraps
+from functools import wraps, partial
from netaddr import IPAddress, IPNetwork
import re
@@ -82,6 +82,23 @@ def access_restricted(message):
return flask.render_template("403.html", message=message), 403
+def generic_error(message, code=500, title=None):
+ """
+ :type message: str
+ :type err: CoprHttpException
+ """
+ return flask.render_template("_error.html",
+ message=message,
+ error_code=code,
+ error_title=title), code
+
+
+server_error_handler = partial(generic_error, code=500, title="Internal Server Error")
+bad_request_handler = partial(generic_error, code=400, title="Bad Request")
+
+app.errorhandler(500)(server_error_handler)
+app.errorhandler(400)(bad_request_handler)
+
misc = flask.Blueprint("misc", __name__)
diff --git a/frontend/coprs_frontend/tests/coprs_test_case.py b/frontend/coprs_frontend/tests/coprs_test_case.py
index d56d181..10ac272 100644
--- a/frontend/coprs_frontend/tests/coprs_test_case.py
+++ b/frontend/coprs_frontend/tests/coprs_test_case.py
@@ -110,6 +110,19 @@ class CoprsTestCase(object):
self.db.session.add_all(self.basic_user_list)
@pytest.fixture
+ def f_fas_groups(self, f_users):
+ self.fas_group_names = [
+ "fas_1",
+ "fas_2",
+ "fas_3",
+ "fas_4",
+ ]
+ self.u1.openid_groups = {'fas_groups': self.fas_group_names[:2]}
+ self.db.session.add(self.u1)
+
+ return self.fas_group_names
+
+ @pytest.fixture
def f_users_api(self):
"""
Requires f_users
diff --git a/frontend/coprs_frontend/tests/test_views/test_coprs_ns/__init__.py b/frontend/coprs_frontend/tests/test_views/test_coprs_ns/__init__.py
deleted file mode 100644
index e69de29..0000000
diff --git a/frontend/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_general.py b/frontend/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_general.py
index f98934b..d5a1252 100644
--- a/frontend/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_general.py
+++ b/frontend/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_general.py
@@ -2,9 +2,8 @@ import json
import flask
import pytest
-from flexmock import flexmock
import mock
-import time
+
from coprs import models
from coprs.helpers import ActionTypeEnum
@@ -550,7 +549,8 @@ class TestCoprUpdatePermissions(CoprsTestCase):
# mock out the order of CoprPermission objects, so that we are sure
# the admin is the first one and therefore this fails if
# the view doesn"t reorder the permissions
- flexmock(self.models.Copr, copr_permissions=[self.cp3, self.cp2])
+
+ # flexmock(self.models.Copr, copr_permissions=[self.cp3, self.cp2])
r = self.test_client.post("/coprs/{0}/{1}/update_permissions/"
.format(self.u2.name, self.c3.name),
data={"copr_admin_1": "1",
diff --git a/frontend/coprs_frontend/tests/test_views/test_groups_ns/test_groups_general.py b/frontend/coprs_frontend/tests/test_views/test_groups_ns/test_groups_general.py
new file mode 100644
index 0000000..e7fb7f6
--- /dev/null
+++ b/frontend/coprs_frontend/tests/test_views/test_groups_ns/test_groups_general.py
@@ -0,0 +1,66 @@
+# coding: utf-8
+from coprs import models
+
+from coprs.logic.users_logic import UsersLogic
+
+from tests.coprs_test_case import CoprsTestCase, TransactionDecorator
+
+
+class TestGroups(CoprsTestCase):
+
+ @TransactionDecorator("u1")
+ def test_group_add(self, f_users, f_fas_groups, f_db):
+ fas_name = f_fas_groups[0]
+ alias = "alias_1"
+ assert not UsersLogic.group_alias_exists(alias)
+ r = self.test_client.post(
+ "/groups/activate/{}".format(fas_name),
+ data={"name": alias},
+ follow_redirects=True
+ )
+ assert r.status_code == 200
+ assert UsersLogic.group_alias_exists(alias)
+
+ @TransactionDecorator("u1")
+ def test_group_add_twice(self, f_users, f_fas_groups, f_db):
+ fas_name = f_fas_groups[0]
+ alias = "alias_1"
+ assert not UsersLogic.group_alias_exists(alias)
+ self.test_client.post(
+ "/groups/activate/{}".format(fas_name),
+ data={"name": alias},
+ follow_redirects=True
+ )
+ assert UsersLogic.group_alias_exists(alias)
+ assert len(models.Group.query.all()) == 1
+ self.test_client.post(
+ "/groups/activate/{}".format(fas_name),
+ data={"name": alias},
+ follow_redirects=True
+ )
+ assert len(models.Group.query.all()) == 1
+
+ @TransactionDecorator("u1")
+ def test_group_add_alias_with_space(self, f_users, f_fas_groups, f_db):
+ fas_name = f_fas_groups[0]
+ alias = "alias_1 foo bar"
+ assert not UsersLogic.group_alias_exists(alias)
+ r = self.test_client.post(
+ "/groups/activate/{}".format(fas_name),
+ data={"name": alias},
+ follow_redirects=True
+ )
+ assert not UsersLogic.group_alias_exists(alias)
+
+ @TransactionDecorator("u1")
+ def test_group_add_not_in_fas_group(self, f_users, f_fas_groups, f_db):
+ fas_name = f_fas_groups[3]
+ alias = "alias_1"
+ assert not UsersLogic.group_alias_exists(alias)
+ r = self.test_client.post(
+ "/groups/activate/{}".format(fas_name),
+ data={"name": alias},
+ follow_redirects=True
+ )
+ # assert r.status_code == 403
+ assert not UsersLogic.group_alias_exists(alias)
diff --git a/frontend/requirements.txt b/frontend/requirements.txt
index 8c3653f..e0885f9 100644
--- a/frontend/requirements.txt
+++ b/frontend/requirements.txt
@@ -12,7 +12,7 @@ pytz
markdown
pyLibravatar
pydns
-flexmock
+# py3dns
decorator
python-dateutil
netaddr
@@ -20,3 +20,5 @@ alembic
flask-restful
# flask-restful-swagger # -- nice to have, but probably later
marshmallow
+redis
+hiredis
diff --git a/frontend/run_tests.sh b/frontend/run3_tests.sh
similarity index 100%
copy from frontend/run_tests.sh
copy to frontend/run3_tests.sh
diff --git a/frontend/run_tests.sh b/frontend/run_tests.sh
index b66bd43..839f1f6 100755
--- a/frontend/run_tests.sh
+++ b/frontend/run_tests.sh
@@ -6,7 +6,7 @@ redis-server --port $REDIS_PORT &> _redis.log &
cd coprs_frontend
-COPR_CONFIG="$(pwd)/config/copr_unit_test.conf" python3 -m pytest tests -s $@ # \
+COPR_CONFIG="$(pwd)/config/copr_unit_test.conf" python -m pytest tests -s $@ # \
#--cov-report term-missing --cov coprs $@
kill %1
8 years, 6 months
[copr] master: Revert "Attributes defined outside __init__" (57f63c5)
by vgologuz@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 57f63c5b8a4a014e6290fe3287dc885e3e236dac
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Thu Nov 12 11:29:38 2015 +0100
Revert "Attributes defined outside __init__"
This reverts commit cafb54ce0c61f7c3929f3b0b6da48e3d82f16baa.
>---------------------------------------------------------------
python/copr/test/client_v2/test_client.py | 8 --------
python/copr/test/client_v2/test_handlers.py | 7 -------
python/copr/test/client_v2/test_net_client.py | 9 ---------
3 files changed, 0 insertions(+), 24 deletions(-)
diff --git a/python/copr/test/client_v2/test_client.py b/python/copr/test/client_v2/test_client.py
index fae90a0..63cde2b 100644
--- a/python/copr/test/client_v2/test_client.py
+++ b/python/copr/test/client_v2/test_client.py
@@ -15,14 +15,6 @@ from copr.client_v2.client import CoprClient
class TestClientV2(object):
- def __init__(self):
- self.login = None
- self.token = None
- self.root_url = None
- self.nc = None
- self.root_json = None
- self.response = None
-
def setup_method(self, method):
self.login = u"foo"
self.token = u"bar"
diff --git a/python/copr/test/client_v2/test_handlers.py b/python/copr/test/client_v2/test_handlers.py
index 5ec48ac..8af03ba 100644
--- a/python/copr/test/client_v2/test_handlers.py
+++ b/python/copr/test/client_v2/test_handlers.py
@@ -14,13 +14,6 @@ from copr.client_v2.handlers import ProjectHandle
class TestHandleBase(object):
- def __init__(self):
- self.nc = None
- self.client = None
- self.root_url = None
- self.response = None
- self.root_json = None
-
def setup_method(self, method):
self.nc = MagicMock()
self.client = MagicMock()
diff --git a/python/copr/test/client_v2/test_net_client.py b/python/copr/test/client_v2/test_net_client.py
index d2923b7..c574d37 100644
--- a/python/copr/test/client_v2/test_net_client.py
+++ b/python/copr/test/client_v2/test_net_client.py
@@ -22,15 +22,6 @@ def mc_request():
class TestNetClient(object):
- def __init__(self):
- self.base_response = None
- self.content = None
- self.login = None
- self.password = None
- self.base_url = None
- self.nc = None
- self.nc_with_auth = None
-
def setup_method(self, method):
# print(sys.path)
8 years, 6 months
[copr] master: show when createrepo is waiting for lock (c928d1c)
by Miroslav Suchý
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit c928d1ca485cd3ddb6e7ee1327142a5de1c3de8f
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Thu Nov 12 10:02:23 2015 +0100
show when createrepo is waiting for lock
when there is forgotten lock, it may wait indefinitely without any trace in log
log is hard to obtain here, so lets change proc title.
it will be nice to move it to logger sometime in future
>---------------------------------------------------------------
backend/backend/createrepo.py | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/backend/backend/createrepo.py b/backend/backend/createrepo.py
index 60bc804..f6302d4 100644
--- a/backend/backend/createrepo.py
+++ b/backend/backend/createrepo.py
@@ -1,6 +1,7 @@
import os
import subprocess
+from setproctitle import getproctitle, setproctitle
from shlex import split
from lockfile import LockFile
@@ -16,13 +17,16 @@ from .exceptions import CreateRepoError
def run_cmd_unsafe(comm_str, lock_path):
# log.info("Running command: {}".format(comm_str))
comm = split(comm_str)
+ title = getproctitle()
try:
+ # TODO change this to logger
+ setproctitle("[locked] in createrepo")
with LockFile(lock_path):
cmd = subprocess.Popen(comm, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = cmd.communicate()
-
except Exception as err:
raise CreateRepoError(msg="Failed to execute: {}".format(err), cmd=comm_str)
+ setproctitle(title)
if cmd.returncode != 0:
raise CreateRepoError(msg="exit code != 0",
8 years, 6 months
[copr] master: do not block builds when processin too much actions (bf8ddd7)
by Miroslav Suchý
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit bf8ddd79893a7e034a1af77fad69bddd02b5fa02
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Thu Nov 12 09:25:53 2015 +0100
do not block builds when processin too much actions
it happened that we have thousands actions in queue, each of them last ~1 minute, so it blocked
builds for nearly a day
just stop processing action, when we reach some limit (10*timeout seems as reasonable) and forget about remaining actions
We will load it when there will next loop of JobGrabber so nothing is lost, and we will not block the builds
>---------------------------------------------------------------
backend/backend/daemons/job_grab.py | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/backend/backend/daemons/job_grab.py b/backend/backend/daemons/job_grab.py
index c8b1eb6..558ae57 100644
--- a/backend/backend/daemons/job_grab.py
+++ b/backend/backend/daemons/job_grab.py
@@ -164,13 +164,19 @@ class CoprJobGrab(object):
self.log.info("New build jobs: %s" % count)
if r_json.get("actions"):
+ count = 0
self.log.info("{0} actions returned".format(len(r_json["actions"])))
for action in r_json["actions"]:
+ start = time.time()
try:
self.process_action(action)
except Exception as error:
self.log.exception("Error during processing action `{}`: {}".format(action, error))
+ if time.time() - start > 2*self.opts.sleeptime:
+ # we are processing actions for too long, stop and fetch everything again (including new builds)
+ break
+
def on_pubsub_event(self, raw):
# from celery.contrib import rdb; rdb.set_trace()
8 years, 6 months
[copr] master: convert comment to docstring (33fb1bb)
by Miroslav Suchý
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 33fb1bb351ae060341536d9d14f84c376e20d02f
Author: Miroslav Suchý <miroslav(a)suchy.cz>
Date: Tue Nov 10 15:44:47 2015 +0100
convert comment to docstring
>---------------------------------------------------------------
backend/backend/daemons/job_grab.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/backend/backend/daemons/job_grab.py b/backend/backend/daemons/job_grab.py
index a638865..c8b1eb6 100644
--- a/backend/backend/daemons/job_grab.py
+++ b/backend/backend/daemons/job_grab.py
@@ -38,7 +38,7 @@ class CoprJobGrab(object):
"""
def __init__(self, opts, frontend_client):
- # base class initialization
+ """ base class initialization """
self.opts = opts
self.arch_to_group_id_map = dict()
8 years, 6 months
[copr] master: W: 38, 0: Class has no __init__ method (no-init) (3771dec)
by frostyx@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 3771dec07be2e81d392d30d323378654841ca1c3
Author: Jakub Kadlčík <jkadlcik(a)redhat.com>
Date: Mon Nov 9 14:57:59 2015 +0100
W: 38, 0: Class has no __init__ method (no-init)
>---------------------------------------------------------------
python/copr/client_v2/client.py | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/python/copr/client_v2/client.py b/python/copr/client_v2/client.py
index c847ee4..3fa70b6 100644
--- a/python/copr/client_v2/client.py
+++ b/python/copr/client_v2/client.py
@@ -38,6 +38,10 @@ log.addHandler(NullHandler())
class HandlersProvider(with_metaclass(ABCMeta)):
@abstractproperty
+ def __init__(self):
+ pass
+
+ @abstractproperty
def projects(self):
"""
:rtype: ProjectHandle
8 years, 6 months
[copr] master: C: 36, 4: Metaclass class method __new__ should have 'mcs' as first argument (bad-mcs-classmethod-argument) (9edc439)
by frostyx@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 9edc439f650baeab97816eadc0bf798ac974fc13
Author: Jakub Kadlčík <jkadlcik(a)redhat.com>
Date: Mon Nov 9 15:18:39 2015 +0100
C: 36, 4: Metaclass class method __new__ should have 'mcs' as first argument (bad-mcs-classmethod-argument)
>---------------------------------------------------------------
python/copr/client_v2/resources.py | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/python/copr/client_v2/resources.py b/python/copr/client_v2/resources.py
index 1c03700..0412548 100644
--- a/python/copr/client_v2/resources.py
+++ b/python/copr/client_v2/resources.py
@@ -33,12 +33,12 @@ class EntityFieldsMetaClass(type):
Magic: we take fields info from class._schema and attach EntityFieldDescriptor
to Resource classes
"""
- def __new__(cls, class_name, bases, class_attrs):
+ def __new__(mcs, class_name, bases, class_attrs):
schema = class_attrs.get("_schema")
if schema:
for f_name, f in schema.fields.items():
class_attrs[f_name] = EntityFieldDescriptor(f_name)
- return type.__new__(cls, class_name, bases, class_attrs)
+ return type.__new__(mcs, class_name, bases, class_attrs)
class IndividualResource(with_metaclass(EntityFieldsMetaClass, UnicodeMixin)):
8 years, 6 months
[copr] master: W: 92, 4: __init__ method from base class 'HandlersProvider' is not called (super-init-not-called) (c84b91f)
by frostyx@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit c84b91f21a9d3900087f3ebd9b6bf95c97b8159c
Author: Jakub Kadlčík <jkadlcik(a)redhat.com>
Date: Mon Nov 9 15:15:24 2015 +0100
W: 92, 4: __init__ method from base class 'HandlersProvider' is not called (super-init-not-called)
>---------------------------------------------------------------
python/copr/client_v2/client.py | 7 +------
1 files changed, 1 insertions(+), 6 deletions(-)
diff --git a/python/copr/client_v2/client.py b/python/copr/client_v2/client.py
index 3fa70b6..afa7045 100644
--- a/python/copr/client_v2/client.py
+++ b/python/copr/client_v2/client.py
@@ -35,11 +35,7 @@ log = logging.getLogger(__name__)
log.addHandler(NullHandler())
-class HandlersProvider(with_metaclass(ABCMeta)):
-
- @abstractproperty
- def __init__(self):
- pass
+class HandlersProvider(object, with_metaclass(ABCMeta)):
@abstractproperty
def projects(self):
@@ -74,7 +70,6 @@ class HandlersProvider(with_metaclass(ABCMeta)):
pass
-
class CoprClient(UnicodeMixin, HandlersProvider):
""" Main interface to the copr service
8 years, 6 months