2016-01-05 08:27:20 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2018-04-30 09:17:23 +00:00
|
|
|
import json
|
2016-01-05 08:27:20 +00:00
|
|
|
import mock
|
2020-01-22 10:02:22 +00:00
|
|
|
|
2016-05-25 11:39:02 +00:00
|
|
|
try:
|
|
|
|
import unittest2 as unittest
|
|
|
|
except ImportError:
|
|
|
|
import unittest
|
2016-02-23 14:16:07 +00:00
|
|
|
import tempfile
|
2016-01-05 08:27:20 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
|
2019-10-04 12:45:03 +00:00
|
|
|
import six
|
|
|
|
|
2017-04-25 13:22:09 +00:00
|
|
|
from pungi.wrappers.kojiwrapper import KojiWrapper, get_buildroot_rpms
|
2016-01-05 08:27:20 +00:00
|
|
|
|
2018-04-30 09:17:23 +00:00
|
|
|
from .helpers import FIXTURE_DIR
|
|
|
|
|
2016-01-05 08:27:20 +00:00
|
|
|
|
2017-04-24 16:44:04 +00:00
|
|
|
class DumbMock(object):
|
|
|
|
def __init__(self, **kwargs):
|
2017-09-05 08:01:21 +00:00
|
|
|
for key, value in kwargs.items():
|
2017-04-24 16:44:04 +00:00
|
|
|
setattr(self, key, value)
|
|
|
|
|
|
|
|
|
2018-04-30 09:17:23 +00:00
|
|
|
def mock_imagebuild_path(id):
|
|
|
|
if isinstance(id, int):
|
2020-01-22 10:02:22 +00:00
|
|
|
return "/koji/imagebuild/" + str(id)
|
|
|
|
return "/koji/imagebuild/" + str(hash(str(id)))
|
2018-04-30 09:17:23 +00:00
|
|
|
|
|
|
|
|
2016-02-11 11:23:54 +00:00
|
|
|
class KojiWrapperBaseTestCase(unittest.TestCase):
|
2016-01-05 08:27:20 +00:00
|
|
|
def setUp(self):
|
2016-02-23 14:16:07 +00:00
|
|
|
_, self.tmpfile = tempfile.mkstemp()
|
2016-01-05 08:27:20 +00:00
|
|
|
self.koji_profile = mock.Mock()
|
2020-01-22 10:02:22 +00:00
|
|
|
with mock.patch("pungi.wrappers.kojiwrapper.koji") as koji:
|
2020-12-02 13:04:31 +00:00
|
|
|
koji.gssapi_login = mock.Mock()
|
2016-01-05 08:27:20 +00:00
|
|
|
koji.get_profile_module = mock.Mock(
|
|
|
|
return_value=mock.Mock(
|
2017-04-24 16:44:04 +00:00
|
|
|
config=DumbMock(
|
2021-03-02 10:19:05 +00:00
|
|
|
server="koji.example.com",
|
|
|
|
authtype="kerberos",
|
|
|
|
cert="",
|
2020-01-22 10:02:22 +00:00
|
|
|
),
|
2016-01-05 08:27:20 +00:00
|
|
|
pathinfo=mock.Mock(
|
2020-01-22 10:02:22 +00:00
|
|
|
work=mock.Mock(return_value="/koji"),
|
|
|
|
taskrelpath=mock.Mock(side_effect=lambda id: "task/" + str(id)),
|
2018-04-30 09:17:23 +00:00
|
|
|
imagebuild=mock.Mock(side_effect=mock_imagebuild_path),
|
2020-01-22 10:02:22 +00:00
|
|
|
),
|
2016-01-05 08:27:20 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
self.koji_profile = koji.get_profile_module.return_value
|
2020-01-22 10:02:22 +00:00
|
|
|
self.koji = KojiWrapper("custom-koji")
|
2016-01-05 08:27:20 +00:00
|
|
|
|
2016-02-23 14:16:07 +00:00
|
|
|
def tearDown(self):
|
|
|
|
os.remove(self.tmpfile)
|
|
|
|
|
2016-02-11 11:23:54 +00:00
|
|
|
|
|
|
|
class KojiWrapperTest(KojiWrapperBaseTestCase):
|
2020-12-02 13:04:31 +00:00
|
|
|
def test_kerberos_login(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
self.koji.koji_module.config.keytab = "testkeytab"
|
|
|
|
self.koji.koji_module.config.principal = "testprincipal"
|
2016-12-14 12:41:28 +00:00
|
|
|
self.koji.login()
|
2020-12-02 13:04:31 +00:00
|
|
|
self.koji.koji_proxy.gssapi_login.assert_called_with(
|
|
|
|
"testprincipal", "testkeytab"
|
|
|
|
)
|
2016-12-14 12:41:28 +00:00
|
|
|
|
2016-02-23 14:16:07 +00:00
|
|
|
def test_get_image_build_cmd_without_required_data(self):
|
2016-01-05 08:27:20 +00:00
|
|
|
with self.assertRaises(AssertionError):
|
|
|
|
self.koji.get_image_build_cmd(
|
2020-01-22 10:02:22 +00:00
|
|
|
{"image-build": {"name": "test-name"}}, self.tmpfile
|
2016-01-05 08:27:20 +00:00
|
|
|
)
|
|
|
|
|
2016-02-23 14:16:07 +00:00
|
|
|
def test_get_image_build_cmd_correct(self):
|
2016-01-05 08:27:20 +00:00
|
|
|
cmd = self.koji.get_image_build_cmd(
|
|
|
|
{
|
2020-01-22 10:02:22 +00:00
|
|
|
"image-build": {
|
|
|
|
"name": "test-name",
|
|
|
|
"version": "1",
|
|
|
|
"target": "test-target",
|
|
|
|
"install_tree": "/tmp/test/install_tree",
|
|
|
|
"arches": "x86_64",
|
|
|
|
"format": ["docker", "qcow2"],
|
|
|
|
"kickstart": "test-kickstart",
|
|
|
|
"ksurl": "git://example.com/ks.git",
|
|
|
|
"distro": "test-distro",
|
|
|
|
"release": "20160222.0",
|
|
|
|
"disk_size": 4,
|
2016-02-11 12:22:03 +00:00
|
|
|
}
|
2016-01-05 08:27:20 +00:00
|
|
|
},
|
2020-01-22 10:02:22 +00:00
|
|
|
self.tmpfile,
|
2016-01-05 08:27:20 +00:00
|
|
|
)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(cmd[:3], ["koji", "--profile=custom-koji", "image-build"])
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(self, cmd[3:], ["--config=" + self.tmpfile, "--wait"])
|
2016-01-05 08:27:20 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
with open(self.tmpfile, "r") as f:
|
|
|
|
lines = f.read().strip().split("\n")
|
|
|
|
self.assertEqual(lines[0], "[image-build]")
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self,
|
|
|
|
lines[1:],
|
2020-01-22 10:02:22 +00:00
|
|
|
[
|
|
|
|
"name = test-name",
|
|
|
|
"version = 1",
|
|
|
|
"target = test-target",
|
|
|
|
"install_tree = /tmp/test/install_tree",
|
|
|
|
"arches = x86_64",
|
|
|
|
"format = docker,qcow2",
|
|
|
|
"kickstart = test-kickstart",
|
|
|
|
"ksurl = git://example.com/ks.git",
|
|
|
|
"distro = test-distro",
|
|
|
|
"release = 20160222.0",
|
|
|
|
"disk_size = 4",
|
|
|
|
],
|
2019-10-04 12:45:03 +00:00
|
|
|
)
|
2016-01-05 08:27:20 +00:00
|
|
|
|
2016-01-28 13:58:24 +00:00
|
|
|
def test_get_image_paths(self):
|
2016-01-05 08:27:20 +00:00
|
|
|
|
|
|
|
# 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
|
|
|
|
# completeness is fully preserved.
|
|
|
|
|
|
|
|
getTaskChildren_data = {
|
|
|
|
12387273: [
|
|
|
|
{
|
2020-01-22 10:02:22 +00:00
|
|
|
"arch": "i386",
|
|
|
|
"awaited": False,
|
|
|
|
"channel_id": 12,
|
|
|
|
"completion_time": "2016-01-03 05:34:08.374262",
|
|
|
|
"completion_ts": 1451799248.37426,
|
|
|
|
"create_time": "2016-01-03 05:15:20.311599",
|
|
|
|
"create_ts": 1451798120.3116,
|
|
|
|
"host_id": 158,
|
|
|
|
"id": 12387276,
|
|
|
|
"label": "i386",
|
|
|
|
"method": "createImage",
|
|
|
|
"owner": 131,
|
|
|
|
"parent": 12387273,
|
|
|
|
"priority": 19,
|
|
|
|
"request": [
|
|
|
|
"Fedora-Cloud-Base",
|
|
|
|
"23",
|
|
|
|
"20160103",
|
|
|
|
"i386",
|
2016-01-05 08:27:20 +00:00
|
|
|
{
|
2020-01-22 10:02:22 +00:00
|
|
|
"build_tag": 299,
|
|
|
|
"build_tag_name": "f23-build",
|
|
|
|
"dest_tag": 294,
|
|
|
|
"dest_tag_name": "f23-updates-candidate",
|
|
|
|
"id": 144,
|
|
|
|
"name": "f23-candidate",
|
2016-01-05 08:27:20 +00:00
|
|
|
},
|
|
|
|
299,
|
|
|
|
{
|
2020-01-22 10:02:22 +00:00
|
|
|
"create_event": 14011966,
|
|
|
|
"create_ts": 1451761803.33528,
|
|
|
|
"creation_time": "2016-01-02 19:10:03.335283",
|
|
|
|
"id": 563977,
|
|
|
|
"state": 1,
|
2016-01-05 08:27:20 +00:00
|
|
|
},
|
2020-02-06 07:09:32 +00:00
|
|
|
"http://infrastructure.fedoraproject.org/pub/alt/releases/23/Cloud/i386/os/", # noqa: E501
|
2016-01-05 08:27:20 +00:00
|
|
|
{
|
2020-01-22 10:02:22 +00:00
|
|
|
"disk_size": "3",
|
|
|
|
"distro": "Fedora-20",
|
|
|
|
"format": ["qcow2", "raw-xz"],
|
2020-02-06 07:09:32 +00:00
|
|
|
"kickstart": "work/cli-image/1451798116.800155.wYJWTVHw/fedora-cloud-base-2878aa0.ks", # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
"release": "20160103",
|
|
|
|
"repo": [
|
2020-02-06 07:09:32 +00:00
|
|
|
"http://infrastructure.fedoraproject.org/pub/alt/releases/23/Cloud/$arch/os/", # noqa: E501
|
|
|
|
"http://infrastructure.fedoraproject.org/pub/fedora/linux/updates/23/$arch/", # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
],
|
|
|
|
"scratch": True,
|
|
|
|
},
|
2016-01-05 08:27:20 +00:00
|
|
|
],
|
2020-01-22 10:02:22 +00:00
|
|
|
"start_time": "2016-01-03 05:15:29.828081",
|
|
|
|
"start_ts": 1451798129.82808,
|
|
|
|
"state": 2,
|
|
|
|
"waiting": None,
|
|
|
|
"weight": 2.0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"arch": "x86_64",
|
|
|
|
"awaited": False,
|
|
|
|
"channel_id": 12,
|
|
|
|
"completion_time": "2016-01-03 05:33:20.066366",
|
|
|
|
"completion_ts": 1451799200.06637,
|
|
|
|
"create_time": "2016-01-03 05:15:20.754201",
|
|
|
|
"create_ts": 1451798120.7542,
|
|
|
|
"host_id": 156,
|
|
|
|
"id": 12387277,
|
|
|
|
"label": "x86_64",
|
|
|
|
"method": "createImage",
|
|
|
|
"owner": 131,
|
|
|
|
"parent": 12387273,
|
|
|
|
"priority": 19,
|
|
|
|
"request": [
|
|
|
|
"Fedora-Cloud-Base",
|
|
|
|
"23",
|
|
|
|
"20160103",
|
|
|
|
"x86_64",
|
2016-01-05 08:27:20 +00:00
|
|
|
{
|
2020-01-22 10:02:22 +00:00
|
|
|
"build_tag": 299,
|
|
|
|
"build_tag_name": "f23-build",
|
|
|
|
"dest_tag": 294,
|
|
|
|
"dest_tag_name": "f23-updates-candidate",
|
|
|
|
"id": 144,
|
|
|
|
"name": "f23-candidate",
|
2016-01-05 08:27:20 +00:00
|
|
|
},
|
|
|
|
299,
|
|
|
|
{
|
2020-01-22 10:02:22 +00:00
|
|
|
"create_event": 14011966,
|
|
|
|
"create_ts": 1451761803.33528,
|
|
|
|
"creation_time": "2016-01-02 19:10:03.335283",
|
|
|
|
"id": 563977,
|
|
|
|
"state": 1,
|
2016-01-05 08:27:20 +00:00
|
|
|
},
|
2020-02-06 07:09:32 +00:00
|
|
|
"http://infrastructure.fedoraproject.org/pub/alt/releases/23/Cloud/x86_64/os/", # noqa: E501
|
2016-01-05 08:27:20 +00:00
|
|
|
{
|
2020-01-22 10:02:22 +00:00
|
|
|
"disk_size": "3",
|
|
|
|
"distro": "Fedora-20",
|
|
|
|
"format": ["qcow2", "raw-xz"],
|
2020-02-06 07:09:32 +00:00
|
|
|
"kickstart": "work/cli-image/1451798116.800155.wYJWTVHw/fedora-cloud-base-2878aa0.ks", # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
"release": "20160103",
|
|
|
|
"repo": [
|
2020-02-06 07:09:32 +00:00
|
|
|
"http://infrastructure.fedoraproject.org/pub/alt/releases/23/Cloud/$arch/os/", # noqa: E501
|
|
|
|
"http://infrastructure.fedoraproject.org/pub/fedora/linux/updates/23/$arch/", # noqa: E501
|
2020-01-22 10:02:22 +00:00
|
|
|
],
|
|
|
|
"scratch": True,
|
|
|
|
},
|
2016-01-05 08:27:20 +00:00
|
|
|
],
|
2020-01-22 10:02:22 +00:00
|
|
|
"start_time": "2016-01-03 05:15:35.196043",
|
|
|
|
"start_ts": 1451798135.19604,
|
|
|
|
"state": 2,
|
|
|
|
"waiting": None,
|
|
|
|
"weight": 2.0,
|
|
|
|
},
|
2016-01-05 08:27:20 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
getTaskResult_data = {
|
|
|
|
12387276: {
|
2020-01-22 10:02:22 +00:00
|
|
|
"arch": "i386",
|
|
|
|
"files": [
|
|
|
|
"tdl-i386.xml",
|
|
|
|
"fedora-cloud-base-2878aa0.ks",
|
|
|
|
"koji-f23-build-12387276-base.ks",
|
|
|
|
"libvirt-qcow2-i386.xml",
|
|
|
|
"Fedora-Cloud-Base-23-20160103.i386.qcow2",
|
|
|
|
"libvirt-raw-xz-i386.xml",
|
|
|
|
"Fedora-Cloud-Base-23-20160103.i386.raw.xz",
|
|
|
|
],
|
|
|
|
"logs": ["oz-i386.log"],
|
|
|
|
"name": "Fedora-Cloud-Base",
|
|
|
|
"release": "20160103",
|
|
|
|
"rpmlist": [],
|
|
|
|
"task_id": 12387276,
|
|
|
|
"version": "23",
|
2016-01-05 08:27:20 +00:00
|
|
|
},
|
|
|
|
12387277: {
|
2020-01-22 10:02:22 +00:00
|
|
|
"arch": "x86_64",
|
|
|
|
"files": [
|
|
|
|
"tdl-x86_64.xml",
|
|
|
|
"fedora-cloud-base-2878aa0.ks",
|
|
|
|
"koji-f23-build-12387277-base.ks",
|
|
|
|
"libvirt-qcow2-x86_64.xml",
|
|
|
|
"Fedora-Cloud-Base-23-20160103.x86_64.qcow2",
|
|
|
|
"libvirt-raw-xz-x86_64.xml",
|
|
|
|
"Fedora-Cloud-Base-23-20160103.x86_64.raw.xz",
|
|
|
|
],
|
|
|
|
"logs": ["oz-x86_64.log"],
|
|
|
|
"name": "Fedora-Cloud-Base",
|
|
|
|
"release": "20160103",
|
|
|
|
"rpmlist": [],
|
|
|
|
"task_id": 12387277,
|
|
|
|
"version": "23",
|
|
|
|
},
|
2016-01-05 08:27:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self.koji.koji_proxy = mock.Mock(
|
2020-01-22 10:02:22 +00:00
|
|
|
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)
|
|
|
|
),
|
2016-01-05 08:27:20 +00:00
|
|
|
)
|
2016-01-28 13:58:24 +00:00
|
|
|
result = self.koji.get_image_paths(12387273)
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(self, result.keys(), ["i386", "x86_64"])
|
2016-01-05 08:27:20 +00:00
|
|
|
self.maxDiff = None
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self,
|
|
|
|
result["i386"],
|
2020-01-22 10:02:22 +00:00
|
|
|
[
|
|
|
|
"/koji/task/12387276/tdl-i386.xml",
|
|
|
|
"/koji/task/12387276/fedora-cloud-base-2878aa0.ks",
|
|
|
|
"/koji/task/12387276/koji-f23-build-12387276-base.ks",
|
|
|
|
"/koji/task/12387276/libvirt-qcow2-i386.xml",
|
|
|
|
"/koji/task/12387276/Fedora-Cloud-Base-23-20160103.i386.qcow2",
|
|
|
|
"/koji/task/12387276/libvirt-raw-xz-i386.xml",
|
|
|
|
"/koji/task/12387276/Fedora-Cloud-Base-23-20160103.i386.raw.xz",
|
|
|
|
],
|
2019-10-04 12:45:03 +00:00
|
|
|
)
|
|
|
|
six.assertCountEqual(
|
|
|
|
self,
|
|
|
|
result["x86_64"],
|
2020-01-22 10:02:22 +00:00
|
|
|
[
|
|
|
|
"/koji/task/12387277/tdl-x86_64.xml",
|
|
|
|
"/koji/task/12387277/fedora-cloud-base-2878aa0.ks",
|
|
|
|
"/koji/task/12387277/koji-f23-build-12387277-base.ks",
|
|
|
|
"/koji/task/12387277/libvirt-qcow2-x86_64.xml",
|
|
|
|
"/koji/task/12387277/Fedora-Cloud-Base-23-20160103.x86_64.qcow2",
|
|
|
|
"/koji/task/12387277/libvirt-raw-xz-x86_64.xml",
|
|
|
|
"/koji/task/12387277/Fedora-Cloud-Base-23-20160103.x86_64.raw.xz",
|
|
|
|
],
|
2019-10-04 12:45:03 +00:00
|
|
|
)
|
2016-01-05 08:27:20 +00:00
|
|
|
|
2018-04-30 09:17:23 +00:00
|
|
|
def test_get_image_paths_failed_subtask(self):
|
|
|
|
|
|
|
|
failed = set()
|
|
|
|
|
|
|
|
def failed_callback(arch):
|
|
|
|
failed.add(arch)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
with open(os.path.join(FIXTURE_DIR, "task_children_25643870.json")) as f:
|
2018-04-30 09:17:23 +00:00
|
|
|
getTaskChildren_data = json.load(f)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
with open(
|
|
|
|
os.path.join(FIXTURE_DIR, "children_task_results_25643870.json")
|
|
|
|
) as f:
|
2018-04-30 09:17:23 +00:00
|
|
|
getTaskResult_data = json.load(f)
|
|
|
|
|
|
|
|
self.koji.koji_proxy = mock.Mock(
|
|
|
|
getTaskChildren=mock.Mock(return_value=getTaskChildren_data),
|
2020-01-22 10:02:22 +00:00
|
|
|
getTaskResult=mock.Mock(
|
|
|
|
side_effect=lambda task_id: getTaskResult_data.get(str(task_id))
|
|
|
|
),
|
2018-04-30 09:17:23 +00:00
|
|
|
getImageBuild=mock.Mock(side_effect=lambda name: {}),
|
|
|
|
)
|
|
|
|
|
|
|
|
result = self.koji.get_image_paths(25643870, callback=failed_callback)
|
|
|
|
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(self, result.keys(), ["aarch64", "armhfp", "x86_64"])
|
|
|
|
six.assertCountEqual(self, failed, ["ppc64le", "s390x"])
|
2018-04-30 09:17:23 +00:00
|
|
|
|
2018-09-14 08:59:53 +00:00
|
|
|
def test_multicall_map(self):
|
|
|
|
self.koji.koji_proxy = mock.Mock()
|
|
|
|
self.koji.koji_proxy.multiCall.return_value = [[1], [2]]
|
|
|
|
|
|
|
|
ret = self.koji.multicall_map(
|
2020-01-22 10:02:22 +00:00
|
|
|
self.koji.koji_proxy,
|
|
|
|
self.koji.koji_proxy.getBuild,
|
|
|
|
["foo", "bar"],
|
|
|
|
[{"x": 1}, {"x": 2}],
|
|
|
|
)
|
2018-09-14 08:59:53 +00:00
|
|
|
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self,
|
2018-09-14 08:59:53 +00:00
|
|
|
self.koji.koji_proxy.getBuild.mock_calls,
|
2020-01-22 10:02:22 +00:00
|
|
|
[mock.call("foo", x=1), mock.call("bar", x=2)],
|
|
|
|
)
|
2018-09-14 08:59:53 +00:00
|
|
|
self.koji.koji_proxy.multiCall.assert_called_with(strict=True)
|
|
|
|
self.assertEqual(ret, [1, 2])
|
|
|
|
|
2016-01-05 08:27:20 +00:00
|
|
|
|
2016-02-11 11:23:54 +00:00
|
|
|
class LiveMediaTestCase(KojiWrapperBaseTestCase):
|
2016-01-28 13:56:22 +00:00
|
|
|
def test_get_live_media_cmd_minimal(self):
|
|
|
|
opts = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"name": "name",
|
|
|
|
"version": "1",
|
|
|
|
"target": "tgt",
|
|
|
|
"arch": "x,y,z",
|
|
|
|
"ksfile": "kickstart",
|
|
|
|
"install_tree": "/mnt/os",
|
2016-01-28 13:56:22 +00:00
|
|
|
}
|
|
|
|
cmd = self.koji.get_live_media_cmd(opts)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(
|
|
|
|
cmd,
|
|
|
|
[
|
|
|
|
"koji",
|
|
|
|
"--profile=custom-koji",
|
|
|
|
"spin-livemedia",
|
|
|
|
"name",
|
|
|
|
"1",
|
|
|
|
"tgt",
|
|
|
|
"x,y,z",
|
|
|
|
"kickstart",
|
|
|
|
"--install-tree=/mnt/os",
|
|
|
|
"--wait",
|
|
|
|
],
|
|
|
|
)
|
2016-01-28 13:56:22 +00:00
|
|
|
|
|
|
|
def test_get_live_media_cmd_full(self):
|
|
|
|
opts = {
|
2020-01-22 10:02:22 +00:00
|
|
|
"name": "name",
|
|
|
|
"version": "1",
|
|
|
|
"target": "tgt",
|
|
|
|
"arch": "x,y,z",
|
|
|
|
"ksfile": "kickstart",
|
|
|
|
"install_tree": "/mnt/os",
|
|
|
|
"scratch": True,
|
|
|
|
"repo": ["repo-1", "repo-2"],
|
|
|
|
"skip_tag": True,
|
|
|
|
"ksurl": "git://example.com/ksurl.git",
|
|
|
|
"release": "20160222.1",
|
2016-01-28 13:56:22 +00:00
|
|
|
}
|
|
|
|
cmd = self.koji.get_live_media_cmd(opts)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(
|
|
|
|
cmd[:9],
|
|
|
|
[
|
|
|
|
"koji",
|
|
|
|
"--profile=custom-koji",
|
|
|
|
"spin-livemedia",
|
|
|
|
"name",
|
|
|
|
"1",
|
|
|
|
"tgt",
|
|
|
|
"x,y,z",
|
|
|
|
"kickstart",
|
|
|
|
"--install-tree=/mnt/os",
|
|
|
|
],
|
|
|
|
)
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self,
|
|
|
|
cmd[9:],
|
2020-01-22 10:02:22 +00:00
|
|
|
[
|
|
|
|
"--repo=repo-1",
|
|
|
|
"--repo=repo-2",
|
|
|
|
"--skip-tag",
|
|
|
|
"--scratch",
|
|
|
|
"--wait",
|
|
|
|
"--ksurl=git://example.com/ksurl.git",
|
|
|
|
"--release=20160222.1",
|
|
|
|
],
|
2019-10-04 12:45:03 +00:00
|
|
|
)
|
2016-01-28 13:56:22 +00:00
|
|
|
|
|
|
|
|
2016-02-11 11:23:54 +00:00
|
|
|
class LiveImageKojiWrapperTest(KojiWrapperBaseTestCase):
|
|
|
|
def test_get_create_image_cmd_minimal(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
cmd = self.koji.get_create_image_cmd(
|
|
|
|
"my_name", "1.0", "f24-candidate", "x86_64", "/path/to/ks", ["/repo/1"]
|
|
|
|
)
|
|
|
|
self.assertEqual(cmd[0:3], ["koji", "--profile=custom-koji", "spin-livecd"])
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self, cmd[3:7], ["--noprogress", "--scratch", "--wait", "--repo=/repo/1"]
|
|
|
|
)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(
|
|
|
|
cmd[7:], ["my_name", "1.0", "f24-candidate", "x86_64", "/path/to/ks"]
|
|
|
|
)
|
2016-02-11 11:23:54 +00:00
|
|
|
|
|
|
|
def test_get_create_image_cmd_full(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
cmd = self.koji.get_create_image_cmd(
|
|
|
|
"my_name",
|
|
|
|
"1.0",
|
|
|
|
"f24-candidate",
|
|
|
|
"x86_64",
|
|
|
|
"/path/to/ks",
|
|
|
|
["/repo/1", "/repo/2"],
|
|
|
|
release="1",
|
|
|
|
wait=False,
|
|
|
|
archive=True,
|
|
|
|
specfile="foo.spec",
|
|
|
|
ksurl="https://git.example.com/",
|
|
|
|
)
|
|
|
|
self.assertEqual(cmd[0:3], ["koji", "--profile=custom-koji", "spin-livecd"])
|
|
|
|
self.assertEqual(
|
|
|
|
cmd[-5:], ["my_name", "1.0", "f24-candidate", "x86_64", "/path/to/ks"]
|
|
|
|
)
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self,
|
|
|
|
cmd[3:-5],
|
2020-01-22 10:02:22 +00:00
|
|
|
[
|
|
|
|
"--noprogress",
|
|
|
|
"--nowait",
|
|
|
|
"--repo=/repo/1",
|
|
|
|
"--repo=/repo/2",
|
|
|
|
"--release=1",
|
|
|
|
"--specfile=foo.spec",
|
|
|
|
"--ksurl=https://git.example.com/",
|
|
|
|
],
|
2019-10-04 12:45:03 +00:00
|
|
|
)
|
2016-02-11 11:23:54 +00:00
|
|
|
|
|
|
|
def test_spin_livecd_with_format(self):
|
|
|
|
with self.assertRaises(ValueError):
|
2020-01-22 10:02:22 +00:00
|
|
|
self.koji.get_create_image_cmd(
|
|
|
|
"my_name",
|
|
|
|
"1.0",
|
|
|
|
"f24-candidate",
|
|
|
|
"x86_64",
|
|
|
|
"/path/to/ks",
|
|
|
|
[],
|
|
|
|
image_format="qcow",
|
|
|
|
)
|
2016-02-11 11:23:54 +00:00
|
|
|
|
|
|
|
def test_spin_appliance_with_format(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
cmd = self.koji.get_create_image_cmd(
|
|
|
|
"my_name",
|
|
|
|
"1.0",
|
|
|
|
"f24-candidate",
|
|
|
|
"x86_64",
|
|
|
|
"/path/to/ks",
|
|
|
|
[],
|
|
|
|
image_type="appliance",
|
|
|
|
image_format="qcow",
|
|
|
|
)
|
|
|
|
self.assertEqual(cmd[0:3], ["koji", "--profile=custom-koji", "spin-appliance"])
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self, cmd[3:7], ["--noprogress", "--scratch", "--wait", "--format=qcow"]
|
|
|
|
)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(
|
|
|
|
cmd[7:], ["my_name", "1.0", "f24-candidate", "x86_64", "/path/to/ks"]
|
|
|
|
)
|
2016-02-11 11:23:54 +00:00
|
|
|
|
|
|
|
def test_spin_appliance_with_wrong_format(self):
|
|
|
|
with self.assertRaises(ValueError):
|
2020-01-22 10:02:22 +00:00
|
|
|
self.koji.get_create_image_cmd(
|
|
|
|
"my_name",
|
|
|
|
"1.0",
|
|
|
|
"f24-candidate",
|
|
|
|
"x86_64",
|
|
|
|
"/path/to/ks",
|
|
|
|
[],
|
|
|
|
image_type="appliance",
|
|
|
|
image_format="pretty",
|
|
|
|
)
|
2016-02-08 12:27:04 +00:00
|
|
|
|
|
|
|
|
2020-08-25 07:07:28 +00:00
|
|
|
@mock.patch.dict("os.environ", {"FOO": "BAR"}, clear=True)
|
2016-02-11 11:23:54 +00:00
|
|
|
class RunrootKojiWrapperTest(KojiWrapperBaseTestCase):
|
2016-02-08 12:27:04 +00:00
|
|
|
def test_get_cmd_minimal(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
cmd = self.koji.get_runroot_cmd("tgt", "s390x", "date", use_shell=False)
|
2020-01-20 01:56:29 +00:00
|
|
|
self.assertEqual(len(cmd), 9)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(
|
|
|
|
cmd[:5],
|
|
|
|
["koji", "--profile=custom-koji", "runroot", "--nowait", "--task-id"],
|
|
|
|
)
|
|
|
|
self.assertEqual(cmd[-3], "tgt")
|
|
|
|
self.assertEqual(cmd[-2], "s390x")
|
|
|
|
self.assertEqual(
|
|
|
|
cmd[-1], "rm -f /var/lib/rpm/__db*; rm -rf /var/cache/yum/*; set -x; date"
|
|
|
|
)
|
2020-01-20 01:56:29 +00:00
|
|
|
six.assertCountEqual(self, cmd[5:-3], ["--channel-override=runroot-local"])
|
2016-02-08 12:27:04 +00:00
|
|
|
|
|
|
|
def test_get_cmd_full(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
cmd = self.koji.get_runroot_cmd(
|
|
|
|
"tgt",
|
|
|
|
"s390x",
|
|
|
|
["/bin/echo", "&"],
|
|
|
|
quiet=True,
|
|
|
|
channel="chan",
|
|
|
|
packages=["lorax", "some_other_package"],
|
|
|
|
mounts=["/tmp"],
|
|
|
|
weight=1000,
|
|
|
|
)
|
2020-01-17 09:06:13 +00:00
|
|
|
self.assertEqual(len(cmd), 15)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(cmd[:3], ["koji", "--profile=custom-koji", "runroot"])
|
|
|
|
self.assertEqual(cmd[-3], "tgt")
|
|
|
|
self.assertEqual(cmd[-2], "s390x")
|
|
|
|
self.assertEqual(
|
|
|
|
cmd[-1],
|
|
|
|
"rm -f /var/lib/rpm/__db*; rm -rf /var/cache/yum/*; set -x; /bin/echo '&'",
|
|
|
|
)
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self,
|
2020-01-17 09:06:13 +00:00
|
|
|
cmd[4:-3],
|
2020-01-22 10:02:22 +00:00
|
|
|
[
|
|
|
|
"--channel-override=chan",
|
|
|
|
"--quiet",
|
|
|
|
"--use-shell",
|
|
|
|
"--task-id",
|
|
|
|
"--weight=1000",
|
|
|
|
"--package=some_other_package",
|
|
|
|
"--package=lorax",
|
|
|
|
"--mount=/tmp",
|
|
|
|
],
|
2019-10-04 12:45:03 +00:00
|
|
|
)
|
2016-02-08 12:27:04 +00:00
|
|
|
|
2018-11-14 11:37:00 +00:00
|
|
|
@mock.patch("os.getuid", new=lambda: 1010)
|
2019-05-16 08:36:09 +00:00
|
|
|
def test_with_chown_paths(self):
|
2020-01-22 10:02:22 +00:00
|
|
|
cmd = self.koji.get_runroot_cmd(
|
|
|
|
"tgt",
|
|
|
|
"s390x",
|
|
|
|
["/bin/echo", "&"],
|
|
|
|
quiet=True,
|
|
|
|
channel="chan",
|
|
|
|
packages=["lorax", "some_other_package"],
|
|
|
|
mounts=["/tmp"],
|
|
|
|
weight=1000,
|
|
|
|
chown_paths=["/output dir", "/foo"],
|
|
|
|
)
|
2020-01-17 09:06:13 +00:00
|
|
|
self.assertEqual(len(cmd), 15)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(cmd[:3], ["koji", "--profile=custom-koji", "runroot"])
|
|
|
|
self.assertEqual(cmd[-3], "tgt")
|
|
|
|
self.assertEqual(cmd[-2], "s390x")
|
2018-05-29 06:38:09 +00:00
|
|
|
self.assertEqual(
|
|
|
|
cmd[-1],
|
2021-03-01 02:49:49 +00:00
|
|
|
"rm -f /var/lib/rpm/__db*; rm -rf /var/cache/yum/*; set -x; /bin/echo '&' ; EXIT_CODE=$? ; chmod -R a+r '/output dir' /foo ; chown -R 1010 '/output dir' /foo ; exit $EXIT_CODE", # noqa: E501
|
2018-05-29 06:38:09 +00:00
|
|
|
)
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self,
|
2020-01-17 09:06:13 +00:00
|
|
|
cmd[4:-3],
|
2020-01-22 10:02:22 +00:00
|
|
|
[
|
|
|
|
"--channel-override=chan",
|
|
|
|
"--quiet",
|
|
|
|
"--use-shell",
|
|
|
|
"--task-id",
|
|
|
|
"--weight=1000",
|
|
|
|
"--package=some_other_package",
|
|
|
|
"--package=lorax",
|
|
|
|
"--mount=/tmp",
|
|
|
|
],
|
2019-10-04 12:45:03 +00:00
|
|
|
)
|
2018-05-29 06:38:09 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.wrappers.kojiwrapper.run")
|
2016-02-08 12:27:04 +00:00
|
|
|
def test_run_runroot_cmd_no_task_id(self, run):
|
2020-01-22 10:02:22 +00:00
|
|
|
cmd = ["koji", "runroot"]
|
|
|
|
output = "Output ..."
|
2020-01-17 09:06:13 +00:00
|
|
|
run.return_value = (1, output)
|
2016-02-08 12:27:04 +00:00
|
|
|
|
2020-01-17 09:06:13 +00:00
|
|
|
with self.assertRaises(RuntimeError) as ctx:
|
|
|
|
self.koji.run_runroot_cmd(cmd)
|
2016-02-08 12:27:04 +00:00
|
|
|
|
2017-04-24 16:44:04 +00:00
|
|
|
self.assertEqual(
|
|
|
|
run.call_args_list,
|
2020-01-22 10:02:22 +00:00
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
cmd,
|
|
|
|
can_fail=True,
|
2020-08-25 07:07:28 +00:00
|
|
|
env={"FOO": "BAR", "PYTHONUNBUFFERED": "1"},
|
2020-07-02 07:32:05 +00:00
|
|
|
buffer_size=-1,
|
2020-01-22 10:02:22 +00:00
|
|
|
logfile=None,
|
|
|
|
show_cmd=True,
|
|
|
|
universal_newlines=True,
|
|
|
|
)
|
|
|
|
],
|
2017-04-24 16:44:04 +00:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
2020-01-22 10:02:22 +00:00
|
|
|
"Could not find task ID in output. Command '%s' returned '%s'."
|
|
|
|
% (" ".join(cmd), output),
|
|
|
|
str(ctx.exception),
|
2017-04-24 16:44:04 +00:00
|
|
|
)
|
2016-02-08 12:27:04 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.wrappers.kojiwrapper.run")
|
2020-01-17 09:06:13 +00:00
|
|
|
def test_run_runroot_cmd_with_task_id(self, run):
|
2020-01-22 10:02:22 +00:00
|
|
|
cmd = ["koji", "runroot", "--task-id"]
|
|
|
|
run.return_value = (0, "1234\n")
|
2020-01-17 09:06:13 +00:00
|
|
|
output = "Output ..."
|
|
|
|
self.koji._wait_for_task = mock.Mock(return_value=(0, output))
|
2016-02-12 11:38:45 +00:00
|
|
|
|
|
|
|
result = self.koji.run_runroot_cmd(cmd)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertDictEqual(result, {"retcode": 0, "output": output, "task_id": 1234})
|
2017-04-24 16:44:04 +00:00
|
|
|
self.assertEqual(
|
|
|
|
run.call_args_list,
|
2020-01-22 10:02:22 +00:00
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
cmd,
|
|
|
|
can_fail=True,
|
2020-08-25 07:07:28 +00:00
|
|
|
env={"FOO": "BAR", "PYTHONUNBUFFERED": "1"},
|
2020-07-02 07:32:05 +00:00
|
|
|
buffer_size=-1,
|
2020-01-22 10:02:22 +00:00
|
|
|
logfile=None,
|
|
|
|
show_cmd=True,
|
|
|
|
universal_newlines=True,
|
|
|
|
)
|
|
|
|
],
|
2017-04-24 16:44:04 +00:00
|
|
|
)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("shutil.rmtree")
|
|
|
|
@mock.patch("tempfile.mkdtemp")
|
|
|
|
@mock.patch("pungi.wrappers.kojiwrapper.run")
|
2017-04-24 16:44:04 +00:00
|
|
|
def test_run_runroot_cmd_with_keytab(self, run, mkdtemp, rmtree):
|
|
|
|
# We mock rmtree to avoid deleing something we did not create.
|
2020-01-22 10:02:22 +00:00
|
|
|
mkdtemp.return_value = "/tmp/foo"
|
|
|
|
self.koji.koji_module.config.keytab = "foo"
|
|
|
|
cmd = ["koji", "runroot"]
|
|
|
|
output = "Output ..."
|
|
|
|
run.return_value = (0, "1234\n")
|
2020-01-17 09:06:13 +00:00
|
|
|
self.koji._wait_for_task = mock.Mock(return_value=(0, output))
|
2017-04-24 16:44:04 +00:00
|
|
|
|
|
|
|
result = self.koji.run_runroot_cmd(cmd)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertDictEqual(result, {"retcode": 0, "output": output, "task_id": 1234})
|
2017-04-24 16:44:04 +00:00
|
|
|
self.assertEqual(
|
|
|
|
run.call_args_list,
|
2020-01-22 10:02:22 +00:00
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
cmd,
|
|
|
|
can_fail=True,
|
2020-07-02 07:32:05 +00:00
|
|
|
env={
|
|
|
|
"KRB5CCNAME": "DIR:/tmp/foo",
|
|
|
|
"FOO": "BAR",
|
|
|
|
"PYTHONUNBUFFERED": "1",
|
|
|
|
},
|
|
|
|
buffer_size=-1,
|
2020-01-22 10:02:22 +00:00
|
|
|
logfile=None,
|
|
|
|
show_cmd=True,
|
|
|
|
universal_newlines=True,
|
|
|
|
)
|
|
|
|
],
|
2017-04-24 16:44:04 +00:00
|
|
|
)
|
2016-02-12 11:38:45 +00:00
|
|
|
|
2016-02-08 12:27:04 +00:00
|
|
|
|
2020-08-25 07:07:28 +00:00
|
|
|
@mock.patch.dict("os.environ", {"FOO": "BAR"}, clear=True)
|
2016-03-02 11:36:17 +00:00
|
|
|
class RunBlockingCmdTest(KojiWrapperBaseTestCase):
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.wrappers.kojiwrapper.run")
|
2016-03-02 11:36:17 +00:00
|
|
|
def test_minimal(self, run):
|
2020-01-22 10:02:22 +00:00
|
|
|
output = "Created task: 1234\nHello\n"
|
2016-03-02 11:36:17 +00:00
|
|
|
run.return_value = (0, output)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
result = self.koji.run_blocking_cmd("cmd")
|
2016-03-02 11:36:17 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertDictEqual(result, {"retcode": 0, "output": output, "task_id": 1234})
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self,
|
|
|
|
run.mock_calls,
|
2020-01-22 10:02:22 +00:00
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
"cmd",
|
|
|
|
can_fail=True,
|
|
|
|
logfile=None,
|
2020-08-25 07:07:28 +00:00
|
|
|
env={"FOO": "BAR", "PYTHONUNBUFFERED": "1"},
|
2020-07-02 07:32:05 +00:00
|
|
|
buffer_size=-1,
|
2020-01-22 10:02:22 +00:00
|
|
|
universal_newlines=True,
|
|
|
|
)
|
|
|
|
],
|
2019-10-04 12:45:03 +00:00
|
|
|
)
|
2017-05-15 17:36:43 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.util.temp_dir")
|
|
|
|
@mock.patch("pungi.wrappers.kojiwrapper.run")
|
2017-05-15 17:36:43 +00:00
|
|
|
def test_with_keytab(self, run, temp_dir):
|
2020-01-22 10:02:22 +00:00
|
|
|
temp_dir.return_value.__enter__.return_value = "/tmp/foo"
|
|
|
|
self.koji.koji_module.config.keytab = "foo"
|
|
|
|
output = "Created task: 1234\nHello\n"
|
2017-05-15 17:36:43 +00:00
|
|
|
run.return_value = (0, output)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
result = self.koji.run_blocking_cmd("cmd")
|
2017-05-15 17:36:43 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertDictEqual(result, {"retcode": 0, "output": output, "task_id": 1234})
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self,
|
|
|
|
run.mock_calls,
|
2020-01-22 10:02:22 +00:00
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
"cmd",
|
|
|
|
can_fail=True,
|
|
|
|
logfile=None,
|
2020-07-02 07:32:05 +00:00
|
|
|
env={
|
|
|
|
"KRB5CCNAME": "DIR:/tmp/foo",
|
|
|
|
"FOO": "BAR",
|
|
|
|
"PYTHONUNBUFFERED": "1",
|
|
|
|
},
|
|
|
|
buffer_size=-1,
|
2020-01-22 10:02:22 +00:00
|
|
|
universal_newlines=True,
|
|
|
|
)
|
|
|
|
],
|
2019-10-04 12:45:03 +00:00
|
|
|
)
|
2016-03-02 11:36:17 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.wrappers.kojiwrapper.run")
|
2016-03-02 11:36:17 +00:00
|
|
|
def test_with_log(self, run):
|
2020-01-22 10:02:22 +00:00
|
|
|
output = "Created task: 1234\nHello\n"
|
2016-03-02 11:36:17 +00:00
|
|
|
run.return_value = (0, output)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
result = self.koji.run_blocking_cmd("cmd", log_file="logfile")
|
2016-03-02 11:36:17 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertDictEqual(result, {"retcode": 0, "output": output, "task_id": 1234})
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self,
|
|
|
|
run.mock_calls,
|
2020-01-22 10:02:22 +00:00
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
"cmd",
|
|
|
|
can_fail=True,
|
|
|
|
logfile="logfile",
|
2020-08-25 07:07:28 +00:00
|
|
|
env={"FOO": "BAR", "PYTHONUNBUFFERED": "1"},
|
2020-07-02 07:32:05 +00:00
|
|
|
buffer_size=-1,
|
2020-01-22 10:02:22 +00:00
|
|
|
universal_newlines=True,
|
|
|
|
)
|
|
|
|
],
|
2019-10-04 12:45:03 +00:00
|
|
|
)
|
2016-03-02 11:36:17 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.wrappers.kojiwrapper.run")
|
2016-03-02 11:36:17 +00:00
|
|
|
def test_fail_with_task_id(self, run):
|
2020-01-22 10:02:22 +00:00
|
|
|
output = "Created task: 1234\nBoom\n"
|
2016-03-02 11:36:17 +00:00
|
|
|
run.return_value = (1, output)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
result = self.koji.run_blocking_cmd("cmd")
|
2016-03-02 11:36:17 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertDictEqual(result, {"retcode": 1, "output": output, "task_id": 1234})
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
2020-01-22 10:02:22 +00:00
|
|
|
self,
|
|
|
|
run.mock_calls,
|
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
"cmd",
|
|
|
|
can_fail=True,
|
|
|
|
logfile=None,
|
2020-08-25 07:07:28 +00:00
|
|
|
env={"FOO": "BAR", "PYTHONUNBUFFERED": "1"},
|
2020-07-02 07:32:05 +00:00
|
|
|
buffer_size=-1,
|
2020-01-22 10:02:22 +00:00
|
|
|
universal_newlines=True,
|
|
|
|
)
|
|
|
|
],
|
2019-10-04 12:45:03 +00:00
|
|
|
)
|
2016-03-02 11:36:17 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.wrappers.kojiwrapper.run")
|
2016-03-02 11:36:17 +00:00
|
|
|
def test_fail_without_task_id(self, run):
|
2020-01-22 10:02:22 +00:00
|
|
|
output = "Not found\n"
|
2016-03-02 11:36:17 +00:00
|
|
|
run.return_value = (1, output)
|
|
|
|
|
|
|
|
with self.assertRaises(RuntimeError) as ctx:
|
2020-01-22 10:02:22 +00:00
|
|
|
self.koji.run_blocking_cmd("cmd")
|
2016-03-02 11:36:17 +00:00
|
|
|
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
2020-01-22 10:02:22 +00:00
|
|
|
self,
|
|
|
|
run.mock_calls,
|
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
"cmd",
|
|
|
|
can_fail=True,
|
|
|
|
logfile=None,
|
2020-08-25 07:07:28 +00:00
|
|
|
env={"FOO": "BAR", "PYTHONUNBUFFERED": "1"},
|
2020-07-02 07:32:05 +00:00
|
|
|
buffer_size=-1,
|
2020-01-22 10:02:22 +00:00
|
|
|
universal_newlines=True,
|
|
|
|
)
|
|
|
|
],
|
2019-10-04 12:45:03 +00:00
|
|
|
)
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertIn("Could not find task ID", str(ctx.exception))
|
2016-03-02 11:36:17 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.wrappers.kojiwrapper.run")
|
2016-03-02 11:36:17 +00:00
|
|
|
def test_disconnect_and_retry(self, run):
|
2020-01-22 10:02:22 +00:00
|
|
|
output = "Created task: 1234\nerror: failed to connect\n"
|
|
|
|
retry = "Created task: 1234\nOook\n"
|
2016-03-02 11:36:17 +00:00
|
|
|
run.side_effect = [(1, output), (0, retry)]
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
result = self.koji.run_blocking_cmd("cmd")
|
2016-03-02 11:36:17 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertDictEqual(result, {"retcode": 0, "output": retry, "task_id": 1234})
|
|
|
|
self.assertEqual(
|
|
|
|
run.mock_calls,
|
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
"cmd",
|
|
|
|
can_fail=True,
|
|
|
|
logfile=None,
|
2020-08-25 07:07:28 +00:00
|
|
|
env={"FOO": "BAR", "PYTHONUNBUFFERED": "1"},
|
2020-07-02 07:32:05 +00:00
|
|
|
buffer_size=-1,
|
2020-01-22 10:02:22 +00:00
|
|
|
universal_newlines=True,
|
|
|
|
),
|
|
|
|
mock.call(
|
|
|
|
["koji", "--profile=custom-koji", "watch-task", "1234"],
|
|
|
|
can_fail=True,
|
|
|
|
logfile=None,
|
|
|
|
universal_newlines=True,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
2016-03-02 11:36:17 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.wrappers.kojiwrapper.run")
|
2016-03-02 11:36:17 +00:00
|
|
|
def test_disconnect_and_retry_but_fail(self, run):
|
2020-01-22 10:02:22 +00:00
|
|
|
output = "Created task: 1234\nerror: failed to connect\n"
|
|
|
|
retry = "Created task: 1234\nNot working still\n"
|
2016-03-02 11:36:17 +00:00
|
|
|
run.side_effect = [(1, output), (1, retry)]
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
result = self.koji.run_blocking_cmd("cmd")
|
2016-03-02 11:36:17 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertDictEqual(result, {"retcode": 1, "output": retry, "task_id": 1234})
|
|
|
|
self.assertEqual(
|
|
|
|
run.mock_calls,
|
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
"cmd",
|
|
|
|
can_fail=True,
|
|
|
|
logfile=None,
|
2020-08-25 07:07:28 +00:00
|
|
|
env={"FOO": "BAR", "PYTHONUNBUFFERED": "1"},
|
2020-07-02 07:32:05 +00:00
|
|
|
buffer_size=-1,
|
2020-01-22 10:02:22 +00:00
|
|
|
universal_newlines=True,
|
|
|
|
),
|
|
|
|
mock.call(
|
|
|
|
["koji", "--profile=custom-koji", "watch-task", "1234"],
|
|
|
|
can_fail=True,
|
|
|
|
logfile=None,
|
|
|
|
universal_newlines=True,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
2016-03-02 11:36:17 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("time.sleep")
|
|
|
|
@mock.patch("pungi.wrappers.kojiwrapper.run")
|
2016-03-02 11:36:17 +00:00
|
|
|
def test_disconnect_and_retry_multiple_times(self, run, sleep):
|
2020-01-22 10:02:22 +00:00
|
|
|
output = "Created task: 1234\nerror: failed to connect\n"
|
|
|
|
retry = "Created task: 1234\nOK\n"
|
2016-03-02 11:36:17 +00:00
|
|
|
run.side_effect = [(1, output), (1, output), (1, output), (0, retry)]
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
result = self.koji.run_blocking_cmd("cmd")
|
|
|
|
|
|
|
|
self.assertDictEqual(result, {"retcode": 0, "output": retry, "task_id": 1234})
|
|
|
|
self.assertEqual(
|
|
|
|
run.mock_calls,
|
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
"cmd",
|
|
|
|
can_fail=True,
|
|
|
|
logfile=None,
|
2020-08-25 07:07:28 +00:00
|
|
|
env={"FOO": "BAR", "PYTHONUNBUFFERED": "1"},
|
2020-07-02 07:32:05 +00:00
|
|
|
buffer_size=-1,
|
2020-01-22 10:02:22 +00:00
|
|
|
universal_newlines=True,
|
|
|
|
),
|
|
|
|
mock.call(
|
|
|
|
["koji", "--profile=custom-koji", "watch-task", "1234"],
|
|
|
|
can_fail=True,
|
|
|
|
logfile=None,
|
|
|
|
universal_newlines=True,
|
|
|
|
),
|
|
|
|
mock.call(
|
|
|
|
["koji", "--profile=custom-koji", "watch-task", "1234"],
|
|
|
|
can_fail=True,
|
|
|
|
logfile=None,
|
|
|
|
universal_newlines=True,
|
|
|
|
),
|
|
|
|
mock.call(
|
|
|
|
["koji", "--profile=custom-koji", "watch-task", "1234"],
|
|
|
|
can_fail=True,
|
|
|
|
logfile=None,
|
|
|
|
universal_newlines=True,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
self.assertEqual(sleep.mock_calls, [mock.call(i * 10) for i in range(1, 3)])
|
|
|
|
|
|
|
|
@mock.patch("time.sleep")
|
|
|
|
@mock.patch("pungi.wrappers.kojiwrapper.run")
|
2016-03-02 11:36:17 +00:00
|
|
|
def test_disconnect_and_never_reconnect(self, run, sleep):
|
2020-01-22 10:02:22 +00:00
|
|
|
output = "Created task: 1234\nerror: failed to connect\n"
|
2016-03-02 11:36:17 +00:00
|
|
|
run.side_effect = [(1, output), (1, output), (1, output), (1, output)]
|
|
|
|
|
|
|
|
with self.assertRaises(RuntimeError) as ctx:
|
2020-01-22 10:02:22 +00:00
|
|
|
self.koji.run_blocking_cmd("cmd", max_retries=2)
|
|
|
|
|
|
|
|
self.assertIn("Failed to wait", str(ctx.exception))
|
|
|
|
self.assertEqual(
|
|
|
|
run.mock_calls,
|
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
"cmd",
|
|
|
|
can_fail=True,
|
|
|
|
logfile=None,
|
2020-08-25 07:07:28 +00:00
|
|
|
env={"FOO": "BAR", "PYTHONUNBUFFERED": "1"},
|
2020-07-02 07:32:05 +00:00
|
|
|
buffer_size=-1,
|
2020-01-22 10:02:22 +00:00
|
|
|
universal_newlines=True,
|
|
|
|
),
|
|
|
|
mock.call(
|
|
|
|
["koji", "--profile=custom-koji", "watch-task", "1234"],
|
|
|
|
can_fail=True,
|
|
|
|
logfile=None,
|
|
|
|
universal_newlines=True,
|
|
|
|
),
|
|
|
|
mock.call(
|
|
|
|
["koji", "--profile=custom-koji", "watch-task", "1234"],
|
|
|
|
can_fail=True,
|
|
|
|
logfile=None,
|
|
|
|
universal_newlines=True,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
2016-03-02 11:36:17 +00:00
|
|
|
self.assertEqual(sleep.mock_calls, [mock.call(i * 10) for i in range(1, 2)])
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.wrappers.kojiwrapper.run")
|
2019-11-01 07:23:24 +00:00
|
|
|
def test_server_offline_and_retry(self, run):
|
2020-01-22 10:02:22 +00:00
|
|
|
output = "Created task: 1234\nkoji: ServerOffline:"
|
|
|
|
retry = "Created task: 1234\nOook\n"
|
2019-11-01 07:23:24 +00:00
|
|
|
run.side_effect = [(1, output), (0, retry)]
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
result = self.koji.run_blocking_cmd("cmd")
|
2019-11-01 07:23:24 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertDictEqual(result, {"retcode": 0, "output": retry, "task_id": 1234})
|
|
|
|
self.assertEqual(
|
|
|
|
run.mock_calls,
|
|
|
|
[
|
|
|
|
mock.call(
|
|
|
|
"cmd",
|
|
|
|
can_fail=True,
|
|
|
|
logfile=None,
|
2020-08-25 07:07:28 +00:00
|
|
|
env={"FOO": "BAR", "PYTHONUNBUFFERED": "1"},
|
2020-07-02 07:32:05 +00:00
|
|
|
buffer_size=-1,
|
2020-01-22 10:02:22 +00:00
|
|
|
universal_newlines=True,
|
|
|
|
),
|
|
|
|
mock.call(
|
|
|
|
["koji", "--profile=custom-koji", "watch-task", "1234"],
|
|
|
|
can_fail=True,
|
|
|
|
logfile=None,
|
|
|
|
universal_newlines=True,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
2019-11-01 07:23:24 +00:00
|
|
|
|
2020-11-09 17:36:16 +00:00
|
|
|
def test_get_pungi_buildinstall_cmd(self):
|
|
|
|
args = {"product": "Fedora 23"}
|
|
|
|
cmd = self.koji.get_pungi_buildinstall_cmd(
|
|
|
|
"rrt",
|
|
|
|
"x86_64",
|
|
|
|
args,
|
|
|
|
channel=None,
|
|
|
|
packages=["lorax"],
|
|
|
|
mounts=["/tmp"],
|
|
|
|
weight=123,
|
|
|
|
chown_uid=456,
|
|
|
|
)
|
|
|
|
|
|
|
|
expected_cmd = [
|
|
|
|
"koji",
|
|
|
|
"--profile=custom-koji",
|
|
|
|
"pungi-buildinstall",
|
|
|
|
"--nowait",
|
|
|
|
"--task-id",
|
|
|
|
"--channel-override=runroot-local",
|
|
|
|
"--weight=123",
|
|
|
|
"--package=lorax",
|
|
|
|
"--mount=/tmp",
|
|
|
|
"--chown-uid=456",
|
|
|
|
"rrt",
|
|
|
|
"x86_64",
|
|
|
|
"product=Fedora 23",
|
|
|
|
]
|
|
|
|
self.assertEqual(cmd, expected_cmd)
|
|
|
|
|
|
|
|
def test_get_pungi_ostree_cmd(self):
|
|
|
|
args = {"product": "Fedora 23"}
|
|
|
|
cmd = self.koji.get_pungi_ostree_cmd(
|
|
|
|
"rrt",
|
|
|
|
"x86_64",
|
|
|
|
args,
|
|
|
|
channel=None,
|
|
|
|
packages=["lorax"],
|
|
|
|
mounts=["/tmp"],
|
|
|
|
weight=123,
|
|
|
|
)
|
|
|
|
|
|
|
|
expected_cmd = [
|
|
|
|
"koji",
|
|
|
|
"--profile=custom-koji",
|
|
|
|
"pungi-ostree",
|
|
|
|
"--nowait",
|
|
|
|
"--task-id",
|
|
|
|
"--channel-override=runroot-local",
|
|
|
|
"--weight=123",
|
|
|
|
"--package=lorax",
|
|
|
|
"--mount=/tmp",
|
|
|
|
"rrt",
|
|
|
|
"x86_64",
|
|
|
|
"product=Fedora 23",
|
|
|
|
]
|
|
|
|
self.assertEqual(cmd, expected_cmd)
|
|
|
|
|
2016-03-02 11:36:17 +00:00
|
|
|
|
2017-04-25 13:22:09 +00:00
|
|
|
RPM_QA_QF_OUTPUT = """
|
|
|
|
cjkuni-uming-fonts-0.2.20080216.1-56.fc23.noarch
|
|
|
|
libmount-2.28-1.fc23.x86_64
|
|
|
|
ed-1.10-5.fc23.x86_64
|
|
|
|
kbd-2.0.2-8.fc23.x86_64
|
|
|
|
coreutils-8.24-6.fc23.x86_64
|
|
|
|
"""
|
|
|
|
|
|
|
|
BUILDROOT_LIST = [
|
2020-01-22 10:02:22 +00:00
|
|
|
{
|
|
|
|
"arch": "x86_64",
|
|
|
|
"br_type": 0,
|
|
|
|
"cg_id": None,
|
|
|
|
"cg_name": None,
|
|
|
|
"cg_version": None,
|
|
|
|
"container_arch": "x86_64",
|
|
|
|
"container_type": "chroot",
|
|
|
|
"create_event_id": 15862222,
|
|
|
|
"create_event_time": "2016-04-28 02:37:00.949772",
|
|
|
|
"create_ts": 1461811020.94977,
|
|
|
|
"extra": None,
|
|
|
|
"host_arch": None,
|
|
|
|
"host_id": 99,
|
|
|
|
"host_name": "buildhw-01.phx2.fedoraproject.org",
|
|
|
|
"host_os": None,
|
|
|
|
"id": 5458481,
|
|
|
|
"repo_create_event_id": 15861452,
|
|
|
|
"repo_create_event_time": "2016-04-28 00:02:40.639317",
|
|
|
|
"repo_id": 599173,
|
|
|
|
"repo_state": 1,
|
|
|
|
"retire_event_id": 15862276,
|
|
|
|
"retire_event_time": "2016-04-28 02:58:07.109387",
|
|
|
|
"retire_ts": 1461812287.10939,
|
|
|
|
"state": 3,
|
|
|
|
"tag_id": 315,
|
|
|
|
"tag_name": "f24-build",
|
|
|
|
"task_id": 13831904,
|
|
|
|
}
|
2017-04-25 13:22:09 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
RPM_LIST = [
|
2020-01-22 10:02:22 +00:00
|
|
|
{
|
|
|
|
"arch": "noarch",
|
|
|
|
"build_id": 756072,
|
|
|
|
"buildroot_id": 5398084,
|
|
|
|
"buildtime": 1461100903,
|
|
|
|
"component_buildroot_id": 5458481,
|
|
|
|
"epoch": None,
|
|
|
|
"external_repo_id": 0,
|
|
|
|
"external_repo_name": "INTERNAL",
|
|
|
|
"extra": None,
|
|
|
|
"id": 7614370,
|
|
|
|
"is_update": True,
|
|
|
|
"metadata_only": False,
|
|
|
|
"name": "python3-kickstart",
|
|
|
|
"nvr": "python3-kickstart-2.25-2.fc24",
|
|
|
|
"payloadhash": "403723502d27e43955036d2dcd1b09e0",
|
|
|
|
"release": "2.fc24",
|
|
|
|
"size": 366038,
|
|
|
|
"version": "2.25",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"arch": "x86_64",
|
|
|
|
"build_id": 756276,
|
|
|
|
"buildroot_id": 5405310,
|
|
|
|
"buildtime": 1461165155,
|
|
|
|
"component_buildroot_id": 5458481,
|
|
|
|
"epoch": None,
|
|
|
|
"external_repo_id": 0,
|
|
|
|
"external_repo_name": "INTERNAL",
|
|
|
|
"extra": None,
|
|
|
|
"id": 7615629,
|
|
|
|
"is_update": False,
|
|
|
|
"metadata_only": False,
|
|
|
|
"name": "binutils",
|
|
|
|
"nvr": "binutils-2.26-18.fc24",
|
|
|
|
"payloadhash": "8ef08c8a64c52787d3559424e5f51d9d",
|
|
|
|
"release": "18.fc24",
|
|
|
|
"size": 6172094,
|
|
|
|
"version": "2.26",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"arch": "x86_64",
|
|
|
|
"build_id": 756616,
|
|
|
|
"buildroot_id": 5412029,
|
|
|
|
"buildtime": 1461252071,
|
|
|
|
"component_buildroot_id": 5458481,
|
|
|
|
"epoch": None,
|
|
|
|
"external_repo_id": 0,
|
|
|
|
"external_repo_name": "INTERNAL",
|
|
|
|
"extra": None,
|
|
|
|
"id": 7619636,
|
|
|
|
"is_update": False,
|
|
|
|
"metadata_only": False,
|
|
|
|
"name": "kernel-headers",
|
|
|
|
"nvr": "kernel-headers-4.5.2-301.fc24",
|
|
|
|
"payloadhash": "11c6d70580c8f0c202c28bc6b0fa98cc",
|
|
|
|
"release": "301.fc24",
|
|
|
|
"size": 1060138,
|
|
|
|
"version": "4.5.2",
|
|
|
|
},
|
2017-04-25 13:22:09 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class TestGetBuildrootRPMs(unittest.TestCase):
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.wrappers.kojiwrapper.KojiWrapper")
|
2017-04-25 13:22:09 +00:00
|
|
|
def test_get_from_koji(self, KojiWrapper):
|
2020-01-22 10:02:22 +00:00
|
|
|
compose = mock.Mock(conf={"koji_profile": "koji"})
|
2017-04-25 13:22:09 +00:00
|
|
|
|
|
|
|
KojiWrapper.return_value.koji_proxy.listBuildroots.return_value = BUILDROOT_LIST
|
|
|
|
KojiWrapper.return_value.koji_proxy.listRPMs.return_value = RPM_LIST
|
|
|
|
|
|
|
|
rpms = get_buildroot_rpms(compose, 1234)
|
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
self.assertEqual(KojiWrapper.call_args_list, [mock.call("koji")])
|
|
|
|
self.assertEqual(
|
|
|
|
KojiWrapper.return_value.mock_calls,
|
|
|
|
[
|
|
|
|
mock.call.koji_proxy.listBuildroots(taskID=1234),
|
|
|
|
mock.call.koji_proxy.listRPMs(componentBuildrootID=5458481),
|
|
|
|
],
|
|
|
|
)
|
2017-04-25 13:22:09 +00:00
|
|
|
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self,
|
|
|
|
rpms,
|
|
|
|
[
|
|
|
|
"python3-kickstart-2.25-2.fc24.noarch",
|
|
|
|
"binutils-2.26-18.fc24.x86_64",
|
|
|
|
"kernel-headers-4.5.2-301.fc24.x86_64",
|
|
|
|
],
|
|
|
|
)
|
2017-04-25 13:22:09 +00:00
|
|
|
|
2020-01-22 10:02:22 +00:00
|
|
|
@mock.patch("pungi.wrappers.kojiwrapper.run")
|
2017-04-25 13:22:09 +00:00
|
|
|
def test_get_local(self, mock_run):
|
|
|
|
compose = mock.Mock()
|
|
|
|
|
|
|
|
mock_run.return_value = (0, RPM_QA_QF_OUTPUT)
|
|
|
|
|
|
|
|
rpms = get_buildroot_rpms(compose, None)
|
|
|
|
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self,
|
|
|
|
rpms,
|
|
|
|
[
|
|
|
|
"cjkuni-uming-fonts-0.2.20080216.1-56.fc23.noarch",
|
|
|
|
"libmount-2.28-1.fc23.x86_64",
|
|
|
|
"ed-1.10-5.fc23.x86_64",
|
|
|
|
"kbd-2.0.2-8.fc23.x86_64",
|
|
|
|
"coreutils-8.24-6.fc23.x86_64",
|
|
|
|
],
|
|
|
|
)
|