Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : master
---------------------------------------------------------------
commit 86a663772910d7eabbe7a983c9029a195f796ec5
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Fri Sep 11 18:52:39 2015 +0200
[backend] eliminate global multiprocessing.Lock
---------------------------------------------------------------
backend/backend/actions.py | 14 ++---
backend/backend/createrepo.py | 33 ++++-----
backend/backend/daemons/job_grab.py | 4 +-
backend/backend/mockremote/__init__.py | 1 -
backend/copr-backend.spec | 5 +-
backend/run/systemd/copr-backend.service | 2 +-
backend/tests/deamons/test_backend.py | 22 +------
backend/tests/deamons/test_job_grab.py | 2 +-
backend/tests/mockremote/test_mockremote.py | 1 -
backend/tests/test_action.py | 39 ++---------
backend/tests/test_createrepo.py | 94 +++++++++------------------
11 files changed, 64 insertions(+), 153 deletions(-)
diff --git a/backend/backend/actions.py b/backend/backend/actions.py
index 7548757..dc3c35d 100644
--- a/backend/backend/actions.py
+++ b/backend/backend/actions.py
@@ -6,15 +6,14 @@ from urllib import urlretrieve
from munch import Munch
-from .createrepo import createrepo, createrepo_unsafe
-from exceptions import CreateRepoError
+from .createrepo import createrepo
+from .exceptions import CreateRepoError
from .helpers import get_redis_logger, silent_remove
class Action(object):
""" Object to send data back to fronted
- :param multiprocessing.Lock lock: Global lock for backend
:param backend.callback.FrontendCallback frontent_callback:
object to post data back to frontend
@@ -29,14 +28,12 @@ class Action(object):
"""
# TODO: get more form opts, decrease number of parameters
- def __init__(self, opts, action, lock, frontend_client):
+ def __init__(self, opts, action, frontend_client):
self.opts = opts
self.frontend_client = frontend_client
self.data = action
- self.lock = lock
-
self.destdir = self.opts.destdir
self.front_url = self.opts.frontend_base_url
self.results_root_url = self.opts.results_baseurl
@@ -66,8 +63,7 @@ class Action(object):
try:
createrepo(path=path, front_url=self.front_url,
username=username, projectname=projectname,
- override_acr_flag=True,
- lock=self.lock)
+ override_acr_flag=True)
done_count += 1
except CreateRepoError:
self.log.exception("Error making local repo for: {}/{}/{}"
@@ -194,7 +190,7 @@ class Action(object):
createrepo_target = os.path.join(path, chroot)
try:
createrepo(
- path=createrepo_target, lock=self.lock,
+ path=createrepo_target,
front_url=self.front_url, base_url=result_base_url,
username=username, projectname=projectname
)
diff --git a/backend/backend/createrepo.py b/backend/backend/createrepo.py
index 8a36e57..e6520e4 100644
--- a/backend/backend/createrepo.py
+++ b/backend/backend/createrepo.py
@@ -2,8 +2,8 @@ import os
import subprocess
from subprocess import Popen, PIPE
-from exceptions import CreateRepoError
from shlex import split
+from lockfile import LockFile
# todo: add logging here
# from backend.helpers import BackendConfigReader, get_redis_logger
@@ -11,20 +11,17 @@ from shlex import split
# log = get_redis_logger(opts, "createrepo", "actions")
from .helpers import get_auto_createrepo_status
+from .exceptions import CreateRepoError
-def run_cmd_unsafe(comm_str, lock=None):
+def run_cmd_unsafe(comm_str, lock_path):
# log.info("Running command: {}".format(comm_str))
comm = split(comm_str)
try:
- # # todo: replace with file lock on target dir
- if lock:
- with lock:
- cmd = Popen(comm, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- out, err = cmd.communicate()
- else:
+ with LockFile(lock_path):
cmd = 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)
@@ -35,7 +32,7 @@ def run_cmd_unsafe(comm_str, lock=None):
return out
-def createrepo_unsafe(path, lock=None, dest_dir=None, base_url=None):
+def createrepo_unsafe(path, dest_dir=None, base_url=None):
"""
Run createrepo_c on the given path
@@ -73,7 +70,7 @@ def createrepo_unsafe(path, lock=None, dest_dir=None, base_url=None):
comm.append(path)
- return run_cmd_unsafe(" ".join(map(str, comm)), lock)
+ return run_cmd_unsafe(" ".join(map(str, comm)), os.path.join(path,
"createrepo.lock"))
APPDATA_CMD_TEMPLATE = \
@@ -115,20 +112,20 @@ def add_appdata(path, username, projectname, lock=None):
}
try:
out += "\n" + run_cmd_unsafe(
- APPDATA_CMD_TEMPLATE.format(**kwargs), lock)
+ APPDATA_CMD_TEMPLATE.format(**kwargs), os.path.join(path,
"createrepo.lock"))
if os.path.exists(os.path.join(path, "appdata",
"appstream.xml.gz")):
out += "\n" + run_cmd_unsafe(
- INCLUDE_APPSTREAM.format(**kwargs), lock)
+ INCLUDE_APPSTREAM.format(**kwargs), os.path.join(path,
"createrepo.lock"))
if os.path.exists(os.path.join(path, "appdata",
"appstream-icons.tar.gz")):
out += "\n" + run_cmd_unsafe(
- INCLUDE_ICONS.format(**kwargs), lock)
+ INCLUDE_ICONS.format(**kwargs), os.path.join(path,
"createrepo.lock"))
# appstream builder provide strange access rights to result dir
# fix them, so that lighttpd could serve appdata dir
out += "\n" + run_cmd_unsafe("chmod -R +rX {packages_dir}"
- .format(**kwargs), lock)
+ .format(**kwargs), os.path.join(path,
"createrepo.lock"))
except CreateRepoError as err:
err.stdout = out + "\nLast command\n" + err.stdout
raise
@@ -136,7 +133,7 @@ def add_appdata(path, username, projectname, lock=None):
def createrepo(path, front_url, username, projectname,
- override_acr_flag=False, base_url=None, lock=None):
+ override_acr_flag=False, base_url=None):
"""
Creates repo depending on the project setting "auto_createrepo".
When enabled creates `repodata` at the provided path, otherwise
@@ -156,8 +153,8 @@ def createrepo(path, front_url, username, projectname,
acr_flag = get_auto_createrepo_status(front_url, username, projectname)
if override_acr_flag or acr_flag:
- out_cr = createrepo_unsafe(path, lock)
- out_ad = add_appdata(path, username, projectname, lock)
+ out_cr = createrepo_unsafe(path)
+ out_ad = add_appdata(path, username, projectname)
return "\n".join([out_cr, out_ad])
else:
- return createrepo_unsafe(path, lock, base_url=base_url,
dest_dir="devel")
+ return createrepo_unsafe(path, base_url=base_url, dest_dir="devel")
diff --git a/backend/backend/daemons/job_grab.py b/backend/backend/daemons/job_grab.py
index 92d8504..df6e98e 100644
--- a/backend/backend/daemons/job_grab.py
+++ b/backend/backend/daemons/job_grab.py
@@ -58,7 +58,7 @@ class CoprJobGrab(Process):
self.task_queues_by_group = {}
self.added_jobs_dict = dict() # task_id -> task dict
- self.lock = lock
+ self.lock = lock # used only for createrepo calls
self.frontend_client = frontend_client
@@ -139,7 +139,7 @@ class CoprJobGrab(Process):
:param action: dict-like object with action task
"""
- ao = Action(self.opts, action, self.lock, frontend_client=self.frontend_client)
+ ao = Action(self.opts, action, frontend_client=self.frontend_client)
ao.run()
def load_tasks(self):
diff --git a/backend/backend/mockremote/__init__.py
b/backend/backend/mockremote/__init__.py
index aec2081..ceffc28 100755
--- a/backend/backend/mockremote/__init__.py
+++ b/backend/backend/mockremote/__init__.py
@@ -243,7 +243,6 @@ class MockRemote(object):
base_url=base_url,
username=self.job.project_owner,
projectname=self.job.project_name,
- lock=self.lock,
)
except CreateRepoError:
self.log.exception("Error making local repo:
{}".format(self.chroot_dir))
diff --git a/backend/copr-backend.spec b/backend/copr-backend.spec
index 3ddd257..bb8fe0e 100644
--- a/backend/copr-backend.spec
+++ b/backend/copr-backend.spec
@@ -28,16 +28,14 @@ BuildRequires: python-copr
BuildRequires: systemd
BuildRequires: redis
-
-
BuildRequires: pytest
BuildRequires: python-pytest-cov
BuildRequires: python-mock
BuildRequires: python-six
BuildRequires: python-munch
+BuildRequires: python-lockfile
# missing python3
BuildRequires: python-daemon
-BuildRequires: python-lockfile
BuildRequires: python-requests
BuildRequires: python-setproctitle
# missing python3
@@ -85,6 +83,7 @@ Requires: fedmsg
Requires: gawk
Requires: crontabs
Requires: python-paramiko
+Requires: python-lockfile
# Requires: python-ipdb
Requires: logstash
Requires: libappstream-glib-builder >= 0.4.0
diff --git a/backend/run/systemd/copr-backend.service
b/backend/run/systemd/copr-backend.service
index ea43924..ce3a4ef 100644
--- a/backend/run/systemd/copr-backend.service
+++ b/backend/run/systemd/copr-backend.service
@@ -1,5 +1,5 @@
[Unit]
-Description=Copr Backend service, Virtual Machine Management component
+Description=Copr Backend service, Workers controller
After=syslog.target network.target auditd.service
Requires=copr-backend-vmm.service
Wants=copr-backend-log.service
diff --git a/backend/tests/deamons/test_backend.py
b/backend/tests/deamons/test_backend.py
index 37fade0..7d047d4 100644
--- a/backend/tests/deamons/test_backend.py
+++ b/backend/tests/deamons/test_backend.py
@@ -124,19 +124,6 @@ class TestBackend(object):
self.be = CoprBackend(self.config_file, self.ext_opts)
self.be.log = MagicMock()
- @pytest.yield_fixture
- def mc_vmm_stuff(self):
- patchers = []
- for klass_name in ["Spawner", "HealthChecker",
"Terminator",
- "VmManager", "VmMaster",
"EventHandler"]:
- patcher = mock.patch("{}.{}".format(MODULE_REF, klass_name))
- patchers.append(patcher)
- setattr(self, klass_name, patcher.start())
-
- yield None
- for patcher in patchers:
- patcher.stop()
-
def teardown_method(self, method):
# print("\nremove: {}".format(self.tmp_dir_path))
shutil.rmtree(self.tmp_dir_path)
@@ -192,9 +179,8 @@ class TestBackend(object):
with pytest.raises(CoprBackendError):
self.be.init_task_queues()
- @mock.patch("backend.daemons.backend.RedisLogHandler")
@mock.patch("backend.daemons.backend.CoprJobGrab")
- def test_dummy_init_sub_process(self, mc_jobgrab, mc_rlh, init_be, mc_vmm_stuff):
+ def test_dummy_init_sub_process(self, mc_jobgrab, init_be):
self.be.init_sub_process()
assert mc_jobgrab.called
@@ -203,12 +189,6 @@ class TestBackend(object):
lock=self.be.lock)
assert mc_jobgrab.return_value.start.called
- assert mc_rlh.called
- assert mc_rlh.return_value.start.called
-
- assert self.VmMaster.called
- assert self.VmMaster.return_value.start.called
-
def test_update_conf(self, init_be):
test_obj = MagicMock()
self.bc_obj.read.return_value = test_obj
diff --git a/backend/tests/deamons/test_job_grab.py
b/backend/tests/deamons/test_job_grab.py
index 0ff8068..b1cf828 100644
--- a/backend/tests/deamons/test_job_grab.py
+++ b/backend/tests/deamons/test_job_grab.py
@@ -220,7 +220,7 @@ class TestJobGrab(object):
self.jg.process_action(test_action)
- expected_call = call(self.opts, test_action, self.lock,
frontend_client=self.jg.frontend_client)
+ expected_call = call(self.opts, test_action,
frontend_client=self.jg.frontend_client)
assert expected_call == mc_action.call_args
assert mc_action.return_value.run.called
diff --git a/backend/tests/mockremote/test_mockremote.py
b/backend/tests/mockremote/test_mockremote.py
index fb13c13..ff0aabc 100644
--- a/backend/tests/mockremote/test_mockremote.py
+++ b/backend/tests/mockremote/test_mockremote.py
@@ -146,7 +146,6 @@ class TestMockRemote(object):
base_url=u"/".join([self.BASE_URL, COPR_OWNER, COPR_NAME,
self.CHROOT]),
username=COPR_OWNER,
projectname=COPR_NAME,
- lock=None,
)
assert mc_createrepo.call_args == expected_call
diff --git a/backend/tests/test_action.py b/backend/tests/test_action.py
index 252d39d..e029740 100644
--- a/backend/tests/test_action.py
+++ b/backend/tests/test_action.py
@@ -93,7 +93,6 @@ class TestAction(object):
"action_type": ActionType.LEGAL_FLAG,
"id": 1
},
- lock=None,
frontend_client=mc_front_cb,
)
test_action.run()
@@ -119,7 +118,6 @@ class TestAction(object):
"old_value": "old_dir",
"new_value": "new_dir"
},
- lock=None,
frontend_client=mc_front_cb,
)
test_action.run()
@@ -150,7 +148,6 @@ class TestAction(object):
"old_value": "old_dir",
"new_value": "new_dir"
},
- lock=None,
frontend_client=mc_front_cb,
)
test_action.run()
@@ -180,7 +177,6 @@ class TestAction(object):
"old_value": "old_dir",
"new_value": "new_dir"
},
- lock=None,
frontend_client=mc_front_cb,
)
test_action.run()
@@ -210,7 +206,6 @@ class TestAction(object):
"id": 6,
"old_value": "old_dir",
},
- lock=None,
frontend_client=mc_front_cb,
)
test_action.run()
@@ -236,7 +231,6 @@ class TestAction(object):
"id": 6,
"old_value": "old_dir",
},
- lock=None,
frontend_client=mc_front_cb
)
test_action.run()
@@ -263,7 +257,6 @@ class TestAction(object):
"old_value": "not-existing-project",
"data": self.ext_data_for_delete_build,
},
- lock=None,
frontend_client=mc_front_cb
)
with mock.patch("backend.actions.shutil") as mc_shutil:
@@ -305,7 +298,6 @@ class TestAction(object):
"data": self.ext_data_for_delete_build,
"object_id": 42
},
- lock=None,
frontend_client=mc_front_cb,
)
@@ -320,7 +312,6 @@ class TestAction(object):
username=u'foo',
projectname=u'bar',
base_url=u'http://example.com/results/foo/bar/fedora20';,
- lock=None,
path='{}/old_dir/fedora20'.format(self.tmp_dir_name),
front_url=None
)
@@ -357,19 +348,18 @@ class TestAction(object):
"data": self.ext_data_for_delete_build,
"object_id": 42,
},
- lock=None,
frontend_client=mc_front_cb,
)
test_action.run()
@mock.patch("backend.actions.createrepo")
- def test_delete_two_chroots(self, mc_createrepo_unsafe, mc_time):
+ def test_delete_two_chroots(self, mc_createrepo, mc_time):
"""
Regression test,
https://bugzilla.redhat.com/show_bug.cgi?id=1171796
"""
- mc_createrepo_unsafe.return_value = 0, STDOUT, ""
+ mc_createrepo.return_value = 0, STDOUT, ""
resource_name = "1171796.tar.gz"
self.unpack_resource(resource_name)
@@ -389,7 +379,7 @@ class TestAction(object):
mc_time.time.return_value = self.test_time
mc_front_cb = MagicMock()
- self.opts.destdir=self.tmp_dir_name
+ self.opts.destdir = self.tmp_dir_name
test_action = Action(
opts=self.opts,
action={
@@ -405,7 +395,6 @@ class TestAction(object):
"chroots": ["fedora-20-x86_64",
"fedora-21-x86_64"]
}),
},
- lock=None,
frontend_client=mc_front_cb,
)
test_action.run()
@@ -423,12 +412,12 @@ class TestAction(object):
assert os.path.exists(chroot_21_path)
@mock.patch("backend.actions.createrepo")
- def test_delete_two_chroots_two_remains(self, mc_createrepo_unsafe, mc_time):
+ def test_delete_two_chroots_two_remains(self, mc_createrepo, mc_time):
"""
Regression test,
https://bugzilla.redhat.com/show_bug.cgi?id=1171796
extended: we also put two more chroots, which should be unaffected
"""
- mc_createrepo_unsafe.return_value = 0, STDOUT, ""
+ mc_createrepo.return_value = 0, STDOUT, ""
resource_name = "1171796_doubled.tar.gz"
self.unpack_resource(resource_name)
@@ -472,7 +461,6 @@ class TestAction(object):
"chroots": ["fedora-20-x86_64",
"fedora-21-x86_64"]
}),
},
- lock=None,
frontend_client=mc_front_cb
)
test_action.run()
@@ -524,7 +512,6 @@ class TestAction(object):
"chroots": ["fedora-20-x86_64",
"fedora-21-x86_64"]
}),
},
- lock=None,
frontend_client=mc_front_cb,
)
@@ -535,15 +522,6 @@ class TestAction(object):
assert os.path.exists(chroot_20_path)
assert os.path.exists(chroot_21_path)
-
- @mock.patch("backend.actions.createrepo_unsafe")
- def test_delete_two_chroots_two_builds_stay_untouched(self, mc_createrepo_unsafe,
mc_time):
- # TODO: prepare archive
- """
- Before: 2 builds of the same package-version, all using different chroot
- """
- pass
-
@mock.patch("backend.actions.createrepo")
def test_handle_createrepo_ok(self, mc_createrepo, mc_time):
mc_front_cb = MagicMock()
@@ -563,7 +541,6 @@ class TestAction(object):
"data": action_data,
"id": 8
},
- lock=None,
frontend_client=mc_front_cb,
)
test_action.run()
@@ -575,10 +552,10 @@ class TestAction(object):
exp_call_1 = mock.call(path=tmp_dir + u'/foo/bar/epel-6-i386',
front_url=self.opts.frontend_base_url,
override_acr_flag=True,
- username=u"foo", projectname=u"bar",
lock=None)
+ username=u"foo", projectname=u"bar")
exp_call_2 = mock.call(path=tmp_dir + u'/foo/bar/fedora-20-x86_64',
front_url=self.opts.frontend_base_url,
override_acr_flag=True,
- username=u"foo", projectname=u"bar",
lock=None)
+ username=u"foo", projectname=u"bar")
assert exp_call_1 in mc_createrepo.call_args_list
assert exp_call_2 in mc_createrepo.call_args_list
assert len(mc_createrepo.call_args_list) == 2
@@ -603,7 +580,6 @@ class TestAction(object):
"data": action_data,
"id": 9
},
- lock=None,
frontend_client=mc_front_cb,
)
test_action.run()
@@ -635,7 +611,6 @@ class TestAction(object):
"data": action_data,
"id": 10
},
- lock=None,
frontend_client=mc_front_cb,
)
test_action.run()
diff --git a/backend/tests/test_createrepo.py b/backend/tests/test_createrepo.py
index d982b8f..ec1bba7 100644
--- a/backend/tests/test_createrepo.py
+++ b/backend/tests/test_createrepo.py
@@ -29,14 +29,14 @@ def test_createrepo_conditional_true(mc_client, mc_add_appdata,
mc_create_unsafe
mc_add_appdata.return_value = ""
createrepo(path="/tmp/",
front_url="http://example.com/api",
- username="foo", projectname="bar", lock=None)
+ username="foo", projectname="bar")
mc_create_unsafe.reset_mock()
mc_client.return_value.get_project_details.return_value = MagicMock(
data={"detail": {"auto_createrepo": True}})
createrepo(path="/tmp/",
front_url="http://example.com/api",
- username="foo", projectname="bar", lock=None)
+ username="foo", projectname="bar")
mc_create_unsafe.reset_mock()
@@ -48,9 +48,9 @@ def test_createrepo_conditional_false(mc_client, mc_create_unsafe):
base_url = "http://example.com/repo/"
createrepo(path="/tmp/",
front_url="http://example.com/api",
- username="foo", projectname="bar", base_url=base_url,
lock=None)
+ username="foo", projectname="bar", base_url=base_url)
- assert mc_create_unsafe.call_args == mock.call('/tmp/', None,
dest_dir='devel', base_url=base_url)
+ assert mc_create_unsafe.call_args == mock.call('/tmp/',
dest_dir='devel', base_url=base_url)
@pytest.yield_fixture
@@ -111,38 +111,35 @@ class TestCreaterepo(object):
mc_popen.return_value.communicate.return_value = ("stdout",
"stderr")
mc_popen.return_value.returncode = 0
- for lock in [None, MagicMock()]:
- assert run_cmd_unsafe(cmd, lock) == "stdout"
- assert mc_popen.call_args[0][0] == ["foo", "--bar"]
- mc_popen.reset()
+ assert run_cmd_unsafe(cmd, self.tmp_dir_name) == "stdout"
+ mc_popen.reset()
def test_run_cmd_unsafe_err_popen(self, mc_popen):
cmd = "foo --bar"
mc_popen.side_effect = IOError()
- for lock in [None, MagicMock()]:
- with pytest.raises(CreateRepoError) as err:
- run_cmd_unsafe(cmd, lock) == "stdout"
+ with pytest.raises(CreateRepoError) as err:
+ run_cmd_unsafe(cmd, self.tmp_dir_name) == "stdout"
- assert err.value.cmd == cmd
- assert mc_popen.call_args[0][0] == ["foo", "--bar"]
- mc_popen.reset()
+ assert err.value.cmd == cmd
+ assert mc_popen.call_args[0][0] == ["foo", "--bar"]
+ mc_popen.reset()
def test_run_cmd_unsafe_err_return_code(self, mc_popen):
cmd = "foo --bar"
mc_popen.return_value.communicate.return_value = ("stdout",
"stderr")
mc_popen.return_value.returncode = 1
- for lock in [None, MagicMock()]:
- with pytest.raises(CreateRepoError) as err:
- run_cmd_unsafe(cmd, lock) == "stdout"
- assert err.value.cmd == cmd
- assert err.value.stdout == "stdout"
- assert err.value.stderr == "stderr"
- assert err.value.exit_code == 1
- assert mc_popen.call_args[0][0] == ["foo", "--bar"]
- mc_popen.reset()
+ with pytest.raises(CreateRepoError) as err:
+ run_cmd_unsafe(cmd, self.tmp_dir_name) == "stdout"
+
+ assert err.value.cmd == cmd
+ assert err.value.stdout == "stdout"
+ assert err.value.stderr == "stderr"
+ assert err.value.exit_code == 1
+ assert mc_popen.call_args[0][0] == ["foo", "--bar"]
+ mc_popen.reset()
def test_run_cmd_unsafe_err_communicate(self, mc_popen):
cmd = "foo --bar"
@@ -151,42 +148,12 @@ class TestCreaterepo(object):
mc_handle.returncode = 0
mc_handle.side_effect = RuntimeError()
- for lock in [None, MagicMock()]:
- with pytest.raises(CreateRepoError) as err:
- run_cmd_unsafe(cmd, lock) == "stdout"
-
- assert err.value.cmd == cmd
- assert mc_popen.call_args[0][0] == ["foo", "--bar"]
- mc_popen.reset()
-
- def test_run_cmd_unsafe_lock_usage(self, mc_popen):
- cmd = "foo --bar"
- mocked_lock = MagicMock()
- self.shared_state = dict(in_lock=False, lock_status=None)
-
- def enter_lock(*args, **kwargs):
- self.shared_state["in_lock"] = True
-
- def exit_lock(*args, **kwargs):
- self.shared_state["in_lock"] = False
+ with pytest.raises(CreateRepoError) as err:
+ run_cmd_unsafe(cmd, self.tmp_dir_name) == "stdout"
- def popen_side_effect(*args, **kwargs):
- self.shared_state["lock_status"] =
copy.copy(self.shared_state["in_lock"])
- return mock.DEFAULT
-
- mocked_lock.__enter__.side_effect = enter_lock
- mocked_lock.__exit__.side_effect = exit_lock
-
- mc_popen.side_effect = popen_side_effect
- mc_popen.return_value.communicate.return_value = ("", "")
- mc_popen.return_value.returncode = 0
-
- run_cmd_unsafe(cmd, lock=mocked_lock)
- assert self.shared_state["lock_status"]
-
- self.shared_state["lock_status"] = None
- run_cmd_unsafe(cmd, lock=None)
- assert not self.shared_state["lock_status"]
+ assert err.value.cmd == cmd
+ assert mc_popen.call_args[0][0] == ["foo", "--bar"]
+ mc_popen.reset()
def test_createrepo_generated_commands_existing_repodata(self, mc_run_cmd_unsafe):
path_epel_5 = os.path.join(self.tmp_dir_name, "epel-5")
@@ -203,7 +170,7 @@ class TestCreaterepo(object):
with open(os.path.join(repo_path, "repomd.xml"), "w") as
handle:
handle.write("1")
- createrepo_unsafe(path, None)
+ createrepo_unsafe(path)
assert mc_run_cmd_unsafe.call_args[0][0] == expected
def test_createrepo_generated_commands_comps_xml(self, mc_run_cmd_unsafe):
@@ -218,13 +185,12 @@ class TestCreaterepo(object):
with open(comps_path, "w") as handle:
handle.write("1")
-
repo_path = os.path.join(path, "repodata")
os.makedirs(repo_path)
with open(os.path.join(repo_path, "repomd.xml"), "w")
as handle:
handle.write("1")
- createrepo_unsafe(path, None)
+ createrepo_unsafe(path)
if add_comps:
assert "--groupfile" in mc_run_cmd_unsafe.call_args[0][0]
else:
@@ -250,7 +216,7 @@ class TestCreaterepo(object):
with open(os.path.join(repo_path, "repomd.xml"), "w") as
handle:
handle.write("1")
- createrepo_unsafe(path, lock=None, base_url=self.base_url,
dest_dir="devel")
+ createrepo_unsafe(path, base_url=self.base_url, dest_dir="devel")
assert mc_run_cmd_unsafe.call_args[0][0] == expected
def test_createrepo_devel_generated_commands(self, mc_run_cmd_unsafe):
@@ -266,7 +232,7 @@ class TestCreaterepo(object):
for path, expected in [(path_epel_5, expected_epel_5), (path_fedora,
expected_fedora)]:
os.makedirs(path)
- createrepo_unsafe(path, lock=None, base_url=self.base_url,
dest_dir="devel")
+ createrepo_unsafe(path, base_url=self.base_url, dest_dir="devel")
assert os.path.exists(os.path.join(path, "devel"))
assert mc_run_cmd_unsafe.call_args[0][0] == expected
# assert mc_popen.call_args == mock.call(expected, stderr=-1, stdout=-1)
@@ -278,5 +244,5 @@ class TestCreaterepo(object):
for path in [path_epel_5, path_fedora]:
os.makedirs(path)
- createrepo_unsafe(path, lock=None, base_url=self.base_url,
dest_dir="devel")
+ createrepo_unsafe(path, base_url=self.base_url, dest_dir="devel")
assert os.path.exists(os.path.join(path, "devel"))