2016-05-12 11:41:53 +00:00
|
|
|
#!/usr/bin/env python2
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import mock
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
|
|
|
|
|
|
|
from pungi.phases import extra_files
|
|
|
|
from tests import helpers
|
|
|
|
|
|
|
|
|
|
|
|
class TestExtraFilePhase(helpers.PungiTestCase):
|
|
|
|
|
2016-05-12 11:50:34 +00:00
|
|
|
@mock.patch('pungi.phases.extra_files.copy_extra_files')
|
|
|
|
def test_skips_unless_has_config(self, copy_extra_files):
|
|
|
|
compose = helpers.DummyCompose(self.topdir, {})
|
|
|
|
compose.just_phases = None
|
|
|
|
compose.skip_phases = []
|
|
|
|
phase = extra_files.ExtraFilesPhase(compose, mock.Mock())
|
|
|
|
self.assertTrue(phase.skip())
|
|
|
|
|
2016-05-12 11:41:53 +00:00
|
|
|
@mock.patch('pungi.phases.extra_files.copy_extra_files')
|
|
|
|
def test_runs_copy_files_for_each_variant(self, copy_extra_files):
|
|
|
|
cfg = mock.Mock()
|
|
|
|
pkgset_phase = mock.Mock()
|
|
|
|
compose = helpers.DummyCompose(self.topdir, {
|
|
|
|
'extra_files': [
|
2016-05-12 12:19:14 +00:00
|
|
|
('^.+$', {'x86_64': [cfg]})
|
2016-05-12 11:41:53 +00:00
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
phase = extra_files.ExtraFilesPhase(compose, pkgset_phase)
|
|
|
|
phase.run()
|
|
|
|
|
|
|
|
self.assertItemsEqual(
|
|
|
|
copy_extra_files.call_args_list,
|
2016-05-12 12:19:14 +00:00
|
|
|
[mock.call(compose, [cfg], 'x86_64', compose.variants['Server'],
|
|
|
|
pkgset_phase.package_sets),
|
|
|
|
mock.call(compose, [cfg], 'x86_64', compose.variants['Everything'],
|
|
|
|
pkgset_phase.package_sets)]
|
2016-05-12 11:41:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class TestCopyFiles(helpers.PungiTestCase):
|
|
|
|
|
|
|
|
def test_copy_local_file(self):
|
|
|
|
tgt = os.path.join(self.topdir, 'file')
|
|
|
|
helpers.touch(tgt)
|
2016-05-12 12:19:14 +00:00
|
|
|
compose = helpers.DummyCompose(self.topdir, {})
|
|
|
|
cfg = {'scm': 'file', 'file': tgt, 'repo': None}
|
|
|
|
|
|
|
|
extra_files.copy_extra_files(compose, [cfg], 'x86_64',
|
|
|
|
compose.variants['Server'], mock.Mock())
|
|
|
|
|
|
|
|
self.assertTrue(os.path.isfile(os.path.join(
|
|
|
|
self.topdir, 'compose', 'Server', 'x86_64', 'os', 'file')))
|
|
|
|
|
|
|
|
def test_copy_multiple_sources(self):
|
|
|
|
tgt1 = os.path.join(self.topdir, 'file')
|
|
|
|
tgt2 = os.path.join(self.topdir, 'gpl')
|
|
|
|
helpers.touch(tgt1)
|
|
|
|
helpers.touch(tgt2)
|
|
|
|
compose = helpers.DummyCompose(self.topdir, {})
|
|
|
|
cfg1 = {'scm': 'file', 'file': tgt1, 'repo': None}
|
|
|
|
cfg2 = {'scm': 'file', 'file': tgt2, 'repo': None, 'target': 'license'}
|
2016-05-12 11:41:53 +00:00
|
|
|
|
2016-05-12 12:19:14 +00:00
|
|
|
extra_files.copy_extra_files(compose, [cfg1, cfg2], 'x86_64',
|
|
|
|
compose.variants['Server'], mock.Mock())
|
2016-05-12 11:41:53 +00:00
|
|
|
|
|
|
|
self.assertTrue(os.path.isfile(os.path.join(
|
|
|
|
self.topdir, 'compose', 'Server', 'x86_64', 'os', 'file')))
|
2016-05-12 12:19:14 +00:00
|
|
|
self.assertTrue(os.path.isfile(os.path.join(
|
|
|
|
self.topdir, 'compose', 'Server', 'x86_64', 'os', 'license', 'gpl')))
|
2016-05-12 11:41:53 +00:00
|
|
|
|
|
|
|
def test_copy_local_dir(self):
|
|
|
|
helpers.touch(os.path.join(self.topdir, 'src', 'file'))
|
|
|
|
helpers.touch(os.path.join(self.topdir, 'src', 'another'))
|
2016-05-12 12:19:14 +00:00
|
|
|
compose = helpers.DummyCompose(self.topdir, {})
|
|
|
|
cfg = {'scm': 'file', 'dir': os.path.join(self.topdir, 'src'),
|
|
|
|
'repo': None, 'target': 'subdir'}
|
|
|
|
extra_files.copy_extra_files(compose, [cfg], 'x86_64',
|
|
|
|
compose.variants['Server'], mock.Mock())
|
2016-05-12 11:41:53 +00:00
|
|
|
|
|
|
|
self.assertTrue(os.path.isfile(os.path.join(
|
|
|
|
self.topdir, 'compose', 'Server', 'x86_64', 'os', 'subdir', 'file')))
|
|
|
|
self.assertTrue(os.path.isfile(os.path.join(
|
|
|
|
self.topdir, 'compose', 'Server', 'x86_64', 'os', 'subdir', 'another')))
|
|
|
|
|
|
|
|
@mock.patch('pungi.phases.extra_files.get_file_from_scm')
|
|
|
|
@mock.patch('pungi.phases.extra_files.get_dir_from_scm')
|
|
|
|
def test_copy_from_external_rpm(self, get_dir_from_scm, get_file_from_scm):
|
2016-05-12 12:19:14 +00:00
|
|
|
compose = helpers.DummyCompose(self.topdir, {})
|
|
|
|
cfg = {'scm': 'rpm', 'file': 'file.txt', 'repo': 'http://example.com/package.rpm'}
|
2016-05-12 11:41:53 +00:00
|
|
|
|
|
|
|
get_file_from_scm.side_effect = self.fake_get_file
|
|
|
|
|
2016-05-12 12:19:14 +00:00
|
|
|
extra_files.copy_extra_files(compose, [cfg], 'x86_64',
|
|
|
|
compose.variants['Server'], mock.Mock())
|
2016-05-12 11:41:53 +00:00
|
|
|
|
|
|
|
self.assertEqual(len(get_file_from_scm.call_args_list), 1)
|
|
|
|
self.assertEqual(get_dir_from_scm.call_args_list, [])
|
|
|
|
self.assertEqual(self.scm_dict,
|
|
|
|
{'scm': 'rpm', 'file': 'file.txt', 'repo': 'http://example.com/package.rpm'})
|
|
|
|
|
|
|
|
self.assertTrue(os.path.isfile(os.path.join(
|
|
|
|
self.topdir, 'compose', 'Server', 'x86_64', 'os', 'file.txt')))
|
|
|
|
|
|
|
|
@mock.patch('pungi.phases.extra_files.get_file_from_scm')
|
|
|
|
@mock.patch('pungi.phases.extra_files.get_dir_from_scm')
|
|
|
|
def test_copy_from_rpm_in_compose(self, get_dir_from_scm, get_file_from_scm):
|
2016-05-12 12:19:14 +00:00
|
|
|
compose = helpers.DummyCompose(self.topdir, {})
|
|
|
|
cfg = {'scm': 'rpm', 'file': 'file.txt', 'repo': '%(variant_uid)s-data*'}
|
2016-05-12 11:41:53 +00:00
|
|
|
server_po, client_po, src_po = mock.Mock(), mock.Mock(), mock.Mock()
|
|
|
|
server_po.configure_mock(name='Server-data-1.1-1.fc24.x86_64.rpm',
|
|
|
|
file_path='/server/location',
|
|
|
|
arch='x86_64')
|
|
|
|
client_po.configure_mock(name='Client-data-1.1-1.fc24.x86_64.rpm',
|
|
|
|
file_path='/client/location',
|
|
|
|
arch='x86_64')
|
|
|
|
src_po.configure_mock(name='extra-data-1.1-1.fc24.src.rpm',
|
|
|
|
file_path='/src/location',
|
|
|
|
arch='src')
|
|
|
|
package_sets = {
|
|
|
|
'x86_64': {server_po.name: server_po,
|
|
|
|
client_po.name: client_po,
|
|
|
|
src_po.name: src_po}
|
|
|
|
}
|
|
|
|
|
|
|
|
get_file_from_scm.side_effect = self.fake_get_file
|
|
|
|
|
2016-05-12 12:19:14 +00:00
|
|
|
extra_files.copy_extra_files(compose, [cfg], 'x86_64',
|
|
|
|
compose.variants['Server'], package_sets)
|
2016-05-12 11:41:53 +00:00
|
|
|
|
|
|
|
self.assertEqual(len(get_file_from_scm.call_args_list), 1)
|
|
|
|
self.assertEqual(get_dir_from_scm.call_args_list, [])
|
|
|
|
|
|
|
|
self.assertEqual(self.scm_dict,
|
|
|
|
{'scm': 'rpm', 'file': 'file.txt', 'repo': ['/server/location']})
|
|
|
|
|
|
|
|
self.assertTrue(os.path.isfile(os.path.join(
|
|
|
|
self.topdir, 'compose', 'Server', 'x86_64', 'os', 'file.txt')))
|
|
|
|
|
|
|
|
def fake_get_file(self, scm_dict, dest, logger):
|
|
|
|
self.scm_dict = scm_dict
|
|
|
|
helpers.touch(os.path.join(dest, scm_dict['file']))
|
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
|
|
|
return [scm_dict['file']]
|
2016-05-12 11:41:53 +00:00
|
|
|
|
2016-11-10 08:38:50 +00:00
|
|
|
@mock.patch('pungi.phases.extra_files.get_file_from_scm')
|
|
|
|
@mock.patch('pungi.phases.extra_files.get_dir_from_scm')
|
|
|
|
def test_copy_from_non_existing_rpm_in_compose(self, get_dir_from_scm, get_file_from_scm):
|
|
|
|
compose = helpers.DummyCompose(self.topdir, {})
|
|
|
|
cfg = {'scm': 'rpm', 'file': 'file.txt', 'repo': 'bad-%(variant_uid_lower)s*'}
|
|
|
|
package_sets = {'x86_64': {}}
|
|
|
|
|
|
|
|
with self.assertRaises(RuntimeError) as ctx:
|
|
|
|
extra_files.copy_extra_files(
|
|
|
|
compose, [cfg], 'x86_64', compose.variants['Server'], package_sets)
|
|
|
|
|
2017-09-05 08:01:21 +00:00
|
|
|
self.assertRegex(str(ctx.exception), 'No.*package.*matching bad-server\*.*')
|
2016-11-10 08:38:50 +00:00
|
|
|
|
|
|
|
self.assertEqual(len(get_file_from_scm.call_args_list), 0)
|
|
|
|
self.assertEqual(get_dir_from_scm.call_args_list, [])
|
|
|
|
|
2016-05-12 11:41:53 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|