Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : master
---------------------------------------------------------------
commit ed95f04c071bffb64c9abbf2bc0b71f72d65d398
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Thu Oct 23 17:18:38 2014 +0200
[backend] createrepo: added logic to create repomd in the `devel` subdir
---------------------------------------------------------------
backend/backend/createrepo.py | 28 ++++++++++-
backend/run/copr_create_repo.py | 13 ++----
backend/tests/test_createrepo.py | 73 +++++++++++++++++++--------
backend/tests/test_run_copr_create_repo.py | 8 ---
4 files changed, 81 insertions(+), 41 deletions(-)
diff --git a/backend/backend/createrepo.py b/backend/backend/createrepo.py
index 0319c8e..31532c4 100644
--- a/backend/backend/createrepo.py
+++ b/backend/backend/createrepo.py
@@ -9,7 +9,7 @@ from copr.client import CoprClient
from backend.helpers import SortedOptParser
-def createrepo_unsafe(path, lock=None):
+def createrepo_unsafe(path, lock=None, dest_dir=None, base_url=None):
"""
Run createrepo_c on the given path
@@ -18,6 +18,10 @@ def createrepo_unsafe(path, lock=None):
:param string path: target location to create repo
:param lock: [optional]
+ :param str dest_dir: [optional] target location for repomd, in most cases
+ you should also provide base_url
+ :param str base_url: optional parameter for createrepo_c, "--baseurl"
+
:return tuple: (return_code, stdout, stderr)
"""
@@ -27,6 +31,13 @@ def createrepo_unsafe(path, lock=None):
if "epel-5" in path:
# this is because rhel-5 doesn't know sha256
comm.extend(['-s', 'sha', '--checksum', 'md5'])
+
+ if dest_dir:
+ comm.extend(['--outputdir', dest_dir])
+
+ if base_url:
+ comm.extend(['--baseurl', base_url])
+
comm.append(path)
if lock:
@@ -51,10 +62,23 @@ def get_auto_createrepo_status(front_url, username, projectname):
def createrepo(path, front_url, username, projectname, lock=None):
+ """
+ Creates repo depending on the project setting "auto_createrepo".
+ When enabled creates `repodata` at the provided path, otherwise
+
+ :param str path: directory with rpms
+ :param str front_url: url to the copr frontend
+ :param str username: copr project owner username
+ :param str projectname: copr project name
+ :param Multiprocessing.Lock lock: [optional] global copr-backend lock
+
+
+ :return: tuple(returncode, stdout, stderr) produced by `createrepo_c`
+ """
# TODO: add means of logging
if get_auto_createrepo_status(front_url, username, projectname):
return createrepo_unsafe(path, lock)
else:
- return None
+ return createrepo_unsafe(path, lock, base_url="../",
dest_dir="devel")
diff --git a/backend/run/copr_create_repo.py b/backend/run/copr_create_repo.py
index ea11a1a..49ea3b5 100644
--- a/backend/run/copr_create_repo.py
+++ b/backend/run/copr_create_repo.py
@@ -31,21 +31,16 @@ def main(args):
sys.exit(1)
if not opts.front_url:
- print("No api url was specified, exiting", file=sys.stderr)
+ print("No front url was specified, exiting", file=sys.stderr)
sys.exit(1)
if not args:
print("No directory with repo was specified, exiting",
file=sys.stderr)
sys.exit(1)
- result = createrepo(path=args[0], front_url=opts.front_url,
- username=opts.user, projectname=opts.project)
- if not result:
- print("Createrepo was skipped")
- else:
- retcode, stdout, stderr = result
- print("STDOUT: {}".format(stdout))
- print("STDERR: {}".format(stderr))
+ createrepo(path=args[0], front_url=opts.front_url,
+ username=opts.user, projectname=opts.project)
+
if __name__ == "__main__":
diff --git a/backend/tests/test_createrepo.py b/backend/tests/test_createrepo.py
index 23dfad6..01762b4 100644
--- a/backend/tests/test_createrepo.py
+++ b/backend/tests/test_createrepo.py
@@ -26,25 +26,34 @@ from backend.createrepo import createrepo, createrepo_unsafe
@mock.patch('backend.createrepo.createrepo_unsafe')
@mock.patch('backend.createrepo.CoprClient')
-def test_createrepo_conditional(mc_client, mc_create_unsafe):
+def test_createrepo_conditional_true(mc_client, mc_create_unsafe):
mc_client.return_value.get_project_details.return_value =
MagicMock(data={"detail": {}})
createrepo(path="/tmp/",
front_url="http://example.com/api",
username="foo", projectname="bar", lock=None)
- assert mc_create_unsafe.called # old behaviour
+
mc_create_unsafe.reset_mock()
- for val in [True, False]:
- mc_client.return_value.get_project_details.return_value =
MagicMock(data={"detail": {"auto_createrepo": val}})
- createrepo(path="/tmp/",
front_url="http://example.com/api",
- username="foo", projectname="bar", lock=None)
- assert val == mc_create_unsafe.called
- 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)
-(a)mock.patch('backend.createrepo.Popen')
+ mc_create_unsafe.reset_mock()
+
+(a)mock.patch('backend.createrepo.createrepo_unsafe')
@mock.patch('backend.createrepo.CoprClient')
+def test_createrepo_conditional_false(mc_client, mc_create_unsafe):
+ mc_client.return_value.get_project_details.return_value =
MagicMock(data={"detail": {"auto_createrepo": False}})
+
+ createrepo(path="/tmp/",
front_url="http://example.com/api",
+ username="foo", projectname="bar", lock=None)
+
+ assert mc_create_unsafe.call_args == mock.call('/tmp/', None,
dest_dir='devel', base_url='../')
+
+
+(a)mock.patch('backend.createrepo.Popen')
class TestCreaterepoUnsafe(object):
def setup_method(self, method):
self.tmp_dir_name = self.make_temp_dir()
@@ -67,9 +76,8 @@ class TestCreaterepoUnsafe(object):
return self.tmp_dir_name
- def test_createrepo_unsafe_lock_usage(self, mc_client, mc_popen):
+ def test_createrepo_unsafe_lock_usage(self, mc_popen):
mocked_lock = MagicMock()
-
self.shared_state = dict(in_lock=False, lock_status=None)
def enter_lock(*args, **kwargs):
@@ -78,8 +86,6 @@ class TestCreaterepoUnsafe(object):
def exit_lock(*args, **kwargs):
self.shared_state["in_lock"] = False
- #mock_cmd_result = MagicMock()
-
def popen_side_effect(*args, **kwargs):
self.shared_state["lock_status"] =
copy.copy(self.shared_state["in_lock"])
return mock.DEFAULT
@@ -91,13 +97,13 @@ class TestCreaterepoUnsafe(object):
mc_popen.return_value.communicate.return_value = ("", "")
createrepo_unsafe(self.tmp_dir_name, lock=mocked_lock)
- assert self.shared_state["lock_status"] == True
+ assert self.shared_state["lock_status"]
self.shared_state["lock_status"] = None
createrepo_unsafe(self.tmp_dir_name, lock=None)
- assert self.shared_state["lock_status"] == False
+ assert not self.shared_state["lock_status"]
- def test_createrepo_generated_commands_existing_repodata(self, mc_client, mc_popen):
+ def test_createrepo_generated_commands_existing_repodata(self, mc_popen):
mc_popen.return_value.communicate.return_value = ("", "")
path_epel_5 = os.path.join(self.tmp_dir_name, "epel-5")
expected_epel_5 = ['/usr/bin/createrepo_c', '--database',
@@ -116,17 +122,40 @@ class TestCreaterepoUnsafe(object):
createrepo_unsafe(path, None)
assert mc_popen.call_args == mock.call(expected, stderr=-1, stdout=-1)
- def test_createrepo_generated_commands(self, mc_client, mc_popen):
+
+ def test_createrepo_devel_generated_commands_existing_repodata(self, mc_popen):
+
mc_popen.return_value.communicate.return_value = ("", "")
path_epel_5 = os.path.join(self.tmp_dir_name, "epel-5")
- expected_epel_5 = ['/usr/bin/createrepo_c', '--database',
- '--ignore-lock', '-s', 'sha',
'--checksum', 'md5', path_epel_5]
+ expected_epel_5 = ['/usr/bin/createrepo_c', '--database',
'--ignore-lock',
+ '-s', 'sha', '--checksum',
'md5',
+ '--outputdir', 'devel', '--baseurl',
'../', path_epel_5]
path_fedora = os.path.join(self.tmp_dir_name, "fedora-21")
- expected_fedora = ['/usr/bin/createrepo_c', '--database',
- '--ignore-lock', path_fedora]
+ expected_fedora = ['/usr/bin/createrepo_c', '--database',
'--ignore-lock',
+ '--outputdir', 'devel', '--baseurl',
'../', path_fedora]
for path, expected in [(path_epel_5, expected_epel_5), (path_fedora,
expected_fedora)]:
os.makedirs(path)
+ repo_path = os.path.join(path, "devel", "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, lock=None, base_url="../",
dest_dir="devel")
+ assert mc_popen.call_args == mock.call(expected, stderr=-1, stdout=-1)
+
+ def test_createrepo_devel_generated_commands(self, mc_popen):
+
+ mc_popen.return_value.communicate.return_value = ("", "")
+ path_epel_5 = os.path.join(self.tmp_dir_name, "epel-5")
+ expected_epel_5 = ['/usr/bin/createrepo_c', '--database',
'--ignore-lock',
+ '-s', 'sha', '--checksum',
'md5',
+ '--outputdir', 'devel', '--baseurl',
'../', path_epel_5]
+ path_fedora = os.path.join(self.tmp_dir_name, "fedora-21")
+ expected_fedora = ['/usr/bin/createrepo_c', '--database',
'--ignore-lock',
+ '--outputdir', 'devel', '--baseurl',
'../', path_fedora]
+ for path, expected in [(path_epel_5, expected_epel_5), (path_fedora,
expected_fedora)]:
+ os.makedirs(path)
+
+ createrepo_unsafe(path, lock=None, base_url="../",
dest_dir="devel")
assert mc_popen.call_args == mock.call(expected, stderr=-1, stdout=-1)
diff --git a/backend/tests/test_run_copr_create_repo.py
b/backend/tests/test_run_copr_create_repo.py
index c5e0bd9..9443b46 100644
--- a/backend/tests/test_run_copr_create_repo.py
+++ b/backend/tests/test_run_copr_create_repo.py
@@ -31,13 +31,6 @@ class TestArgParser(object):
mc_createrepo.return_value = 0, "", ""
createrepo_main(args)
-
- assert mc_createrepo.call_args == mock.call(username='foo',
projectname='bar',
-
front_url='http://example.com/api/';, path='/tmp')
-
- mc_createrepo.return_value = None
- createrepo_main(args)
-
assert mc_createrepo.call_args == mock.call(username='foo',
projectname='bar',
front_url='http://example.com/api/';, path='/tmp')
@@ -61,7 +54,6 @@ class TestArgParser(object):
stdout, stderr = capsys.readouterr()
assert "No user" in stderr
-
def test_arg_parser_missing_project(self, mc_main, capsys):
args = ['-u', 'foo', '-f',
'http://example.com/api/', '/tmp']