Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : master
---------------------------------------------------------------
commit 45535f53b8a10c396876e12011d9148c05d6b9d4
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Thu Oct 23 18:06:09 2014 +0200
[backend] passing username/projectname to Action::delete_build
---------------------------------------------------------------
backend/backend/actions.py | 14 ++++++--
backend/copr-be.py | 3 +-
backend/tests/test_action.py | 35 ++++++++++++-------
.../coprs_frontend/coprs/logic/builds_logic.py | 7 +++-
.../test_views/test_coprs_ns/test_coprs_builds.py | 3 +-
5 files changed, 42 insertions(+), 20 deletions(-)
diff --git a/backend/backend/actions.py b/backend/backend/actions.py
index d9b4f00..3da35e7 100644
--- a/backend/backend/actions.py
+++ b/backend/backend/actions.py
@@ -1,10 +1,11 @@
+import json
import os.path
import shutil
import time
from bunch import Bunch
-from mockremote import createrepo
+from .createrepo import createrepo
class Action(object):
@@ -23,13 +24,14 @@ class Action(object):
"""
- def __init__(self, events, action, lock, frontend_callback, destdir):
+ def __init__(self, events, action, lock, frontend_callback, destdir, front_url):
super(Action, self).__init__()
self.frontend_callback = frontend_callback
self.destdir = destdir
self.data = action
self.events = events
self.lock = lock
+ self.front_url = front_url
def event(self, what):
self.events.put({"when": time.time(), "who":
"action", "what": what})
@@ -66,8 +68,11 @@ class Action(object):
def handle_delete_build(self):
self.event("Action delete build")
project = self.data["old_value"]
+ ext_data = json.loads(self.data["data"])
+
packages = [os.path.basename(x).replace(".src.rpm", "") for x
in \
- self.data["data"].split()]
+ ext_data["pkgs"].split()]
+ # self.data["data"].split()]
path = os.path.join(self.destdir, project)
@@ -106,7 +111,8 @@ class Action(object):
if altered:
self.event("Running createrepo")
- _, _, err = createrepo(os.path.join(path, chroot), self.lock)
+ _, _, err = createrepo(path=os.path.join(path, chroot),
lock=self.lock,
+ front_url=self.front_url)
if err.strip():
self.event(
"Error making local repo: {0}".format(err))
diff --git a/backend/copr-be.py b/backend/copr-be.py
index c213770..bc60ea8 100755
--- a/backend/copr-be.py
+++ b/backend/copr-be.py
@@ -112,7 +112,8 @@ class CoprJobGrab(multiprocessing.Process):
for action in r_json["actions"]:
ao = Action(self.events, action, self.lock, destdir=self.opts.destdir,
- frontend_callback=FrontendCallback(self.opts))
+ frontend_callback=FrontendCallback(self.opts),
+ front_url=self.opts.frontend_url)
ao.run()
def run(self):
diff --git a/backend/tests/test_action.py b/backend/tests/test_action.py
index 934765d..e0c4515 100644
--- a/backend/tests/test_action.py
+++ b/backend/tests/test_action.py
@@ -75,7 +75,7 @@ class TestAction(object):
def test_action_event(self, mc_time):
test_action = Action(events=self.test_q, action={}, lock=None,
- frontend_callback=None, destdir=None)
+ frontend_callback=None, destdir=None, front_url=None)
with pytest.raises(EmptyQueue):
test_action.events.get_nowait()
@@ -98,7 +98,8 @@ class TestAction(object):
},
events=self.test_q, lock=None,
frontend_callback=mc_front_cb,
- destdir=None
+ destdir=None,
+ front_url=None
)
test_action.run()
assert not mc_front_cb.called
@@ -128,7 +129,8 @@ class TestAction(object):
},
events=self.test_q, lock=None,
frontend_callback=mc_front_cb,
- destdir=tmp_dir
+ destdir=tmp_dir,
+ front_url=None
)
test_action.run()
result_dict = mc_front_cb.update.call_args[0][0]["actions"][0]
@@ -158,7 +160,8 @@ class TestAction(object):
},
events=self.test_q, lock=None,
frontend_callback=mc_front_cb,
- destdir=os.path.join(tmp_dir, "dir-not-exists")
+ destdir=os.path.join(tmp_dir, "dir-not-exists"),
+ front_url=None
)
test_action.run()
result_dict = mc_front_cb.update.call_args[0][0]["actions"][0]
@@ -187,7 +190,8 @@ class TestAction(object):
},
events=self.test_q, lock=None,
frontend_callback=mc_front_cb,
- destdir=tmp_dir
+ destdir=tmp_dir,
+ front_url=None
)
test_action.run()
result_dict = mc_front_cb.update.call_args[0][0]["actions"][0]
@@ -216,7 +220,8 @@ class TestAction(object):
},
events=self.test_q, lock=None,
frontend_callback=mc_front_cb,
- destdir=os.path.join(tmp_dir, "dir-not-exists")
+ destdir=os.path.join(tmp_dir, "dir-not-exists"),
+ front_url=None
)
test_action.run()
@@ -250,7 +255,8 @@ class TestAction(object):
},
events=self.test_q, lock=None,
frontend_callback=mc_front_cb,
- destdir=tmp_dir
+ destdir=tmp_dir,
+ front_url=None
)
test_action.run()
@@ -286,11 +292,12 @@ class TestAction(object):
"object_type": obj_type,
"id": 7,
"old_value": "not-existing-project",
- "data": " ".join(self.pkgs),
+ "data": json.dumps({"pkgs": "
".join(self.pkgs)}),
},
events=self.test_q, lock=None,
frontend_callback=mc_front_cb,
- destdir=tmp_dir
+ destdir=tmp_dir,
+ front_url=None
)
with mock.patch("backend.actions.shutil") as mc_shutil:
test_action.run()
@@ -342,12 +349,13 @@ class TestAction(object):
"object_type": "build-succeeded",
"id": 7,
"old_value": "old_dir",
- "data": " ".join(self.pkgs),
+ "data": json.dumps({"pkgs": "
".join(self.pkgs)}),
"object_id": 42
},
events=self.test_q, lock=None,
frontend_callback=mc_front_cb,
- destdir=tmp_dir
+ destdir=tmp_dir,
+ front_url=None,
)
assert os.path.exists(foo_pkg_dir)
@@ -421,12 +429,13 @@ class TestAction(object):
"object_type": "build-succeeded",
"id": 7,
"old_value": "old_dir",
- "data": " ".join(self.pkgs),
+ "data": json.dumps({"pkgs": "
".join(self.pkgs)}),
"object_id": 42
},
events=self.test_q, lock=None,
frontend_callback=mc_front_cb,
- destdir=tmp_dir
+ destdir=tmp_dir,
+ front_url=None
)
test_action.run()
diff --git a/frontend/coprs_frontend/coprs/logic/builds_logic.py
b/frontend/coprs_frontend/coprs/logic/builds_logic.py
index 225ecfe..e1907ec 100644
--- a/frontend/coprs_frontend/coprs/logic/builds_logic.py
+++ b/frontend/coprs_frontend/coprs/logic/builds_logic.py
@@ -1,3 +1,4 @@
+import json
import os
import time
from sqlalchemy import or_
@@ -211,12 +212,16 @@ class BuildsLogic(object):
# Only failed (and finished), succeeded, skipped and cancelled get here.
if build.state != "cancelled": #has nothing in backend to delete
object_type = "build-{0}".format(build.state)
+ data_dict = {"pkgs": build.pkgs,
+ "username": build.copr.owner.name,
+ "project": build.copr.name}
+
action =
models.Action(action_type=helpers.ActionTypeEnum("delete"),
object_type=object_type,
object_id=build.id,
old_value="{0}/{1}".format(build.copr.owner.name,
build.copr.name),
- data=build.pkgs,
+ data=json.dumps(data_dict),
created_on=int(time.time()))
db.session.add(action)
diff --git a/frontend/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_builds.py
b/frontend/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_builds.py
index 47e3a8b..1be3cc2 100644
--- a/frontend/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_builds.py
+++ b/frontend/coprs_frontend/tests/test_views/test_coprs_ns/test_coprs_builds.py
@@ -1,3 +1,4 @@
+import json
from coprs import models
from tests.coprs_test_case import CoprsTestCase, TransactionDecorator
@@ -119,7 +120,7 @@ class TestCoprDeleteBuild(CoprsTestCase):
act = self.models.Action.query.first()
assert act.object_type == "build-succeeded"
assert act.old_value == "user1/foocopr"
- assert act.data == pkgs
+ assert json.loads(act.data)["pkgs"] == pkgs
@TransactionDecorator("u2")
def test_copr_build_non_submitter_cannot_delete_build(self, f_users,