[koji-wrapper] Use more descriptive method names
The methods mentioning image build are generic and can work for other task types. get_image_build_paths -> get_image_paths run_create_image_cmd -> run_blocking_cmd Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
d85f00818d
commit
ae30c07553
@ -176,7 +176,7 @@ class CreateImageBuildThread(WorkerThread):
|
|||||||
# avoid race conditions?
|
# avoid race conditions?
|
||||||
# Kerberos authentication failed: Permission denied in replay cache code (-1765328215)
|
# Kerberos authentication failed: Permission denied in replay cache code (-1765328215)
|
||||||
time.sleep(num * 3)
|
time.sleep(num * 3)
|
||||||
output = koji_wrapper.run_create_image_cmd(koji_cmd, log_file=log_file)
|
output = koji_wrapper.run_blocking_cmd(koji_cmd, log_file=log_file)
|
||||||
self.pool.log_debug("build-image outputs: %s" % (output))
|
self.pool.log_debug("build-image outputs: %s" % (output))
|
||||||
if output["retcode"] != 0:
|
if output["retcode"] != 0:
|
||||||
self.fail(compose, cmd)
|
self.fail(compose, cmd)
|
||||||
@ -185,7 +185,7 @@ class CreateImageBuildThread(WorkerThread):
|
|||||||
# copy image to images/
|
# copy image to images/
|
||||||
image_infos = []
|
image_infos = []
|
||||||
|
|
||||||
paths = koji_wrapper.get_image_build_paths(output["task_id"])
|
paths = koji_wrapper.get_image_paths(output["task_id"])
|
||||||
|
|
||||||
for arch, paths in paths.iteritems():
|
for arch, paths in paths.iteritems():
|
||||||
for path in paths:
|
for path in paths:
|
||||||
|
@ -201,7 +201,7 @@ class CreateLiveImageThread(WorkerThread):
|
|||||||
# Kerberos authentication failed: Permission denied in replay cache code (-1765328215)
|
# Kerberos authentication failed: Permission denied in replay cache code (-1765328215)
|
||||||
time.sleep(num * 3)
|
time.sleep(num * 3)
|
||||||
|
|
||||||
output = koji_wrapper.run_create_image_cmd(koji_cmd, log_file=log_file)
|
output = koji_wrapper.run_blocking_cmd(koji_cmd, log_file=log_file)
|
||||||
if output["retcode"] != 0:
|
if output["retcode"] != 0:
|
||||||
self.fail(compose, cmd)
|
self.fail(compose, cmd)
|
||||||
raise RuntimeError("LiveImage task failed: %s. See %s for more details." % (output["task_id"], log_file))
|
raise RuntimeError("LiveImage task failed: %s. See %s for more details." % (output["task_id"], log_file))
|
||||||
|
@ -191,8 +191,12 @@ class KojiWrapper(object):
|
|||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
def run_create_image_cmd(self, command, log_file=None):
|
def run_blocking_cmd(self, command, log_file=None):
|
||||||
# spin-{livecd,appliance} is blocking by default -> you probably want to run it in a thread
|
"""
|
||||||
|
Run a blocking koji command. Returns a dict with output of the command,
|
||||||
|
its exit code and parsed task id. This method will block until the
|
||||||
|
command finishes.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
retcode, output = run(command, can_fail=True, logfile=log_file)
|
retcode, output = run(command, can_fail=True, logfile=log_file)
|
||||||
except RuntimeError, e:
|
except RuntimeError, e:
|
||||||
@ -209,7 +213,7 @@ class KojiWrapper(object):
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def get_image_build_paths(self, task_id):
|
def get_image_paths(self, task_id):
|
||||||
"""
|
"""
|
||||||
Given an image task in Koji, get a mapping from arches to a list of
|
Given an image task in Koji, get a mapping from arches to a list of
|
||||||
paths to results of the task.
|
paths to results of the task.
|
||||||
|
@ -349,12 +349,12 @@ class TestCreateImageBuildThread(unittest.TestCase):
|
|||||||
"link_type": 'hardlink-or-copy',
|
"link_type": 'hardlink-or-copy',
|
||||||
}
|
}
|
||||||
koji_wrapper = KojiWrapper.return_value
|
koji_wrapper = KojiWrapper.return_value
|
||||||
koji_wrapper.run_create_image_cmd.return_value = {
|
koji_wrapper.run_blocking_cmd.return_value = {
|
||||||
"retcode": 0,
|
"retcode": 0,
|
||||||
"output": None,
|
"output": None,
|
||||||
"task_id": 1234,
|
"task_id": 1234,
|
||||||
}
|
}
|
||||||
koji_wrapper.get_image_build_paths.return_value = {
|
koji_wrapper.get_image_paths.return_value = {
|
||||||
'amd64': [
|
'amd64': [
|
||||||
'/koji/task/1235/tdl-amd64.xml',
|
'/koji/task/1235/tdl-amd64.xml',
|
||||||
'/koji/task/1235/Fedora-Docker-Base-20160103.amd64.qcow2',
|
'/koji/task/1235/Fedora-Docker-Base-20160103.amd64.qcow2',
|
||||||
@ -468,7 +468,7 @@ class TestCreateImageBuildThread(unittest.TestCase):
|
|||||||
"link_type": 'hardlink-or-copy',
|
"link_type": 'hardlink-or-copy',
|
||||||
}
|
}
|
||||||
koji_wrapper = KojiWrapper.return_value
|
koji_wrapper = KojiWrapper.return_value
|
||||||
koji_wrapper.run_create_image_cmd.return_value = {
|
koji_wrapper.run_blocking_cmd.return_value = {
|
||||||
"retcode": 1,
|
"retcode": 1,
|
||||||
"output": None,
|
"output": None,
|
||||||
"task_id": 1234,
|
"task_id": 1234,
|
||||||
@ -520,7 +520,7 @@ class TestCreateImageBuildThread(unittest.TestCase):
|
|||||||
raise RuntimeError('BOOM')
|
raise RuntimeError('BOOM')
|
||||||
|
|
||||||
koji_wrapper = KojiWrapper.return_value
|
koji_wrapper = KojiWrapper.return_value
|
||||||
koji_wrapper.run_create_image_cmd.side_effect = boom
|
koji_wrapper.run_blocking_cmd.side_effect = boom
|
||||||
|
|
||||||
t = CreateImageBuildThread(pool)
|
t = CreateImageBuildThread(pool)
|
||||||
with mock.patch('os.stat') as stat:
|
with mock.patch('os.stat') as stat:
|
||||||
|
@ -75,7 +75,7 @@ class KojiWrapperTest(unittest.TestCase):
|
|||||||
mock.call('distro = test-distro\n'),
|
mock.call('distro = test-distro\n'),
|
||||||
mock.call('\n')])
|
mock.call('\n')])
|
||||||
|
|
||||||
def test_get_image_build_paths(self):
|
def test_get_image_paths(self):
|
||||||
|
|
||||||
# The data for this tests is obtained from the actual Koji build. It
|
# The data for this tests is obtained from the actual Koji build. It
|
||||||
# includes lots of fields that are not used, but for the sake of
|
# includes lots of fields that are not used, but for the sake of
|
||||||
@ -233,7 +233,7 @@ class KojiWrapperTest(unittest.TestCase):
|
|||||||
getTaskChildren=mock.Mock(side_effect=lambda task_id, request: getTaskChildren_data.get(task_id)),
|
getTaskChildren=mock.Mock(side_effect=lambda task_id, request: getTaskChildren_data.get(task_id)),
|
||||||
getTaskResult=mock.Mock(side_effect=lambda task_id: getTaskResult_data.get(task_id))
|
getTaskResult=mock.Mock(side_effect=lambda task_id: getTaskResult_data.get(task_id))
|
||||||
)
|
)
|
||||||
result = self.koji.get_image_build_paths(12387273)
|
result = self.koji.get_image_paths(12387273)
|
||||||
self.assertItemsEqual(result.keys(), ['i386', 'x86_64'])
|
self.assertItemsEqual(result.keys(), ['i386', 'x86_64'])
|
||||||
self.maxDiff = None
|
self.maxDiff = None
|
||||||
self.assertItemsEqual(result['i386'],
|
self.assertItemsEqual(result['i386'],
|
||||||
|
@ -129,7 +129,7 @@ class TestCreateLiveImageThread(unittest.TestCase):
|
|||||||
|
|
||||||
koji_wrapper = KojiWrapper.return_value
|
koji_wrapper = KojiWrapper.return_value
|
||||||
koji_wrapper.get_create_image_cmd.return_value = 'koji spin-livecd ...'
|
koji_wrapper.get_create_image_cmd.return_value = 'koji spin-livecd ...'
|
||||||
koji_wrapper.run_create_image_cmd.return_value = {
|
koji_wrapper.run_blocking_cmd.return_value = {
|
||||||
'retcode': 0,
|
'retcode': 0,
|
||||||
'output': 'some output',
|
'output': 'some output',
|
||||||
'task_id': 123
|
'task_id': 123
|
||||||
@ -140,7 +140,7 @@ class TestCreateLiveImageThread(unittest.TestCase):
|
|||||||
with mock.patch('time.sleep'):
|
with mock.patch('time.sleep'):
|
||||||
t.process((compose, cmd, compose.variants['Client'], 'amd64'), 1)
|
t.process((compose, cmd, compose.variants['Client'], 'amd64'), 1)
|
||||||
|
|
||||||
self.assertEqual(koji_wrapper.run_create_image_cmd.mock_calls,
|
self.assertEqual(koji_wrapper.run_blocking_cmd.mock_calls,
|
||||||
[mock.call('koji spin-livecd ...', log_file='/a/b/log/log_file')])
|
[mock.call('koji spin-livecd ...', log_file='/a/b/log/log_file')])
|
||||||
self.assertEqual(koji_wrapper.get_image_path.mock_calls, [mock.call(123)])
|
self.assertEqual(koji_wrapper.get_image_path.mock_calls, [mock.call(123)])
|
||||||
self.assertEqual(copy2.mock_calls,
|
self.assertEqual(copy2.mock_calls,
|
||||||
@ -178,7 +178,7 @@ class TestCreateLiveImageThread(unittest.TestCase):
|
|||||||
|
|
||||||
koji_wrapper = KojiWrapper.return_value
|
koji_wrapper = KojiWrapper.return_value
|
||||||
koji_wrapper.get_create_image_cmd.return_value = 'koji spin-livecd ...'
|
koji_wrapper.get_create_image_cmd.return_value = 'koji spin-livecd ...'
|
||||||
koji_wrapper.run_create_image_cmd.return_value = {
|
koji_wrapper.run_blocking_cmd.return_value = {
|
||||||
'retcode': 1,
|
'retcode': 1,
|
||||||
'output': 'some output',
|
'output': 'some output',
|
||||||
'task_id': 123
|
'task_id': 123
|
||||||
|
Loading…
Reference in New Issue
Block a user