2016-05-04 13:22:23 +00:00
|
|
|
import mock
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2019-10-04 12:45:03 +00:00
|
|
|
import six
|
|
|
|
|
2016-05-04 13:22:23 +00:00
|
|
|
from tests import helpers
|
|
|
|
|
|
|
|
from pungi import metadata
|
|
|
|
from pungi.compose_metadata import discinfo
|
|
|
|
|
|
|
|
|
|
|
|
class DiscInfoTestCase(helpers.PungiTestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(DiscInfoTestCase, self).setUp()
|
2019-03-09 13:57:19 +00:00
|
|
|
os.environ['SOURCE_DATE_EPOCH'] = '101010101'
|
2016-05-04 13:22:23 +00:00
|
|
|
self.path = os.path.join(self.topdir, 'compose/Server/x86_64/os/.discinfo')
|
|
|
|
|
|
|
|
def test_write_discinfo_variant(self):
|
|
|
|
compose = helpers.DummyCompose(self.topdir, {
|
|
|
|
'release_name': 'Test',
|
|
|
|
'release_version': '1.0',
|
|
|
|
})
|
|
|
|
|
|
|
|
metadata.write_discinfo(compose, 'x86_64', compose.variants['Server'])
|
|
|
|
|
|
|
|
with open(self.path) as f:
|
|
|
|
self.assertEqual(f.read().strip().split('\n'),
|
2019-03-09 13:57:19 +00:00
|
|
|
['101010101',
|
2016-05-04 13:22:23 +00:00
|
|
|
'Test 1.0',
|
|
|
|
'x86_64',
|
|
|
|
'ALL'])
|
|
|
|
|
|
|
|
self.assertEqual(discinfo.read_discinfo(self.path),
|
2019-03-09 13:57:19 +00:00
|
|
|
{'timestamp': '101010101',
|
2016-05-04 13:22:23 +00:00
|
|
|
'description': 'Test 1.0',
|
|
|
|
'disc_numbers': ['ALL'],
|
|
|
|
'arch': 'x86_64'})
|
|
|
|
|
|
|
|
def test_write_discinfo_custom_description(self):
|
|
|
|
compose = helpers.DummyCompose(self.topdir, {
|
|
|
|
'release_name': 'Test',
|
|
|
|
'release_version': '1.0',
|
|
|
|
'release_discinfo_description': 'Fuzzy %(variant_name)s.%(arch)s',
|
|
|
|
})
|
|
|
|
compose.variants['Server'].name = 'Server'
|
|
|
|
|
|
|
|
metadata.write_discinfo(compose, 'x86_64', compose.variants['Server'])
|
|
|
|
|
|
|
|
with open(self.path) as f:
|
|
|
|
self.assertEqual(f.read().strip().split('\n'),
|
2019-03-09 13:57:19 +00:00
|
|
|
['101010101',
|
2016-05-04 13:22:23 +00:00
|
|
|
'Fuzzy Server.x86_64',
|
|
|
|
'x86_64',
|
|
|
|
'ALL'])
|
|
|
|
|
|
|
|
def test_write_discinfo_layered_product(self):
|
|
|
|
compose = helpers.DummyCompose(self.topdir, {
|
|
|
|
'release_name': 'Test',
|
|
|
|
'release_version': '1.0',
|
|
|
|
'base_product_name': 'Base',
|
|
|
|
'base_product_version': 42,
|
|
|
|
})
|
|
|
|
|
|
|
|
metadata.write_discinfo(compose, 'x86_64', compose.variants['Server'])
|
|
|
|
|
|
|
|
with open(self.path) as f:
|
|
|
|
self.assertEqual(f.read().strip().split('\n'),
|
2019-03-09 13:57:19 +00:00
|
|
|
['101010101',
|
2016-05-04 13:22:23 +00:00
|
|
|
'Test 1.0 for Base 42',
|
|
|
|
'x86_64',
|
|
|
|
'ALL'])
|
|
|
|
|
|
|
|
def test_write_discinfo_integrated_layered_product(self):
|
|
|
|
compose = helpers.DummyCompose(self.topdir, {
|
|
|
|
'release_name': 'Test',
|
|
|
|
'release_version': '1.0',
|
|
|
|
})
|
|
|
|
compose.variants['ILP'] = mock.Mock(uid='Server', arches=['x86_64'],
|
|
|
|
type='layered-product', is_empty=False,
|
|
|
|
release_name='Integrated',
|
|
|
|
release_version='2.1',
|
|
|
|
parent=compose.variants['Server'])
|
|
|
|
|
|
|
|
metadata.write_discinfo(compose, 'x86_64', compose.variants['ILP'])
|
|
|
|
|
|
|
|
with open(self.path) as f:
|
|
|
|
self.assertEqual(f.read().strip().split('\n'),
|
2019-03-09 13:57:19 +00:00
|
|
|
['101010101',
|
2016-05-04 13:22:23 +00:00
|
|
|
'Integrated 2.1 for Test 1',
|
|
|
|
'x86_64',
|
|
|
|
'ALL'])
|
|
|
|
|
|
|
|
def test_addons_dont_have_discinfo(self):
|
|
|
|
compose = helpers.DummyCompose(self.topdir, {
|
|
|
|
'release_name': 'Test',
|
|
|
|
'release_version': '1.0',
|
|
|
|
})
|
|
|
|
compose.variants['ILP'] = mock.Mock(uid='Server', arches=['x86_64'],
|
|
|
|
type='addon', is_empty=False,
|
|
|
|
parent=compose.variants['Server'])
|
|
|
|
|
|
|
|
metadata.write_discinfo(compose, 'x86_64', compose.variants['ILP'])
|
|
|
|
|
|
|
|
self.assertFalse(os.path.isfile(self.path))
|
|
|
|
|
|
|
|
|
2016-05-04 13:41:32 +00:00
|
|
|
class MediaRepoTestCase(helpers.PungiTestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(MediaRepoTestCase, self).setUp()
|
|
|
|
self.path = os.path.join(self.topdir, 'compose/Server/x86_64/os/media.repo')
|
|
|
|
|
|
|
|
def test_write_media_repo(self):
|
|
|
|
compose = helpers.DummyCompose(self.topdir, {
|
|
|
|
'release_name': 'Test',
|
|
|
|
'release_version': '1.0',
|
|
|
|
})
|
|
|
|
|
|
|
|
metadata.write_media_repo(compose, 'x86_64', compose.variants['Server'],
|
|
|
|
timestamp=123456)
|
|
|
|
|
|
|
|
with open(self.path) as f:
|
|
|
|
lines = f.read().strip().split('\n')
|
|
|
|
self.assertEqual(lines[0], '[InstallMedia]')
|
2019-10-04 12:45:03 +00:00
|
|
|
six.assertCountEqual(
|
|
|
|
self,
|
|
|
|
lines[1:],
|
|
|
|
[
|
|
|
|
"name=Test 1.0",
|
|
|
|
"mediaid=123456",
|
|
|
|
"metadata_expire=-1",
|
|
|
|
"gpgcheck=0",
|
|
|
|
"cost=500",
|
|
|
|
],
|
|
|
|
)
|
2016-05-04 13:41:32 +00:00
|
|
|
|
|
|
|
def test_addons_dont_have_media_repo(self):
|
|
|
|
compose = helpers.DummyCompose(self.topdir, {
|
|
|
|
'release_name': 'Test',
|
|
|
|
'release_version': '1.0',
|
|
|
|
})
|
|
|
|
compose.variants['ILP'] = mock.Mock(uid='Server', arches=['x86_64'],
|
|
|
|
type='addon', is_empty=False,
|
|
|
|
parent=compose.variants['Server'])
|
|
|
|
|
|
|
|
metadata.write_discinfo(compose, 'x86_64', compose.variants['ILP'])
|
|
|
|
|
|
|
|
self.assertFalse(os.path.isfile(self.path))
|
|
|
|
|
|
|
|
|
2019-11-01 08:10:34 +00:00
|
|
|
FOO_MD5 = {"md5": "acbd18db4cc2f85cedef654fccc4a4d8"}
|
|
|
|
BAR_MD5 = {"md5": "37b51d194a7513e45b56f6524f2d51f2"}
|
|
|
|
|
|
|
|
|
|
|
|
class TestPopulateExtraFiles(helpers.PungiTestCase):
|
extra-files: Write a metadata file enumerating extra files
Introduces a new metadata file to track arbitrary files added during the
extra-files phase. This file is placed in the root of each tree and is
called ``extra_files.json``. It is a JSON file containing a single
object, which contains a "header" key with an object describing the
metadata, and a "data" key, which is an array of objects, where each
object represents a file. Each object contains the "file", "checksums",
and "size" keys. "file" is the relative path from the tree root to the
extra file. "checksums" is an object containing one or more checksums,
where the key is the digest type and the value of that key is the hex
digest. Finally, the size is the size of the file in bytes.
For example:
{
"header": {"version": "1.0},
"data": [
{
"file": "GPL",
"checksums": {
"sha256": "8177f97513213526df2cf6184d8ff986c675afb514d4e68a404010521b880643"
},
"size": 18092
},
{
"file": "release-notes/notes.html",
"checksums": {
"sha256": "82b1ba8db522aadf101dca6404235fba179e559b95ea24ff39ee1e5d9a53bdcb"
},
"size": 1120
}
]
}
Signed-off-by: Jeremy Cline <jeremy@jcline.org>
Fixes: #295
2016-05-31 13:40:20 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
2019-11-01 08:10:34 +00:00
|
|
|
super(TestPopulateExtraFiles, self).setUp()
|
|
|
|
self.variant = mock.Mock(uid="Server")
|
|
|
|
self.metadata = mock.Mock()
|
|
|
|
|
|
|
|
def test_with_relative_root(self):
|
|
|
|
helpers.touch(
|
|
|
|
os.path.join(self.topdir, "compose/Server/x86_64/os/foo"), content="foo"
|
|
|
|
)
|
|
|
|
helpers.touch(
|
|
|
|
os.path.join(self.topdir, "compose/Server/x86_64/os/bar"), content="bar"
|
|
|
|
)
|
|
|
|
|
|
|
|
metadata.populate_extra_files_metadata(
|
|
|
|
self.metadata,
|
|
|
|
self.variant,
|
|
|
|
"x86_64",
|
|
|
|
os.path.join(self.topdir, "compose/Server/x86_64/os"),
|
|
|
|
["foo", "bar"],
|
|
|
|
["md5"],
|
|
|
|
relative_root=os.path.join(self.topdir, "compose"),
|
|
|
|
)
|
|
|
|
|
2017-04-20 06:58:27 +00:00
|
|
|
self.maxDiff = None
|
2019-11-01 08:10:34 +00:00
|
|
|
|
|
|
|
six.assertCountEqual(
|
|
|
|
self,
|
|
|
|
self.metadata.mock_calls,
|
|
|
|
[
|
|
|
|
mock.call.add(
|
|
|
|
"Server", "x86_64", "Server/x86_64/os/foo", 3, FOO_MD5
|
|
|
|
),
|
|
|
|
mock.call.add(
|
|
|
|
"Server", "x86_64", "Server/x86_64/os/bar", 3, BAR_MD5
|
|
|
|
),
|
|
|
|
mock.call.dump_for_tree(
|
|
|
|
mock.ANY, "Server", "x86_64", "Server/x86_64/os/"
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_without_relative_root(self):
|
|
|
|
helpers.touch(os.path.join(self.topdir, "foo"), content="foo")
|
|
|
|
helpers.touch(os.path.join(self.topdir, "bar"), content="bar")
|
|
|
|
|
|
|
|
metadata.populate_extra_files_metadata(
|
|
|
|
self.metadata, self.variant, "x86_64", self.topdir, ["foo", "bar"], ["md5"]
|
|
|
|
)
|
|
|
|
|
|
|
|
six.assertCountEqual(
|
|
|
|
self,
|
|
|
|
self.metadata.mock_calls,
|
|
|
|
[
|
|
|
|
mock.call.add("Server", "x86_64", "foo", 3, FOO_MD5),
|
|
|
|
mock.call.add("Server", "x86_64", "bar", 3, BAR_MD5),
|
|
|
|
mock.call.dump_for_tree(mock.ANY, "Server", "x86_64", ""),
|
|
|
|
],
|
|
|
|
)
|